Skip to content

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

Closed
@RalfJung

Description

@RalfJung
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

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Oct 19, 2023
oli-obk

oli-obk commented on Oct 19, 2023

@oli-obk
Contributor

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

RalfJung commented on Oct 19, 2023

@RalfJung
MemberAuthor

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.

added
A-diagnosticsArea: Messages for errors, warnings, and lints
A-patternsRelating to patterns and pattern matching
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-bugCategory: This is a bug.
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Oct 19, 2023
added a commit that references this issue on Oct 28, 2023

Auto merge of rust-lang#116930 - RalfJung:raw-ptr-match, r=<try>

added a commit that references this issue on Nov 8, 2023

Auto merge of rust-lang#116930 - RalfJung:raw-ptr-match, r=davidtwco

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-patternsRelating to patterns and pattern matchingC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @RalfJung@oli-obk@workingjubilee@rustbot

      Issue actions

        We're not warning against fn ptr and wide raw ptr nested inside ADTs · Issue #116929 · rust-lang/rust