slight rewording of labels

This commit is contained in:
Esteban Küber 2018-09-05 08:39:50 -07:00
parent d7a74be09b
commit 941b2e32ad
5 changed files with 23 additions and 17 deletions

View File

@ -197,15 +197,26 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
err.span_label(span, "use of type variable from outer function");
let cm = resolver.session.source_map();
let mut is_self = false;
match outer_def {
Def::SelfTy(_, maybe_impl_defid) => {
if let Some(impl_span) = maybe_impl_defid.map_or(None,
|def_id| resolver.definitions.opt_span(def_id)) {
err.span_label(reduce_impl_span_to_impl_keyword(cm, impl_span),
"`Self` type implicitly declared here, on the `impl`");
Def::SelfTy(maybe_trait_defid, maybe_impl_defid) => {
if let Some(impl_span) = maybe_impl_defid.and_then(|def_id| {
resolver.definitions.opt_span(def_id)
}) {
err.span_label(
reduce_impl_span_to_impl_keyword(cm, impl_span),
"`Self` type implicitly declared here, on the `impl`",
);
}
is_self = true;
match (maybe_trait_defid, maybe_impl_defid) {
(Some(_), None) => {
err.span_label(span, "can't use `Self` here");
}
(_, Some(_)) => {
err.span_label(span, "use a type here instead");
}
(None, None) => bug!("`impl` without trait nor type?"),
}
return err;
},
Def::TyParam(typaram_defid) => {
if let Some(typaram_span) = resolver.definitions.opt_span(typaram_defid) {
@ -221,12 +232,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
// Try to retrieve the span of the function signature and generate a new message with
// a local type parameter
let sugg_msg = "try using a local type parameter instead";
if is_self {
// Suggest using the actual type
err.span_label(span, "use a materialized type here instead");
} else if let Some(
(sugg_span, new_snippet),
) = cm.generate_local_type_param_snippet(span) {
if let Some((sugg_span, new_snippet)) = cm.generate_local_type_param_snippet(span) {
// Suggest the modification to the user
err.span_suggestion_with_applicability(
sugg_span,

View File

@ -30,7 +30,7 @@ LL | fn helper(sel: &Self) -> u8 { //~ ERROR E0401
| ^^^^
| |
| use of type variable from outer function
| use a materialized type here instead
| use a type here instead
error: aborting due to 3 previous errors

View File

@ -5,7 +5,7 @@ LL | fn inner(_: &Self) {
| ^^^^
| |
| use of type variable from outer function
| use a materialized type here instead
| can't use `Self` here
error: aborting due to previous error

View File

@ -16,7 +16,7 @@ impl A {
fn peach(this: &Self) {
//~^ ERROR can't use type parameters from outer function
//~| NOTE use of type variable from outer function
//~| NOTE use a materialized type here instead
//~| NOTE use a type here instead
}
}
}

View File

@ -8,7 +8,7 @@ LL | fn peach(this: &Self) {
| ^^^^
| |
| use of type variable from outer function
| use a materialized type here instead
| use a type here instead
error: aborting due to previous error