Skip to content

Commit 6140134

Browse files
committed
librustc_lint => 2018
1 parent b139669 commit 6140134

File tree

7 files changed

+108
-100
lines changed

7 files changed

+108
-100
lines changed

src/librustc_lint/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
authors = ["The Rust Project Developers"]
33
name = "rustc_lint"
44
version = "0.0.0"
5+
edition = "2018"
56

67
[lib]
78
name = "rustc_lint"

src/librustc_lint/builtin.rs

+56-52
Large diffs are not rendered by default.

src/librustc_lint/diagnostics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use syntax::{register_diagnostic, register_diagnostics};
2+
13
register_diagnostics! {
24
E0721, // `await` keyword
35
}

src/librustc_lint/lib.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,10 @@
2121

2222
#![recursion_limit="256"]
2323

24-
#[macro_use]
25-
extern crate syntax;
24+
#![deny(rust_2018_idioms)]
25+
2626
#[macro_use]
2727
extern crate rustc;
28-
#[macro_use]
29-
extern crate log;
30-
extern crate rustc_target;
31-
extern crate syntax_pos;
32-
extern crate rustc_data_structures;
3328

3429
mod diagnostics;
3530
mod nonstandard_style;
@@ -51,7 +46,6 @@ use rustc::lint::builtin::{
5146
parser::ILL_FORMED_ATTRIBUTE_INPUT,
5247
};
5348
use rustc::session;
54-
use rustc::util;
5549
use rustc::hir;
5650

5751
use syntax::ast;

src/librustc_lint/nonstandard_style.rs

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc::hir::{self, GenericParamKind, PatKind};
22
use rustc::hir::def::Def;
33
use rustc::hir::intravisit::FnKind;
4+
use rustc::lint;
45
use rustc::ty;
56
use rustc_target::spec::abi::Abi;
67
use lint::{EarlyContext, LateContext, LintContext, LintArray};
@@ -17,7 +18,7 @@ pub enum MethodLateContext {
1718
PlainImpl,
1819
}
1920

