Skip to content

Commit 3518178

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

83 files changed

Lines changed: 530 additions & 506 deletions

File tree

Some content is hidden

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

‎README.md‎

Lines changed: 0 additions & 1 deletion
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‎

Lines changed: 0 additions & 1 deletion
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‎

Lines changed: 13 additions & 7 deletions
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-
ifletSome(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+
ifletSome(end) = iter.find_map(|t| {
766+
ifletLintDeclSearchResult{
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‎

Lines changed: 2 additions & 2 deletions
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-
pubfncheck<'cx>(cx:&LateContext<'cx>,attr:&'cxAttribute){
10+
pubfncheck<'cx>(cx:&EarlyContext<'cx>,attr:&'cxAttribute){
1111
if !in_external_macro(cx.sess(), attr.span)
1212
&& letAttrStyle::Outer = attr.style
1313
&& letSome(ident) = attr.ident()

‎clippy_lints/src/attrs/allow_attributes_without_reason.rs‎

Lines changed: 2 additions & 2 deletions
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)fncheck<'cx>(cx:&LateContext<'cx>,name:Symbol,items:&[MetaItemInner],attr:&'cxAttribute){
10+
pub(super)fncheck<'cx>(cx:&EarlyContext<'cx>,name:Symbol,items:&[MetaItemInner],attr:&'cxAttribute){
1111
// Check if the reason is present
1212
ifletSome(item) = items.last().and_then(MetaItemInner::meta_item)
1313
&& letMetaItemKind::NameValue(_) = &item.kind

‎clippy_lints/src/attrs/blanket_clippy_restriction_lints.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use super::BLANKET_CLIPPY_RESTRICTION_LINTS;
22
usesuper::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)fncheck(cx:&LateContext<'_>,name:Symbol,items:&[MetaItemInner]){
9+
pub(super)fncheck(cx:&EarlyContext<'_>,name:Symbol,items:&[MetaItemInner]){
1010
for lint in items {
1111
ifletSome(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)fncheck_command_line(cx:&LateContext<'_>){
26+
pub(super)fncheck_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‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
usesuper::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)fncheck(cx:&LateContext<'_>,span:Span,lit:&MetaItemLit){
8+
pub(super)fncheck(cx:&EarlyContext<'_>,span:Span,lit:&MetaItemLit){
99
ifletLitKind::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‎

Lines changed: 4 additions & 4 deletions
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
fnemit_if_duplicated(
10-
cx:&LateContext<'_>,
10+
cx:&EarlyContext<'_>,
1111
attr:&MetaItem,
1212
attr_paths:&mutFxHashMap<String,Span>,
1313
complete_path:String,
@@ -26,7 +26,7 @@ fn emit_if_duplicated(
2626
}
2727

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

68-
pubfncheck(cx:&LateContext<'_>,attrs:&[Attribute]){
68+
pubfncheck(cx:&EarlyContext<'_>,attrs:&[Attribute]){
6969
letmut attr_paths = FxHashMap::default();
7070

7171
for attr in attrs {

‎clippy_lints/src/attrs/mixed_attributes_style.rs‎

Lines changed: 3 additions & 3 deletions
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)fncheck(cx:&LateContext<'_>,item_span:Span,attrs:&[Attribute]){
35+
pub(super)fncheck(cx:&EarlyContext<'_>,item_span:Span,attrs:&[Attribute]){
3636
letmut inner_attr_kind:FxHashSet<SimpleAttrKind> = FxHashSet::default();
3737
letmut 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-
fnlint_mixed_attrs(cx:&LateContext<'_>,attrs:&[Attribute]){
67+
fnlint_mixed_attrs(cx:&EarlyContext<'_>,attrs:&[Attribute]){
6868
letmut attrs_iter = attrs.iter().filter(|attr| !attr.span.from_expansion());
6969
let span = iflet(Some(first),Some(last)) = (attrs_iter.next(), attrs_iter.last()){
7070
first.span.with_hi(last.span.hi())

‎clippy_lints/src/attrs/mod.rs‎

Lines changed: 76 additions & 52 deletions
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::{selfas 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
implAttributes{
@@ -434,53 +426,11 @@ impl Attributes {
434426
}
435427

436428
impl<'tcx>LateLintPass<'tcx>forAttributes{
437-
fncheck_crate(&mutself,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-
fncheck_attribute(&mutself,cx:&LateContext<'tcx>,attr:&'tcxAttribute){
443-
ifletSome(items) = &attr.meta_item_list(){
444-
ifletSome(ident) = attr.ident(){
445-
ifis_lint_level(ident.name, attr.id){
446-
blanket_clippy_restriction_lints::check(cx, ident.name, items);
447-
}
448-
ifmatches!(ident.name, sym::allow) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION){
449-
allow_attributes::check(cx, attr);
450-
}
451-
ifmatches!(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-
ifletMetaItemInner::MetaItem(mi) = &item
460-
&& letMetaItemKind::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
fncheck_item(&mutself,cx:&LateContext<'tcx>,item:&'tcxItem<'_>){
474430
let attrs = cx.tcx.hir().attrs(item.hir_id());
475431
ifis_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
fncheck_impl_item(&mutself,cx:&LateContext<'tcx>,item:&'tcxImplItem<'_>){
@@ -526,3 +476,77 @@ impl EarlyLintPass for EarlyAttributes {
526476

527477
extract_msrv_attr!(EarlyContext);
528478
}
479+
480+
pubstructPostExpansionEarlyAttributes{
481+
msrv:Msrv,
482+
}
483+
484+
implPostExpansionEarlyAttributes{
485+
pubfnnew(conf:&'staticConf) -> 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+
implEarlyLintPassforPostExpansionEarlyAttributes{
504+
fncheck_crate(&mutself,cx:&EarlyContext<'_>,krate:&ast::Crate){
505+
blanket_clippy_restriction_lints::check_command_line(cx);
506+
duplicated_attributes::check(cx,&krate.attrs);
507+
}
508+
509+
fncheck_attribute(&mutself,cx:&EarlyContext<'_>,attr:&Attribute){
510+
ifletSome(items) = &attr.meta_item_list(){
511+
ifletSome(ident) = attr.ident(){
512+
ifmatches!(ident.name, sym::allow) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION){
513+
allow_attributes::check(cx, attr);
514+
}
515+
ifmatches!(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+
ifis_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+
ifletMetaItemInner::MetaItem(mi) = &item
527+
&& letMetaItemKind::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+
fncheck_item(&mutself,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+
}

0 commit comments

Comments
 (0)