Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::traits::solve::NoSolution;
use rustc_middle::ty::trait_def::TraitSpecializationKind;
use rustc_middle::ty::{
self, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFlags, TypeFoldable,
self, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFoldable,
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Unnormalized,
Upcast,
};
Expand Down Expand Up @@ -2293,7 +2293,8 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
/// aren't true.
#[instrument(level = "debug", skip(self))]
fn check_false_global_bounds(&mut self) {
let tcx = self.ocx.infcx.tcx;
let infcx = self.ocx.infcx;
let tcx = infcx.tcx;
let mut span = tcx.def_span(self.body_def_id);
let empty_env = ty::ParamEnv::empty();

Expand All @@ -2312,10 +2313,8 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
_ => {}
}

// Match the existing behavior.
if pred.is_global() && !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) {
let pred = self.normalize(span, None, Unnormalized::new_wip(pred));

let pred = self.deeply_normalize(span, None, Unnormalized::new_wip(pred));
if pred.is_global() && pred.kind().bound_vars().is_empty() {
// only use the span of the predicate clause (#90869)
let hir_node = tcx.hir_node_by_def_id(self.body_def_id);
if let Some(hir::Generics { predicates, .. }) = hir_node.generics() {
Expand All @@ -2327,16 +2326,12 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
.unwrap_or(obligation_span);
}

let obligation = Obligation::new(
tcx,
traits::ObligationCause::new(
span,
self.body_def_id,
ObligationCauseCode::TrivialBound,
),
empty_env,
pred,
let cause = traits::ObligationCause::new(
span,
self.body_def_id,
ObligationCauseCode::TrivialBound,
);
let obligation = Obligation::new(tcx, cause, empty_env, pred);
self.ocx.register_obligation(obligation);
}
}
Expand Down
13 changes: 0 additions & 13 deletions tests/crashes/148630.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ pub(crate) const B: usize = 5;
pub trait Tec: Bar<B> {}

pub struct Structure<C: Tec> { //~ ERROR the trait bound `C: Bar<5>` is not satisfied
_field: C::BarType, //~ ERROR the trait bound `C: Bar<5>` is not satisfied
//~| ERROR the trait bound `C: Bar<5>` is not satisfied
_field: C::BarType,
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ LL | pub struct Structure<C: Tec + Bar<5>> {
| ++++++++

error[E0277]: the trait bound `C: Bar<5>` is not satisfied
--> $DIR/projections-in-super-trait-bound-unsatisfied.rs:17:13
--> $DIR/projections-in-super-trait-bound-unsatisfied.rs:16:1
|
LL | _field: C::BarType,
| ^^^^^^^^^^ the trait `Bar<5>` is not implemented for `C`
LL | pub struct Structure<C: Tec> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar<5>` is not implemented for `C`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider further restricting type parameter `C` with trait `Bar`
|
LL | pub struct Structure<C: Tec + Bar<5>> {
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/associated-types/issue-38821.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ pub trait Column: Expression {}
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
pub enum ColumnInsertValue<Col, Expr> where
//~^ ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
pub enum ColumnInsertValue<Col, Expr> where
//~^ ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
Col: Column,
Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
//~^ ERROR the trait bound `<Col as Expression>::SqlType: IntoNullable` is not satisfied
{
Expression(Col, Expr),
Default(Col),
Expand Down
72 changes: 15 additions & 57 deletions tests/ui/associated-types/issue-38821.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
--> $DIR/issue-38821.rs:37:1
--> $DIR/issue-38821.rs:40:1
|
LL | pub enum ColumnInsertValue<Col, Expr> where
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
Expand All @@ -16,11 +16,11 @@ help: consider extending the `where` clause, but there might be an alternative b
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull
| +++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `<Col as Expression>::SqlType: IntoNullable` is not satisfied
--> $DIR/issue-38821.rs:43:22
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
--> $DIR/issue-38821.rs:40:1
|
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
LL | pub enum ColumnInsertValue<Col, Expr> where
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
|
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
--> $DIR/issue-38821.rs:9:18
Expand All @@ -29,6 +29,7 @@ LL | impl<T: NotNull> IntoNullable for T {
| ------- ^^^^^^^^^^^^ ^
| |
| unsatisfied trait bound introduced here
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
|
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull
Expand Down Expand Up @@ -82,13 +83,10 @@ LL | impl<T: NotNull> IntoNullable for T {
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
--> $DIR/issue-38821.rs:37:10
--> $DIR/issue-38821.rs:23:10
|
LL | #[derive(Debug, Copy, Clone)]
| ----- in this derive macro expansion
...
LL | pub enum ColumnInsertValue<Col, Expr> where
| ^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
| ^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
|
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
--> $DIR/issue-38821.rs:9:18
Expand All @@ -97,19 +95,7 @@ LL | impl<T: NotNull> IntoNullable for T {
| ------- ^^^^^^^^^^^^ ^
| |
| unsatisfied trait bound introduced here
note: required for `ColumnInsertValue<Col, Expr>` to implement `Debug`
--> $DIR/issue-38821.rs:37:10
|
LL | #[derive(Debug, Copy, Clone)]
| ----- in this derive macro expansion
...
LL | pub enum ColumnInsertValue<Col, Expr> where
| ^^^^^^^^^^^^^^^^^
...
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
| ------------------------------------------------ unsatisfied trait bound
= help: consider manually implementing `Debug` to avoid undesired bounds caused by "imperfect derives"
= note: to learn more, visit <https://github.com/rust-lang/rust/issues/26925>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider further restricting the associated type
|
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
Expand All @@ -134,13 +120,10 @@ LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Co
| +++++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
--> $DIR/issue-38821.rs:37:10
--> $DIR/issue-38821.rs:23:17
|
LL | #[derive(Debug, Copy, Clone)]
| ---- in this derive macro expansion
...
LL | pub enum ColumnInsertValue<Col, Expr> where
| ^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
| ^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
|
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
--> $DIR/issue-38821.rs:9:18
Expand All @@ -149,17 +132,7 @@ LL | impl<T: NotNull> IntoNullable for T {
| ------- ^^^^^^^^^^^^ ^
| |
| unsatisfied trait bound introduced here
note: required for `ColumnInsertValue<Col, Expr>` to implement `Copy`
--> $DIR/issue-38821.rs:37:10
|
LL | #[derive(Debug, Copy, Clone)]
| ---- in this derive macro expansion
...
LL | pub enum ColumnInsertValue<Col, Expr> where
| ^^^^^^^^^^^^^^^^^
...
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
| ------------------------------------------------ unsatisfied trait bound
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider further restricting the associated type
|
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
Expand Down Expand Up @@ -213,13 +186,10 @@ LL | impl<T: NotNull> IntoNullable for T {
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
--> $DIR/issue-38821.rs:37:10
--> $DIR/issue-38821.rs:23:23
|
LL | #[derive(Debug, Copy, Clone)]
| ----- in this derive macro expansion
...
LL | pub enum ColumnInsertValue<Col, Expr> where
| ^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
| ^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
|
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
--> $DIR/issue-38821.rs:9:18
Expand All @@ -228,19 +198,7 @@ LL | impl<T: NotNull> IntoNullable for T {
| ------- ^^^^^^^^^^^^ ^
| |
| unsatisfied trait bound introduced here
note: required for `ColumnInsertValue<Col, Expr>` to implement `Clone`
--> $DIR/issue-38821.rs:37:10
|
LL | #[derive(Debug, Copy, Clone)]
| ----- in this derive macro expansion
...
LL | pub enum ColumnInsertValue<Col, Expr> where
| ^^^^^^^^^^^^^^^^^
...
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
| ------------------------------------------------ unsatisfied trait bound
= help: consider manually implementing `Clone` to avoid undesired bounds caused by "imperfect derives"
= note: to learn more, visit <https://github.com/rust-lang/rust/issues/26925>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider further restricting the associated type
|
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-types/issue-59324.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub trait Service {

pub trait ThriftService<Bug: NotFoo>:
//~^ ERROR the trait bound `Bug: Foo` is not satisfied
//~| ERROR the trait bound `Bug: Foo` is not satisfied
Service<AssocType = <Bug as Foo>::OnlyFoo>
//~^ ERROR the trait bound `Bug: Foo` is not satisfied
{
fn get_service(
//~^ ERROR the trait bound `Bug: Foo` is not satisfied
Expand Down
11 changes: 7 additions & 4 deletions tests/ui/associated-types/issue-59324.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0277]: the trait bound `Bug: Foo` is not satisfied
--> $DIR/issue-59324.rs:11:1
|
LL | / pub trait ThriftService<Bug: NotFoo>:
LL | |
... |
LL | | Service<AssocType = <Bug as Foo>::OnlyFoo>
| |______________________________________________^ the trait `Foo` is not implemented for `Bug`
|
Expand All @@ -12,11 +12,14 @@ LL | pub trait ThriftService<Bug: NotFoo + Foo>:
| +++++

error[E0277]: the trait bound `Bug: Foo` is not satisfied
--> $DIR/issue-59324.rs:13:13
--> $DIR/issue-59324.rs:11:1
|
LL | Service<AssocType = <Bug as Foo>::OnlyFoo>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `Bug`
LL | / pub trait ThriftService<Bug: NotFoo>:
... |
LL | | Service<AssocType = <Bug as Foo>::OnlyFoo>
| |______________________________________________^ the trait `Foo` is not implemented for `Bug`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider further restricting type parameter `Bug` with trait `Foo`
|
LL | pub trait ThriftService<Bug: NotFoo + Foo>:
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/associated-types/issue-69398.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ check-pass

pub trait Foo {
type Bar;
}
Expand All @@ -12,6 +10,7 @@ pub trait Broken {
impl<T> Broken for T {
type Assoc = ();
fn broken(&self) where Self::Assoc: Foo {
//~^ ERROR the trait bound `(): Foo` is not satisfied
let _x: <Self::Assoc as Foo>::Bar;
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/associated-types/issue-69398.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0277]: the trait bound `(): Foo` is not satisfied
--> $DIR/issue-69398.rs:12:28
|
LL | fn broken(&self) where Self::Assoc: Foo {
| ^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()`
|
help: this trait has no implementations, consider adding one
--> $DIR/issue-69398.rs:1:1
|
LL | pub trait Foo {
| ^^^^^^^^^^^^^
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
|
LL + #![feature(trivial_bounds)]
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ check-pass
//@ compile-flags: -Znext-solver -Zassumptions-on-binders

#![crate_type = "lib"]
Expand All @@ -16,6 +15,7 @@ fn mk() -> for<'b> fn(&'b ()) { loop {} }
fn ice()
where
(for<'b> fn(&'b ())): Trait
//~^ ERROR the trait bound `for<'b> fn(&'b ()): Trait` is not satisfied
{
req_trait(mk());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0277]: the trait bound `for<'b> fn(&'b ()): Trait` is not satisfied
--> $DIR/type_relation_binders_inside_solver-3.rs:17:5
|
LL | (for<'b> fn(&'b ())): Trait
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `for<'b> fn(&'b ())`
|
help: this trait has no implementations, consider adding one
--> $DIR/type_relation_binders_inside_solver-3.rs:9:1
|
LL | trait Trait { }
| ^^^^^^^^^^^
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
|
LL + #![feature(trivial_bounds)]
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! regression test for <https://github.com/rust-lang/rust/issues/141014>
//@ run-pass
#![expect(incomplete_features)]
#![feature(min_generic_const_args)]
#![allow(dead_code)]
Expand All @@ -19,6 +18,7 @@ trait S<const K: usize> {}
trait Handler<T: Abc>
where
(): S<{ <T as A>::VALUE }>,
//~^ ERROR the trait bound `(): S<0>` is not satisfied
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0277]: the trait bound `(): S<0>` is not satisfied
--> $DIR/assoc-const-projection-in-bound.rs:20:5
|
LL | (): S<{ <T as A>::VALUE }>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `S<0>` is not implemented for `()`
|
help: this trait has no implementations, consider adding one
--> $DIR/assoc-const-projection-in-bound.rs:16:1
|
LL | trait S<const K: usize> {}
| ^^^^^^^^^^^^^^^^^^^^^^^
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
|
LL + #![feature(trivial_bounds)]
|

error: aborting due to 1 previous error

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