Skip to content

Commit 5c51396

Browse files
committed
do not use <: in subtyping overflow msg
1 parent 6fe47bd commit 5c51396

15 files changed

+35
-22
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,26 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
246246
}
247247
OverflowCause::TraitSolver(predicate) => {
248248
let predicate = self.resolve_vars_if_possible(predicate);
249-
let pred_str = with_short_path(self.tcx, predicate);
250-
struct_span_code_err!(
251-
self.dcx(),
252-
span,
253-
E0275,
254-
"overflow evaluating the requirement `{pred_str}`",
255-
)
249+
match predicate.kind().skip_binder() {
250+
ty::PredicateKind::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ })
251+
| ty::PredicateKind::Coerce(ty::CoercePredicate { a, b }) => {
252+
struct_span_code_err!(
253+
self.dcx(),
254+
span,
255+
E0275,
256+
"overflow setting `{a}` to a subtype of `{b}`",
257+
)
258+
}
259+
_ => {
260+
let pred_str = with_short_path(self.tcx, predicate);
261+
struct_span_code_err!(
262+
self.dcx(),
263+
span,
264+
E0275,
265+
"overflow evaluating the requirement `{pred_str}`",
266+
)
267+
}
268+
}
256269
}
257270
};
258271

tests/ui/impl-trait/issues/issue-84073.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ where
2929
}
3030

3131
fn main() {
32-
Race::new(|race| race.when()); //~ ERROR overflow evaluating the requirement `_ <: Option<_>`
32+
Race::new(|race| race.when()); //~ ERROR overflow setting `_` to a subtype of `Option<_>`
3333
}

tests/ui/impl-trait/issues/issue-84073.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0275]: overflow evaluating the requirement `_ <: Option<_>`
1+
error[E0275]: overflow setting `_` to a subtype of `Option<_>`
22
--> $DIR/issue-84073.rs:32:22
33
|
44
LL | Race::new(|race| race.when());

tests/ui/infinite/infinite-autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn main() {
1414
let mut x;
1515
loop {
1616
x = Box::new(x);
17-
//~^ ERROR overflow evaluating the requirement `Box<_> <: _`
17+
//~^ ERROR overflow setting `Box<_>` to a subtype of `_`
1818
x.foo;
1919
x.bar();
2020
}

tests/ui/infinite/infinite-autoderef.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0275]: overflow evaluating the requirement `Box<_> <: _`
1+
error[E0275]: overflow setting `Box<_>` to a subtype of `_`
22
--> $DIR/infinite-autoderef.rs:16:13
33
|
44
LL | x = Box::new(x);

tests/ui/occurs-check-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ fn main() {
55

66
g = f;
77
f = Box::new(g);
8-
//~^ ERROR overflow evaluating the requirement `Box<_> <: _`
8+
//~^ ERROR overflow setting `Box<_>` to a subtype of `_`
99
}

tests/ui/occurs-check-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0275]: overflow evaluating the requirement `Box<_> <: _`
1+
error[E0275]: overflow setting `Box<_>` to a subtype of `_`
22
--> $DIR/occurs-check-2.rs:7:9
33
|
44
LL | f = Box::new(g);

tests/ui/occurs-check-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ enum Clam<T> { A(T) }
44
fn main() {
55
let c;
66
c = Clam::A(c);
7-
//~^ ERROR overflow evaluating the requirement `Clam<_> <: _`
7+
//~^ ERROR overflow setting `Clam<_>` to a subtype of `_`
88
match c {
99
Clam::A::<isize>(_) => { }
1010
}

tests/ui/occurs-check-3.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0275]: overflow evaluating the requirement `Clam<_> <: _`
1+
error[E0275]: overflow setting `Clam<_>` to a subtype of `_`
22
--> $DIR/occurs-check-3.rs:6:9
33
|
44
LL | c = Clam::A(c);

tests/ui/occurs-check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
22
let f;
33
f = Box::new(f);
4-
//~^ ERROR overflow evaluating the requirement `Box<_> <: _`
4+
//~^ ERROR overflow setting `Box<_>` to a subtype of `_`
55
}

0 commit comments

Comments
 (0)