Skip to content

Commit

Permalink
Rollup merge of #84316 - teymour-aldridge:improve-defaulted-never-not…
Browse files Browse the repository at this point in the history
…e, r=petrochenkov

Improve an error message.
  • Loading branch information
GuillaumeGomez committed Apr 18, 2021
2 parents 7f20b6f + 567de4a commit 8eb1f5c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let unit_obligation =
obligation.with(predicate.without_const().to_predicate(tcx));
if self.predicate_may_hold(&unit_obligation) {
err.note("this trait is implemented for `()`.");
err.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.",
"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).",
);
err.help("did you intend to use the type `()` here instead?");
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/never_type/defaulted-never-note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ fn smeg() {
foo(_x);
//~^ ERROR the trait bound
//~| NOTE the trait `ImplementedForUnitButNotNever` is not implemented
//~| NOTE the trait is implemented for `()`
//~| NOTE this trait is implemented for `()`
//~| NOTE this error might have been caused
//~| HELP did you intend
}

fn main() {
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/never_type/defaulted-never-note.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ LL | fn foo<T: ImplementedForUnitButNotNever>(_t: T) {}
LL | foo(_x);
| ^^^ the trait `ImplementedForUnitButNotNever` is not implemented for `!`
|
= 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.
= note: this trait is implemented for `()`.
= 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).
= help: did you intend to use the type `()` here instead?

error: aborting due to previous error

Expand Down

0 comments on commit 8eb1f5c

Please sign in to comment.