Skip to content

Commit

Permalink
Fix according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
F001 committed May 20, 2018
1 parent 4bb3996 commit c332255
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/librustc/lint/builtin.rs
Expand Up @@ -280,7 +280,7 @@ declare_lint! {
}

declare_lint! {
pub DUPLICATE_ASSOCIATED_TYPE_BINDING,
pub DUPLICATE_ASSOCIATED_TYPE_BINDINGS,
Warn,
"warns about duplicate associated type bindings in generics"
}
Expand Down Expand Up @@ -336,7 +336,7 @@ impl LintPass for HardwiredLints {
BARE_TRAIT_OBJECT,
ABSOLUTE_PATH_NOT_STARTING_WITH_CRATE,
UNSTABLE_NAME_COLLISION,
DUPLICATE_ASSOCIATED_TYPE_BINDING,
DUPLICATE_ASSOCIATED_TYPE_BINDINGS,
)
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_lint/lib.rs
Expand Up @@ -283,6 +283,11 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
reference: "issue TBD",
edition: Some(Edition::Edition2018),
},
FutureIncompatibleInfo {
id: LintId::of(DUPLICATE_ASSOCIATED_TYPE_BINDINGS),
reference: "issue #50589 <https://github.com/rust-lang/rust/issues/50589>",
edition: None,
},
]);

// Register renamed and removed lints
Expand Down
28 changes: 16 additions & 12 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -406,16 +406,6 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
trait_ref.ref_id, poly_trait_ref, binding, speculative, &mut dup_bindings);
predicate.ok() // ok to ignore Err() because ErrorReported (see above)
}));
for (_id, spans) in dup_bindings {
if spans.len() > 1 {
self.tcx().struct_span_lint_node(
::rustc::lint::builtin::DUPLICATE_ASSOCIATED_TYPE_BINDING,
trait_ref.ref_id,
spans,
"duplicate associated type binding"
).emit();
}
}

debug!("ast_path_to_poly_trait_ref({:?}, projections={:?}) -> {:?}",
trait_ref, poly_projections, poly_trait_ref);
Expand Down Expand Up @@ -499,7 +489,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
trait_ref: ty::PolyTraitRef<'tcx>,
binding: &ConvertedBinding<'tcx>,
speculative: bool,
dup_bindings: &mut FxHashMap<DefId, Vec<Span>>)
dup_bindings: &mut FxHashMap<DefId, Span>)
-> Result<ty::PolyProjectionPredicate<'tcx>, ErrorReported>
{
let tcx = self.tcx();
Expand Down Expand Up @@ -577,7 +567,21 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
tcx.sess.span_err(binding.span, &msg);
}
tcx.check_stability(assoc_ty.def_id, Some(ref_id), binding.span);
dup_bindings.entry(assoc_ty.def_id).or_insert(Vec::new()).push(binding.span);

dup_bindings.entry(assoc_ty.def_id)
.and_modify(|prev_span| {
let mut err = self.tcx().struct_span_lint_node(
::rustc::lint::builtin::DUPLICATE_ASSOCIATED_TYPE_BINDINGS,
ref_id,
binding.span,
&format!("associated type binding `{}` specified more than once",
binding.item_name)
);
err.span_label(binding.span, "used more than once");
err.span_label(*prev_span, format!("first use of `{}`", binding.item_name));
err.emit();
})
.or_insert(binding.span);

Ok(candidate.map_bound(|trait_ref| {
ty::ProjectionPredicate {
Expand Down
23 changes: 16 additions & 7 deletions src/test/ui/lint/issue-50589-multiple-associated-types.stderr
@@ -1,14 +1,23 @@
warning: duplicate associated type binding
--> $DIR/issue-50589-multiple-associated-types.rs:17:28
warning: associated type binding `Item` specified more than once
--> $DIR/issue-50589-multiple-associated-types.rs:17:39
|
LL | fn test() -> Box<Iterator<Item = (), Item = Unit>> {
| ^^^^^^^^^ ^^^^^^^^^^^
| --------- ^^^^^^^^^^^ used more than once
| |
| first use of `Item`
|
= note: #[warn(duplicate_associated_type_binding)] on by default
= note: #[warn(duplicate_associated_type_bindings)] on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #50589 <https://github.com/rust-lang/rust/issues/50589>

warning: duplicate associated type binding
--> $DIR/issue-50589-multiple-associated-types.rs:17:28
warning: associated type binding `Item` specified more than once
--> $DIR/issue-50589-multiple-associated-types.rs:17:39
|
LL | fn test() -> Box<Iterator<Item = (), Item = Unit>> {
| ^^^^^^^^^ ^^^^^^^^^^^
| --------- ^^^^^^^^^^^ used more than once
| |
| first use of `Item`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #50589 <https://github.com/rust-lang/rust/issues/50589>

0 comments on commit c332255

Please sign in to comment.