Skip to content

Wrong diagnostic when using constant of TAIT type in pattern #102011

Closed
@oli-obk

Description

@oli-obk

The test src/test/ui/type-alias-impl-trait/structural-match-no-leak.rs (copied below to preserve its state)

#![feature(type_alias_impl_trait)]

type Bar = impl Send;

// While i32 is structural-match, we do not want to leak this information.
// (See https://github.com/rust-lang/rust/issues/72156)
const fn leak_free() -> Bar {
    7i32
}
const LEAK_FREE: Bar = leak_free();

fn leak_free_test() {
    match LEAK_FREE {
        LEAK_FREE => (),
        //~^ ERROR constant pattern depends on a generic parameter
        //~| ERROR constant pattern depends on a generic parameter
        _ => (),
    }
}

fn main() {}

reports an error about "depends on a generic parameter", when there are no generic parameters anywhere. The issue is that we only have a single TooGeneric variant in https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/enum.ErrorHandled.html#variant.TooGeneric . We should change that fieldless variant to TooGeneric(TooGeneric) and introduce an

enum TooGeneric {
    /// The query encountered a generic parameter and could
    /// not extract required information from it.
    Param,
    /// The query encountered an opaque type in `Reveal::Userfacing`
    /// mode and was thus unable to reveal the hidden type.
    OpaqueType,
}

Originally posted by @lcnr in #101478 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions