Skip to content

Commit 321162b

Browse files
committedMay 5, 2022
update error messages and explicitly mention them in tests
1 parent ba0ecbd commit 321162b

File tree

5 files changed

+54
-34
lines changed

5 files changed

+54
-34
lines changed
 

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'tcx> InherentCollect<'tcx> {
149149
self.tcx.sess,
150150
item.span,
151151
E0390,
152-
"cannot define inherent `impl` for a type outside of crate where the type is defined",
152+
"cannot define inherent `impl` for a type outside of the crate where the type is defined",
153153
)
154154
.help(INTO_DEFINING_CRATE)
155155
.span_help(item.span, ADD_ATTR_TO_TY)
@@ -166,7 +166,7 @@ impl<'tcx> InherentCollect<'tcx> {
166166
self.tcx.sess,
167167
item.span,
168168
E0390,
169-
"cannot define inherent `impl` for a type outside of crate where the type is defined",
169+
"cannot define inherent `impl` for a type outside of the crate where the type is defined",
170170
)
171171
.help(INTO_DEFINING_CRATE)
172172
.span_help(impl_item.span, ADD_ATTR)

‎src/test/ui/incoherent-inherent-impls/needs-has-incoherent-impls.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,37 @@
22
#![feature(rustc_attrs)]
33
extern crate extern_crate;
44

