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

Include enum path in variant suggestion #101357

Merged
merged 1 commit into from
Sep 6, 2022

Conversation

compiler-errors
Copy link
Member

(except for Result and Option, which we should have via the prelude)

Fixes #101356

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 3, 2022
@rust-highfive
Copy link
Collaborator

r? @oli-obk

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 3, 2022
@bors
Copy link
Contributor

bors commented Sep 3, 2022

☔ The latest upstream changes (presumably #101139) made this pull request unmergeable. Please resolve the merge conflicts.

Comment on lines +702 to +703
let name = if tcx.get_diagnostic_item(sym::Option) == Some(adt_did)
|| tcx.get_diagnostic_item(sym::Result) == Some(adt_did)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it might give incorrect suggestions when using #![no_implicit_prelude].

Copy link
Member Author

@compiler-errors compiler-errors Sep 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, but that could probably be said about plenty of other suggestions where we're currently rendering paths, making suggestions, etc. They're, at most, best effort.

I don't think this needs to be fixed, especially because it's basically impossible to determine what the proper shortest path to refer to an item is in any module, due to rustc_resolve not exposing import information in a way we can consume here, and it would be unnecessarily verbose to print the full untrimmed path (e.g. std::option::Option::Some).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @estebank I remember some tests getting updated that now figure out the best import path to use, but I may be totally off here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the change you remember @oli-obk was about the ordering of suggestions (it filters core:: paths if the std:: is available too), not for this. I think that we eventually would want to rebuild suggestions so that we can ask for paths in a specific DefId or HirId so that it is always accurate for that scope, but we're far from there.

I'm ok with landing this as is.

@oli-obk
Copy link
Contributor

oli-obk commented Sep 6, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Sep 6, 2022

📌 Commit be53bd8 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 6, 2022
{
variant.name.to_string()
} else {
format!("{}::{}", tcx.def_path_str(adt_def.did()), variant.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't variants have a def id that can be passed into def_path_str?

let name = if tcx.get_diagnostic_item(sym::Option) == Some(adt_did)
|| tcx.get_diagnostic_item(sym::Result) == Some(adt_did)
{
variant.name.to_string()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use the printing machinery (that only uses the name if it is unique, otherwise the full path), then this suggestion would be mostly right in the face of local shadowing (but see previous comment about needing a function that takes a scope identifier for accurate paths, always).

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 6, 2022
…llaumeGomez

Rollup of 7 pull requests

Successful merges:

 - rust-lang#101357 (Include enum path in variant suggestion)
 - rust-lang#101434 (Update `SessionDiagnostic::into_diagnostic` to take `Handler` instead of `ParseSess`)
 - rust-lang#101445 (Suggest introducing an explicit lifetime if it does not exist)
 - rust-lang#101457 (Recover from using `;` as separator between fields)
 - rust-lang#101462 (Rustdoc-Json: Store Variant Fields as their own item.)
 - rust-lang#101471 (Report number of delayed bugs properly with `-Ztreat-err-as-bug`)
 - rust-lang#101473 (Add more size assertions for MIR types.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d13aefd into rust-lang:master Sep 6, 2022
@rustbot rustbot added this to the 1.65.0 milestone Sep 6, 2022
@compiler-errors compiler-errors deleted the variant-sugg-tweak branch November 2, 2022 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

E0004 non-exhaustive patterns suggestion has unqualified enum variant
7 participants