1
1
use itertools:: { repeat_n, Itertools } ;
2
- use rustc:: hir:: * ;
3
- use rustc:: ty:: { AssociatedKind , TyKind } ;
2
+ use rustc:: hir:: { Expr , Stmt , DeclKind , StmtKind , ExprKind } ;
3
+ use rustc:: ty:: { AssociatedKind } ;
4
4
use syntax:: ast:: NodeId ;
5
5
6
6
use std:: collections:: HashSet ;
@@ -9,7 +9,8 @@ use crate::rustc_errors::Applicability;
9
9
use crate :: rustc:: lint:: {
10
10
LateContext , LateLintPass , LintArray , LintPass ,
11
11
} ;
12
- use crate :: rustc:: { declare_tool_lint, lint_array} ;
12
+ use crate :: rustc:: ty:: Ty ;
13
+ use crate :: rustc:: { declare_tool_lint, lint_array, ty} ;
13
14
use crate :: utils:: { match_trait_method, match_type, span_lint_and_sugg} ;
14
15
use crate :: utils:: paths;
15
16
@@ -75,11 +76,11 @@ struct Suggestion {
75
76
76
77
fn format_suggestion_pattern < ' a , ' tcx > (
77
78
cx : & LateContext < ' a , ' tcx > ,
78
- collection_ty : & TyKind < ' _ > ,
79
+ collection_ty : & Ty < ' _ > ,
79
80
is_option : bool ,
80
81
) -> String {
81
- let collection_pat = match collection_ty {
82
- TyKind :: Adt ( def, subs) => {
82
+ let collection_pat = match collection_ty. sty {
83
+ ty :: Adt ( def, subs) => {
83
84
let mut buf = cx. tcx . item_path_str ( def. did ) ;
84
85
85
86
if !subs. is_empty ( ) {
@@ -90,7 +91,7 @@ fn format_suggestion_pattern<'a, 'tcx>(
90
91
91
92
buf
92
93
} ,
93
- TyKind :: Param ( p) => p. to_string ( ) ,
94
+ ty :: Param ( p) => p. to_string ( ) ,
94
95
_ => "_" . into ( ) ,
95
96
} ;
96
97
@@ -131,13 +132,13 @@ fn check_expr_for_collect<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr
131
132
132
133
return if match_type( cx, normal_ty, & paths:: OPTION ) {
133
134
Some ( Suggestion {
134
- pattern: format_suggestion_pattern( cx, & collect_ty. sty . clone ( ) , true ) ,
135
+ pattern: format_suggestion_pattern( cx, & collect_ty, true ) ,
135
136
type_colloquial: "Option" ,
136
137
success_variant: "Some" ,
137
138
} )
138
139
} else if match_type( cx, normal_ty, & paths:: RESULT ) {
139
140
Some ( Suggestion {
140
- pattern: format_suggestion_pattern( cx, & collect_ty. sty . clone ( ) , false ) ,
141
+ pattern: format_suggestion_pattern( cx, & collect_ty, false ) ,
141
142
type_colloquial: "Result" ,
142
143
success_variant: "Ok" ,
143
144
} )
0 commit comments