@@ -42,15 +42,16 @@ impl<'tcx> LateLintPass<'tcx> for AndThenThenSome {
42
42
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > ) {
43
43
match expr. kind {
44
44
ExprKind :: MethodCall ( method_name, selfarg, [ arg ] , span) => {
45
+ dbg ! ( expr) ;
45
46
//let option_id = cx.tcx.get_diagnostic_item(sym::Option);
46
47
// TODO: check if type of reciever is diagnostic item Option.
47
48
let tckr = cx. typeck_results ( ) ;
48
49
let def_id = tckr. type_dependent_def_id ( expr. hir_id ) . unwrap ( ) ;
49
50
//dbg!(method_name, selfarg, arg);
50
- if match_def_path ( cx, def_id,
51
- & [ "core" , "option" , "Option" , "and_then" ] )
51
+ if dbg ! ( match_def_path( cx, dbg! ( def_id) ,
52
+ & [ "core" , "option" , "Option" , "and_then" ] ) )
52
53
{
53
- if let Some ( ( closure_args, predicate) ) = then_some_closure_arg ( cx, arg) {
54
+ if let Some ( ( closure_args, predicate) ) = dbg ! ( then_some_closure_arg( cx, arg) ) {
54
55
//dbg!(predicate);
55
56
show_sugg ( cx, expr. span , selfarg, closure_args, predicate) ;
56
57
}
@@ -104,7 +105,7 @@ fn peel_closure_body<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, closu
104
105
None
105
106
}
106
107
}
107
- ExprKind :: Call ( func /*@ Expr{ kind: ExprKind::Path(QPath::Resolved(_, Path{ res: Res::Local(local_hid), ..})), ..},*/ , [ pred, arg ] ) => {
108
+ ExprKind :: Call ( func, [ pred, arg ] ) => {
108
109
//dbg!(func, fn_def_id(cx, expr));
109
110
//todo!();
110
111
if is_then_some ( cx, func) && dbg ! ( is_local_defined_at( cx, arg, closure_arg_id) ) {
@@ -163,3 +164,13 @@ fn is_then_some(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
163
164
}
164
165
}
165
166
167
+ fn is_and_then ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
168
+ if let Some ( def_id) = fn_def_id ( cx, expr) {
169
+ match_def_path (
170
+ cx, dbg ! ( def_id) ,
171
+ & [ "core" , "option" , "Option" , "and_then" ] )
172
+ } else {
173
+ //todo!("not type dependent");
174
+ false
175
+ }
176
+ }
0 commit comments