Skip to content

Commit 68a799a

Browse files
committed
Auto merge of rust-lang#12999 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 4ddc8a2 + 585170e commit 68a799a

File tree

148 files changed

+1579
-1255
lines changed

Some content is hidden

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

148 files changed

+1579
-1255
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ Released 2022-05-19
19431943
[#8218](https://github.com/rust-lang/rust-clippy/pull/8218)
19441944
* [`needless_match`]
19451945
[#8471](https://github.com/rust-lang/rust-clippy/pull/8471)
1946-
* [`allow_attributes_without_reason`] (Requires `#![feature(lint_reasons)]`)
1946+
* [`allow_attributes_without_reason`]
19471947
[#8504](https://github.com/rust-lang/rust-clippy/pull/8504)
19481948
* [`print_in_format_impl`]
19491949
[#8253](https://github.com/rust-lang/rust-clippy/pull/8253)

book/src/lint_configuration.md

+2
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
669669

670670
---
671671
**Affected lints:**
672+
* [`allow_attributes`](https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes)
673+
* [`allow_attributes_without_reason`](https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes_without_reason)
672674
* [`almost_complete_range`](https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_range)
673675
* [`approx_constant`](https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant)
674676
* [`assigning_clones`](https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones)

clippy_config/src/conf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ define_Conf! {
266266
///
267267
/// Suppress lints whenever the suggested change would cause breakage for other crates.
268268
(avoid_breaking_exported_api: bool = true),
269-
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE, ITER_KV_MAP, MANUAL_C_STR_LITERALS, ASSIGNING_CLONES, LEGACY_NUMERIC_CONSTANTS, MANUAL_PATTERN_CHAR_COMPARISON.
269+
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE, ITER_KV_MAP, MANUAL_C_STR_LITERALS, ASSIGNING_CLONES, LEGACY_NUMERIC_CONSTANTS, MANUAL_PATTERN_CHAR_COMPARISON, ALLOW_ATTRIBUTES, ALLOW_ATTRIBUTES_WITHOUT_REASON.
270270
///
271271
/// The minimum rust version that the project supports. Defaults to the `rust-version` field in `Cargo.toml`
272272
#[default_text = ""]

clippy_config/src/msrvs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ macro_rules! msrv_aliases {
1717

1818
// names may refer to stabilized feature flags or library items
1919
msrv_aliases! {
20+
1,81,0 { LINT_REASONS_STABILIZATION }
2021
1,77,0 { C_STR_LITERALS }
2122
1,76,0 { PTR_FROM_REF, OPTION_RESULT_INSPECT }
2223
1,71,0 { TUPLE_ARRAY_CONVERSIONS, BUILD_HASHER_HASH_ONE }

clippy_lints/src/allow_attributes.rs

-73
This file was deleted.
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use super::ALLOW_ATTRIBUTES;
2+
use clippy_utils::diagnostics::span_lint_and_sugg;
3+
use clippy_utils::is_from_proc_macro;
4+
use rustc_ast::{AttrStyle, Attribute};
5+
use rustc_errors::Applicability;
6+
use rustc_lint::{LateContext, LintContext};
7+
use rustc_middle::lint::in_external_macro;
8+
9+
// Separate each crate's features.
10+
pub fn check<'cx>(cx: &LateContext<'cx>, attr: &'cx Attribute) {
11+
if !in_external_macro(cx.sess(), attr.span)
12+
&& let AttrStyle::Outer = attr.style
13+
&& let Some(ident) = attr.ident()
14+
&& !is_from_proc_macro(cx, attr)
15+
{
16+
span_lint_and_sugg(
17+
cx,
18+
ALLOW_ATTRIBUTES,
19+
ident.span,
20+
"#[allow] attribute found",
21+
"replace it with",
22+
"expect".into(),
23+
Applicability::MachineApplicable,
24+
);
25+
}
26+
}

clippy_lints/src/attrs/allow_attributes_without_reason.rs

-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ use rustc_span::sym;
88
use rustc_span::symbol::Symbol;
99

1010
pub(super) fn check<'cx>(cx: &LateContext<'cx>, name: Symbol, items: &[NestedMetaItem], attr: &'cx Attribute) {
11-
// Check for the feature
12-
if !cx.tcx.features().lint_reasons {
13-
return;
14-
}
15-
1611
// Check if the reason is present
1712
if let Some(item) = items.last().and_then(NestedMetaItem::meta_item)
1813
&& let MetaItemKind::NameValue(_) = &item.kind

clippy_lints/src/attrs/mod.rs

+62-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! checks for attributes
22
3+
mod allow_attributes;
34
mod allow_attributes_without_reason;
45
mod blanket_clippy_restriction_lints;
56
mod deprecated_cfg_attr;
@@ -14,11 +15,11 @@ mod unnecessary_clippy_cfg;
1415
mod useless_attribute;
1516
mod utils;
1617

17-
use clippy_config::msrvs::Msrv;
18+
use clippy_config::msrvs::{self, Msrv};
1819
use rustc_ast::{Attribute, MetaItemKind, NestedMetaItem};
1920
use rustc_hir::{ImplItem, Item, ItemKind, TraitItem};
2021
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
21-
use rustc_session::{declare_lint_pass, impl_lint_pass};
22+
use rustc_session::impl_lint_pass;
2223
use rustc_span::sym;
2324
use utils::{is_lint_level, is_relevant_impl, is_relevant_item, is_relevant_trait};
2425

@@ -270,26 +271,19 @@ declare_clippy_lint! {
270271

271272
declare_clippy_lint! {
272273
/// ### What it does
273-
/// Checks for attributes that allow lints without specifying the reason
274-
/// they should be allowed. (This requires the `lint_reasons` feature.)
274+
/// Checks for attributes that allow lints without a reason.
275275
///
276276
/// ### Why restrict this?
277-
/// There should always be a specific reason to allow a lint. This reason
278-
/// should be documented using the `reason` parameter, so that readers can
279-
/// understand why the `allow` is required, or remove it if it's no
280-
/// longer needed.
277+
/// Justifying each `allow` helps readers understand the reasoning,
278+
/// and may allow removing `allow` attributes if their purpose is obsolete.
281279
///
282280
/// ### Example
283281
/// ```no_run
284-
/// #![feature(lint_reasons)]
285-
///
286282
/// #![allow(clippy::some_lint)]
287283
/// ```
288284
///
289285
/// Use instead:
290286
/// ```no_run
291-
/// #![feature(lint_reasons)]
292-
///
293287
/// #![allow(clippy::some_lint, reason = "False positive rust-lang/rust-clippy#1002020")]
294288
/// ```
295289
#[clippy::version = "1.61.0"]
@@ -298,6 +292,41 @@ declare_clippy_lint! {
298292
"ensures that all `allow` and `expect` attributes have a reason"
299293
}
300294

295+
declare_clippy_lint! {
296+
/// ### What it does
297+
/// Checks for usage of the `#[allow]` attribute and suggests replacing it with
298+
/// the `#[expect]` (See [RFC 2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html))
299+
///
300+
/// This lint only warns outer attributes (`#[allow]`), as inner attributes
301+
/// (`#![allow]`) are usually used to enable or disable lints on a global scale.
302+
///
303+
/// ### Why is this bad?
304+
/// `#[expect]` attributes suppress the lint emission, but emit a warning, if
305+
/// the expectation is unfulfilled. This can be useful to be notified when the
306+
/// lint is no longer triggered.
307+
///
308+
/// ### Example
309+
/// ```rust,ignore
310+
/// #[allow(unused_mut)]
311+
/// fn foo() -> usize {
312+
/// let mut a = Vec::new();
313+
/// a.len()
314+
/// }
315+
/// ```
316+
/// Use instead:
317+
/// ```rust,ignore
318+
/// #[expect(unused_mut)]
319+
/// fn foo() -> usize {
320+
/// let mut a = Vec::new();
321+
/// a.len()
322+
/// }
323+
/// ```
324+
#[clippy::version = "1.70.0"]
325+
pub ALLOW_ATTRIBUTES,
326+
restriction,
327+
"`#[allow]` will not trigger if a warning isn't found. `#[expect]` triggers if there are no warnings."
328+
}
329+
301330
declare_clippy_lint! {
302331
/// ### What it does
303332
/// Checks for `#[should_panic]` attributes without specifying the expected panic message.
@@ -470,7 +499,13 @@ declare_clippy_lint! {
470499
"duplicated attribute"
471500
}
472501

473-
declare_lint_pass!(Attributes => [
502+
#[derive(Clone)]
503+
pub struct Attributes {
504+
msrv: Msrv,
505+
}
506+
507+
impl_lint_pass!(Attributes => [
508+
ALLOW_ATTRIBUTES,
474509
ALLOW_ATTRIBUTES_WITHOUT_REASON,
475510
INLINE_ALWAYS,
476511
DEPRECATED_SEMVER,
@@ -481,6 +516,13 @@ declare_lint_pass!(Attributes => [
481516
DUPLICATED_ATTRIBUTES,
482517
]);
483518

519+
impl Attributes {
520+
#[must_use]
521+
pub fn new(msrv: Msrv) -> Self {
522+
Self { msrv }
523+
}
524+
}
525+
484526
impl<'tcx> LateLintPass<'tcx> for Attributes {
485527
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
486528
blanket_clippy_restriction_lints::check_command_line(cx);
@@ -493,7 +535,11 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
493535
if is_lint_level(ident.name, attr.id) {
494536
blanket_clippy_restriction_lints::check(cx, ident.name, items);
495537
}
496-
if matches!(ident.name, sym::allow | sym::expect) {
538+
if matches!(ident.name, sym::allow) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) {
539+
allow_attributes::check(cx, attr);
540+
}
541+
if matches!(ident.name, sym::allow | sym::expect) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION)
542+
{
497543
allow_attributes_without_reason::check(cx, ident.name, items, attr);
498544
}
499545
if items.is_empty() || !attr.has_name(sym::deprecated) {
@@ -538,6 +584,8 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
538584
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id()));
539585
}
540586
}
587+
588+
extract_msrv_attr!(LateContext);
541589
}
542590

543591
pub struct EarlyAttributes {

clippy_lints/src/bool_assert_comparison.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
6161
)
6262
})
6363
.map_or(false, |assoc_item| {
64-
let proj = Ty::new_projection(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, []));
64+
let proj = Ty::new_projection_from_args(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, []));
6565
let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj);
6666

6767
nty.is_bool()

clippy_lints/src/casts/cast_nan_to_int.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
2121

2222
fn is_known_nan(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
2323
match constant(cx, cx.typeck_results(), e) {
24+
// FIXME(f16_f128): add these types when nan checks are available on all platforms
2425
Some(Constant::F64(n)) => n.is_nan(),
2526
Some(Constant::F32(n)) => n.is_nan(),
2627
_ => false,

clippy_lints/src/declared_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
3838
#[cfg(feature = "internal")]
3939
crate::utils::internal_lints::unsorted_clippy_utils_paths::UNSORTED_CLIPPY_UTILS_PATHS_INFO,
4040
crate::absolute_paths::ABSOLUTE_PATHS_INFO,
41-
crate::allow_attributes::ALLOW_ATTRIBUTES_INFO,
4241
crate::almost_complete_range::ALMOST_COMPLETE_RANGE_INFO,
4342
crate::approx_const::APPROX_CONSTANT_INFO,
4443
crate::arc_with_non_send_sync::ARC_WITH_NON_SEND_SYNC_INFO,
@@ -49,6 +48,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
4948
crate::assertions_on_result_states::ASSERTIONS_ON_RESULT_STATES_INFO,
5049
crate::assigning_clones::ASSIGNING_CLONES_INFO,
5150
crate::async_yields_async::ASYNC_YIELDS_ASYNC_INFO,
51+
crate::attrs::ALLOW_ATTRIBUTES_INFO,
5252
crate::attrs::ALLOW_ATTRIBUTES_WITHOUT_REASON_INFO,
5353
crate::attrs::BLANKET_CLIPPY_RESTRICTION_LINTS_INFO,
5454
crate::attrs::DEPRECATED_CFG_ATTR_INFO,

clippy_lints/src/dereference.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use clippy_utils::{
66
expr_use_ctxt, get_parent_expr, is_block_like, is_lint_allowed, path_to_local, DefinedTy, ExprUseNode,
77
};
88
use core::mem;
9-
use rustc_ast::util::parser::{PREC_POSTFIX, PREC_PREFIX};
9+
use rustc_ast::util::parser::{PREC_PREFIX, PREC_UNAMBIGUOUS};
1010
use rustc_data_structures::fx::FxIndexMap;
1111
use rustc_errors::Applicability;
1212
use rustc_hir::intravisit::{walk_ty, Visitor};
@@ -1007,7 +1007,7 @@ fn report<'tcx>(
10071007
let (precedence, calls_field) = match cx.tcx.parent_hir_node(data.first_expr.hir_id) {
10081008
Node::Expr(e) => match e.kind {
10091009
ExprKind::Call(callee, _) if callee.hir_id != data.first_expr.hir_id => (0, false),
1010-
ExprKind::Call(..) => (PREC_POSTFIX, matches!(expr.kind, ExprKind::Field(..))),
1010+
ExprKind::Call(..) => (PREC_UNAMBIGUOUS, matches!(expr.kind, ExprKind::Field(..))),
10111011
_ => (e.precedence().order(), false),
10121012
},
10131013
_ => (0, false),
@@ -1154,7 +1154,7 @@ impl<'tcx> Dereferencing<'tcx> {
11541154
},
11551155
Some(parent) if !parent.span.from_expansion() => {
11561156
// Double reference might be needed at this point.
1157-
if parent.precedence().order() == PREC_POSTFIX {
1157+
if parent.precedence().order() == PREC_UNAMBIGUOUS {
11581158
// Parentheses would be needed here, don't lint.
11591159
*outer_pat = None;
11601160
} else {

clippy_lints/src/float_literal.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,17 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
141141
#[must_use]
142142
fn max_digits(fty: FloatTy) -> u32 {
143143
match fty {
144-
// FIXME(f16_f128): replace the magic numbers once `{f16,f128}::DIGITS` are available
145-
FloatTy::F16 => 3,
144+
FloatTy::F16 => f16::DIGITS,
146145
FloatTy::F32 => f32::DIGITS,
147146
FloatTy::F64 => f64::DIGITS,
148-
FloatTy::F128 => 33,
147+
FloatTy::F128 => f128::DIGITS,
149148
}
150149
}
151150

152151
/// Counts the digits excluding leading zeros
153152
#[must_use]
154153
fn count_digits(s: &str) -> usize {
155-
// Note that s does not contain the f32/64 suffix, and underscores have been stripped
154+
// Note that s does not contain the `f{16,32,64,128}` suffix, and underscores have been stripped
156155
s.chars()
157156
.filter(|c| *c != '-' && *c != '.')
158157
.take_while(|c| *c != 'e' && *c != 'E')

0 commit comments

Comments
 (0)