Skip to content

Commit

Permalink
Updating a few more errors with labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Turner committed May 12, 2016
1 parent f3054ce commit 104fe1c
Showing 1 changed file with 46 additions and 26 deletions.
72 changes: 46 additions & 26 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 => {
Expand Down Expand Up @@ -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,
Expand All @@ -291,54 +296,63 @@ 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,
span,
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
}
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 104fe1c

Please sign in to comment.