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

Allow #[deny] inside #[forbid] as a no-op #121560

Merged
merged 2 commits into from
Oct 20, 2024

Conversation

Noratrieb
Copy link
Member

Forbid cannot be overriden. When someome tries to do this anyways, it results in a hard error. That makes sense.

Except it doesn't, because macros. Macros may reasonably use #[deny] (or #[warn] for an allow-by-default lint) in their expansion to assert that their expanded code follows the lint. This is doesn't work when the output gets expanded into a forbid() context. This is pretty silly, since both the macros and the code agree on the lint!

By making it a warning instead, we remove the problem with the macro, which is now nothing as warnings are suppressed in macro expanded code, while still telling users that something is up.

fixes #121483

@rustbot
Copy link
Collaborator

rustbot commented Feb 24, 2024

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 24, 2024
/// expanded output, which might get expanded into a context that is `forbid()` already,
/// this is not a hard error.
/// As lints in macros are suppressed, so this lint will not show up in these cases.
pub UNOVERRIDABLE_LINT_LEVEL,
Copy link
Member Author

Choose a reason for hiding this comment

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

better lint name ideas welcome

@Noratrieb Noratrieb added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). I-lang-nominated Nominated for discussion during a lang team meeting. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 24, 2024
@rust-log-analyzer

This comment has been minimized.

@workingjubilee
Copy link
Member

workingjubilee commented Feb 25, 2024

My understanding is that this allows this pattern:

#![forbid(lint)]

#[deny(lint)]
fn something() {
    // code
}

Can this come with a test for this case?

#![forbid(lint)]

#[deny(lint)]
fn something() {
    #[allow(lint)]
    {
        // linted code
    }
}

Apologies if this test already exists and I just didn't notice it.

@TaKO8Ki
Copy link
Member

TaKO8Ki commented Feb 26, 2024

@rustbot author

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 26, 2024
@scottmcm
Copy link
Member

scottmcm commented Feb 28, 2024

When do people really want forbid? The only thing that comes to mind for me is forbid(unsafe_code), where I could consider it a plus that a macro can't allow(unsafe_code) to use it anyway.

If people hit this, maybe the resolution instead would be to say "well use deny then"?

@joshtriplett
Copy link
Member

joshtriplett commented Feb 28, 2024

It seems completely fine to #[deny] inside a #[forbid], and I don't think we need a warning for that. (The lint should remain in the forbidden state, and should still not subsequently be allow-able.)

The thing that shouldn't be allowed is using #[warn] or #[allow] inside #[forbid]; that's the exact thing that #[forbid] forbids, so if you want to allow that, don't use #[forbid].

@joshtriplett
Copy link
Member

@workingjubilee Agreed that we should have a test for allow-inside-deny-inside-forbid, as well as a test for warn-inside-deny-inside-forbid, both of which should be an error. (The test should check the case where that happens via a macro, as well.)

@traviscross
Copy link
Contributor

traviscross commented Feb 28, 2024

We discussed this at the end of the lang triage call today and did not reach a resolution before running out of time.

We'll leave this nominated so as to discuss in the meeting on a future week.

@joshtriplett joshtriplett added T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 6, 2024
@joshtriplett
Copy link
Member

We discussed this again in today's @rust-lang/lang meeting. Concrete proposal to get consensus on:

  • Allow deny within forbid, silently without any warning, but keep the state forbid. Rationale: forbid is just "deny and don't allow that to be changed".

  • Continue to hard-error on warn or allow within forbid. Re-evaluate after fixing deny.

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Mar 6, 2024

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Mar 6, 2024
@joshtriplett
Copy link
Member

joshtriplett commented Mar 6, 2024

@Nilstrieb Could you please remove the warning, and silently allow deny within forbid (but ensure that the state remains forbid so that allow-inside-deny-inside-forbid is still a hard error)?

@traviscross
Copy link
Contributor

@rustbot labels -I-lang-nominated

As mentioned above, this was discussed today and the mood in the meeting was positive on doing what Josh proposed. Since it was discussed and there's now a propose FCP here, let's unnominate.

@rustbot rustbot removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Mar 6, 2024
@workingjubilee
Copy link
Member

Thanks! This will help me significantly for situations where a forbid(lint) holding is critical... yes, usually forbid(unsafe_code)... while permitting macro code to generate its own deny(lint)s so that it retains internal consistency in its expansion, so that if a macro is used in both a forbid(lint) context and outside of that context, it doesn't have to rethink how it expands certain pieces of code.

