Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evaluation cache, freshen each predicate by itself #102713

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::{
SelectionResult, TraitObligation, TraitQueryMode,
};

use crate::infer::{InferCtxt, InferOk, TypeFreshener};
use crate::infer::{InferCtxt, InferOk};
use crate::traits::error_reporting::TypeErrCtxtExt;
use crate::traits::project::ProjectAndUnifyResult;
use crate::traits::project::ProjectionCacheKeyExt;
Expand Down Expand Up @@ -95,13 +95,6 @@ impl IntercrateAmbiguityCause {
pub struct SelectionContext<'cx, 'tcx> {
infcx: &'cx InferCtxt<'tcx>,

/// Freshener used specifically for entries on the obligation
/// stack. This ensures that all entries on the stack at one time
/// will have the same set of placeholder entries, which is
/// important for checking for trait bounds that recursively
/// require themselves.
freshener: TypeFreshener<'cx, 'tcx>,

/// During coherence we have to assume that other crates may add
/// additional impls which we currently don't know about.
///
Expand Down Expand Up @@ -217,7 +210,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
pub fn new(infcx: &'cx InferCtxt<'tcx>) -> SelectionContext<'cx, 'tcx> {
SelectionContext {
infcx,
freshener: infcx.freshener_keep_static(),
intercrate: false,
intercrate_ambiguity_causes: None,
query_mode: TraitQueryMode::Standard,
Expand Down Expand Up @@ -2251,7 +2243,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
previous_stack: TraitObligationStackList<'o, 'tcx>,
obligation: &'o TraitObligation<'tcx>,
) -> TraitObligationStack<'o, 'tcx> {
let fresh_trait_pred = obligation.predicate.fold_with(&mut self.freshener);
let fresh_trait_pred =
obligation.predicate.fold_with(&mut self.infcx.freshener_keep_static());
Copy link
Contributor Author

@lcnr lcnr Oct 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keeping 'static here is wrong. I am changing this separately in #102472 which is blocked on #102635


let dfn = previous_stack.cache.next_dfn();
let depth = previous_stack.depth() + 1;
Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/coherence/issue-100191-2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//~ ERROR overflow evaluating the requirement `T: Trait<_>`

#![feature(specialization, with_negative_coherence)]
#![allow(incomplete_features)]

Expand All @@ -8,5 +6,6 @@ pub trait Trait<T> {}
default impl<T, U> Trait<T> for U {}

impl<T> Trait<<T as Iterator>::Item> for T {}
//~^ ERROR conflicting implementations of trait `Trait<_>`

fn main() {}
16 changes: 7 additions & 9 deletions src/test/ui/coherence/issue-100191-2.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
error[E0275]: overflow evaluating the requirement `T: Trait<_>`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_100191_2`)
note: required for `T` to implement `Trait<_>`
--> $DIR/issue-100191-2.rs:8:20
error[E0119]: conflicting implementations of trait `Trait<_>`
--> $DIR/issue-100191-2.rs:8:1
|
LL | default impl<T, U> Trait<T> for U {}
| ^^^^^^^^ ^
= note: 128 redundant requirements hidden
= note: required for `T` to implement `Trait<_>`
| --------------------------------- first implementation here
LL |
LL | impl<T> Trait<<T as Iterator>::Item> for T {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

error: aborting due to previous error

For more information about this error, try `rustc --explain E0275`.
For more information about this error, try `rustc --explain E0119`.
3 changes: 1 addition & 2 deletions src/test/ui/issues/issue-69683.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ where
fn main() {
let b: [u8; 3] = [0u8; 3];

0u16.foo(b); //~ ERROR type annotations needed
//~^ ERROR type annotations needed
0u16.foo(b); //~ ERROR mismatched types
//<u16 as Foo<[(); 3]>>::foo(0u16, b);
}
46 changes: 10 additions & 36 deletions src/test/ui/issues/issue-69683.stderr
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
error[E0284]: type annotations needed
--> $DIR/issue-69683.rs:30:10
error[E0308]: mismatched types
--> $DIR/issue-69683.rs:30:14
|
LL | 0u16.foo(b);
| ^^^
| --- ^ expected `u8`, found array `[u8; 3]`
| |
| arguments to this function are incorrect
|
= note: cannot satisfy `<u8 as Element<_>>::Array == [u8; 3]`
help: try using a fully qualified path to specify the expected types
note: associated function defined here
--> $DIR/issue-69683.rs:17:8
|
LL | <u16 as Foo<I>>::foo(0u16, b);
| +++++++++++++++++++++ ~

error[E0283]: type annotations needed
--> $DIR/issue-69683.rs:30:10
|
LL | 0u16.foo(b);
| ^^^
|
note: multiple `impl`s satisfying `u8: Element<_>` found
--> $DIR/issue-69683.rs:5:1
|
LL | impl<T> Element<()> for T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | impl<T: Element<S>, S> Element<[S; 3]> for T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `Foo::foo`
--> $DIR/issue-69683.rs:15:9
|
LL | u8: Element<I>,
| ^^^^^^^^^^ required by this bound in `Foo::foo`
LL | {
LL | fn foo(self, x: <u8 as Element<I>>::Array);
| --- required by a bound in this
help: try using a fully qualified path to specify the expected types
|
LL | <u16 as Foo<I>>::foo(0u16, b);
| +++++++++++++++++++++ ~
| ^^^

error: aborting due to 2 previous errors
error: aborting due to previous error

Some errors have detailed explanations: E0283, E0284.
For more information about an error, try `rustc --explain E0283`.
For more information about this error, try `rustc --explain E0308`.
22 changes: 14 additions & 8 deletions src/test/ui/partialeq_help.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ LL | a == b;
| ^^ no implementation for `&T == T`
|
= help: the trait `PartialEq<T>` is not implemented for `&T`
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
LL | fn foo<T: PartialEq>(a: &T, b: T) where &T: PartialEq<T> {
| ++++++++++++++++++++++
= help: the following other types implement trait `PartialEq<Rhs>`:
<&A as PartialEq<&B>>
<&A as PartialEq<&mut B>>
<&mut A as PartialEq<&B>>
<&mut A as PartialEq<&mut B>>
<*const T as PartialEq>
<*mut T as PartialEq>

error[E0277]: can't compare `&T` with `T`
--> $DIR/partialeq_help.rs:6:7
Expand All @@ -17,10 +20,13 @@ LL | a == b;
| ^^ no implementation for `&T == T`
|
= help: the trait `PartialEq<T>` is not implemented for `&T`
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
|
LL | fn foo2<T: PartialEq>(a: &T, b: T) where &T: PartialEq<T> {
| ++++++++++++++++
= help: the following other types implement trait `PartialEq<Rhs>`:
<&A as PartialEq<&B>>
<&A as PartialEq<&mut B>>
<&mut A as PartialEq<&B>>
<&mut A as PartialEq<&mut B>>
<*const T as PartialEq>
<*mut T as PartialEq>

error: aborting due to 2 previous errors

Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/specialization/issue-45814.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//~ ERROR overflow evaluating the requirement `T: Trait<_>`

#![feature(specialization)]
#![allow(incomplete_features)]

Expand All @@ -8,5 +6,6 @@ pub trait Trait<T> {}
default impl<T, U> Trait<T> for U {}

impl<T> Trait<<T as Iterator>::Item> for T {}
//~^ ERROR conflicting implementations of trait `Trait<_>`

fn main() {}
16 changes: 7 additions & 9 deletions src/test/ui/specialization/issue-45814.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
error[E0275]: overflow evaluating the requirement `T: Trait<_>`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_45814`)
note: required for `T` to implement `Trait<_>`
--> $DIR/issue-45814.rs:8:20
error[E0119]: conflicting implementations of trait `Trait<_>`
--> $DIR/issue-45814.rs:8:1
|
LL | default impl<T, U> Trait<T> for U {}
| ^^^^^^^^ ^
= note: 128 redundant requirements hidden
= note: required for `T` to implement `Trait<_>`
| --------------------------------- first implementation here
LL |
LL | impl<T> Trait<<T as Iterator>::Item> for T {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

error: aborting due to previous error

For more information about this error, try `rustc --explain E0275`.
For more information about this error, try `rustc --explain E0119`.
2 changes: 1 addition & 1 deletion src/test/ui/traits/issue-18400.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ fn main() {
let bits: &[_] = &[0, 1];

0.contains(bits);
//~^ ERROR overflow
//~^ ERROR can't call method `contains` on ambiguous numeric type `{integer}
}
14 changes: 5 additions & 9 deletions src/test/ui/traits/issue-18400.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
error[E0275]: overflow evaluating the requirement `_: Sized`
error[E0689]: can't call method `contains` on ambiguous numeric type `{integer}`
--> $DIR/issue-18400.rs:24:7
|
LL | 0.contains(bits);
| ^^^^^^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_18400`)
note: required for `{integer}` to implement `Set<&[_]>`
--> $DIR/issue-18400.rs:6:16
help: you must specify a concrete type for this numeric value, like `i32`
|
LL | impl<'a, T, S> Set<&'a [T]> for S where
| ^^^^^^^^^^^^ ^
= note: 128 redundant requirements hidden
= note: required for `{integer}` to implement `Set<&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[&[_]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]>`
LL | 0_i32.contains(bits);
| ~~~~~

error: aborting due to previous error

For more information about this error, try `rustc --explain E0275`.
For more information about this error, try `rustc --explain E0689`.