Skip to content

Commit 04ea1e1

Browse files
Auto merge of #148477 - lqd:crater-wfcheck, r=<try>
crater: don't normalize where-clauses when checking well-formedness
2 parents 5dbf406 + 79b0a42 commit 04ea1e1

17 files changed

+126
-114
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,17 +1147,16 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuarant
11471147
///
11481148
/// Assuming the defaults are used, check that all predicates (bounds on the
11491149
/// assoc type and where clauses on the trait) hold.
1150-
fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocItem, span: Span) {
1150+
fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocItem, _span: Span) {
11511151
let bounds = wfcx.tcx().explicit_item_bounds(item.def_id);
11521152

11531153
debug!("check_associated_type_bounds: bounds={:?}", bounds);
11541154
let wf_obligations = bounds.iter_identity_copied().flat_map(|(bound, bound_span)| {
1155-
let normalized_bound = wfcx.normalize(span, None, bound);
11561155
traits::wf::clause_obligations(
11571156
wfcx.infcx,
11581157
wfcx.param_env,
11591158
wfcx.body_def_id,
1160-
normalized_bound,
1159+
bound,
11611160
bound_span,
11621161
)
11631162
});
@@ -1518,7 +1517,6 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id:
15181517

15191518
assert_eq!(predicates.predicates.len(), predicates.spans.len());
15201519
let wf_obligations = predicates.into_iter().flat_map(|(p, sp)| {
1521-
let p = wfcx.normalize(sp, None, p);
15221520
traits::wf::clause_obligations(infcx, wfcx.param_env, wfcx.body_def_id, p, sp)
15231521
});
15241522
let obligations: Vec<_> = wf_obligations.chain(default_obligations).collect();

tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ fn take(
2121
K = { () }
2222
>,
2323
) {}
24-
//~^^^^^ ERROR implementation of `Project` is not general enough
25-
//~^^^^ ERROR higher-ranked subtype error
24+
//~^^^ ERROR higher-ranked subtype error
2625
//~| ERROR higher-ranked subtype error
2726

2827
trait Project { type Out; }

tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,5 @@ LL | K = { () }
1212
|
1313
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1414

15-
error: implementation of `Project` is not general enough
16-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:19:13
17-
|
18-
LL | _: impl Trait<
19-
| _____________^
20-
LL | | <<for<'a> fn(&'a str) -> &'a str as Project>::Out as Discard>::Out,
21-
LL | | K = { () }
22-
LL | | >,
23-
| |_____^ implementation of `Project` is not general enough
24-
|
25-
= note: `Project` would have to be implemented for the type `for<'a> fn(&'a str) -> &'a str`
26-
= note: ...but `Project` is actually implemented for the type `fn(&'0 str) -> &'0 str`, for some specific lifetime `'0`
27-
28-
error: aborting due to 3 previous errors
15+
error: aborting due to 2 previous errors
2916