20-
pub fn method_context(cx: &LateContext, id: ast::NodeId) -> MethodLateContext {
21+
pub fn method_context(cx: &LateContext<'_, '_>, id: ast::NodeId) -> MethodLateContext {
2122
let def_id = cx.tcx.hir().local_def_id(id);
2223
let item = cx.tcx.associated_item(def_id);
2324
match item.container {
@@ -41,7 +42,7 @@ declare_lint! {
4142
pub struct NonCamelCaseTypes;
4243

4344
impl NonCamelCaseTypes {
44-
fn check_case(&self, cx: &EarlyContext, sort: &str, ident: &Ident) {
45+
fn check_case(&self, cx: &EarlyContext<'_>, sort: &str, ident: &Ident) {
4546
fn char_has_case(c: char) -> bool {
4647
c.is_lowercase() || c.is_uppercase()
4748
}
@@ -115,7 +116,7 @@ impl LintPass for NonCamelCaseTypes {
115116
}
116117

117118
impl EarlyLintPass for NonCamelCaseTypes {
118-
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
119+
fn check_item(&mut self, cx: &EarlyContext<'_>, it: &ast::Item) {
119120
let has_repr_c = it.attrs
120121
.iter()
121122
.any(|attr| {
@@ -138,11 +139,11 @@ impl EarlyLintPass for NonCamelCaseTypes {
138139
}
139140
}
140141

141-
fn check_variant(&mut self, cx: &EarlyContext, v: &ast::Variant, _: &ast::Generics) {
142+
fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant, _: &ast::Generics) {
142143
self.check_case(cx, "variant", &v.node.ident);
143144
}
144145

145-
fn check_generic_param(&mut self, cx: &EarlyContext, param: &ast::GenericParam) {
146+
fn check_generic_param(&mut self, cx: &EarlyContext<'_>, param: &ast::GenericParam) {
146147
if let ast::GenericParamKind::Type { .. } = param.kind {
147148
self.check_case(cx, "type parameter", &param.ident);
148149
}
@@ -190,7 +191,7 @@ impl NonSnakeCase {
190191
}
191192

192193
/// Checks if a given identifier is snake case, and reports a diagnostic if not.
193-
fn check_snake_case(&self, cx: &LateContext, sort: &str, ident: &Ident) {
194+
fn check_snake_case(&self, cx: &LateContext<'_, '_>, sort: &str, ident: &Ident) {
194195
fn is_snake_case(ident: &str) -> bool {
195196
if ident.is_empty() {
196197
return true;
@@ -249,7 +250,7 @@ impl LintPass for NonSnakeCase {
249250
}
250251

251252
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
252-
fn check_crate(&mut self, cx: &LateContext, cr: &hir::Crate) {
253+
fn check_crate(&mut self, cx: &LateContext<'_, '_>, cr: &hir::Crate) {
253254
let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name {
254255
Some(Ident::from_str(name))
255256
} else {
@@ -286,16 +287,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
286287
}
287288
}
288289

289-
fn check_generic_param(&mut self, cx: &LateContext, param: &hir::GenericParam) {
290+
fn check_generic_param(&mut self, cx: &LateContext<'_, '_>, param: &hir::GenericParam) {
290291
if let GenericParamKind::Lifetime { .. } = param.kind {
291292
self.check_snake_case(cx, "lifetime", &param.name.ident());
292293
}
293294
}
294295

295296
fn check_fn(
296297
&mut self,
297-
cx: &LateContext,
298-
fk: FnKind,
298+
cx: &LateContext<'_, '_>,
299+
fk: FnKind<'_>,
299300
_: &hir::FnDecl,
300301
_: &hir::Body,
301302
_: Span,
@@ -324,13 +325,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
324325
}
325326
}
326327

327-
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
328+
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
328329
if let hir::ItemKind::Mod(_) = it.node {
329330
self.check_snake_case(cx, "module", &it.ident);
330331
}
331332
}
332333

333-
fn check_trait_item(&mut self, cx: &LateContext, item: &hir::TraitItem) {
334+
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::TraitItem) {
334335
if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(pnames)) = &item.node {
335336
self.check_snake_case(cx, "trait method", &item.ident);
336337
for param_name in pnames {
@@ -339,15 +340,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
339340
}
340341
}
341342

342-
fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) {
343+
fn check_pat(&mut self, cx: &LateContext<'_, '_>, p: &hir::Pat) {
343344
if let &PatKind::Binding(_, _, _, ident, _) = &p.node {
344345
self.check_snake_case(cx, "variable", &ident);
345346
}
346347
}
347348

348349
fn check_struct_def(
349350
&mut self,
350-
cx: &LateContext,
351+
cx: &LateContext<'_, '_>,
351352
s: &hir::VariantData,
352353
_: ast::Name,
353354
_: &hir::Generics,
@@ -369,7 +370,7 @@ declare_lint! {
369370
pub struct NonUpperCaseGlobals;
370371

371372
impl NonUpperCaseGlobals {
372-
fn check_upper_case(cx: &LateContext, sort: &str, ident: &Ident) {
373+
fn check_upper_case(cx: &LateContext<'_, '_>, sort: &str, ident: &Ident) {
373374
let name = &ident.name.as_str();
374375

375376
if name.chars().any(|c| c.is_lowercase()) {
@@ -399,7 +400,7 @@ impl LintPass for NonUpperCaseGlobals {
399400
}
400401

401402
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
402-
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
403+
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
403404
match it.node {
404405
hir::ItemKind::Static(..) if !attr::contains_name(&it.attrs, "no_mangle") => {
405406
NonUpperCaseGlobals::check_upper_case(cx, "static variable", &it.ident);
@@ -411,19 +412,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
411412
}
412413
}
413414

414-
fn check_trait_item(&mut self, cx: &LateContext, ti: &hir::TraitItem) {
415+
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, ti: &hir::TraitItem) {
415416
if let hir::TraitItemKind::Const(..) = ti.node {
416417
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ti.ident);
417418
}
418419
}
419420

420-
fn check_impl_item(&mut self, cx: &LateContext, ii: &hir::ImplItem) {
421+
fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, ii: &hir::ImplItem) {
421422
if let hir::ImplItemKind::Const(..) = ii.node {
422423
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ii.ident);
423424
}
424425
}
425426

426-
fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) {
427+
fn check_pat(&mut self, cx: &LateContext<'_, '_>, p: &hir::Pat) {
427428
// Lint for constants that look like binding identifiers (#7526)
428429
if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.node {
429430
if let Def::Const(..) = path.def {

src/librustc_lint/types.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc::hir::Node;
44
use rustc::ty::subst::Substs;
55
use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
66
use rustc::ty::layout::{self, IntegerExt, LayoutOf, VariantIdx};
7+
use rustc::{lint, util};
78
use rustc_data_structures::indexed_vec::Idx;
89
use util::nodemap::FxHashSet;
910
use lint::{LateContext, LintContext, LintArray};
@@ -23,6 +24,8 @@ use rustc::hir;
2324

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

27+
use log::debug;
28+
2629
declare_lint! {
2730
UNUSED_COMPARISONS,
2831
Warn,
@@ -241,7 +244,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
241244
}
242245
}
243246

244-
fn check_limits(cx: &LateContext,
247+
fn check_limits(cx: &LateContext<'_, '_>,
245248
binop: hir::BinOp,
246249
l: &hir::Expr,
247250
r: &hir::Expr)
@@ -298,7 +301,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
298301
}
299302
}
300303

301-
fn get_bin_hex_repr(cx: &LateContext, lit: &ast::Lit) -> Option<String> {
304+
fn get_bin_hex_repr(cx: &LateContext<'_, '_>, lit: &ast::Lit) -> Option<String> {
302305
let src = cx.sess().source_map().span_to_snippet(lit.span).ok()?;
303306
let firstch = src.chars().next()?;
304307

@@ -320,7 +323,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
320323
//
321324
// No suggestion for: `isize`, `usize`.
322325
fn get_type_suggestion<'a>(
323-
t: &ty::TyKind,
326+
t: &ty::TyKind<'_>,
324327
val: u128,
325328
negative: bool,
326329
) -> Option<String> {
@@ -364,9 +367,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
364367
}
365368

366369
fn report_bin_hex_error(
367-
cx: &LateContext,
370+
cx: &LateContext<'_, '_>,
368371
expr: &hir::Expr,
369-
ty: ty::TyKind,
372+
ty: ty::TyKind<'_>,
370373
repr_str: String,
371374
val: u128,
372375
negative: bool,
@@ -481,7 +484,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
481484
fn check_type_for_ffi(&self,
482485
cache: &mut FxHashSet<Ty<'tcx>>,
483486
ty: Ty<'tcx>) -> FfiResult<'tcx> {
484-
use self::FfiResult::*;
487+
use FfiResult::*;
485488

486489
let cx = self.cx.tcx;
487490

@@ -799,7 +802,7 @@ impl LintPass for ImproperCTypes {
799802
}
800803

801804
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes {
802-
fn check_foreign_item(&mut self, cx: &LateContext, it: &hir::ForeignItem) {
805+
fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem) {
803806
let mut vis = ImproperCTypesVisitor { cx };
804807
let abi = cx.tcx.hir().get_foreign_abi(it.id);
805808
if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic {
@@ -829,7 +832,7 @@ impl LintPass for VariantSizeDifferences {
829832
}
830833

831834
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
832-
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
835+
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
833836
if let hir::ItemKind::Enum(ref enum_definition, _) = it.node {
834837
let item_def_id = cx.tcx.hir().local_def_id(it.id);
835838
let t = cx.tcx.type_of(item_def_id);

0 commit comments

Comments
 (0)