Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E0403 update error format #35739

Merged
merged 2 commits into from
Aug 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ enum ResolutionError<'a> {
/// error E0402: cannot use an outer type parameter in this context
OuterTypeParameterContext,
/// error E0403: the name is already used for a type parameter in this type parameter list
NameAlreadyUsedInTypeParameterList(Name),
NameAlreadyUsedInTypeParameterList(Name, &'a Span),
/// error E0404: is not a trait
IsNotATrait(&'a str),
/// error E0405: use of undeclared trait name
Expand Down Expand Up @@ -209,13 +209,17 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
E0402,
"cannot use an outer type parameter in this context")
}
ResolutionError::NameAlreadyUsedInTypeParameterList(name) => {
struct_span_err!(resolver.session,
span,
E0403,
"the name `{}` is already used for a type parameter in this type \
parameter list",
name)
ResolutionError::NameAlreadyUsedInTypeParameterList(name, first_use_span) => {
let mut err = struct_span_err!(resolver.session,
span,
E0403,
"the name `{}` is already used for a type parameter \
in this type parameter list",
name);
err.span_label(span, &format!("already used"));
err.span_label(first_use_span.clone(), &format!("first use of `{}`", name));
err

}
ResolutionError::IsNotATrait(name) => {
let mut err = struct_span_err!(resolver.session,
Expand Down Expand Up @@ -1719,17 +1723,19 @@ impl<'a> Resolver<'a> {
match type_parameters {
HasTypeParameters(generics, rib_kind) => {
let mut function_type_rib = Rib::new(rib_kind);
let mut seen_bindings = HashSet::new();
let mut seen_bindings = HashMap::new();
for type_parameter in &generics.ty_params {
let name = type_parameter.ident.name;
debug!("with_type_parameter_rib: {}", type_parameter.id);

if seen_bindings.contains(&name) {
if seen_bindings.contains_key(&name) {
let span = seen_bindings.get(&name).unwrap();
resolve_error(self,
type_parameter.span,
ResolutionError::NameAlreadyUsedInTypeParameterList(name));
ResolutionError::NameAlreadyUsedInTypeParameterList(name,
span));
}
seen_bindings.insert(name);
seen_bindings.entry(name).or_insert(type_parameter.span);

// plain insert (no renaming)
let def_id = self.definitions.local_def_id(type_parameter.id);
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/E0403.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// except according to those terms.

fn foo<T, T>(s: T, u: T) {} //~ ERROR E0403
//~| NOTE already used
//~| NOTE first use of `T`

fn main() {
}