1
Fork 0

Rollup merge of #58245 - taiki-e:librustc_lint-2018, r=Centril

librustc_lint => 2018

Transitions `librustc_lint` to Rust 2018; cc #58099

r? @Centril
This commit is contained in:
Mazdak Farrokhzad 2019-02-09 00:15:52 +01:00 committed by GitHub
commit 543f457169
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 108 additions and 100 deletions

View file

@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"] authors = ["The Rust Project Developers"]
name = "rustc_lint" name = "rustc_lint"
version = "0.0.0" version = "0.0.0"
edition = "2018"
[lib] [lib]
name = "rustc_lint" name = "rustc_lint"

View file

@ -21,6 +21,7 @@
use rustc::hir::def::Def; use rustc::hir::def::Def;
use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::ty::{self, Ty}; use rustc::ty::{self, Ty};
use rustc::{lint, util};
use hir::Node; use hir::Node;
use util::nodemap::NodeSet; use util::nodemap::NodeSet;
use lint::{LateContext, LintContext, LintArray}; use lint::{LateContext, LintContext, LintArray};
@ -42,10 +43,13 @@ use syntax::symbol::keywords;
use syntax::errors::{Applicability, DiagnosticBuilder}; use syntax::errors::{Applicability, DiagnosticBuilder};
use syntax::print::pprust::expr_to_string; use syntax::print::pprust::expr_to_string;
use syntax::visit::FnKind; use syntax::visit::FnKind;
use syntax::struct_span_err;
use rustc::hir::{self, GenericParamKind, PatKind}; use rustc::hir::{self, GenericParamKind, PatKind};
use nonstandard_style::{MethodLateContext, method_context}; use crate::nonstandard_style::{MethodLateContext, method_context};
use log::debug;
// hardwired lints from librustc // hardwired lints from librustc
pub use lint::builtin::*; pub use lint::builtin::*;
@ -70,7 +74,7 @@ impl LintPass for WhileTrue {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WhileTrue { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WhileTrue {
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) { fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) {
if let hir::ExprKind::While(ref cond, ..) = e.node { if let hir::ExprKind::While(ref cond, ..) = e.node {
if let hir::ExprKind::Lit(ref lit) = cond.node { if let hir::ExprKind::Lit(ref lit) = cond.node {
if let ast::LitKind::Bool(true) = lit.node { if let ast::LitKind::Bool(true) = lit.node {
@ -102,7 +106,7 @@ declare_lint! {
pub struct BoxPointers; pub struct BoxPointers;
impl BoxPointers { impl BoxPointers {
fn check_heap_type<'a, 'tcx>(&self, cx: &LateContext, span: Span, ty: Ty) { fn check_heap_type<'a, 'tcx>(&self, cx: &LateContext<'_, '_>, span: Span, ty: Ty<'_>) {
for leaf_ty in ty.walk() { for leaf_ty in ty.walk() {
if leaf_ty.is_box() { if leaf_ty.is_box() {
let m = format!("type uses owned (Box type) pointers: {}", ty); let m = format!("type uses owned (Box type) pointers: {}", ty);
@ -123,7 +127,7 @@ impl LintPass for BoxPointers {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
match it.node { match it.node {
hir::ItemKind::Fn(..) | hir::ItemKind::Fn(..) |
hir::ItemKind::Ty(..) | hir::ItemKind::Ty(..) |
@ -150,7 +154,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers {
} }
} }
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) { fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) {
let ty = cx.tables.node_id_to_type(e.hir_id); let ty = cx.tables.node_id_to_type(e.hir_id);
self.check_heap_type(cx, e.span, ty); self.check_heap_type(cx, e.span, ty);
} }
@ -176,7 +180,7 @@ impl LintPass for NonShorthandFieldPatterns {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
fn check_pat(&mut self, cx: &LateContext, pat: &hir::Pat) { fn check_pat(&mut self, cx: &LateContext<'_, '_>, pat: &hir::Pat) {
if let PatKind::Struct(ref qpath, ref field_pats, _) = pat.node { if let PatKind::Struct(ref qpath, ref field_pats, _) = pat.node {
let variant = cx.tables.pat_ty(pat).ty_adt_def() let variant = cx.tables.pat_ty(pat).ty_adt_def()
.expect("struct pattern type is not an ADT") .expect("struct pattern type is not an ADT")
@ -233,7 +237,7 @@ impl LintPass for UnsafeCode {
} }
impl UnsafeCode { impl UnsafeCode {
fn report_unsafe(&self, cx: &EarlyContext, span: Span, desc: &'static str) { fn report_unsafe(&self, cx: &EarlyContext<'_>, span: Span, desc: &'static str) {
// This comes from a macro that has #[allow_internal_unsafe]. // This comes from a macro that has #[allow_internal_unsafe].
if span.allows_unsafe() { if span.allows_unsafe() {
return; return;
@ -244,7 +248,7 @@ impl UnsafeCode {
} }
impl EarlyLintPass for UnsafeCode { impl EarlyLintPass for UnsafeCode {
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) { fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
if attr.check_name("allow_internal_unsafe") { if attr.check_name("allow_internal_unsafe") {
self.report_unsafe(cx, attr.span, "`allow_internal_unsafe` allows defining \ self.report_unsafe(cx, attr.span, "`allow_internal_unsafe` allows defining \
macros using unsafe without triggering \ macros using unsafe without triggering \
@ -252,7 +256,7 @@ impl EarlyLintPass for UnsafeCode {
} }
} }
fn check_expr(&mut self, cx: &EarlyContext, e: &ast::Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
if let ast::ExprKind::Block(ref blk, _) = e.node { if let ast::ExprKind::Block(ref blk, _) = e.node {
// Don't warn about generated blocks, that'll just pollute the output. // Don't warn about generated blocks, that'll just pollute the output.
if blk.rules == ast::BlockCheckMode::Unsafe(ast::UserProvided) { if blk.rules == ast::BlockCheckMode::Unsafe(ast::UserProvided) {
@ -261,7 +265,7 @@ impl EarlyLintPass for UnsafeCode {
} }
} }
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { fn check_item(&mut self, cx: &EarlyContext<'_>, it: &ast::Item) {
match it.node { match it.node {
ast::ItemKind::Trait(_, ast::Unsafety::Unsafe, ..) => { ast::ItemKind::Trait(_, ast::Unsafety::Unsafe, ..) => {
self.report_unsafe(cx, it.span, "declaration of an `unsafe` trait") self.report_unsafe(cx, it.span, "declaration of an `unsafe` trait")
@ -276,8 +280,8 @@ impl EarlyLintPass for UnsafeCode {
} }
fn check_fn(&mut self, fn check_fn(&mut self,
cx: &EarlyContext, cx: &EarlyContext<'_>,
fk: FnKind, fk: FnKind<'_>,
_: &ast::FnDecl, _: &ast::FnDecl,
span: Span, span: Span,
_: ast::NodeId) { _: ast::NodeId) {
@ -296,7 +300,7 @@ impl EarlyLintPass for UnsafeCode {
} }
} }
fn check_trait_item(&mut self, cx: &EarlyContext, item: &ast::TraitItem) { fn check_trait_item(&mut self, cx: &EarlyContext<'_>, item: &ast::TraitItem) {
if let ast::TraitItemKind::Method(ref sig, None) = item.node { if let ast::TraitItemKind::Method(ref sig, None) = item.node {
if sig.header.unsafety == ast::Unsafety::Unsafe { if sig.header.unsafety == ast::Unsafety::Unsafe {
self.report_unsafe(cx, item.span, "declaration of an `unsafe` method") self.report_unsafe(cx, item.span, "declaration of an `unsafe` method")
@ -354,7 +358,7 @@ impl MissingDoc {
} }
fn check_missing_docs_attrs(&self, fn check_missing_docs_attrs(&self,
cx: &LateContext, cx: &LateContext<'_, '_>,
id: Option<ast::NodeId>, id: Option<ast::NodeId>,
attrs: &[ast::Attribute], attrs: &[ast::Attribute],
sp: Span, sp: Span,
@ -399,7 +403,7 @@ impl LintPass for MissingDoc {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
fn enter_lint_attrs(&mut self, _: &LateContext, attrs: &[ast::Attribute]) { fn enter_lint_attrs(&mut self, _: &LateContext<'_, '_>, attrs: &[ast::Attribute]) {
let doc_hidden = self.doc_hidden() || let doc_hidden = self.doc_hidden() ||
attrs.iter().any(|attr| { attrs.iter().any(|attr| {
attr.check_name("doc") && attr.check_name("doc") &&
@ -411,11 +415,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
self.doc_hidden_stack.push(doc_hidden); self.doc_hidden_stack.push(doc_hidden);
} }
fn exit_lint_attrs(&mut self, _: &LateContext, _attrs: &[ast::Attribute]) { fn exit_lint_attrs(&mut self, _: &LateContext<'_, '_>, _attrs: &[ast::Attribute]) {
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack"); self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
} }
fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) { fn check_crate(&mut self, cx: &LateContext<'_, '_>, krate: &hir::Crate) {
self.check_missing_docs_attrs(cx, None, &krate.attrs, krate.span, "crate"); self.check_missing_docs_attrs(cx, None, &krate.attrs, krate.span, "crate");
for macro_def in &krate.exported_macros { for macro_def in &krate.exported_macros {
@ -428,7 +432,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
} }
} }
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
let desc = match it.node { let desc = match it.node {
hir::ItemKind::Fn(..) => "a function", hir::ItemKind::Fn(..) => "a function",
hir::ItemKind::Mod(..) => "a module", hir::ItemKind::Mod(..) => "a module",
@ -473,7 +477,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
self.check_missing_docs_attrs(cx, Some(it.id), &it.attrs, it.span, desc); self.check_missing_docs_attrs(cx, Some(it.id), &it.attrs, it.span, desc);
} }
fn check_trait_item(&mut self, cx: &LateContext, trait_item: &hir::TraitItem) { fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, trait_item: &hir::TraitItem) {
if self.private_traits.contains(&trait_item.id) { if self.private_traits.contains(&trait_item.id) {
return; return;
} }
@ -491,7 +495,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
desc); desc);
} }
fn check_impl_item(&mut self, cx: &LateContext, impl_item: &hir::ImplItem) { fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, impl_item: &hir::ImplItem) {
// If the method is an impl for a trait, don't doc. // If the method is an impl for a trait, don't doc.
if method_context(cx, impl_item.id) == MethodLateContext::TraitImpl { if method_context(cx, impl_item.id) == MethodLateContext::TraitImpl {
return; return;
@ -510,7 +514,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
desc); desc);
} }
fn check_struct_field(&mut self, cx: &LateContext, sf: &hir::StructField) { fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, sf: &hir::StructField) {
if !sf.is_positional() { if !sf.is_positional() {
self.check_missing_docs_attrs(cx, self.check_missing_docs_attrs(cx,
Some(sf.id), Some(sf.id),
@ -520,7 +524,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
} }
} }
fn check_variant(&mut self, cx: &LateContext, v: &hir::Variant, _: &hir::Generics) { fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant, _: &hir::Generics) {
self.check_missing_docs_attrs(cx, self.check_missing_docs_attrs(cx,
Some(v.node.data.id()), Some(v.node.data.id()),
&v.node.attrs, &v.node.attrs,
@ -549,7 +553,7 @@ impl LintPass for MissingCopyImplementations {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations {
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) {
if !cx.access_levels.is_reachable(item.id) { if !cx.access_levels.is_reachable(item.id) {
return; return;
} }
@ -620,7 +624,7 @@ impl LintPass for MissingDebugImplementations {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) {
if !cx.access_levels.is_reachable(item.id) { if !cx.access_levels.is_reachable(item.id) {
return; return;
} }
@ -681,7 +685,7 @@ impl LintPass for AnonymousParameters {
} }
impl EarlyLintPass for AnonymousParameters { impl EarlyLintPass for AnonymousParameters {
fn check_trait_item(&mut self, cx: &EarlyContext, it: &ast::TraitItem) { fn check_trait_item(&mut self, cx: &EarlyContext<'_>, it: &ast::TraitItem) {
match it.node { match it.node {
ast::TraitItemKind::Method(ref sig, _) => { ast::TraitItemKind::Method(ref sig, _) => {
for arg in sig.decl.inputs.iter() { for arg in sig.decl.inputs.iter() {
@ -749,7 +753,7 @@ impl LintPass for DeprecatedAttr {
} }
impl EarlyLintPass for DeprecatedAttr { impl EarlyLintPass for DeprecatedAttr {
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) { fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
for &&(n, _, _, ref g) in &self.depr_attrs { for &&(n, _, _, ref g) in &self.depr_attrs {
if attr.name() == n { if attr.name() == n {
if let &AttributeGate::Gated(Stability::Deprecated(link, suggestion), if let &AttributeGate::Gated(Stability::Deprecated(link, suggestion),
@ -804,15 +808,15 @@ impl UnusedDocComment {
} }
impl EarlyLintPass for UnusedDocComment { impl EarlyLintPass for UnusedDocComment {
fn check_local(&mut self, cx: &EarlyContext, decl: &ast::Local) { fn check_local(&mut self, cx: &EarlyContext<'_>, decl: &ast::Local) {
self.warn_if_doc(decl.attrs.iter(), cx); self.warn_if_doc(decl.attrs.iter(), cx);
} }
fn check_arm(&mut self, cx: &EarlyContext, arm: &ast::Arm) { fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) {
self.warn_if_doc(arm.attrs.iter(), cx); self.warn_if_doc(arm.attrs.iter(), cx);
} }
fn check_expr(&mut self, cx: &EarlyContext, expr: &ast::Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
self.warn_if_doc(expr.attrs.iter(), cx); self.warn_if_doc(expr.attrs.iter(), cx);
} }
} }
@ -837,7 +841,7 @@ impl LintPass for PluginAsLibrary {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PluginAsLibrary { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PluginAsLibrary {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
if cx.tcx.plugin_registrar_fn(LOCAL_CRATE).is_some() { if cx.tcx.plugin_registrar_fn(LOCAL_CRATE).is_some() {
// We're compiling a plugin; it's fine to link other plugins. // We're compiling a plugin; it's fine to link other plugins.
return; return;
@ -894,7 +898,7 @@ impl LintPass for InvalidNoMangleItems {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
match it.node { match it.node {
hir::ItemKind::Fn(.., ref generics, _) => { hir::ItemKind::Fn(.., ref generics, _) => {
if let Some(no_mangle_attr) = attr::find_by_name(&it.attrs, "no_mangle") { if let Some(no_mangle_attr) = attr::find_by_name(&it.attrs, "no_mangle") {
@ -968,7 +972,7 @@ impl LintPass for MutableTransmutes {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
fn check_expr(&mut self, cx: &LateContext, expr: &hir::Expr) { fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &hir::Expr) {
use rustc_target::spec::abi::Abi::RustIntrinsic; use rustc_target::spec::abi::Abi::RustIntrinsic;
let msg = "mutating transmuted &mut T from &T may cause undefined behavior, \ let msg = "mutating transmuted &mut T from &T may cause undefined behavior, \
@ -1004,7 +1008,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
None None
} }
fn def_id_is_transmute(cx: &LateContext, def_id: DefId) -> bool { fn def_id_is_transmute(cx: &LateContext<'_, '_>, def_id: DefId) -> bool {
cx.tcx.fn_sig(def_id).abi() == RustIntrinsic && cx.tcx.fn_sig(def_id).abi() == RustIntrinsic &&
cx.tcx.item_name(def_id) == "transmute" cx.tcx.item_name(def_id) == "transmute"
} }
@ -1032,7 +1036,7 @@ impl LintPass for UnstableFeatures {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnstableFeatures { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnstableFeatures {
fn check_attribute(&mut self, ctx: &LateContext, attr: &ast::Attribute) { fn check_attribute(&mut self, ctx: &LateContext<'_, '_>, attr: &ast::Attribute) {
if attr.check_name("feature") { if attr.check_name("feature") {
if let Some(items) = attr.meta_item_list() { if let Some(items) = attr.meta_item_list() {
for item in items { for item in items {
@ -1063,7 +1067,7 @@ impl LintPass for UnionsWithDropFields {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnionsWithDropFields { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnionsWithDropFields {
fn check_item(&mut self, ctx: &LateContext, item: &hir::Item) { fn check_item(&mut self, ctx: &LateContext<'_, '_>, item: &hir::Item) {
if let hir::ItemKind::Union(ref vdata, _) = item.node { if let hir::ItemKind::Union(ref vdata, _) = item.node {
for field in vdata.fields() { for field in vdata.fields() {
let field_ty = ctx.tcx.type_of(ctx.tcx.hir().local_def_id(field.id)); let field_ty = ctx.tcx.type_of(ctx.tcx.hir().local_def_id(field.id));
@ -1099,7 +1103,7 @@ impl LintPass for UnreachablePub {
} }
impl UnreachablePub { impl UnreachablePub {
fn perform_lint(&self, cx: &LateContext, what: &str, id: ast::NodeId, fn perform_lint(&self, cx: &LateContext<'_, '_>, what: &str, id: ast::NodeId,
vis: &hir::Visibility, span: Span, exportable: bool) { vis: &hir::Visibility, span: Span, exportable: bool) {
let mut applicability = Applicability::MachineApplicable; let mut applicability = Applicability::MachineApplicable;
match vis.node { match vis.node {
@ -1134,20 +1138,20 @@ impl UnreachablePub {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub {
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) {
self.perform_lint(cx, "item", item.id, &item.vis, item.span, true); self.perform_lint(cx, "item", item.id, &item.vis, item.span, true);
} }
fn check_foreign_item(&mut self, cx: &LateContext, foreign_item: &hir::ForeignItem) { fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, foreign_item: &hir::ForeignItem) {
self.perform_lint(cx, "item", foreign_item.id, &foreign_item.vis, self.perform_lint(cx, "item", foreign_item.id, &foreign_item.vis,
foreign_item.span, true); foreign_item.span, true);
} }
fn check_struct_field(&mut self, cx: &LateContext, field: &hir::StructField) { fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, field: &hir::StructField) {
self.perform_lint(cx, "field", field.id, &field.vis, field.span, false); self.perform_lint(cx, "field", field.id, &field.vis, field.span, false);
} }
fn check_impl_item(&mut self, cx: &LateContext, impl_item: &hir::ImplItem) { fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, impl_item: &hir::ImplItem) {
self.perform_lint(cx, "item", impl_item.id, &impl_item.vis, impl_item.span, false); self.perform_lint(cx, "item", impl_item.id, &impl_item.vis, impl_item.span, false);
} }
} }
@ -1193,7 +1197,7 @@ impl TypeAliasBounds {
} }
} }
fn suggest_changing_assoc_types(ty: &hir::Ty, err: &mut DiagnosticBuilder) { fn suggest_changing_assoc_types(ty: &hir::Ty, err: &mut DiagnosticBuilder<'_>) {
// Access to associates types should use `<T as Bound>::Assoc`, which does not need a // Access to associates types should use `<T as Bound>::Assoc`, which does not need a
// bound. Let's see if this type does that. // bound. Let's see if this type does that.
@ -1225,7 +1229,7 @@ impl TypeAliasBounds {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) {
let (ty, type_alias_generics) = match item.node { let (ty, type_alias_generics) = match item.node {
hir::ItemKind::Ty(ref ty, ref generics) => (&*ty, generics), hir::ItemKind::Ty(ref ty, ref generics) => (&*ty, generics),
_ => return, _ => return,
@ -1281,7 +1285,7 @@ impl LintPass for UnusedBrokenConst {
lint_array!() lint_array!()
} }
} }
fn check_const(cx: &LateContext, body_id: hir::BodyId) { fn check_const(cx: &LateContext<'_, '_>, body_id: hir::BodyId) {
let def_id = cx.tcx.hir().body_owner_def_id(body_id); let def_id = cx.tcx.hir().body_owner_def_id(body_id);
let is_static = cx.tcx.is_static(def_id).is_some(); let is_static = cx.tcx.is_static(def_id).is_some();
let param_env = if is_static { let param_env = if is_static {
@ -1299,7 +1303,7 @@ fn check_const(cx: &LateContext, body_id: hir::BodyId) {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedBrokenConst { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedBrokenConst {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
match it.node { match it.node {
hir::ItemKind::Const(_, body_id) => { hir::ItemKind::Const(_, body_id) => {
check_const(cx, body_id); check_const(cx, body_id);
@ -1429,7 +1433,7 @@ impl LintPass for EllipsisInclusiveRangePatterns {
} }
impl EarlyLintPass for EllipsisInclusiveRangePatterns { impl EarlyLintPass for EllipsisInclusiveRangePatterns {
fn check_pat(&mut self, cx: &EarlyContext, pat: &ast::Pat, visit_subpats: &mut bool) { fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &ast::Pat, visit_subpats: &mut bool) {
use self::ast::{PatKind, RangeEnd, RangeSyntax::DotDotDot}; use self::ast::{PatKind, RangeEnd, RangeSyntax::DotDotDot};
/// If `pat` is a `...` pattern, return the start and end of the range, as well as the span /// If `pat` is a `...` pattern, return the start and end of the range, as well as the span
@ -1507,7 +1511,7 @@ impl LintPass for UnnameableTestItems {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
if self.items_nameable { if self.items_nameable {
if let hir::ItemKind::Mod(..) = it.node {} if let hir::ItemKind::Mod(..) = it.node {}
else { else {
@ -1526,7 +1530,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems {
} }
} }
fn check_item_post(&mut self, _cx: &LateContext, it: &hir::Item) { fn check_item_post(&mut self, _cx: &LateContext<'_, '_>, it: &hir::Item) {
if !self.items_nameable && self.boundary == it.id { if !self.items_nameable && self.boundary == it.id {
self.items_nameable = true; self.items_nameable = true;
} }
@ -1554,7 +1558,7 @@ impl LintPass for KeywordIdents {
} }
impl KeywordIdents { impl KeywordIdents {
fn check_tokens(&mut self, cx: &EarlyContext, tokens: TokenStream) { fn check_tokens(&mut self, cx: &EarlyContext<'_>, tokens: TokenStream) {
for tt in tokens.into_trees() { for tt in tokens.into_trees() {
match tt { match tt {
TokenTree::Token(span, tok) => match tok.ident() { TokenTree::Token(span, tok) => match tok.ident() {
@ -1576,13 +1580,13 @@ impl KeywordIdents {
} }
impl EarlyLintPass for KeywordIdents { impl EarlyLintPass for KeywordIdents {
fn check_mac_def(&mut self, cx: &EarlyContext, mac_def: &ast::MacroDef, _id: ast::NodeId) { fn check_mac_def(&mut self, cx: &EarlyContext<'_>, mac_def: &ast::MacroDef, _id: ast::NodeId) {
self.check_tokens(cx, mac_def.stream()); self.check_tokens(cx, mac_def.stream());
} }
fn check_mac(&mut self, cx: &EarlyContext, mac: &ast::Mac) { fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
self.check_tokens(cx, mac.node.tts.clone().into()); self.check_tokens(cx, mac.node.tts.clone().into());
} }
fn check_ident(&mut self, cx: &EarlyContext, ident: ast::Ident) { fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: ast::Ident) {
let ident_str = &ident.as_str()[..]; let ident_str = &ident.as_str()[..];
let cur_edition = cx.sess.edition(); let cur_edition = cx.sess.edition();
let is_raw_ident = |ident: ast::Ident| { let is_raw_ident = |ident: ast::Ident| {
@ -1665,7 +1669,7 @@ impl LintPass for ExplicitOutlivesRequirements {
impl ExplicitOutlivesRequirements { impl ExplicitOutlivesRequirements {
fn collect_outlives_bound_spans( fn collect_outlives_bound_spans(
&self, &self,
cx: &LateContext, cx: &LateContext<'_, '_>,
item_def_id: DefId, item_def_id: DefId,
param_name: &str, param_name: &str,
bounds: &hir::GenericBounds, bounds: &hir::GenericBounds,

View file

@ -1,3 +1,5 @@
use syntax::{register_diagnostic, register_diagnostics};
register_diagnostics! { register_diagnostics! {
E0721, // `await` keyword E0721, // `await` keyword
} }

View file

@ -19,15 +19,10 @@
#![recursion_limit="256"] #![recursion_limit="256"]
#[macro_use] #![deny(rust_2018_idioms)]
extern crate syntax;
#[macro_use] #[macro_use]
extern crate rustc; extern crate rustc;
#[macro_use]
extern crate log;
extern crate rustc_target;
extern crate syntax_pos;
extern crate rustc_data_structures;
mod diagnostics; mod diagnostics;
mod nonstandard_style; mod nonstandard_style;
@ -49,7 +44,6 @@ use rustc::lint::builtin::{
parser::ILL_FORMED_ATTRIBUTE_INPUT, parser::ILL_FORMED_ATTRIBUTE_INPUT,
}; };
use rustc::session; use rustc::session;
use rustc::util;
use rustc::hir; use rustc::hir;
use syntax::ast; use syntax::ast;

View file

@ -1,6 +1,7 @@
use rustc::hir::{self, GenericParamKind, PatKind}; use rustc::hir::{self, GenericParamKind, PatKind};
use rustc::hir::def::Def; use rustc::hir::def::Def;
use rustc::hir::intravisit::FnKind; use rustc::hir::intravisit::FnKind;
use rustc::lint;
use rustc::ty; use rustc::ty;
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
use lint::{EarlyContext, LateContext, LintContext, LintArray}; use lint::{EarlyContext, LateContext, LintContext, LintArray};
@ -17,7 +18,7 @@ pub enum MethodLateContext {
PlainImpl, PlainImpl,
} }
pub fn method_context(cx: &LateContext, id: ast::NodeId) -> MethodLateContext { pub fn method_context(cx: &LateContext<'_, '_>, id: ast::NodeId) -> MethodLateContext {
let def_id = cx.tcx.hir().local_def_id(id); let def_id = cx.tcx.hir().local_def_id(id);
let item = cx.tcx.associated_item(def_id); let item = cx.tcx.associated_item(def_id);
match item.container { match item.container {
@ -41,7 +42,7 @@ declare_lint! {
pub struct NonCamelCaseTypes; pub struct NonCamelCaseTypes;
impl NonCamelCaseTypes { impl NonCamelCaseTypes {
fn check_case(&self, cx: &EarlyContext, sort: &str, ident: &Ident) { fn check_case(&self, cx: &EarlyContext<'_>, sort: &str, ident: &Ident) {
fn char_has_case(c: char) -> bool { fn char_has_case(c: char) -> bool {
c.is_lowercase() || c.is_uppercase() c.is_lowercase() || c.is_uppercase()
} }
@ -115,7 +116,7 @@ impl LintPass for NonCamelCaseTypes {
} }
impl EarlyLintPass for NonCamelCaseTypes { impl EarlyLintPass for NonCamelCaseTypes {
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { fn check_item(&mut self, cx: &EarlyContext<'_>, it: &ast::Item) {
let has_repr_c = it.attrs let has_repr_c = it.attrs
.iter() .iter()
.any(|attr| { .any(|attr| {
@ -138,11 +139,11 @@ impl EarlyLintPass for NonCamelCaseTypes {
} }
} }
fn check_variant(&mut self, cx: &EarlyContext, v: &ast::Variant, _: &ast::Generics) { fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant, _: &ast::Generics) {
self.check_case(cx, "variant", &v.node.ident); self.check_case(cx, "variant", &v.node.ident);
} }
fn check_generic_param(&mut self, cx: &EarlyContext, param: &ast::GenericParam) { fn check_generic_param(&mut self, cx: &EarlyContext<'_>, param: &ast::GenericParam) {
if let ast::GenericParamKind::Type { .. } = param.kind { if let ast::GenericParamKind::Type { .. } = param.kind {
self.check_case(cx, "type parameter", &param.ident); self.check_case(cx, "type parameter", &param.ident);
} }
@ -190,7 +191,7 @@ impl NonSnakeCase {
} }
/// Checks if a given identifier is snake case, and reports a diagnostic if not. /// Checks if a given identifier is snake case, and reports a diagnostic if not.
fn check_snake_case(&self, cx: &LateContext, sort: &str, ident: &Ident) { fn check_snake_case(&self, cx: &LateContext<'_, '_>, sort: &str, ident: &Ident) {
fn is_snake_case(ident: &str) -> bool { fn is_snake_case(ident: &str) -> bool {
if ident.is_empty() { if ident.is_empty() {
return true; return true;
@ -249,7 +250,7 @@ impl LintPass for NonSnakeCase {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
fn check_crate(&mut self, cx: &LateContext, cr: &hir::Crate) { fn check_crate(&mut self, cx: &LateContext<'_, '_>, cr: &hir::Crate) {
let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name { let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name {
Some(Ident::from_str(name)) Some(Ident::from_str(name))
} else { } else {
@ -286,7 +287,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
} }
} }
fn check_generic_param(&mut self, cx: &LateContext, param: &hir::GenericParam) { fn check_generic_param(&mut self, cx: &LateContext<'_, '_>, param: &hir::GenericParam) {
if let GenericParamKind::Lifetime { .. } = param.kind { if let GenericParamKind::Lifetime { .. } = param.kind {
self.check_snake_case(cx, "lifetime", &param.name.ident()); self.check_snake_case(cx, "lifetime", &param.name.ident());
} }
@ -294,8 +295,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
fn check_fn( fn check_fn(
&mut self, &mut self,
cx: &LateContext, cx: &LateContext<'_, '_>,
fk: FnKind, fk: FnKind<'_>,
_: &hir::FnDecl, _: &hir::FnDecl,
_: &hir::Body, _: &hir::Body,
_: Span, _: Span,
@ -324,13 +325,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
} }
} }
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
if let hir::ItemKind::Mod(_) = it.node { if let hir::ItemKind::Mod(_) = it.node {
self.check_snake_case(cx, "module", &it.ident); self.check_snake_case(cx, "module", &it.ident);
} }
} }
fn check_trait_item(&mut self, cx: &LateContext, item: &hir::TraitItem) { fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::TraitItem) {
if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(pnames)) = &item.node { if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(pnames)) = &item.node {
self.check_snake_case(cx, "trait method", &item.ident); self.check_snake_case(cx, "trait method", &item.ident);
for param_name in pnames { for param_name in pnames {
@ -339,7 +340,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
} }
} }
fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) { fn check_pat(&mut self, cx: &LateContext<'_, '_>, p: &hir::Pat) {
if let &PatKind::Binding(_, _, _, ident, _) = &p.node { if let &PatKind::Binding(_, _, _, ident, _) = &p.node {
self.check_snake_case(cx, "variable", &ident); self.check_snake_case(cx, "variable", &ident);
} }
@ -347,7 +348,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
fn check_struct_def( fn check_struct_def(
&mut self, &mut self,
cx: &LateContext, cx: &LateContext<'_, '_>,
s: &hir::VariantData, s: &hir::VariantData,
_: ast::Name, _: ast::Name,
_: &hir::Generics, _: &hir::Generics,
@ -369,7 +370,7 @@ declare_lint! {
pub struct NonUpperCaseGlobals; pub struct NonUpperCaseGlobals;
impl NonUpperCaseGlobals { impl NonUpperCaseGlobals {
fn check_upper_case(cx: &LateContext, sort: &str, ident: &Ident) { fn check_upper_case(cx: &LateContext<'_, '_>, sort: &str, ident: &Ident) {
let name = &ident.name.as_str(); let name = &ident.name.as_str();
if name.chars().any(|c| c.is_lowercase()) { if name.chars().any(|c| c.is_lowercase()) {
@ -399,7 +400,7 @@ impl LintPass for NonUpperCaseGlobals {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
match it.node { match it.node {
hir::ItemKind::Static(..) if !attr::contains_name(&it.attrs, "no_mangle") => { hir::ItemKind::Static(..) if !attr::contains_name(&it.attrs, "no_mangle") => {
NonUpperCaseGlobals::check_upper_case(cx, "static variable", &it.ident); NonUpperCaseGlobals::check_upper_case(cx, "static variable", &it.ident);
@ -411,19 +412,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
} }
} }
fn check_trait_item(&mut self, cx: &LateContext, ti: &hir::TraitItem) { fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, ti: &hir::TraitItem) {
if let hir::TraitItemKind::Const(..) = ti.node { if let hir::TraitItemKind::Const(..) = ti.node {
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ti.ident); NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ti.ident);
} }
} }
fn check_impl_item(&mut self, cx: &LateContext, ii: &hir::ImplItem) { fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, ii: &hir::ImplItem) {
if let hir::ImplItemKind::Const(..) = ii.node { if let hir::ImplItemKind::Const(..) = ii.node {
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ii.ident); NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ii.ident);
} }
} }
fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) { fn check_pat(&mut self, cx: &LateContext<'_, '_>, p: &hir::Pat) {
// Lint for constants that look like binding identifiers (#7526) // Lint for constants that look like binding identifiers (#7526)
if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.node { if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.node {
if let Def::Const(..) = path.def { if let Def::Const(..) = path.def {

View file

@ -4,6 +4,7 @@ use rustc::hir::Node;
use rustc::ty::subst::Substs; use rustc::ty::subst::Substs;
use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt}; use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
use rustc::ty::layout::{self, IntegerExt, LayoutOf, VariantIdx}; use rustc::ty::layout::{self, IntegerExt, LayoutOf, VariantIdx};
use rustc::{lint, util};
use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::indexed_vec::Idx;
use util::nodemap::FxHashSet; use util::nodemap::FxHashSet;
use lint::{LateContext, LintContext, LintArray}; use lint::{LateContext, LintContext, LintArray};
@ -23,6 +24,8 @@ use rustc::hir;
use rustc::mir::interpret::{sign_extend, truncate}; use rustc::mir::interpret::{sign_extend, truncate};
use log::debug;
declare_lint! { declare_lint! {
UNUSED_COMPARISONS, UNUSED_COMPARISONS,
Warn, Warn,
@ -241,7 +244,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
} }
} }
fn check_limits(cx: &LateContext, fn check_limits(cx: &LateContext<'_, '_>,
binop: hir::BinOp, binop: hir::BinOp,
l: &hir::Expr, l: &hir::Expr,
r: &hir::Expr) r: &hir::Expr)
@ -298,7 +301,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
} }
} }
fn get_bin_hex_repr(cx: &LateContext, lit: &ast::Lit) -> Option<String> { fn get_bin_hex_repr(cx: &LateContext<'_, '_>, lit: &ast::Lit) -> Option<String> {
let src = cx.sess().source_map().span_to_snippet(lit.span).ok()?; let src = cx.sess().source_map().span_to_snippet(lit.span).ok()?;
let firstch = src.chars().next()?; let firstch = src.chars().next()?;
@ -320,7 +323,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
// //
// No suggestion for: `isize`, `usize`. // No suggestion for: `isize`, `usize`.
fn get_type_suggestion<'a>( fn get_type_suggestion<'a>(
t: &ty::TyKind, t: &ty::TyKind<'_>,
val: u128, val: u128,
negative: bool, negative: bool,
) -> Option<String> { ) -> Option<String> {
@ -364,9 +367,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
} }
fn report_bin_hex_error( fn report_bin_hex_error(
cx: &LateContext, cx: &LateContext<'_, '_>,
expr: &hir::Expr, expr: &hir::Expr,
ty: ty::TyKind, ty: ty::TyKind<'_>,
repr_str: String, repr_str: String,
val: u128, val: u128,
negative: bool, negative: bool,
@ -481,7 +484,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
fn check_type_for_ffi(&self, fn check_type_for_ffi(&self,
cache: &mut FxHashSet<Ty<'tcx>>, cache: &mut FxHashSet<Ty<'tcx>>,
ty: Ty<'tcx>) -> FfiResult<'tcx> { ty: Ty<'tcx>) -> FfiResult<'tcx> {
use self::FfiResult::*; use FfiResult::*;
let cx = self.cx.tcx; let cx = self.cx.tcx;
@ -799,7 +802,7 @@ impl LintPass for ImproperCTypes {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes {
fn check_foreign_item(&mut self, cx: &LateContext, it: &hir::ForeignItem) { fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem) {
let mut vis = ImproperCTypesVisitor { cx }; let mut vis = ImproperCTypesVisitor { cx };
let abi = cx.tcx.hir().get_foreign_abi(it.id); let abi = cx.tcx.hir().get_foreign_abi(it.id);
if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic { if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic {
@ -829,7 +832,7 @@ impl LintPass for VariantSizeDifferences {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
if let hir::ItemKind::Enum(ref enum_definition, _) = it.node { if let hir::ItemKind::Enum(ref enum_definition, _) = it.node {
let item_def_id = cx.tcx.hir().local_def_id(it.id); let item_def_id = cx.tcx.hir().local_def_id(it.id);
let t = cx.tcx.type_of(item_def_id); let t = cx.tcx.type_of(item_def_id);

View file

@ -1,5 +1,6 @@
use rustc::hir::def::Def; use rustc::hir::def::Def;
use rustc::hir::def_id::DefId; use rustc::hir::def_id::DefId;
use rustc::lint;
use rustc::ty; use rustc::ty;
use rustc::ty::adjustment; use rustc::ty::adjustment;
use lint::{LateContext, EarlyContext, LintContext, LintArray}; use lint::{LateContext, EarlyContext, LintContext, LintArray};
@ -16,6 +17,8 @@ use syntax_pos::Span;
use rustc::hir; use rustc::hir;
use log::debug;
declare_lint! { declare_lint! {
pub UNUSED_MUST_USE, pub UNUSED_MUST_USE,
Warn, Warn,
@ -43,7 +46,7 @@ impl LintPass for UnusedResults {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) { fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt) {
let expr = match s.node { let expr = match s.node {
hir::StmtKind::Semi(ref expr) => &**expr, hir::StmtKind::Semi(ref expr) => &**expr,
_ => return, _ => return,
@ -168,7 +171,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
} }
fn check_must_use( fn check_must_use(
cx: &LateContext, cx: &LateContext<'_, '_>,
def_id: DefId, def_id: DefId,
sp: Span, sp: Span,
descr_pre_path: &str, descr_pre_path: &str,
@ -212,7 +215,7 @@ impl LintPass for PathStatements {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathStatements { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathStatements {
fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) { fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt) {
if let hir::StmtKind::Semi(ref expr) = s.node { if let hir::StmtKind::Semi(ref expr) = s.node {
if let hir::ExprKind::Path(_) = expr.node { if let hir::ExprKind::Path(_) = expr.node {
cx.span_lint(PATH_STATEMENTS, s.span, "path statement with no effect"); cx.span_lint(PATH_STATEMENTS, s.span, "path statement with no effect");
@ -241,7 +244,7 @@ impl LintPass for UnusedAttributes {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
fn check_attribute(&mut self, cx: &LateContext, attr: &ast::Attribute) { fn check_attribute(&mut self, cx: &LateContext<'_, '_>, attr: &ast::Attribute) {
debug!("checking attribute: {:?}", attr); debug!("checking attribute: {:?}", attr);
// Note that check_name() marks the attribute as used if it matches. // Note that check_name() marks the attribute as used if it matches.
for &(name, ty, ..) in BUILTIN_ATTRIBUTES { for &(name, ty, ..) in BUILTIN_ATTRIBUTES {
@ -303,7 +306,7 @@ pub struct UnusedParens;
impl UnusedParens { impl UnusedParens {
fn check_unused_parens_expr(&self, fn check_unused_parens_expr(&self,
cx: &EarlyContext, cx: &EarlyContext<'_>,
value: &ast::Expr, value: &ast::Expr,
msg: &str, msg: &str,
followed_by_block: bool) { followed_by_block: bool) {
@ -325,7 +328,7 @@ impl UnusedParens {
} }
fn check_unused_parens_pat(&self, fn check_unused_parens_pat(&self,
cx: &EarlyContext, cx: &EarlyContext<'_>,
value: &ast::Pat, value: &ast::Pat,
msg: &str) { msg: &str) {
if let ast::PatKind::Paren(_) = value.node { if let ast::PatKind::Paren(_) = value.node {
@ -339,7 +342,7 @@ impl UnusedParens {
} }
} }
fn remove_outer_parens(cx: &EarlyContext, span: Span, pattern: &str, msg: &str) { fn remove_outer_parens(cx: &EarlyContext<'_>, span: Span, pattern: &str, msg: &str) {
let span_msg = format!("unnecessary parentheses around {}", msg); let span_msg = format!("unnecessary parentheses around {}", msg);
let mut err = cx.struct_span_lint(UNUSED_PARENS, span, &span_msg); let mut err = cx.struct_span_lint(UNUSED_PARENS, span, &span_msg);
let mut ate_left_paren = false; let mut ate_left_paren = false;
@ -387,7 +390,7 @@ impl LintPass for UnusedParens {
} }
impl EarlyLintPass for UnusedParens { impl EarlyLintPass for UnusedParens {
fn check_expr(&mut self, cx: &EarlyContext, e: &ast::Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
use syntax::ast::ExprKind::*; use syntax::ast::ExprKind::*;
let (value, msg, followed_by_block) = match e.node { let (value, msg, followed_by_block) = match e.node {
If(ref cond, ..) => (cond, "`if` condition", true), If(ref cond, ..) => (cond, "`if` condition", true),
@ -429,7 +432,7 @@ impl EarlyLintPass for UnusedParens {
self.check_unused_parens_expr(cx, &value, msg, followed_by_block); self.check_unused_parens_expr(cx, &value, msg, followed_by_block);
} }
fn check_pat(&mut self, cx: &EarlyContext, p: &ast::Pat, _: &mut bool) { fn check_pat(&mut self, cx: &EarlyContext<'_>, p: &ast::Pat, _: &mut bool) {
use ast::PatKind::{Paren, Range}; use ast::PatKind::{Paren, Range};
// The lint visitor will visit each subpattern of `p`. We do not want to lint any range // The lint visitor will visit each subpattern of `p`. We do not want to lint any range
// pattern no matter where it occurs in the pattern. For something like `&(a..=b)`, there // pattern no matter where it occurs in the pattern. For something like `&(a..=b)`, there
@ -443,7 +446,7 @@ impl EarlyLintPass for UnusedParens {
} }
} }
fn check_stmt(&mut self, cx: &EarlyContext, s: &ast::Stmt) { fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
if let ast::StmtKind::Local(ref local) = s.node { if let ast::StmtKind::Local(ref local) = s.node {
if let Some(ref value) = local.init { if let Some(ref value) = local.init {
self.check_unused_parens_expr(cx, &value, "assigned value", false); self.check_unused_parens_expr(cx, &value, "assigned value", false);
@ -462,7 +465,7 @@ declare_lint! {
pub struct UnusedImportBraces; pub struct UnusedImportBraces;
impl UnusedImportBraces { impl UnusedImportBraces {
fn check_use_tree(&self, cx: &EarlyContext, use_tree: &ast::UseTree, item: &ast::Item) { fn check_use_tree(&self, cx: &EarlyContext<'_>, use_tree: &ast::UseTree, item: &ast::Item) {
if let ast::UseTreeKind::Nested(ref items) = use_tree.kind { if let ast::UseTreeKind::Nested(ref items) = use_tree.kind {
// Recursively check nested UseTrees // Recursively check nested UseTrees
for &(ref tree, _) in items { for &(ref tree, _) in items {
@ -509,7 +512,7 @@ impl LintPass for UnusedImportBraces {
} }
impl EarlyLintPass for UnusedImportBraces { impl EarlyLintPass for UnusedImportBraces {
fn check_item(&mut self, cx: &EarlyContext, item: &ast::Item) { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
if let ast::ItemKind::Use(ref use_tree) = item.node { if let ast::ItemKind::Use(ref use_tree) = item.node {
self.check_use_tree(cx, use_tree, item); self.check_use_tree(cx, use_tree, item);
} }
@ -536,7 +539,7 @@ impl LintPass for UnusedAllocation {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAllocation { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAllocation {
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) { fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) {
match e.node { match e.node {
hir::ExprKind::Box(_) => {} hir::ExprKind::Box(_) => {}
_ => return, _ => return,