@@ -47,19 +47,19 @@ impl<'tcx> LateLintPass<'tcx> for AndThenThenSome {
47
47
// TODO: check if type of reciever is diagnostic item Option.
48
48
//let tckr = cx.typeck_results();
49
49
//let def_id = tckr.type_dependent_def_id(expr.hir_id).unwrap();
50
- //dbg! (method_name, selfarg, arg);
50
+ //(method_name, selfarg, arg);
51
51
if is_and_then ( cx, expr)
52
52
{
53
- if let Some ( ( closure_args, predicate) ) = dbg ! ( then_some_closure_arg( cx, arg) ) {
54
- //dbg! (predicate);
53
+ if let Some ( ( closure_args, predicate) ) = ( then_some_closure_arg ( cx, arg) ) {
54
+ //(predicate);
55
55
show_sugg ( cx, expr. span , selfarg, closure_args, predicate) ;
56
56
}
57
57
}
58
58
}
59
59
ExprKind :: Call ( _func, [ selfarg, arg ] ) => {
60
- if dbg ! ( is_and_then( cx, expr) ) {
61
- if let Some ( ( closure_args, predicate) ) = dbg ! ( then_some_closure_arg( cx, arg) ) {
62
- //dbg! (predicate);
60
+ if ( is_and_then ( cx, expr) ) {
61
+ if let Some ( ( closure_args, predicate) ) = ( then_some_closure_arg ( cx, arg) ) {
62
+ //(predicate);
63
63
show_sugg ( cx, expr. span , selfarg, closure_args, predicate) ;
64
64
}
65
65
}
@@ -74,16 +74,16 @@ impl<'tcx> LateLintPass<'tcx> for AndThenThenSome {
74
74
fn then_some_closure_arg < ' tcx > ( cx : & LateContext < ' tcx > , expr : & Expr < ' tcx > )
75
75
-> Option < ( Span , & ' tcx Expr < ' tcx > ) >
76
76
{
77
- dbg ! ( expr) ;
77
+ ( expr) ;
78
78
match expr. kind {
79
79
ExprKind :: Closure ( Closure {
80
80
fn_decl : FnDecl { inputs : [ Ty { hir_id : arg_id, ..} ] , .. } ,
81
81
body,
82
82
..
83
83
} ) => {
84
- if let Node :: Expr ( expr) = dbg ! ( cx. tcx. hir_node( body. hir_id) ) {
85
- //dbg! (arg_id);
86
- if let Some ( body) = dbg ! ( peel_closure_body( cx, expr, * arg_id) ) {
84
+ if let Node :: Expr ( expr) = ( cx. tcx . hir_node ( body. hir_id ) ) {
85
+ //(arg_id);
86
+ if let Some ( body) = ( peel_closure_body ( cx, expr, * arg_id) ) {
87
87
Some ( ( cx. tcx . hir ( ) . span ( * arg_id) , body) )
88
88
} else {
89
89
None
@@ -114,35 +114,29 @@ fn peel_closure_body<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, closu
114
114
}
115
115
}
116
116
ExprKind :: Call ( func, [ pred, arg ] ) => {
117
- //dbg!(func, fn_def_id(cx, expr));
118
- //todo!();
119
- if dbg ! ( is_then_some( cx, expr) ) && dbg ! ( is_local_defined_at( cx, arg, closure_arg_id) ) {
120
- //todo!("it worked!!");
117
+ if ( is_then_some ( cx, expr) ) && ( is_local_defined_at ( cx, arg, closure_arg_id) ) {
121
118
Some ( pred)
122
119
123
120
} else {
124
- //todo!("nope");
125
121
None
126
122
}
127
123
}
128
124
_ => {
129
- eprintln ! ( "cannot peel {expr:#?}" ) ;
130
125
None
131
126
}
132
127
}
133
128
}
134
129
135
130
fn is_local_defined_at < ' tcx > ( cx : & LateContext < ' tcx > , local : & Expr < ' _ > , arg_hid : HirId ) -> bool {
136
- dbg ! ( local) ;
137
131
match local. kind {
138
132
ExprKind :: Path ( QPath :: Resolved ( _, Path { res : Res :: Local ( local_hid) , .. } ) ) => {
139
133
// FIXME: this is the best way i could find to compare if
140
134
// a local refers to a specific closure argument.
141
135
//
142
136
// it breaks if the closure argument has an explicitly declared type,
143
137
// since the spans only align for TyKind::Infer
144
- if let Node :: Pat ( Pat { span : local_span, .. } ) = dbg ! ( cx. tcx. hir_node( * local_hid) ) &&
145
- let Node :: Ty ( Ty { span : arg_span, .. } ) = dbg ! ( cx. tcx. hir_node( arg_hid) ) &&
138
+ if let Node :: Pat ( Pat { span : local_span, .. } ) = ( cx. tcx . hir_node ( * local_hid) ) &&
139
+ let Node :: Ty ( Ty { span : arg_span, .. } ) = ( cx. tcx . hir_node ( arg_hid) ) &&
146
140
local_span == arg_span
147
141
{
148
142
true
@@ -170,19 +164,19 @@ fn show_sugg(cx: &LateContext<'_>, span: Span, selfarg: &Expr<'_>, closure_args:
170
164
171
165
fn is_then_some ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
172
166
if let Some ( def_id) = fn_def_id ( cx, expr) {
173
- dbg ! ( match_def_path(
174
- cx, dbg! ( def_id) ,
167
+ ( match_def_path (
168
+ cx, ( def_id) ,
175
169
& [ "core" , "bool" , "<impl bool>" , "then_some" ] ) )
176
170
} else {
177
- dbg ! ( expr) ;
171
+ ( expr) ;
178
172
false
179
173
}
180
174
}
181
175
182
176
fn is_and_then ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
183
177
if let Some ( def_id) = fn_def_id ( cx, expr) {
184
- dbg ! ( match_def_path(
185
- cx, dbg! ( def_id) ,
178
+ ( match_def_path (
179
+ cx, ( def_id) ,
186
180
& [ "core" , "option" , "Option" , "and_then" ] ) )
187
181
} else {
188
182
false
0 commit comments