-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix never_loop
forget to remove break
in suggestion
#15064
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
base: master
Are you sure you want to change the base?
Conversation
r? @Alexendoo rustbot has assigned @Alexendoo. Use |
d2ee798
to
4f18d7f
Compare
Alexendoo's a little bit over the top on capacity (32 assigned PRs) r? @blyxyas |
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.
Some starting review, mainly on readability.
for_to_if_let_sugg(cx, iterator, pat), | ||
)]; | ||
suggestions.extend(inner.iter().map(|span| (*span, String::new()))); |
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.
(In tandem with the last suggestion)
How about a comment here?
suggestions.extend(inner.iter().map(|span| (*span, String::new()))); | |
// Make sure to clear up the diverging sites when we remove a loopp. | |
suggestions.extend(break_spans.iter().map(|span| (*span, String::new()))); |
@@ -20,7 +22,7 @@ pub(super) fn check<'tcx>( | |||
for_loop: Option<&ForLoop<'_>>, | |||
) { | |||
match never_loop_block(cx, block, &mut Vec::new(), loop_id) { | |||
NeverLoopResult::Diverging => { | |||
NeverLoopResult::Diverging(ref inner) => { |
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.
A better variable name could help the readability here.
NeverLoopResult::Diverging(ref inner) => { | |
NeverLoopResult::Diverging(ref break_spans) => { |
enum NeverLoopResult { | ||
/// A continue may occur for the main loop. | ||
MayContinueMainLoop, | ||
/// We have not encountered any main loop continue, | ||
/// but we are diverging (subsequent control flow is not reachable) | ||
Diverging, | ||
Diverging(Vec<Span>), |
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.
What do you think about?
Diverging(Vec<Span>), | |
Diverging { break_spans: Vec<Span> }, |
@@ -118,7 +124,10 @@ fn combine_branches(b1: NeverLoopResult, b2: NeverLoopResult) -> NeverLoopResult | |||
NeverLoopResult::MayContinueMainLoop | |||
}, | |||
(NeverLoopResult::Normal, _) | (_, NeverLoopResult::Normal) => NeverLoopResult::Normal, | |||
(NeverLoopResult::Diverging, NeverLoopResult::Diverging) => NeverLoopResult::Diverging, | |||
(NeverLoopResult::Diverging(mut inner1), NeverLoopResult::Diverging(mut inner2)) => { |
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.
(NeverLoopResult::Diverging(mut inner1), NeverLoopResult::Diverging(mut inner2)) => { | |
(NeverLoopResult::Diverging(mut break_spans1), NeverLoopResult::Diverging(mut break_spans2)) => { |
@@ -159,6 +168,38 @@ fn stmt_to_expr<'tcx>(stmt: &Stmt<'tcx>) -> Option<(&'tcx Expr<'tcx>, Option<&'t | |||
} | |||
} | |||
|
|||
fn stmt_source_span(stmt: &Stmt<'_>) -> Span { | |||
let call_span = stmt.span.source_callsite(); | |||
// if it is a macro call, the span will missing the trailing semicolon |
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.
// if it is a macro call, the span will missing the trailing semicolon | |
// if it is a macro call, the span will be missing the trailing semicolon |
if stmt.span == call_span { | ||
return call_span; | ||
} | ||
call_span.with_hi(call_span.hi() + BytePos(1)) |
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.
You should probably check the statement kind, because there are statements with explicitly no semicolon.
call_span.with_hi(call_span.hi() + BytePos(1)) | ||
} | ||
|
||
fn expr_find_remove_span(cx: &LateContext<'_>, expr: &Expr<'_>) -> Vec<Span> { |
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.
fn expr_find_remove_span(cx: &LateContext<'_>, expr: &Expr<'_>) -> Vec<Span> { | |
/// Returns a Vec of all the individual spans after the highlighted expression in a block | |
fn all_spans_after_expr(cx: &LateContext<'_>, expr: &Expr<'_>) -> Vec<Span> { |
Closes #15007
Removes the
break
stmt and the dead code after it when appropriate.changelog: [
never_loop
] Make sure to removebreak
in suggestions