@bors
Copy link
Contributor

bors commented Mar 14, 2024

☔ The latest upstream changes (presumably #122483) made this pull request unmergeable. Please resolve the merge conflicts.

@tmandry
Copy link
Member

tmandry commented Jun 28, 2024

@rfcbot reviewed

Note that the PR still needs to be updated to reflect the lang team consensus (no warning on deny-in-forbid, but it's a no-op).

Personally I'm in favor of going farther and allowing #[warn] and even #[allow] as no-ops with a warning (and that warning would be suppressed inside macro expansions). But let's get this merged first.

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Jun 28, 2024
@rust-log-analyzer

This comment has been minimized.

@jieyouxu jieyouxu removed the needs-fcp This change is insta-stable, so needs a completed FCP to proceed. label Oct 18, 2024
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Thanks, this LGTM with some additional test coverage. Though may need to fix the lint docs failure, not sure what's up with that, I haven't looked closely at it.

tests/ui/lint/deny-inside-forbid-ignored.rs Show resolved Hide resolved
tests/ui/lint/forbid-macro-with-deny.rs Outdated Show resolved Hide resolved
tests/ui/lint/deny-inside-forbid-ignored.rs Outdated Show resolved Hide resolved
@jieyouxu jieyouxu added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Oct 18, 2024
@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Oct 18, 2024
@rust-log-analyzer

This comment has been minimized.

Noratrieb and others added 2 commits October 18, 2024 18:18
Forbid cannot be overriden. When someome tries to do this anyways,
it results in a hard error. That makes sense.

Except it doesn't, because macros. Macros may reasonably use `#[deny]`
in their expansion to assert
that their expanded code follows the lint. This is doesn't work when the
output gets expanded into a `forbid()` context. This is pretty silly,
since both the macros and the code agree on the lint!

Therefore, we allow `#[deny(..)]`ing a lint that's already forbidden,
keeping the level at forbid.
@Noratrieb
Copy link
Member Author

the lint-docs failure was because the lint docs were relying on deny inside forbid being wrong, i changed that one to warn.
i also opened a pr to the reference: rust-lang/reference#1655

@Noratrieb
Copy link
Member Author

oh @rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 20, 2024
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Thanks!

@jieyouxu
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Oct 20, 2024

📌 Commit 1af9d11 has been approved by jieyouxu

It is now in the queue for this repository.

@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 Oct 20, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 20, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#121560 (Allow `#[deny]` inside `#[forbid]` as a no-op)
 - rust-lang#131365 (Fix missing rustfmt in msi installer rust-lang#101993)
 - rust-lang#131647 (Register `src/tools/unicode-table-generator` as a runnable tool)
 - rust-lang#131843 (compiler: Error on layout of enums with invalid reprs)
 - rust-lang#131926 (Align boolean option descriptions in `configure.py`)
 - rust-lang#131961 (compiletest: tidy up how `tidy` and `tidy` (html version) are disambiguated)
 - rust-lang#131962 (Make `llvm::set_section` take a `&CStr`)
 - rust-lang#131964 (add latest crash tests)
 - rust-lang#131965 (remove outdated comment)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7b714d4 into rust-lang:master Oct 20, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Oct 20, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 20, 2024
Rollup merge of rust-lang#121560 - Noratrieb:stop-lint-macro-nonsense, r=jieyouxu

Allow `#[deny]` inside `#[forbid]` as a no-op

Forbid cannot be overriden. When someome tries to do this anyways, it results in a hard error. That makes sense.

Except it doesn't, because macros. Macros may reasonably use `#[deny]` (or `#[warn]` for an allow-by-default lint) in their expansion to assert that their expanded code follows the lint. This is doesn't work when the output gets expanded into a `forbid()` context. This is pretty silly, since both the macros and the code agree on the lint!

By making it a warning instead, we remove the problem with the macro, which is now nothing as warnings are suppressed in macro expanded code, while still telling users that something is up.

fixes rust-lang#121483
@Noratrieb Noratrieb deleted the stop-lint-macro-nonsense branch October 20, 2024 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-testsuite Area: The testsuite used to check the correctness of rustc 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-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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.

thread_local with const { } fails to compile in file with #![forbid(unsafe_op_in_unsafe_fn)]