-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
forbid empty impls for types with incoherent impls
- Loading branch information
Showing
6 changed files
with
228 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/test/ui/incoherent-inherent-impls/auxiliary/extern-crate.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_has_incoherent_inherent_impls] | ||
pub struct StructWithAttr; | ||
pub struct StructNoAttr; | ||
|
||
#[rustc_has_incoherent_inherent_impls] | ||
pub enum EnumWithAttr {} | ||
pub enum EnumNoAttr {} |
34 changes: 34 additions & 0 deletions
34
src/test/ui/incoherent-inherent-impls/needs-has-incoherent-impls.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// aux-build:extern-crate.rs | ||
#![feature(rustc_attrs)] | ||
extern crate extern_crate; | ||
|
||
impl extern_crate::StructWithAttr { //~ ERROR | ||
fn foo() {} | ||
} | ||
impl extern_crate::StructWithAttr { | ||
#[rustc_allow_incoherent_impl] | ||
fn bar() {} | ||
} | ||
impl extern_crate::StructNoAttr { //~ ERROR | ||
fn foo() {} | ||
} | ||
impl extern_crate::StructNoAttr { //~ ERROR | ||
#[rustc_allow_incoherent_impl] | ||
fn bar() {} | ||
} | ||
impl extern_crate::EnumWithAttr { //~ ERROR | ||
fn foo() {} | ||
} | ||
impl extern_crate::EnumWithAttr { | ||
#[rustc_allow_incoherent_impl] | ||
fn bar() {} | ||
} | ||
impl extern_crate::EnumNoAttr { //~ ERROR | ||
fn foo() {} | ||
} | ||
impl extern_crate::EnumNoAttr { //~ ERROR | ||
#[rustc_allow_incoherent_impl] | ||
fn bar() {} | ||
} | ||
|
||
fn main() {} |
105 changes: 105 additions & 0 deletions
105
src/test/ui/incoherent-inherent-impls/needs-has-incoherent-impls.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
error[E0390]: cannot define inherent `impl` for a type outside of crate where the type is defined | ||
--> $DIR/needs-has-incoherent-impls.rs:5:1 | ||
| | ||
LL | / impl extern_crate::StructWithAttr { | ||
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 | ||
| | ||
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 | ||
| | ||
LL | / impl extern_crate::StructNoAttr { | ||
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 | ||
| | ||
LL | / impl extern_crate::StructNoAttr { | ||
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 | ||
| | ||
LL | / impl extern_crate::StructNoAttr { | ||
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 | ||
| | ||
LL | / impl extern_crate::StructNoAttr { | ||
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 | ||
| | ||
LL | / impl extern_crate::EnumWithAttr { | ||
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 | ||
| | ||
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 | ||
| | ||
LL | / impl extern_crate::EnumNoAttr { | ||
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 | ||
| | ||
LL | / impl extern_crate::EnumNoAttr { | ||
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 | ||
| | ||
LL | / impl extern_crate::EnumNoAttr { | ||
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 | ||
| | ||
LL | / impl extern_crate::EnumNoAttr { | ||
LL | | #[rustc_allow_incoherent_impl] | ||
LL | | fn bar() {} | ||
LL | | } | ||
| |_^ | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0390`. |
14 changes: 14 additions & 0 deletions
14
src/test/ui/incoherent-inherent-impls/no-attr-empty-impl.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// aux-build:extern-crate.rs | ||
extern crate extern_crate; | ||
|
||
impl extern_crate::StructWithAttr {} //~ ERROR | ||
|
||
impl extern_crate::StructNoAttr {} //~ ERROR | ||
|
||
impl extern_crate::EnumWithAttr {} //~ ERROR | ||
|
||
impl extern_crate::EnumNoAttr {} //~ ERROR | ||
|
||
impl f32 {} //~ ERROR | ||
|
||
fn main() {} |
44 changes: 44 additions & 0 deletions
44
src/test/ui/incoherent-inherent-impls/no-attr-empty-impl.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined | ||
--> $DIR/no-attr-empty-impl.rs:4:1 | ||
| | ||
LL | impl extern_crate::StructWithAttr {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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:6: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 | ||
| | ||
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 | ||
| | ||
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 | ||
| | ||
LL | impl f32 {} | ||
| ^^^ | ||
| | ||
= help: consider using an extension trait instead | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors have detailed explanations: E0116, E0390. | ||
For more information about an error, try `rustc --explain E0116`. |