Skip to content

Commit

Permalink
Auto merge of #12570 - J-ZhengLi:issue12569, r=Jarcho
Browse files Browse the repository at this point in the history
allow [`manual_unwrap_or_default`] in const function

closes: #12568

---

changelog: allow [`manual_unwrap_or_default`] in const function

This is a small fix, I was originally decided to fix it along with `#12568` but there are some problems needs to be addressed (which is why my branch is called `issue12569` 😆 ), so I decide to open a separated PR to fix them one at a time.
  • Loading branch information
bors committed Mar 28, 2024
2 parents 014230c + c27f52d commit 124e68b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/manual_unwrap_or_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use rustc_session::declare_lint_pass;
use rustc_span::sym;

use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::is_default_equivalent;
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::implements_trait;
use clippy_utils::{in_constant, is_default_equivalent};

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -172,7 +172,7 @@ fn handle_if_let<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {

impl<'tcx> LateLintPass<'tcx> for ManualUnwrapOrDefault {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
if expr.span.from_expansion() {
if expr.span.from_expansion() || in_constant(cx, expr.hir_id) {
return;
}
if !handle_match(cx, expr) {
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/manual_unwrap_or_default.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ unsafe fn no_deref_ptr(a: Option<i32>, b: *const Option<i32>) -> i32 {
_ => 0,
}
}

const fn issue_12568(opt: Option<bool>) -> bool {
match opt {
Some(s) => s,
None => false,
}
}
7 changes: 7 additions & 0 deletions tests/ui/manual_unwrap_or_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ unsafe fn no_deref_ptr(a: Option<i32>, b: *const Option<i32>) -> i32 {
_ => 0,
}
}

const fn issue_12568(opt: Option<bool>) -> bool {
match opt {
Some(s) => s,
None => false,
}
}

0 comments on commit 124e68b

Please sign in to comment.