Skip to content

Commit dc1f683

Browse files
committed
Auto merge of #32219 - brson:lints, r=alexcrichton
Make warnings of renamed and removed lints themselves lints This adds the `renamed_and_removed_lints` warning, defaulting to the warning level. Fixes #31141
2 parents 43843d0 + addde1f commit dc1f683

File tree

6 files changed

+68
-30
lines changed

6 files changed

+68
-30
lines changed

src/librustc/lint/builtin.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ declare_lint! {
160160
"two overlapping inherent impls define an item with the same name were erroneously allowed"
161161
}
162162

163+
declare_lint! {
164+
pub RENAMED_AND_REMOVED_LINTS,
165+
Warn,
166+
"lints that have been renamed or removed"
167+
}
168+
163169
/// Does nothing as a lint pass, but registers some `Lint`s
164170
/// which are used by other parts of the compiler.
165171
#[derive(Copy, Clone)]
@@ -191,7 +197,8 @@ impl LintPass for HardwiredLints {
191197
CONST_ERR,
192198
RAW_POINTER_DERIVE,
193199
TRANSMUTE_FROM_FN_ITEM_TYPES,
194-
OVERLAPPING_INHERENT_IMPLS
200+
OVERLAPPING_INHERENT_IMPLS,
201+
RENAMED_AND_REMOVED_LINTS
195202
)
196203
}
197204
}

src/librustc/lint/context.rs

+21-26
Original file line numberDiff line numberDiff line change
@@ -1144,13 +1144,13 @@ impl LateLintPass for GatherNodeLevels {
11441144
}
11451145
}
11461146

1147-
enum CheckLintNameResult<'a> {
1147+
enum CheckLintNameResult {
11481148
Ok,
11491149
// Lint doesn't exist
11501150
NoLint,
1151-
// The lint is either renamed or removed and a warning was
1152-
// generated in the DiagnosticBuilder
1153-
Mentioned(DiagnosticBuilder<'a>)
1151+
// The lint is either renamed or removed. This is the warning
1152+
// message.
1153+
Warning(String)
11541154
}
11551155

11561156
/// Checks the name of a lint for its existence, and whether it was
@@ -1160,27 +1160,18 @@ enum CheckLintNameResult<'a> {
11601160
/// it emits non-fatal warnings and there are *two* lint passes that
11611161
/// inspect attributes, this is only run from the late pass to avoid
11621162
/// printing duplicate warnings.
1163-
fn check_lint_name<'a>(sess: &'a Session,
1164-
lint_cx: &LintStore,
1165-
lint_name: &str,
1166-
span: Option<Span>) -> CheckLintNameResult<'a> {
1163+
fn check_lint_name(lint_cx: &LintStore,
1164+
lint_name: &str) -> CheckLintNameResult {
11671165
match lint_cx.by_name.get(lint_name) {
11681166
Some(&Renamed(ref new_name, _)) => {
1169-
let warning = format!("lint {} has been renamed to {}",
1170-
lint_name, new_name);
1171-
let db = match span {
1172-
Some(span) => sess.struct_span_warn(span, &warning[..]),
1173-
None => sess.struct_warn(&warning[..]),
1174-
};
1175-
CheckLintNameResult::Mentioned(db)
1167+
CheckLintNameResult::Warning(
1168+
format!("lint {} has been renamed to {}", lint_name, new_name)
1169+
)
11761170
},
11771171
Some(&Removed(ref reason)) => {
1178-
let warning = format!("lint {} has been removed: {}", lint_name, reason);
1179-
let db = match span {
1180-
Some(span) => sess.struct_span_warn(span, &warning[..]),
1181-
None => sess.struct_warn(&warning[..])
1182-
};
1183-
CheckLintNameResult::Mentioned(db)
1172+
CheckLintNameResult::Warning(
1173+
format!("lint {} has been removed: {}", lint_name, reason)
1174+
)
11841175
},
11851176
None => {
11861177
match lint_cx.lint_groups.get(lint_name) {
@@ -1209,10 +1200,12 @@ fn check_lint_name_attribute(cx: &LateContext, attr: &ast::Attribute) {
12091200
continue;
12101201
}
12111202
Ok((lint_name, _, span)) => {
1212-
match check_lint_name(&cx.tcx.sess, &cx.lints, &lint_name[..], Some(span)) {
1203+
match check_lint_name(&cx.lints,
1204+
&lint_name[..]) {
12131205
CheckLintNameResult::Ok => (),
1214-
CheckLintNameResult::Mentioned(mut db) => {
1215-
db.emit();
1206+
CheckLintNameResult::Warning(ref msg) => {
1207+
cx.span_lint(builtin::RENAMED_AND_REMOVED_LINTS,
1208+
span, msg);
12161209
}
12171210
CheckLintNameResult::NoLint => {
12181211
cx.span_lint(builtin::UNKNOWN_LINTS, span,
@@ -1228,9 +1221,11 @@ fn check_lint_name_attribute(cx: &LateContext, attr: &ast::Attribute) {
12281221
// Checks the validity of lint names derived from the command line
12291222
fn check_lint_name_cmdline(sess: &Session, lint_cx: &LintStore,
12301223
lint_name: &str, level: Level) {
1231-
let db = match check_lint_name(sess, lint_cx, lint_name, None) {
1224+
let db = match check_lint_name(lint_cx, lint_name) {
12321225
CheckLintNameResult::Ok => None,
1233-
CheckLintNameResult::Mentioned(db) => Some(db),
1226+
CheckLintNameResult::Warning(ref msg) => {
1227+
Some(sess.struct_warn(msg))
1228+
},
12341229
CheckLintNameResult::NoLint => {
12351230
Some(sess.struct_err(&format!("unknown lint: `{}`", lint_name)))
12361231
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// No warnings about removed lint when
12+
// allow(renamed_and_removed_lints)
13+
14+
#[deny(raw_pointer_derive)]
15+
#[allow(renamed_and_removed_lints)]
16+
#[deny(unused_variables)]
17+
fn main() { let unused = (); } //~ ERR unused

src/test/compile-fail/lint-removed.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// The raw_pointer_derived lint only warns about its own removal
11+
// The raw_pointer_derived lint was removed, but is now reported by
12+
// the renamed_and_removed_lints lint, which means it's a warning by
13+
// default, and allowed in cargo dependency builds.
1214
// cc #30346
1315

1416
#[deny(raw_pointer_derive)] //~ WARN raw_pointer_derive has been removed
15-
#[deny(warnings)]
17+
#[deny(unused_variables)]
1618
fn main() { let unused = (); } //~ ERR unused
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// No warnings about renamed lint when
12+
// allow(renamed_and_removed_lints)
13+
14+
#[deny(unknown_features)]
15+
#[allow(renamed_and_removed_lints)]
16+
#[deny(unused)]
17+
fn main() { let unused = (); } //~ ERR unused

src/test/run-pass/ifmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#![deny(warnings)]
1414
#![allow(unused_must_use)]
15-
#![allow(unknown_features)]
15+
#![allow(unused_features)]
1616
#![feature(box_syntax)]
1717
#![feature(question_mark)]
1818

0 commit comments

Comments
 (0)