Skip to content

Commit f72f5d8

Browse files
Enforce nominal obligations for RPIT too
1 parent 558cfd2 commit f72f5d8

File tree

7 files changed

+85
-13
lines changed

7 files changed

+85
-13
lines changed

compiler/rustc_trait_selection/src/traits/wf.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -792,13 +792,8 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
792792
}
793793

794794
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
795-
// All of the requirements on type parameters
796-
// have already been checked for `impl Trait` in
797-
// return position. We do need to check type-alias-impl-trait though.
798-
if self.tcx().is_type_alias_impl_trait(def_id) {
799-
let obligations = self.nominal_obligations(def_id, args);
800-
self.out.extend(obligations);
801-
}
795+
let obligations = self.nominal_obligations(def_id, args);
796+
self.out.extend(obligations);
802797
}
803798

804799
ty::Alias(ty::Weak, ty::AliasTy { def_id, args, .. }) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ check-pass
2+
3+
#![allow(unconditional_recursion)]
4+
5+
fn test<'a>() -> impl Sized + 'a {
6+
let _: () = test::<'a>();
7+
}
8+
9+
fn main() {}

tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ impl Foo<char> for Bar {
99
//~^ ERROR: the trait bound `impl Foo<u8>: Foo<char>` is not satisfied [E0277]
1010
//~| ERROR: the trait bound `Bar: Foo<u8>` is not satisfied [E0277]
1111
//~| ERROR: impl has stricter requirements than trait
12+
//~| ERROR: the trait bound `F2: Foo<u8>` is not satisfied
1213
self
1314
}
1415
}

tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr

+17-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ note: required by a bound in `Foo::{synthetic#0}`
1111
LL | fn foo<F2>(self) -> impl Foo<T>;
1212
| ^^^^^^ required by this bound in `Foo::{synthetic#0}`
1313