tests/ui/associated-types/issue-38821.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ pub trait Column: Expression {}
3232
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
3333
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
3434
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
35-
pub enum ColumnInsertValue<Col, Expr> where
36-
//~^ ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
37-
Col: Column,
38-
Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
39-
//~^ ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
4035
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
4136
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
4237
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
4338
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
4439
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
40+
pub enum ColumnInsertValue<Col, Expr> where
41+
//~^ ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
42+
Col: Column,
43+
Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
44+
//~^ ERROR the trait bound `<Col as Expression>::SqlType: IntoNullable` is not satisfied
4545
{
4646
Expression(Col, Expr),
4747
Default(Col),

tests/ui/associated-types/issue-38821.stderr

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
2-
--> $DIR/issue-38821.rs:35:1
2+
--> $DIR/issue-38821.rs:40:1
33
|
44
LL | pub enum ColumnInsertValue<Col, Expr> where
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
@@ -16,8 +16,8 @@ help: consider extending the `where` clause, but there might be an alternative b
1616
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull
1717
| +++++++++++++++++++++++++++++++++++++
1818

19-
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
20-
--> $DIR/issue-38821.rs:38:22
19+
error[E0277]: the trait bound `<Col as Expression>::SqlType: IntoNullable` is not satisfied
20+
--> $DIR/issue-38821.rs:43:22
2121
|
2222
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
@@ -82,10 +82,10 @@ LL | impl<T: NotNull> IntoNullable for T {
8282
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
8383

8484
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
85-
--> $DIR/issue-38821.rs:38:22
85+
--> $DIR/issue-38821.rs:23:10
8686
|
87-
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
88-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
87+
LL | #[derive(Debug, Copy, Clone)]
88+
| ^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
8989
|
9090
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
9191
--> $DIR/issue-38821.rs:9:18
@@ -94,6 +94,14 @@ LL | impl<T: NotNull> IntoNullable for T {
9494
| ------- ^^^^^^^^^^^^ ^
9595
| |
9696
| unsatisfied trait bound introduced here
97+
note: required for `ColumnInsertValue<Col, Expr>` to implement `Debug`
98+
--> $DIR/issue-38821.rs:23:10
99+
|
100+
LL | #[derive(Debug, Copy, Clone)]
101+
| ^^^^^
102+
...
103+
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
104+
| ------------------------------------------------ unsatisfied trait bound introduced in this `derive` macro
97105
help: consider further restricting the associated type
98106
|
99107
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
@@ -118,10 +126,10 @@ LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Co
118126
| +++++++++++++++++++++++++++++++++++++++
119127

120128
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
121-
--> $DIR/issue-38821.rs:38:22
129+
--> $DIR/issue-38821.rs:23:17
122130
|
123-
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
124-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
131+
LL | #[derive(Debug, Copy, Clone)]
132+
| ^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
125133
|
126134
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
127135
--> $DIR/issue-38821.rs:9:18
@@ -130,6 +138,14 @@ LL | impl<T: NotNull> IntoNullable for T {
130138
| ------- ^^^^^^^^^^^^ ^
131139
| |
132140
| unsatisfied trait bound introduced here
141+
note: required for `ColumnInsertValue<Col, Expr>` to implement `Copy`
142+
--> $DIR/issue-38821.rs:23:17
143+
|
144+
LL | #[derive(Debug, Copy, Clone)]
145+
| ^^^^
146+
...
147+
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
148+
| ------------------------------------------------ unsatisfied trait bound introduced in this `derive` macro
133149
help: consider further restricting the associated type
134150
|
135151
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
@@ -183,10 +199,10 @@ LL | impl<T: NotNull> IntoNullable for T {
183199
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
184200

185201
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
186-
--> $DIR/issue-38821.rs:38:22
202+
--> $DIR/issue-38821.rs:23:23
187203
|
188-
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
189-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
204+
LL | #[derive(Debug, Copy, Clone)]
205+
| ^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
190206
|
191207
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
192208
--> $DIR/issue-38821.rs:9:18
@@ -195,6 +211,14 @@ LL | impl<T: NotNull> IntoNullable for T {
195211
| ------- ^^^^^^^^^^^^ ^
196212
| |
197213
| unsatisfied trait bound introduced here
214+
note: required for `ColumnInsertValue<Col, Expr>` to implement `Clone`
215+
--> $DIR/issue-38821.rs:23:23
216+
|
217+
LL | #[derive(Debug, Copy, Clone)]
218+
| ^^^^^
219+
...
220+
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
221+
| ------------------------------------------------ unsatisfied trait bound introduced in this `derive` macro
198222
help: consider further restricting the associated type
199223
|
200224
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
@@ -216,10 +240,10 @@ LL | impl<T: NotNull> IntoNullable for T {
216240
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
217241

218242
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
219-
--> $DIR/issue-38821.rs:38:22
243+
--> $DIR/issue-38821.rs:23:10
220244
|
221-
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
222-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
245+
LL | #[derive(Debug, Copy, Clone)]
246+
| ^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
223247
|
224248
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
225249
--> $DIR/issue-38821.rs:9:18
@@ -245,10 +269,10 @@ LL | impl<T: NotNull> IntoNullable for T {
245269
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
246270

247271
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
248-
--> $DIR/issue-38821.rs:38:22
272+
--> $DIR/issue-38821.rs:23:23
249273
|
250-
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
251-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
274+
LL | #[derive(Debug, Copy, Clone)]
275+
| ^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
252276
|
253277
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
254278
--> $DIR/issue-38821.rs:9:18
@@ -257,7 +281,6 @@ LL | impl<T: NotNull> IntoNullable for T {
257281
| ------- ^^^^^^^^^^^^ ^
258282
| |
259283
| unsatisfied trait bound introduced here
260-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
261284

262285
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
263286
--> $DIR/issue-38821.rs:23:10

tests/ui/impl-trait/in-trait/refine-resolution-errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ impl<T: ?Sized> Mirror for () {
1414

1515
pub trait First {
1616
async fn first() -> <() as Mirror>::Assoc;
17+
//~^ ERROR type annotations needed
1718
}
1819

1920
impl First for () {

tests/ui/impl-trait/in-trait/refine-resolution-errors.stderr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ help: consider relaxing the implicit `Sized` restriction
2828
LL | type Assoc: ?Sized;
2929
| ++++++++
3030

31-
error: aborting due to 2 previous errors
31+
error[E0282]: type annotations needed
32+
--> $DIR/refine-resolution-errors.rs:16:5
33+
|
34+
LL | async fn first() -> <() as Mirror>::Assoc;
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
36+
37+
error: aborting due to 3 previous errors
3238

33-
Some errors have detailed explanations: E0207, E0277.
39+
Some errors have detailed explanations: E0207, E0277, E0282.
3440
For more information about an error, try `rustc --explain E0207`.

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ async fn wrapper<F>(f: F)
1010
where
1111
F:,
1212
for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
13-
//~^ ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
14-
//~| ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
15-
//~| ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
1613
{
1714
//~^ ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
1815
let mut i = 41;

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

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,6 @@ LL | | for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a
99
|
1010
= help: the trait `for<'a> FnOnce(&'a mut i32)` is not implemented for `i32`
1111

12-
error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `i32`
13-
--> $DIR/issue-76168-hr-outlives-3.rs:12:50
14-
|
15-
LL | for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
16-
| ^^^^^^^^^^^^^^^^^^^ expected an `FnOnce(&'a mut i32)` closure, found `i32`
17-
|
18-
= help: the trait `for<'a> FnOnce(&'a mut i32)` is not implemented for `i32`
19-
20-
error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `i32`
21-
--> $DIR/issue-76168-hr-outlives-3.rs:12:57
22-
|
23-
LL | for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
24-
| ^^^^^^^^^^^ expected an `FnOnce(&'a mut i32)` closure, found `i32`
25-
|
26-
= help: the trait `for<'a> FnOnce(&'a mut i32)` is not implemented for `i32`
27-
28-
error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `i32`
29-
--> $DIR/issue-76168-hr-outlives-3.rs:12:72
30-
|
31-
LL | for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
32-
| ^^ expected an `FnOnce(&'a mut i32)` closure, found `i32`
33-
|
34-
= help: the trait `for<'a> FnOnce(&'a mut i32)` is not implemented for `i32`
35-
3612
error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `i32`
3713
--> $DIR/issue-76168-hr-outlives-3.rs:6:1
3814
|
@@ -57,7 +33,7 @@ LL | | for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a
5733
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
5834

5935
error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `i32`
60-
--> $DIR/issue-76168-hr-outlives-3.rs:16:1
36+
--> $DIR/issue-76168-hr-outlives-3.rs:13:1
6137
|
6238
LL | / {
6339
LL | |
@@ -68,6 +44,6 @@ LL | | }
6844
|
6945
= help: the trait `for<'a> FnOnce(&'a mut i32)` is not implemented for `i32`
7046

71-
error: aborting due to 7 previous errors
47+
error: aborting due to 4 previous errors
7248

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

tests/ui/methods/filter-relevant-fn-bounds.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ impl Wrapper {
99
//~^ ERROR the trait bound `for<'a> F: Output<'a>` is not satisfied
1010
where
1111
F: for<'a> FnOnce(<F as Output<'a>>::Type),
12-
//~^ ERROR the trait bound `for<'a> F: Output<'a>` is not satisfied
13-
//~| ERROR the trait bound `for<'a> F: Output<'a>` is not satisfied
1412
{
1513
}
1614
}

0 commit comments

Comments
 (0)