Skip to content

Commit f837c34

Browse files
committed
avoid reporting twice
1 parent c332255 commit f837c34

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

src/librustc_typeck/astconv.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -568,20 +568,22 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
568568
}
569569
tcx.check_stability(assoc_ty.def_id, Some(ref_id), binding.span);
570570

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);
571+
if speculative {
572+
dup_bindings.entry(assoc_ty.def_id)
573+
.and_modify(|prev_span| {
574+
let mut err = self.tcx().struct_span_lint_node(
575+
::rustc::lint::builtin::DUPLICATE_ASSOCIATED_TYPE_BINDINGS,
576+
ref_id,
577+
binding.span,
578+
&format!("associated type binding `{}` specified more than once",
579+
binding.item_name)
580+
);
581+
err.span_label(binding.span, "used more than once");
582+
err.span_label(*prev_span, format!("first use of `{}`", binding.item_name));
583+
err.emit();
584+
})
585+
.or_insert(binding.span);
586+
}
585587

586588
Ok(candidate.map_bound(|trait_ref| {
587589
ty::ProjectionPredicate {

src/test/ui/lint/issue-50589-multiple-associated-types.stderr

-11
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,3 @@ LL | fn test() -> Box<Iterator<Item = (), Item = Unit>> {
1010
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1111
= note: for more information, see issue #50589 <https://github.com/rust-lang/rust/issues/50589>
1212

13-
warning: associated type binding `Item` specified more than once
14-
--> $DIR/issue-50589-multiple-associated-types.rs:17:39
15-
|
16-
LL | fn test() -> Box<Iterator<Item = (), Item = Unit>> {
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>
23-

0 commit comments

Comments
 (0)