-
-
Notifications
You must be signed in to change notification settings - Fork 15k
validate #[link_name = "..."] & #[link(name = "...")] parameters
#155817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,54 @@ | ||
| #![crate_type = "lib"] | ||
|
|
||
| #[link(name = "")] | ||
| //~^ ERROR link name must not be empty | ||
| unsafe extern "C" { | ||
| #[link_name = ""] | ||
| //~^ ERROR link name must not be empty | ||
| safe fn empty(); | ||
| } | ||
|
|
||
| #[link(name = " ")] | ||
| unsafe extern "C" { | ||
| #[link_name = " "] | ||
| safe fn this_is_fine(); | ||
| } | ||
|
|
||
| #[export_name = " "] | ||
| extern "C" fn bar() -> i32 { | ||
| 42 | ||
| } | ||
|
|
||
| #[link(name = "\0")] | ||
| //~^ ERROR link name may not contain null characters | ||
| unsafe extern "C" {} | ||
|
|
||
| #[link(name = "foo\0")] | ||
| //~^ ERROR link name may not contain null characters | ||
| unsafe extern "C" {} | ||
|
|
||
| #[link(name = "\0foo")] | ||
| //~^ ERROR link name may not contain null characters | ||
| unsafe extern "C" {} | ||
|
|
||
| #[link(name = "fo\0o")] | ||
| //~^ ERROR link name may not contain null characters | ||
| unsafe extern "C" {} | ||
|
|
||
| unsafe extern "C" { | ||
| #[link_name = "\0"] | ||
| //~^ ERROR link name may not contain null characters | ||
| safe fn empty_null(); | ||
|
|
||
| #[link_name = "foo\0"] | ||
| //~^ ERROR link name may not contain null characters | ||
| safe fn trailing_null(); | ||
|
|
||
| #[link_name = "\0foo"] | ||
| //~^ ERROR link name may not contain null characters | ||
| safe fn leading_null(); | ||
|
|
||
| #[link_name = "fo\0o"] | ||
| //~^ ERROR link name may not contain null characters | ||
| safe fn middle_null(); | ||
| } |
This file contains hidden or 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,64 @@ | ||
| error[E0454]: link name must not be empty | ||
| --> $DIR/invalid-link-name.rs:3:15 | ||
| | | ||
| LL | #[link(name = "")] | ||
| | ^^ empty link name | ||
|
|
||
| error[E0454]: link name must not be empty | ||
| --> $DIR/invalid-link-name.rs:6:19 | ||
| | | ||
| LL | #[link_name = ""] | ||
| | ^^ empty link name | ||
|
|
||
| error[E0648]: link name may not contain null characters | ||
| --> $DIR/invalid-link-name.rs:22:15 | ||
| | | ||
| LL | #[link(name = "\0")] | ||
| | ^^^^ | ||
|
|
||
| error[E0648]: link name may not contain null characters | ||
| --> $DIR/invalid-link-name.rs:26:15 | ||
| | | ||
| LL | #[link(name = "foo\0")] | ||
| | ^^^^^^^ | ||
|
|
||
| error[E0648]: link name may not contain null characters | ||
| --> $DIR/invalid-link-name.rs:30:15 | ||
| | | ||
| LL | #[link(name = "\0foo")] | ||
| | ^^^^^^^ | ||
|
|
||
| error[E0648]: link name may not contain null characters | ||
| --> $DIR/invalid-link-name.rs:34:15 | ||
| | | ||
| LL | #[link(name = "fo\0o")] | ||
| | ^^^^^^^ | ||
|
|
||
| error[E0648]: link name may not contain null characters | ||
| --> $DIR/invalid-link-name.rs:39:19 | ||
| | | ||
| LL | #[link_name = "\0"] | ||
| | ^^^^ | ||
|
|
||
| error[E0648]: link name may not contain null characters | ||
| --> $DIR/invalid-link-name.rs:43:19 | ||
| | | ||
| LL | #[link_name = "foo\0"] | ||
| | ^^^^^^^ | ||
|
|
||
| error[E0648]: link name may not contain null characters | ||
| --> $DIR/invalid-link-name.rs:47:19 | ||
| | | ||
| LL | #[link_name = "\0foo"] | ||
| | ^^^^^^^ | ||
|
|
||
| error[E0648]: link name may not contain null characters | ||
| --> $DIR/invalid-link-name.rs:51:19 | ||
| | | ||
| LL | #[link_name = "fo\0o"] | ||
| | ^^^^^^^ | ||
|
|
||
| error: aborting due to 10 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0454, E0648. | ||
| For more information about an error, try `rustc --explain E0454`. |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should move these errors to
rustc_attr_parsingtoo, for consistency and so that the ranges can actually point to the attribute instead of the item.That's not something T-lang needs to worry about though, so probably best done separately.
cc @usamoi (this test was added by #144221)
View changes since the review