Skip to content

Commit 38c2e62

Browse files
authored
Rollup merge of #128718 - jieyouxu:check-cfg_attr, r=nnethercote
Consider `cfg_attr` checked by `CheckAttrVisitor` I forgor about `cfg_attr` in #128581, it should be treated like `cfg`. Fixes #128716.
2 parents 6c2a2e6 + 97cbc20 commit 38c2e62

File tree

3 files changed

+170
-0
lines changed

3 files changed

+170
-0
lines changed

compiler/rustc_passes/src/check_attr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
250250
| sym::deny
251251
| sym::forbid
252252
| sym::cfg
253+
| sym::cfg_attr
253254
// need to be fixed
254255
| sym::cfi_encoding // FIXME(cfi_encoding)
255256
| sym::may_dangle // FIXME(dropck_eyepatch)
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//! I missed a `cfg_attr` match in #128581, it should have had the same treatment as `cfg`. If
2+
//! an invalid attribute starting with `cfg_attr` is passed, then it would trigger an ICE because
3+
//! it was not considered "checked" (e.g. `#[cfg_attr::skip]` or `#[cfg_attr::no_such_thing]`).
4+
//!
5+
//! This test is not exhaustive, there's too many possible positions to check, instead it just does
6+
//! a basic smoke test in a few select positions to make sure we don't ICE for e.g.
7+
//! `#[cfg_attr::no_such_thing]`.
8+
//!
9+
//! issue: rust-lang/rust#128716
10+
#![crate_type = "lib"]
11+
12+
#[cfg_attr::no_such_thing]
13+
//~^ ERROR failed to resolve
14+
mod we_are_no_strangers_to_love {}
15+
16+
#[cfg_attr::no_such_thing]
17+
//~^ ERROR failed to resolve
18+
struct YouKnowTheRules {
19+
#[cfg_attr::no_such_thing]
20+
//~^ ERROR failed to resolve
21+
and_so_do_i: u8,
22+
}
23+
24+
#[cfg_attr::no_such_thing]
25+
//~^ ERROR failed to resolve
26+
fn a_full_commitment() {
27+
#[cfg_attr::no_such_thing]
28+
//~^ ERROR failed to resolve
29+
let is_what_i_am_thinking_of = ();
30+
}
31+
32+
#[cfg_attr::no_such_thing]
33+
//~^ ERROR failed to resolve
34+
union AnyOtherGuy {
35+
owo: ()
36+
}
37+
struct This;
38+
39+
#[cfg_attr(FALSE, doc = "you wouldn't get this")]
40+
impl From<AnyOtherGuy> for This {
41+
#[cfg_attr::no_such_thing]
42+
//~^ ERROR failed to resolve
43+
fn from(#[cfg_attr::no_such_thing] any_other_guy: AnyOtherGuy) -> This {
44+
//~^ ERROR failed to resolve
45+
#[cfg_attr::no_such_thing]
46+
//~^ ERROR attributes on expressions are experimental
47+
//~| ERROR failed to resolve
48+
unreachable!()
49+
}
50+
}
51+
52+
#[cfg_attr::no_such_thing]
53+
//~^ ERROR failed to resolve
54+
enum NeverGonna {
55+
#[cfg_attr::no_such_thing]
56+
//~^ ERROR failed to resolve
57+
GiveYouUp(#[cfg_attr::no_such_thing] u8),
58+
//~^ ERROR failed to resolve
59+
LetYouDown {
60+
#![cfg_attr::no_such_thing]
61+
//~^ ERROR an inner attribute is not permitted in this context
62+
never_gonna: (),
63+
round_around: (),
64+
#[cfg_attr::no_such_thing]
65+
//~^ ERROR failed to resolve
66+
and_desert_you: (),
67+
},
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
error: an inner attribute is not permitted in this context
2+
--> $DIR/check-cfg_attr-ice.rs:60:9
3+
|
4+
LL | #![cfg_attr::no_such_thing]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
8+
= note: outer attributes, like `#[test]`, annotate the item following them
9+
10+
error[E0658]: attributes on expressions are experimental
11+
--> $DIR/check-cfg_attr-ice.rs:45:9
12+
|
13+
LL | #[cfg_attr::no_such_thing]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
17+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
18+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
19+
20+
error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
21+
--> $DIR/check-cfg_attr-ice.rs:52:3
22+
|
23+
LL | #[cfg_attr::no_such_thing]
24+
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`
25+
26+
error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
27+
--> $DIR/check-cfg_attr-ice.rs:55:7
28+
|
29+
LL | #[cfg_attr::no_such_thing]
30+
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`
31+
32+
error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
33+
--> $DIR/check-cfg_attr-ice.rs:57:17
34+
|
35+
LL | GiveYouUp(#[cfg_attr::no_such_thing] u8),
36+
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`
37+
38+
error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
39+
--> $DIR/check-cfg_attr-ice.rs:64:11
40+
|
41+
LL | #[cfg_attr::no_such_thing]
42+
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`
43+
44+
error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
45+
--> $DIR/check-cfg_attr-ice.rs:41:7
46+
|
47+
LL | #[cfg_attr::no_such_thing]
48+
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`
49+
50+
error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
51+
--> $DIR/check-cfg_attr-ice.rs:43:15
52+
|
53+
LL | fn from(#[cfg_attr::no_such_thing] any_other_guy: AnyOtherGuy) -> This {
54+
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`
55+
56+
error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
57+
--> $DIR/check-cfg_attr-ice.rs:45:11
58+
|
59+
LL | #[cfg_attr::no_such_thing]
60+
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`
61+
62+
error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
63+
--> $DIR/check-cfg_attr-ice.rs:32:3
64+
|
65+
LL | #[cfg_attr::no_such_thing]
66+
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`
67+
68+
error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
69+
--> $DIR/check-cfg_attr-ice.rs:24:3
70+
|
71+
LL | #[cfg_attr::no_such_thing]
72+
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`
73+
74+
error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
75+
--> $DIR/check-cfg_attr-ice.rs:27:7
76+
|
77+
LL | #[cfg_attr::no_such_thing]
78+
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`
79+
80+
error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
81+
--> $DIR/check-cfg_attr-ice.rs:16:3
82+
|
83+
LL | #[cfg_attr::no_such_thing]
84+
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`
85+
86+
error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
87+
--> $DIR/check-cfg_attr-ice.rs:19:7
88+
|
89+
LL | #[cfg_attr::no_such_thing]
90+
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`
91+
92+
error[E0433]: failed to resolve: use of undeclared crate or module `cfg_attr`
93+
--> $DIR/check-cfg_attr-ice.rs:12:3
94+
|
95+
LL | #[cfg_attr::no_such_thing]
96+
| ^^^^^^^^ use of undeclared crate or module `cfg_attr`
97+
98+
error: aborting due to 15 previous errors
99+
100+
Some errors have detailed explanations: E0433, E0658.
101+
For more information about an error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)