Skip to content

Commit a5888a2

Browse files
committed
don't prove WC when projecting from param-env
If the param-env tells you that, forall 'a, `T::Item<'a> = u32`, we can believe it.
1 parent 7425fb2 commit a5888a2

25 files changed

+125
-260
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
19511951
match infcx.at(cause, param_env).eq(cache_projection, obligation_projection) {
19521952
Ok(InferOk { value: _, obligations }) => {
19531953
nested_obligations.extend(obligations);
1954-
assoc_ty_own_obligations(selcx, obligation, &mut nested_obligations);
1954+
// NDM assoc_ty_own_obligations(selcx, obligation, &mut nested_obligations);
19551955
// FIXME(associated_const_equality): Handle consts here as well? Maybe this progress type should just take
19561956
// a term instead.
19571957
Progress { term: cache_entry.term, obligations: nested_obligations }

compiler/rustc_typeck/src/check/compare_method.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,11 @@ fn compare_predicate_entailment<'tcx>(
222222
let impl_m_own_bounds = impl_m_predicates.instantiate_own(tcx, impl_to_placeholder_substs);
223223
for (predicate, span) in iter::zip(impl_m_own_bounds.predicates, impl_m_own_bounds.spans) {
224224
let normalize_cause = traits::ObligationCause::misc(span, impl_m_hir_id);
225+
debug!("predicate before normalization: {:?}", predicate);
225226
let traits::Normalized { value: predicate, obligations } =
226227
traits::normalize(&mut selcx, param_env, normalize_cause, predicate);
228+
debug!("predicate after normalization: {:?}", predicate);
229+
debug!("normalization obligations: {:#?}", obligations);
227230

228231
inh.register_predicates(obligations);
229232
let cause = ObligationCause::new(

src/test/ui/feature-gates/feature-gate-generic_associated_types.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ use std::ops::Deref;
33
trait PointerFamily<U> {
44
type Pointer<T>: Deref<Target = T>;
55
//~^ ERROR generic associated types are unstable
6-
type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
7-
//~^ ERROR generic associated types are unstable
6+
type Pointer2<T>: Deref<Target = T>
7+
where
8+
T: Clone,
9+
U: Clone;
10+
//~^^^^ ERROR generic associated types are unstable
811
//~| ERROR where clauses on associated types are unstable
912
}
1013

@@ -15,12 +18,13 @@ impl PointerFamily<u32> for Foo {
1518
//~^ ERROR generic associated types are unstable
1619
type Pointer2<U32> = Box<U32>;
1720
//~^ ERROR generic associated types are unstable
18-
//~| ERROR the trait bound `U32: Clone` is not satisfied
1921
}
2022

2123
trait Bar {
22-
type Assoc where Self: Sized;
23-
//~^ ERROR where clauses on associated types are unstable
24+
type Assoc
25+
where
26+
Self: Sized;
27+
//~^^^ ERROR where clauses on associated types are unstable
2428
}
2529

2630
impl Bar for Foo {

src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,29 @@ LL | type Pointer<T>: Deref<Target = T>;
1010
error[E0658]: generic associated types are unstable
1111
--> $DIR/feature-gate-generic_associated_types.rs:6:5
1212
|
13-
LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
LL | / type Pointer2<T>: Deref<Target = T>
14+
LL | | where
15+
LL | | T: Clone,
16+
LL | | U: Clone;
17+
| |_________________^
1518
|
1619
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
1720
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
1821

1922
error[E0658]: where clauses on associated types are unstable
2023
--> $DIR/feature-gate-generic_associated_types.rs:6:5
2124
|
22-
LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25+
LL | / type Pointer2<T>: Deref<Target = T>
26+
LL | | where
27+
LL | | T: Clone,
28+
LL | | U: Clone;
29+
| |_________________^
2430
|
2531
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
2632
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
2733

2834
error[E0658]: generic associated types are unstable
29-
--> $DIR/feature-gate-generic_associated_types.rs:14:5
35+
--> $DIR/feature-gate-generic_associated_types.rs:17:5
3036
|
3137
LL | type Pointer<Usize> = Box<Usize>;
3238
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -35,7 +41,7 @@ LL | type Pointer<Usize> = Box<Usize>;
3541
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
3642

3743
error[E0658]: generic associated types are unstable
38-
--> $DIR/feature-gate-generic_associated_types.rs:16:5
44+
--> $DIR/feature-gate-generic_associated_types.rs:19:5
3945
|
4046
LL | type Pointer2<U32> = Box<U32>;
4147
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -44,35 +50,25 @@ LL | type Pointer2<U32> = Box<U32>;
4450
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
4551

4652
error[E0658]: where clauses on associated types are unstable
47-
--> $DIR/feature-gate-generic_associated_types.rs:22:5
53+
--> $DIR/feature-gate-generic_associated_types.rs:24:5
4854
|
49-
LL | type Assoc where Self: Sized;
50-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55+
LL | / type Assoc
56+
LL | | where
57+
LL | | Self: Sized;
58+
| |____________________^
5159
|
5260
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
5361
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
5462

5563
error[E0658]: where clauses on associated types are unstable
56-
--> $DIR/feature-gate-generic_associated_types.rs:27:5
64+
--> $DIR/feature-gate-generic_associated_types.rs:31:5
5765
|
5866
LL | type Assoc = Foo where Self: Sized;
5967
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6068
|
6169
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
6270
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
6371

64-
error[E0277]: the trait bound `U32: Clone` is not satisfied
65-
--> $DIR/feature-gate-generic_associated_types.rs:16:26
66-
|
67-
LL | type Pointer2<U32> = Box<U32>;
68-
| ^^^^^^^^ the trait `Clone` is not implemented for `U32`
69-
|
70-
help: consider restricting type parameter `U32`
71-
|
72-
LL | type Pointer2<U32: std::clone::Clone> = Box<U32>;
73-
| +++++++++++++++++++
74-
75-
error: aborting due to 8 previous errors
72+
error: aborting due to 7 previous errors
7673

77-
Some errors have detailed explanations: E0277, E0658.
78-
For more information about an error, try `rustc --explain E0277`.
74+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/generic-associated-types/bugs/issue-87755.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
// check-fail
2-
// known-bug: #87755
3-
4-
// This should pass.
1+
// check-pass
52

63
#![feature(generic_associated_types)]
74

85
use std::fmt::Debug;
96

107
trait Foo {
11-
type Ass where Self::Ass: Debug;
8+
type Ass
9+
where
10+
Self::Ass: Debug;
1211
}
1312

1413
#[derive(Debug)]

src/test/ui/generic-associated-types/bugs/issue-87755.stderr

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

src/test/ui/generic-associated-types/collectivity-regression.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Regression test from https://github.com/rust-lang/rust/pull/98109
2+
//
3+
// check-pass
24

35
#![feature(generic_associated_types)]
46

@@ -13,10 +15,6 @@ where
1315
for<'a> T: Get<Value<'a> = ()>,
1416
{
1517
|| {
16-
//~^ `T` does not live long enough
17-
//
18-
// FIXME(#98437). This regressed at some point and
19-
// probably should work.
2018
let _x = x;
2119
};
2220
}

src/test/ui/generic-associated-types/collectivity-regression.stderr

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

src/test/ui/generic-associated-types/extended/lending_iterator.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
// revisions: base extended
2-
//[base] check-fail
3-
//[extended] check-pass
1+
// check-pass
42

53
#![feature(generic_associated_types)]
6-
#![cfg_attr(extended, feature(generic_associated_types_extended))]
7-
#![cfg_attr(extended, allow(incomplete_features))]
84

95
pub trait FromLendingIterator<A>: Sized {
106
fn from_iter<T: for<'x> LendingIterator<Item<'x> = A>>(iter: T) -> Self;
117
}
128

139
impl<A> FromLendingIterator<A> for Vec<A> {
1410
fn from_iter<I: for<'x> LendingIterator<Item<'x> = A>>(mut iter: I) -> Self {
15-
//[base]~^ impl has stricter
1611
let mut v = vec![];
1712
while let Some(item) = iter.next() {
1813
v.push(item);

src/test/ui/generic-associated-types/extended/lending_iterator_2.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
// revisions: base extended
2-
//[base] check-fail
3-
//[extended] check-pass
1+
// check-pass
42

53
#![feature(generic_associated_types)]
6-
#![cfg_attr(extended, feature(generic_associated_types_extended))]
7-
#![cfg_attr(extended, allow(incomplete_features))]
84

95
pub trait FromLendingIterator<A>: Sized {
106
fn from_iter<T: for<'x> LendingIterator<Item<'x> = A>>(iter: T) -> Self;
117
}
128

139
impl<A> FromLendingIterator<A> for Vec<A> {
1410
fn from_iter<I: for<'x> LendingIterator<Item<'x> = A>>(mut iter: I) -> Self {
15-
//[base]~^ impl has stricter
1611
let mut v = vec![];
1712
while let Some(item) = iter.next() {
1813
v.push(item);

src/test/ui/generic-associated-types/generic-associated-types-where.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
#![feature(generic_associated_types)]
2-
32
// Checking the interaction with this other feature
43
#![feature(associated_type_defaults)]
54

6-
use std::fmt::{Display, Debug};
5+
use std::fmt::{Debug, Display};
76

87
trait Foo {
9-
type Assoc where Self: Sized;
10-
type Assoc2<T> where T: Display;
8+
type Assoc
9+
where
10+
Self: Sized;
11+
type Assoc2<T>
12+
where
13+
T: Display;
1114
type Assoc3<T>;
12-
type WithDefault<'a, T: Debug + 'a>: ?Sized = dyn Iterator<Item=T>;
15+
type WithDefault<'a, T: Debug + 'a>: ?Sized = dyn Iterator<Item = T>;
1316
type NoGenerics;
1417
}
1518

@@ -18,10 +21,9 @@ struct Bar;
1821
impl Foo for Bar {
1922
type Assoc = usize;
2023
type Assoc2<T> = Vec<T>;
21-
//~^ ERROR `T` doesn't implement `std::fmt::Display`
2224
type Assoc3<T> = Vec<T> where T: Iterator;
2325
//~^ ERROR impl has stricter requirements than trait
24-
type WithDefault<'a, T: Debug + 'a> = &'a dyn Iterator<Item=T>;
26+
type WithDefault<'a, T: Debug + 'a> = &'a dyn Iterator<Item = T>;
2527
type NoGenerics = ::std::cell::Cell<i32>;
2628
}
2729

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1-
error[E0277]: `T` doesn't implement `std::fmt::Display`
2-
--> $DIR/generic-associated-types-where.rs:20:22
3-
|
4-
LL | type Assoc2<T> = Vec<T>;
5-
| ^^^^^^ `T` cannot be formatted with the default formatter
6-
|
7-
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
8-
help: consider restricting type parameter `T`
9-
|
10-
LL | type Assoc2<T: std::fmt::Display> = Vec<T>;
11-
| +++++++++++++++++++
12-
131
error[E0276]: impl has stricter requirements than trait
14-
--> $DIR/generic-associated-types-where.rs:22:5
2+
--> $DIR/generic-associated-types-where.rs:24:5
153
|
164
LL | type Assoc3<T>;
175
| --------------- definition of `Assoc3` from trait
186
...
197
LL | type Assoc3<T> = Vec<T> where T: Iterator;
208
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: Iterator`
219

