@@ -3,7 +3,7 @@ use clippy_utils::higher::VecArgs;
3
3
use clippy_utils:: source:: snippet_opt;
4
4
use clippy_utils:: ty:: get_type_diagnostic_name;
5
5
use clippy_utils:: usage:: { local_used_after_expr, local_used_in} ;
6
- use clippy_utils:: { get_path_from_caller_to_method_type, is_adjusted, path_to_local, path_to_local_id} ;
6
+ use clippy_utils:: { get_path_from_caller_to_method_type, is_adjusted, path_to_local, path_to_local_id, std_or_core } ;
7
7
use rustc_errors:: Applicability ;
8
8
use rustc_hir:: { BindingMode , Expr , ExprKind , FnRetTy , Param , PatKind , QPath , Safety , TyKind } ;
9
9
use rustc_infer:: infer:: TyCtxtInferExt ;
@@ -101,19 +101,20 @@ fn check_clousure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tc
101
101
} ;
102
102
103
103
if body. value . span . from_expansion ( ) {
104
- if body. params . is_empty ( ) {
105
- if let Some ( VecArgs :: Vec ( & [ ] ) ) = VecArgs :: hir ( cx, body. value ) {
106
- // replace `|| vec![]` with `Vec::new`
107
- span_lint_and_sugg (
108
- cx,
109
- REDUNDANT_CLOSURE ,
110
- expr. span ,
111
- "redundant closure" ,
112
- "replace the closure with `Vec::new`" ,
113
- "std::vec::Vec::new" . into ( ) ,
114
- Applicability :: MachineApplicable ,
115
- ) ;
116
- }
104
+ if body. params . is_empty ( ) &&let Some ( VecArgs :: Vec ( & [ ] ) ) = VecArgs :: hir ( cx, body. value )
105
+ // FIXME: When we can correctly determine if `alloc` crate can use in a `no_std` environment, we suggest using `alloc::vec::Vec::new` here.
106
+ && let Some ( "std" ) =std_or_core ( cx)
107
+ {
108
+ // replace `|| vec![]` with `Vec::new`
109
+ span_lint_and_sugg (
110
+ cx,
111
+ REDUNDANT_CLOSURE ,
112
+ expr. span ,
113
+ "redundant closure" ,
114
+ "replace the closure with `Vec::new`" ,
115
+ "std::vec::Vec::new" . into ( ) ,
116
+ Applicability :: MachineApplicable ,
117
+ ) ;
117
118
}
118
119
// skip `foo(|| macro!())`
119
120
return ;
0 commit comments