diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2021-01-29 09:17:32 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-29 09:17:32 +0900 |
| commit | c18d6f1ffa683a998e9c8a3ff93f6560b2103008 (patch) | |
| tree | 47ac6c8534e0ec3bd7ab102ee880323b46061664 /clippy_lints/src/default.rs | |
| parent | 299ff49667c213a87c22e371298a87a5b4f874a6 (diff) | |
| parent | 2454408318814a2451b0698fa6d1cbffcaafda5f (diff) | |
Rollup merge of #81176 - camsteffen:qpath-res, r=oli-obk
Improve safety of `LateContext::qpath_res` This is my first rustc code change, inspired by hacking on clippy! The first change is to clear cached `TypeckResults` from `LateContext` when visiting a nested item. I took a hint from [here](https://github.com/rust-lang/rust/blob/5e91c4ecc09312d8b63d250a432b0f3ef83f1df7/compiler/rustc_privacy/src/lib.rs#L1300). Clippy has a `qpath_res` util function to avoid a possible ICE in `LateContext::qpath_res`. But the docs of `LateContext::qpath_res` promise no ICE. So this updates the `LateContext` method to keep its promises, and removes the util function. Related: rust-lang/rust-clippy#4545 CC ````````````@eddyb```````````` since you've done related work CC ````````````@flip1995```````````` FYI
Diffstat (limited to 'clippy_lints/src/default.rs')
| -rw-r--r-- | clippy_lints/src/default.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index f7224811e6e..6fa1378b8c7 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -1,5 +1,5 @@ use crate::utils::{ - any_parent_is_automatically_derived, contains_name, match_def_path, paths, qpath_res, snippet_with_macro_callsite, + any_parent_is_automatically_derived, contains_name, match_def_path, paths, snippet_with_macro_callsite, }; use crate::utils::{span_lint_and_note, span_lint_and_sugg}; use if_chain::if_chain; @@ -231,7 +231,7 @@ fn is_expr_default<'tcx>(expr: &'tcx Expr<'tcx>, cx: &LateContext<'tcx>) -> bool if_chain! { if let ExprKind::Call(ref fn_expr, _) = &expr.kind; if let ExprKind::Path(qpath) = &fn_expr.kind; - if let Res::Def(_, def_id) = qpath_res(cx, qpath, fn_expr.hir_id); + if let Res::Def(_, def_id) = cx.qpath_res(qpath, fn_expr.hir_id); then { // right hand side of assignment is `Default::default` match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD) |
