1
Fork 0

termination_trait: Put examples in error help, not label

This commit is contained in:
Tyler Mandry 2018-03-21 13:32:46 -05:00
parent 2cdc7af413
commit b6934c91b2
4 changed files with 18 additions and 13 deletions

View file

@ -585,20 +585,25 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
trait_ref.to_predicate(), post_message)
}));
let explanation = match obligation.cause.code {
ObligationCauseCode::MainFunctionType => {
"consider using `()`, or a `Result`".to_owned()
}
_ => {
format!("{}the trait `{}` is not implemented for `{}`",
pre_message,
trait_ref,
trait_ref.self_ty())
}
};
if let Some(ref s) = label {
// If it has a custom "#[rustc_on_unimplemented]"
// error message, let's display it as the label!
err.span_label(span, s.as_str());
err.help(&format!("{}the trait `{}` is not implemented for `{}`",
pre_message,
trait_ref,
trait_ref.self_ty()));
err.help(&explanation);
} else {
err.span_label(span,
&*format!("{}the trait `{}` is not implemented for `{}`",
pre_message,
trait_ref,
trait_ref.self_ty()));
err.span_label(span, explanation);
}
if let Some(ref s) = note {
// If it has a custom "#[rustc_on_unimplemented]" note, let's display it

View file

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

View file

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

View file

@ -2,9 +2,9 @@ error[E0277]: the trait bound `char: std::process::Termination` is not satisfied
--> $DIR/termination-trait-main-wrong-type.rs:11:14
|
LL | fn main() -> char { //~ ERROR
| ^^^^ `main` can only return types like `()` that implement std::process::Termination, not `char`
| ^^^^ `main` can only return types that implement std::process::Termination, not `char`
|
= help: the trait `std::process::Termination` is not implemented for `char`
= help: consider using `()`, or a `Result`
error: aborting due to previous error