Skip to content

Commit 4db76a6

Browse files
committed
Auto merge of #6653 - flip1995:rustup, r=flip1995
Rustup changelog: Deprecate `unknown_clippy_lints` (integrated in `unknown_lints`) r? `@ghost`
2 parents 5db215b + 60ab57e commit 4db76a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+185
-239
lines changed

clippy_lints/src/attrs.rs

+2-70
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ use rustc_errors::Applicability;
1010
use rustc_hir::{
1111
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,
1212
};
13-
use rustc_lint::{CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
13+
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
1414
use rustc_middle::lint::in_external_macro;
1515
use rustc_middle::ty;
1616
use rustc_session::{declare_lint_pass, declare_tool_lint};
17-
use rustc_span::lev_distance::find_best_match_for_name;
1817
use rustc_span::source_map::Span;
1918
use rustc_span::sym;
2019
use rustc_span::symbol::{Symbol, SymbolStr};
@@ -156,33 +155,6 @@ declare_clippy_lint! {
156155
"empty line after outer attribute"
157156
}
158157

159-
declare_clippy_lint! {
160-
/// **What it does:** Checks for `allow`/`warn`/`deny`/`forbid` attributes with scoped clippy
161-
/// lints and if those lints exist in clippy. If there is an uppercase letter in the lint name
162-
/// (not the tool name) and a lowercase version of this lint exists, it will suggest to lowercase
163-
/// the lint name.
164-
///
165-
/// **Why is this bad?** A lint attribute with a mistyped lint name won't have an effect.
166-
///
167-
/// **Known problems:** None.
168-
///
169-
/// **Example:**
170-
/// Bad:
171-
/// ```rust
172-
/// #![warn(if_not_els)]
173-
/// #![deny(clippy::All)]
174-
/// ```
175-
///
176-
/// Good:
177-
/// ```rust
178-
/// #![warn(if_not_else)]
179-
/// #![deny(clippy::all)]
180-
/// ```
181-
pub UNKNOWN_CLIPPY_LINTS,
182-
style,
183-
"unknown_lints for scoped Clippy lints"
184-
}
185-
186158
declare_clippy_lint! {
187159
/// **What it does:** Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category.
188160
///
@@ -272,7 +244,6 @@ declare_lint_pass!(Attributes => [
272244
INLINE_ALWAYS,
273245
DEPRECATED_SEMVER,
274246
USELESS_ATTRIBUTE,
275-
UNKNOWN_CLIPPY_LINTS,
276247
BLANKET_CLIPPY_RESTRICTION_LINTS,
277248
]);
278249

@@ -409,48 +380,9 @@ fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<SymbolStr> {
409380
}
410381

411382
fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMetaItem]) {
412-
let lint_store = cx.lints();
413383
for lint in items {
414384
if let Some(lint_name) = extract_clippy_lint(lint) {
415-
if let CheckLintNameResult::Tool(Err((None, _))) = lint_store.check_lint_name(&lint_name, Some(sym::clippy))
416-
{
417-
span_lint_and_then(
418-
cx,
419-
UNKNOWN_CLIPPY_LINTS,
420-
lint.span(),
421-
&format!("unknown clippy lint: clippy::{}", lint_name),
422-
|diag| {
423-
let name_lower = lint_name.to_lowercase();
424-
let symbols = lint_store
425-
.get_lints()
426-
.iter()
427-
.map(|l| Symbol::intern(&l.name_lower()))
428-
.collect::<Vec<_>>();
429-
let sugg = find_best_match_for_name(
430-
&symbols,
431-
Symbol::intern(&format!("clippy::{}", name_lower)),
432-
None,
433-
);
434-
if lint_name.chars().any(char::is_uppercase)
435-
&& lint_store.find_lints(&format!("clippy::{}", name_lower)).is_ok()
436-
{
437-
diag.span_suggestion(
438-
lint.span(),
439-
"lowercase the lint name",
440-
format!("clippy::{}", name_lower),
441-
Applicability::MachineApplicable,
442-
);
443-
} else if let Some(sugg) = sugg {
444-
diag.span_suggestion(
445-
lint.span(),
446-
"did you mean",
447-
sugg.to_string(),
448-
Applicability::MachineApplicable,
449-
);
450-
}
451-
},
452-
);
453-
} else if lint_name == "restriction" && ident != "allow" {
385+
if lint_name == "restriction" && ident != "allow" {
454386
span_lint_and_help(
455387
cx,
456388
BLANKET_CLIPPY_RESTRICTION_LINTS,

clippy_lints/src/bytecount.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ use crate::utils::{
22
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability, span_lint_and_sugg,
33
};
44
use if_chain::if_chain;
5-
use rustc_ast::ast::UintTy;
65
use rustc_errors::Applicability;
76
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, UnOp};
87
use rustc_lint::{LateContext, LateLintPass};
9-
use rustc_middle::ty;
8+
use rustc_middle::ty::{self, UintTy};
109
use rustc_session::{declare_lint_pass, declare_tool_lint};
1110
use rustc_span::sym;
1211
use rustc_span::Symbol;

clippy_lints/src/consts.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
use crate::utils::{clip, sext, unsext};
44
use if_chain::if_chain;
5-
use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
5+
use rustc_ast::ast::{self, LitFloatType, LitKind};
66
use rustc_data_structures::sync::Lrc;
77
use rustc_hir::def::{DefKind, Res};
88
use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, QPath, UnOp};
99
use rustc_lint::LateContext;
1010
use rustc_middle::mir::interpret::Scalar;
1111
use rustc_middle::ty::subst::{Subst, SubstsRef};
12-
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt};
12+
use rustc_middle::ty::{self, FloatTy, ScalarInt, Ty, TyCtxt};
1313
use rustc_middle::{bug, span_bug};
1414
use rustc_span::symbol::Symbol;
1515
use std::cmp::Ordering::{self, Equal};
@@ -167,8 +167,8 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
167167
LitKind::Char(c) => Constant::Char(c),
168168
LitKind::Int(n, _) => Constant::Int(n),
169169
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {
170-
FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()),
171-
FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()),
170+
ast::FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()),
171+
ast::FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()),
172172
},
173173
LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind() {
174174
ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),

