-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tidy up miscellaneous bounds suggestions #97778
Conversation
r? @cjgillot (rust-highfive has picked a reviewer for you, use r? to override) |
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 is a good improvement in diagnostics.
I have the impression we could get rid of the string comparisons, to avoid nonsense diagnostics if we have multiple impl trait with the same trait.
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Show resolved
Hide resolved
|
||
Param(param) => { | ||
if let Some(found_bound_str) = | ||
param.name.as_str().strip_prefix("impl ").map(|s| s.trim_start()) |
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.
Could we rather work on the DefId
?
There may be multiple impl Trait
with the same string name.
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 would like to do this, but I was having trouble associating a hir::GenericParam
, ty::Param
, DefId
... etc. I don't really know how to convert all of them to each other. Is there anywhere I should look to learn?
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.
def_id == tcx.hir().local_def_id(hir_generic_param.hir_id) == tcx.generics_of(item).type_param(ty_param).def_id
Does this help?
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.
Yup, that probably works. I will try to refactor all of the string stuff to instead use the DefId
of the generic instead.
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.
Actually -- for the is_suggestable
type visitor (which walks a TypeFoldable
kind to see if it references any types that aren't suggestable, i.e. don't make sense to emit in a suggestion when pretty-printed), we don't have ty::Generics
available to look up the ty::ParamTy
.
All of the other usages are fine, but specifically here, I think it would be kind of hard to refactor to use a def id.
Anyways, I will see what I can do.
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
Hopefully addressed comments. I couldn't get rid of all of the string manipulation, but I tried to use def-id where I could. @rustbot ready |
@bors r+ |
📌 Commit 91b9988 has been approved by |
…dy, r=cjgillot Tidy up miscellaneous bounds suggestions Just some small fixes to suggestions - Generalizes `Ty::is_suggestable` into a `TypeVisitor`, so that it can be called on things other than `Ty` - Makes `impl Trait` in arg position no longer suggestible (generalizing the fix in rust-lang#97640) - Fixes `impl Trait` not being replaced with fresh type param when it's deeply nested in function signature (fixes rust-lang#97760) - Fixes some poor handling of `where` clauses with no predicates (also rust-lang#97760) - Uses `InferCtxt::resolve_numeric_literals_with_default` so we suggest `i32` instead of `{integer}` (fixes rust-lang#97677) Sorry there aren't many tests the fixes. Most of them would just be duplicates of other tests with empty `where` clauses or `impl Trait` in arg position instead of generic params. Let me know if you'd want more test coverage.
failed in rollup ci |
@bors r- |
91b9988
to
5f7474e
Compare
Added @bors r=cjgillot |
📌 Commit 5f7474e has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (37a4225): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |
Just some small fixes to suggestions
Ty::is_suggestable
into aTypeVisitor
, so that it can be called on things other thanTy
impl Trait
in arg position no longer suggestible (generalizing the fix in Fix wrong suggestion for adding where clauses #97640)impl Trait
not being replaced with fresh type param when it's deeply nested in function signature (fixes Rust diagnostic forimpl Trait
suggests broken code #97760)where
clauses with no predicates (also Rust diagnostic forimpl Trait
suggests broken code #97760)InferCtxt::resolve_numeric_literals_with_default
so we suggesti32
instead of{integer}
(fixes Give helpful suggestions for code containing {integer} and other non-concrete types #97677)Sorry there aren't many tests the fixes. Most of them would just be duplicates of other tests with empty
where
clauses orimpl Trait
in arg position instead of generic params. Let me know if you'd want more test coverage.