Auto merge of #45611 - Manishearth:lint-generics, r=petrochenkov
Add generics to LateContext Fixes clippy breakage from https://github.com/rust-lang/rust/pull/44766 as discussed in https://github.com/rust-lang-nursery/rust-clippy/pull/2140#issuecomment-336973875 r? @nikomatsakis
This commit is contained in:
commit
690ff04594
5 changed files with 36 additions and 3 deletions
7
src/Cargo.lock
generated
7
src/Cargo.lock
generated
|
@ -290,6 +290,7 @@ version = "0.1.0"
|
|||
name = "clippy_lints"
|
||||
version = "0.0.166"
|
||||
dependencies = [
|
||||
"if_chain 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -789,6 +790,11 @@ dependencies = [
|
|||
"unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "if_chain"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ignore"
|
||||
version = "0.2.2"
|
||||
|
@ -2665,6 +2671,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum html-diff 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5298d63081a642508fce965740ddb03a386c5d81bf1fef0579a815cf49cb8c68"
|
||||
"checksum html5ever 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a49d5001dd1bddf042ea41ed4e0a671d50b1bf187e66b349d7ec613bdce4ad90"
|
||||
"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d"
|
||||
"checksum if_chain 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "61bb90bdd39e3af69b0172dfc6130f6cd6332bf040fbb9bdd4401d37adbd48b8"
|
||||
"checksum ignore 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b3fcaf2365eb14b28ec7603c98c06cc531f19de9eb283d89a3dff8417c8c99f5"
|
||||
"checksum itertools 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d3f2be4da1690a039e9ae5fd575f706a63ad5a2120f161b1d653c9da3930dd21"
|
||||
"checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c"
|
||||
|
|
|
@ -1854,6 +1854,19 @@ impl Item_ {
|
|||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generics(&self) -> Option<&Generics> {
|
||||
Some(match *self {
|
||||
ItemFn(_, _, _, _, ref generics, _) |
|
||||
ItemTy(_, ref generics) |
|
||||
ItemEnum(_, ref generics) |
|
||||
ItemStruct(_, ref generics) |
|
||||
ItemUnion(_, ref generics) |
|
||||
ItemTrait(_, ref generics, _, _) |
|
||||
ItemImpl(_, _, _, ref generics, _, _, _)=> generics,
|
||||
_ => return None
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A reference from an trait to one of its associated items. This
|
||||
|
|
|
@ -352,6 +352,9 @@ pub struct LateContext<'a, 'tcx: 'a> {
|
|||
lint_sess: LintSession<'tcx, LateLintPassObject>,
|
||||
|
||||
last_ast_node_with_lint_attrs: ast::NodeId,
|
||||
|
||||
/// Generic type parameters in scope for the item we are in.
|
||||
pub generics: Option<&'tcx hir::Generics>,
|
||||
}
|
||||
|
||||
/// Context for lint checking of the AST, after expansion, before lowering to
|
||||
|
@ -646,13 +649,16 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn visit_item(&mut self, it: &'tcx hir::Item) {
|
||||
let generics = self.generics.take();
|
||||
self.generics = it.node.generics();
|
||||
self.with_lint_attrs(it.id, &it.attrs, |cx| {
|
||||
cx.with_param_env(it.id, |cx| {
|
||||
run_lints!(cx, check_item, late_passes, it);
|
||||
hir_visit::walk_item(cx, it);
|
||||
run_lints!(cx, check_item_post, late_passes, it);
|
||||
});
|
||||
})
|
||||
});
|
||||
self.generics = generics;
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem) {
|
||||
|
@ -774,6 +780,8 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) {
|
||||
let generics = self.generics.take();
|
||||
self.generics = Some(&trait_item.generics);
|
||||
self.with_lint_attrs(trait_item.id, &trait_item.attrs, |cx| {
|
||||
cx.with_param_env(trait_item.id, |cx| {
|
||||
run_lints!(cx, check_trait_item, late_passes, trait_item);
|
||||
|
@ -781,9 +789,12 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
|
|||
run_lints!(cx, check_trait_item_post, late_passes, trait_item);
|
||||
});
|
||||
});
|
||||
self.generics = generics;
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
|
||||
let generics = self.generics.take();
|
||||
self.generics = Some(&impl_item.generics);
|
||||
self.with_lint_attrs(impl_item.id, &impl_item.attrs, |cx| {
|
||||
cx.with_param_env(impl_item.id, |cx| {
|
||||
run_lints!(cx, check_impl_item, late_passes, impl_item);
|
||||
|
@ -791,6 +802,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
|
|||
run_lints!(cx, check_impl_item_post, late_passes, impl_item);
|
||||
});
|
||||
});
|
||||
self.generics = generics;
|
||||
}
|
||||
|
||||
fn visit_lifetime(&mut self, lt: &'tcx hir::Lifetime) {
|
||||
|
@ -991,6 +1003,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
|||
access_levels,
|
||||
lint_sess: LintSession::new(&tcx.sess.lint_store),
|
||||
last_ast_node_with_lint_attrs: ast::CRATE_NODE_ID,
|
||||
generics: None,
|
||||
};
|
||||
|
||||
// Visit the whole crate.
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 281bd790de7b992831a1ff8a589c0fc38c842c95
|
||||
Subproject commit f76225e3887170743403af9204887918b5db5a80
|
|
@ -26,7 +26,7 @@
|
|||
miri = "Broken"
|
||||
|
||||
# ping @Manishearth @llogiq @mcarton @oli-obk
|
||||
clippy = "Broken"
|
||||
clippy = "Compiling"
|
||||
|
||||
# ping @nrc
|
||||
rls = "Broken"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue