-
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
Add parentheses properly for borrowing suggestion #105019
Conversation
r? @cjgillot (rustbot has picked a reviewer for you, use r? to override) |
It's a hacky fix, but seems we also use rust/compiler/rustc_hir_typeck/src/demand.rs Line 830 in df04d28
|
@@ -1118,13 +1118,22 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { | |||
); | |||
} else { | |||
let is_mut = mut_ref_self_ty_satisfies_pred || ref_inner_ty_mut; | |||
// FIXME: hacky way to get the correct suggestion, see #104961 |
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 honestly just suggest &(<expr>)
always, it's too difficult to create a correct check here, since you could do String::new() + ("")
.
Since we don't have access to the hir::Expr
, we should just always be pessimistic.
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.
Yes, let me check how we passing to here, I had a dig yesterday, seems need lot of changes.
6ad47da
to
327f1b9
Compare
@rustbot ready |
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
if !needs_parens { | ||
sugg_prefix | ||
} else { | ||
format!("{}({})", sugg_prefix, snippet) |
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.
Suggestions that copy user code are typically hard to understand: everything is underlined, and the difference is not underlined.
Could you prefer a multipart suggestion with &(
at the beginning and )
at the end?
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.
make sense, fixed.
@@ -1351,13 +1352,34 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { | |||
); |
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.
Should the parentheses be added to this suggestion too?
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 don't think so, I go through all the UI testcase come from this part,
they are all with single argument, and scenrio here is both &
and &mut
can be added for borrowing.
I haven't figure out an case which we should add parentheses here.
327f1b9
to
8f736a4
Compare
@bors r+ |
Rollup of 9 pull requests Successful merges: - rust-lang#105019 (Add parentheses properly for borrowing suggestion) - rust-lang#106001 (Stop at the first `NULL` argument when iterating `argv`) - rust-lang#107098 (Suggest function call on pattern type mismatch) - rust-lang#107490 (rustdoc: remove inconsistently-present sidebar tooltips) - rust-lang#107855 (Add a couple random projection tests for new solver) - rust-lang#107857 (Add ui test for implementation on projection) - rust-lang#107878 (Clarify `new_size` for realloc means bytes) - rust-lang#107888 (revert rust-lang#107074, add regression test) - rust-lang#107900 (Zero the `REPARSE_MOUNTPOINT_DATA_BUFFER` header) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes #104961