1+ use clippy_utils:: diagnostics:: span_lint_and_help;
2+ use clippy_utils:: ty:: is_type_diagnostic_item;
13use if_chain:: if_chain;
2- use rustc_hir:: * ;
4+ use rustc_hir:: { Expr , ExprKind , QPath } ;
35use rustc_lint:: { LateContext , LateLintPass } ;
46use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
5- use rustc_span:: { Span , sym} ;
6- use clippy_utils:: diagnostics:: span_lint_and_help;
7- use clippy_utils:: ty:: is_type_diagnostic_item;
8-
7+ use rustc_span:: { sym, Span } ;
98
109declare_clippy_lint ! {
1110 /// ### What it does
@@ -39,7 +38,6 @@ declare_lint_pass!(UseUnwrapOr => [USE_UNWRAP_OR]);
3938
4039impl < ' tcx > LateLintPass < ' tcx > for UseUnwrapOr {
4140 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' _ > ) {
42-
4341 // look for x.or().unwrap()
4442 if_chain ! {
4543 if let ExprKind :: MethodCall ( path, args, unwrap_span) = expr. kind;
@@ -52,13 +50,13 @@ impl<'tcx> LateLintPass<'tcx> for UseUnwrapOr {
5250 let title;
5351 let arg = & caller_args[ 1 ] ; // the argument or(xyz) is called with
5452
55- if is_type_diagnostic_item( & cx, ty, sym:: Option ) {
53+ if is_type_diagnostic_item( cx, ty, sym:: Option ) {
5654 title = ".or(Some(…)).unwrap() found" ;
5755 if !is( arg, "Some" ) {
5856 return ;
5957 }
6058
61- } else if is_type_diagnostic_item( & cx, ty, sym:: Result ) {
59+ } else if is_type_diagnostic_item( cx, ty, sym:: Result ) {
6260 title = ".or(Ok(…)).unwrap() found" ;
6361 if !is( arg, "Ok" ) {
6462 return ;
@@ -90,16 +88,14 @@ impl<'tcx> LateLintPass<'tcx> for UseUnwrapOr {
9088fn is < ' a > ( expr : & Expr < ' a > , name : & str ) -> bool {
9189 if_chain ! {
9290 if let ExprKind :: Call ( some_expr, _some_args) = expr. kind;
93- if let ExprKind :: Path ( path) = & some_expr. kind;
94- if let QPath :: Resolved ( _, path) = path;
91+ if let ExprKind :: Path ( QPath :: Resolved ( _, path) ) = & some_expr. kind;
9592 if let Some ( path_segment) = path. segments. first( ) ;
9693 if path_segment. ident. name. as_str( ) == name;
9794 then {
98- return true ;
95+ true
9996 }
10097 else {
101- return false ;
98+ false
10299 }
103100 }
104101}
105-
0 commit comments