diff options
| author | Aaron Turon <aturon@mozilla.com> | 2016-03-17 09:05:24 -0700 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2016-03-18 09:48:30 -0700 |
| commit | e477703bbfa47bb03eb0f983164fea4ecaf73cf7 (patch) | |
| tree | 0e09298e298b6da0a00e3f9024fbc4f64161e43e /src | |
| parent | abb1515c53d209be3e8c1e9e73c1a98bc86b8692 (diff) | |
| download | rust-e477703bbfa47bb03eb0f983164fea4ecaf73cf7.tar.gz rust-e477703bbfa47bb03eb0f983164fea4ecaf73cf7.zip | |
Change inherent overlap error to a warning for now, to ease the breakage.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/lint/builtin.rs | 9 | ||||
| -rw-r--r-- | src/librustc_lint/lib.rs | 4 | ||||
| -rw-r--r-- | src/librustc_typeck/coherence/overlap.rs | 18 | ||||
| -rw-r--r-- | src/test/compile-fail/inherent-overlap.rs | 15 |
4 files changed, 30 insertions, 16 deletions
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 97a550a4076..d99d6afd812 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -154,6 +154,12 @@ declare_lint! { "transmute from function item type to pointer-sized type erroneously allowed" } +declare_lint! { + pub OVERLAPPING_INHERENT_IMPLS, + Warn, + "two overlapping inherent impls define an item with the same name were erroneously allowed" +} + /// Does nothing as a lint pass, but registers some `Lint`s /// which are used by other parts of the compiler. #[derive(Copy, Clone)] @@ -184,7 +190,8 @@ impl LintPass for HardwiredLints { MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT, CONST_ERR, RAW_POINTER_DERIVE, - TRANSMUTE_FROM_FN_ITEM_TYPES + TRANSMUTE_FROM_FN_ITEM_TYPES, + OVERLAPPING_INHERENT_IMPLS ) } } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index e47f67dad8f..4288f6258ae 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -175,6 +175,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { id: LintId::of(TRANSMUTE_FROM_FN_ITEM_TYPES), reference: "issue #19925 <https://github.com/rust-lang/rust/issues/19925>", }, + FutureIncompatibleInfo { + id: LintId::of(OVERLAPPING_INHERENT_IMPLS), + reference: "issue #22889 <https://github.com/rust-lang/rust/issues/22889>", + }, ]); // We have one lint pass defined specially diff --git a/src/librustc_typeck/coherence/overlap.rs b/src/librustc_typeck/coherence/overlap.rs index f7fa3e1b142..78ae8fa65f8 100644 --- a/src/librustc_typeck/coherence/overlap.rs +++ b/src/librustc_typeck/coherence/overlap.rs @@ -18,11 +18,11 @@ use middle::traits::{self, ProjectionMode}; use middle::infer; use middle::ty::{self, TyCtxt}; use syntax::ast; -use syntax::codemap::Span; use rustc::dep_graph::DepNode; use rustc_front::hir; use rustc_front::intravisit; use util::nodemap::DefIdMap; +use lint; pub fn check(tcx: &TyCtxt) { let mut overlap = OverlapChecker { tcx: tcx, @@ -41,11 +41,6 @@ struct OverlapChecker<'cx, 'tcx:'cx> { } impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> { - fn span_of_def_id(&self, did: DefId) -> Span { - let node_id = self.tcx.map.as_local_node_id(did).unwrap(); - self.tcx.map.span(node_id) - } - fn check_for_common_items_in_impls(&self, impl1: DefId, impl2: DefId) { #[derive(Copy, Clone, PartialEq)] enum Namespace { Type, Value } @@ -68,11 +63,12 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> { for item2 in &impl_items[&impl2] { if (name, namespace) == name_and_namespace(&self.tcx, item2) { - let mut err = super::report_duplicate_item( - &self.tcx, self.span_of_def_id(item1.def_id()), name); - span_note!(&mut err, self.span_of_def_id(item2.def_id()), - "conflicting definition is here:"); - err.emit(); + let msg = format!("duplicate definitions with name `{}`", name); + let node_id = self.tcx.map.as_local_node_id(item1.def_id()).unwrap(); + self.tcx.sess.add_lint(lint::builtin::OVERLAPPING_INHERENT_IMPLS, + node_id, + self.tcx.span_of_impl(item1.def_id()).unwrap(), + msg); } } } diff --git a/src/test/compile-fail/inherent-overlap.rs b/src/test/compile-fail/inherent-overlap.rs index 5b014dbfd22..333a4ee04b2 100644 --- a/src/test/compile-fail/inherent-overlap.rs +++ b/src/test/compile-fail/inherent-overlap.rs @@ -11,10 +11,14 @@ // Test that you cannot define items with the same name in overlapping inherent // impl blocks. +#![feature(rustc_attrs)] +#![allow(dead_code)] + struct Foo; impl Foo { - fn id() {} //~ ERROR E0201 + fn id() {} //~ WARN duplicate definitions + //~^ WARN previously accepted } impl Foo { @@ -24,7 +28,8 @@ impl Foo { struct Bar<T>(T); impl<T> Bar<T> { - fn bar(&self) {} //~ ERROR E0201 + fn bar(&self) {} //~ WARN duplicate definitions + //~^ WARN previously accepted } impl Bar<u32> { @@ -34,11 +39,13 @@ impl Bar<u32> { struct Baz<T>(T); impl<T: Copy> Baz<T> { - fn baz(&self) {} //~ ERROR E0201 + fn baz(&self) {} //~ WARN duplicate definitions + //~^ WARN previously accepted } impl<T> Baz<Vec<T>> { fn baz(&self) {} } -fn main() {} +#[rustc_error] +fn main() {} //~ ERROR compilation successful |
