Skip to content

Change inherent overlap error to a warning for now, to ease the breakage #32309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
)
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 7 additions & 11 deletions src/librustc_typeck/coherence/overlap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 }
Expand All @@ -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);
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions src/test/compile-fail/inherent-overlap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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> {
Expand All @@ -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