1
1
use rustc:: hir;
2
- use rustc:: hir:: { Body , FnDecl , Constness } ;
3
2
use rustc:: hir:: intravisit:: FnKind ;
3
+ use rustc:: hir:: { Body , Constness , FnDecl } ;
4
4
// use rustc::mir::*;
5
- use syntax:: ast:: { NodeId , Attribute } ;
6
- use syntax_pos:: Span ;
5
+ use crate :: utils:: { is_entrypoint_fn, span_lint} ;
7
6
use rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
8
7
use rustc:: { declare_tool_lint, lint_array} ;
9
8
use rustc_mir:: transform:: qualify_min_const_fn:: is_min_const_fn;
10
- use crate :: utils:: { span_lint, is_entrypoint_fn} ;
9
+ use syntax:: ast:: { Attribute , NodeId } ;
10
+ use syntax_pos:: Span ;
11
11
12
12
/// **What it does:**
13
13
///
@@ -26,8 +26,12 @@ use crate::utils::{span_lint, is_entrypoint_fn};
26
26
/// Also, the lint only runs one pass over the code. Consider these two non-const functions:
27
27
///
28
28
/// ```rust
29
- /// fn a() -> i32 { 0 }
30
- /// fn b() -> i32 { a() }
29
+ /// fn a() -> i32 {
30
+ /// 0
31
+ /// }
32
+ /// fn b() -> i32 {
33
+ /// a()
34
+ /// }
31
35
/// ```
32
36
///
33
37
/// When running Clippy, the lint will only suggest to make `a` const, because `b` at this time
@@ -38,19 +42,15 @@ use crate::utils::{span_lint, is_entrypoint_fn};
38
42
///
39
43
/// ```rust
40
44
/// fn new() -> Self {
41
- /// Self {
42
- /// random_number: 42
43
- /// }
45
+ /// Self { random_number: 42 }
44
46
/// }
45
47
/// ```
46
48
///
47
49
/// Could be a const fn:
48
50
///
49
51
/// ```rust
50
52
/// const fn new() -> Self {
51
- /// Self {
52
- /// random_number: 42
53
- /// }
53
+ /// Self { random_number: 42 }
54
54
/// }
55
55
/// ```
56
56
declare_clippy_lint ! {
@@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
76
76
_: & FnDecl ,
77
77
_: & Body ,
78
78
span : Span ,
79
- node_id : NodeId
79
+ node_id : NodeId ,
80
80
) {
81
81
// Perform some preliminary checks that rule out constness on the Clippy side. This way we
82
82
// can skip the actual const check and return early.
@@ -93,7 +93,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
93
93
return ;
94
94
}
95
95
} ,
96
- _ => return
96
+ _ => return ,
97
97
}
98
98
99
99
let def_id = cx. tcx . hir ( ) . local_def_id ( node_id) ;
@@ -111,9 +111,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
111
111
112
112
fn can_be_const_fn ( name : & str , header : hir:: FnHeader , attrs : & [ Attribute ] ) -> bool {
113
113
// Main and custom entrypoints can't be `const`
114
- if is_entrypoint_fn ( name, attrs) { return false }
114
+ if is_entrypoint_fn ( name, attrs) {
115
+ return false ;
116
+ }
115
117
116
118
// We don't have to lint on something that's already `const`
117
- if header. constness == Constness :: Const { return false }
119
+ if header. constness == Constness :: Const {
120
+ return false ;
121
+ }
118
122
true
119
123
}
0 commit comments