Skip to content

Commit 407f45c

Browse files
committed
fixup no_{core,std} handling code
1 parent 0db2eb7 commit 407f45c

File tree

3 files changed

+113
-8
lines changed

3 files changed

+113
-8
lines changed

src/tools/clippy/clippy_utils/src/lib.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,17 +2133,11 @@ pub fn std_or_core(cx: &LateContext<'_>) -> Option<&'static str> {
21332133
}
21342134

21352135
pub fn is_no_std_crate(cx: &LateContext<'_>) -> bool {
2136-
cx.tcx
2137-
.hir_attrs(hir::CRATE_HIR_ID)
2138-
.iter()
2139-
.any(|attr| attr.has_name(sym::no_std))
2136+
find_attr!(cx.tcx.hir_attrs(hir::CRATE_HIR_ID), AttributeKind::NoStd(..))
21402137
}
21412138

21422139
pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool {
2143-
cx.tcx
2144-
.hir_attrs(hir::CRATE_HIR_ID)
2145-
.iter()
2146-
.any(|attr| attr.has_name(sym::no_core))
2140+
find_attr!(cx.tcx.hir_attrs(hir::CRATE_HIR_ID), AttributeKind::NoCore(..))
21472141
}
21482142

21492143
/// Check if parent of a hir node is a trait implementation block.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(no_core)]
2+
// these all still apply no_std and then later error
3+
#![no_std = "foo"]
4+
//~^ ERROR malformed `no_std` attribute input
5+
#![no_std("bar")]
6+
//~^ ERROR malformed `no_std` attribute input
7+
#![no_std(foo = "bar")]
8+
//~^ ERROR malformed `no_std` attribute input
9+
#![no_core = "foo"]
10+
//~^ ERROR malformed `no_core` attribute input
11+
#![no_core("bar")]
12+
//~^ ERROR malformed `no_core` attribute input
13+
#![no_core(foo = "bar")]
14+
//~^ ERROR malformed `no_core` attribute input
15+
16+
#[deny(unused_attributes)]
17+
#[no_std]
18+
//~^ ERROR crate-level attribute should be an inner attribute: add an exclamation mark:
19+
#[no_core]
20+
//~^ ERROR crate-level attribute should be an inner attribute: add an exclamation mark:
21+
// to fix compilation
22+
extern crate core;
23+
extern crate std;
24+
25+
fn main() {}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
error[E0565]: malformed `no_std` attribute input
2+
--> $DIR/malformed-no-std.rs:3:1
3+
|
4+
LL | #![no_std = "foo"]
5+
| ^^^^^^^^^^-------^
6+
| | |
7+
| | didn't expect any arguments here
8+
| help: must be of the form: `#![no_std]`
9+
10+
error[E0565]: malformed `no_std` attribute input
11+
--> $DIR/malformed-no-std.rs:5:1
12+
|
13+
LL | #![no_std("bar")]
14+
| ^^^^^^^^^-------^
15+
| | |
16+
| | didn't expect any arguments here
17+
| help: must be of the form: `#![no_std]`
18+
19+
error[E0565]: malformed `no_std` attribute input
20+
--> $DIR/malformed-no-std.rs:7:1
21+
|
22+
LL | #![no_std(foo = "bar")]
23+
| ^^^^^^^^^-------------^
24+
| | |
25+
| | didn't expect any arguments here
26+
| help: must be of the form: `#![no_std]`
27+
28+
error[E0565]: malformed `no_core` attribute input
29+
--> $DIR/malformed-no-std.rs:9:1
30+
|
31+
LL | #![no_core = "foo"]
32+
| ^^^^^^^^^^^-------^
33+
| | |
34+
| | didn't expect any arguments here
35+
| help: must be of the form: `#![no_core]`
36+
37+
error[E0565]: malformed `no_core` attribute input
38+
--> $DIR/malformed-no-std.rs:11:1
39+
|
40+
LL | #![no_core("bar")]
41+
| ^^^^^^^^^^-------^
42+
| | |
43+
| | didn't expect any arguments here
44+
| help: must be of the form: `#![no_core]`
45+
46+
error[E0565]: malformed `no_core` attribute input
47+
--> $DIR/malformed-no-std.rs:13:1
48+
|
49+
LL | #![no_core(foo = "bar")]
50+
| ^^^^^^^^^^-------------^
51+
| | |
52+
| | didn't expect any arguments here
53+
| help: must be of the form: `#![no_core]`
54+
55+
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_std]`
56+
--> $DIR/malformed-no-std.rs:17:1
57+
|
58+
LL | #[no_std]
59+
| ^^^^^^^^^
60+
|
61+
note: This attribute does not have an `!`, which means it is applied to this extern crate
62+
--> $DIR/malformed-no-std.rs:22:1
63+
|
64+
LL | extern crate core;
65+
| ^^^^^^^^^^^^^^^^^^
66+
note: the lint level is defined here
67+
--> $DIR/malformed-no-std.rs:16:8
68+
|
69+
LL | #[deny(unused_attributes)]
70+
| ^^^^^^^^^^^^^^^^^
71+
72+
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_core]`
73+
--> $DIR/malformed-no-std.rs:19:1
74+
|
75+
LL | #[no_core]
76+
| ^^^^^^^^^^
77+
|
78+
note: This attribute does not have an `!`, which means it is applied to this extern crate
79+
--> $DIR/malformed-no-std.rs:22:1
80+
|
81+
LL | extern crate core;
82+
| ^^^^^^^^^^^^^^^^^^
83+
84+
error: aborting due to 8 previous errors
85+
86+
For more information about this error, try `rustc --explain E0565`.

0 commit comments

Comments
 (0)