-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Improve Error Messaging for Unconstructed Structs and Enum Variants in Generic Contexts #92569
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @davidtwco (or someone else) soon. Please see the contribution instructions for more information. |
r? @estebank |
if let Some(snippet) = snippet { | ||
if let ty::FnDef(def_id, _) = rcvr_ty.kind() { | ||
let hir_id = | ||
tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we assume this won't fail here? Is it ok for it to fail?
Please also add a UI test ( |
error[E0599]: no method named `foo` found for fn item `fn() -> Inner {Inner}` in the current scope | ||
--> src/test/ui/typeck/issue-87181-empty-tuple-fields.rs:16:15 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to run ./x.py test --bless src/test/ui/typeck/issue-87181-empty-tuple-fields.rs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I might be missing something? I ran your command and it generated the stderr file, but the test still fails, and it's showing me some JSON.
Edit: I figured it out, I needed a //~^ ERROR
in there
@camelid Did I pick an acceptable filename for the ui test? I couldn't find much guidance in the contribution guide |
The name seems fine to me. |
This comment has been minimized.
This comment has been minimized.
Proposal: Go beyond the scope of the ticket to improve error handling to support tuple-structs with elements, and also add the check to member access rather than just to method calls For instance we can cover this case as so: struct Bar<T> {
bar: T
}
struct Foo(u8);
impl Foo {
fn foo() { }
}
fn main() {
let thing = Bar { bar: Foo };
thing.bar.0;
} error[E0609]: no field `0` on type `fn(u8) -> Foo {Foo}`
--> test.rs:12:15
|
12 | thing.bar.0;
| --------- ^
| |
| help: call the constructor: `(thing.bar)(_)`
|
= help: placeholder
error: aborting due to previous error
For more information about this error, try `rustc --explain E0609`. Also, if the original code has unnecessary brackets, like |
I have expanded the scope a little in line with my proposal. Now, the same checks are applied to field accesses, and non-empty tuple constructors are handled. There are 2 new tests to cover these cases. |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
It seems like there might have been a network error? |
@bors retry |
🔒 Merge conflict This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again. How do I rebase?Assuming
You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial. Please avoid the "Resolve conflicts" button on GitHub. It uses Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Error message
|
It seems like you'll have to rebase. You might want to squash all your commits into one before doing that to make it easier to resolve the merge conflicts. |
It does seem that way. I'm looking at it now and it looks like some new diagnostics were implemented, so I'll have to figure out what it does so I can integrate it with my diagnostics 🤔 |
☔ The latest upstream changes (presumably #96428) made this pull request unmergeable. Please resolve the merge conflicts. |
Oh God |
I think I messed up the rebase. At this point I just want to make a new branch Edit: I'm in the process of making a new branch now. |
Unfortunately I had to force push, but I think it should be ok now |
@bors r+ |
📌 Commit a6b570b has been approved by |
Rollup of 6 pull requests Successful merges: - rust-lang#92569 (Improve Error Messaging for Unconstructed Structs and Enum Variants in Generic Contexts) - rust-lang#96370 (Cleanup `report_method_error` a bit) - rust-lang#96383 (Fix erased region escaping into wfcheck due to rust-lang#95395) - rust-lang#96385 (Recover most `impl Trait` and `dyn Trait` lifetime bound suggestions under NLL) - rust-lang#96410 (rustdoc: do not write `{{root}}` in `pub use ::foo` docs) - rust-lang#96430 (Fix handling of `!` in rustdoc search) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Improves error messaging for empty-tuple structs and enum variants in certain generic contexts. See new ui tests for examples.
Closes #87181