Skip to content

Commit

Permalink
update error messages and explicitly mention them in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed May 5, 2022
1 parent ba0ecbd commit 321162b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 34 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/coherence/inherent_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'tcx> InherentCollect<'tcx> {
self.tcx.sess,
item.span,
E0390,
"cannot define inherent `impl` for a type outside of crate where the type is defined",
"cannot define inherent `impl` for a type outside of the crate where the type is defined",
)
.help(INTO_DEFINING_CRATE)
.span_help(item.span, ADD_ATTR_TO_TY)
Expand All @@ -166,7 +166,7 @@ impl<'tcx> InherentCollect<'tcx> {
self.tcx.sess,
item.span,
E0390,
"cannot define inherent `impl` for a type outside of crate where the type is defined",
"cannot define inherent `impl` for a type outside of the crate where the type is defined",
)
.help(INTO_DEFINING_CRATE)
.span_help(impl_item.span, ADD_ATTR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,37 @@
#![feature(rustc_attrs)]
extern crate extern_crate;

impl extern_crate::StructWithAttr { //~ ERROR
impl extern_crate::StructWithAttr {
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
fn foo() {}
}
impl extern_crate::StructWithAttr {
#[rustc_allow_incoherent_impl]
fn bar() {}
}
impl extern_crate::StructNoAttr { //~ ERROR
impl extern_crate::StructNoAttr {
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
fn foo() {}
}
impl extern_crate::StructNoAttr { //~ ERROR
impl extern_crate::StructNoAttr {
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
#[rustc_allow_incoherent_impl]
fn bar() {}
}
impl extern_crate::EnumWithAttr { //~ ERROR
impl extern_crate::EnumWithAttr {
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
fn foo() {}
}
impl extern_crate::EnumWithAttr {
#[rustc_allow_incoherent_impl]
fn bar() {}
}
impl extern_crate::EnumNoAttr { //~ ERROR
impl extern_crate::EnumNoAttr {
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
fn foo() {}
}
impl extern_crate::EnumNoAttr { //~ ERROR
impl extern_crate::EnumNoAttr {
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
#[rustc_allow_incoherent_impl]
fn bar() {}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,100 +1,110 @@
error[E0390]: cannot define inherent `impl` for a type outside of crate where the type is defined
error[E0390]: cannot define inherent `impl` for a type outside of the crate where the type is defined
--> $DIR/needs-has-incoherent-impls.rs:5:1
|
LL | / impl extern_crate::StructWithAttr {
LL | |
LL | | fn foo() {}
LL | | }
| |_^
|
= help: consider moving this inherent impl into the crate defining the type if possible
help: alternatively add `#[rustc_allow_incoherent_impl]` to the relevant impl items
--> $DIR/needs-has-incoherent-impls.rs:6:5
--> $DIR/needs-has-incoherent-impls.rs:7:5
|
LL | fn foo() {}
| ^^^^^^^^^^^

error[E0390]: cannot define inherent `impl` for a type outside of crate where the type is defined
--> $DIR/needs-has-incoherent-impls.rs:12:1
error[E0390]: cannot define inherent `impl` for a type outside of the crate where the type is defined
--> $DIR/needs-has-incoherent-impls.rs:13:1
|
LL | / impl extern_crate::StructNoAttr {
LL | |
LL | | fn foo() {}
LL | | }
| |_^
|
= help: consider moving this inherent impl into the crate defining the type if possible
help: alternatively add `#[rustc_has_incoherent_inherent_impls]` to the type and `#[rustc_allow_incoherent_impl]` to the relevant impl items
--> $DIR/needs-has-incoherent-impls.rs:12:1
--> $DIR/needs-has-incoherent-impls.rs:13:1
|
LL | / impl extern_crate::StructNoAttr {
LL | |
LL | | fn foo() {}
LL | | }
| |_^

error[E0390]: cannot define inherent `impl` for a type outside of crate where the type is defined
--> $DIR/needs-has-incoherent-impls.rs:15:1
error[E0390]: cannot define inherent `impl` for a type outside of the crate where the type is defined
--> $DIR/needs-has-incoherent-impls.rs:17:1
|
LL | / impl extern_crate::StructNoAttr {
LL | |
LL | | #[rustc_allow_incoherent_impl]
LL | | fn bar() {}
LL | | }
| |_^
|
= help: consider moving this inherent impl into the crate defining the type if possible
help: alternatively add `#[rustc_has_incoherent_inherent_impls]` to the type and `#[rustc_allow_incoherent_impl]` to the relevant impl items
--> $DIR/needs-has-incoherent-impls.rs:15:1
--> $DIR/needs-has-incoherent-impls.rs:17:1
|
LL | / impl extern_crate::StructNoAttr {
LL | |
LL | | #[rustc_allow_incoherent_impl]
LL | | fn bar() {}
LL | | }
| |_^

error[E0390]: cannot define inherent `impl` for a type outside of crate where the type is defined
--> $DIR/needs-has-incoherent-impls.rs:19:1
error[E0390]: cannot define inherent `impl` for a type outside of the crate where the type is defined
--> $DIR/needs-has-incoherent-impls.rs:22:1
|
LL | / impl extern_crate::EnumWithAttr {
LL | |
LL | | fn foo() {}
LL | | }
| |_^
|
= help: consider moving this inherent impl into the crate defining the type if possible
help: alternatively add `#[rustc_allow_incoherent_impl]` to the relevant impl items
--> $DIR/needs-has-incoherent-impls.rs:20:5
--> $DIR/needs-has-incoherent-impls.rs:24:5
|
LL | fn foo() {}
| ^^^^^^^^^^^

error[E0390]: cannot define inherent `impl` for a type outside of crate where the type is defined
--> $DIR/needs-has-incoherent-impls.rs:26:1
error[E0390]: cannot define inherent `impl` for a type outside of the crate where the type is defined
--> $DIR/needs-has-incoherent-impls.rs:30:1
|
LL | / impl extern_crate::EnumNoAttr {
LL | |
LL | | fn foo() {}
LL | | }
| |_^
|
= help: consider moving this inherent impl into the crate defining the type if possible
help: alternatively add `#[rustc_has_incoherent_inherent_impls]` to the type and `#[rustc_allow_incoherent_impl]` to the relevant impl items
--> $DIR/needs-has-incoherent-impls.rs:26:1
--> $DIR/needs-has-incoherent-impls.rs:30:1
|
LL | / impl extern_crate::EnumNoAttr {
LL | |
LL | | fn foo() {}
LL | | }
| |_^

error[E0390]: cannot define inherent `impl` for a type outside of crate where the type is defined
--> $DIR/needs-has-incoherent-impls.rs:29:1
error[E0390]: cannot define inherent `impl` for a type outside of the crate where the type is defined
--> $DIR/needs-has-incoherent-impls.rs:34:1
|
LL | / impl extern_crate::EnumNoAttr {
LL | |
LL | | #[rustc_allow_incoherent_impl]
LL | | fn bar() {}
LL | | }
| |_^
|
= help: consider moving this inherent impl into the crate defining the type if possible
help: alternatively add `#[rustc_has_incoherent_inherent_impls]` to the type and `#[rustc_allow_incoherent_impl]` to the relevant impl items
--> $DIR/needs-has-incoherent-impls.rs:29:1
--> $DIR/needs-has-incoherent-impls.rs:34:1
|
LL | / impl extern_crate::EnumNoAttr {
LL | |
LL | | #[rustc_allow_incoherent_impl]
LL | | fn bar() {}
LL | | }
Expand Down
14 changes: 9 additions & 5 deletions src/test/ui/incoherent-inherent-impls/no-attr-empty-impl.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// aux-build:extern-crate.rs
extern crate extern_crate;

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

impl extern_crate::StructNoAttr {} //~ ERROR
impl extern_crate::StructNoAttr {}
//~^ ERROR cannot define inherent `impl` for a type outside of the crate

impl extern_crate::EnumWithAttr {} //~ ERROR
impl extern_crate::EnumWithAttr {}
//~^ ERROR cannot define inherent `impl` for a type outside of the crate

impl extern_crate::EnumNoAttr {} //~ ERROR
impl extern_crate::EnumNoAttr {}
//~^ ERROR cannot define inherent `impl` for a type outside of the crate

impl f32 {} //~ ERROR
impl f32 {} //~ ERROR cannot define inherent `impl` for primitive types

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ LL | impl extern_crate::StructWithAttr {}
= note: define and implement a trait or new type instead

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

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

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

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

0 comments on commit 321162b

Please sign in to comment.