Skip to content

Commit ef124f6

Browse files
authored
Rustup (#17447)
r? @ghost changelog: none
2 parents eaaf49c + 4a940e5 commit ef124f6

39 files changed

Lines changed: 131 additions & 143 deletions

clippy_lints/src/approx_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl ApproxConstant {
7575
}
7676

7777
impl LateLintPass<'_> for ApproxConstant {
78-
fn check_lit(&mut self, cx: &LateContext<'_>, _hir_id: HirId, lit: Lit, _negated: bool) {
78+
fn check_lit(&mut self, cx: &LateContext<'_>, _hir_id: HirId, lit: Lit, _is_negated_pat: bool) {
7979
match lit.node {
8080
LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty {
8181
FloatTy::F16 => self.check_known_consts(cx, lit.span, s, "f16"),

clippy_lints/src/attrs/duplicated_attributes.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,12 @@ fn check_duplicated_attr(
4343
};
4444
if let Some(ident) = attr.ident() {
4545
let name = ident.name;
46-
if name == sym::doc || name == sym::cfg_attr_trace || name == sym::rustc_on_unimplemented || name == sym::reason
47-
{
46+
if name == sym::doc || name == sym::rustc_on_unimplemented || name == sym::reason {
4847
// FIXME: Would be nice to handle `cfg_attr` as well. Only problem is to check that cfg
4948
// conditions are the same.
5049
// `#[rustc_on_unimplemented]` contains duplicated subattributes, that's expected.
5150
return;
5251
}
53-
if let Some(direct_parent) = parent.last()
54-
&& *direct_parent == sym::cfg_trace
55-
&& [sym::all, sym::not, sym::any].contains(&name)
56-
{
57-
// FIXME: We don't correctly check `cfg`s for now, so if it's more complex than just a one
58-
// level `cfg`, we leave.
59-
return;
60-
}
6152
}
6253
if let Some(value) = attr.value_str() {
6354
emit_if_duplicated(

clippy_lints/src/attrs/mixed_attributes_style.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::MIXED_ATTRIBUTES_STYLE;
22
use clippy_utils::diagnostics::span_lint;
3-
use rustc_ast::{AttrKind, AttrStyle, Attribute};
3+
use rustc_ast::{AttrKind, AttrStyle, Attribute, SyntheticAttr};
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_lint::{EarlyContext, LintContext as _};
66
use rustc_span::source_map::SourceMap;
@@ -12,6 +12,8 @@ enum SimpleAttrKind {
1212
Doc,
1313
/// A normal attribute, with its name symbols.
1414
Normal(Vec<Symbol>),
15+
CfgTrace,
16+
CfgAttrTrace,
1517
}
1618

1719
impl From<&AttrKind> for SimpleAttrKind {
@@ -27,6 +29,10 @@ impl From<&AttrKind> for SimpleAttrKind {
2729
.collect::<Vec<_>>();
2830
Self::Normal(path_symbols)
2931
},
32+
AttrKind::Synthetic(synthetic) => match &**synthetic {
33+
SyntheticAttr::CfgTrace(_) => Self::CfgTrace,
34+
SyntheticAttr::CfgAttrTrace => Self::CfgAttrTrace,
35+
},
3036
AttrKind::DocComment(..) => Self::Doc,
3137
}
3238
}

clippy_lints/src/attrs/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use clippy_config::Conf;
1717
use clippy_utils::check_clippy_attr;
1818
use clippy_utils::diagnostics::span_lint_and_help;
1919
use clippy_utils::msrvs::{self, Msrv, MsrvStack};
20-
use rustc_ast::{self as ast, AttrArgs, AttrItemKind, AttrKind, Attribute, MetaItemInner, MetaItemKind};
20+
use rustc_ast::{self as ast, AttrArgs, AttrKind, Attribute, MetaItemInner, MetaItemKind};
2121
use rustc_hir::{ImplItem, ImplItemKind, Item, ItemKind, TraitFn, TraitItem, TraitItemKind};
2222
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext as _};
2323
use rustc_session::impl_lint_pass;
@@ -614,12 +614,8 @@ impl EarlyLintPass for PostExpansionEarlyAttributes {
614614
}
615615

616616
if attr.has_name(sym::ignore)
617-
&& match &attr.kind {
618-
AttrKind::Normal(normal_attr) => {
619-
!matches!(normal_attr.item.args, AttrItemKind::Unparsed(AttrArgs::Eq { .. }))
620-
},
621-
AttrKind::DocComment(..) => true,
622-
}
617+
&& let AttrKind::Normal(normal_attr) = &attr.kind
618+
&& !matches!(normal_attr.item.args, AttrArgs::Eq { .. })
623619
{
624620
span_lint_and_help(
625621
cx,

clippy_lints/src/attrs/should_panic_without_expect.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ use super::{Attribute, SHOULD_PANIC_WITHOUT_EXPECT};
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use rustc_ast::token::{Token, TokenKind};
44
use rustc_ast::tokenstream::TokenTree;
5-
use rustc_ast::{AttrArgs, AttrItemKind, AttrKind};
5+
use rustc_ast::{AttrArgs, AttrKind};
66
use rustc_errors::Applicability;
77
use rustc_lint::EarlyContext;
88
use rustc_span::sym;
99

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

17-
if let AttrItemKind::Unparsed(AttrArgs::Delimited(args)) = &normal_attr.item.args
17+
if let AttrArgs::Delimited(args) = &normal_attr.item.args
1818
&& let mut tt_iter = args.tokens.iter()
1919
&& let Some(TokenTree::Token(
2020
Token {

clippy_lints/src/casts/confusing_method_to_numeric_cast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
6565

6666
if let ty::FnDef(def_id, generics) = cast_from.kind()
6767
&& let Some(method_name) = cx.tcx.opt_item_name(*def_id)
68-
&& let Some((const_name, ty_name)) = get_const_name_and_ty_name(cx, method_name, *def_id, generics.as_slice())
68+
&& let Some((const_name, ty_name)) =
69+
get_const_name_and_ty_name(cx, method_name, *def_id, generics.no_bound_vars().unwrap().as_slice())
6970
{
7071
let mut applicability = Applicability::MaybeIncorrect;
7172
let from_snippet = snippet_with_applicability(cx, cast_expr.span, "..", &mut applicability);

clippy_lints/src/cfg_not_test.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use rustc_ast::attr::data_structures::CfgEntry;
3-
use rustc_ast::{AttrItemKind, EarlyParsedAttribute};
3+
use rustc_ast::{AttrKind, SyntheticAttr};
44
use rustc_lint::{EarlyContext, EarlyLintPass};
55
use rustc_session::declare_lint_pass;
66
use rustc_span::sym;
@@ -34,23 +34,20 @@ declare_lint_pass!(CfgNotTest => [CFG_NOT_TEST]);
3434

3535
impl EarlyLintPass for CfgNotTest {
3636
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &rustc_ast::Attribute) {
37-
if attr.has_name(sym::cfg_trace) {
38-
let AttrItemKind::Parsed(EarlyParsedAttribute::CfgTrace(cfg)) = &attr.get_normal_item().args else {
39-
unreachable!()
40-
};
41-
42-
if contains_not_test(cfg, false) {
43-
span_lint_and_then(
44-
cx,
45-
CFG_NOT_TEST,
46-
attr.span,
47-
"code is excluded from test builds",
48-
|diag| {
49-
diag.help("consider not excluding any code from test builds");
50-
diag.note_once("this could increase code coverage despite not actually being tested");
51-
},
52-
);
53-
}
37+
if let AttrKind::Synthetic(synthetic) = &attr.kind
38+
&& let SyntheticAttr::CfgTrace(cfg) = &**synthetic
39+
&& contains_not_test(cfg, false)
40+
{
41+
span_lint_and_then(
42+
cx,
43+
CFG_NOT_TEST,
44+
attr.span,
45+
"code is excluded from test builds",
46+
|diag| {
47+
diag.help("consider not excluding any code from test builds");
48+
diag.note_once("this could increase code coverage despite not actually being tested");
49+
},
50+
);
5451
}
5552
}
5653
}

clippy_lints/src/dereference.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,10 @@ impl TyCoercionStability {
902902
| TyKind::TraitObject(..)
903903
| TyKind::InferDelegation(..)
904904
| TyKind::Err(_) => Self::Reborrow,
905+
TyKind::View(ty, _) => {
906+
// FIXME(scrabsha): what are the semantics of view types here?
907+
Self::for_hir_ty(ty)
908+
},
905909
TyKind::UnsafeBinder(..) => Self::None,
906910
};
907911
}

clippy_lints/src/doc/include_in_doc_without_cfg.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_opt;
3-
use rustc_ast::{AttrArgs, AttrItemKind, AttrKind, AttrStyle, Attribute};
3+
use rustc_ast::{AttrArgs, AttrKind, AttrStyle, Attribute};
44
use rustc_errors::Applicability;
55
use rustc_lint::EarlyContext;
66

@@ -9,9 +9,9 @@ use super::DOC_INCLUDE_WITHOUT_CFG;
99
pub fn check(cx: &EarlyContext<'_>, attrs: &[Attribute]) {
1010
for attr in attrs {
1111
if !attr.span.from_expansion()
12-
&& let AttrKind::Normal(ref item) = attr.kind
12+
&& let AttrKind::Normal(ref normal) = attr.kind
1313
&& attr.doc_str().is_some()
14-
&& let AttrItemKind::Unparsed(AttrArgs::Eq { expr: meta, .. }) = &item.item.args
14+
&& let AttrArgs::Eq { expr: meta, .. } = &normal.item.args
1515
&& !attr.span.contains(meta.span)
1616
// Since the `include_str` is already expanded at this point, we can only take the
1717
// whole attribute snippet and then modify for our suggestion.

clippy_lints/src/doc/mod.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,8 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
12461246
containers.pop();
12471247
}
12481248
if check_doc_markdown {
1249-
if ticks_unbalanced && let Some(span) = fragments.span(cx, paragraph_range.clone()) {
1249+
if ticks_unbalanced && let Some(span) = fragments.span(cx, paragraph_range.clone())
1250+
.or_else(|| span_of_fragments(fragments.fragments)) {
12501251
span_lint_and_help(
12511252
cx,
12521253
DOC_MARKDOWN,
@@ -1259,13 +1260,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
12591260
} else {
12601261
for (text, range, assoc_code_level) in text_to_check.drain(..) {
12611262
markdown::check(
1262-
cx,
1263-
valid_idents,
1264-
&text,
1265-
&fragments,
1266-
range,
1267-
assoc_code_level,
1268-
blockquote_level,
1263+
cx, valid_idents, &text, &fragments, range, assoc_code_level, blockquote_level
12691264
);
12701265
}
12711266
}

0 commit comments

Comments
 (0)