Skip to content

Commit

Permalink
respect comments in question_mark
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Dec 23, 2023
1 parent dfb4ff8 commit e44caea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
7 changes: 4 additions & 3 deletions clippy_lints/src/question_mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::{
eq_expr_value, get_parent_node, higher, in_constant, is_else_clause, is_lint_allowed, is_path_lang_item,
is_res_lang_ctor, pat_and_expr_can_be_question_mark, path_to_local, path_to_local_id, peel_blocks,
peel_blocks_with_stmt,
peel_blocks_with_stmt, span_contains_comment,
};
use rustc_errors::Applicability;
use rustc_hir::def::Res;
Expand Down Expand Up @@ -121,8 +121,9 @@ fn check_let_some_else_return_none(cx: &LateContext<'_>, stmt: &Stmt<'_>) {
els: Some(els),
..
}) = stmt.kind
&& let Some(els) = find_let_else_ret_expression(els)
&& let Some(inner_pat) = pat_and_expr_can_be_question_mark(cx, pat, els)
&& let Some(ret) = find_let_else_ret_expression(els)
&& let Some(inner_pat) = pat_and_expr_can_be_question_mark(cx, pat, ret)
&& !span_contains_comment(cx.tcx.sess.source_map(), els.span)
{
let mut applicability = Applicability::MaybeIncorrect;
let init_expr_str = snippet_with_applicability(cx, init_expr.span, "..", &mut applicability);
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/manual_let_else_question_mark.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,13 @@ fn issue11993(y: Option<i32>) -> Option<i32> {
return None;
};

let Some(x) = y else {
// Roses are red,
// violets are blue,
// please keep this comment,
// it's art, you know?
return None;
};

None
}
8 changes: 8 additions & 0 deletions tests/ui/manual_let_else_question_mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,13 @@ fn issue11993(y: Option<i32>) -> Option<i32> {
return None;
};

let Some(x) = y else {
// Roses are red,
// violets are blue,
// please keep this comment,
// it's art, you know?
return None;
};

None
}

0 comments on commit e44caea

Please sign in to comment.