Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1d34cb4

Browse files
committedNov 11, 2021
Auto merge of #89550 - lcnr:coherence-specialization, r=nikomatsakis
do not emit overlap errors for impls failing the orphan check this should finally allow us to merge #86986, see #86986 (comment) for more details. r? `@nikomatsakis` cc `@eddyb`
2 parents 9dbbbb1 + f55ff41 commit 1d34cb4

28 files changed

+501
-497
lines changed
 

‎compiler/rustc_middle/src/query/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,14 @@ rustc_queries! {
822822
desc { "check for overlap between inherent impls defined in this crate" }
823823
}
824824

825+
/// Checks whether all impls in the crate pass the overlap check, returning
826+
/// which impls fail it. If all impls are correct, the returned slice is empty.
827+
query orphan_check_crate(_: ()) -> &'tcx [LocalDefId] {
828+
desc {
829+
"checking whether the immpl in the this crate follow the orphan rules",
830+
}
831+
}
832+
825833
/// Check whether the function has any recursion that could cause the inliner to trigger
826834
/// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
827835
/// current function, just all intermediate functions.
@@ -1056,11 +1064,6 @@ rustc_queries! {
10561064
}
10571065

10581066
/// Return all `impl` blocks in the current crate.
1059-
///
1060-
/// To allow caching this between crates, you must pass in [`LOCAL_CRATE`] as the crate number.
1061-
/// Passing in any other crate will cause an ICE.
1062-
///
1063-
/// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE
10641067
query all_local_trait_impls(_: ()) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
10651068
desc { "local trait impls" }
10661069
}

‎compiler/rustc_trait_selection/src/traits/specialize/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ pub(super) fn specialization_graph_provider(
291291
sg
292292
}
293293