5-
impl extern_crate::StructWithAttr { //~ ERROR
5+
impl extern_crate::StructWithAttr {
6+
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
67
fn foo() {}
78
}
89
impl extern_crate::StructWithAttr {
910
#[rustc_allow_incoherent_impl]
1011
fn bar() {}
1112
}
12-
impl extern_crate::StructNoAttr { //~ ERROR
13+
impl extern_crate::StructNoAttr {
14+
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
1315
fn foo() {}
1416
}
15-
impl extern_crate::StructNoAttr { //~ ERROR
17+
impl extern_crate::StructNoAttr {
18+
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
1619
#[rustc_allow_incoherent_impl]
1720
fn bar() {}
1821
}
19-
impl extern_crate::EnumWithAttr { //~ ERROR
22+
impl extern_crate::EnumWithAttr {
23+
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
2024
fn foo() {}
2125
}
2226
impl extern_crate::EnumWithAttr {
2327
#[rustc_allow_incoherent_impl]
2428
fn bar() {}
2529
}
26-
impl extern_crate::EnumNoAttr { //~ ERROR
30+
impl extern_crate::EnumNoAttr {
31+
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
2732
fn foo() {}
2833
}
29-
impl extern_crate::EnumNoAttr { //~ ERROR
34+
impl extern_crate::EnumNoAttr {
35+
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
3036
#[rustc_allow_incoherent_impl]
3137
fn bar() {}
3238
}

‎src/test/ui/incoherent-inherent-impls/needs-has-incoherent-impls.stderr

+27-17
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,110 @@
1-
error[E0390]: cannot define inherent `impl` for a type outside of crate where the type is defined
1+
error[E0390]: cannot define inherent `impl` for a type outside of the crate where the type is defined
22
--> $DIR/needs-has-incoherent-impls.rs:5:1
33
|
44
LL | / impl extern_crate::StructWithAttr {
5+
LL | |
56
LL | | fn foo() {}
67
LL | | }
78
| |_^
89
|
910
= help: consider moving this inherent impl into the crate defining the type if possible
1011
help: alternatively add `#[rustc_allow_incoherent_impl]` to the relevant impl items
11-
--> $DIR/needs-has-incoherent-impls.rs:6:5
12+
--> $DIR/needs-has-incoherent-impls.rs:7:5
1213
|
1314
LL | fn foo() {}
1415
| ^^^^^^^^^^^
1516

16-
error[E0390]: cannot define inherent `impl` for a type outside of crate where the type is defined
17-
--> $DIR/needs-has-incoherent-impls.rs:12:1
17+
error[E0390]: cannot define inherent `impl` for a type outside of the crate where the type is defined
18+
--> $DIR/needs-has-incoherent-impls.rs:13:1
1819
|
1920
LL | / impl extern_crate::StructNoAttr {
21+
LL | |
2022
LL | | fn foo() {}
2123
LL | | }
2224
| |_^
2325
|
2426
= help: consider moving this inherent impl into the crate defining the type if possible
2527
help: alternatively add `#[rustc_has_incoherent_inherent_impls]` to the type and `#[rustc_allow_incoherent_impl]` to the relevant impl items
26-
--> $DIR/needs-has-incoherent-impls.rs:12:1
28+
--> $DIR/needs-has-incoherent-impls.rs:13:1
2729
|
2830
LL | / impl extern_crate::StructNoAttr {
31+
LL | |
2932
LL | | fn foo() {}
3033
LL | | }
3134
| |_^
3235

33-
error[E0390]: cannot define inherent `impl` for a type outside of crate where the type is defined
34-
--> $DIR/needs-has-incoherent-impls.rs:15:1
36+
error[E0390]: cannot define inherent `impl` for a type outside of the crate where the type is defined
37+
--> $DIR/needs-has-incoherent-impls.rs:17:1
3538
|
3639
LL | / impl extern_crate::StructNoAttr {
40+
LL | |
3741
LL | | #[rustc_allow_incoherent_impl]
3842
LL | | fn bar() {}
3943
LL | | }
4044
| |_^
4145
|
4246
= help: consider moving this inherent impl into the crate defining the type if possible
4347
help: alternatively add `#[rustc_has_incoherent_inherent_impls]` to the type and `#[rustc_allow_incoherent_impl]` to the relevant impl items
44-
--> $DIR/needs-has-incoherent-impls.rs:15:1
48+
--> $DIR/needs-has-incoherent-impls.rs:17:1
4549
|
4650
LL | / impl extern_crate::StructNoAttr {
51+
LL | |
4752
LL | | #[rustc_allow_incoherent_impl]
4853
LL | | fn bar() {}
4954
LL | | }
5055
| |_^
5156

52-
error[E0390]: cannot define inherent `impl` for a type outside of crate where the type is defined
53-
--> $DIR/needs-has-incoherent-impls.rs:19:1
57+
error[E0390]: cannot define inherent `impl` for a type outside of the crate where the type is defined
58+
--> $DIR/needs-has-incoherent-impls.rs:22:1
5459
|
5560
LL | / impl extern_crate::EnumWithAttr {
61+
LL | |
5662
LL | | fn foo() {}
5763
LL | | }
5864
| |_^
5965
|
6066
= help: consider moving this inherent impl into the crate defining the type if possible
6167
help: alternatively add `#[rustc_allow_incoherent_impl]` to the relevant impl items
62-
--> $DIR/needs-has-incoherent-impls.rs:20:5
68+
--> $DIR/needs-has-incoherent-impls.rs:24:5
6369
|
6470
LL | fn foo() {}
6571
| ^^^^^^^^^^^
6672

67-
error[E0390]: cannot define inherent `impl` for a type outside of crate where the type is defined
68-
--> $DIR/needs-has-incoherent-impls.rs:26:1
73+
error[E0390]: cannot define inherent `impl` for a type outside of the crate where the type is defined
74+
--> $DIR/needs-has-incoherent-impls.rs:30:1
6975
|
7076
LL | / impl extern_crate::EnumNoAttr {
77+
LL | |
7178
LL | | fn foo() {}
7279
LL | | }
7380
| |_^
7481
|
7582
= help: consider moving this inherent impl into the crate defining the type if possible
7683
help: alternatively add `#[rustc_has_incoherent_inherent_impls]` to the type and `#[rustc_allow_incoherent_impl]` to the relevant impl items
77-
--> $DIR/needs-has-incoherent-impls.rs:26:1
84+
--> $DIR/needs-has-incoherent-impls.rs:30:1
7885
|
7986
LL | / impl extern_crate::EnumNoAttr {
87+
LL | |
8088
LL | | fn foo() {}
8189
LL | | }
8290
| |_^
8391

84-
error[E0390]: cannot define inherent `impl` for a type outside of crate where the type is defined
85-
--> $DIR/needs-has-incoherent-impls.rs:29:1
92+
error[E0390]: cannot define inherent `impl` for a type outside of the crate where the type is defined
93+
--> $DIR/needs-has-incoherent-impls.rs:34:1
8694
|
8795
LL | / impl extern_crate::EnumNoAttr {
96+
LL | |
8897
LL | | #[rustc_allow_incoherent_impl]
8998
LL | | fn bar() {}
9099
LL | | }
91100
| |_^
92101
|
93102
= help: consider moving this inherent impl into the crate defining the type if possible
94103
help: alternatively add `#[rustc_has_incoherent_inherent_impls]` to the type and `#[rustc_allow_incoherent_impl]` to the relevant impl items
95-
--> $DIR/needs-has-incoherent-impls.rs:29:1
104+
--> $DIR/needs-has-incoherent-impls.rs:34:1
96105
|
97106
LL | / impl extern_crate::EnumNoAttr {
107+
LL | |
98108
LL | | #[rustc_allow_incoherent_impl]
99109
LL | | fn bar() {}
100110
LL | | }
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
// aux-build:extern-crate.rs
22
extern crate extern_crate;
33

4-
impl extern_crate::StructWithAttr {} //~ ERROR
4+
impl extern_crate::StructWithAttr {}
5+
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
56

6-
impl extern_crate::StructNoAttr {} //~ ERROR
7+
impl extern_crate::StructNoAttr {}
8+
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
79

8-
impl extern_crate::EnumWithAttr {} //~ ERROR
10+
impl extern_crate::EnumWithAttr {}
11+
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
912

10-
impl extern_crate::EnumNoAttr {} //~ ERROR
13+
impl extern_crate::EnumNoAttr {}
14+
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
1115

12-
impl f32 {} //~ ERROR
16+
impl f32 {} //~ ERROR cannot define inherent `impl` for primitive types
1317

1418
fn main() {}

‎src/test/ui/incoherent-inherent-impls/no-attr-empty-impl.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@ LL | impl extern_crate::StructWithAttr {}
77
= note: define and implement a trait or new type instead
88

99
error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
10-
--> $DIR/no-attr-empty-impl.rs:6:1
10+
--> $DIR/no-attr-empty-impl.rs:7:1
1111
|
1212
LL | impl extern_crate::StructNoAttr {}
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl for type defined outside of crate.
1414
|
1515
= note: define and implement a trait or new type instead
1616

1717
error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
18-
--> $DIR/no-attr-empty-impl.rs:8:1
18+
--> $DIR/no-attr-empty-impl.rs:10:1
1919
|
2020
LL | impl extern_crate::EnumWithAttr {}
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl for type defined outside of crate.
2222
|
2323
= note: define and implement a trait or new type instead
2424

2525
error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
26-
--> $DIR/no-attr-empty-impl.rs:10:1
26+
--> $DIR/no-attr-empty-impl.rs:13:1
2727
|
2828
LL | impl extern_crate::EnumNoAttr {}
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl for type defined outside of crate.
3030
|
3131
= note: define and implement a trait or new type instead
3232

3333
error[E0390]: cannot define inherent `impl` for primitive types
34-
--> $DIR/no-attr-empty-impl.rs:12:6
34+
--> $DIR/no-attr-empty-impl.rs:16:6
3535
|
3636
LL | impl f32 {}
3737
| ^^^

0 commit comments

Comments
 (0)
Please sign in to comment.