Skip to content

Commit 6aa3732

Browse files
committed
trait_sel: no norm of preds of projections
So that some of the previous tests start passing again, it required removing normalisation of the predicates of projections when confirming projection candidates. This permits more uses of GATs and changes the output of yet more tests.
1 parent 03e0fda commit 6aa3732

File tree

9 files changed

+76
-108
lines changed

9 files changed

+76
-108
lines changed

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
144144
obligation: &PolyTraitObligation<'tcx>,
145145
idx: usize,
146146
) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
147-
let tcx = self.tcx();
148-
149147
let placeholder_trait_predicate =
150148
self.infcx.enter_forall_and_leak_universe(obligation.predicate).trait_ref;
151149
let placeholder_self_ty = self.infcx.shallow_resolve(placeholder_trait_predicate.self_ty());
@@ -194,28 +192,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
194192
.map_err(|_| SelectionError::Unimplemented)?,
195193
);
196194

197-
// FIXME(compiler-errors): I don't think this is needed.
198-
if let ty::Alias(ty::Projection, alias_ty) = placeholder_self_ty.kind() {
199-
let predicates = tcx.predicates_of(alias_ty.def_id).instantiate_own(tcx, alias_ty.args);
200-
for (predicate, _) in predicates {
201-
let normalized = normalize_with_depth_to(
202-
self,
203-
obligation.param_env,
204-
obligation.cause.clone(),
205-
obligation.recursion_depth + 1,
206-
predicate,
207-
&mut obligations,
208-
);
209-
obligations.push(Obligation::with_depth(
210-
self.tcx(),
211-
obligation.cause.clone(),
212-
obligation.recursion_depth + 1,
213-
obligation.param_env,
214-
normalized,
215-
));
216-
}
217-
}
218-
219195
Ok(obligations)
220196
}
221197

tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ trait Bop {
99

1010
fn bop<T: Bop + ?Sized>() {
1111
let _ = <T as Bop>::Bar::default();
12-
//~^ ERROR: trait bounds were not satisfied
12+
//~^ ERROR: the size for values of type `T` cannot be known at compilation time
13+
//~| ERROR: the size for values of type `T` cannot be known at compilation time
1314
//~| ERROR: the size for values of type `T` cannot be known at compilation time
1415
}
1516

tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.stderr

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,58 @@ help: consider relaxing the implicit `Sized` restriction
2424
LL | type Bar: Default + ?Sized
2525
| ++++++++
2626

27-
error[E0599]: the function or associated item `default` exists for associated type `<T as Bop>::Bar`, but its trait bounds were not satisfied
28-
--> $DIR/assoc_type_bounds_sized_used.rs:11:30
27+
error[E0277]: the size for values of type `T` cannot be known at compilation time
28+
--> $DIR/assoc_type_bounds_sized_used.rs:11:13
2929
|
30+
LL | fn bop<T: Bop + ?Sized>() {
31+
| - this type parameter needs to be `Sized`
3032
LL | let _ = <T as Bop>::Bar::default();
31-
| ^^^^^^^ function or associated item cannot be called on `<T as Bop>::Bar` due to unsatisfied trait bounds
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
34+
|
35+
note: required by a bound in `Bop::Bar`
36+
--> $DIR/assoc_type_bounds_sized_used.rs:7:15
37+
|
38+
LL | type Bar: Default
39+
| --- required by a bound in this associated type
40+
LL | where
41+
LL | Self: Sized;
42+
| ^^^^^ required by this bound in `Bop::Bar`
43+
help: consider removing the `?Sized` bound to make the type parameter `Sized`
44+
|
45+
LL - fn bop<T: Bop + ?Sized>() {
46+
LL + fn bop<T: Bop>() {
3247
|
33-
= note: the following trait bounds were not satisfied:
34-
`T: Sized`
35-
which is required by `<T as Bop>::Bar: Default`
36-
help: consider restricting the type parameter to satisfy the trait bound
48+
help: consider relaxing the implicit `Sized` restriction
49+
|
50+
LL | type Bar: Default + ?Sized
51+
| ++++++++
52+
53+
error[E0277]: the size for values of type `T` cannot be known at compilation time
54+
--> $DIR/assoc_type_bounds_sized_used.rs:11:13
3755
|
38-
LL | fn bop<T: Bop + ?Sized>() where T: Sized {
39-
| ++++++++++++++
56+
LL | fn bop<T: Bop + ?Sized>() {
57+
| - this type parameter needs to be `Sized`
58+
LL | let _ = <T as Bop>::Bar::default();
59+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
60+
|
61+
note: required by a bound in `Bop::Bar`
62+
--> $DIR/assoc_type_bounds_sized_used.rs:7:15
63+
|
64+
LL | type Bar: Default
65+
| --- required by a bound in this associated type
66+
LL | where
67+
LL | Self: Sized;
68+
| ^^^^^ required by this bound in `Bop::Bar`
69+
help: consider removing the `?Sized` bound to make the type parameter `Sized`
70+
|
71+
LL - fn bop<T: Bop + ?Sized>() {
72+
LL + fn bop<T: Bop>() {
73+
|
74+
help: consider relaxing the implicit `Sized` restriction
75+
|
76+
LL | type Bar: Default + ?Sized
77+
| ++++++++
4078

41-
error: aborting due to 2 previous errors
79+
error: aborting due to 3 previous errors
4280

43-
Some errors have detailed explanations: E0277, E0599.
44-
For more information about an error, try `rustc --explain E0277`.
81+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
error: lifetime bound not satisfied
2-
--> $DIR/issue-100013.rs:15:5
3-
|
4-
LL | / async { // a coroutine checked for autotrait impl `Send`
5-
LL | | let x = None::<I::Future<'_, '_>>; // a type referencing GAT
6-
LL | | async {}.await; // a yield point
7-
LL | | }
8-
| |_____^
9-
|
10-
= note: this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)
11-
12-
error: lifetime bound not satisfied
13-
--> $DIR/issue-100013.rs:22:5
14-
|
15-
LL | / async { // a coroutine checked for autotrait impl `Send`
16-
LL | | let x = None::<I::Future<'a, 'b>>; // a type referencing GAT
17-
LL | | async {}.await; // a yield point
18-
LL | | }
19-
| |_____^
20-
|
21-
= note: this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)
22-
231
error: lifetime may not live long enough
242
--> $DIR/issue-100013.rs:23:17
253
|
@@ -33,16 +11,5 @@ LL | let x = None::<I::Future<'a, 'b>>; // a type referencing GAT
3311
|
3412
= help: consider adding the following bound: `'a: 'b`
3513

36-
error: lifetime bound not satisfied
37-
--> $DIR/issue-100013.rs:29:5
38-
|
39-
LL | / async { // a coroutine checked for autotrait impl `Send`
40-
LL | | let x = None::<I::Future<'a, 'b>>; // a type referencing GAT
41-
LL | | async {}.await; // a yield point
42-
LL | | }
43-
| |_____^
44-
|
45-
= note: this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)
46-
47-
error: aborting due to 4 previous errors
14+
error: aborting due to 1 previous error
4815

tests/ui/generic-associated-types/issue-92096.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ check-pass
12
//@ edition:2018
23

34
use std::future::Future;
@@ -15,14 +16,6 @@ where
1516
C: Client + Send + Sync,
1617
{
1718
async move { c.connect().await }
18-
//~^ ERROR `C` does not live long enough
19-
//
20-
// FIXME(#71723). This is because we infer at some point a value of
21-
//
22-
// impl Future<Output = <C as Client>::Connection<'_>>
23-
//
24-
// and then we somehow fail the WF check because `where C: 'a` is not known,
25-
// but I'm not entirely sure how that comes about.
2619
}
2720

2821
fn main() {}

tests/ui/generic-associated-types/issue-92096.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/ui/generic-associated-types/issue-93262.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ check-fail
1+
//@ check-pass
22

33
pub trait Trait {
44
type Assoc<'a> where Self: 'a;
@@ -11,7 +11,7 @@ where
1111

1212
pub struct Type;
1313

14-
impl<T: Trait> Foo<T> for Type //~ ERROR: the parameter type `T` may not live long enough
14+
impl<T: Trait> Foo<T> for Type
1515
where
1616
for<'a> T::Assoc<'a>: Clone
1717
{}

tests/ui/generic-associated-types/issue-93262.stderr

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ check-pass
2+
//@ compile-flags: --crate-type=lib
3+
//@ revisions: old next
4+
//@[next] compile-flags: -Znext-solver
5+
6+
use std::marker::PhantomData;
7+
8+
pub trait ZeroMapKV<'a> {
9+
type Container;
10+
}
11+
12+
pub trait ZeroFrom<'zf, C: ?Sized> {}
13+
14+
pub struct ZeroMap<'a, K: ZeroMapKV<'a>>(PhantomData<&'a K>);
15+
16+
impl<'zf, 's, K> ZeroFrom<'zf, ZeroMap<'s, K>> for ZeroMap<'zf, K>
17+
where
18+
K: for<'b> ZeroMapKV<'b>,
19+
<K as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <K as ZeroMapKV<'s>>::Container>,
20+
{
21+
}

0 commit comments

Comments
 (0)