forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#96520 - lcnr:general-incoherent-impls, r=petr…
…ochenkov generalize "incoherent impls" impl for user defined types To allow the move of `trait Error` into core. continues the work from rust-lang#94963, finishes rust-lang/compiler-team#487 r? `@petrochenkov` cc `@yaahc`
- Loading branch information
Showing
12 changed files
with
326 additions
and
18 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
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
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
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
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
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
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 {} |
40 changes: 40 additions & 0 deletions
40
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,40 @@ | ||
// aux-build:extern-crate.rs | ||
#![feature(rustc_attrs)] | ||
extern crate extern_crate; | ||
|
||
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 cannot define inherent `impl` for a type outside of the crate | ||
fn foo() {} | ||
} | ||
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 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 cannot define inherent `impl` for a type outside of the crate | ||
fn foo() {} | ||
} | ||
impl extern_crate::EnumNoAttr { | ||
//~^ ERROR cannot define inherent `impl` for a type outside of the crate | ||
#[rustc_allow_incoherent_impl] | ||
fn bar() {} | ||
} | ||
|
||
fn main() {} |
115 changes: 115 additions & 0 deletions
115
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,115 @@ | ||
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:7:5 | ||
| | ||
LL | fn foo() {} | ||
| ^^^^^^^^^^^ | ||
|
||
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:13:1 | ||
| | ||
LL | / impl extern_crate::StructNoAttr { | ||
LL | | | ||
LL | | fn foo() {} | ||
LL | | } | ||
| |_^ | ||
|
||
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: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 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:24:5 | ||
| | ||
LL | fn foo() {} | ||
| ^^^^^^^^^^^ | ||
|
||
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:30:1 | ||
| | ||
LL | / impl extern_crate::EnumNoAttr { | ||
LL | | | ||
LL | | fn foo() {} | ||
LL | | } | ||
| |_^ | ||
|
||
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:34:1 | ||
| | ||
LL | / impl extern_crate::EnumNoAttr { | ||
LL | | | ||
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`. |
Oops, something went wrong.