Skip to content

Commit

Permalink
Rollup merge of rust-lang#128718 - jieyouxu:check-cfg_attr, r=nnether…
Browse files Browse the repository at this point in the history
…cote

Consider `cfg_attr` checked by `CheckAttrVisitor`

I forgor about `cfg_attr` in rust-lang#128581, it should be treated like `cfg`.

Fixes rust-lang#128716.
  • Loading branch information
matthiaskrgr authored Aug 6, 2024
2 parents 6c2a2e6 + 97cbc20 commit 38c2e62
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| sym::deny
| sym::forbid
| sym::cfg
| sym::cfg_attr
// need to be fixed
| sym::cfi_encoding // FIXME(cfi_encoding)
| sym::may_dangle // FIXME(dropck_eyepatch)
Expand Down
68 changes: 68 additions & 0 deletions tests/ui/attributes/check-cfg_attr-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//! I missed a `cfg_attr` match in #128581, it should have had the same treatment as `cfg`. If
//! an invalid attribute starting with `cfg_attr` is passed, then it would trigger an ICE because
//! it was not considered "checked" (e.g. `#[cfg_attr::skip]` or `#[cfg_attr::no_such_thing]`).
//!
//! This test is not exhaustive, there's too many possible positions to check, instead it just does
//! a basic smoke test in a few select positions to make sure we don't ICE for e.g.
//! `#[cfg_attr::no_such_thing]`.
//!
//! issue: rust-lang/rust#128716
#![crate_type = "lib"]

#[cfg_attr::no_such_thing]
//~^ ERROR failed to resolve
mod we_are_no_strangers_to_love {}

#[cfg_attr::no_such_thing]
//~^ ERROR failed to resolve
struct YouKnowTheRules {
#[cfg_attr::no_such_thing]
//~^ ERROR failed to resolve
and_so_do_i: u8,
}

#[cfg_attr::no_such_thing]
//~^ ERROR failed to resolve
fn a_full_commitment() {
#[cfg_attr::no_such_thing]
//~^ ERROR failed to resolve
let is_what_i_am_thinking_of = ();
}

#[cfg_attr::no_such_thing]
//~^ ERROR failed to resolve
union AnyOtherGuy {
owo: ()
}
struct This;

#[cfg_attr(FALSE, doc = "you wouldn't get this")]
impl From<AnyOtherGuy> for This {
#[cfg_attr::no_such_thing]
//~^ ERROR failed to resolve
fn from(#[cfg_attr::no_such_thing] any_other_guy: AnyOtherGuy) -> This {
//~^ ERROR failed to resolve
#[cfg_attr::no_such_thing]
//~^ ERROR attributes on expressions are experimental
//~| ERROR failed to resolve
unreachable!()
}
}

#[cfg_attr::no_such_thing]
//~^ ERROR failed to resolve
enum NeverGonna {
#[cfg_attr::no_such_thing]
//~^ ERROR failed to resolve
GiveYouUp(#[cfg_attr::no_such_thing] u8),
//~^ ERROR failed to resolve
LetYouDown {
#![cfg_attr::no_such_thing]
//~^ ERROR an inner attribute is not permitted in this context
never_gonna: (),
round_around: (),
#[cfg_attr::no_such_thing]
//~^ ERROR failed to resolve
and_desert_you: (),
},
}
101 changes: 101 additions & 0 deletions tests/ui/attributes/check-cfg_attr-ice.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
error: an inner attribute is not permitted in this context
--> $DIR/check-cfg_attr-ice.rs:60:9
|
LL | #![cfg_attr::no_such_thing]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
= note: outer attributes, like `#[test]`, annotate the item following them

error[E0658]: attributes on expressions are experimental
--> $DIR/check-cfg_attr-ice.rs:45:9
|
LL | #[cfg_attr::no_such_thing]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
--> $DIR/check-cfg_attr-ice.rs:52:3
|
LL | #[cfg_attr::no_such_thing]
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`

error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
--> $DIR/check-cfg_attr-ice.rs:55:7
|
LL | #[cfg_attr::no_such_thing]
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`

error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
--> $DIR/check-cfg_attr-ice.rs:57:17
|
LL | GiveYouUp(#[cfg_attr::no_such_thing] u8),
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`

error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
--> $DIR/check-cfg_attr-ice.rs:64:11
|
LL | #[cfg_attr::no_such_thing]
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`

error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
--> $DIR/check-cfg_attr-ice.rs:41:7
|
LL | #[cfg_attr::no_such_thing]
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`

error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
--> $DIR/check-cfg_attr-ice.rs:43:15
|
LL | fn from(#[cfg_attr::no_such_thing] any_other_guy: AnyOtherGuy) -> This {
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`

error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
--> $DIR/check-cfg_attr-ice.rs:45:11
|
LL | #[cfg_attr::no_such_thing]
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`

error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
--> $DIR/check-cfg_attr-ice.rs:32:3
|
LL | #[cfg_attr::no_such_thing]
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`

error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
--> $DIR/check-cfg_attr-ice.rs:24:3
|
LL | #[cfg_attr::no_such_thing]
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`

error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
--> $DIR/check-cfg_attr-ice.rs:27:7
|
LL | #[cfg_attr::no_such_thing]
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`

error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
--> $DIR/check-cfg_attr-ice.rs:16:3
|
LL | #[cfg_attr::no_such_thing]
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`

error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
--> $DIR/check-cfg_attr-ice.rs:19:7
|
LL | #[cfg_attr::no_such_thing]
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`

error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
--> $DIR/check-cfg_attr-ice.rs:12:3
|
LL | #[cfg_attr::no_such_thing]
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`

error: aborting due to 15 previous errors

Some errors have detailed explanations: E0433, E0658.
For more information about an error, try `rustc --explain E0433`.

0 comments on commit 38c2e62

Please sign in to comment.