-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Do not use desugared ident when suggesting adding a type #52418
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
While this does seem like an improvement, it doesn't feel like a fix to me. But I'm trying to think what would be the better fix -- it's probably at least somewhat involved.
I imagine we could do this:
- given some unresolved type variable
?X
- perhaps just those that are found in a for loop pattern
- we look for a pending trait obligation where
?X
is an "output", so something like?Y: IntoIterator<Item = ?X>
in this case, and find an unresolved type variable in the inputs (here,?Y
) - and then we try to find a good suggestion for
?Y
src/test/ui/issue-51116.stderr
Outdated
--> $DIR/issue-51116.rs:16:13 | ||
| | ||
LL | for tile in row { | ||
| ---- consider giving this a type |
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 you give tile
a type? I don't think you can. It seems like it'd be better to put the suggestion on tiles
...
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.
While I was in the shower thinking about PR this I realized that no, you can't. I'm tempted at completely removing that label for a partial "fix" and call it a day until I have time to explore the suggestion above.
src/test/ui/issue-51116.stderr
Outdated
| ---- consider giving this a type | ||
LL | //~^ NOTE consider giving this a type | ||
LL | *tile = 0; | ||
| ^^^^^ cannot infer type for `_` |
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.
Cannot infer type for _
is not particularly clear I fear :(
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.
This less than ideal text appears more than I would like... I'm not sure if there's already a ticket for it. I'll create one.
Looking at the code, it seems like implementing my suggestion would be not entirely trivial. I wonder if we could do something simpler to start -- e.g., if we notice that we are part of a for loop desugaring, we could walk up the HIR tree to find the for loop, and then highlight the collection expression that we are iterating over. Then we might say something like:
not... great I guess. But easy-ish and better than where we are. |
Maybe worth doing the better thing though |
Your last suggestion might be able to be implemented by giving |
@nikomatsakis changed the output to #52418 (comment). I feel this is enough of an improvement for this PR, but we can leave the original ticket open. |
This comment has been minimized.
This comment has been minimized.
@nikomatsakis Just took a look at the existing test output that generates the
I can't really think of an improvement at this time for them :-/ |
It doesn't seem to me that the "for For example, isn't
ever so slightly better than
? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
|
r=me |
956bab7
to
2c5b60d
Compare
@bors r=nikomatsakis rollup |
📌 Commit 2c5b60d has been approved by |
…sakis Do not use desugared ident when suggesting adding a type Re rust-lang#51116.
Rollup of 13 pull requests Successful merges: - #51628 (use checked write in `LineWriter` example) - #52116 (Handle array manually in str case conversion methods) - #52218 (Amend option.take examples) - #52418 (Do not use desugared ident when suggesting adding a type) - #52439 (Revert some changes from #51917 to fix custom libdir) - #52455 (Fix doc comment: use `?` instead of `.unwrap()`) - #52458 (rustc: Fix a suggestion for the `proc_macro` feature) - #52464 (Allow clippy to be installed with make install) - #52472 (rustc: Enable `use_extern_macros` in 2018 edition) - #52477 (Clarify short-circuiting behvaior of Iterator::zip.) - #52480 (Cleanup #24958) - #52487 (Don't build twice the sanitizers on Linux) - #52510 (rustdoc: remove FIXME about macro redirects) Failed merges: r? @ghost
Re #51116.