Skip to content

Commit 00ed4ed

Browse files
committed
Auto merge of rust-lang#123674 - oli-obk:bogus_note, r=estebank
Silence some follow-up errors on trait impls in case the trait has conflicting or otherwise incoherent impls fixes rust-lang#123292 Also removes a bunch of extra diagnostics that were introduced in rust-lang#121154 and rust-lang#120558
2 parents 6c6b302 + c0a9c8c commit 00ed4ed

11 files changed

+55
-109
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,14 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
660660
}
661661
DefKind::Impl { of_trait } => {
662662
if of_trait && let Some(impl_trait_header) = tcx.impl_trait_header(def_id) {
663-
check_impl_items_against_trait(tcx, def_id, impl_trait_header);
664-
check_on_unimplemented(tcx, def_id);
663+
if tcx
664+
.ensure()
665+
.coherent_trait(impl_trait_header.trait_ref.instantiate_identity().def_id)
666+
.is_ok()
667+
{
668+
check_impl_items_against_trait(tcx, def_id, impl_trait_header);
669+
check_on_unimplemented(tcx, def_id);
670+
}
665671
}
666672
}
667673
DefKind::Trait => {

tests/ui/coherence/coherence-blanket-conflicts-with-specific-multidispatch.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ struct MyType {
2222
impl MyTrait<MyType> for MyType {
2323
//~^ ERROR E0119
2424
fn get(&self) -> usize { (*self).clone() }
25-
//~^ ERROR incompatible type
26-
//~| ERROR mismatched types
25+
//~^ ERROR mismatched types
2726
}
2827

2928
fn main() { }

tests/ui/coherence/coherence-blanket-conflicts-with-specific-multidispatch.stderr

+3-20
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,6 @@ LL | impl<T> MyTrait<T> for T {
77
LL | impl MyTrait<MyType> for MyType {
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyType`
99

10-
error[E0053]: method `get` has an incompatible type for trait
11-
--> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:24:22
12-
|
13-
LL | fn get(&self) -> usize { (*self).clone() }
14-
| ^^^^^
15-
| |
16-
| expected `MyType`, found `usize`
17-
| help: change the output type to match the trait: `MyType`
18-
|
19-
note: type in trait
20-
--> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:8:22
21-
|
22-
LL | fn get(&self) -> T;
23-
| ^
24-
= note: expected signature `fn(&MyType) -> MyType`
25-
found signature `fn(&MyType) -> usize`
26-
2710
error[E0308]: mismatched types
2811
--> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:24:30
2912
|
@@ -32,7 +15,7 @@ LL | fn get(&self) -> usize { (*self).clone() }
3215
| |
3316
| expected `usize` because of return type
3417

35-
error: aborting due to 3 previous errors
18+
error: aborting due to 2 previous errors
3619

37-
Some errors have detailed explanations: E0053, E0119, E0308.
38-
For more information about an error, try `rustc --explain E0053`.
20+
Some errors have detailed explanations: E0119, E0308.
21+
For more information about an error, try `rustc --explain E0119`.

tests/ui/coherence/coherence-orphan.rs

-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ struct TheType;
99

1010
impl TheTrait<usize> for isize {}
1111
//~^ ERROR E0117
12-
//~| ERROR not all trait items implemented
1312

1413
impl TheTrait<TheType> for isize {}
15-
//~^ ERROR not all trait items implemented
1614

1715
impl TheTrait<isize> for TheType {}
18-
//~^ ERROR not all trait items implemented
1916

2017
impl !Send for Vec<isize> {} //~ ERROR E0117
2118

tests/ui/coherence/coherence-orphan.stderr

+3-28
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,8 @@ LL | impl TheTrait<usize> for isize {}
1010
|
1111
= note: define and implement a trait or new type instead
1212

13-
error[E0046]: not all trait items implemented, missing: `the_fn`
14-
--> $DIR/coherence-orphan.rs:10:1
15-
|
16-
LL | impl TheTrait<usize> for isize {}
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `the_fn` in implementation
18-
|
19-
= help: implement the missing item: `fn the_fn(&self) { todo!() }`
20-
21-
error[E0046]: not all trait items implemented, missing: `the_fn`
22-
--> $DIR/coherence-orphan.rs:14:1
23-
|
24-
LL | impl TheTrait<TheType> for isize {}
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `the_fn` in implementation
26-
|
27-
= help: implement the missing item: `fn the_fn(&self) { todo!() }`
28-
29-
error[E0046]: not all trait items implemented, missing: `the_fn`
30-
--> $DIR/coherence-orphan.rs:17:1
31-
|
32-
LL | impl TheTrait<isize> for TheType {}
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `the_fn` in implementation
34-
|
35-
= help: implement the missing item: `fn the_fn(&self) { todo!() }`
36-
3713
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
38-
--> $DIR/coherence-orphan.rs:20:1
14+
--> $DIR/coherence-orphan.rs:17:1
3915
|
4016
LL | impl !Send for Vec<isize> {}
4117
| ^^^^^^^^^^^^^^^----------
@@ -45,7 +21,6 @@ LL | impl !Send for Vec<isize> {}
4521
|
4622
= note: define and implement a trait or new type instead
4723

48-
error: aborting due to 5 previous errors
24+
error: aborting due to 2 previous errors
4925

50-
Some errors have detailed explanations: E0046, E0117.
51-
For more information about an error, try `rustc --explain E0046`.
26+
For more information about this error, try `rustc --explain E0117`.

tests/ui/error-codes/E0117.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
impl Drop for u32 {} //~ ERROR E0117
22
//~| ERROR the `Drop` trait may only be implemented for local structs, enums, and unions
3-
//~| ERROR not all trait items implemented
43

54
fn main() {}

tests/ui/error-codes/E0117.stderr

+3-11
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@ error[E0120]: the `Drop` trait may only be implemented for local structs, enums,
1515
LL | impl Drop for u32 {}
1616
| ^^^ must be a struct, enum, or union in the current crate
1717

18-
error[E0046]: not all trait items implemented, missing: `drop`
19-
--> $DIR/E0117.rs:1:1
20-
|
21-
LL | impl Drop for u32 {}
22-
| ^^^^^^^^^^^^^^^^^ missing `drop` in implementation
23-
|
24-
= help: implement the missing item: `fn drop(&mut self) { todo!() }`
25-
26-
error: aborting due to 3 previous errors
18+
error: aborting due to 2 previous errors
2719

28-
Some errors have detailed explanations: E0046, E0117, E0120.
29-
For more information about an error, try `rustc --explain E0046`.
20+
Some errors have detailed explanations: E0117, E0120.
21+
For more information about an error, try `rustc --explain E0117`.

tests/ui/issues/issue-67535.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ fn main() {}
22

33
impl std::ops::AddAssign for () {
44
//~^ ERROR only traits defined in the current crate can be implemented for arbitrary types
5-
fn add_assign(&self, other: ()) -> () { //~ ERROR incompatible type
5+
fn add_assign(&self, other: ()) -> () {
66
()
77
}
88
}
99

1010
impl std::ops::AddAssign for [(); 1] {
1111
//~^ ERROR only traits defined in the current crate can be implemented for arbitrary types
12-
fn add_assign(&self, other: [(); 1]) -> [(); 1] { //~ ERROR incompatible type
12+
fn add_assign(&self, other: [(); 1]) -> [(); 1] {
1313
[()]
1414
}
1515
}
1616

1717
impl std::ops::AddAssign for &[u8] {
1818
//~^ ERROR only traits defined in the current crate can be implemented for arbitrary types
19-
fn add_assign(&self, other: &[u8]) -> &[u8] { //~ ERROR incompatible type
19+
fn add_assign(&self, other: &[u8]) -> &[u8] {
2020
self
2121
}
2222
}

tests/ui/issues/issue-67535.stderr

+2-39
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,6 @@ LL | impl std::ops::AddAssign for &[u8] {
3434
|
3535
= note: define and implement a trait or new type instead
3636

37-
error[E0053]: method `add_assign` has an incompatible type for trait
38-
--> $DIR/issue-67535.rs:5:19
39-
|
40-
LL | fn add_assign(&self, other: ()) -> () {
41-
| ^^^^^
42-
| |
43-
| types differ in mutability
44-
| help: change the self-receiver type to match the trait: `&mut self`
45-
|
46-
= note: expected signature `fn(&mut (), ())`
47-
found signature `fn(&(), ())`
48-
49-
error[E0053]: method `add_assign` has an incompatible type for trait
50-
--> $DIR/issue-67535.rs:12:19
51-
|
52-
LL | fn add_assign(&self, other: [(); 1]) -> [(); 1] {
53-
| ^^^^^
54-
| |
55-
| types differ in mutability
56-
| help: change the self-receiver type to match the trait: `&mut self`
57-
|
58-
= note: expected signature `fn(&mut _, _)`
59-
found signature `fn(&_, _) -> [(); 1]`
60-
61-
error[E0053]: method `add_assign` has an incompatible type for trait
62-
--> $DIR/issue-67535.rs:19:19
63-
|
64-
LL | fn add_assign(&self, other: &[u8]) -> &[u8] {
65-
| ^^^^^
66-
| |
67-
| types differ in mutability
68-
| help: change the self-receiver type to match the trait: `&mut self`
69-
|
70-
= note: expected signature `fn(&mut &_, &_)`
71-
found signature `fn(&&_, &_) -> &[u8]`
72-
73-
error: aborting due to 6 previous errors
37+
error: aborting due to 3 previous errors
7438

75-
Some errors have detailed explanations: E0053, E0117.
76-
For more information about an error, try `rustc --explain E0053`.
39+
For more information about this error, try `rustc --explain E0117`.

tests/ui/wf/conflicting-impls.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ edition: 2021
2+
3+
struct Ty;
4+
5+
impl TryFrom<Ty> for u8 {
6+
type Error = Ty;
7+
fn try_from(_: Ty) -> Result<Self, Self::Error> {
8+
loop {}
9+
}
10+
}
11+
12+
impl TryFrom<Ty> for u8 {
13+
//~^ ERROR conflicting implementations of trait
14+
type Error = Ty;
15+
fn try_from(_: Ty) -> Result<Self, Self::Error> {
16+
loop {}
17+
}
18+
}
19+
20+
fn main() {}

tests/ui/wf/conflicting-impls.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0119]: conflicting implementations of trait `TryFrom<Ty>` for type `u8`
2+
--> $DIR/conflicting-impls.rs:12:1
3+
|
4+
LL | impl TryFrom<Ty> for u8 {
5+
| ----------------------- first implementation here
6+
...
7+
LL | impl TryFrom<Ty> for u8 {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `u8`
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)