Updating a few more errors with labels

This commit is contained in:
Jonathan Turner 2016-05-11 14:42:18 -07:00
parent f3054ce18c
commit 104fe1c4db

View File

@ -200,11 +200,13 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
match resolution_error {
ResolutionError::TypeParametersFromOuterFunction => {
struct_span_err!(resolver.session,
span,
E0401,
"can't use type parameters from outer function; try using a local \
type parameter instead")
let mut err = struct_span_err!(resolver.session,
span,
E0401,
"can't use type parameters from outer function; \
try using a local type parameter instead");
err = err.span_label(span, &format!("use of type variable from outer function"));
err
}
ResolutionError::OuterTypeParameterContext => {
struct_span_err!(resolver.session,
@ -230,6 +232,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
"trait `{}` is not in scope",
name);
show_candidates(&mut err, &candidates);
err = err.span_label(span, &format!("`{}` is not in scope", name));
err
}
ResolutionError::UndeclaredAssociatedType => {
@ -278,10 +281,12 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
pattern_number)
}
ResolutionError::SelfUsedOutsideImplOrTrait => {
struct_span_err!(resolver.session,
span,
E0411,
"use of `Self` outside of an impl or trait")
let mut err = struct_span_err!(resolver.session,
span,
E0411,
"use of `Self` outside of an impl or trait");
err = err.span_label(span, &format!("Used outside of impl or trait"));
err
}
ResolutionError::UseOfUndeclared(kind, name, candidates) => {
let mut err = struct_span_err!(resolver.session,
@ -291,44 +296,52 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
kind,
name);
show_candidates(&mut err, &candidates);
err = err.span_label(span, &format!("undefined or not in scope"));
err
}
ResolutionError::DeclarationShadowsEnumVariantOrUnitLikeStruct(name) => {
struct_span_err!(resolver.session,
let mut err = struct_span_err!(resolver.session,
span,
E0413,
"declaration of `{}` shadows an enum variant \
"`{}` cannot be named the same as an enum variant \
or unit-like struct in scope",
name)
name);
err = err.span_label(span,
&format!("has same name as enum variant or unit-like struct"));
err
}
ResolutionError::ConstantForIrrefutableBinding(name) => {
let mut err = struct_span_err!(resolver.session,
span,
E0414,
"variable bindings cannot shadow constants");
err.span_note(span,
"there already is a constant in scope sharing the same \
name as this pattern");
"let variables cannot be named the same as const variables");
err = err.span_label(span,
&format!("cannot be named the same as a const variable"));
if let Some(binding) = resolver.current_module
.resolve_name_in_lexical_scope(name, ValueNS) {
let participle = if binding.is_import() { "imported" } else { "defined" };
err.span_note(binding.span, &format!("constant {} here", participle));
err = err.span_label(binding.span, &format!("a constant `{}` is {} here",
name, participle));
}
err
}
ResolutionError::IdentifierBoundMoreThanOnceInParameterList(identifier) => {
struct_span_err!(resolver.session,
let mut err = struct_span_err!(resolver.session,
span,
E0415,
"identifier `{}` is bound more than once in this parameter list",
identifier)
identifier);
err = err.span_label(span, &format!("used as parameter more than once"));
err
}
ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(identifier) => {
struct_span_err!(resolver.session,
let mut err = struct_span_err!(resolver.session,
span,
E0416,
"identifier `{}` is bound more than once in the same pattern",
identifier)
identifier);
err = err.span_label(span, &format!("used in a pattern more than once"));
err
}
ResolutionError::StaticVariableReference(binding) => {
let mut err = struct_span_err!(resolver.session,
@ -336,9 +349,10 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
E0417,
"static variables cannot be referenced in a \
pattern, use a `const` instead");
err = err.span_label(span, &format!("static variable used in pattern"));
if binding.span != codemap::DUMMY_SP {
let participle = if binding.is_import() { "imported" } else { "defined" };
err.span_note(binding.span, &format!("static variable {} here", participle));
err = err.span_label(binding.span, &format!("static variable {} here", participle));
}
err
}
@ -1804,7 +1818,9 @@ impl<'a> Resolver<'a> {
// If it's a typedef, give a note
if let Def::TyAlias(..) = path_res.base_def {
err.note("`type` aliases cannot be used for traits");
let trait_name = trait_path.segments.last().unwrap().identifier.name;
err = err.span_label(trait_path.span,
&format!("`{}` is not a trait", trait_name));
let definition_site = {
let segments = &trait_path.segments;
@ -1816,7 +1832,8 @@ impl<'a> Resolver<'a> {
};
if definition_site != codemap::DUMMY_SP {
err.span_note(definition_site, "type defined here");
err = err.span_label(definition_site,
&format!("note: type aliases cannot be used for traits"));
}
}
err.emit();
@ -3462,12 +3479,15 @@ impl<'a> Resolver<'a> {
_ => match (old_binding.is_import(), binding.is_import()) {
(false, false) => struct_span_err!(self.session, span, E0428, "{}", msg),
(true, true) => struct_span_err!(self.session, span, E0252, "{}", msg),
_ => struct_span_err!(self.session, span, E0255, "{}", msg),
_ => {
let e = struct_span_err!(self.session, span, E0255, "{}", msg);
e.span_label(span, &format!("`{}` was already imported", name))
}
},
};
if old_binding.span != codemap::DUMMY_SP {
err.span_note(old_binding.span, &format!("previous {} of `{}` here", noun, name));
err = err.span_label(old_binding.span, &format!("previous {} of `{}` here", noun, name));
}
err.emit();
}