Skip to content

Commit e7bbda2

Browse files
committed
deeply_normalize before checking trivial bounds
1 parent d0babd8 commit e7bbda2

64 files changed

Lines changed: 719 additions & 208 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_middle::mir::interpret::ErrorHandled;
2222
use rustc_middle::traits::solve::NoSolution;
2323
use rustc_middle::ty::trait_def::TraitSpecializationKind;
2424
use rustc_middle::ty::{
25-
self, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFlags, TypeFoldable,
25+
self, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFoldable,
2626
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Unnormalized,
2727
Upcast,
2828
};
@@ -2293,7 +2293,8 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
22932293
/// aren't true.
22942294
#[instrument(level = "debug", skip(self))]
22952295
fn check_false_global_bounds(&mut self) {
2296-
let tcx = self.ocx.infcx.tcx;
2296+
let infcx = self.ocx.infcx;
2297+
let tcx = infcx.tcx;
22972298
let mut span = tcx.def_span(self.body_def_id);
22982299
let empty_env = ty::ParamEnv::empty();
22992300

@@ -2312,10 +2313,8 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
23122313
_ => {}
23132314
}
23142315

2315-
// Match the existing behavior.
2316-
if pred.is_global() && !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) {
2317-
let pred = self.normalize(span, None, Unnormalized::new_wip(pred));
2318-
2316+
let pred = self.deeply_normalize(span, None, Unnormalized::new_wip(pred));
2317+
if pred.is_global() && pred.kind().bound_vars().is_empty() {
23192318
// only use the span of the predicate clause (#90869)
23202319
let hir_node = tcx.hir_node_by_def_id(self.body_def_id);
23212320
if let Some(hir::Generics { predicates, .. }) = hir_node.generics() {
@@ -2327,16 +2326,12 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
23272326
.unwrap_or(obligation_span);
23282327
}
23292328

2330-
let obligation = Obligation::new(
2331-
tcx,
2332-
traits::ObligationCause::new(
2333-
span,
2334-
self.body_def_id,
2335-
ObligationCauseCode::TrivialBound,
2336-
),
2337-
empty_env,
2338-
pred,
2329+
let cause = traits::ObligationCause::new(
2330+
span,
2331+
self.body_def_id,
2332+
ObligationCauseCode::TrivialBound,
23392333
);
2334+
let obligation = Obligation::new(tcx, cause, empty_env, pred);
23402335
self.ocx.register_obligation(obligation);
23412336
}
23422337
}

tests/crashes/148630.rs

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

tests/rustdoc-ui/synthetic-auto-trait-impls/projections-in-super-trait-bound-unsatisfied.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ pub(crate) const B: usize = 5;
1414
pub trait Tec: Bar<B> {}
1515

1616
pub struct Structure<C: Tec> { //~ ERROR the trait bound `C: Bar<5>` is not satisfied
17-
_field: C::BarType, //~ ERROR the trait bound `C: Bar<5>` is not satisfied
17+
//~| ERROR the trait bound `C: Bar<5>` is not satisfied
18+
_field: C::BarType,
1819
}

tests/rustdoc-ui/synthetic-auto-trait-impls/projections-in-super-trait-bound-unsatisfied.stderr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ LL | pub struct Structure<C: Tec + Bar<5>> {
1010
| ++++++++
1111

1212
error[E0277]: the trait bound `C: Bar<5>` is not satisfied
13-
--> $DIR/projections-in-super-trait-bound-unsatisfied.rs:17:13
13+
--> $DIR/projections-in-super-trait-bound-unsatisfied.rs:16:1
1414
|
15-
LL | _field: C::BarType,
16-
| ^^^^^^^^^^ the trait `Bar<5>` is not implemented for `C`
15+
LL | pub struct Structure<C: Tec> {
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar<5>` is not implemented for `C`
1717
|
18+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1819
help: consider further restricting type parameter `C` with trait `Bar`
1920
|
2021
LL | pub struct Structure<C: Tec + Bar<5>> {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ pub trait Column: Expression {}
3434
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
3535
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
3636
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
37-
pub enum ColumnInsertValue<Col, Expr> where
38-
//~^ ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
3937
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
4038
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
39+
//~| 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
4142
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
4243
Col: Column,
4344
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: 15 additions & 57 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:37: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,11 +16,11 @@ 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: IntoNullable` is not satisfied
20-
--> $DIR/issue-38821.rs:43:22
19+
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
20+
--> $DIR/issue-38821.rs:40:1
2121
|
22-
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
22+
LL | pub enum ColumnInsertValue<Col, Expr> where
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
2424
|
2525
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
2626
--> $DIR/issue-38821.rs:9:18
@@ -29,6 +29,7 @@ LL | impl<T: NotNull> IntoNullable for T {
2929
| ------- ^^^^^^^^^^^^ ^
3030
| |
3131
| unsatisfied trait bound introduced here
32+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
3233
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
3334
|
3435
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull
@@ -82,13 +83,10 @@ LL | impl<T: NotNull> IntoNullable for T {
8283
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
8384

8485
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
85-
--> $DIR/issue-38821.rs:37:10
86+
--> $DIR/issue-38821.rs:23:10
8687
|
8788
LL | #[derive(Debug, Copy, Clone)]
88-
| ----- in this derive macro expansion
89-
...
90-
LL | pub enum ColumnInsertValue<Col, Expr> where
91-
| ^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
89+
| ^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
9290
|
9391
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
9492
--> $DIR/issue-38821.rs:9:18
@@ -97,19 +95,7 @@ LL | impl<T: NotNull> IntoNullable for T {
9795
| ------- ^^^^^^^^^^^^ ^
9896
| |
9997
| unsatisfied trait bound introduced here
100-
note: required for `ColumnInsertValue<Col, Expr>` to implement `Debug`
101-
--> $DIR/issue-38821.rs:37:10
102-
|
103-
LL | #[derive(Debug, Copy, Clone)]
104-
| ----- in this derive macro expansion
105-
...
106-
LL | pub enum ColumnInsertValue<Col, Expr> where
107-
| ^^^^^^^^^^^^^^^^^
108-
...
109-
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
110-
| ------------------------------------------------ unsatisfied trait bound
111-
= help: consider manually implementing `Debug` to avoid undesired bounds caused by "imperfect derives"
112-
= note: to learn more, visit <https://github.com/rust-lang/rust/issues/26925>
98+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
11399
help: consider further restricting the associated type
114100
|
115101
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
@@ -134,13 +120,10 @@ LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Co
134120
| +++++++++++++++++++++++++++++++++++++++
135121

136122
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
137-
--> $DIR/issue-38821.rs:37:10
123+
--> $DIR/issue-38821.rs:23:17
138124
|
139125
LL | #[derive(Debug, Copy, Clone)]
140-
| ---- in this derive macro expansion
141-
...
142-
LL | pub enum ColumnInsertValue<Col, Expr> where
143-
| ^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
126+
| ^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
144127
|
145128
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
146129
--> $DIR/issue-38821.rs:9:18
@@ -149,17 +132,7 @@ LL | impl<T: NotNull> IntoNullable for T {
149132
| ------- ^^^^^^^^^^^^ ^
150133
| |
151134
| unsatisfied trait bound introduced here
152-
note: required for `ColumnInsertValue<Col, Expr>` to implement `Copy`
153-
--> $DIR/issue-38821.rs:37:10
154-
|
155-
LL | #[derive(Debug, Copy, Clone)]
156-
| ---- in this derive macro expansion
157-
...
158-
LL | pub enum ColumnInsertValue<Col, Expr> where
159-
| ^^^^^^^^^^^^^^^^^
160-
...
161-
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
162-
| ------------------------------------------------ unsatisfied trait bound
135+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
163136
help: consider further restricting the associated type
164137
|
165138
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
@@ -213,13 +186,10 @@ LL | impl<T: NotNull> IntoNullable for T {
213186
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
214187

215188
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
216-
--> $DIR/issue-38821.rs:37:10
189+
--> $DIR/issue-38821.rs:23:23
217190
|
218191
LL | #[derive(Debug, Copy, Clone)]
219-
| ----- in this derive macro expansion
220-
...
221-
LL | pub enum ColumnInsertValue<Col, Expr> where
222-
| ^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
192+
| ^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
223193
|
224194
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
225195
--> $DIR/issue-38821.rs:9:18
@@ -228,19 +198,7 @@ LL | impl<T: NotNull> IntoNullable for T {
228198
| ------- ^^^^^^^^^^^^ ^
229199
| |
230200
| unsatisfied trait bound introduced here
231-
note: required for `ColumnInsertValue<Col, Expr>` to implement `Clone`
232-
--> $DIR/issue-38821.rs:37:10
233-
|
234-
LL | #[derive(Debug, Copy, Clone)]
235-
| ----- in this derive macro expansion
236-
...
237-
LL | pub enum ColumnInsertValue<Col, Expr> where
238-
| ^^^^^^^^^^^^^^^^^
239-
...
240-
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
241-
| ------------------------------------------------ unsatisfied trait bound
242-
= help: consider manually implementing `Clone` to avoid undesired bounds caused by "imperfect derives"
243-
= note: to learn more, visit <https://github.com/rust-lang/rust/issues/26925>
201+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
244202
help: consider further restricting the associated type
245203
|
246204
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ pub trait Service {
1010

1111
pub trait ThriftService<Bug: NotFoo>:
1212
//~^ ERROR the trait bound `Bug: Foo` is not satisfied
13+
//~| ERROR the trait bound `Bug: Foo` is not satisfied
1314
Service<AssocType = <Bug as Foo>::OnlyFoo>
14-
//~^ ERROR the trait bound `Bug: Foo` is not satisfied
1515
{
1616
fn get_service(
1717
//~^ ERROR the trait bound `Bug: Foo` is not satisfied

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `Bug: Foo` is not satisfied
22
--> $DIR/issue-59324.rs:11:1
33
|
44
LL | / pub trait ThriftService<Bug: NotFoo>:
5-
LL | |
5+
... |
66
LL | | Service<AssocType = <Bug as Foo>::OnlyFoo>
77
| |______________________________________________^ the trait `Foo` is not implemented for `Bug`
88
|
@@ -12,11 +12,14 @@ LL | pub trait ThriftService<Bug: NotFoo + Foo>:
1212
| +++++
1313

1414
error[E0277]: the trait bound `Bug: Foo` is not satisfied
15-
--> $DIR/issue-59324.rs:13:13
15+
--> $DIR/issue-59324.rs:11:1
1616
|
17-
LL | Service<AssocType = <Bug as Foo>::OnlyFoo>
18-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `Bug`
17+
LL | / pub trait ThriftService<Bug: NotFoo>:
18+
... |
19+
LL | | Service<AssocType = <Bug as Foo>::OnlyFoo>
20+
| |______________________________________________^ the trait `Foo` is not implemented for `Bug`
1921
|
22+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
2023
help: consider further restricting type parameter `Bug` with trait `Foo`
2124
|
2225
LL | pub trait ThriftService<Bug: NotFoo + Foo>:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@ check-pass
2-
31
pub trait Foo {
42
type Bar;
53
}
@@ -12,6 +10,7 @@ pub trait Broken {
1210
impl<T> Broken for T {
1311
type Assoc = ();
1412
fn broken(&self) where Self::Assoc: Foo {
13+
//~^ ERROR the trait bound `(): Foo` is not satisfied
1514
let _x: <Self::Assoc as Foo>::Bar;
1615
}
1716
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0277]: the trait bound `(): Foo` is not satisfied
2+
--> $DIR/issue-69398.rs:12:28
3+
|
4+
LL | fn broken(&self) where Self::Assoc: Foo {
5+
| ^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/issue-69398.rs:1:1
9+
|
10+
LL | pub trait Foo {
11+
| ^^^^^^^^^^^^^
12+
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
13+
|
14+
LL + #![feature(trivial_bounds)]
15+
|
16+
17+
error: aborting due to 1 previous error
18+
19+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)