From 42a38164e6e5cb4905fff380760bfd6437813c54 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 15 Jan 2024 15:31:30 +0100 Subject: [PATCH] do not use <: in subtyping overflow msg --- .../error_reporting/type_err_ctxt_ext.rs | 27 ++++++++++++++----- tests/ui/impl-trait/issues/issue-84073.rs | 2 +- tests/ui/impl-trait/issues/issue-84073.stderr | 2 +- tests/ui/infinite/infinite-autoderef.rs | 2 +- tests/ui/infinite/infinite-autoderef.stderr | 2 +- tests/ui/occurs-check-2.rs | 2 +- tests/ui/occurs-check-2.stderr | 2 +- tests/ui/occurs-check-3.rs | 2 +- tests/ui/occurs-check-3.stderr | 2 +- tests/ui/occurs-check.rs | 2 +- tests/ui/occurs-check.stderr | 2 +- tests/ui/traits/subtype-recursion-limit.rs | 2 +- .../ui/traits/subtype-recursion-limit.stderr | 2 +- .../ui/traits/well-formed-recursion-limit.rs | 4 +-- .../traits/well-formed-recursion-limit.stderr | 2 +- 15 files changed, 35 insertions(+), 22 deletions(-) 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 761f515970d9a..28a99baa1afda 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 @@ -299,13 +299,26 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } 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 60f98a7c7b53c..124b1d0eec848 100644 --- a/tests/ui/impl-trait/issues/issue-84073.rs +++ b/tests/ui/impl-trait/issues/issue-84073.rs @@ -29,5 +29,5 @@ where } 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 b9039211db63f..2441e523684c1 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 cf5c9fe5678c2..ae854e1d20480 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 24be1a11373cd..94ec00c591e4a 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 6cdb757d65bc6..80ae75632a5de 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 acc474319b059..cf5c95a1c42b5 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 cdf8dc3bd160b..f3d9a28b62d4c 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 7bc28e61d9f96..84197162c3827 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 3fae3ff1238e3..dce0a41bce71d 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 3f61d8fd08d17..0454e6ddda67d 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 5804748844e5a..c652e24644d35 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 5310f822cc338..6544852bbf06a 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 056cf947d4b55..49713be3a798e 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 6f5fda02315c0..690d869b24354 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 {