Skip to content

Commit 44e31de

Browse files
committed
Auto merge of rust-lang#139763 - compiler-errors:rigid-proj-in-old-solver, r=<try>
[Experiment] Check that corresponding trait goal holds when projection is rigid r? `@ghost`
2 parents 092a284 + cd4572a commit 44e31de

10 files changed

+1165
-16
lines changed

Diff for: compiler/rustc_trait_selection/src/traits/project.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,12 @@ pub(super) fn opt_normalize_projection_term<'a, 'b, 'tcx>(
415415
let result =
416416
Normalized { value: projected_ty, obligations: PredicateObligations::new() };
417417
infcx.inner.borrow_mut().projection_cache().insert_term(cache_key, result.clone());
418-
// No need to extend `obligations`.
418+
obligations.push(Obligation::new(
419+
infcx.tcx,
420+
cause,
421+
param_env,
422+
projection_term.trait_ref(infcx.tcx),
423+
));
419424
Ok(Some(result.value))
420425
}
421426
Err(ProjectionError::TooManyCandidates) => {

Diff for: tests/ui/associated-types/hr-associated-type-bound-1.stderr

+158-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
error: implementation of `X` is not general enough
2+
|
3+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
4+
= note: ...but it actually implements `X<'a>`
5+
6+
error: implementation of `X` is not general enough
7+
|
8+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
9+
= note: ...but it actually implements `X<'a>`
10+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
11+
12+
error: implementation of `X` is not general enough
13+
--> $DIR/hr-associated-type-bound-1.rs:1:1
14+
|
15+
LL | / trait X<'a>
16+
LL | | where
17+
LL | | for<'b> <Self as X<'b>>::U: Clone,
18+
... |
19+
LL | | }
20+
| |_^ implementation of `X` is not general enough
21+
|
22+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
23+
= note: ...but it actually implements `X<'a>`
24+
25+
error: implementation of `X` is not general enough
26+
--> $DIR/hr-associated-type-bound-1.rs:1:1
27+
|
28+
LL | / trait X<'a>
29+
LL | | where
30+
LL | | for<'b> <Self as X<'b>>::U: Clone,
31+
... |
32+
LL | | }
33+
| |_^ implementation of `X` is not general enough
34+
|
35+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
36+
= note: ...but it actually implements `X<'a>`
37+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
38+
139
error[E0277]: the trait bound `str: Clone` is not satisfied
240
--> $DIR/hr-associated-type-bound-1.rs:12:14
341
|
@@ -14,6 +52,80 @@ LL | where
1452
LL | for<'b> <Self as X<'b>>::U: Clone,
1553
| ^^^^^ required by this bound in `X`
1654

