mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-11 22:02:55 +00:00
Merge pull request #51 from pythonesque/fix-const-lookup
Fix panic during constant lookup.
This commit is contained in:
commit
0f77b8cb38
1 changed files with 10 additions and 8 deletions
|
@ -142,14 +142,16 @@ fn fetch_int_literal(cx: &Context, lit : &Expr) -> Option<u64> {
|
||||||
} else { Option::None }
|
} else { Option::None }
|
||||||
},
|
},
|
||||||
&ExprPath(_, _) => {
|
&ExprPath(_, _) => {
|
||||||
|
// Important to let the borrow expire before the const lookup to avoid double
|
||||||
|
// borrowing.
|
||||||
let def_map = cx.tcx.def_map.borrow();
|
let def_map = cx.tcx.def_map.borrow();
|
||||||
let path_res_op = def_map.get(&lit.id);
|
match def_map.get(&lit.id) {
|
||||||
path_res_op.as_ref().and_then(|x| {
|
Some(&PathResolution { base_def: DefConst(def_id), ..}) => Some(def_id),
|
||||||
if let &DefConst(def_id) = &x.base_def {
|
_ => None
|
||||||
lookup_const_by_id(cx.tcx, def_id, Option::None).and_then(|l| fetch_int_literal(cx, l))
|
}
|
||||||
} else { Option::None }
|
}
|
||||||
})
|
.and_then(|def_id| lookup_const_by_id(cx.tcx, def_id, Option::None))
|
||||||
},
|
.and_then(|l| fetch_int_literal(cx, l)),
|
||||||
_ => Option::None
|
_ => Option::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue