Improve &pin reference-pattern suggestions#156087
Improve &pin reference-pattern suggestions#156087P8L1 wants to merge 1 commit intorust-lang:mainfrom
&pin reference-pattern suggestions#156087Conversation
|
r? @mu001999 rustbot has assigned @mu001999. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
r? Kivooeo |
1b1b070 to
61cf5f2
Compare
|
two things i think should be improved
so, if we can't check 1 point then i'd say to wait on stabilization of this feature, and then fix that fixme |
|
@rustbot authot |
Thanks for the suggestion. I gated the type-position |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
This diff could be simplified, looks slightly over-engineered. Here's a leaner approach: diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs
index d7f15222376..604beb6da3c 100644
--- a/compiler/rustc_hir_typeck/src/pat.rs
+++ b/compiler/rustc_hir_typeck/src/pat.rs
@@ -1407,6 +1407,11 @@ fn borrow_pat_suggestion(&self, err: &mut Diag<'_>, pat: &Pat<'_>) {
};
match binding_parent {
+ // FIXME(pin_ergnomics): we currenty skip suggestion if feature is not enabled
+ // because the correct suggestion requeiers feature to be enabled
+ // so we want only ask user to enable feature
+ hir::Node::Param(hir::Param { ty_span, pat, .. })
+ if pat.span != *ty_span && !tcx.features().pin_ergonomics() => {}
// Check that there is explicit type (ie this is not a closure param with inferred type)
// so we don't suggest moving something to the type that does not exist
hir::Node::Param(hir::Param { ty_span, pat, .. }) if pat.span != *ty_span => {
@@ -1414,7 +1419,7 @@ fn borrow_pat_suggestion(&self, err: &mut Diag<'_>, pat: &Pat<'_>) {
format!("to take parameter `{binding}` by reference, move `&{pin_and_mut}` to the type"),
vec![
(pat.span.until(inner.span), "".to_owned()),
- (ty_span.shrink_to_lo(), mutbl.ref_prefix_str().to_owned()),
+ (ty_span.shrink_to_lo(), format!("&{}", pinned.prefix_str(mutbl))),
],
Applicability::MachineApplicable
); |
Thanks, simplified this along those lines. I kept the feature-gate arm limited to pinned reference patterns so ordinary I also kept the stabilization FIXME and re-blessed the affected UI output. |
|
@bors squash |
This comment has been minimized.
This comment has been minimized.
* Improve diagnostics for pinned reference patterns * Gate pin pattern suggestion on pin ergonomics * Document pin ergonomics suggestion gate * Remove unnecessary incomplete_features allow Co-authored-by: Redddy <midzy0228@gmail.com> * Remove redundant incomplete_features allow UI tests already allow incomplete_features by default, so the explicit allow is unnecessary. * Update ref-pat-suggestions stderr Bless line-number changes after removing the redundant incomplete_features allow. * Simplify pinned ref pattern suggestion gating * Fix formatting * More formatting fixes
|
🔨 9 commits were squashed into 14d414b. |
0907979 to
14d414b
Compare
|
@bors r+ rollup |
…ns, r=Kivooeo Improve `&pin` reference-pattern suggestions This fills in the `pin_ergonomics` FIXME in `borrow_pat_suggestion` by making the diagnostic prefix account for both `Pinnedness` and `Mutability`. Previously, the type-position suggestion path used ordinary reference spelling, which can spell `&` and `&mut` but cannot correctly spell pinned reference-pattern suggestions such as `&pin const` and `&pin mut`. This is a diagnostic-only change. It adds focused UI coverage for both pinned const and pinned mut reference-pattern suggestions.
Rollup of 16 pull requests Successful merges: - #155848 ([doc]: Revert `core::io::ErrorKind` doc changes) - #155855 (Remove unnecessary `get_unchecked`) - #155543 (docs(unstable-book): Document const generics features) - #155962 (`rustc`: `target_features`: allow for `cfg`-only stable `target_features`) - #156043 (c-variadic: gate `va_arg` on `c_variadic_experimental_arch`) - #156082 (Move tests associated types) - #156087 (Improve `&pin` reference-pattern suggestions) - #156092 (Clean up `TyCtxt::needs_crate_hash` usage and rename it to `needs_hir_hash`.) - #156103 (Fix E0040 suggestion for explicit `Drop::drop` UFCS calls) - #156104 (Relax `T: Sized` bound on `try_as_dyn` / `try_as_dyn_mut`) - #156122 (Add a `doc_cfg` regression test to ensure foreign types impls are working as expected) - #156128 (.mailmap: prefer matching just based on commit emails) - #156135 (Remove most uses of def_id_to_node_id) - #156152 (Update books) - #156154 (tests: mark import UI tests as check-pass) - #156162 (Update `browser-ui-test` version to `0.23.5`)
View all comments
This fills in the
pin_ergonomicsFIXME inborrow_pat_suggestionby making the diagnostic prefix account for bothPinnednessandMutability.Previously, the type-position suggestion path used ordinary reference spelling, which can spell
&and&mutbut cannot correctly spell pinned reference-pattern suggestions such as&pin constand&pin mut.This is a diagnostic-only change. It adds focused UI coverage for both pinned const and pinned mut reference-pattern suggestions.