55+
error: implementation of `X` is not general enough
56+
|
57+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
58+
= note: ...but it actually implements `X<'a>`
59+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
60+
61+
error: implementation of `X` is not general enough
62+
|
63+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
64+
= note: ...but it actually implements `X<'a>`
65+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
66+
67+
error[E0478]: lifetime bound not satisfied
68+
--> $DIR/hr-associated-type-bound-1.rs:6:5
69+
|
70+
LL | fn f(&self, x: &Self::U) {
71+
| ^^^^^^^^^^^^^^^^^^^^^^^^
72+
|
73+
note: lifetime parameter instantiated with the lifetime `'a` as defined here
74+
--> $DIR/hr-associated-type-bound-1.rs:1:9
75+
|
76+
LL | trait X<'a>
77+
| ^^
78+
79+
error[E0478]: lifetime bound not satisfied
80+
--> $DIR/hr-associated-type-bound-1.rs:6:5
81+
|
82+
LL | fn f(&self, x: &Self::U) {
83+
| ^^^^^^^^^^^^^^^^^^^^^^^^
84+
|
85+
note: but lifetime parameter must outlive the lifetime `'a` as defined here
86+
--> $DIR/hr-associated-type-bound-1.rs:1:9
87+
|
88+
LL | trait X<'a>
89+
| ^^
90+
91+
error: implementation of `X` is not general enough
92+
--> $DIR/hr-associated-type-bound-1.rs:6:8
93+
|
94+
LL | fn f(&self, x: &Self::U) {
95+
| ^ implementation of `X` is not general enough
96+
|
97+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
98+
= note: ...but it actually implements `X<'a>`
99+
100+
error: implementation of `X` is not general enough
101+
--> $DIR/hr-associated-type-bound-1.rs:6:8
102+
|
103+
LL | fn f(&self, x: &Self::U) {
104+
| ^ implementation of `X` is not general enough
105+
|
106+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
107+
= note: ...but it actually implements `X<'a>`
108+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
109+
110+
error: implementation of `X` is not general enough
111+
--> $DIR/hr-associated-type-bound-1.rs:6:20
112+
|
113+
LL | fn f(&self, x: &Self::U) {
114+
| ^^^^^^^^ implementation of `X` is not general enough
115+
|
116+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
117+
= note: ...but it actually implements `X<'a>`
118+
119+
error: implementation of `X` is not general enough
120+
--> $DIR/hr-associated-type-bound-1.rs:6:20
121+
|
122+
LL | fn f(&self, x: &Self::U) {
123+
| ^^^^^^^^ implementation of `X` is not general enough
124+
|
125+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
126+
= note: ...but it actually implements `X<'a>`
127+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
128+
17129
error[E0277]: the trait bound `str: Clone` is not satisfied
18130
--> $DIR/hr-associated-type-bound-1.rs:17:10
19131
|
@@ -30,6 +142,50 @@ LL | for<'b> <Self as X<'b>>::U: Clone,
30142
LL | fn f(&self, x: &Self::U) {
31143
| - required by a bound in this associated function
32144

33-
error: aborting due to 2 previous errors
145+
error: lifetime may not live long enough
146+
--> $DIR/hr-associated-type-bound-1.rs:6:5
147+
|
148+
LL | trait X<'a>
149+
| -- lifetime `'a` defined here
150+
...
151+
LL | fn f(&self, x: &Self::U) {
152+
| ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
153+
154+
error: higher-ranked subtype error
155+
--> $DIR/hr-associated-type-bound-1.rs:6:5
156+
|
157+
LL | fn f(&self, x: &Self::U) {
158+
| ^^^^^^^^^^^^^^^^^^^^^^^^
159+
160+
error: implementation of `X` is not general enough
161+
--> $DIR/hr-associated-type-bound-1.rs:7:9
162+
|
163+
LL | <Self::U>::clone(x);
164+
| ^^^^^^^^^^^^^^^^ implementation of `X` is not general enough
165+
|
166+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
167+
= note: ...but it actually implements `X<'1>`, for some specific lifetime `'1`
168+
169+
error: implementation of `X` is not general enough
170+
--> $DIR/hr-associated-type-bound-1.rs:7:9
171+
|
172+
LL | <Self::U>::clone(x);
173+
| ^^^^^^^^^^^^^^^^^^^ implementation of `X` is not general enough
174+
|
175+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
176+
= note: ...but it actually implements `X<'1>`, for some specific lifetime `'1`
177+
178+
error: implementation of `X` is not general enough
179+
--> $DIR/hr-associated-type-bound-1.rs:7:9
180+
|
181+
LL | <Self::U>::clone(x);
182+
| ^^^^^^^^^^^^^^^^^^^ implementation of `X` is not general enough
183+
|
184+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
185+
= note: ...but it actually implements `X<'1>`, for some specific lifetime `'1`
186+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
187+
188+
error: aborting due to 19 previous errors
34189

35-
For more information about this error, try `rustc --explain E0277`.
190+
Some errors have detailed explanations: E0277, E0478.
191+
For more information about an error, try `rustc --explain E0277`.

Diff for: tests/ui/associated-types/hr-associated-type-bound-2.stderr

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
error: implementation of `X` is not general enough
2+
|
3+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
4+
= note: ...but it actually implements `X<'a>`
5+
6+
error: implementation of `X` is not general enough
7+
|
8+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
9+
= note: ...but it actually implements `X<'a>`
10+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
11+
12+
error: implementation of `X` is not general enough
13+
--> $DIR/hr-associated-type-bound-2.rs:1:1
14+
|
15+
LL | / trait X<'a>
16+
LL | | where
17+
LL | | for<'b> <Self as X<'b>>::U: Clone,
18+
... |
19+
LL | | }
20+
| |_^ implementation of `X` is not general enough
21+
|
22+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
23+
= note: ...but it actually implements `X<'a>`
24+
25+
error: implementation of `X` is not general enough
26+
--> $DIR/hr-associated-type-bound-2.rs:1:1
27+
|
28+
LL | / trait X<'a>
29+
LL | | where
30+
LL | | for<'b> <Self as X<'b>>::U: Clone,
31+
... |
32+
LL | | }
33+
| |_^ implementation of `X` is not general enough
34+
|
35+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
36+
= note: ...but it actually implements `X<'a>`
37+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
38+
139
error[E0275]: overflow evaluating the requirement `for<'b> u32: X<'b>`
240
--> $DIR/hr-associated-type-bound-2.rs:11:1
341
|
@@ -18,6 +56,6 @@ LL | for<'b> <Self as X<'b>>::U: Clone,
1856
= note: 128 redundant requirements hidden
1957
= note: required for `u32` to implement `for<'b> X<'b>`
2058

21-
error: aborting due to 1 previous error
59+
error: aborting due to 5 previous errors
2260

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

Diff for: tests/ui/associated-types/hr-associated-type-bound-object.stderr

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
error: implementation of `X` is not general enough
2+
|
3+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
4+
= note: ...but it actually implements `X<'a>`
5+
6+
error: implementation of `X` is not general enough
7+
|
8+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
9+
= note: ...but it actually implements `X<'a>`
10+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
11+
12+
error: implementation of `X` is not general enough
13+
--> $DIR/hr-associated-type-bound-object.rs:1:1
14+
|
15+
LL | / trait X<'a>
16+
LL | | where
17+
LL | | for<'b> <Self as X<'b>>::U: Clone,
18+
... |
19+
LL | | }
20+
| |_^ implementation of `X` is not general enough
21+
|
22+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
23+
= note: ...but it actually implements `X<'a>`
24+
25+
error: implementation of `X` is not general enough
26+
--> $DIR/hr-associated-type-bound-object.rs:1:1
27+
|
28+
LL | / trait X<'a>
29+
LL | | where
30+
LL | | for<'b> <Self as X<'b>>::U: Clone,
31+
... |
32+
LL | | }
33+
| |_^ implementation of `X` is not general enough
34+
|
35+
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
36+
= note: ...but it actually implements `X<'a>`
37+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
38+
139
error[E0277]: the trait bound `for<'b> <T as X<'b>>::U: Clone` is not satisfied
240
--> $DIR/hr-associated-type-bound-object.rs:7:13
341
|
@@ -85,6 +123,6 @@ help: consider further restricting the associated type
85123
LL | fn f<'a, T: X<'a> + ?Sized>(x: &<T as X<'a>>::U) where for<'b> <T as X<'b>>::U: Clone {
86124
| ++++++++++++++++++++++++++++++++++++
87125

88-
error: aborting due to 5 previous errors
126+
error: aborting due to 9 previous errors
89127

90128
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)