11use rustc:: hir;
2- use rustc:: hir:: { Body , FnDecl , Constness } ;
32use rustc:: hir:: intravisit:: FnKind ;
3+ use rustc:: hir:: { Body , Constness , FnDecl } ;
44// use rustc::mir::*;
5- use syntax:: ast:: { NodeId , Attribute } ;
6- use syntax_pos:: Span ;
5+ use crate :: utils:: { is_entrypoint_fn, span_lint} ;
76use rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
87use rustc:: { declare_tool_lint, lint_array} ;
98use 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 ;
1111
1212/// **What it does:**
1313///
@@ -26,8 +26,12 @@ use crate::utils::{span_lint, is_entrypoint_fn};
2626/// Also, the lint only runs one pass over the code. Consider these two non-const functions:
2727///
2828/// ```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+ /// }
3135/// ```
3236///
3337/// 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};
3842///
3943/// ```rust
4044/// fn new() -> Self {
41- /// Self {
42- /// random_number: 42
43- /// }
45+ /// Self { random_number: 42 }
4446/// }
4547/// ```
4648///
4749/// Could be a const fn:
4850///
4951/// ```rust
5052/// const fn new() -> Self {
51- /// Self {
52- /// random_number: 42
53- /// }
53+ /// Self { random_number: 42 }
5454/// }
5555/// ```
5656declare_clippy_lint ! {
@@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
7676 _: & FnDecl ,
7777 _: & Body ,
7878 span : Span ,
79- node_id : NodeId
79+ node_id : NodeId ,
8080 ) {
8181 // Perform some preliminary checks that rule out constness on the Clippy side. This way we
8282 // can skip the actual const check and return early.
@@ -93,7 +93,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
9393 return ;
9494 }
9595 } ,
96- _ => return
96+ _ => return ,
9797 }
9898
9999 let def_id = cx. tcx . hir ( ) . local_def_id ( node_id) ;
@@ -111,9 +111,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
111111
112112fn can_be_const_fn ( name : & str , header : hir:: FnHeader , attrs : & [ Attribute ] ) -> bool {
113113 // 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+ }
115117
116118 // 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+ }
118122 true
119123}
0 commit comments