Skip to content

Commit c332255

Browse files
committed
Fix according to comments
1 parent 4bb3996 commit c332255

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

src/librustc/lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ declare_lint! {
280280
}
281281

282282
declare_lint! {
283-
pub DUPLICATE_ASSOCIATED_TYPE_BINDING,
283+
pub DUPLICATE_ASSOCIATED_TYPE_BINDINGS,
284284
Warn,
285285
"warns about duplicate associated type bindings in generics"
286286
}
@@ -336,7 +336,7 @@ impl LintPass for HardwiredLints {
336336
BARE_TRAIT_OBJECT,
337337
ABSOLUTE_PATH_NOT_STARTING_WITH_CRATE,
338338
UNSTABLE_NAME_COLLISION,
339-
DUPLICATE_ASSOCIATED_TYPE_BINDING,
339+
DUPLICATE_ASSOCIATED_TYPE_BINDINGS,
340340
)
341341
}
342342
}

src/librustc_lint/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
283283
reference: "issue TBD",
284284
edition: Some(Edition::Edition2018),
285285
},
286+
FutureIncompatibleInfo {
287+
id: LintId::of(DUPLICATE_ASSOCIATED_TYPE_BINDINGS),
288+
reference: "issue #50589 <https://github.com/rust-lang/rust/issues/50589>",
289+
edition: None,
290+
},
286291
]);
287292

288293
// Register renamed and removed lints

src/librustc_typeck/astconv.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -406,16 +406,6 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
406406
trait_ref.ref_id, poly_trait_ref, binding, speculative, &mut dup_bindings);
407407
predicate.ok() // ok to ignore Err() because ErrorReported (see above)
408408
}));
409-
for (_id, spans) in dup_bindings {
410-
if spans.len() > 1 {
411-
self.tcx().struct_span_lint_node(
412-
::rustc::lint::builtin::DUPLICATE_ASSOCIATED_TYPE_BINDING,
413-
trait_ref.ref_id,
414-
spans,
415-
"duplicate associated type binding"
416-
).emit();
417-
}
418-
}
419409

420410
debug!("ast_path_to_poly_trait_ref({:?}, projections={:?}) -> {:?}",
421411
trait_ref, poly_projections, poly_trait_ref);
@@ -499,7 +489,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
499489
trait_ref: ty::PolyTraitRef<'tcx>,
500490
binding: &ConvertedBinding<'tcx>,
501491
speculative: bool,
502-
dup_bindings: &mut FxHashMap<DefId, Vec<Span>>)
492+
dup_bindings: &mut FxHashMap<DefId, Span>)
503493
-> Result<ty::PolyProjectionPredicate<'tcx>, ErrorReported>
504494
{
505495
let tcx = self.tcx();
@@ -577,7 +567,21 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
577567
tcx.sess.span_err(binding.span, &msg);
578568
}
579569
tcx.check_stability(assoc_ty.def_id, Some(ref_id), binding.span);
580-
dup_bindings.entry(assoc_ty.def_id).or_insert(Vec::new()).push(binding.span);
570+
571+
dup_bindings.entry(assoc_ty.def_id)
572+
.and_modify(|prev_span| {
573+
let mut err = self.tcx().struct_span_lint_node(
574+
::rustc::lint::builtin::DUPLICATE_ASSOCIATED_TYPE_BINDINGS,
575+
ref_id,
576+
binding.span,
577+
&format!("associated type binding `{}` specified more than once",
578+
binding.item_name)
579+
);
580+
err.span_label(binding.span, "used more than once");
581+
err.span_label(*prev_span, format!("first use of `{}`", binding.item_name));
582+
err.emit();
583+
})
584+
.or_insert(binding.span);
581585

582586
Ok(candidate.map_bound(|trait_ref| {
583587
ty::ProjectionPredicate {
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
warning: duplicate associated type binding
2-
--> $DIR/issue-50589-multiple-associated-types.rs:17:28
1+
warning: associated type binding `Item` specified more than once
2+
--> $DIR/issue-50589-multiple-associated-types.rs:17:39
33
|
44
LL | fn test() -> Box<Iterator<Item = (), Item = Unit>> {
5-
| ^^^^^^^^^ ^^^^^^^^^^^
5+
| --------- ^^^^^^^^^^^ used more than once
6+
| |
7+
| first use of `Item`
68
|
7-
= note: #[warn(duplicate_associated_type_binding)] on by default
9+
= note: #[warn(duplicate_associated_type_bindings)] on by default
10+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
11+
= note: for more information, see issue #50589 <https://github.com/rust-lang/rust/issues/50589>
812

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

0 commit comments

Comments
 (0)