diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index a5411a04d59..eaae900549e 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -239,13 +239,26 @@ fn with_short_path<'tcx, T>(tcx: TyCtxt<'tcx>, value: T) -> String } OverflowCause::TraitSolver(predicate) => { let predicate = self.resolve_vars_if_possible(predicate); - let pred_str = with_short_path(self.tcx, predicate); - struct_span_code_err!( - self.dcx(), - span, - E0275, - "overflow evaluating the requirement `{pred_str}`", - ) + match predicate.kind().skip_binder() { + ty::PredicateKind::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) + | ty::PredicateKind::Coerce(ty::CoercePredicate { a, b }) => { + struct_span_code_err!( + self.dcx(), + span, + E0275, + "overflow setting `{a}` to a subtype of `{b}`", + ) + } + _ => { + let pred_str = with_short_path(self.tcx, predicate); + struct_span_code_err!( + self.dcx(), + span, + E0275, + "overflow evaluating the requirement `{pred_str}`", + ) + } + } } }; diff --git a/tests/ui/impl-trait/issues/issue-84073.rs b/tests/ui/impl-trait/issues/issue-84073.rs index 60f98a7c7b5..124b1d0eec8 100644 --- a/tests/ui/impl-trait/issues/issue-84073.rs +++ b/tests/ui/impl-trait/issues/issue-84073.rs @@ -29,5 +29,5 @@ pub fn new(race: R) {} } fn main() { - Race::new(|race| race.when()); //~ ERROR overflow evaluating the requirement `_ <: Option<_>` + Race::new(|race| race.when()); //~ ERROR overflow setting `_` to a subtype of `Option<_>` } diff --git a/tests/ui/impl-trait/issues/issue-84073.stderr b/tests/ui/impl-trait/issues/issue-84073.stderr index b9039211db6..2441e523684 100644 --- a/tests/ui/impl-trait/issues/issue-84073.stderr +++ b/tests/ui/impl-trait/issues/issue-84073.stderr @@ -1,4 +1,4 @@ -error[E0275]: overflow evaluating the requirement `_ <: Option<_>` +error[E0275]: overflow setting `_` to a subtype of `Option<_>` --> $DIR/issue-84073.rs:32:22 | LL | Race::new(|race| race.when()); diff --git a/tests/ui/infinite/infinite-autoderef.rs b/tests/ui/infinite/infinite-autoderef.rs index cf5c9fe5678..ae854e1d204 100644 --- a/tests/ui/infinite/infinite-autoderef.rs +++ b/tests/ui/infinite/infinite-autoderef.rs @@ -14,7 +14,7 @@ pub fn main() { let mut x; loop { x = Box::new(x); - //~^ ERROR overflow evaluating the requirement `Box<_> <: _` + //~^ ERROR overflow setting `Box<_>` to a subtype of `_` x.foo; x.bar(); } diff --git a/tests/ui/infinite/infinite-autoderef.stderr b/tests/ui/infinite/infinite-autoderef.stderr index 24be1a11373..94ec00c591e 100644 --- a/tests/ui/infinite/infinite-autoderef.stderr +++ b/tests/ui/infinite/infinite-autoderef.stderr @@ -1,4 +1,4 @@ -error[E0275]: overflow evaluating the requirement `Box<_> <: _` +error[E0275]: overflow setting `Box<_>` to a subtype of `_` --> $DIR/infinite-autoderef.rs:16:13 | LL | x = Box::new(x); diff --git a/tests/ui/occurs-check-2.rs b/tests/ui/occurs-check-2.rs index 6cdb757d65b..80ae75632a5 100644 --- a/tests/ui/occurs-check-2.rs +++ b/tests/ui/occurs-check-2.rs @@ -5,5 +5,5 @@ fn main() { g = f; f = Box::new(g); - //~^ ERROR overflow evaluating the requirement `Box<_> <: _` + //~^ ERROR overflow setting `Box<_>` to a subtype of `_` } diff --git a/tests/ui/occurs-check-2.stderr b/tests/ui/occurs-check-2.stderr index acc474319b0..cf5c95a1c42 100644 --- a/tests/ui/occurs-check-2.stderr +++ b/tests/ui/occurs-check-2.stderr @@ -1,4 +1,4 @@ -error[E0275]: overflow evaluating the requirement `Box<_> <: _` +error[E0275]: overflow setting `Box<_>` to a subtype of `_` --> $DIR/occurs-check-2.rs:7:9 | LL | f = Box::new(g); diff --git a/tests/ui/occurs-check-3.rs b/tests/ui/occurs-check-3.rs index cdf8dc3bd16..f3d9a28b62d 100644 --- a/tests/ui/occurs-check-3.rs +++ b/tests/ui/occurs-check-3.rs @@ -4,7 +4,7 @@ enum Clam { A(T) } fn main() { let c; c = Clam::A(c); - //~^ ERROR overflow evaluating the requirement `Clam<_> <: _` + //~^ ERROR overflow setting `Clam<_>` to a subtype of `_` match c { Clam::A::(_) => { } } diff --git a/tests/ui/occurs-check-3.stderr b/tests/ui/occurs-check-3.stderr index 7bc28e61d9f..84197162c38 100644 --- a/tests/ui/occurs-check-3.stderr +++ b/tests/ui/occurs-check-3.stderr @@ -1,4 +1,4 @@ -error[E0275]: overflow evaluating the requirement `Clam<_> <: _` +error[E0275]: overflow setting `Clam<_>` to a subtype of `_` --> $DIR/occurs-check-3.rs:6:9 | LL | c = Clam::A(c); diff --git a/tests/ui/occurs-check.rs b/tests/ui/occurs-check.rs index 3fae3ff1238..dce0a41bce7 100644 --- a/tests/ui/occurs-check.rs +++ b/tests/ui/occurs-check.rs @@ -1,5 +1,5 @@ fn main() { let f; f = Box::new(f); - //~^ ERROR overflow evaluating the requirement `Box<_> <: _` + //~^ ERROR overflow setting `Box<_>` to a subtype of `_` } diff --git a/tests/ui/occurs-check.stderr b/tests/ui/occurs-check.stderr index 3f61d8fd08d..0454e6ddda6 100644 --- a/tests/ui/occurs-check.stderr +++ b/tests/ui/occurs-check.stderr @@ -1,4 +1,4 @@ -error[E0275]: overflow evaluating the requirement `Box<_> <: _` +error[E0275]: overflow setting `Box<_>` to a subtype of `_` --> $DIR/occurs-check.rs:3:9 | LL | f = Box::new(f); diff --git a/tests/ui/traits/subtype-recursion-limit.rs b/tests/ui/traits/subtype-recursion-limit.rs index 5804748844e..c652e24644d 100644 --- a/tests/ui/traits/subtype-recursion-limit.rs +++ b/tests/ui/traits/subtype-recursion-limit.rs @@ -10,7 +10,7 @@ fn main() { let x = return; let y = return; let mut w = (x, y); - //~^ ERROR overflow evaluating the requirement + //~^ ERROR overflow setting `_` to a subtype of `*const _` // Avoid creating lifetimes, `Sized` bounds or function calls. let a = (ptr::addr_of!(y), ptr::addr_of!(x)); w = a; diff --git a/tests/ui/traits/subtype-recursion-limit.stderr b/tests/ui/traits/subtype-recursion-limit.stderr index 5310f822cc3..6544852bbf0 100644 --- a/tests/ui/traits/subtype-recursion-limit.stderr +++ b/tests/ui/traits/subtype-recursion-limit.stderr @@ -1,4 +1,4 @@ -error[E0275]: overflow evaluating the requirement `_ <: *const _` +error[E0275]: overflow setting `_` to a subtype of `*const _` --> $DIR/subtype-recursion-limit.rs:12:17 | LL | let mut w = (x, y); diff --git a/tests/ui/traits/well-formed-recursion-limit.rs b/tests/ui/traits/well-formed-recursion-limit.rs index 056cf947d4b..49713be3a79 100644 --- a/tests/ui/traits/well-formed-recursion-limit.rs +++ b/tests/ui/traits/well-formed-recursion-limit.rs @@ -13,8 +13,8 @@ pub fn iso_un_option(i: ISO, Option>) -> IS //~^ ERROR no field `ab` on type //~| ERROR no field `ba` on type let left = move |o_a| match o_a { - //~^ ERROR overflow evaluating the requirement - None => panic!("absured"), + //~^ ERROR overflow setting `_` to a subtype of `Option<_>` + None => panic!("absurd"), Some(a) => a, }; let right = move |o_b| match o_b { diff --git a/tests/ui/traits/well-formed-recursion-limit.stderr b/tests/ui/traits/well-formed-recursion-limit.stderr index 6f5fda02315..690d869b243 100644 --- a/tests/ui/traits/well-formed-recursion-limit.stderr +++ b/tests/ui/traits/well-formed-recursion-limit.stderr @@ -10,7 +10,7 @@ error[E0609]: no field `ba` on type `(Box<(dyn Fn(Option) -> Option + 'sta LL | let (ab, ba) = (i.ab, i.ba); | ^^ unknown field -error[E0275]: overflow evaluating the requirement `_ <: Option<_>` +error[E0275]: overflow setting `_` to a subtype of `Option<_>` --> $DIR/well-formed-recursion-limit.rs:15:33 | LL | let left = move |o_a| match o_a {