Skip to content

Commit 9982e7d

Browse files
committed
lint: convert incoherent_fundamental_impls into hard error
Also remove it from lint listings.
1 parent 2975a3c commit 9982e7d

File tree

8 files changed

+34
-113
lines changed

8 files changed

+34
-113
lines changed

src/doc/rustc/src/lints/groups.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Here's a list of each lint group, and the lints that they are made up of:
2121
| edition-2018 | Lints that will be turned into errors in Rust 2018 | tyvar-behind-raw-pointer |
2222
| rust-2018-idioms | Lints to nudge you toward idiomatic features of Rust 2018 | bare-trait-object, unreachable-pub |
2323
| unused | These lints detect things being declared but not used | unused-imports, unused-variables, unused-assignments, dead-code, unused-mut, unreachable-code, unreachable-patterns, unused-must-use, unused-unsafe, path-statements, unused-attributes, unused-macros, unused-allocation, unused-doc-comment, unused-extern-crates, unused-features, unused-parens |
24-
| future-incompatible | Lints that detect code that has future-compatibility problems | private-in-public, pub-use-of-private-extern-crate, patterns-in-fns-without-body, safe-extern-statics, invalid-type-param-default, legacy-directory-ownership, legacy-imports, legacy-constructor-visibility, missing-fragment-specifier, illegal-floating-point-literal-pattern, anonymous-parameters, parenthesized-params-in-types-and-modules, late-bound-lifetime-arguments, safe-packed-borrows, incoherent-fundamental-impls, tyvar-behind-raw-pointer, unstable-name-collision |
24+
| future-incompatible | Lints that detect code that has future-compatibility problems | private-in-public, pub-use-of-private-extern-crate, patterns-in-fns-without-body, safe-extern-statics, invalid-type-param-default, legacy-directory-ownership, legacy-imports, legacy-constructor-visibility, missing-fragment-specifier, illegal-floating-point-literal-pattern, anonymous-parameters, parenthesized-params-in-types-and-modules, late-bound-lifetime-arguments, safe-packed-borrows, tyvar-behind-raw-pointer, unstable-name-collision |
2525

2626
Additionally, there's a `bad-style` lint group that's a deprecated alias for `nonstandard-style`.
2727

2828
Finally, you can also see the table above by invoking `rustc -W help`. This will give you the exact values for the specific
29-
compiler you have installed.
29+
compiler you have installed.

src/doc/rustc/src/lints/listing/deny-by-default.md

