Fix according to comments
This commit is contained in:
@@ -280,7 +280,7 @@ declare_lint! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
pub DUPLICATE_ASSOCIATED_TYPE_BINDING,
|
pub DUPLICATE_ASSOCIATED_TYPE_BINDINGS,
|
||||||
Warn,
|
Warn,
|
||||||
"warns about duplicate associated type bindings in generics"
|
"warns about duplicate associated type bindings in generics"
|
||||||
}
|
}
|
||||||
@@ -336,7 +336,7 @@ impl LintPass for HardwiredLints {
|
|||||||
BARE_TRAIT_OBJECT,
|
BARE_TRAIT_OBJECT,
|
||||||
ABSOLUTE_PATH_NOT_STARTING_WITH_CRATE,
|
ABSOLUTE_PATH_NOT_STARTING_WITH_CRATE,
|
||||||
UNSTABLE_NAME_COLLISION,
|
UNSTABLE_NAME_COLLISION,
|
||||||
DUPLICATE_ASSOCIATED_TYPE_BINDING,
|
DUPLICATE_ASSOCIATED_TYPE_BINDINGS,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -283,6 +283,11 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
|
|||||||
reference: "issue TBD",
|
reference: "issue TBD",
|
||||||
edition: Some(Edition::Edition2018),
|
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
|
// Register renamed and removed lints
|
||||||
|
|||||||
@@ -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);
|
trait_ref.ref_id, poly_trait_ref, binding, speculative, &mut dup_bindings);
|
||||||
predicate.ok() // ok to ignore Err() because ErrorReported (see above)
|
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={:?}) -> {:?}",
|
debug!("ast_path_to_poly_trait_ref({:?}, projections={:?}) -> {:?}",
|
||||||
trait_ref, poly_projections, poly_trait_ref);
|
trait_ref, poly_projections, poly_trait_ref);
|
||||||
@@ -499,7 +489,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||||
binding: &ConvertedBinding<'tcx>,
|
binding: &ConvertedBinding<'tcx>,
|
||||||
speculative: bool,
|
speculative: bool,
|
||||||
dup_bindings: &mut FxHashMap<DefId, Vec<Span>>)
|
dup_bindings: &mut FxHashMap<DefId, Span>)
|
||||||
-> Result<ty::PolyProjectionPredicate<'tcx>, ErrorReported>
|
-> Result<ty::PolyProjectionPredicate<'tcx>, ErrorReported>
|
||||||
{
|
{
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
@@ -577,7 +567,21 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||||||
tcx.sess.span_err(binding.span, &msg);
|
tcx.sess.span_err(binding.span, &msg);
|
||||||
}
|
}
|
||||||
tcx.check_stability(assoc_ty.def_id, Some(ref_id), binding.span);
|
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| {
|
Ok(candidate.map_bound(|trait_ref| {
|
||||||
ty::ProjectionPredicate {
|
ty::ProjectionPredicate {
|
||||||
|
|||||||
@@ -1,14 +1,23 @@
|
|||||||
warning: duplicate associated type binding
|
warning: associated type binding `Item` specified more than once
|
||||||
--> $DIR/issue-50589-multiple-associated-types.rs:17:28
|
--> $DIR/issue-50589-multiple-associated-types.rs:17:39
|
||||||
|
|
|
|
||||||
LL | fn test() -> Box<Iterator<Item = (), Item = Unit>> {
|
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
|
warning: associated type binding `Item` specified more than once
|
||||||
--> $DIR/issue-50589-multiple-associated-types.rs:17:28
|
--> $DIR/issue-50589-multiple-associated-types.rs:17:39
|
||||||
|
|
|
|
||||||
LL | fn test() -> Box<Iterator<Item = (), Item = Unit>> {
|
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>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user