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

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

Closed
oli-obk opened this issue Sep 19, 2022 · 6 comments
Closed

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

oli-obk opened this issue Sep 19, 2022 · 6 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-needs-test Call 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-diagnostics Working group: Diagnostics

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Sep 19, 2022

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)

@oli-obk oli-obk added WG-diagnostics Working group: Diagnostics F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` labels Sep 19, 2022
@oli-obk oli-obk moved this to Can do after stabilization in type alias impl trait stabilization Sep 19, 2022
@lcnr
Copy link
Contributor

lcnr commented Sep 19, 2022

i do think we should experiment with adding the too generic type to TooGeneric, i tried splitting that variant which was more annoying than helpful

@inquisitivecrystal inquisitivecrystal added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints labels Sep 20, 2022
@inquisitivecrystal
Copy link
Contributor

inquisitivecrystal commented Sep 20, 2022

Triage note: I was going to add one or more of the D- labels, but wasn't sure which ones were appropriate. The OP and linked post don't really help me to understand what's going on and why it's a problem. I'm sure they're perfectly comprehensible to those who understand the situation better than I do, but a little bit of elaboration might help make this issue clearer. :)

@oli-obk
Copy link
Contributor Author

oli-obk commented Sep 20, 2022

Oof, yea, sorry about that. I added some explanation including what should actually be done.

@oli-obk oli-obk added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Sep 20, 2022
@inquisitivecrystal inquisitivecrystal added D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. C-bug Category: This is a bug. and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Sep 20, 2022
@lcnr
Copy link
Contributor

lcnr commented Sep 20, 2022

my idea was

pub enum ErrorHandled<'tcx> {
    Reported(ErrorGuaranteed),
    Linted,
    TooGeneric(Ty<'tcx>),
}

Ty<'tcx> might not be perfect, e.g. sometimes we fail to resolve an instance, so there using Ty<'tcx> is wrong 🤔 maybe TooGeneric(&'tcx TooGenericCause<'tcx>) with TooGenericCause<'tcx> being an enum with the variants we care about 🤔

this should give us pretty good error messages with a hopefully acceptable perf impact

@compiler-errors
Copy link
Member

compiler-errors commented Oct 22, 2022

This no longer reports the same error as the issue, and instead just says:

error: `Bar` cannot be used in patterns
  --> src/main.rs:15:9
   |
15 |         LEAK_FREE => (),
   |         ^^^^^^^^^

warning: unreachable pattern
  --> src/main.rs:16:9
   |
15 |         LEAK_FREE => (),
   |         --------- matches any value
16 |         _ => (),
   |         ^ unreachable pattern
   |
   = note: `#[warn(unreachable_patterns)]` on by default

warning: `playground` (bin "playground") generated 1 warning
error: could not compile `playground` due to previous error; 1 warning emitted

@oli-obk oli-obk added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Oct 22, 2022
@JohnTitor
Copy link
Member

Triage: Since we already have a test as src/test/ui/type-alias-impl-trait/structural-match-no-leak.rs, I think we could just close this issue. Closing.

@github-project-automation github-project-automation bot moved this from Can do after stabilization to Done in type alias impl trait stabilization Jan 5, 2023
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 C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-needs-test Call 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-diagnostics Working group: Diagnostics
Development

No branches or pull requests

5 participants