Skip to content

Commit b6934c9

Browse files
committed
termination_trait: Put examples in error help, not label
1 parent 2cdc7af commit b6934c9

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

src/librustc/traits/error_reporting.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -585,20 +585,25 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
585585
trait_ref.to_predicate(), post_message)
586586
}));
587587

588+
let explanation = match obligation.cause.code {
589+
ObligationCauseCode::MainFunctionType => {
590+
"consider using `()`, or a `Result`".to_owned()
591+
}
592+
_ => {
593+
format!("{}the trait `{}` is not implemented for `{}`",
594+
pre_message,
595+
trait_ref,
596+
trait_ref.self_ty())
597+
}
598+
};
599+
588600
if let Some(ref s) = label {
589601
// If it has a custom "#[rustc_on_unimplemented]"
590602
// error message, let's display it as the label!
591603
err.span_label(span, s.as_str());
592-
err.help(&format!("{}the trait `{}` is not implemented for `{}`",
593-
pre_message,
594-
trait_ref,
595-
trait_ref.self_ty()));
604+
err.help(&explanation);
596605
} else {
597-
err.span_label(span,
598-
&*format!("{}the trait `{}` is not implemented for `{}`",
599-
pre_message,
600-
trait_ref,
601-
trait_ref.self_ty()));
606+
err.span_label(span, explanation);
602607
}
603608
if let Some(ref s) = note {
604609
// If it has a custom "#[rustc_on_unimplemented]" note, let's display it

src/libstd/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ pub fn id() -> u32 {
14431443
#[cfg_attr(not(test), lang = "termination")]
14441444
#[unstable(feature = "termination_trait_lib", issue = "43301")]
14451445
#[rustc_on_unimplemented =
1446-
"`main` can only return types like `()` that implement {Termination}, not `{Self}`"]
1446+
"`main` can only return types that implement {Termination}, not `{Self}`"]
14471447
pub trait Termination {
14481448
/// Is called to get the representation of the value as status code.
14491449
/// This status code is returned to the operating system.

src/test/compile-fail/rfc-1937-termination-trait/termination-trait-main-i32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
fn main() -> i32 {
1212
//~^ ERROR `i32: std::process::Termination` is not satisfied
13-
//~| NOTE `main` can only return types like `()` that implement std::process::Termination, not `i32`
13+
//~| NOTE `main` can only return types that implement std::process::Termination, not `i32`
1414
0
1515
}

src/test/ui/rfc-1937-termination-trait/termination-trait-main-wrong-type.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ error[E0277]: the trait bound `char: std::process::Termination` is not satisfied
22
--> $DIR/termination-trait-main-wrong-type.rs:11:14
33
|
44
LL | fn main() -> char { //~ ERROR
5-
| ^^^^ `main` can only return types like `()` that implement std::process::Termination, not `char`
5+
| ^^^^ `main` can only return types that implement std::process::Termination, not `char`
66
|
7-
= help: the trait `std::process::Termination` is not implemented for `char`
7+
= help: consider using `()`, or a `Result`
88

99
error: aborting due to previous error
1010

0 commit comments

Comments
 (0)