294+
// This function is only used when
295+
// encountering errors and inlining
296+
// it negatively impacts perf.
297+
#[cold]
298+
#[inline(never)]
294299
fn report_overlap_conflict(
295300
tcx: TyCtxt<'_>,
296301
overlap: OverlapError,
@@ -443,8 +448,12 @@ fn report_conflicting_impls(
443448
match used_to_be_allowed {
444449
None => {
445450
sg.has_errored = true;
446-
let err = struct_span_err!(tcx.sess, impl_span, E0119, "");
447-
decorate(LintDiagnosticBuilder::new(err));
451+
if overlap.with_impl.is_local() || !tcx.orphan_check_crate(()).contains(&impl_def_id) {
452+
let err = struct_span_err!(tcx.sess, impl_span, E0119, "");
453+
decorate(LintDiagnosticBuilder::new(err));
454+
} else {
455+
tcx.sess.delay_span_bug(impl_span, "impl should have failed the orphan check");
456+
}
448457
}
449458
Some(kind) => {
450459
let lint = match kind {

‎compiler/rustc_typeck/src/coherence/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,15 @@ pub fn provide(providers: &mut Providers) {
168168
use self::builtin::coerce_unsized_info;
169169
use self::inherent_impls::{crate_inherent_impls, inherent_impls};
170170
use self::inherent_impls_overlap::crate_inherent_impls_overlap_check;
171+
use self::orphan::orphan_check_crate;
171172

172173
*providers = Providers {
173174
coherent_trait,
174175
crate_inherent_impls,
175176
inherent_impls,
176177
crate_inherent_impls_overlap_check,
177178
coerce_unsized_info,
179+
orphan_check_crate,
178180
..*providers
179181
};
180182
}
@@ -195,13 +197,13 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) {
195197
}
196198

197199
pub fn check_coherence(tcx: TyCtxt<'_>) {
200+
tcx.sess.time("unsafety_checking", || unsafety::check(tcx));
201+
tcx.ensure().orphan_check_crate(());
202+
198203
for &trait_def_id in tcx.all_local_trait_impls(()).keys() {
199204
tcx.ensure().coherent_trait(trait_def_id);
200205
}
201206

202-
tcx.sess.time("unsafety_checking", || unsafety::check(tcx));
203-
tcx.sess.time("orphan_checking", || orphan::check(tcx));
204-
205207
// these queries are executed for side-effects (error reporting):
206208
tcx.ensure().crate_inherent_impls(());
207209
tcx.ensure().crate_inherent_impls_overlap_check(());

‎compiler/rustc_typeck/src/coherence/orphan.rs

Lines changed: 240 additions & 224 deletions
Large diffs are not rendered by default.

‎src/test/ui/coherence/coherence-cross-crate-conflict.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
extern crate trait_impl_conflict;
77
use trait_impl_conflict::Foo;
88

9-
impl<A> Foo for A {
10-
//~^ ERROR E0119
11-
//~| ERROR E0210
9+
impl<A> Foo for A { //~ ERROR E0210
1210
}
1311

1412
fn main() {
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
error[E0119]: conflicting implementations of trait `trait_impl_conflict::Foo` for type `isize`
2-
--> $DIR/coherence-cross-crate-conflict.rs:9:1
3-
|
4-
LL | impl<A> Foo for A {
5-
| ^^^^^^^^^^^^^^^^^
6-
|
7-
= note: conflicting implementation in crate `trait_impl_conflict`:
8-
- impl Foo for isize;
9-
101
error[E0210]: type parameter `A` must be used as the type parameter for some local type (e.g., `MyStruct<A>`)
112
--> $DIR/coherence-cross-crate-conflict.rs:9:6
123
|
@@ -16,7 +7,6 @@ LL | impl<A> Foo for A {
167
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
178
= note: only traits defined in the current crate can be implemented for a type parameter
189

19-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2011

21-
Some errors have detailed explanations: E0119, E0210.
22-
For more information about an error, try `rustc --explain E0119`.
12+
For more information about this error, try `rustc --explain E0210`.

‎src/test/ui/coherence/coherence-impl-trait-for-marker-trait-negative.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
error[E0371]: the object type `(dyn Object + Marker2 + 'static)` automatically implements the trait `Marker1`
2-
--> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:15:1
3-
|
4-
LL | impl !Marker1 for dyn Object + Marker2 { }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Object + Marker2 + 'static)` automatically implements trait `Marker1`
6-
7-
error[E0371]: the object type `(dyn Object + Marker2 + 'static)` automatically implements the trait `Marker2`
8-
--> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:17:1
9-
|
10-
LL | impl !Marker2 for dyn Object + Marker2 { }
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Object + Marker2 + 'static)` automatically implements trait `Marker2`
12-
131
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
142
--> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:23:1
153
|
@@ -33,6 +21,18 @@ error[E0321]: cross-crate traits with a default impl, like `Send`, can only be i
3321
LL | impl !Send for dyn Object + Marker2 {}
3422
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type
3523

24+
error[E0371]: the object type `(dyn Object + Marker2 + 'static)` automatically implements the trait `Marker1`
25+
--> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:15:1
26+
|
27+
LL | impl !Marker1 for dyn Object + Marker2 { }
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Object + Marker2 + 'static)` automatically implements trait `Marker1`
29+
30+
error[E0371]: the object type `(dyn Object + Marker2 + 'static)` automatically implements the trait `Marker2`
31+
--> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:17:1
32+
|
33+
LL | impl !Marker2 for dyn Object + Marker2 { }
34+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Object + Marker2 + 'static)` automatically implements trait `Marker2`
35+
3636
error: aborting due to 5 previous errors
3737

3838
Some errors have detailed explanations: E0117, E0321, E0371.

‎src/test/ui/coherence/coherence-impl-trait-for-marker-trait-positive.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
error[E0371]: the object type `(dyn Object + Marker2 + 'static)` automatically implements the trait `Marker1`
2-
--> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:15:1
3-
|
4-
LL | impl Marker1 for dyn Object + Marker2 { }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Object + Marker2 + 'static)` automatically implements trait `Marker1`
6-
7-
error[E0371]: the object type `(dyn Object + Marker2 + 'static)` automatically implements the trait `Marker2`
8-
--> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:17:1
9-
|
10-
LL | impl Marker2 for dyn Object + Marker2 { }
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Object + Marker2 + 'static)` automatically implements trait `Marker2`
12-
131
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
142
--> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:23:1
153
|
@@ -33,6 +21,18 @@ error[E0321]: cross-crate traits with a default impl, like `Send`, can only be i
3321
LL | unsafe impl Send for dyn Object + Marker2 {}
3422
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type
3523

24+
error[E0371]: the object type `(dyn Object + Marker2 + 'static)` automatically implements the trait `Marker1`
25+
--> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:15:1
26+
|
27+
LL | impl Marker1 for dyn Object + Marker2 { }
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Object + Marker2 + 'static)` automatically implements trait `Marker1`
29+
30+
error[E0371]: the object type `(dyn Object + Marker2 + 'static)` automatically implements the trait `Marker2`
31+
--> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:17:1
32+
|
33+
LL | impl Marker2 for dyn Object + Marker2 { }
34+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Object + Marker2 + 'static)` automatically implements trait `Marker2`
35+
3636
error: aborting due to 5 previous errors
3737

3838
Some errors have detailed explanations: E0117, E0321, E0371.

‎src/test/ui/coherence/coherence-impls-copy.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
use std::marker::Copy;
44

55
impl Copy for i32 {}
6-
//~^ ERROR E0119
7-
//~| ERROR E0117
6+
//~^ ERROR E0117
87
enum TestE {
98
A
109
}
@@ -32,7 +31,6 @@ impl Copy for [MyType] {}
3231
//~^ ERROR E0206
3332
//~| ERROR E0117
3433
impl Copy for &'static [NotSync] {}
35-
//~^ ERROR E0119
36-
//~| ERROR E0117
34+
//~^ ERROR E0117
3735
fn main() {
3836
}
Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,3 @@
1-
error[E0119]: conflicting implementations of trait `std::marker::Copy` for type `i32`
2-
--> $DIR/coherence-impls-copy.rs:5:1
3-
|
4-
LL | impl Copy for i32 {}
5-
| ^^^^^^^^^^^^^^^^^
6-
|
7-
= note: conflicting implementation in crate `core`:
8-
- impl Copy for i32;
9-
10-
error[E0119]: conflicting implementations of trait `std::marker::Copy` for type `&NotSync`
11-
--> $DIR/coherence-impls-copy.rs:29:1
12-
|
13-
LL | impl Copy for &'static NotSync {}
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15-
|
16-
= note: conflicting implementation in crate `core`:
17-
- impl<T> Copy for &T
18-
where T: ?Sized;
19-
20-
error[E0119]: conflicting implementations of trait `std::marker::Copy` for type `&[NotSync]`
21-
--> $DIR/coherence-impls-copy.rs:34:1
22-
|
23-
LL | impl Copy for &'static [NotSync] {}
24-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25-
|
26-
= note: conflicting implementation in crate `core`:
27-
- impl<T> Copy for &T
28-
where T: ?Sized;
29-
30-
error[E0206]: the trait `Copy` may not be implemented for this type
31-
--> $DIR/coherence-impls-copy.rs:22:15
32-
|
33-
LL | impl Copy for &'static mut MyType {}
34-
| ^^^^^^^^^^^^^^^^^^^ type is not a structure or enumeration
35-
36-
error[E0206]: the trait `Copy` may not be implemented for this type
37-
--> $DIR/coherence-impls-copy.rs:26:15
38-
|
39-
LL | impl Copy for (MyType, MyType) {}
40-
| ^^^^^^^^^^^^^^^^ type is not a structure or enumeration
41-
42-
error[E0206]: the trait `Copy` may not be implemented for this type
43-
--> $DIR/coherence-impls-copy.rs:31:15
44-
|
45-
LL | impl Copy for [MyType] {}
46-
| ^^^^^^^^ type is not a structure or enumeration
47-
481
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
492
--> $DIR/coherence-impls-copy.rs:5:1
503
|
@@ -57,7 +10,7 @@ LL | impl Copy for i32 {}
5710
= note: define and implement a trait or new type instead
5811

5912
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
60-
--> $DIR/coherence-impls-copy.rs:26:1
13+
--> $DIR/coherence-impls-copy.rs:25:1
6114
|
6215
LL | impl Copy for (MyType, MyType) {}
6316
| ^^^^^^^^^^^^^^----------------
@@ -68,7 +21,7 @@ LL | impl Copy for (MyType, MyType) {}
6821
= note: define and implement a trait or new type instead
6922

7023
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
71-
--> $DIR/coherence-impls-copy.rs:31:1
24+
--> $DIR/coherence-impls-copy.rs:30:1
7225
|
7326
LL | impl Copy for [MyType] {}
7427
| ^^^^^^^^^^^^^^--------
@@ -79,7 +32,7 @@ LL | impl Copy for [MyType] {}
7932
= note: define and implement a trait or new type instead
8033

8134
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
82-
--> $DIR/coherence-impls-copy.rs:34:1
35+
--> $DIR/coherence-impls-copy.rs:33:1
8336
|
8437
LL | impl Copy for &'static [NotSync] {}
8538
| ^^^^^^^^^^^^^^------------------
@@ -89,7 +42,35 @@ LL | impl Copy for &'static [NotSync] {}
8942
|
9043
= note: define and implement a trait or new type instead
9144

92-
error: aborting due to 10 previous errors
45+
error[E0119]: conflicting implementations of trait `std::marker::Copy` for type `&NotSync`
46+
--> $DIR/coherence-impls-copy.rs:28:1
47+
|
48+
LL | impl Copy for &'static NotSync {}
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
|
51+
= note: conflicting implementation in crate `core`:
52+
- impl<T> Copy for &T
53+
where T: ?Sized;
54+
55+
error[E0206]: the trait `Copy` may not be implemented for this type
56+
--> $DIR/coherence-impls-copy.rs:21:15
57+
|
58+
LL | impl Copy for &'static mut MyType {}
59+
| ^^^^^^^^^^^^^^^^^^^ type is not a structure or enumeration
60+
61+
error[E0206]: the trait `Copy` may not be implemented for this type
62+
--> $DIR/coherence-impls-copy.rs:25:15
63+
|
64+
LL | impl Copy for (MyType, MyType) {}
65+
| ^^^^^^^^^^^^^^^^ type is not a structure or enumeration
66+
67+
error[E0206]: the trait `Copy` may not be implemented for this type
68+
--> $DIR/coherence-impls-copy.rs:30:15
69+
|
70+
LL | impl Copy for [MyType] {}
71+
| ^^^^^^^^ type is not a structure or enumeration
72+
73+
error: aborting due to 8 previous errors
9374

9475
Some errors have detailed explanations: E0117, E0119, E0206.
9576
For more information about an error, try `rustc --explain E0117`.

‎src/test/ui/coherence/coherence-impls-send.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ unsafe impl Send for [MyType] {}
2323
//~^ ERROR E0117
2424

2525
unsafe impl Send for &'static [NotSync] {}
26-
//~^ ERROR conflicting implementations of trait
27-
//~| ERROR only traits defined in the current crate
26+
//~^ ERROR only traits defined in the current crate
2827

2928
fn main() {}

‎src/test/ui/coherence/coherence-impls-send.stderr

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
error[E0119]: conflicting implementations of trait `std::marker::Send` for type `&[NotSync]`
2-
--> $DIR/coherence-impls-send.rs:25:1
3-
|
4-
LL | unsafe impl Send for &'static [NotSync] {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: conflicting implementation in crate `core`:
8-
- impl<T> Send for &T
9-
where T: Sync, T: ?Sized;
10-
= note: upstream crates may add a new impl of trait `std::marker::Sync` for type `[NotSync]` in future versions
11-
121
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
132
--> $DIR/coherence-impls-send.rs:16:1
143
|
@@ -48,7 +37,7 @@ LL | unsafe impl Send for &'static [NotSync] {}
4837
|
4938
= note: define and implement a trait or new type instead
5039

51-
error: aborting due to 5 previous errors
40+
error: aborting due to 4 previous errors
5241

53-
Some errors have detailed explanations: E0117, E0119, E0321.
42+
Some errors have detailed explanations: E0117, E0321.
5443
For more information about an error, try `rustc --explain E0117`.

‎src/test/ui/coherence/coherence-impls-sized.stderr

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
2+
--> $DIR/coherence-impls-sized.rs:20:1
3+
|
4+
LL | impl Sized for (MyType, MyType) {}
5+
| ^^^^^^^^^^^^^^^----------------
6+
| | |
7+
| | this is not defined in the current crate because tuples are always foreign
8+
| impl doesn't use only types from inside the current crate
9+
|
10+
= note: define and implement a trait or new type instead
11+
12+
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
13+
--> $DIR/coherence-impls-sized.rs:27:1
14+
|
15+
LL | impl Sized for [MyType] {}
16+
| ^^^^^^^^^^^^^^^--------
17+
| | |
18+
| | this is not defined in the current crate because slices are always foreign
19+
| impl doesn't use only types from inside the current crate
20+
|
21+
= note: define and implement a trait or new type instead
22+
23+
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
24+
--> $DIR/coherence-impls-sized.rs:31:1
25+
|
26+
LL | impl Sized for &'static [NotSync] {}
27+
| ^^^^^^^^^^^^^^^------------------
28+
| | |
29+
| | this is not defined in the current crate because slices are always foreign
30+
| impl doesn't use only types from inside the current crate
31+
|
32+
= note: define and implement a trait or new type instead
33+
134
error[E0322]: explicit impls for the `Sized` trait are not permitted
235
--> $DIR/coherence-impls-sized.rs:14:1
336
|
@@ -34,39 +67,6 @@ error[E0322]: explicit impls for the `Sized` trait are not permitted
3467
LL | impl Sized for &'static [NotSync] {}
3568
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of 'Sized' not allowed
3669

37-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
38-
--> $DIR/coherence-impls-sized.rs:20:1
39-
|
40-
LL | impl Sized for (MyType, MyType) {}
41-
| ^^^^^^^^^^^^^^^----------------
42-
| | |
43-
| | this is not defined in the current crate because tuples are always foreign
44-
| impl doesn't use only types from inside the current crate
45-
|
46-
= note: define and implement a trait or new type instead
47-
48-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
49-
--> $DIR/coherence-impls-sized.rs:27:1
50-
|
51-
LL | impl Sized for [MyType] {}
52-
| ^^^^^^^^^^^^^^^--------
53-
| | |
54-
| | this is not defined in the current crate because slices are always foreign
55-
| impl doesn't use only types from inside the current crate
56-
|
57-
= note: define and implement a trait or new type instead
58-
59-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
60-
--> $DIR/coherence-impls-sized.rs:31:1
61-
|
62-
LL | impl Sized for &'static [NotSync] {}
63-
| ^^^^^^^^^^^^^^^------------------
64-
| | |
65-
| | this is not defined in the current crate because slices are always foreign
66-
| impl doesn't use only types from inside the current crate
67-
|
68-
= note: define and implement a trait or new type instead
69-
7070
error: aborting due to 9 previous errors
7171

7272
Some errors have detailed explanations: E0117, E0322.

‎src/test/ui/coherence/coherence-orphan.stderr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
2-
--> $DIR/coherence-orphan.rs:10:1
2+
--> $DIR/coherence-orphan.rs:17:1
33
|
4-
LL | impl TheTrait<usize> for isize { }
5-
| ^^^^^---------------^^^^^-----
6-
| | | |
7-
| | | `isize` is not defined in the current crate
8-
| | `usize` is not defined in the current crate
4+
LL | impl !Send for Vec<isize> { }
5+
| ^^^^^^^^^^^^^^^----------
6+
| | |
7+
| | `Vec` is not defined in the current crate
98
| impl doesn't use only types from inside the current crate
109
|
1110
= note: define and implement a trait or new type instead
1211

1312
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
14-
--> $DIR/coherence-orphan.rs:17:1
13+
--> $DIR/coherence-orphan.rs:10:1
1514
|
16-
LL | impl !Send for Vec<isize> { }
17-
| ^^^^^^^^^^^^^^^----------
18-
| | |
19-
| | `Vec` is not defined in the current crate
15+
LL | impl TheTrait<usize> for isize { }
16+
| ^^^^^---------------^^^^^-----
17+
| | | |
18+
| | | `isize` is not defined in the current crate
19+
| | `usize` is not defined in the current crate
2020
| impl doesn't use only types from inside the current crate
2121
|
2222
= note: define and implement a trait or new type instead

‎src/test/ui/dropck/drop-on-non-struct.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ error[E0412]: cannot find type `Nonexistent` in this scope
44
LL | impl Drop for Nonexistent {
55
| ^^^^^^^^^^^ not found in this scope
66

7-
error[E0120]: the `Drop` trait may only be implemented for structs, enums, and unions
8-
--> $DIR/drop-on-non-struct.rs:1:19
9-
|
10-
LL | impl<'a> Drop for &'a mut isize {
11-
| ^^^^^^^^^^^^^ must be a struct, enum, or union
12-
137
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
148
--> $DIR/drop-on-non-struct.rs:1:1
159
|
@@ -21,6 +15,12 @@ LL | impl<'a> Drop for &'a mut isize {
2115
|
2216
= note: define and implement a trait or new type instead
2317

18+
error[E0120]: the `Drop` trait may only be implemented for structs, enums, and unions
19+
--> $DIR/drop-on-non-struct.rs:1:19
20+
|
21+
LL | impl<'a> Drop for &'a mut isize {
22+
| ^^^^^^^^^^^^^ must be a struct, enum, or union
23+
2424
error: aborting due to 3 previous errors
2525

2626
Some errors have detailed explanations: E0117, E0120, E0412.

‎src/test/ui/error-codes/E0117.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
error[E0120]: the `Drop` trait may only be implemented for structs, enums, and unions
2-
--> $DIR/E0117.rs:1:15
3-
|
4-
LL | impl Drop for u32 {}
5-
| ^^^ must be a struct, enum, or union
6-
71
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
82
--> $DIR/E0117.rs:1:1
93
|
@@ -15,6 +9,12 @@ LL | impl Drop for u32 {}
159
|
1610
= note: define and implement a trait or new type instead
1711

12+
error[E0120]: the `Drop` trait may only be implemented for structs, enums, and unions
13+
--> $DIR/E0117.rs:1:15
14+
|
15+
LL | impl Drop for u32 {}
16+
| ^^^ must be a struct, enum, or union
17+
1818
error: aborting due to 2 previous errors
1919

2020
Some errors have detailed explanations: E0117, E0120.

‎src/test/ui/error-codes/e0119/complex-impl.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ use complex_impl_support::{External, M};
77
struct Q;
88

99
impl<R> External for (Q, R) {} //~ ERROR only traits defined
10-
//~^ ERROR conflicting implementations of trait
1110

1211
fn main() {}
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
error[E0119]: conflicting implementations of trait `complex_impl_support::External` for type `(Q, complex_impl_support::M<'_, '_, '_, std::boxed::Box<_>, _, _>)`
2-
--> $DIR/complex-impl.rs:9:1
3-
|
4-
LL | impl<R> External for (Q, R) {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: conflicting implementation in crate `complex_impl_support`:
8-
- impl<'a, 'b, 'c, T, U, V, W> External for (T, M<'a, 'b, 'c, Box<U>, V, W>)
9-
where <U as FnOnce<(T,)>>::Output == V, <V as Iterator>::Item == T, 'b: 'a, T: 'a, U: 'static, U: FnOnce<(T,)>, V: Iterator, V: Clone, W: Add, <W as Add>::Output: Copy;
10-
111
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
122
--> $DIR/complex-impl.rs:9:1
133
|
@@ -19,7 +9,6 @@ LL | impl<R> External for (Q, R) {}
199
|
2010
= note: define and implement a trait or new type instead
2111

22-
error: aborting due to 2 previous errors
12+
error: aborting due to previous error
2313

24-
Some errors have detailed explanations: E0117, E0119.
25-
For more information about an error, try `rustc --explain E0117`.
14+
For more information about this error, try `rustc --explain E0117`.

‎src/test/ui/error-codes/e0119/issue-28981.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ use std::ops::Deref;
33
struct Foo;
44

55
impl<Foo> Deref for Foo { } //~ ERROR must be used
6-
//~^ ERROR conflicting implementations
76

87
fn main() {}
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
error[E0119]: conflicting implementations of trait `std::ops::Deref` for type `&_`
2-
--> $DIR/issue-28981.rs:5:1
3-
|
4-
LL | impl<Foo> Deref for Foo { }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: conflicting implementation in crate `core`:
8-
- impl<T> Deref for &T
9-
where T: ?Sized;
10-
111
error[E0210]: type parameter `Foo` must be used as the type parameter for some local type (e.g., `MyStruct<Foo>`)
122
--> $DIR/issue-28981.rs:5:6
133
|
@@ -17,7 +7,6 @@ LL | impl<Foo> Deref for Foo { }
177
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
188
= note: only traits defined in the current crate can be implemented for a type parameter
199

20-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2111

22-
Some errors have detailed explanations: E0119, E0210.
23-
For more information about an error, try `rustc --explain E0119`.
12+
For more information about this error, try `rustc --explain E0210`.

‎src/test/ui/issues/issue-41974.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ struct Flags;
44
trait A {
55
}
66

7-
impl<T> Drop for T where T: A { //~ ERROR E0119
8-
//~^ ERROR E0120
9-
//~| ERROR E0210
7+
impl<T> Drop for T where T: A {
8+
//~^ ERROR E0120
9+
//~| ERROR E0210
1010
fn drop(&mut self) {
1111
}
1212
}

‎src/test/ui/issues/issue-41974.stderr

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
1-
error[E0119]: conflicting implementations of trait `std::ops::Drop` for type `std::boxed::Box<_, _>`
2-
--> $DIR/issue-41974.rs:7:1
1+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
2+
--> $DIR/issue-41974.rs:7:6
33
|
44
LL | impl<T> Drop for T where T: A {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^ type parameter `T` must be used as the type parameter for some local type
66
|
7-
= note: conflicting implementation in crate `alloc`:
8-
- impl<T, A> Drop for Box<T, A>
9-
where A: Allocator, T: ?Sized;
10-
= note: downstream crates may implement trait `A` for type `std::boxed::Box<_, _>`
7+
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
8+
= note: only traits defined in the current crate can be implemented for a type parameter
119

1210
error[E0120]: the `Drop` trait may only be implemented for structs, enums, and unions
1311
--> $DIR/issue-41974.rs:7:18
1412
|
1513
LL | impl<T> Drop for T where T: A {
1614
| ^ must be a struct, enum, or union
1715

18-
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
19-
--> $DIR/issue-41974.rs:7:6
20-
|
21-
LL | impl<T> Drop for T where T: A {
22-
| ^ type parameter `T` must be used as the type parameter for some local type
23-
|
24-
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
25-
= note: only traits defined in the current crate can be implemented for a type parameter
26-
27-
error: aborting due to 3 previous errors
16+
error: aborting due to 2 previous errors
2817

29-
Some errors have detailed explanations: E0119, E0120, E0210.
30-
For more information about an error, try `rustc --explain E0119`.
18+
Some errors have detailed explanations: E0120, E0210.
19+
For more information about an error, try `rustc --explain E0120`.

‎src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@
22

33
pub struct Int(i32);
44

5-
impl const std::ops::Add for i32 {
6-
//~^ ERROR conflicting implementations of trait
7-
//~| ERROR only traits defined in the current crate can be implemented for arbitrary types
5+
impl const std::ops::Add for i32 { //~ ERROR type annotations needed
6+
//~^ ERROR only traits defined in the current crate can be implemented for arbitrary types
87
type Output = Self;
98

109
fn add(self, rhs: Self) -> Self {
1110
self + rhs
1211
}
1312
}
1413

15-
impl std::ops::Add for Int {
14+
impl std::ops::Add for Int { //~ ERROR type annotations needed
1615
type Output = Self;
1716

1817
fn add(self, rhs: Self) -> Self {
1918
Int(self.0 + rhs.0)
2019
}
2120
}
2221

23-
impl const std::ops::Add for Int {
22+
impl const std::ops::Add for Int { //~ ERROR type annotations needed
2423
//~^ ERROR conflicting implementations of trait
2524
type Output = Self;
2625

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,101 @@
1-
error[E0119]: conflicting implementations of trait `std::ops::Add` for type `i32`
1+
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
22
--> $DIR/const-and-non-const-impl.rs:5:1
33
|
44
LL | impl const std::ops::Add for i32 {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^-------------^^^^^---
6+
| | | |
7+
| | | `i32` is not defined in the current crate
8+
| | `i32` is not defined in the current crate
9+
| impl doesn't use only types from inside the current crate
610
|
7-
= note: conflicting implementation in crate `core`:
8-
- impl Add for i32;
11+
= note: define and implement a trait or new type instead
912

1013
error[E0119]: conflicting implementations of trait `std::ops::Add` for type `Int`
11-
--> $DIR/const-and-non-const-impl.rs:23:1
14+
--> $DIR/const-and-non-const-impl.rs:22:1
1215
|
1316
LL | impl std::ops::Add for Int {
1417
| -------------------------- first implementation here
1518
...
1619
LL | impl const std::ops::Add for Int {
1720
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Int`
1821

19-
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
22+
error[E0283]: type annotations needed
23+
--> $DIR/const-and-non-const-impl.rs:5:12
24+
|
25+
LL | impl const std::ops::Add for i32 {
26+
| ^^^^^^^^^^^^^ cannot infer type for type `i32`
27+
|
28+
note: multiple `impl`s satisfying `i32: Add` found
2029
--> $DIR/const-and-non-const-impl.rs:5:1
2130
|
2231
LL | impl const std::ops::Add for i32 {
23-
| ^^^^^^^^^^^-------------^^^^^---
24-
| | | |
25-
| | | `i32` is not defined in the current crate
26-
| | `i32` is not defined in the current crate
27-
| impl doesn't use only types from inside the current crate
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
= note: and another `impl` found in the `core` crate: `impl Add for i32;`
34+
note: required by a bound in `Add`
35+
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
2836
|
29-
= note: define and implement a trait or new type instead
37+
LL | / pub trait Add<Rhs = Self> {
38+
LL | | /// The resulting type after applying the `+` operator.
39+
LL | | #[stable(feature = "rust1", since = "1.0.0")]
40+
LL | | type Output;
41+
... |
42+
LL | | fn add(self, rhs: Rhs) -> Self::Output;
43+
LL | | }
44+
| |_^ required by this bound in `Add`
45+
46+
error[E0283]: type annotations needed
47+
--> $DIR/const-and-non-const-impl.rs:14:6
48+
|
49+
LL | impl std::ops::Add for Int {
50+
| ^^^^^^^^^^^^^ cannot infer type for struct `Int`
51+
|
52+
note: multiple `impl`s satisfying `Int: Add` found
53+
--> $DIR/const-and-non-const-impl.rs:14:1
54+
|
55+
LL | impl std::ops::Add for Int {
56+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
57+
...
58+
LL | impl const std::ops::Add for Int {
59+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60+
note: required by a bound in `Add`
61+
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
62+
|
63+
LL | / pub trait Add<Rhs = Self> {
64+
LL | | /// The resulting type after applying the `+` operator.
65+
LL | | #[stable(feature = "rust1", since = "1.0.0")]
66+
LL | | type Output;
67+
... |
68+
LL | | fn add(self, rhs: Rhs) -> Self::Output;
69+
LL | | }
70+
| |_^ required by this bound in `Add`
71+
72+
error[E0283]: type annotations needed
73+
--> $DIR/const-and-non-const-impl.rs:22:12
74+
|
75+
LL | impl const std::ops::Add for Int {
76+
| ^^^^^^^^^^^^^ cannot infer type for struct `Int`
77+
|
78+
note: multiple `impl`s satisfying `Int: Add` found
79+
--> $DIR/const-and-non-const-impl.rs:14:1
80+
|
81+
LL | impl std::ops::Add for Int {
82+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
83+
...
84+
LL | impl const std::ops::Add for Int {
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86+
note: required by a bound in `Add`
87+
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
88+
|
89+
LL | / pub trait Add<Rhs = Self> {
90+
LL | | /// The resulting type after applying the `+` operator.
91+
LL | | #[stable(feature = "rust1", since = "1.0.0")]
92+
LL | | type Output;
93+
... |
94+
LL | | fn add(self, rhs: Rhs) -> Self::Output;
95+
LL | | }
96+
| |_^ required by this bound in `Add`
3097

31-
error: aborting due to 3 previous errors
98+
error: aborting due to 5 previous errors
3299

33-
Some errors have detailed explanations: E0117, E0119.
100+
Some errors have detailed explanations: E0117, E0119, E0283.
34101
For more information about an error, try `rustc --explain E0117`.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `impl OpaqueTrait`
2-
--> $DIR/issue-83613.rs:10:1
3-
|
4-
LL | impl<T: Send> AnotherTrait for T {}
5-
| -------------------------------- first implementation here
6-
LL | impl AnotherTrait for OpaqueType {}
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `impl OpaqueTrait`
8-
91
error: cannot implement trait on type alias impl trait
102
--> $DIR/issue-83613.rs:10:1
113
|
@@ -18,6 +10,14 @@ note: type alias impl trait defined here
1810
LL | type OpaqueType = impl OpaqueTrait;
1911
| ^^^^^^^^^^^^^^^^
2012

13+
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `impl OpaqueTrait`
14+
--> $DIR/issue-83613.rs:10:1
15+
|
16+
LL | impl<T: Send> AnotherTrait for T {}
17+
| -------------------------------- first implementation here
18+
LL | impl AnotherTrait for OpaqueType {}
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `impl OpaqueTrait`
20+
2121
error: aborting due to 2 previous errors
2222

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

‎src/test/ui/traits/issue-78372.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ LL | impl<T> DispatchFromDyn<Smaht<U, MISC>> for T {}
5050
|
5151
= help: add `#![feature(dispatch_from_dyn)]` to the crate attributes to enable
5252

53-
error[E0378]: the trait `DispatchFromDyn` may only be implemented for a coercion between structures
54-
--> $DIR/issue-78372.rs:3:1
55-
|
56-
LL | impl<T> DispatchFromDyn<Smaht<U, MISC>> for T {}
57-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
58-
5953
error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Smaht<[type error], [type error]>`)
6054
--> $DIR/issue-78372.rs:3:6
6155
|
@@ -65,6 +59,12 @@ LL | impl<T> DispatchFromDyn<Smaht<U, MISC>> for T {}
6559
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type
6660
= note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last
6761

62+
error[E0378]: the trait `DispatchFromDyn` may only be implemented for a coercion between structures
63+
--> $DIR/issue-78372.rs:3:1
64+
|
65+
LL | impl<T> DispatchFromDyn<Smaht<U, MISC>> for T {}
66+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67+
6868
error: aborting due to 7 previous errors
6969

7070
Some errors have detailed explanations: E0210, E0378, E0412, E0658.

‎src/test/ui/type-alias-impl-trait/incoherent-assoc-imp-trait.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ trait MyTrait {}
88
impl MyTrait for () {}
99

1010
impl<F> FnOnce<()> for &F {
11-
//~^ ERROR conflicting implementations
12-
//~| ERROR type parameter `F` must be used
11+
//~^ ERROR type parameter `F` must be used
1312
type Output = impl MyTrait;
1413
extern "rust-call" fn call_once(self, _: ()) -> Self::Output {}
1514
}
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
error[E0119]: conflicting implementations of trait `std::ops::FnOnce<()>` for type `&_`
2-
--> $DIR/incoherent-assoc-imp-trait.rs:10:1
3-
|
4-
LL | impl<F> FnOnce<()> for &F {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: conflicting implementation in crate `core`:
8-
- impl<A, F> FnOnce<A> for &F
9-
where F: Fn<A>, F: ?Sized;
10-
111
error[E0210]: type parameter `F` must be used as the type parameter for some local type (e.g., `MyStruct<F>`)
122
--> $DIR/incoherent-assoc-imp-trait.rs:10:6
133
|
@@ -17,7 +7,6 @@ LL | impl<F> FnOnce<()> for &F {
177
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
188
= note: only traits defined in the current crate can be implemented for a type parameter
199

20-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2111

22-
Some errors have detailed explanations: E0119, E0210.
23-
For more information about an error, try `rustc --explain E0119`.
12+
For more information about this error, try `rustc --explain E0210`.

0 commit comments

Comments
 (0)
Please sign in to comment.