forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#61547 - petrochenkov:cfgen, r=Centril
Support `cfg` and `cfg_attr` on generic parameters `cfg` attributes are supported in all other positions where attributes are accepted at all. They were previously prohibited in rust-lang#51283 because they weren't implemented correctly before that and were simply ignored.
- Loading branch information
Showing
6 changed files
with
111 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// compile-flags:--cfg yes | ||
|
||
fn f_lt<#[cfg(yes)] 'a: 'a, #[cfg(no)] T>() {} | ||
fn f_ty<#[cfg(no)] 'a: 'a, #[cfg(yes)] T>() {} | ||
|
||
type FnGood = for<#[cfg(yes)] 'a, #[cfg(no)] T> fn(); // OK | ||
type FnBad = for<#[cfg(no)] 'a, #[cfg(yes)] T> fn(); | ||
//~^ ERROR only lifetime parameters can be used in this context | ||
|
||
type PolyGood = dyn for<#[cfg(yes)] 'a, #[cfg(no)] T> Copy; // OK | ||
type PolyBad = dyn for<#[cfg(no)] 'a, #[cfg(yes)] T> Copy; | ||
//~^ ERROR only lifetime parameters can be used in this context | ||
|
||
struct WhereGood where for<#[cfg(yes)] 'a, #[cfg(no)] T> u8: Copy; // OK | ||
struct WhereBad where for<#[cfg(no)] 'a, #[cfg(yes)] T> u8: Copy; | ||
//~^ ERROR only lifetime parameters can be used in this context | ||
|
||
fn f_lt_no<#[cfg_attr(no, unknown)] 'a>() {} // OK | ||
fn f_lt_yes<#[cfg_attr(yes, unknown)] 'a>() {} //~ ERROR attribute `unknown` is currently unknown | ||
fn f_ty_no<#[cfg_attr(no, unknown)] T>() {} // OK | ||
fn f_ty_yes<#[cfg_attr(yes, unknown)] T>() {} //~ ERROR attribute `unknown` is currently unknown | ||
|
||
type FnNo = for<#[cfg_attr(no, unknown)] 'a> fn(); // OK | ||
type FnYes = for<#[cfg_attr(yes, unknown)] 'a> fn(); | ||
//~^ ERROR attribute `unknown` is currently unknown | ||
|
||
type PolyNo = dyn for<#[cfg_attr(no, unknown)] 'a> Copy; // OK | ||
type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> Copy; | ||
//~^ ERROR attribute `unknown` is currently unknown | ||
|
||
struct WhereNo where for<#[cfg_attr(no, unknown)] 'a> u8: Copy; // OK | ||
struct WhereYes where for<#[cfg_attr(yes, unknown)] 'a> u8: Copy; | ||
//~^ ERROR attribute `unknown` is currently unknown | ||
|
||
fn main() { | ||
f_lt::<'static>(); | ||
f_ty::<u8>(); | ||
} |
66 changes: 66 additions & 0 deletions
66
src/test/ui/conditional-compilation/cfg-generic-params.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,66 @@ | ||
error: only lifetime parameters can be used in this context | ||
--> $DIR/cfg-generic-params.rs:7:45 | ||
| | ||
LL | type FnBad = for<#[cfg(no)] 'a, #[cfg(yes)] T> fn(); | ||
| ^ | ||
|
||
error: only lifetime parameters can be used in this context | ||
--> $DIR/cfg-generic-params.rs:11:51 | ||
| | ||
LL | type PolyBad = dyn for<#[cfg(no)] 'a, #[cfg(yes)] T> Copy; | ||
| ^ | ||
|
||
error: only lifetime parameters can be used in this context | ||
--> $DIR/cfg-generic-params.rs:15:54 | ||
| | ||
LL | struct WhereBad where for<#[cfg(no)] 'a, #[cfg(yes)] T> u8: Copy; | ||
| ^ | ||
|
||
error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future | ||
--> $DIR/cfg-generic-params.rs:19:29 | ||
| | ||
LL | fn f_lt_yes<#[cfg_attr(yes, unknown)] 'a>() {} | ||
| ^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/29642 | ||
= help: add #![feature(custom_attribute)] to the crate attributes to enable | ||
|
||
error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future | ||
--> $DIR/cfg-generic-params.rs:21:29 | ||
| | ||
LL | fn f_ty_yes<#[cfg_attr(yes, unknown)] T>() {} | ||
| ^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/29642 | ||
= help: add #![feature(custom_attribute)] to the crate attributes to enable | ||
|
||
error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future | ||
--> $DIR/cfg-generic-params.rs:24:34 | ||
| | ||
LL | type FnYes = for<#[cfg_attr(yes, unknown)] 'a> fn(); | ||
| ^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/29642 | ||
= help: add #![feature(custom_attribute)] to the crate attributes to enable | ||
|
||
error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future | ||
--> $DIR/cfg-generic-params.rs:28:40 | ||
| | ||
LL | type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> Copy; | ||
| ^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/29642 | ||
= help: add #![feature(custom_attribute)] to the crate attributes to enable | ||
|
||
error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future | ||
--> $DIR/cfg-generic-params.rs:32:43 | ||
| | ||
LL | struct WhereYes where for<#[cfg_attr(yes, unknown)] 'a> u8: Copy; | ||
| ^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/29642 | ||
= help: add #![feature(custom_attribute)] to the crate attributes to enable | ||
|
||
error: aborting due to 8 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.