-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit an error for invalid use of the linkage attribute
- Loading branch information
Showing
5 changed files
with
116 additions
and
1 deletion.
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
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 @@ | ||
#![feature(linkage)] | ||
#![feature(stmt_expr_attributes)] | ||
#![deny(unused_attributes)] | ||
#![allow(dead_code)] | ||
|
||
#[linkage = "weak"] //~ ERROR attribute should be applied to a free function, impl method or static, foreign static | ||
type InvalidTy = (); | ||
|
||
#[linkage = "weak"] //~ ERROR attribute should be applied to a free function, impl method or static, foreign static | ||
mod invalid_module {} | ||
|
||
#[linkage = "weak"] //~ ERROR attribute should be applied to a free function, impl method or static, foreign static | ||
struct F; | ||
|
||
#[linkage = "weak"] //~ ERROR attribute should be applied to a free function, impl method or static, foreign static | ||
impl F { | ||
#[linkage = "weak"] | ||
fn valid(&self) {} | ||
} | ||
|
||
#[linkage = "weak"] | ||
fn f() { | ||
#[linkage = "weak"] | ||
{ | ||
1 | ||
}; | ||
//~^^^^ ERROR attribute should be applied to a free function, impl method or static, foreign static | ||
} | ||
|
||
extern "C" { | ||
#[linkage = "weak"] | ||
static A: *const (); | ||
} | ||
|
||
fn main() { | ||
let _ = #[linkage = "weak"] //~ ERROR attribute should be applied to a free function, impl method or static, foreign static | ||
(|| 1); | ||
} |
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,55 @@ | ||
error: attribute should be applied to a free function, impl method or static, foreign static | ||
--> $DIR/linkage.rs:6:1 | ||
| | ||
LL | #[linkage = "weak"] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
LL | type InvalidTy = (); | ||
| -------------------- not a free function, impl method or static, foreign static | ||
|
||
error: attribute should be applied to a free function, impl method or static, foreign static | ||
--> $DIR/linkage.rs:9:1 | ||
| | ||
LL | #[linkage = "weak"] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
LL | mod invalid_module {} | ||
| --------------------- not a free function, impl method or static, foreign static | ||
|
||
error: attribute should be applied to a free function, impl method or static, foreign static | ||
--> $DIR/linkage.rs:12:1 | ||
| | ||
LL | #[linkage = "weak"] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
LL | struct F; | ||
| --------- not a free function, impl method or static, foreign static | ||
|
||
error: attribute should be applied to a free function, impl method or static, foreign static | ||
--> $DIR/linkage.rs:15:1 | ||
| | ||
LL | #[linkage = "weak"] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
LL | / impl F { | ||
LL | | #[linkage = "weak"] | ||
LL | | fn valid(&self) {} | ||
LL | | } | ||
| |_- not a free function, impl method or static, foreign static | ||
|
||
error: attribute should be applied to a free function, impl method or static, foreign static | ||
--> $DIR/linkage.rs:23:5 | ||
| | ||
LL | #[linkage = "weak"] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
LL | / { | ||
LL | | 1 | ||
LL | | }; | ||
| |_____- not a free function, impl method or static, foreign static | ||
|
||
error: attribute should be applied to a free function, impl method or static, foreign static | ||
--> $DIR/linkage.rs:36:13 | ||
| | ||
LL | let _ = #[linkage = "weak"] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
LL | (|| 1); | ||
| ------ not a free function, impl method or static, foreign static | ||
|
||
error: aborting due to 6 previous errors | ||
|