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

cfg!(unsafe(foo)) and --check-cfg=unsafe(cfg(foo)) are erroneously accepted on beta #131055

Closed
Urgau opened this issue Sep 30, 2024 · 4 comments
Closed
Assignees
Labels
C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@Urgau
Copy link
Member

Urgau commented Sep 30, 2024

cfg!(unsafe(foo)) and --check-cfg=unsafe(cfg(foo)) both are erroneously accepted on beta.

They should not be accepted, neither of them is in any way "unsafe".

Code

I tried this code:

fn main() {
    let _a = cfg!(unsafe(foo));
}

I expected to see this happen: an error saying that unsafe cannot be put here like for #[cfg]&#[cfg_attr].

Instead, this happened: the unsafe is silently accepted.

Version it worked on

It most recently worked on: 1.81

Version with regression

rustc --version --verbose:

rustc 1.82.0-beta.5 (6a3b69c6b 2024-09-27)
binary: rustc
commit-hash: 6a3b69c6b0529151da5fb4568961519a80adccf9
commit-date: 2024-09-27
host: x86_64-unknown-linux-gnu
release: 1.82.0-beta.5
LLVM version: 19.1.0

@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged

@Urgau Urgau added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Sep 30, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-untriaged Untriaged performance or correctness regression. labels Sep 30, 2024
@Urgau Urgau self-assigned this Sep 30, 2024
@Noratrieb
Copy link
Member

unsafe { 1 } is also accepted, so I feel like it makes sense to accept it

@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 30, 2024
@Urgau
Copy link
Member Author

Urgau commented Sep 30, 2024

@Noratrieb except that neither #[cfg(unsafe(foo)] nor #[cfg_attr(unsafe(foo), ...)] is accepted.

error: expected identifier, found keyword `unsafe`
 --> src/main.rs:1:7
  |
1 | #[cfg(unsafe(foo))]
  |       ^^^^^^ expected identifier, found keyword
  |
help: escape `unsafe` to use it as an identifier
  |
1 | #[cfg(r#unsafe(foo))]
  |       ++

cfg! is also not on the list of unsafe attributes.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 30, 2024
Reject leading unsafe in `cfg!(...)` and `--check-cfg`

This PR reject leading unsafe in `cfg!(...)` and `--check-cfg`.

Fixes (after-backport) rust-lang#131055
r? `@jieyouxu`
@Noratrieb
Copy link
Member

makes sense

rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 30, 2024
Rollup merge of rust-lang#131057 - Urgau:cfg-erronous-unsafe, r=jieyouxu

Reject leading unsafe in `cfg!(...)` and `--check-cfg`

This PR reject leading unsafe in `cfg!(...)` and `--check-cfg`.

Fixes (after-backport) rust-lang#131055
r? `@jieyouxu`
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 9, 2024
@Mark-Simulacrum Mark-Simulacrum added this to the 1.82.0 milestone Oct 11, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 11, 2024
[beta] backports

- Only add an automatic SONAME for Rust dylibs rust-lang#130960
- Reject leading unsafe in `cfg!(...)` and `--check-cfg` rust-lang#131057, resolving rust-lang#131055
- Disable jump threading `UnOp::Not` for non-bool rust-lang#131201
- Update LLVM submodule rust-lang#131448

r? ghost
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 11, 2024
[beta] backports

- Only add an automatic SONAME for Rust dylibs rust-lang#130960
- Reject leading unsafe in `cfg!(...)` and `--check-cfg` rust-lang#131057, resolving rust-lang#131055
- Disable jump threading `UnOp::Not` for non-bool rust-lang#131201
- Update LLVM submodule rust-lang#131448

r? ghost
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 12, 2024
[beta] backports

- Only add an automatic SONAME for Rust dylibs rust-lang#130960
- Reject leading unsafe in `cfg!(...)` and `--check-cfg` rust-lang#131057, resolving rust-lang#131055
- Disable jump threading `UnOp::Not` for non-bool rust-lang#131201
- Update LLVM submodule rust-lang#131448

r? ghost
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 12, 2024
[beta] backports

- Only add an automatic SONAME for Rust dylibs rust-lang#130960
- Reject leading unsafe in `cfg!(...)` and `--check-cfg` rust-lang#131057, resolving rust-lang#131055
- Disable jump threading `UnOp::Not` for non-bool rust-lang#131201
- Update LLVM submodule rust-lang#131448
- Split x86_64-msvc-ext into two jobs rust-lang#130072
- Use a small runner for msvc-ext2 job rust-lang#130151

r? ghost
@Urgau
Copy link
Member Author

Urgau commented Oct 16, 2024

Backported in #131423, closing.

@Urgau Urgau closed this as completed Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants