From 70a2d8043b85a4721c1f78ff8628122e48aca2b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=A0ng=20=C4=90=E1=BB=A9c=20Hi=E1=BA=BFu?= Date: Mon, 9 Apr 2018 14:17:46 +0700 Subject: [PATCH] lint: convert incoherent_fundamental_impls into hard error implement #46205 --- src/librustc/lint/builtin.rs | 7 --- src/librustc/traits/specialize/mod.rs | 29 ++-------- src/librustc_lint/lib.rs | 7 +-- .../coherence/inherent_impls_overlap.rs | 57 ++++--------------- src/test/compile-fail/issue-43355.rs | 3 - src/test/run-pass/issue-43355.rs | 36 ------------ 6 files changed, 20 insertions(+), 119 deletions(-) delete mode 100644 src/test/run-pass/issue-43355.rs diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 97cfcf0f60795..0ef0520d08bcc 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -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, @@ -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, diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 30b2c55afa194..a107723b0efe0 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -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. @@ -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) => { diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index c915181213d38..c4314b0f8c241 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -262,11 +262,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { reference: "issue #46043 ", edition: None, }, - FutureIncompatibleInfo { - id: LintId::of(INCOHERENT_FUNDAMENTAL_IMPLS), - reference: "issue #46205 ", - edition: None, - }, FutureIncompatibleInfo { id: LintId::of(TYVAR_BEHIND_RAW_POINTER), reference: "issue #46906 ", @@ -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"); } diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs index 88a2dc817ae63..0acf0eaa6f4c8 100644 --- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs +++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs @@ -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); @@ -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); @@ -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)); @@ -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, - ), - || (), - ); - } + || (), + ) } } } diff --git a/src/test/compile-fail/issue-43355.rs b/src/test/compile-fail/issue-43355.rs index 4db5c84df9a63..b379507c1dbd8 100644 --- a/src/test/compile-fail/issue-43355.rs +++ b/src/test/compile-fail/issue-43355.rs @@ -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 { type Output; } @@ -24,7 +22,6 @@ impl Trait1 for T where T: Trait2 { impl Trait1> for A { //~^ ERROR conflicting implementations of trait -//~| hard error //~| downstream crates may implement trait `Trait2>` for type `A` type Output = i32; } diff --git a/src/test/run-pass/issue-43355.rs b/src/test/run-pass/issue-43355.rs deleted file mode 100644 index 19431a6a42923..0000000000000 --- a/src/test/run-pass/issue-43355.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Check that the code for issue #43355 can run without an ICE, please remove -// this test when it becomes an hard error. - -pub trait Trait1 { - type Output; -} -pub trait Trait2 {} - -impl Trait1 for T where T: Trait2 { - type Output = (); -} -impl Trait1> for A { - type Output = i32; -} - -pub struct A; - -fn f>>() { - println!("k: {}", ::std::mem::size_of::<>>::Output>()); -} - -pub fn g>>() { - f::(); -} - -fn main() {}