Skip to content

Commit b28b235

Browse files
committed
evaluation cache, freshen each predicate by itself
1 parent 1536ab1 commit b28b235

File tree

10 files changed

+50
-88
lines changed

10 files changed

+50
-88
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use super::{
1919
SelectionResult, TraitObligation, TraitQueryMode,
2020
};
2121

22-
use crate::infer::{InferCtxt, InferOk, TypeFreshener};
22+
use crate::infer::{InferCtxt, InferOk};
2323
use crate::traits::error_reporting::TypeErrCtxtExt;
2424
use crate::traits::project::ProjectAndUnifyResult;
2525
use crate::traits::project::ProjectionCacheKeyExt;
@@ -95,13 +95,6 @@ impl IntercrateAmbiguityCause {
9595
pub struct SelectionContext<'cx, 'tcx> {
9696
infcx: &'cx InferCtxt<'tcx>,
9797

98-
/// Freshener used specifically for entries on the obligation
99-
/// stack. This ensures that all entries on the stack at one time
100-
/// will have the same set of placeholder entries, which is
101-
/// important for checking for trait bounds that recursively
102-
/// require themselves.
103-
freshener: TypeFreshener<'cx, 'tcx>,
104-
10598
/// During coherence we have to assume that other crates may add
10699
/// additional impls which we currently don't know about.
107100
///
@@ -217,7 +210,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
217210
pub fn new(infcx: &'cx InferCtxt<'tcx>) -> SelectionContext<'cx, 'tcx> {
218211
SelectionContext {
219212
infcx,
220-
freshener: infcx.freshener_keep_static(),
221213
intercrate: false,
222214
intercrate_ambiguity_causes: None,
223215
query_mode: TraitQueryMode::Standard,
@@ -2251,7 +2243,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
22512243
previous_stack: TraitObligationStackList<'o, 'tcx>,
22522244
obligation: &'o TraitObligation<'tcx>,
22532245
) -> TraitObligationStack<'o, 'tcx> {
2254-
let fresh_trait_pred = obligation.predicate.fold_with(&mut self.freshener);
2246+
let fresh_trait_pred =
2247+
obligation.predicate.fold_with(&mut self.infcx.freshener_keep_static());
22552248

22562249
let dfn = previous_stack.cache.next_dfn();
22572250
let depth = previous_stack.depth() + 1;
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//~ ERROR overflow evaluating the requirement `T: Trait<_>`
2-
31
#![feature(specialization, with_negative_coherence)]
42
#![allow(incomplete_features)]
53

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

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

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

1210
error: aborting due to previous error
1311

14-
For more information about this error, try `rustc --explain E0275`.
12+
For more information about this error, try `rustc --explain E0119`.

src/test/ui/issues/issue-69683.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ where
2727
fn main() {
2828
let b: [u8; 3] = [0u8; 3];
2929

30-
0u16.foo(b); //~ ERROR type annotations needed
31-
//~^ ERROR type annotations needed
30+
0u16.foo(b); //~ ERROR mismatched types
3231
//<u16 as Foo<[(); 3]>>::foo(0u16, b);
3332
}

src/test/ui/issues/issue-69683.stderr

+10-36
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,17 @@
1-
error[E0284]: type annotations needed
2-
--> $DIR/issue-69683.rs:30:10
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-69683.rs:30:14
33
|
44
LL | 0u16.foo(b);
5-
| ^^^
5+
| --- ^ expected `u8`, found array `[u8; 3]`
6+
| |
7+
| arguments to this function are incorrect
68
|
7-
= note: cannot satisfy `<u8 as Element<_>>::Array == [u8; 3]`
8-
help: try using a fully qualified path to specify the expected types
9+
note: associated function defined here
10+
--> $DIR/issue-69683.rs:17:8
911
|
10-
LL | <u16 as Foo<I>>::foo(0u16, b);
11-
| +++++++++++++++++++++ ~
12-
13-
error[E0283]: type annotations needed
14-
--> $DIR/issue-69683.rs:30:10
15-
|
16-
LL | 0u16.foo(b);
17-
| ^^^
18-
|
19-
note: multiple `impl`s satisfying `u8: Element<_>` found
20-
--> $DIR/issue-69683.rs:5:1
21-
|
22-
LL | impl<T> Element<()> for T {
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
24-
...
25-
LL | impl<T: Element<S>, S> Element<[S; 3]> for T {
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27-
note: required by a bound in `Foo::foo`
28-
--> $DIR/issue-69683.rs:15:9
29-
|
30-
LL | u8: Element<I>,
31-
| ^^^^^^^^^^ required by this bound in `Foo::foo`
32-
LL | {
3312
LL | fn foo(self, x: <u8 as Element<I>>::Array);
34-
| --- required by a bound in this
35-
help: try using a fully qualified path to specify the expected types
36-
|
37-
LL | <u16 as Foo<I>>::foo(0u16, b);
38-
| +++++++++++++++++++++ ~
13+
| ^^^
3914

40-
error: aborting due to 2 previous errors
15+
error: aborting due to previous error
4116

42-
Some errors have detailed explanations: E0283, E0284.
43-
For more information about an error, try `rustc --explain E0283`.
17+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/partialeq_help.stderr

+14-8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ LL | a == b;
55
| ^^ no implementation for `&T == T`
66
|
77
= help: the trait `PartialEq<T>` is not implemented for `&T`
8-
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
9-
|
10-
LL | fn foo<T: PartialEq>(a: &T, b: T) where &T: PartialEq<T> {
11-
| ++++++++++++++++++++++
8+
= help: the following other types implement trait `PartialEq<Rhs>`:
9+
<&A as PartialEq<&B>>
10+
<&A as PartialEq<&mut B>>
11+
<&mut A as PartialEq<&B>>
12+
<&mut A as PartialEq<&mut B>>
13+
<*const T as PartialEq>
14+
<*mut T as PartialEq>
1215

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

2531
error: aborting due to 2 previous errors
2632

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//~ ERROR overflow evaluating the requirement `T: Trait<_>`
2-
31
#![feature(specialization)]
42
#![allow(incomplete_features)]
53

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

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

1211
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
error[E0275]: overflow evaluating the requirement `T: Trait<_>`
2-
|
3-
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_45814`)
4-
note: required for `T` to implement `Trait<_>`
5-
--> $DIR/issue-45814.rs:8:20
1+
error[E0119]: conflicting implementations of trait `Trait<_>`
2+
--> $DIR/issue-45814.rs:8:1
63
|
74
LL | default impl<T, U> Trait<T> for U {}
8-
| ^^^^^^^^ ^
9-
= note: 128 redundant requirements hidden
10-
= note: required for `T` to implement `Trait<_>`
5+
| --------------------------------- first implementation here
6+
LL |
7+
LL | impl<T> Trait<<T as Iterator>::Item> for T {}
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
119

1210
error: aborting due to previous error
1311

14-
For more information about this error, try `rustc --explain E0275`.
12+
For more information about this error, try `rustc --explain E0119`.

src/test/ui/traits/issue-18400.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ fn main() {
2222
let bits: &[_] = &[0, 1];
2323

2424
0.contains(bits);
25-
//~^ ERROR overflow
25+
//~^ ERROR can't call method `contains` on ambiguous numeric type `{integer}
2626
}

src/test/ui/traits/issue-18400.stderr

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

1612
error: aborting due to previous error
1713

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

0 commit comments

Comments
 (0)