14+
error[E0277]: the trait bound `F2: Foo<u8>` is not satisfied
15+
--> $DIR/return-dont-satisfy-bounds.rs:8:34
16+
|
17+
LL | fn foo<F2: Foo<u8>>(self) -> impl Foo<u8> {
18+
| ^^^^^^^^^^^^ the trait `Foo<u8>` is not implemented for `F2`
19+
|
20+
note: required by a bound in `<Bar as Foo<char>>::foo`
21+
--> $DIR/return-dont-satisfy-bounds.rs:8:16
22+
|
23+
LL | fn foo<F2: Foo<u8>>(self) -> impl Foo<u8> {
24+
| ^^^^^^^ required by this bound in `<Bar as Foo<char>>::foo`
25+
help: consider further restricting this bound
26+
|
27+
LL | fn foo<F2: Foo<u8> + Foo<u8>>(self) -> impl Foo<u8> {
28+
| +++++++++
29+
1430
error[E0276]: impl has stricter requirements than trait
1531
--> $DIR/return-dont-satisfy-bounds.rs:8:16
1632
|
@@ -32,7 +48,7 @@ LL | self
3248
= help: the trait `Foo<char>` is implemented for `Bar`
3349
= help: for that trait implementation, expected `char`, found `u8`
3450

35-
error: aborting due to 3 previous errors
51+
error: aborting due to 4 previous errors
3652

3753
Some errors have detailed explanations: E0276, E0277.
3854
For more information about an error, try `rustc --explain E0276`.

tests/ui/lifetimes/issue-76168-hr-outlives-3.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ async fn wrapper<F>(f: F)
77
//~^ ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
88
//~| ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
99
//~| ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
10+
//~| ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
1011
where
1112
F:,
1213
for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,

tests/ui/lifetimes/issue-76168-hr-outlives-3.stderr

+19-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | / async fn wrapper<F>(f: F)
55
LL | |
66
LL | |
77
LL | |
8-
LL | | where
8+
... |
99
LL | | F:,
1010
LL | | for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
1111
| |__________________________________________________________________________^ expected an `FnOnce(&'a mut i32)` closure, found `i32`
@@ -27,15 +27,30 @@ LL | / async fn wrapper<F>(f: F)
2727
LL | |
2828
LL | |
2929
LL | |
30-
LL | | where
30+
... |
3131
LL | | F:,
3232
LL | | for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
3333
| |__________________________________________________________________________^ expected an `FnOnce(&'a mut i32)` closure, found `i32`
3434
|
3535
= help: the trait `for<'a> FnOnce<(&'a mut i32,)>` is not implemented for `i32`
3636

3737
error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `i32`
38-
--> $DIR/issue-76168-hr-outlives-3.rs:13:1
38+
--> $DIR/issue-76168-hr-outlives-3.rs:6:1
39+
|
40+
LL | / async fn wrapper<F>(f: F)
41+
LL | |
42+
LL | |
43+
LL | |
44+
... |
45+
LL | | F:,
46+
LL | | for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
47+
| |__________________________________________________________________________^ expected an `FnOnce(&'a mut i32)` closure, found `i32`
48+
|
49+
= help: the trait `for<'a> FnOnce<(&'a mut i32,)>` is not implemented for `i32`
50+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
51+
52+
error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `i32`
53+
--> $DIR/issue-76168-hr-outlives-3.rs:14:1
3954
|
4055
LL | / {
4156
LL | |
@@ -46,6 +61,6 @@ LL | | }
4661
|
4762
= help: the trait `for<'a> FnOnce<(&'a mut i32,)>` is not implemented for `i32`
4863

49-
error: aborting due to 4 previous errors
64+
error: aborting due to 5 previous errors
5065

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

tests/ui/traits/non_lifetime_binders/type-match-with-late-bound.stderr

+36-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ LL | #![feature(non_lifetime_binders)]
77
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
88
= note: `#[warn(incomplete_features)]` on by default
99

10+
error[E0309]: the placeholder type `!1_"F"` may not live long enough
11+
--> $DIR/type-match-with-late-bound.rs:8:1
12+
|
13+
LL | async fn walk2<'a, T: 'a>(_: T)
14+
| ^ -- the placeholder type `!1_"F"` must be valid for the lifetime `'a` as defined here...
15+
| _|
16+
| |
17+
LL | | where
18+
LL | | for<F> F: 'a,
19+
| |_________________^ ...so that the type `F` will meet its required lifetime bounds...
20+
|
21+
note: ...that is required by this bound
22+
--> $DIR/type-match-with-late-bound.rs:10:15
23+
|
24+
LL | for<F> F: 'a,
25+
| ^^
26+
help: consider adding an explicit lifetime bound
27+
|
28+
LL | for<F> F: 'a, !1_"F": 'a
29+
| ~~~~~~~~~~~~
30+
1031
error[E0309]: the placeholder type `!1_"F"` may not live long enough
1132
--> $DIR/type-match-with-late-bound.rs:11:1
1233
|
@@ -35,6 +56,20 @@ help: consider adding an explicit lifetime bound
3556
LL | for<F> F: 'a, !2_"F": 'a
3657
| ~~~~~~~~~~~~
3758

38-
error: aborting due to 2 previous errors; 1 warning emitted
59+
error[E0309]: the placeholder type `!3_"F"` may not live long enough
60+
--> $DIR/type-match-with-late-bound.rs:11:1
61+
|
62+
LL | async fn walk2<'a, T: 'a>(_: T)
63+
| -- the placeholder type `!3_"F"` must be valid for the lifetime `'a` as defined here...
64+
...
65+
LL | {}
66+
| ^^ ...so that the type `F` will meet its required lifetime bounds
67+
|
68+
help: consider adding an explicit lifetime bound
69+
|
70+
LL | for<F> F: 'a, !3_"F": 'a
71+
| ~~~~~~~~~~~~
72+
73+
error: aborting due to 4 previous errors; 1 warning emitted
3974

4075
For more information about this error, try `rustc --explain E0309`.

0 commit comments

Comments
 (0)