22-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2311

24-
Some errors have detailed explanations: E0276, E0277.
25-
For more information about an error, try `rustc --explain E0276`.
12+
For more information about this error, try `rustc --explain E0276`.

src/test/ui/generic-associated-types/impl_bounds.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22
#![feature(associated_type_defaults)]
33

44
trait Foo {
5-
type A<'a> where Self: 'a;
6-
type B<'a, 'b> where 'a: 'b;
7-
type C where Self: Clone;
8-
fn d() where Self: Clone;
5+
type A<'a>
6+
where
7+
Self: 'a;
8+
type B<'a, 'b>
9+
where
10+
'a: 'b;
11+
type C
12+
where
13+
Self: Clone;
14+
fn d()
15+
where
16+
Self: Clone;
917
}
1018

1119
#[derive(Copy, Clone)]
@@ -16,11 +24,13 @@ impl<T> Foo for Fooy<T> {
1624
//~^ ERROR `impl` associated type
1725
type B<'a, 'b> = (&'a(), &'b ()) where 'b: 'a;
1826
//~^ ERROR `impl` associated type
19-
//~| ERROR lifetime bound not satisfied
2027
type C = String where Self: Copy;
2128
//~^ ERROR the trait bound `T: Copy` is not satisfied
22-
fn d() where Self: Copy {}
23-
//~^ ERROR the trait bound `T: Copy` is not satisfied
29+
fn d()
30+
where
31+
Self: Copy, //~ ERROR the trait bound `T: Copy` is not satisfied
32+
{
33+
}
2434
}
2535

2636
fn main() {}

0 commit comments

Comments
 (0)