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

We're not warning against fn ptr and wide raw ptr nested inside ADTs #116929

Closed
RalfJung opened this issue Oct 19, 2023 · 2 comments · Fixed by #116930
Closed

We're not warning against fn ptr and wide raw ptr nested inside ADTs #116929

RalfJung opened this issue Oct 19, 2023 · 2 comments · Fixed by #116930
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

I found a gap in our match forward-compatibility warnings:

type T = (*const [i32], i32);
const C: T = (unsafe { std::mem::transmute((0usize, 0usize)) }, 0);

fn test(x: T) -> bool {
    matches!(x, C)
}

This should warn but doesn't.

The reason is that here we are only checking the top-level type to be a wide raw ptr or fn ptr, we are not recursing.

The fix IMO is to reject those types in compiler/rustc_trait_selection/src/traits/structural_match.rs, which already recurses the type.

Cc @oli-obk @lcnr

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 19, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Oct 19, 2023

The fix IMO is to reject those types in compiler/rustc_trait_selection/src/traits/structural_match.rs, which already recurses the type.

That would warn on Option<String>, which can be used at None value

@RalfJung
Copy link
Member Author

RalfJung commented Oct 19, 2023

That would warn on Option, which can be used at None value

It would? That's surprising, since valtree construction will succeed for None: Option<String>.
So that could be used as a signal not to lint.

@workingjubilee workingjubilee added A-diagnostics Area: Messages for errors, warnings, and lints A-patterns Relating to patterns and pattern matching T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 19, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 28, 2023
patterns: reject raw pointers that are not just integers

Matching against `0 as *const i32` is fine, matching against `&42 as *const i32` is not.

Also fixes rust-lang#116929.

Cc `@oli-obk` `@lcnr`
@bors bors closed this as completed in fdaaaf9 Nov 8, 2023
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Nov 15, 2023
patterns: reject raw pointers that are not just integers

Matching against `0 as *const i32` is fine, matching against `&42 as *const i32` is not.

This extends the existing check against function pointers and wide pointers: we now uniformly reject all these pointer types during valtree construction, and then later lint because of that. See [here](rust-lang/rust#116930 (comment)) for some more explanation and context.

Also fixes rust-lang/rust#116929.

Cc `@oli-obk` `@lcnr`
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
patterns: reject raw pointers that are not just integers

Matching against `0 as *const i32` is fine, matching against `&42 as *const i32` is not.

This extends the existing check against function pointers and wide pointers: we now uniformly reject all these pointer types during valtree construction, and then later lint because of that. See [here](rust-lang/rust#116930 (comment)) for some more explanation and context.

Also fixes rust-lang/rust#116929.

Cc `@oli-obk` `@lcnr`
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
patterns: reject raw pointers that are not just integers

Matching against `0 as *const i32` is fine, matching against `&42 as *const i32` is not.

This extends the existing check against function pointers and wide pointers: we now uniformly reject all these pointer types during valtree construction, and then later lint because of that. See [here](rust-lang/rust#116930 (comment)) for some more explanation and context.

Also fixes rust-lang/rust#116929.

Cc `@oli-obk` `@lcnr`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants