Skip to content

Commit

Permalink
Rollup merge of rust-lang#58245 - taiki-e:librustc_lint-2018, r=Centril
Browse files Browse the repository at this point in the history
librustc_lint => 2018

Transitions `librustc_lint` to Rust 2018; cc rust-lang#58099

r? @Centril
  • Loading branch information
Centril authored Feb 8, 2019
2 parents 2b8ed1e + 6140134 commit 543f457
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 100 deletions.
1 change: 1 addition & 0 deletions src/librustc_lint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"]
name = "rustc_lint"
version = "0.0.0"
edition = "2018"

[lib]
name = "rustc_lint"
Expand Down
108 changes: 56 additions & 52 deletions src/librustc_lint/builtin.rs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/librustc_lint/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use syntax::{register_diagnostic, register_diagnostics};

register_diagnostics! {
E0721, // `await` keyword
}
10 changes: 2 additions & 8 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@

#![recursion_limit="256"]

#[macro_use]
extern crate syntax;
#![deny(rust_2018_idioms)]

#[macro_use]
extern crate rustc;
#[macro_use]
extern crate log;
extern crate rustc_target;
extern crate syntax_pos;
extern crate rustc_data_structures;

mod diagnostics;
mod nonstandard_style;
Expand All @@ -49,7 +44,6 @@ use rustc::lint::builtin::{
parser::ILL_FORMED_ATTRIBUTE_INPUT,
};
use rustc::session;
use rustc::util;
use rustc::hir;

use syntax::ast;
Expand Down
39 changes: 20 additions & 19 deletions src/librustc_lint/nonstandard_style.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rustc::hir::{self, GenericParamKind, PatKind};
use rustc::hir::def::Def;
use rustc::hir::intravisit::FnKind;
use rustc::lint;
use rustc::ty;
use rustc_target::spec::abi::Abi;
use lint::{EarlyContext, LateContext, LintContext, LintArray};
Expand All @@ -17,7 +18,7 @@ pub enum MethodLateContext {
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 item = cx.tcx.associated_item(def_id);
match item.container {
Expand All @@ -41,7 +42,7 @@ declare_lint! {
pub struct 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 {
c.is_lowercase() || c.is_uppercase()
}
Expand Down Expand Up @@ -115,7 +116,7 @@ impl LintPass 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
.iter()
.any(|attr| {
Expand All @@ -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);
}

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 {
self.check_case(cx, "type parameter", &param.ident);
}
Expand Down Expand Up @@ -190,7 +191,7 @@ impl NonSnakeCase {
}

/// 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 {
if ident.is_empty() {
return true;
Expand Down Expand Up @@ -249,7 +250,7 @@ impl LintPass 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 {
Some(Ident::from_str(name))
} else {
Expand Down Expand Up @@ -286,16 +287,16 @@ 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 {
self.check_snake_case(cx, "lifetime", &param.name.ident());
}
}

fn check_fn(
&mut self,
cx: &LateContext,
fk: FnKind,
cx: &LateContext<'_, '_>,
fk: FnKind<'_>,
_: &hir::FnDecl,
_: &hir::Body,
_: Span,
Expand Down Expand Up @@ -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 {
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 {
self.check_snake_case(cx, "trait method", &item.ident);
for param_name in pnames {
Expand All @@ -339,15 +340,15 @@ 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 {
self.check_snake_case(cx, "variable", &ident);
}
}

fn check_struct_def(
&mut self,
cx: &LateContext,
cx: &LateContext<'_, '_>,
s: &hir::VariantData,
_: ast::Name,
_: &hir::Generics,
Expand All @@ -369,7 +370,7 @@ declare_lint! {
pub struct 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();

if name.chars().any(|c| c.is_lowercase()) {
Expand Down Expand Up @@ -399,7 +400,7 @@ impl LintPass 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 {
hir::ItemKind::Static(..) if !attr::contains_name(&it.attrs, "no_mangle") => {
NonUpperCaseGlobals::check_upper_case(cx, "static variable", &it.ident);
Expand All @@ -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 {
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 {
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)
if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.node {
if let Def::Const(..) = path.def {
Expand Down
19 changes: 11 additions & 8 deletions src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rustc::hir::Node;
use rustc::ty::subst::Substs;
use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
use rustc::ty::layout::{self, IntegerExt, LayoutOf, VariantIdx};
use rustc::{lint, util};
use rustc_data_structures::indexed_vec::Idx;
use util::nodemap::FxHashSet;
use lint::{LateContext, LintContext, LintArray};
Expand All @@ -23,6 +24,8 @@ use rustc::hir;

use rustc::mir::interpret::{sign_extend, truncate};

use log::debug;

declare_lint! {
UNUSED_COMPARISONS,
Warn,
Expand Down Expand Up @@ -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,
l: &hir::Expr,
r: &hir::Expr)
Expand Down Expand Up @@ -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 firstch = src.chars().next()?;

Expand All @@ -320,7 +323,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
//
// No suggestion for: `isize`, `usize`.
fn get_type_suggestion<'a>(
t: &ty::TyKind,
t: &ty::TyKind<'_>,
val: u128,
negative: bool,
) -> Option<String> {
Expand Down Expand Up @@ -364,9 +367,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
}

fn report_bin_hex_error(
cx: &LateContext,
cx: &LateContext<'_, '_>,
expr: &hir::Expr,
ty: ty::TyKind,
ty: ty::TyKind<'_>,
repr_str: String,
val: u128,
negative: bool,
Expand Down Expand Up @@ -481,7 +484,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
fn check_type_for_ffi(&self,
cache: &mut FxHashSet<Ty<'tcx>>,
ty: Ty<'tcx>) -> FfiResult<'tcx> {
use self::FfiResult::*;
use FfiResult::*;

let cx = self.cx.tcx;

Expand Down Expand Up @@ -799,7 +802,7 @@ impl LintPass 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 abi = cx.tcx.hir().get_foreign_abi(it.id);
if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic {
Expand Down Expand Up @@ -829,7 +832,7 @@ impl LintPass 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 {
let item_def_id = cx.tcx.hir().local_def_id(it.id);
let t = cx.tcx.type_of(item_def_id);
Expand Down
Loading

0 comments on commit 543f457

Please sign in to comment.