Skip to content
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

Add checking for no_mangle to unsafe_code lint #72209

Merged
merged 6 commits into from
Feb 9, 2021

Conversation

Nemo157
Copy link
Member

@Nemo157 Nemo157 commented May 14, 2020

fixes #72188

r? @estebank

src/librustc_lint/builtin.rs Outdated Show resolved Hide resolved
@Dylan-DPC-zz
Copy link

r? @estebank

@ollie27
Copy link
Member

ollie27 commented May 14, 2020

#[export_name = "..."] is unsafe for the same reason as #[no_mangle] so it should also be detected by this lint.

@jonas-schievink jonas-schievink added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 15, 2020
@joelpalmer joelpalmer added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 26, 2020
@Elinvynia Elinvynia added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2020
@Dylan-DPC-zz
Copy link

@estebank any updates on this?

@Elinvynia Elinvynia added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 18, 2020
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. We'll need to do a crater run with this to make sure we don't cause major regressions in the wild as this is being added to an existing lint. Beyond these nitpicks, it looks good to me.

@@ -272,6 +272,32 @@ impl EarlyLintPass for UnsafeCode {
})
}

ast::ItemKind::Fn(..) => {
if attr::contains_name(&it.attrs, sym::no_mangle) {
self.report_unsafe(cx, it.span, |lint| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use it.name.span instead here and in the other 2 places?

ast::ItemKind::Fn(..) => {
if attr::contains_name(&it.attrs, sym::no_mangle) {
self.report_unsafe(cx, it.span, |lint| {
lint.build("declaration of a `no_mangle` function").emit();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a note to explain why the annotation is problematic and or a link to the docs?

@Nemo157
Copy link
Member Author

Nemo157 commented Jun 30, 2020

@estebank fixed the nitpicks. Are you able to trigger the crater run?

@Dylan-DPC-zz
Copy link

@bors try (before crater run)

@bors
Copy link
Contributor

bors commented Jun 30, 2020

⌛ Trying commit 36c75f4d7dc23bad408f0eb92cd30365434cf2a2 with merge 00bf438af9d3399b4145c87e4f9f6133e40fd673...

@bors
Copy link
Contributor

bors commented Jun 30, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 00bf438af9d3399b4145c87e4f9f6133e40fd673 (00bf438af9d3399b4145c87e4f9f6133e40fd673)

@Dylan-DPC-zz
Copy link

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-72209 created and queued.
🤖 Automatically detected try build 00bf438af9d3399b4145c87e4f9f6133e40fd673
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 17, 2020
LL | unsafe fn baz() {}
| ^^^^^^^^^^^^^^^^^^
LL | #[no_mangle] fn foo() {}
| ^^^
Copy link
Contributor

@danielhenrymantilla danielhenrymantilla Jul 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the lint span point to the attribute itself, rather than the identifier of the item being defined?

Suggested change
| ^^^
| ^^^^^^^^^^^^

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I'll try to get this changed tomorrow.

@craterbot
Copy link
Collaborator

🚧 Experiment pr-72209 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🚨 Experiment pr-72209 has encountered an error: command Command { std: "/workspace/cargo-home/bin/rustup-toolchain-install-master" "e070765f6e6c1035c7c728be486e7e69cb2b4808" "-c" "cargo", kill_on_drop: false } failed
🛠️ If the error is fixed use the retry command.

🆘 Can someone from the infra team check in on this? @rust-lang/infra
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@Mark-Simulacrum
Copy link
Member

@craterbot retry seems to have been spurious

@craterbot
Copy link
Collaborator

🚨 Error: failed to parse the command

🆘 If you have any trouble with Crater please ping @rust-lang/infra!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@Mark-Simulacrum
Copy link
Member

@craterbot retry

@craterbot
Copy link
Collaborator

🛠️ Experiment pr-72209 queued again.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🚧 Experiment pr-72209 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

I'm nominated for lang team discussion next week to draw attention to this.

@pnkfelix
Copy link
Member

pnkfelix commented Nov 2, 2020

@rfcbot reviewed

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Nov 2, 2020
@rfcbot
Copy link

rfcbot commented Nov 2, 2020

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Nov 12, 2020
@rfcbot
Copy link

rfcbot commented Nov 12, 2020

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@spastorino spastorino removed the to-announce Announce this issue on triage meeting label Nov 19, 2020
@tesuji

This comment has been minimized.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Nov 30, 2020
@crlf0710 crlf0710 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 18, 2020
@Dylan-DPC-zz
Copy link

@estebank this is waiting for your final review. Looks ready imo 😃

@nikomatsakis
Copy link
Contributor

@bors r+

I'm sniping this one. Sorry @estebank =)

@bors
Copy link
Contributor

bors commented Feb 8, 2021

📌 Commit fc8a3ad has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 8, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 9, 2021
Rollup of 11 pull requests

Successful merges:

 - rust-lang#72209 (Add checking for no_mangle to unsafe_code lint)
 - rust-lang#80732 (Allow Trait inheritance with cycles on associated types take 2)
 - rust-lang#81697 (Add "every" as a doc alias for "all".)
 - rust-lang#81826 (Prefer match over combinators to make some Box methods inlineable)
 - rust-lang#81834 (Resolve typedef in HashMap lldb pretty-printer only if possible)
 - rust-lang#81841 ([rustbuild] Output rustdoc-json-types docs )
 - rust-lang#81849 (Expand the docs for ops::ControlFlow a bit)
 - rust-lang#81876 (parser: Fix panic in 'const impl' recovery)
 - rust-lang#81882 (:arrow_up: rust-analyzer)
 - rust-lang#81888 (Fix pretty printer macro_rules with semicolon.)
 - rust-lang#81896 (Remove outdated comment in windows' mutex.rs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f8b330d into rust-lang:master Feb 9, 2021
@rustbot rustbot added this to the 1.52.0 milestone Feb 9, 2021
@Nemo157 Nemo157 deleted the lint-no-mangle-in-unsafe-code branch February 9, 2021 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an allow-by-default lint against #[no_mangle]