clippy_lints/src/default.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::{
2-
any_parent_is_automatically_derived, contains_name, match_def_path, paths, qpath_res, snippet_with_macro_callsite,
2+
any_parent_is_automatically_derived, contains_name, match_def_path, paths, snippet_with_macro_callsite,
33
};
44
use crate::utils::{span_lint_and_note, span_lint_and_sugg};
55
use if_chain::if_chain;
@@ -231,7 +231,7 @@ fn is_expr_default<'tcx>(expr: &'tcx Expr<'tcx>, cx: &LateContext<'tcx>) -> bool
231231
if_chain! {
232232
if let ExprKind::Call(ref fn_expr, _) = &expr.kind;
233233
if let ExprKind::Path(qpath) = &fn_expr.kind;
234-
if let Res::Def(_, def_id) = qpath_res(cx, qpath, fn_expr.hir_id);
234+
if let Res::Def(_, def_id) = cx.qpath_res(qpath, fn_expr.hir_id);
235235
then {
236236
// right hand side of assignment is `Default::default`
237237
match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD)

clippy_lints/src/deprecated_lints.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,28 @@ declare_deprecated_lint! {
163163
}
164164

165165
declare_deprecated_lint! {
166+
/// **What it does:** Nothing. This lint has been deprecated.
167+
///
168+
/// **Deprecation reason:** This lint has been uplifted to rustc and is now called
169+
/// `panic_fmt`.
166170
pub PANIC_PARAMS,
167171
"this lint has been uplifted to rustc and is now called `panic_fmt`"
168172
}
169173

170174
declare_deprecated_lint! {
175+
/// **What it does:** Nothing. This lint has been deprecated.
176+
///
177+
/// **Deprecation reason:** This lint has been integrated into the `unknown_lints`
178+
/// rustc lint.
179+
pub UNKNOWN_CLIPPY_LINTS,
180+
"this lint has been integrated into the `unknown_lints` rustc lint"
181+
}
182+
183+
declare_deprecated_lint! {
184+
/// **What it does:** Nothing. This lint has been deprecated.
185+
///
186+
/// **Deprecation reason:** This lint has been replaced by `manual_find_map`, a
187+
/// more specific lint.
171188
pub FIND_MAP,
172-
"this lint is replaced by `manual_find_map`, a more specific lint"
189+
"this lint has been replaced by `manual_find_map`, a more specific lint"
173190
}

clippy_lints/src/doc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_lint::{LateContext, LateLintPass};
1212
use rustc_middle::lint::in_external_macro;
1313
use rustc_middle::ty;
1414
use rustc_parse::maybe_new_parser_from_source_str;
15+
use rustc_parse::parser::ForceCollect;
1516
use rustc_session::parse::ParseSess;
1617
use rustc_session::{declare_tool_lint, impl_lint_pass};
1718
use rustc_span::edition::Edition;
@@ -483,7 +484,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
483484

484485
let mut relevant_main_found = false;
485486
loop {
486-
match parser.parse_item() {
487+
match parser.parse_item(ForceCollect::No) {
487488
Ok(Some(item)) => match &item.kind {
488489
// Tests with one of these items are ignored
489490
ItemKind::Static(..)

clippy_lints/src/drop_forget_ref.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{is_copy, match_def_path, paths, qpath_res, span_lint_and_note};
1+
use crate::utils::{is_copy, match_def_path, paths, span_lint_and_note};
22
use if_chain::if_chain;
33
use rustc_hir::{Expr, ExprKind};
44
use rustc_lint::{LateContext, LateLintPass};
@@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
114114
if let ExprKind::Call(ref path, ref args) = expr.kind;
115115
if let ExprKind::Path(ref qpath) = path.kind;
116116
if args.len() == 1;
117-
if let Some(def_id) = qpath_res(cx, qpath, path.hir_id).opt_def_id();
117+
if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id();
118118
then {
119119
let lint;
120120
let msg;

clippy_lints/src/enum_clike.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
44
use crate::consts::{miri_to_const, Constant};
55
use crate::utils::span_lint;
6-
use rustc_ast::ast::{IntTy, UintTy};
76
use rustc_hir::{Item, ItemKind};
87
use rustc_lint::{LateContext, LateLintPass};
9-
use rustc_middle::ty;
108
use rustc_middle::ty::util::IntTypeExt;
9+
use rustc_middle::ty::{self, IntTy, UintTy};
1110
use rustc_session::{declare_lint_pass, declare_tool_lint};
1211
use std::convert::TryFrom;
1312

clippy_lints/src/exit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{is_entrypoint_fn, match_def_path, paths, qpath_res, span_lint};
1+
use crate::utils::{is_entrypoint_fn, match_def_path, paths, span_lint};
22
use if_chain::if_chain;
33
use rustc_hir::{Expr, ExprKind, Item, ItemKind, Node};
44
use rustc_lint::{LateContext, LateLintPass};
@@ -29,7 +29,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit {
2929
if_chain! {
3030
if let ExprKind::Call(ref path_expr, ref _args) = e.kind;
3131
if let ExprKind::Path(ref path) = path_expr.kind;
32-
if let Some(def_id) = qpath_res(cx, path, path_expr.hir_id).opt_def_id();
32+
if let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id();
3333
if match_def_path(cx, def_id, &paths::EXIT);
3434
then {
3535
let parent = cx.tcx.hir().get_parent_item(e.hir_id);

clippy_lints/src/fallible_impl_from.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::utils::paths::FROM_TRAIT;
2-
use crate::utils::{
3-
is_expn_of, is_type_diagnostic_item, match_def_path, match_panic_def_id, method_chain_args, span_lint_and_then,
4-
};
1+
use crate::utils::{is_expn_of, is_type_diagnostic_item, match_panic_def_id, method_chain_args, span_lint_and_then};
52
use if_chain::if_chain;
63
use rustc_hir as hir;
74
use rustc_lint::{LateContext, LateLintPass};
@@ -59,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
5956
if_chain! {
6057
if let hir::ItemKind::Impl(impl_) = &item.kind;
6158
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
62-
if match_def_path(cx, impl_trait_ref.def_id, &FROM_TRAIT);
59+
if cx.tcx.is_diagnostic_item(sym::from_trait, impl_trait_ref.def_id);
6360
then {
6461
lint_impl_body(cx, item.span, impl_.items);
6562
}

clippy_lints/src/float_literal.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::utils::{numeric_literal, span_lint_and_sugg};
22
use if_chain::if_chain;
3-
use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
3+
use rustc_ast::ast::{self, LitFloatType, LitKind};
44
use rustc_errors::Applicability;
55
use rustc_hir as hir;
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_middle::ty;
7+
use rustc_middle::ty::{self, FloatTy};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use std::fmt;
1010

@@ -75,8 +75,8 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
7575
let digits = count_digits(&sym_str);
7676
let max = max_digits(fty);
7777
let type_suffix = match lit_float_ty {
78-
LitFloatType::Suffixed(FloatTy::F32) => Some("f32"),
79-
LitFloatType::Suffixed(FloatTy::F64) => Some("f64"),
78+
LitFloatType::Suffixed(ast::FloatTy::F32) => Some("f32"),
79+
LitFloatType::Suffixed(ast::FloatTy::F64) => Some("f64"),
8080
LitFloatType::Unsuffixed => None
8181
};
8282
let (is_whole, mut float_str) = match fty {

clippy_lints/src/functions.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::{
22
attr_by_name, attrs::is_proc_macro, is_must_use_ty, is_trait_impl_item, is_type_diagnostic_item, iter_input_pats,
3-
last_path_segment, match_def_path, must_use_attr, qpath_res, return_ty, snippet, snippet_opt, span_lint,
4-
span_lint_and_help, span_lint_and_then, trait_ref_of_method, type_is_unsafe_function,
3+
last_path_segment, match_def_path, must_use_attr, return_ty, snippet, snippet_opt, span_lint, span_lint_and_help,
4+
span_lint_and_then, trait_ref_of_method, type_is_unsafe_function,
55
};
66
use if_chain::if_chain;
77
use rustc_ast::ast::Attribute;
@@ -659,7 +659,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
659659
impl<'a, 'tcx> DerefVisitor<'a, 'tcx> {
660660
fn check_arg(&self, ptr: &hir::Expr<'_>) {
661661
if let hir::ExprKind::Path(ref qpath) = ptr.kind {
662-
if let Res::Local(id) = qpath_res(self.cx, qpath, ptr.hir_id) {
662+
if let Res::Local(id) = self.cx.qpath_res(qpath, ptr.hir_id) {
663663
if self.ptrs.contains(&id) {
664664
span_lint(
665665
self.cx,
@@ -722,7 +722,7 @@ fn is_mutated_static(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> bool {
722722
use hir::ExprKind::{Field, Index, Path};
723723

724724
match e.kind {
725-
Path(ref qpath) => !matches!(qpath_res(cx, qpath, e.hir_id), Res::Local(_)),
725+
Path(ref qpath) => !matches!(cx.qpath_res(qpath, e.hir_id), Res::Local(_)),
726726
Field(ref inner, _) | Index(ref inner, _) => is_mutated_static(cx, inner),
727727
_ => false,
728728
}

clippy_lints/src/future_not_send.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::{Body, FnDecl, HirId};
44
use rustc_infer::infer::TyCtxtInferExt;
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_middle::ty::subst::Subst;
7-
use rustc_middle::ty::{Opaque, PredicateAtom::Trait};
7+
use rustc_middle::ty::{Opaque, PredicateKind::Trait};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::{sym, Span};
1010
use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt;
@@ -93,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
9393
cx.tcx.infer_ctxt().enter(|infcx| {
9494
for FulfillmentError { obligation, .. } in send_errors {
9595
infcx.maybe_note_obligation_cause_for_async_await(db, &obligation);
96-
if let Trait(trait_pred, _) = obligation.predicate.skip_binders() {
96+
if let Trait(trait_pred, _) = obligation.predicate.kind().skip_binder() {
9797
db.note(&format!(
9898
"`{}` doesn't implement `{}`",
9999
trait_pred.self_ty(),

clippy_lints/src/let_if_seq.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{qpath_res, snippet, span_lint_and_then, visitors::LocalUsedVisitor};
1+
use crate::utils::{snippet, span_lint_and_then, visitors::LocalUsedVisitor};
22
use if_chain::if_chain;
33
use rustc_errors::Applicability;
44
use rustc_hir as hir;
@@ -145,7 +145,7 @@ fn check_assign<'tcx>(
145145
if let hir::StmtKind::Semi(ref expr) = expr.kind;
146146
if let hir::ExprKind::Assign(ref var, ref value, _) = expr.kind;
147147
if let hir::ExprKind::Path(ref qpath) = var.kind;
148-
if let Res::Local(local_id) = qpath_res(cx, qpath, var.hir_id);
148+
if let Res::Local(local_id) = cx.qpath_res(qpath, var.hir_id);
149149
if decl == local_id;
150150
then {
151151
let mut v = LocalUsedVisitor::new(decl);

clippy_lints/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,13 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
506506
"clippy::panic_params",
507507
"this lint has been uplifted to rustc and is now called `panic_fmt`",
508508
);
509+
store.register_removed(
510+
"clippy::unknown_clippy_lints",
511+
"this lint has been integrated into the `unknown_lints` rustc lint",
512+
);
509513
store.register_removed(
510514
"clippy::find_map",
511-
"this lint is replaced by `manual_find_map`, a more specific lint",
515+
"this lint has been replaced by `manual_find_map`, a more specific lint",
512516
);
513517
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
514518

@@ -553,7 +557,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
553557
&attrs::EMPTY_LINE_AFTER_OUTER_ATTR,
554558
&attrs::INLINE_ALWAYS,
555559
&attrs::MISMATCHED_TARGET_OS,
556-
&attrs::UNKNOWN_CLIPPY_LINTS,
557560
&attrs::USELESS_ATTRIBUTE,
558561
&await_holding_invalid::AWAIT_HOLDING_LOCK,
559562
&await_holding_invalid::AWAIT_HOLDING_REFCELL_REF,
@@ -1409,7 +1412,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14091412
LintId::of(&attrs::DEPRECATED_CFG_ATTR),
14101413
LintId::of(&attrs::DEPRECATED_SEMVER),
14111414
LintId::of(&attrs::MISMATCHED_TARGET_OS),
1412-
LintId::of(&attrs::UNKNOWN_CLIPPY_LINTS),
14131415
LintId::of(&attrs::USELESS_ATTRIBUTE),
14141416
LintId::of(&bit_mask::BAD_BIT_MASK),
14151417
LintId::of(&bit_mask::INEFFECTIVE_BIT_MASK),
@@ -1692,7 +1694,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16921694
LintId::of(&assertions_on_constants::ASSERTIONS_ON_CONSTANTS),
16931695
LintId::of(&assign_ops::ASSIGN_OP_PATTERN),
16941696
LintId::of(&attrs::BLANKET_CLIPPY_RESTRICTION_LINTS),
1695-
LintId::of(&attrs::UNKNOWN_CLIPPY_LINTS),
16961697
LintId::of(&blacklisted_name::BLACKLISTED_NAME),
16971698
LintId::of(&blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS),
16981699
LintId::of(&collapsible_if::COLLAPSIBLE_ELSE_IF),

0 commit comments

Comments
 (0)