Skip to content

Commit 3518178

Browse files
authored
Merge pull request #13639 from flip1995/rustup
Rustup
2 parents a28c44f + b116696 commit 3518178

File tree

83 files changed

+530
-506
lines changed

Some content is hidden

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

83 files changed

+530
-506
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Clippy
22

3-
[![Clippy Test](https://github.com/rust-lang/rust-clippy/workflows/Clippy%20Test%20(bors)/badge.svg?branch=auto&event=push)](https://github.com/rust-lang/rust-clippy/actions?query=workflow%3A%22Clippy+Test+(bors)%22+event%3Apush+branch%3Aauto)
43
[![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](#license)
54

65
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.

book/src/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Clippy
22

3-
[![Clippy Test](https://github.com/rust-lang/rust-clippy/workflows/Clippy%20Test%20(bors)/badge.svg?branch=auto&event=push)](https://github.com/rust-lang/rust-clippy/actions?query=workflow%3A%22Clippy+Test+(bors)%22+event%3Apush+branch%3Aauto)
43
[![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](https://github.com/rust-lang/rust-clippy#license)
54

65
A collection of lints to catch common mistakes and improve your

clippy_dev/src/update_lints.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -762,13 +762,19 @@ fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
762762
Literal{..}(desc)
763763
);
764764

765-
if let Some(LintDeclSearchResult {
766-
token_kind: TokenKind::CloseBrace,
767-
range,
768-
..
769-
}) = iter.next()
770-
{
771-
lints.push(Lint::new(name, group, desc, module, start..range.end));
765+
if let Some(end) = iter.find_map(|t| {
766+
if let LintDeclSearchResult {
767+
token_kind: TokenKind::CloseBrace,
768+
range,
769+
..
770+
} = t
771+
{
772+
Some(range.end)
773+
} else {
774+
None
775+
}
776+
}) {
777+
lints.push(Lint::new(name, group, desc, module, start..end));
772778
}
773779
}
774780
}

clippy_lints/src/attrs/allow_attributes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::is_from_proc_macro;
44
use rustc_ast::{AttrStyle, Attribute};
55
use rustc_errors::Applicability;
6-
use rustc_lint::{LateContext, LintContext};
6+
use rustc_lint::{EarlyContext, LintContext};
77
use rustc_middle::lint::in_external_macro;
88

99
// Separate each crate's features.
10-
pub fn check<'cx>(cx: &LateContext<'cx>, attr: &'cx Attribute) {
10+
pub fn check<'cx>(cx: &EarlyContext<'cx>, attr: &'cx Attribute) {
1111
if !in_external_macro(cx.sess(), attr.span)
1212
&& let AttrStyle::Outer = attr.style
1313
&& let Some(ident) = attr.ident()

clippy_lints/src/attrs/allow_attributes_without_reason.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use super::{ALLOW_ATTRIBUTES_WITHOUT_REASON, Attribute};
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::is_from_proc_macro;
44
use rustc_ast::{MetaItemInner, MetaItemKind};
5-
use rustc_lint::{LateContext, LintContext};
5+
use rustc_lint::{EarlyContext, LintContext};
66
use rustc_middle::lint::in_external_macro;
77
use rustc_span::sym;
88
use rustc_span::symbol::Symbol;
99

10-
pub(super) fn check<'cx>(cx: &LateContext<'cx>, name: Symbol, items: &[MetaItemInner], attr: &'cx Attribute) {
10+
pub(super) fn check<'cx>(cx: &EarlyContext<'cx>, name: Symbol, items: &[MetaItemInner], attr: &'cx Attribute) {
1111
// Check if the reason is present
1212
if let Some(item) = items.last().and_then(MetaItemInner::meta_item)
1313
&& let MetaItemKind::NameValue(_) = &item.kind

clippy_lints/src/attrs/blanket_clippy_restriction_lints.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use super::BLANKET_CLIPPY_RESTRICTION_LINTS;
22
use super::utils::extract_clippy_lint;
33
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
44
use rustc_ast::MetaItemInner;
5-
use rustc_lint::{LateContext, Level, LintContext};
5+
use rustc_lint::{EarlyContext, Level, LintContext};
66
use rustc_span::symbol::Symbol;
77
use rustc_span::{DUMMY_SP, sym};
88

9-
pub(super) fn check(cx: &LateContext<'_>, name: Symbol, items: &[MetaItemInner]) {
9+
pub(super) fn check(cx: &EarlyContext<'_>, name: Symbol, items: &[MetaItemInner]) {
1010
for lint in items {
1111
if let Some(lint_name) = extract_clippy_lint(lint) {
1212
if lint_name.as_str() == "restriction" && name != sym::allow {
@@ -23,7 +23,7 @@ pub(super) fn check(cx: &LateContext<'_>, name: Symbol, items: &[MetaItemInner])
2323
}
2424
}
2525

26-
pub(super) fn check_command_line(cx: &LateContext<'_>) {
26+
pub(super) fn check_command_line(cx: &EarlyContext<'_>) {
2727
for (name, level) in &cx.sess().opts.lint_opts {
2828
if name == "clippy::restriction" && *level > Level::Allow {
2929
span_lint_and_then(

clippy_lints/src/attrs/deprecated_semver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use super::DEPRECATED_SEMVER;
22
use clippy_utils::diagnostics::span_lint;
33
use rustc_ast::{LitKind, MetaItemLit};
4-
use rustc_lint::LateContext;
4+
use rustc_lint::EarlyContext;
55
use rustc_span::Span;
66
use semver::Version;
77

8-
pub(super) fn check(cx: &LateContext<'_>, span: Span, lit: &MetaItemLit) {
8+
pub(super) fn check(cx: &EarlyContext<'_>, span: Span, lit: &MetaItemLit) {
99
if let LitKind::Str(is, _) = lit.kind {
1010
if is.as_str() == "TBD" || Version::parse(is.as_str()).is_ok() {
1111
return;

clippy_lints/src/attrs/duplicated_attributes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use super::DUPLICATED_ATTRIBUTES;
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use rustc_ast::{Attribute, MetaItem};
44
use rustc_data_structures::fx::FxHashMap;
5-
use rustc_lint::LateContext;
5+
use rustc_lint::EarlyContext;
66
use rustc_span::{Span, sym};
77
use std::collections::hash_map::Entry;
88

99
fn emit_if_duplicated(
10-
cx: &LateContext<'_>,
10+
cx: &EarlyContext<'_>,
1111
attr: &MetaItem,
1212
attr_paths: &mut FxHashMap<String, Span>,
1313
complete_path: String,
@@ -26,7 +26,7 @@ fn emit_if_duplicated(
2626
}
2727

2828
fn check_duplicated_attr(
29-
cx: &LateContext<'_>,
29+
cx: &EarlyContext<'_>,
3030
attr: &MetaItem,
3131
attr_paths: &mut FxHashMap<String, Span>,
3232
parent: &mut Vec<String>,
@@ -65,7 +65,7 @@ fn check_duplicated_attr(
6565
}
6666
}
6767

68-
pub fn check(cx: &LateContext<'_>, attrs: &[Attribute]) {
68+
pub fn check(cx: &EarlyContext<'_>, attrs: &[Attribute]) {
6969
let mut attr_paths = FxHashMap::default();
7070

7171
for attr in attrs {

clippy_lints/src/attrs/mixed_attributes_style.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint;
33
use rustc_ast::{AttrKind, AttrStyle, Attribute};
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_data_structures::sync::Lrc;
6-
use rustc_lint::{LateContext, LintContext};
6+
use rustc_lint::{EarlyContext, LintContext};
77
use rustc_span::source_map::SourceMap;
88
use rustc_span::{SourceFile, Span, Symbol};
99

@@ -32,7 +32,7 @@ impl From<&AttrKind> for SimpleAttrKind {
3232
}
3333
}
3434

35-
pub(super) fn check(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute]) {
35+
pub(super) fn check(cx: &EarlyContext<'_>, item_span: Span, attrs: &[Attribute]) {
3636
let mut inner_attr_kind: FxHashSet<SimpleAttrKind> = FxHashSet::default();
3737
let mut outer_attr_kind: FxHashSet<SimpleAttrKind> = FxHashSet::default();
3838

@@ -64,7 +64,7 @@ pub(super) fn check(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute])
6464
}
6565
}
6666

67-
fn lint_mixed_attrs(cx: &LateContext<'_>, attrs: &[Attribute]) {
67+
fn lint_mixed_attrs(cx: &EarlyContext<'_>, attrs: &[Attribute]) {
6868
let mut attrs_iter = attrs.iter().filter(|attr| !attr.span.from_expansion());
6969
let span = if let (Some(first), Some(last)) = (attrs_iter.next(), attrs_iter.last()) {
7070
first.span.with_hi(last.span.hi())

clippy_lints/src/attrs/mod.rs

+76-52
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ mod utils;
1414

1515
use clippy_config::Conf;
1616
use clippy_config::msrvs::{self, Msrv};
17-
use rustc_ast::{Attribute, MetaItemInner, MetaItemKind};
18-
use rustc_hir::{ImplItem, Item, ItemKind, TraitItem};
17+
use rustc_ast::{self as ast, Attribute, MetaItemInner, MetaItemKind};
18+
use rustc_hir::{ImplItem, Item, TraitItem};
1919
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
2020
use rustc_session::impl_lint_pass;
2121
use rustc_span::sym;
@@ -414,15 +414,7 @@ pub struct Attributes {
414414
}
415415

416416
impl_lint_pass!(Attributes => [
417-
ALLOW_ATTRIBUTES,
418-
ALLOW_ATTRIBUTES_WITHOUT_REASON,
419417
INLINE_ALWAYS,
420-
DEPRECATED_SEMVER,
421-
USELESS_ATTRIBUTE,
422-
BLANKET_CLIPPY_RESTRICTION_LINTS,
423-
SHOULD_PANIC_WITHOUT_EXPECT,
424-
MIXED_ATTRIBUTES_STYLE,
425-
DUPLICATED_ATTRIBUTES,
426418
]);
427419

428420
impl Attributes {
@@ -434,53 +426,11 @@ impl Attributes {
434426
}
435427

436428
impl<'tcx> LateLintPass<'tcx> for Attributes {
437-
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
438-
blanket_clippy_restriction_lints::check_command_line(cx);
439-
duplicated_attributes::check(cx, cx.tcx.hir().krate_attrs());
440-
}
441-
442-
fn check_attribute(&mut self, cx: &LateContext<'tcx>, attr: &'tcx Attribute) {
443-
if let Some(items) = &attr.meta_item_list() {
444-
if let Some(ident) = attr.ident() {
445-
if is_lint_level(ident.name, attr.id) {
446-
blanket_clippy_restriction_lints::check(cx, ident.name, items);
447-
}
448-
if matches!(ident.name, sym::allow) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) {
449-
allow_attributes::check(cx, attr);
450-
}
451-
if matches!(ident.name, sym::allow | sym::expect) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION)
452-
{
453-
allow_attributes_without_reason::check(cx, ident.name, items, attr);
454-
}
455-
if items.is_empty() || !attr.has_name(sym::deprecated) {
456-
return;
457-
}
458-
for item in items {
459-
if let MetaItemInner::MetaItem(mi) = &item
460-
&& let MetaItemKind::NameValue(lit) = &mi.kind
461-
&& mi.has_name(sym::since)
462-
{
463-
deprecated_semver::check(cx, item.span(), lit);
464-
}
465-
}
466-
}
467-
}
468-
if attr.has_name(sym::should_panic) {
469-
should_panic_without_expect::check(cx, attr);
470-
}
471-
}
472-
473429
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
474430
let attrs = cx.tcx.hir().attrs(item.hir_id());
475431
if is_relevant_item(cx, item) {
476432
inline_always::check(cx, item.span, item.ident.name, attrs);
477433
}
478-
match item.kind {
479-
ItemKind::ExternCrate(..) | ItemKind::Use(..) => useless_attribute::check(cx, item, attrs),
480-
_ => {},
481-
}
482-
mixed_attributes_style::check(cx, item.span, attrs);
483-
duplicated_attributes::check(cx, attrs);
484434
}
485435

486436
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
@@ -526,3 +476,77 @@ impl EarlyLintPass for EarlyAttributes {
526476

527477
extract_msrv_attr!(EarlyContext);
528478
}
479+
480+
pub struct PostExpansionEarlyAttributes {
481+
msrv: Msrv,
482+
}
483+
484+
impl PostExpansionEarlyAttributes {
485+
pub fn new(conf: &'static Conf) -> Self {
486+
Self {
487+
msrv: conf.msrv.clone(),
488+
}
489+
}
490+
}
491+
492+
impl_lint_pass!(PostExpansionEarlyAttributes => [
493+
ALLOW_ATTRIBUTES,
494+
ALLOW_ATTRIBUTES_WITHOUT_REASON,
495+
DEPRECATED_SEMVER,
496+
USELESS_ATTRIBUTE,
497+
BLANKET_CLIPPY_RESTRICTION_LINTS,
498+
SHOULD_PANIC_WITHOUT_EXPECT,
499+
MIXED_ATTRIBUTES_STYLE,
500+
DUPLICATED_ATTRIBUTES,
501+
]);
502+
503+
impl EarlyLintPass for PostExpansionEarlyAttributes {
504+
fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &ast::Crate) {
505+
blanket_clippy_restriction_lints::check_command_line(cx);
506+
duplicated_attributes::check(cx, &krate.attrs);
507+
}
508+
509+
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
510+
if let Some(items) = &attr.meta_item_list() {
511+
if let Some(ident) = attr.ident() {
512+
if matches!(ident.name, sym::allow) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) {
513+
allow_attributes::check(cx, attr);
514+
}
515+
if matches!(ident.name, sym::allow | sym::expect) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION)
516+
{
517+
allow_attributes_without_reason::check(cx, ident.name, items, attr);
518+
}
519+
if is_lint_level(ident.name, attr.id) {
520+
blanket_clippy_restriction_lints::check(cx, ident.name, items);
521+
}
522+
if items.is_empty() || !attr.has_name(sym::deprecated) {
523+
return;
524+
}
525+
for item in items {
526+
if let MetaItemInner::MetaItem(mi) = &item
527+
&& let MetaItemKind::NameValue(lit) = &mi.kind
528+
&& mi.has_name(sym::since)
529+
{
530+
deprecated_semver::check(cx, item.span(), lit);
531+
}
532+
}
533+
}
534+
}
535+
536+
if attr.has_name(sym::should_panic) {
537+
should_panic_without_expect::check(cx, attr);
538+
}
539+
}
540+
541+
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &'_ ast::Item) {
542+
match item.kind {
543+
ast::ItemKind::ExternCrate(..) | ast::ItemKind::Use(..) => useless_attribute::check(cx, item, &item.attrs),
544+
_ => {},
545+
}
546+
547+
mixed_attributes_style::check(cx, item.span, &item.attrs);
548+
duplicated_attributes::check(cx, &item.attrs);
549+
}
550+
551+
extract_msrv_attr!(EarlyContext);
552+
}

clippy_lints/src/attrs/should_panic_without_expect.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use rustc_ast::token::{Token, TokenKind};
44
use rustc_ast::tokenstream::TokenTree;
55
use rustc_ast::{AttrArgs, AttrArgsEq, AttrKind};
66
use rustc_errors::Applicability;
7-
use rustc_lint::LateContext;
7+
use rustc_lint::EarlyContext;
88
use rustc_span::sym;
99

10-
pub(super) fn check(cx: &LateContext<'_>, attr: &Attribute) {
10+
pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute) {
1111
if let AttrKind::Normal(normal_attr) = &attr.kind {
12-
if let AttrArgs::Eq(_, AttrArgsEq::Hir(_)) = &normal_attr.item.args {
12+
if let AttrArgs::Eq(_, AttrArgsEq::Ast(_)) = &normal_attr.item.args {
1313
// `#[should_panic = ".."]` found, good
1414
return;
1515
}

clippy_lints/src/attrs/useless_attribute.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
use super::USELESS_ATTRIBUTE;
12
use super::utils::{extract_clippy_lint, is_lint_level, is_word};
2-
use super::{Attribute, USELESS_ATTRIBUTE};
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::source::{SpanRangeExt, first_line_of_span};
5-
use rustc_ast::MetaItemInner;
5+
use rustc_ast::{Attribute, Item, ItemKind, MetaItemInner};
66
use rustc_errors::Applicability;
7-
use rustc_hir::{Item, ItemKind};
8-
use rustc_lint::{LateContext, LintContext};
7+
use rustc_lint::{EarlyContext, LintContext};
98
use rustc_middle::lint::in_external_macro;
109
use rustc_span::sym;
1110

12-
pub(super) fn check(cx: &LateContext<'_>, item: &Item<'_>, attrs: &[Attribute]) {
11+
pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
1312
let skip_unused_imports = attrs.iter().any(|attr| attr.has_name(sym::macro_use));
1413

1514
for attr in attrs {

clippy_lints/src/cognitive_complexity.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ declare_clippy_lint! {
3030
#[clippy::version = "1.35.0"]
3131
pub COGNITIVE_COMPLEXITY,
3232
nursery,
33-
"functions that should be split up into multiple functions"
33+
"functions that should be split up into multiple functions",
34+
@eval_always = true
3435
}
3536

3637
pub struct CognitiveComplexity {

clippy_lints/src/ctfe.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use rustc_hir::def_id::LocalDefId;
2+
use rustc_hir::intravisit::FnKind;
3+
use rustc_hir::{Body, FnDecl};
4+
use rustc_lint::{LateContext, LateLintPass};
5+
use rustc_session::declare_lint_pass;
6+
use rustc_span::Span;
7+
8+
declare_lint_pass! {
9+
/// Ensures that Constant-time Function Evaluation is being done (specifically, MIR lint passes).
10+
/// As Clippy deactivates codegen, this lint ensures that CTFE (used in hard errors) is still ran.
11+
ClippyCtfe => []
12+
}
13+
14+
impl<'tcx> LateLintPass<'tcx> for ClippyCtfe {
15+
fn check_fn(
16+
&mut self,
17+
cx: &LateContext<'_>,
18+
_: FnKind<'tcx>,
19+
_: &'tcx FnDecl<'tcx>,
20+
_: &'tcx Body<'tcx>,
21+
_: Span,
22+
defid: LocalDefId,
23+
) {
24+
cx.tcx.ensure().mir_drops_elaborated_and_const_checked(defid); // Lint
25+
}
26+
}

0 commit comments

Comments
 (0)