diff options
| author | F001 <changchun.fan@qq.com> | 2018-05-19 22:47:34 +0800 |
|---|---|---|
| committer | F001 <changchun.fan@qq.com> | 2018-05-20 10:16:33 +0800 |
| commit | c3322556f50fbdcdbd235e5d15406f1dea77048c (patch) | |
| tree | 3bc25f4f69c3141c0fb4848ff9b4f0ef722eaef9 | |
| parent | 4bb39966a670864de0078cafc1e5b623ca1b2ec3 (diff) | |
| download | rust-c3322556f50fbdcdbd235e5d15406f1dea77048c.tar.gz rust-c3322556f50fbdcdbd235e5d15406f1dea77048c.zip | |
Fix according to comments
| -rw-r--r-- | src/librustc/lint/builtin.rs | 4 | ||||
| -rw-r--r-- | src/librustc_lint/lib.rs | 5 | ||||
| -rw-r--r-- | src/librustc_typeck/astconv.rs | 28 | ||||
| -rw-r--r-- | src/test/ui/lint/issue-50589-multiple-associated-types.stderr | 23 |
4 files changed, 39 insertions, 21 deletions
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 1cb00abbb7e..5d7d2f0f9e6 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -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" } @@ -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, ) } } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index cfd5cf5a0f9..e35537459b7 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -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 diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 091ed0a4b36..677244b612a 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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); @@ -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(); @@ -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 { diff --git a/src/test/ui/lint/issue-50589-multiple-associated-types.stderr b/src/test/ui/lint/issue-50589-multiple-associated-types.stderr index 05e02879f1f..7f0a1ee1f33 100644 --- a/src/test/ui/lint/issue-50589-multiple-associated-types.stderr +++ b/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> |
