diff options
| -rw-r--r-- | src/tools/clippy/clippy_utils/src/visitors.rs | 6 | ||||
| -rw-r--r-- | src/tools/clippy/tests/ui/or_fun_call.fixed | 4 | ||||
| -rw-r--r-- | src/tools/clippy/tests/ui/or_fun_call.rs | 2 | ||||
| -rw-r--r-- | src/tools/clippy/tests/ui/or_fun_call.stderr | 8 |
4 files changed, 14 insertions, 6 deletions
diff --git a/src/tools/clippy/clippy_utils/src/visitors.rs b/src/tools/clippy/clippy_utils/src/visitors.rs index fc6e30a9804..615a0910dfd 100644 --- a/src/tools/clippy/clippy_utils/src/visitors.rs +++ b/src/tools/clippy/clippy_utils/src/visitors.rs @@ -1,5 +1,7 @@ +use crate::msrvs::Msrv; use crate::ty::needs_ordered_drop; use crate::{get_enclosing_block, path_to_local_id}; +use crate::qualify_min_const_fn::is_stable_const_fn; use core::ops::ControlFlow; use rustc_ast::visit::{VisitorResult, try_visit}; use rustc_hir::def::{CtorKind, DefKind, Res}; @@ -343,13 +345,13 @@ pub fn is_const_evaluatable<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> .cx .qpath_res(p, hir_id) .opt_def_id() - .is_some_and(|id| self.cx.tcx.is_const_fn(id)) => {}, + .is_some_and(|id| is_stable_const_fn(self.cx, id, Msrv::default())) => {}, ExprKind::MethodCall(..) if self .cx .typeck_results() .type_dependent_def_id(e.hir_id) - .is_some_and(|id| self.cx.tcx.is_const_fn(id)) => {}, + .is_some_and(|id| is_stable_const_fn(self.cx, id, Msrv::default())) => {}, ExprKind::Binary(_, lhs, rhs) if self.cx.typeck_results().expr_ty(lhs).peel_refs().is_primitive_ty() && self.cx.typeck_results().expr_ty(rhs).peel_refs().is_primitive_ty() => {}, diff --git a/src/tools/clippy/tests/ui/or_fun_call.fixed b/src/tools/clippy/tests/ui/or_fun_call.fixed index 38822bdbb30..34f3e046841 100644 --- a/src/tools/clippy/tests/ui/or_fun_call.fixed +++ b/src/tools/clippy/tests/ui/or_fun_call.fixed @@ -406,8 +406,8 @@ fn fn_call_in_nested_expr() { val: String::from("123"), }); - // ok, `String::default()` is now `const` - let _ = opt_foo.unwrap_or(Foo { val: String::default() }); + let _ = opt_foo.unwrap_or_else(|| Foo { val: String::default() }); + //~^ or_fun_call } mod result_map_or { diff --git a/src/tools/clippy/tests/ui/or_fun_call.rs b/src/tools/clippy/tests/ui/or_fun_call.rs index 7e8647f221c..dc57bd6060a 100644 --- a/src/tools/clippy/tests/ui/or_fun_call.rs +++ b/src/tools/clippy/tests/ui/or_fun_call.rs @@ -406,8 +406,8 @@ fn fn_call_in_nested_expr() { val: String::from("123"), }); - // ok, `String::default()` is now `const` let _ = opt_foo.unwrap_or(Foo { val: String::default() }); + //~^ or_fun_call } mod result_map_or { diff --git a/src/tools/clippy/tests/ui/or_fun_call.stderr b/src/tools/clippy/tests/ui/or_fun_call.stderr index 0d88929e131..0f159fe8bff 100644 --- a/src/tools/clippy/tests/ui/or_fun_call.stderr +++ b/src/tools/clippy/tests/ui/or_fun_call.stderr @@ -240,6 +240,12 @@ error: use of `unwrap_or` to construct default value LL | let _ = opt.unwrap_or({ i32::default() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` +error: function call inside of `unwrap_or` + --> tests/ui/or_fun_call.rs:409:21 + | +LL | let _ = opt_foo.unwrap_or(Foo { val: String::default() }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Foo { val: String::default() })` + error: function call inside of `map_or` --> tests/ui/or_fun_call.rs:424:19 | @@ -258,5 +264,5 @@ error: function call inside of `get_or_insert` LL | let _ = x.get_or_insert(g()); | ^^^^^^^^^^^^^^^^^^ help: try: `get_or_insert_with(g)` -error: aborting due to 40 previous errors +error: aborting due to 41 previous errors |
