Skip to content

Commit 532609b

Browse files
committed
Auto merge of rust-lang#84316 - teymour-aldridge:improve-defaulted-never-note, r=petrochenkov
Improve an error message.
2 parents 8108e17 + 567de4a commit 532609b

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
503503
let unit_obligation =
504504
obligation.with(predicate.without_const().to_predicate(tcx));
505505
if self.predicate_may_hold(&unit_obligation) {
506+
err.note("this trait is implemented for `()`.");
506507
err.note(
507-
"the trait is implemented for `()`. \
508-
Possibly this error has been caused by changes to \
509-
Rust's type-inference algorithm (see issue #48950 \
510-
<https://github.com/rust-lang/rust/issues/48950> \
511-
for more information). Consider whether you meant to use \
512-
the type `()` here instead.",
508+
"this error might have been caused by changes to \
509+
Rust's type-inference algorithm (see issue #48950 \
510+
<https://github.com/rust-lang/rust/issues/48950> \
511+
for more information).",
513512
);
513+
err.help("did you intend to use the type `()` here instead?");
514514
}
515515
}
516516

src/test/ui/never_type/defaulted-never-note.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ fn smeg() {
2626
foo(_x);
2727
//~^ ERROR the trait bound
2828
//~| NOTE the trait `ImplementedForUnitButNotNever` is not implemented
29-
//~| NOTE the trait is implemented for `()`
29+
//~| NOTE this trait is implemented for `()`
30+
//~| NOTE this error might have been caused
31+
//~| HELP did you intend
3032
}
3133

3234
fn main() {

src/test/ui/never_type/defaulted-never-note.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ LL | fn foo<T: ImplementedForUnitButNotNever>(_t: T) {}
77
LL | foo(_x);
88
| ^^^ the trait `ImplementedForUnitButNotNever` is not implemented for `!`
99
|
10-
= note: the trait is implemented for `()`. Possibly this error has been caused by changes to Rust's type-inference algorithm (see issue #48950 <https://github.com/rust-lang/rust/issues/48950> for more information). Consider whether you meant to use the type `()` here instead.
10+
= note: this trait is implemented for `()`.
11+
= note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #48950 <https://github.com/rust-lang/rust/issues/48950> for more information).
12+
= help: did you intend to use the type `()` here instead?
1113

1214
error: aborting due to previous error
1315

0 commit comments

Comments
 (0)