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

Tidy up miscellaneous bounds suggestions #97778

Merged
merged 5 commits into from
Jun 12, 2022

Conversation

compiler-errors
Copy link
Member

Just some small fixes to suggestions

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.

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

r? @cjgillot

(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 Jun 6, 2022
@compiler-errors compiler-errors changed the title Tidy up miscellaneous bounds suggestion Tidy up miscellaneous bounds suggestions Jun 6, 2022
Copy link
Contributor

@cjgillot cjgillot left a 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_hir/src/hir.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/diagnostics.rs Show resolved Hide resolved
compiler/rustc_middle/src/ty/diagnostics.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/diagnostics.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())
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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-errors
Copy link
Member Author

compiler-errors commented Jun 7, 2022

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

@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 11, 2022

📌 Commit 91b9988 has been approved by cjgillot

@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 Jun 11, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 11, 2022
…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.
@Dylan-DPC
Copy link
Member

failed in rollup ci

@Dylan-DPC
Copy link
Member

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 11, 2022
@compiler-errors
Copy link
Member Author

Added TypeSuperFoldable import, which was apparently introduced sometime recently

@bors r=cjgillot

@bors
Copy link
Contributor

bors commented Jun 11, 2022

📌 Commit 5f7474e has been approved by cjgillot

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 11, 2022
@bors
Copy link
Contributor

bors commented Jun 12, 2022

⌛ Testing commit 5f7474e with merge 37a4225...

@bors
Copy link
Contributor

bors commented Jun 12, 2022

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 37a4225 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 12, 2022
@bors bors merged commit 37a4225 into rust-lang:master Jun 12, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 12, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (37a4225): comparison url.

Instruction count

  • Primary benchmarks: 🎉 relevant improvements found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
-0.3% -0.4% 2
Improvements 🎉
(secondary)
-0.7% -0.8% 6
All 😿🎉 (primary) -0.3% -0.4% 2

Max RSS (memory usage)

Results
  • Primary benchmarks: 😿 relevant regression found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
3.8% 3.8% 1
Regressions 😿
(secondary)
3.3% 3.3% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-2.3% -2.4% 2
All 😿🎉 (primary) 3.8% 3.8% 1

Cycles

Results
  • Primary benchmarks: 🎉 relevant improvements found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
-3.7% -5.1% 4
Improvements 🎉
(secondary)
-2.7% -3.3% 4
All 😿🎉 (primary) -3.7% -5.1% 4

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@compiler-errors compiler-errors deleted the misc-diagnostics-tidy branch August 11, 2023 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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
7 participants