Skip to content

Commit cda7547

Browse files
committed
Make semicolon_span code more refactor-tolerant
1 parent 5c0cb0d commit cda7547

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

clippy_lints/src/returns.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
99
use rustc_middle::lint::in_external_macro;
1010
use rustc_middle::ty::subst::GenericArgKind;
1111
use rustc_session::{declare_lint_pass, declare_tool_lint};
12-
use rustc_span::source_map::{Span, DUMMY_SP};
12+
use rustc_span::source_map::Span;
1313

1414
declare_clippy_lint! {
1515
/// ### What it does
@@ -182,8 +182,10 @@ fn check_block_return<'tcx>(cx: &LateContext<'tcx>, expr_kind: &ExprKind<'tcx>,
182182
StmtKind::Semi(semi_expr) => {
183183
let mut semi_spans_and_this_one = semi_spans;
184184
// we only want the span containing the semicolon so we can remove it later. From `entry.rs:382`
185-
semi_spans_and_this_one.push(stmt.span.trim_start(semi_expr.span).unwrap_or(DUMMY_SP));
186-
check_final_expr(cx, semi_expr, semi_spans_and_this_one, RetReplacement::Empty);
185+
if let Some(semicolon_span) = stmt.span.trim_start(semi_expr.span) {
186+
semi_spans_and_this_one.push(semicolon_span);
187+
check_final_expr(cx, semi_expr, semi_spans_and_this_one, RetReplacement::Empty);
188+
}
187189
},
188190
_ => (),
189191
}

0 commit comments

Comments
 (0)