-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
redundant_slicing
precedence fix
#7976
Conversation
r? @xFrednet (rust-highfive has picked a reviewer for you, use r? to override) |
1b67c0b
to
1571cc7
Compare
/// The `SyntaxContext` of the expression will be walked up to the given target context (usually | ||
/// from the parent expression) before extracting a snippet. This allows getting the call to a macro | ||
/// rather than the expression from expanding the macro. e.g. In the expression `&vec![]` taking a | ||
/// snippet of the chile of the borrow expression will get a snippet of what `vec![]` expands in to. |
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.
/// snippet of the chile of the borrow expression will get a snippet of what `vec![]` expands in to. | |
/// snippet of the child of the borrow expression will get a snippet of what `vec![]` expands in to. |
Did you mean child here? Otherwise, I'm not sure what chile is referring to :)
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 swear I know how to type.
|
||
// Attempt to determine if parenthesis are needed base on the target position. The snippet may have | ||
// parenthesis already, so attempt to find those. | ||
// TODO: Remove parenthesis if they aren't needed at the target position. |
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.
We can create an issue for this enhancement, once the PR is merged 🙃
ExprKind::Cast(lhs, rhs) | ||
if (ctxt == lhs.span.ctxt() && expr.span.lo() != lhs.span.lo()) | ||
|| (ctxt == rhs.span.ctxt() && expr.span.hi() != rhs.span.hi()) => | ||
{ | ||
false | ||
}, |
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.
NIT: This can be combined with the first case (ExprKind::Binary(_, lhs, rhs) ...
) as the guards and bindings are the identical :)
app, | ||
); | ||
} | ||
|
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.
Really, nit picky, but I thought I mention it since, there are some other adjustments/comments :)
/// `MaybeIncorrect` to `HasPlaceholders`. | ||
/// * If the snippet is taken from a macro expansion then it will be changed from | ||
/// `MachineApplicable` to `MaybeIncorrect`. | ||
pub fn snippet_expr( |
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.
The tests don't have any instance where the parenthesis are added by this function. Can you please add some test cases to ensure that this works correctly.
Just btw I'm working on #7986 which is an alternative to the extra util functions. |
I'll give it a fix for the specific issue as that doesn't need anything added to utils. |
Closing in favour of #8218. |
fixes: #7972
changelog: Fix
redundant_slicing
suggestion when the result is used in a postfix expression