Skip to content

Commit

Permalink
lint: convert incoherent_fundamental_impls into hard error
Browse files Browse the repository at this point in the history
implement #46205
  • Loading branch information
hdhoang committed Apr 9, 2018
1 parent 292685e commit 70a2d80
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 119 deletions.
7 changes: 0 additions & 7 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,6 @@ declare_lint! {
"detects generic lifetime arguments in path segments with late bound lifetime parameters"
}

declare_lint! {
pub INCOHERENT_FUNDAMENTAL_IMPLS,
Warn,
"potentially-conflicting impls were erroneously allowed"
}

declare_lint! {
pub DEPRECATED,
Warn,
Expand Down Expand Up @@ -306,7 +300,6 @@ impl LintPass for HardwiredLints {
MISSING_FRAGMENT_SPECIFIER,
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
LATE_BOUND_LIFETIME_ARGUMENTS,
INCOHERENT_FUNDAMENTAL_IMPLS,
DEPRECATED,
UNUSED_UNSAFE,
UNUSED_MUT,
Expand Down
29 changes: 6 additions & 23 deletions src/librustc/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ use ty::{self, TyCtxt, TypeFoldable};
use syntax_pos::DUMMY_SP;
use rustc_data_structures::sync::Lrc;

use lint;

pub mod specialization_graph;

/// Information pertinent to an overlapping impl error.
Expand Down Expand Up @@ -329,36 +327,21 @@ pub(super) fn specialization_graph_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
// This is where impl overlap checking happens:
let insert_result = sg.insert(tcx, impl_def_id);
// Report error if there was one.
let (overlap, used_to_be_allowed) = match insert_result {
Err(overlap) => (Some(overlap), false),
Ok(opt_overlap) => (opt_overlap, true)
};

if let Some(overlap) = overlap {
let msg = format!("conflicting implementations of trait `{}`{}:{}",
if let Some(overlap) = match insert_result {
Err(overlap) => Some(overlap),
Ok(opt_overlap) => opt_overlap,
} {
let msg = format!("conflicting implementations of trait `{}`{}:",
overlap.trait_desc,
overlap.self_desc.clone().map_or(
String::new(), |ty| {
format!(" for type `{}`", ty)
}),
if used_to_be_allowed { " (E0119)" } else { "" }
);
let impl_span = tcx.sess.codemap().def_span(
tcx.span_of_impl(impl_def_id).unwrap()
);
let mut err = if used_to_be_allowed {
tcx.struct_span_lint_node(
lint::builtin::INCOHERENT_FUNDAMENTAL_IMPLS,
tcx.hir.as_local_node_id(impl_def_id).unwrap(),
impl_span,
&msg)
} else {
struct_span_err!(tcx.sess,
impl_span,
E0119,
"{}",
msg)
};
let mut err = struct_span_err!(tcx.sess, impl_span, E0119, "{}", msg);

match tcx.span_of_impl(overlap.with_impl) {
Ok(span) => {
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
reference: "issue #46043 <https://github.com/rust-lang/rust/issues/46043>",
edition: None,
},
FutureIncompatibleInfo {
id: LintId::of(INCOHERENT_FUNDAMENTAL_IMPLS),
reference: "issue #46205 <https://github.com/rust-lang/rust/issues/46205>",
edition: None,
},
FutureIncompatibleInfo {
id: LintId::of(TYVAR_BEHIND_RAW_POINTER),
reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>",
Expand Down Expand Up @@ -314,4 +309,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
"converted into hard error, see https://github.com/rust-lang/rust/issues/48950");
store.register_removed("resolve_trait_on_defaulted_unit",
"converted into hard error, see https://github.com/rust-lang/rust/issues/48950");
store.register_removed("incoherent_fundamental_impls",
"converted into hard error, see https://github.com/rust-lang/rust/issues/46205");
}
57 changes: 12 additions & 45 deletions src/librustc_typeck/coherence/inherent_impls_overlap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor;
use rustc::traits::{self, IntercrateMode};
use rustc::ty::TyCtxt;

use lint;

pub fn crate_inherent_impls_overlap_check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
crate_num: CrateNum) {
assert_eq!(crate_num, LOCAL_CRATE);
Expand All @@ -30,8 +28,7 @@ struct InherentOverlapChecker<'a, 'tcx: 'a> {

impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {
fn check_for_common_items_in_impls(&self, impl1: DefId, impl2: DefId,
overlap: traits::OverlapResult,
used_to_be_allowed: bool) {
overlap: traits::OverlapResult) {

let name_and_namespace = |def_id| {
let item = self.tcx.associated_item(def_id);
Expand All @@ -46,21 +43,13 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {

for &item2 in &impl_items2[..] {
if (name, namespace) == name_and_namespace(item2) {
let node_id = self.tcx.hir.as_local_node_id(impl1);
let mut err = if used_to_be_allowed && node_id.is_some() {
self.tcx.struct_span_lint_node(
lint::builtin::INCOHERENT_FUNDAMENTAL_IMPLS,
node_id.unwrap(),
self.tcx.span_of_impl(item1).unwrap(),
&format!("duplicate definitions with name `{}` (E0592)", name)
)
} else {
struct_span_err!(self.tcx.sess,
self.tcx.span_of_impl(item1).unwrap(),
E0592,
"duplicate definitions with name `{}`",
name)
};
let mut err = struct_span_err!(
self.tcx.sess,
self.tcx.span_of_impl(item1).unwrap(),
E0592,
"duplicate definitions with name `{}`",
name
);

err.span_label(self.tcx.span_of_impl(item1).unwrap(),
format!("duplicate definitions for `{}`", name));
Expand All @@ -82,38 +71,16 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {

for (i, &impl1_def_id) in impls.iter().enumerate() {
for &impl2_def_id in &impls[(i + 1)..] {
let used_to_be_allowed = traits::overlapping_impls(
traits::overlapping_impls(
self.tcx,
impl1_def_id,
impl2_def_id,
IntercrateMode::Issue43355,
|overlap| {
self.check_for_common_items_in_impls(
impl1_def_id,
impl2_def_id,
overlap,
false,
);
false
self.check_for_common_items_in_impls(impl1_def_id, impl2_def_id, overlap)
},
|| true,
);

if used_to_be_allowed {
traits::overlapping_impls(
self.tcx,
impl1_def_id,
impl2_def_id,
IntercrateMode::Fixed,
|overlap| self.check_for_common_items_in_impls(
impl1_def_id,
impl2_def_id,
overlap,
true,
),
|| (),
);
}
|| (),
)
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/test/compile-fail/issue-43355.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![deny(incoherent_fundamental_impls)]

pub trait Trait1<X> {
type Output;
}
Expand All @@ -24,7 +22,6 @@ impl<X, T> Trait1<X> for T where T: Trait2<X> {

impl<X> Trait1<Box<X>> for A {
//~^ ERROR conflicting implementations of trait
//~| hard error
//~| downstream crates may implement trait `Trait2<std::boxed::Box<_>>` for type `A`
type Output = i32;
}
Expand Down
36 changes: 0 additions & 36 deletions src/test/run-pass/issue-43355.rs

This file was deleted.

0 comments on commit 70a2d80

Please sign in to comment.