-41
Original file line numberDiff line numberDiff line change
@@ -222,44 +222,3 @@ error: invalid `crate_type` value
222222
| ^^^^^^^^^^^^^^^^^^^^
223223
|
224224
```
225-
226-
## incoherent-fundamental-impls
227-
228-
This lint detects potentially-conflicting impls that were erroneously allowed. Some
229-
example code that triggers this lint:
230-
231-
```rust,ignore
232-
pub trait Trait1<X> {
233-
type Output;
234-
}
235-
236-
pub trait Trait2<X> {}
237-
238-
pub struct A;
239-
240-
impl<X, T> Trait1<X> for T where T: Trait2<X> {
241-
type Output = ();
242-
}
243-
244-
impl<X> Trait1<Box<X>> for A {
245-
type Output = i32;
246-
}
247-
```
248-
249-
This will produce:
250-
251-
```text
252-
error: conflicting implementations of trait `Trait1<std::boxed::Box<_>>` for type `A`: (E0119)
253-
--> src/main.rs:13:1
254-
|
255-
9 | impl<X, T> Trait1<X> for T where T: Trait2<X> {
256-
| --------------------------------------------- first implementation here
257-
...
258-
13 | impl<X> Trait1<Box<X>> for A {
259-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `A`
260-
|
261-
= note: #[deny(incoherent_fundamental_impls)] on by default
262-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
263-
= note: for more information, see issue #46205 <https://github.com/rust-lang/rust/issues/46205>
264-
= note: downstream crates may implement trait `Trait2<std::boxed::Box<_>>` for type `A`
265-
```

src/librustc/lint/builtin.rs

-7
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,6 @@ declare_lint! {
198198
"detects generic lifetime arguments in path segments with late bound lifetime parameters"
199199
}
200200

201-
declare_lint! {
202-
pub INCOHERENT_FUNDAMENTAL_IMPLS,
203-
Deny,
204-
"potentially-conflicting impls were erroneously allowed"
205-
}
206-
207201
declare_lint! {
208202
pub ORDER_DEPENDENT_TRAIT_OBJECTS,
209203
Deny,
@@ -428,7 +422,6 @@ declare_lint_pass! {
428422
MISSING_FRAGMENT_SPECIFIER,
429423
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
430424
LATE_BOUND_LIFETIME_ARGUMENTS,
431-
INCOHERENT_FUNDAMENTAL_IMPLS,
432425
ORDER_DEPENDENT_TRAIT_OBJECTS,
433426
DEPRECATED,
434427
UNUSED_UNSAFE,

src/librustc/traits/specialize/mod.rs

+24-19
Original file line numberDiff line numberDiff line change
@@ -321,29 +321,34 @@ pub(super) fn specialization_graph_provider<'a, 'tcx>(
321321
String::new(), |ty| {
322322
format!(" for type `{}`", ty)
323323
}),
324-
if used_to_be_allowed.is_some() { " (E0119)" } else { "" }
324+
match used_to_be_allowed {
325+
Some(FutureCompatOverlapErrorKind::Issue33140) => " (E0119)",
326+
_ => "",
327+
}
325328
);
326329
let impl_span = tcx.sess.source_map().def_span(
327330
tcx.span_of_impl(impl_def_id).unwrap()
328331
);
329-
let mut err = if let Some(kind) = used_to_be_allowed {
330-
let lint = match kind {
331-
FutureCompatOverlapErrorKind::Issue43355 =>
332-
lint::builtin::INCOHERENT_FUNDAMENTAL_IMPLS,
333-
FutureCompatOverlapErrorKind::Issue33140 =>
334-
lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS,
335-
};
336-
tcx.struct_span_lint_hir(
337-
lint,
338-
tcx.hir().as_local_hir_id(impl_def_id).unwrap(),
339-
impl_span,
340-
&msg)
341-
} else {
342-
struct_span_err!(tcx.sess,
343-
impl_span,
344-
E0119,
345-
"{}",
346-
msg)
332+
let mut err = match used_to_be_allowed {
333+
Some(FutureCompatOverlapErrorKind::Issue43355) | None =>
334+
struct_span_err!(tcx.sess,
335+
impl_span,
336+
E0119,
337+
"{}",
338+
msg),
339+
Some(kind) => {
340+
let lint = match kind {
341+
FutureCompatOverlapErrorKind::Issue43355 =>
342+
unreachable!("converted to hard error above"),
343+
FutureCompatOverlapErrorKind::Issue33140 =>
344+
lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS,
345+
};
346+
tcx.struct_span_lint_hir(
347+
lint,
348+
tcx.hir().as_local_hir_id(impl_def_id).unwrap(),
349+
impl_span,
350+
&msg)
351+
}
347352
};
348353

349354
match tcx.span_of_impl(overlap.with_impl) {

src/librustc_lint/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
371371
reference: "issue #46043 <https://github.com/rust-lang/rust/issues/46043>",
372372
edition: None,
373373
},
374-
FutureIncompatibleInfo {
375-
id: LintId::of(INCOHERENT_FUNDAMENTAL_IMPLS),
376-
reference: "issue #46205 <https://github.com/rust-lang/rust/issues/46205>",
377-
edition: None,
378-
},
379374
FutureIncompatibleInfo {
380375
id: LintId::of(ORDER_DEPENDENT_TRAIT_OBJECTS),
381376
reference: "issue #56484 <https://github.com/rust-lang/rust/issues/56484>",
@@ -491,6 +486,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
491486
"replaced with a generic attribute input check");
492487
store.register_removed("duplicate_matcher_binding_name",
493488
"converted into hard error, see https://github.com/rust-lang/rust/issues/57742");
489+
store.register_removed("incoherent_fundamental_impls",
490+
"converted into hard error, see https://github.com/rust-lang/rust/issues/46205");
494491
}
495492

496493
pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) {

src/librustc_typeck/coherence/inherent_impls_overlap.rs

+4-34
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor;
55
use rustc::traits::{self, IntercrateMode};
66
use rustc::ty::TyCtxt;
77

8-
use crate::lint;
9-
108
pub fn crate_inherent_impls_overlap_check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
119
crate_num: CrateNum) {
1210
assert_eq!(crate_num, LOCAL_CRATE);
@@ -20,8 +18,7 @@ struct InherentOverlapChecker<'a, 'tcx: 'a> {
2018

2119
impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {
2220
fn check_for_common_items_in_impls(&self, impl1: DefId, impl2: DefId,
23-
overlap: traits::OverlapResult<'_>,
24-
used_to_be_allowed: bool) {
21+
overlap: traits::OverlapResult<'_>) {
2522

2623
let name_and_namespace = |def_id| {
2724
let item = self.tcx.associated_item(def_id);
@@ -36,22 +33,12 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {
3633

3734
for &item2 in &impl_items2[..] {
3835
if (name, namespace) == name_and_namespace(item2) {
39-
let hir_id = self.tcx.hir().as_local_hir_id(impl1);
40-
let mut err = if used_to_be_allowed && hir_id.is_some() {
41-
self.tcx.struct_span_lint_hir(
42-
lint::builtin::INCOHERENT_FUNDAMENTAL_IMPLS,
43-
hir_id.unwrap(),
44-
self.tcx.span_of_impl(item1).unwrap(),
45-
&format!("duplicate definitions with name `{}` (E0592)", name)
46-
)
47-
} else {
36+
let mut err =
4837
struct_span_err!(self.tcx.sess,
4938
self.tcx.span_of_impl(item1).unwrap(),
5039
E0592,
5140
"duplicate definitions with name `{}`",
52-
name)
53-
};
54-
41+
name);
5542
err.span_label(self.tcx.span_of_impl(item1).unwrap(),
5643
format!("duplicate definitions for `{}`", name));
5744
err.span_label(self.tcx.span_of_impl(item2).unwrap(),
@@ -76,7 +63,7 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {
7663

7764
for (i, &impl1_def_id) in impls.iter().enumerate() {
7865
for &impl2_def_id in &impls[(i + 1)..] {
79-
let used_to_be_allowed = traits::overlapping_impls(
66+
traits::overlapping_impls(
8067
self.tcx,
8168
impl1_def_id,
8269
impl2_def_id,
@@ -86,28 +73,11 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {
8673
impl1_def_id,
8774
impl2_def_id,
8875
overlap,
89-
false,
9076
);
9177
false
9278
},
9379
|| true,
9480
);
95-
96-
if used_to_be_allowed {
97-
traits::overlapping_impls(
98-
self.tcx,
99-
impl1_def_id,
100-
impl2_def_id,
101-
IntercrateMode::Fixed,
102-
|overlap| self.check_for_common_items_in_impls(
103-
impl1_def_id,
104-
impl2_def_id,
105-
overlap,
106-
true,
107-
),
108-
|| (),
109-
);
110-
}
11181
}
11282
}
11383
}

src/test/ui/issues/issue-43355.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ impl<X, T> Trait1<X> for T where T: Trait2<X> {
1212

1313
impl<X> Trait1<Box<X>> for A {
1414
//~^ ERROR conflicting implementations of trait
15-
//~| hard error
1615
//~| downstream crates may implement trait `Trait2<std::boxed::Box<_>>` for type `A`
1716
type Output = i32;
1817
}

src/test/ui/issues/issue-43355.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: conflicting implementations of trait `Trait1<std::boxed::Box<_>>` for type `A`: (E0119)
1+
error[E0119]: conflicting implementations of trait `Trait1<std::boxed::Box<_>>` for type `A`:
22
--> $DIR/issue-43355.rs:13:1
33
|
44
LL | impl<X, T> Trait1<X> for T where T: Trait2<X> {
@@ -7,10 +7,8 @@ LL | impl<X, T> Trait1<X> for T where T: Trait2<X> {
77
LL | impl<X> Trait1<Box<X>> for A {
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `A`
99
|
10-
= note: #[deny(incoherent_fundamental_impls)] on by default
11-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
12-
= note: for more information, see issue #46205 <https://github.com/rust-lang/rust/issues/46205>
1310
= note: downstream crates may implement trait `Trait2<std::boxed::Box<_>>` for type `A`
1411

1512
error: aborting due to previous error
1613

14+
For more information about this error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)