Skip to content

Commit ea0d038

Browse files
committed
Error on invalid uses of the cfi_encoding attribute.
1 parent c999cef commit ea0d038

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/cfi_encoding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::prelude::*;
44
pub(crate) struct CfiEncodingParser;
55
impl SingleAttributeParser for CfiEncodingParser {
66
const PATH: &[Symbol] = &[sym::cfi_encoding];
7-
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListWarnRest(&[
7+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
88
Allow(Target::Struct),
99
Allow(Target::ForeignTy),
1010
Allow(Target::Enum),
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// Verifies that invalid user-defined CFI encodings can't be used.
2-
//
3-
//@ needs-sanitizer-cfi
4-
//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi
1+
//! Checks for invalid uses of the `cfi_encoding` attribute
52
6-
#![feature(cfi_encoding, no_core)]
7-
#![no_core]
8-
#![no_main]
3+
#![feature(cfi_encoding)]
4+
#![crate_type = "lib"]
95

106
#[cfi_encoding] //~ ERROR malformed `cfi_encoding` attribute input
117
pub struct Type1(i32);
8+
9+
#[cfi_encoding = "Foo"] //~ ERROR the `cfi_encoding` attribute cannot be used on traits
10+
pub trait X {}
11+
12+
#[cfi_encoding = "Bar"] //~ ERROR the `cfi_encoding` attribute cannot be used on type aliases
13+
pub type Y = Type1;
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0539]: malformed `cfi_encoding` attribute input
2-
--> $DIR/invalid-attr-encoding.rs:10:3
2+
--> $DIR/invalid-attr-encoding.rs:7:3
33
|
44
LL | #[cfi_encoding]
55
| ^^^^^^^^^^^^ expected this to be of the form `cfi_encoding = "..."`
@@ -9,6 +9,22 @@ help: must be of the form
99
LL | #[cfi_encoding = "encoding"]
1010
| ++++++++++++
1111

12-
error: aborting due to 1 previous error
12+
error: the `cfi_encoding` attribute cannot be used on traits
13+
--> $DIR/invalid-attr-encoding.rs:10:3
14+
|
15+
LL | #[cfi_encoding = "Foo"]
16+
| ^^^^^^^^^^^^
17+
|
18+
= help: the `cfi_encoding` attribute can only be applied to data types
19+
20+
error: the `cfi_encoding` attribute cannot be used on type aliases
21+
--> $DIR/invalid-attr-encoding.rs:13:3
22+
|
23+
LL | #[cfi_encoding = "Bar"]
24+
| ^^^^^^^^^^^^
25+
|
26+
= help: the `cfi_encoding` attribute can only be applied to data types
27+
28+
error: aborting due to 3 previous errors
1329

1430
For more information about this error, try `rustc --explain E0539`.

0 commit comments

Comments
 (0)