diff --git a/Cargo.toml b/Cargo.toml index 6c19e7af5f8b..23b2b4ff0b47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy" # begin autogenerated version -version = "0.1.86" +version = "0.1.87" # end autogenerated version description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" diff --git a/clippy_config/Cargo.toml b/clippy_config/Cargo.toml index e473a5839402..934725fccb8e 100644 --- a/clippy_config/Cargo.toml +++ b/clippy_config/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_config" # begin autogenerated version -version = "0.1.86" +version = "0.1.87" # end autogenerated version edition = "2024" publish = false diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index c62a7ec783b6..54347043a13d 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_lints" # begin autogenerated version -version = "0.1.86" +version = "0.1.87" # end autogenerated version description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 95c85f250e98..fbcd49f00184 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -3,10 +3,10 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::msrvs::{self, Msrv}; use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; use rustc_attr_parsing::RustcVersion; -use rustc_hir::{Expr, ExprKind}; +use rustc_hir::{HirId, Lit}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; -use rustc_span::symbol; +use rustc_span::{Span, symbol}; use std::f64::consts as f64; declare_clippy_lint! { @@ -73,22 +73,28 @@ impl ApproxConstant { msrv: conf.msrv.clone(), } } +} - fn check_lit(&self, cx: &LateContext<'_>, lit: &LitKind, e: &Expr<'_>) { - match *lit { +impl LateLintPass<'_> for ApproxConstant { + fn check_lit(&mut self, cx: &LateContext<'_>, _hir_id: HirId, lit: &Lit, _negated: bool) { + match lit.node { LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty { - FloatTy::F16 => self.check_known_consts(cx, e, s, "f16"), - FloatTy::F32 => self.check_known_consts(cx, e, s, "f32"), - FloatTy::F64 => self.check_known_consts(cx, e, s, "f64"), - FloatTy::F128 => self.check_known_consts(cx, e, s, "f128"), + FloatTy::F16 => self.check_known_consts(cx, lit.span, s, "f16"), + FloatTy::F32 => self.check_known_consts(cx, lit.span, s, "f32"), + FloatTy::F64 => self.check_known_consts(cx, lit.span, s, "f64"), + FloatTy::F128 => self.check_known_consts(cx, lit.span, s, "f128"), }, // FIXME(f16_f128): add `f16` and `f128` when these types become stable. - LitKind::Float(s, LitFloatType::Unsuffixed) => self.check_known_consts(cx, e, s, "f{32, 64}"), + LitKind::Float(s, LitFloatType::Unsuffixed) => self.check_known_consts(cx, lit.span, s, "f{32, 64}"), _ => (), } } - fn check_known_consts(&self, cx: &LateContext<'_>, e: &Expr<'_>, s: symbol::Symbol, module: &str) { + extract_msrv_attr!(LateContext); +} + +impl ApproxConstant { + fn check_known_consts(&self, cx: &LateContext<'_>, span: Span, s: symbol::Symbol, module: &str) { let s = s.as_str(); if s.parse::().is_ok() { for &(constant, name, min_digits, msrv) in &KNOWN_CONSTS { @@ -96,7 +102,7 @@ impl ApproxConstant { span_lint_and_help( cx, APPROX_CONSTANT, - e.span, + span, format!("approximate value of `{module}::consts::{name}` found"), None, "consider using the constant directly", @@ -110,16 +116,6 @@ impl ApproxConstant { impl_lint_pass!(ApproxConstant => [APPROX_CONSTANT]); -impl<'tcx> LateLintPass<'tcx> for ApproxConstant { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if let ExprKind::Lit(lit) = &e.kind { - self.check_lit(cx, &lit.node, e); - } - } - - extract_msrv_attr!(LateContext); -} - /// Returns `false` if the number of significant figures in `value` are /// less than `min_digits`; otherwise, returns true if `value` is equal /// to `constant`, rounded to the number of digits present in `value`. diff --git a/clippy_lints/src/arbitrary_source_item_ordering.rs b/clippy_lints/src/arbitrary_source_item_ordering.rs index f519a65fc272..aff40fa846be 100644 --- a/clippy_lints/src/arbitrary_source_item_ordering.rs +++ b/clippy_lints/src/arbitrary_source_item_ordering.rs @@ -338,7 +338,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering { return; } - let items = module.item_ids.iter().map(|&id| cx.tcx.hir().item(id)); + let items = module.item_ids.iter().map(|&id| cx.tcx.hir_item(id)); // Iterates over the items within a module. // diff --git a/clippy_lints/src/async_yields_async.rs b/clippy_lints/src/async_yields_async.rs index eeaa3de3725f..013819b0da8a 100644 --- a/clippy_lints/src/async_yields_async.rs +++ b/clippy_lints/src/async_yields_async.rs @@ -60,12 +60,12 @@ impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { // XXXkhuey maybe we should? return; }, - CoroutineSource::Block => cx.tcx.hir().body(*body_id).value, + CoroutineSource::Block => cx.tcx.hir_body(*body_id).value, CoroutineSource::Closure => { // Like `async fn`, async closures are wrapped in an additional block // to move all of the closure's arguments into the future. - let async_closure_body = cx.tcx.hir().body(*body_id).value; + let async_closure_body = cx.tcx.hir_body(*body_id).value; let ExprKind::Block(block, _) = async_closure_body.kind else { return; }; diff --git a/clippy_lints/src/attrs/mixed_attributes_style.rs b/clippy_lints/src/attrs/mixed_attributes_style.rs index 3e4bcfbfc190..d71c8e9894bf 100644 --- a/clippy_lints/src/attrs/mixed_attributes_style.rs +++ b/clippy_lints/src/attrs/mixed_attributes_style.rs @@ -2,10 +2,10 @@ use super::MIXED_ATTRIBUTES_STYLE; use clippy_utils::diagnostics::span_lint; use rustc_ast::{AttrKind, AttrStyle, Attribute}; use rustc_data_structures::fx::FxHashSet; -use rustc_data_structures::sync::Lrc; use rustc_lint::{EarlyContext, LintContext}; use rustc_span::source_map::SourceMap; use rustc_span::{SourceFile, Span, Symbol}; +use std::sync::Arc; #[derive(Hash, PartialEq, Eq)] enum SimpleAttrKind { @@ -79,7 +79,7 @@ fn lint_mixed_attrs(cx: &EarlyContext<'_>, attrs: &[Attribute]) { ); } -fn attr_in_same_src_as_item(source_map: &SourceMap, item_src: &Lrc, attr_span: Span) -> bool { +fn attr_in_same_src_as_item(source_map: &SourceMap, item_src: &Arc, attr_span: Span) -> bool { let attr_src = source_map.lookup_source_file(attr_span.lo()); - Lrc::ptr_eq(item_src, &attr_src) + Arc::ptr_eq(item_src, &attr_src) } diff --git a/clippy_lints/src/attrs/utils.rs b/clippy_lints/src/attrs/utils.rs index 152e6ec70a18..a667649f7343 100644 --- a/clippy_lints/src/attrs/utils.rs +++ b/clippy_lints/src/attrs/utils.rs @@ -22,7 +22,7 @@ pub(super) fn is_lint_level(symbol: Symbol, attr_id: AttrId) -> bool { pub(super) fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool { if let ItemKind::Fn { body: eid, .. } = item.kind { - is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value) + is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir_body(eid).value) } else { true } @@ -30,7 +30,7 @@ pub(super) fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool { pub(super) fn is_relevant_impl(cx: &LateContext<'_>, item: &ImplItem<'_>) -> bool { match item.kind { - ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value), + ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir_body(eid).value), _ => false, } } @@ -39,7 +39,7 @@ pub(super) fn is_relevant_trait(cx: &LateContext<'_>, item: &TraitItem<'_>) -> b match item.kind { TraitItemKind::Fn(_, TraitFn::Required(_)) => true, TraitItemKind::Fn(_, TraitFn::Provided(eid)) => { - is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value) + is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir_body(eid).value) }, _ => false, } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 58a011713a7b..f57f56f3efdc 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -454,7 +454,7 @@ fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Opti }) }, ExprKind::Closure(closure) => { - let body = cx.tcx.hir().body(closure.body); + let body = cx.tcx.hir_body(closure.body); let params = body .params .iter() diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs index 48e9f1d690ee..ca973f4bb1aa 100644 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/clippy_lints/src/casts/cast_possible_truncation.rs @@ -4,13 +4,13 @@ use clippy_utils::expr_or_init; use clippy_utils::source::snippet; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize}; +use rustc_abi::IntegerType; use rustc_errors::{Applicability, Diag}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::{self, FloatTy, Ty}; use rustc_span::Span; -use rustc_target::abi::IntegerType; use super::{CAST_ENUM_TRUNCATION, CAST_POSSIBLE_TRUNCATION, utils}; diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index e4c0db5d9ef0..57a135abc2e2 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -66,7 +66,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned") && let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id) && let Some(def_id) = cx.tcx.impl_of_method(def_id) - && cx.tcx.type_of(def_id).instantiate_identity().is_unsafe_ptr() + && cx.tcx.type_of(def_id).instantiate_identity().is_raw_ptr() { true } else { diff --git a/clippy_lints/src/collection_is_never_read.rs b/clippy_lints/src/collection_is_never_read.rs index 8276e53648c0..1279be34ed8f 100644 --- a/clippy_lints/src/collection_is_never_read.rs +++ b/clippy_lints/src/collection_is_never_read.rs @@ -118,7 +118,7 @@ fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirI let is_read_in_closure_arg = args.iter().any(|arg| { if let ExprKind::Closure(closure) = arg.kind // To keep things simple, we only check the first param to see if its read. - && let Body { params: [param, ..], value } = cx.tcx.hir().body(closure.body) + && let Body { params: [param, ..], value } = cx.tcx.hir_body(closure.body) { !has_no_read_access(cx, param.hir_id, *value) } else { diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 011eed25552c..1cc1a81f8cee 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -145,8 +145,6 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::doc::DOC_NESTED_REFDEFS_INFO, crate::doc::DOC_OVERINDENTED_LIST_ITEMS_INFO, crate::doc::EMPTY_DOCS_INFO, - crate::doc::EMPTY_LINE_AFTER_DOC_COMMENTS_INFO, - crate::doc::EMPTY_LINE_AFTER_OUTER_ATTR_INFO, crate::doc::MISSING_ERRORS_DOC_INFO, crate::doc::MISSING_PANICS_DOC_INFO, crate::doc::MISSING_SAFETY_DOC_INFO, @@ -163,6 +161,8 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::else_if_without_else::ELSE_IF_WITHOUT_ELSE_INFO, crate::empty_drop::EMPTY_DROP_INFO, crate::empty_enum::EMPTY_ENUM_INFO, + crate::empty_line_after::EMPTY_LINE_AFTER_DOC_COMMENTS_INFO, + crate::empty_line_after::EMPTY_LINE_AFTER_OUTER_ATTR_INFO, crate::empty_with_brackets::EMPTY_ENUM_VARIANTS_WITH_BRACKETS_INFO, crate::empty_with_brackets::EMPTY_STRUCTS_WITH_BRACKETS_INFO, crate::endian_bytes::BIG_ENDIAN_BYTES_INFO, diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index 772268e7899e..784214c29af9 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -52,11 +52,10 @@ declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]); impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback { fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) { - let hir = cx.tcx.hir(); // NOTE: this is different from `clippy_utils::is_inside_always_const_context`. // Inline const supports type inference. let is_parent_const = matches!( - hir.body_const_context(hir.body_owner_def_id(body.id())), + cx.tcx.hir_body_const_context(cx.tcx.hir_body_owner_def_id(body.id())), Some(ConstContext::Const { inline: false } | ConstContext::Static(_)) ); let mut visitor = NumericFallbackVisitor::new(cx, is_parent_const); diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 233ebe00d8e7..849c60b89b97 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -682,7 +682,7 @@ fn try_parse_ref_op<'tcx>( }, [arg], ) => (true, typeck.qpath_res(path, *hir_id).opt_def_id()?, arg), - ExprKind::Unary(UnOp::Deref, sub_expr) if !typeck.expr_ty(sub_expr).is_unsafe_ptr() => { + ExprKind::Unary(UnOp::Deref, sub_expr) if !typeck.expr_ty(sub_expr).is_raw_ptr() => { return Some((RefOp::Deref, sub_expr)); }, ExprKind::AddrOf(BorrowKind::Ref, mutability, sub_expr) => return Some((RefOp::AddrOf(mutability), sub_expr)), diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index 9569081ad088..bb445e0155f6 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -197,7 +197,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { && let impl_item_hir = child.id.hir_id() && let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir) && let ImplItemKind::Fn(_, b) = &impl_item.kind - && let Body { value: func_expr, .. } = cx.tcx.hir().body(*b) + && let Body { value: func_expr, .. } = cx.tcx.hir_body(*b) && let &ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() && let attrs = cx.tcx.hir().attrs(item.hir_id()) && !attrs.iter().any(|attr| attr.doc_str().is_some()) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 91ddbb44ff89..db3e6034c5ba 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -437,8 +437,8 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { walk_expr(self, expr) } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/doc/empty_line_after.rs b/clippy_lints/src/doc/empty_line_after.rs deleted file mode 100644 index 6e85c6af642b..000000000000 --- a/clippy_lints/src/doc/empty_line_after.rs +++ /dev/null @@ -1,345 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::{SpanRangeExt, snippet_indent}; -use clippy_utils::tokenize_with_text; -use itertools::Itertools; -use rustc_ast::AttrStyle; -use rustc_ast::token::CommentKind; -use rustc_errors::{Applicability, Diag, SuggestionStyle}; -use rustc_hir::{AttrKind, Attribute, ItemKind, Node}; -use rustc_lexer::TokenKind; -use rustc_lint::LateContext; -use rustc_span::{BytePos, ExpnKind, InnerSpan, Span, SpanData}; - -use super::{EMPTY_LINE_AFTER_DOC_COMMENTS, EMPTY_LINE_AFTER_OUTER_ATTR}; - -#[derive(Debug, PartialEq, Clone, Copy)] -enum StopKind { - Attr, - Doc(CommentKind), -} - -impl StopKind { - fn is_doc(self) -> bool { - matches!(self, StopKind::Doc(_)) - } -} - -#[derive(Debug)] -struct Stop { - span: Span, - kind: StopKind, - first: usize, - last: usize, -} - -impl Stop { - fn convert_to_inner(&self) -> (Span, String) { - let inner = match self.kind { - // #|[...] - StopKind::Attr => InnerSpan::new(1, 1), - // /// or /** - // ^ ^ - StopKind::Doc(_) => InnerSpan::new(2, 3), - }; - (self.span.from_inner(inner), "!".into()) - } - - fn comment_out(&self, cx: &LateContext<'_>, suggestions: &mut Vec<(Span, String)>) { - match self.kind { - StopKind::Attr => { - if cx.tcx.sess.source_map().is_multiline(self.span) { - suggestions.extend([ - (self.span.shrink_to_lo(), "/* ".into()), - (self.span.shrink_to_hi(), " */".into()), - ]); - } else { - suggestions.push((self.span.shrink_to_lo(), "// ".into())); - } - }, - StopKind::Doc(CommentKind::Line) => suggestions.push((self.span.shrink_to_lo(), "// ".into())), - StopKind::Doc(CommentKind::Block) => { - // /** outer */ /*! inner */ - // ^ ^ - let asterisk = self.span.from_inner(InnerSpan::new(1, 2)); - suggestions.push((asterisk, String::new())); - }, - } - } - - fn from_attr(cx: &LateContext<'_>, attr: &Attribute) -> Option { - let SpanData { lo, hi, .. } = attr.span.data(); - let file = cx.tcx.sess.source_map().lookup_source_file(lo); - - Some(Self { - span: attr.span, - kind: match attr.kind { - AttrKind::Normal(_) => StopKind::Attr, - AttrKind::DocComment(comment_kind, _) => StopKind::Doc(comment_kind), - }, - first: file.lookup_line(file.relative_position(lo))?, - last: file.lookup_line(file.relative_position(hi))?, - }) - } -} - -/// Represents a set of attrs/doc comments separated by 1 or more empty lines -/// -/// ```ignore -/// /// chunk 1 docs -/// // not an empty line so also part of chunk 1 -/// #[chunk_1_attrs] // <-- prev_stop -/// -/// /* gap */ -/// -/// /// chunk 2 docs // <-- next_stop -/// #[chunk_2_attrs] -/// ``` -struct Gap<'a> { - /// The span of individual empty lines including the newline at the end of the line - empty_lines: Vec, - has_comment: bool, - next_stop: &'a Stop, - prev_stop: &'a Stop, - /// The chunk that includes [`prev_stop`](Self::prev_stop) - prev_chunk: &'a [Stop], -} - -impl<'a> Gap<'a> { - fn new(cx: &LateContext<'_>, prev_chunk: &'a [Stop], next_chunk: &'a [Stop]) -> Option { - let prev_stop = prev_chunk.last()?; - let next_stop = next_chunk.first()?; - let gap_span = prev_stop.span.between(next_stop.span); - let gap_snippet = gap_span.get_source_text(cx)?; - - let mut has_comment = false; - let mut empty_lines = Vec::new(); - - for (token, source, inner_span) in tokenize_with_text(&gap_snippet) { - match token { - TokenKind::BlockComment { - doc_style: None, - terminated: true, - } - | TokenKind::LineComment { doc_style: None } => has_comment = true, - TokenKind::Whitespace => { - let newlines = source.bytes().positions(|b| b == b'\n'); - empty_lines.extend( - newlines - .tuple_windows() - .map(|(a, b)| InnerSpan::new(inner_span.start + a + 1, inner_span.start + b)) - .map(|inner_span| gap_span.from_inner(inner_span)), - ); - }, - // Ignore cfg_attr'd out attributes as they may contain empty lines, could also be from macro - // shenanigans - _ => return None, - } - } - - (!empty_lines.is_empty()).then_some(Self { - empty_lines, - has_comment, - next_stop, - prev_stop, - prev_chunk, - }) - } - - fn contiguous_empty_lines(&self) -> impl Iterator + '_ { - self.empty_lines - // The `+ BytePos(1)` means "next line", because each empty line span is "N:1-N:1". - .chunk_by(|a, b| a.hi() + BytePos(1) == b.lo()) - .map(|chunk| { - let first = chunk.first().expect("at least one empty line"); - let last = chunk.last().expect("at least one empty line"); - // The BytePos subtraction here is safe, as before an empty line, there must be at least one - // attribute/comment. The span needs to start at the end of the previous line. - first.with_lo(first.lo() - BytePos(1)).with_hi(last.hi()) - }) - } -} - -/// If the node the attributes/docs apply to is the first in the module/crate suggest converting -/// them to inner attributes/docs -fn suggest_inner(cx: &LateContext<'_>, diag: &mut Diag<'_, ()>, kind: StopKind, gaps: &[Gap<'_>]) { - let Some(owner) = cx.last_node_with_lint_attrs.as_owner() else { - return; - }; - let parent_desc = match cx.tcx.parent_hir_node(owner.into()) { - Node::Item(item) - if let ItemKind::Mod(parent_mod) = item.kind - && let [first, ..] = parent_mod.item_ids - && first.owner_id == owner => - { - "parent module" - }, - Node::Crate(crate_mod) - if let Some(first) = crate_mod - .item_ids - .iter() - .map(|&id| cx.tcx.hir().item(id)) - // skip prelude imports - .find(|item| !matches!(item.span.ctxt().outer_expn_data().kind, ExpnKind::AstPass(_))) - && first.owner_id == owner => - { - "crate" - }, - _ => return, - }; - - diag.multipart_suggestion_verbose( - match kind { - StopKind::Attr => format!("if the attribute should apply to the {parent_desc} use an inner attribute"), - StopKind::Doc(_) => format!("if the comment should document the {parent_desc} use an inner doc comment"), - }, - gaps.iter() - .flat_map(|gap| gap.prev_chunk) - .map(Stop::convert_to_inner) - .collect(), - Applicability::MaybeIncorrect, - ); -} - -fn check_gaps(cx: &LateContext<'_>, gaps: &[Gap<'_>]) -> bool { - let Some(first_gap) = gaps.first() else { - return false; - }; - let empty_lines = || gaps.iter().flat_map(|gap| gap.empty_lines.iter().copied()); - let contiguous_empty_lines = || gaps.iter().flat_map(Gap::contiguous_empty_lines); - let mut has_comment = false; - let mut has_attr = false; - for gap in gaps { - has_comment |= gap.has_comment; - if !has_attr { - has_attr = gap.prev_chunk.iter().any(|stop| stop.kind == StopKind::Attr); - } - } - let kind = first_gap.prev_stop.kind; - let (lint, kind_desc) = match kind { - StopKind::Attr => (EMPTY_LINE_AFTER_OUTER_ATTR, "outer attribute"), - StopKind::Doc(_) => (EMPTY_LINE_AFTER_DOC_COMMENTS, "doc comment"), - }; - let (lines, are, them) = if empty_lines().nth(1).is_some() { - ("lines", "are", "them") - } else { - ("line", "is", "it") - }; - span_lint_and_then( - cx, - lint, - first_gap.prev_stop.span.to(empty_lines().last().unwrap()), - format!("empty {lines} after {kind_desc}"), - |diag| { - if let Some(owner) = cx.last_node_with_lint_attrs.as_owner() { - let def_id = owner.to_def_id(); - let def_descr = cx.tcx.def_descr(def_id); - diag.span_label( - cx.tcx.def_span(def_id), - match kind { - StopKind::Attr => format!("the attribute applies to this {def_descr}"), - StopKind::Doc(_) => format!("the comment documents this {def_descr}"), - }, - ); - } - - diag.multipart_suggestion_with_style( - format!("if the empty {lines} {are} unintentional remove {them}"), - contiguous_empty_lines() - .map(|empty_lines| (empty_lines, String::new())) - .collect(), - Applicability::MaybeIncorrect, - SuggestionStyle::HideCodeAlways, - ); - - if has_comment && kind.is_doc() { - // Likely doc comments that applied to some now commented out code - // - // /// Old docs for Foo - // // struct Foo; - - let mut suggestions = Vec::new(); - for stop in gaps.iter().flat_map(|gap| gap.prev_chunk) { - stop.comment_out(cx, &mut suggestions); - } - let name = match cx.tcx.hir().opt_name(cx.last_node_with_lint_attrs) { - Some(name) => format!("`{name}`"), - None => "this".into(), - }; - diag.multipart_suggestion_verbose( - format!("if the doc comment should not document {name} comment it out"), - suggestions, - Applicability::MaybeIncorrect, - ); - } else { - suggest_inner(cx, diag, kind, gaps); - } - - if kind == StopKind::Doc(CommentKind::Line) - && gaps - .iter() - .all(|gap| !gap.has_comment && gap.next_stop.kind == StopKind::Doc(CommentKind::Line)) - { - // Commentless empty gaps between line doc comments, possibly intended to be part of the markdown - - let indent = snippet_indent(cx, first_gap.prev_stop.span).unwrap_or_default(); - diag.multipart_suggestion_verbose( - format!("if the documentation should include the empty {lines} include {them} in the comment"), - empty_lines() - .map(|empty_line| (empty_line, format!("{indent}///"))) - .collect(), - Applicability::MaybeIncorrect, - ); - } - }, - ); - kind.is_doc() -} - -/// Returns `true` if [`EMPTY_LINE_AFTER_DOC_COMMENTS`] triggered, used to skip other doc comment -/// lints where they would be confusing -/// -/// [`EMPTY_LINE_AFTER_OUTER_ATTR`] is also here to share an implementation but does not return -/// `true` if it triggers -pub(super) fn check(cx: &LateContext<'_>, attrs: &[Attribute]) -> bool { - let mut outer = attrs - .iter() - .filter(|attr| attr.style == AttrStyle::Outer && !attr.span.from_expansion()) - .map(|attr| Stop::from_attr(cx, attr)) - .collect::>>() - .unwrap_or_default(); - - if outer.is_empty() { - return false; - } - - // Push a fake attribute Stop for the item itself so we check for gaps between the last outer - // attr/doc comment and the item they apply to - let span = cx.tcx.hir().span(cx.last_node_with_lint_attrs); - if !span.from_expansion() - && let Ok(line) = cx.tcx.sess.source_map().lookup_line(span.lo()) - { - outer.push(Stop { - span, - kind: StopKind::Attr, - first: line.line, - // last doesn't need to be accurate here, we don't compare it with anything - last: line.line, - }); - } - - let mut gaps = Vec::new(); - let mut last = 0; - for pos in outer - .array_windows() - .positions(|[a, b]| b.first.saturating_sub(a.last) > 1) - { - // we want to be after the first stop in the window - let pos = pos + 1; - if let Some(gap) = Gap::new(cx, &outer[last..pos], &outer[pos..]) { - last = pos; - gaps.push(gap); - } - } - - check_gaps(cx, &gaps) -} diff --git a/clippy_lints/src/doc/missing_headers.rs b/clippy_lints/src/doc/missing_headers.rs index 8e2af6bf14a6..d1ffbb6ffe25 100644 --- a/clippy_lints/src/doc/missing_headers.rs +++ b/clippy_lints/src/doc/missing_headers.rs @@ -68,7 +68,7 @@ pub fn check( } else if let Some(body_id) = body_id && let Some(future) = cx.tcx.lang_items().future_trait() && let typeck = cx.tcx.typeck_body(body_id) - && let body = cx.tcx.hir().body(body_id) + && let body = cx.tcx.hir_body(body_id) && let ret_ty = typeck.expr_ty(body.value) && implements_trait_with_env( cx.tcx, diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index b5fb492b96c8..bc3e78c7a2c6 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -33,7 +33,6 @@ use rustc_span::{Span, sym}; use std::ops::Range; use url::Url; -mod empty_line_after; mod include_in_doc_without_cfg; mod link_with_quotes; mod markdown; @@ -513,82 +512,6 @@ declare_clippy_lint! { "ensure the first documentation paragraph is short" } -declare_clippy_lint! { - /// ### What it does - /// Checks for empty lines after outer attributes - /// - /// ### Why is this bad? - /// The attribute may have meant to be an inner attribute (`#![attr]`). If - /// it was meant to be an outer attribute (`#[attr]`) then the empty line - /// should be removed - /// - /// ### Example - /// ```no_run - /// #[allow(dead_code)] - /// - /// fn not_quite_good_code() {} - /// ``` - /// - /// Use instead: - /// ```no_run - /// // Good (as inner attribute) - /// #![allow(dead_code)] - /// - /// fn this_is_fine() {} - /// - /// // or - /// - /// // Good (as outer attribute) - /// #[allow(dead_code)] - /// fn this_is_fine_too() {} - /// ``` - #[clippy::version = "pre 1.29.0"] - pub EMPTY_LINE_AFTER_OUTER_ATTR, - suspicious, - "empty line after outer attribute" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for empty lines after doc comments. - /// - /// ### Why is this bad? - /// The doc comment may have meant to be an inner doc comment, regular - /// comment or applied to some old code that is now commented out. If it was - /// intended to be a doc comment, then the empty line should be removed. - /// - /// ### Example - /// ```no_run - /// /// Some doc comment with a blank line after it. - /// - /// fn f() {} - /// - /// /// Docs for `old_code` - /// // fn old_code() {} - /// - /// fn new_code() {} - /// ``` - /// - /// Use instead: - /// ```no_run - /// //! Convert it to an inner doc comment - /// - /// // Or a regular comment - /// - /// /// Or remove the empty line - /// fn f() {} - /// - /// // /// Docs for `old_code` - /// // fn old_code() {} - /// - /// fn new_code() {} - /// ``` - #[clippy::version = "1.70.0"] - pub EMPTY_LINE_AFTER_DOC_COMMENTS, - suspicious, - "empty line after doc comments" -} - declare_clippy_lint! { /// ### What it does /// Checks if included files in doc comments are included only for `cfg(doc)`. @@ -673,8 +596,6 @@ impl_lint_pass!(Documentation => [ EMPTY_DOCS, DOC_LAZY_CONTINUATION, DOC_OVERINDENTED_LIST_ITEMS, - EMPTY_LINE_AFTER_OUTER_ATTR, - EMPTY_LINE_AFTER_DOC_COMMENTS, TOO_LONG_FIRST_DOC_PARAGRAPH, DOC_INCLUDE_WITHOUT_CFG, ]); @@ -699,7 +620,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { if !(is_entrypoint_fn(cx, item.owner_id.to_def_id()) || item.span.in_external_macro(cx.tcx.sess.source_map())) { - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let panic_info = FindPanicUnwrap::find_span(cx, cx.tcx.typeck(item.owner_id), body.value); missing_headers::check( @@ -751,7 +672,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { && !impl_item.span.in_external_macro(cx.tcx.sess.source_map()) && !is_trait_impl_item(cx, impl_item.hir_id()) { - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let panic_span = FindPanicUnwrap::find_span(cx, cx.tcx.typeck(impl_item.owner_id), body.value); missing_headers::check( @@ -807,7 +728,7 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ } include_in_doc_without_cfg::check(cx, attrs); - if suspicious_doc_comments::check(cx, attrs) || empty_line_after::check(cx, attrs) || is_doc_hidden(attrs) { + if suspicious_doc_comments::check(cx, attrs) || is_doc_hidden(attrs) { return None; } @@ -1256,8 +1177,8 @@ impl<'tcx> Visitor<'tcx> for FindPanicUnwrap<'_, 'tcx> { // Panics in const blocks will cause compilation to fail. fn visit_anon_const(&mut self, _: &'tcx AnonConst) {} - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index 9ba2723157ad..3008082c2329 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -1,10 +1,10 @@ use std::ops::Range; +use std::sync::Arc; use std::{io, thread}; use crate::doc::{NEEDLESS_DOCTEST_MAIN, TEST_ATTR_IN_DOCTEST}; use clippy_utils::diagnostics::span_lint; use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind}; -use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::HumanEmitter; use rustc_errors::{Diag, DiagCtxt}; use rustc_lint::LateContext; @@ -46,8 +46,8 @@ pub fn check( rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false); let emitter = HumanEmitter::new(Box::new(io::sink()), fallback_bundle); let dcx = DiagCtxt::new(Box::new(emitter)).disable_warnings(); - #[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_dcx - let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); + #[expect(clippy::arc_with_non_send_sync)] // `Arc` is expected by with_dcx + let sm = Arc::new(SourceMap::new(FilePathMapping::empty())); let psess = ParseSess::with_dcx(dcx, sm); let mut parser = match new_parser_from_source_str(&psess, filename, code) { diff --git a/clippy_lints/src/empty_drop.rs b/clippy_lints/src/empty_drop.rs index 10a84b1b2ff2..d557a36c7ac2 100644 --- a/clippy_lints/src/empty_drop.rs +++ b/clippy_lints/src/empty_drop.rs @@ -44,7 +44,7 @@ impl LateLintPass<'_> for EmptyDrop { && let impl_item_hir = child.id.hir_id() && let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir) && let ImplItemKind::Fn(_, b) = &impl_item.kind - && let Body { value: func_expr, .. } = cx.tcx.hir().body(*b) + && let Body { value: func_expr, .. } = cx.tcx.hir_body(*b) && let func_expr = peel_blocks(func_expr) && let ExprKind::Block(block, _) = func_expr.kind && block.stmts.is_empty() diff --git a/clippy_lints/src/empty_line_after.rs b/clippy_lints/src/empty_line_after.rs new file mode 100644 index 000000000000..80c2b03c41cf --- /dev/null +++ b/clippy_lints/src/empty_line_after.rs @@ -0,0 +1,495 @@ +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::source::{SpanRangeExt, snippet_indent}; +use clippy_utils::tokenize_with_text; +use itertools::Itertools; +use rustc_ast::token::CommentKind; +use rustc_ast::{AssocItemKind, AttrKind, AttrStyle, Attribute, Crate, Item, ItemKind, ModKind, NodeId}; +use rustc_errors::{Applicability, Diag, SuggestionStyle}; +use rustc_lexer::TokenKind; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_session::impl_lint_pass; +use rustc_span::symbol::kw; +use rustc_span::{BytePos, ExpnKind, Ident, InnerSpan, Span, SpanData, Symbol}; + +declare_clippy_lint! { + /// ### What it does + /// Checks for empty lines after outer attributes + /// + /// ### Why is this bad? + /// The attribute may have meant to be an inner attribute (`#![attr]`). If + /// it was meant to be an outer attribute (`#[attr]`) then the empty line + /// should be removed + /// + /// ### Example + /// ```no_run + /// #[allow(dead_code)] + /// + /// fn not_quite_good_code() {} + /// ``` + /// + /// Use instead: + /// ```no_run + /// // Good (as inner attribute) + /// #![allow(dead_code)] + /// + /// fn this_is_fine() {} + /// + /// // or + /// + /// // Good (as outer attribute) + /// #[allow(dead_code)] + /// fn this_is_fine_too() {} + /// ``` + #[clippy::version = "pre 1.29.0"] + pub EMPTY_LINE_AFTER_OUTER_ATTR, + suspicious, + "empty line after outer attribute" +} + +declare_clippy_lint! { + /// ### What it does + /// Checks for empty lines after doc comments. + /// + /// ### Why is this bad? + /// The doc comment may have meant to be an inner doc comment, regular + /// comment or applied to some old code that is now commented out. If it was + /// intended to be a doc comment, then the empty line should be removed. + /// + /// ### Example + /// ```no_run + /// /// Some doc comment with a blank line after it. + /// + /// fn f() {} + /// + /// /// Docs for `old_code` + /// // fn old_code() {} + /// + /// fn new_code() {} + /// ``` + /// + /// Use instead: + /// ```no_run + /// //! Convert it to an inner doc comment + /// + /// // Or a regular comment + /// + /// /// Or remove the empty line + /// fn f() {} + /// + /// // /// Docs for `old_code` + /// // fn old_code() {} + /// + /// fn new_code() {} + /// ``` + #[clippy::version = "1.70.0"] + pub EMPTY_LINE_AFTER_DOC_COMMENTS, + suspicious, + "empty line after doc comments" +} + +#[derive(Debug)] +struct ItemInfo { + kind: &'static str, + name: Symbol, + span: Span, + mod_items: Option, +} + +pub struct EmptyLineAfter { + items: Vec, +} + +impl_lint_pass!(EmptyLineAfter => [ + EMPTY_LINE_AFTER_OUTER_ATTR, + EMPTY_LINE_AFTER_DOC_COMMENTS, +]); + +impl EmptyLineAfter { + pub fn new() -> Self { + Self { items: Vec::new() } + } +} + +#[derive(Debug, PartialEq, Clone, Copy)] +enum StopKind { + Attr, + Doc(CommentKind), +} + +impl StopKind { + fn is_doc(self) -> bool { + matches!(self, StopKind::Doc(_)) + } +} + +#[derive(Debug)] +struct Stop { + span: Span, + kind: StopKind, + first: usize, + last: usize, +} + +impl Stop { + fn convert_to_inner(&self) -> (Span, String) { + let inner = match self.kind { + // #![...] + StopKind::Attr => InnerSpan::new(1, 1), + // /// or /** + // ^ ^ + StopKind::Doc(_) => InnerSpan::new(2, 3), + }; + (self.span.from_inner(inner), "!".into()) + } + + fn comment_out(&self, cx: &EarlyContext<'_>, suggestions: &mut Vec<(Span, String)>) { + match self.kind { + StopKind::Attr => { + if cx.sess().source_map().is_multiline(self.span) { + suggestions.extend([ + (self.span.shrink_to_lo(), "/* ".into()), + (self.span.shrink_to_hi(), " */".into()), + ]); + } else { + suggestions.push((self.span.shrink_to_lo(), "// ".into())); + } + }, + StopKind::Doc(CommentKind::Line) => suggestions.push((self.span.shrink_to_lo(), "// ".into())), + StopKind::Doc(CommentKind::Block) => { + // /** outer */ /*! inner */ + // ^ ^ + let asterisk = self.span.from_inner(InnerSpan::new(1, 2)); + suggestions.push((asterisk, String::new())); + }, + } + } + + fn from_attr(cx: &EarlyContext<'_>, attr: &Attribute) -> Option { + let SpanData { lo, hi, .. } = attr.span.data(); + let file = cx.sess().source_map().lookup_source_file(lo); + + Some(Self { + span: attr.span, + kind: match attr.kind { + AttrKind::Normal(_) => StopKind::Attr, + AttrKind::DocComment(comment_kind, _) => StopKind::Doc(comment_kind), + }, + first: file.lookup_line(file.relative_position(lo))?, + last: file.lookup_line(file.relative_position(hi))?, + }) + } +} + +/// Represents a set of attrs/doc comments separated by 1 or more empty lines +/// +/// ```ignore +/// /// chunk 1 docs +/// // not an empty line so also part of chunk 1 +/// #[chunk_1_attrs] // <-- prev_stop +/// +/// /* gap */ +/// +/// /// chunk 2 docs // <-- next_stop +/// #[chunk_2_attrs] +/// ``` +struct Gap<'a> { + /// The span of individual empty lines including the newline at the end of the line + empty_lines: Vec, + has_comment: bool, + next_stop: &'a Stop, + prev_stop: &'a Stop, + /// The chunk that includes [`prev_stop`](Self::prev_stop) + prev_chunk: &'a [Stop], +} + +impl<'a> Gap<'a> { + fn new(cx: &EarlyContext<'_>, prev_chunk: &'a [Stop], next_chunk: &'a [Stop]) -> Option { + let prev_stop = prev_chunk.last()?; + let next_stop = next_chunk.first()?; + let gap_span = prev_stop.span.between(next_stop.span); + let gap_snippet = gap_span.get_source_text(cx)?; + + let mut has_comment = false; + let mut empty_lines = Vec::new(); + + for (token, source, inner_span) in tokenize_with_text(&gap_snippet) { + match token { + TokenKind::BlockComment { + doc_style: None, + terminated: true, + } + | TokenKind::LineComment { doc_style: None } => has_comment = true, + TokenKind::Whitespace => { + let newlines = source.bytes().positions(|b| b == b'\n'); + empty_lines.extend( + newlines + .tuple_windows() + .map(|(a, b)| InnerSpan::new(inner_span.start + a + 1, inner_span.start + b)) + .map(|inner_span| gap_span.from_inner(inner_span)), + ); + }, + // Ignore cfg_attr'd out attributes as they may contain empty lines, could also be from macro + // shenanigans + _ => return None, + } + } + + (!empty_lines.is_empty()).then_some(Self { + empty_lines, + has_comment, + next_stop, + prev_stop, + prev_chunk, + }) + } + + fn contiguous_empty_lines(&self) -> impl Iterator + '_ { + self.empty_lines + // The `+ BytePos(1)` means "next line", because each empty line span is "N:1-N:1". + .chunk_by(|a, b| a.hi() + BytePos(1) == b.lo()) + .map(|chunk| { + let first = chunk.first().expect("at least one empty line"); + let last = chunk.last().expect("at least one empty line"); + // The BytePos subtraction here is safe, as before an empty line, there must be at least one + // attribute/comment. The span needs to start at the end of the previous line. + first.with_lo(first.lo() - BytePos(1)).with_hi(last.hi()) + }) + } +} + +impl EmptyLineAfter { + fn check_gaps(&self, cx: &EarlyContext<'_>, gaps: &[Gap<'_>], id: NodeId) { + let Some(first_gap) = gaps.first() else { + return; + }; + let empty_lines = || gaps.iter().flat_map(|gap| gap.empty_lines.iter().copied()); + let contiguous_empty_lines = || gaps.iter().flat_map(Gap::contiguous_empty_lines); + let mut has_comment = false; + let mut has_attr = false; + for gap in gaps { + has_comment |= gap.has_comment; + if !has_attr { + has_attr = gap.prev_chunk.iter().any(|stop| stop.kind == StopKind::Attr); + } + } + let kind = first_gap.prev_stop.kind; + let (lint, kind_desc) = match kind { + StopKind::Attr => (EMPTY_LINE_AFTER_OUTER_ATTR, "outer attribute"), + StopKind::Doc(_) => (EMPTY_LINE_AFTER_DOC_COMMENTS, "doc comment"), + }; + let (lines, are, them) = if empty_lines().nth(1).is_some() { + ("lines", "are", "them") + } else { + ("line", "is", "it") + }; + span_lint_and_then( + cx, + lint, + first_gap.prev_stop.span.to(empty_lines().last().unwrap()), + format!("empty {lines} after {kind_desc}"), + |diag| { + let info = self.items.last().unwrap(); + diag.span_label( + info.span, + match kind { + StopKind::Attr => format!("the attribute applies to this {}", info.kind), + StopKind::Doc(_) => format!("the comment documents this {}", info.kind), + }, + ); + + diag.multipart_suggestion_with_style( + format!("if the empty {lines} {are} unintentional, remove {them}"), + contiguous_empty_lines() + .map(|empty_lines| (empty_lines, String::new())) + .collect(), + Applicability::MaybeIncorrect, + SuggestionStyle::HideCodeAlways, + ); + + if has_comment && kind.is_doc() { + // Likely doc comments that applied to some now commented out code + // + // /// Old docs for Foo + // // struct Foo; + + let mut suggestions = Vec::new(); + for stop in gaps.iter().flat_map(|gap| gap.prev_chunk) { + stop.comment_out(cx, &mut suggestions); + } + diag.multipart_suggestion_verbose( + format!("if the doc comment should not document `{}` comment it out", info.name), + suggestions, + Applicability::MaybeIncorrect, + ); + } else { + self.suggest_inner(diag, kind, gaps, id); + } + + if kind == StopKind::Doc(CommentKind::Line) + && gaps + .iter() + .all(|gap| !gap.has_comment && gap.next_stop.kind == StopKind::Doc(CommentKind::Line)) + { + // Commentless empty gaps between line doc comments, possibly intended to be part of the markdown + + let indent = snippet_indent(cx, first_gap.prev_stop.span).unwrap_or_default(); + diag.multipart_suggestion_verbose( + format!("if the documentation should include the empty {lines} include {them} in the comment"), + empty_lines() + .map(|empty_line| (empty_line, format!("{indent}///"))) + .collect(), + Applicability::MaybeIncorrect, + ); + } + }, + ); + } + + /// If the node the attributes/docs apply to is the first in the module/crate suggest converting + /// them to inner attributes/docs + fn suggest_inner(&self, diag: &mut Diag<'_, ()>, kind: StopKind, gaps: &[Gap<'_>], id: NodeId) { + if let Some(parent) = self.items.iter().rev().nth(1) + && (parent.kind == "module" || parent.kind == "crate") + && parent.mod_items == Some(id) + { + let desc = if parent.kind == "module" { + "parent module" + } else { + parent.kind + }; + diag.multipart_suggestion_verbose( + match kind { + StopKind::Attr => format!("if the attribute should apply to the {desc} use an inner attribute"), + StopKind::Doc(_) => format!("if the comment should document the {desc} use an inner doc comment"), + }, + gaps.iter() + .flat_map(|gap| gap.prev_chunk) + .map(Stop::convert_to_inner) + .collect(), + Applicability::MaybeIncorrect, + ); + } + } + + fn check_item_kind( + &mut self, + cx: &EarlyContext<'_>, + kind: &ItemKind, + ident: &Ident, + span: Span, + attrs: &[Attribute], + id: NodeId, + ) { + self.items.push(ItemInfo { + kind: kind.descr(), + name: ident.name, + span: if span.contains(ident.span) { + span.with_hi(ident.span.hi()) + } else { + span.with_hi(span.lo()) + }, + mod_items: match kind { + ItemKind::Mod(_, ModKind::Loaded(items, _, _, _)) => items + .iter() + .filter(|i| !matches!(i.span.ctxt().outer_expn_data().kind, ExpnKind::AstPass(_))) + .map(|i| i.id) + .next(), + _ => None, + }, + }); + + let mut outer = attrs + .iter() + .filter(|attr| attr.style == AttrStyle::Outer && !attr.span.from_expansion()) + .map(|attr| Stop::from_attr(cx, attr)) + .collect::>>() + .unwrap_or_default(); + + if outer.is_empty() { + return; + } + + // Push a fake attribute Stop for the item itself so we check for gaps between the last outer + // attr/doc comment and the item they apply to + let span = self.items.last().unwrap().span; + if !span.from_expansion() + && let Ok(line) = cx.sess().source_map().lookup_line(span.lo()) + { + outer.push(Stop { + span, + kind: StopKind::Attr, + first: line.line, + // last doesn't need to be accurate here, we don't compare it with anything + last: line.line, + }); + } + + let mut gaps = Vec::new(); + let mut last = 0; + for pos in outer + .array_windows() + .positions(|[a, b]| b.first.saturating_sub(a.last) > 1) + { + // we want to be after the first stop in the window + let pos = pos + 1; + if let Some(gap) = Gap::new(cx, &outer[last..pos], &outer[pos..]) { + last = pos; + gaps.push(gap); + } + } + + self.check_gaps(cx, &gaps, id); + } +} + +impl EarlyLintPass for EmptyLineAfter { + fn check_crate(&mut self, _: &EarlyContext<'_>, krate: &Crate) { + self.items.push(ItemInfo { + kind: "crate", + name: kw::Crate, + span: krate.spans.inner_span.with_hi(krate.spans.inner_span.lo()), + mod_items: krate + .items + .iter() + .filter(|i| !matches!(i.span.ctxt().outer_expn_data().kind, ExpnKind::AstPass(_))) + .map(|i| i.id) + .next(), + }); + } + + fn check_item_post(&mut self, _: &EarlyContext<'_>, _: &Item) { + self.items.pop(); + } + fn check_impl_item_post(&mut self, _: &EarlyContext<'_>, _: &Item) { + self.items.pop(); + } + fn check_trait_item_post(&mut self, _: &EarlyContext<'_>, _: &Item) { + self.items.pop(); + } + + fn check_impl_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { + self.check_item_kind( + cx, + &item.kind.clone().into(), + &item.ident, + item.span, + &item.attrs, + item.id, + ); + } + + fn check_trait_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { + self.check_item_kind( + cx, + &item.kind.clone().into(), + &item.ident, + item.span, + &item.attrs, + item.id, + ); + } + + fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { + self.check_item_kind(cx, &item.kind, &item.ident, item.span, &item.attrs, item.id); + } +} diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index a090a987d4fc..2e1f8ac615a2 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -41,7 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant { if let ItemKind::Enum(def, _) = &item.kind { for var in def.variants { if let Some(anon_const) = &var.disr_expr { - let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body); + let def_id = cx.tcx.hir_body_owner_def_id(anon_const.body); let mut ty = cx.tcx.type_of(def_id.to_def_id()).instantiate_identity(); let constant = cx .tcx diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index a89f0d9c4327..eda8a979968f 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -1,5 +1,6 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_hir; +use rustc_abi::ExternAbi; use rustc_hir::{AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind, intravisit}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_lint::{LateContext, LateLintPass}; @@ -10,7 +11,6 @@ use rustc_session::impl_lint_pass; use rustc_span::Span; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; -use rustc_target::spec::abi::Abi; pub struct BoxedLocal { too_large_for_stack: u64, @@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { fn_def_id: LocalDefId, ) { if let Some(header) = fn_kind.header() { - if header.abi != Abi::Rust { + if header.abi != ExternAbi::Rust { return; } } diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index f90bf9157aad..645f93068496 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -6,6 +6,7 @@ use clippy_utils::usage::{local_used_after_expr, local_used_in}; use clippy_utils::{ get_path_from_caller_to_method_type, is_adjusted, is_no_std_crate, path_to_local, path_to_local_id, }; +use rustc_abi::ExternAbi; use rustc_errors::Applicability; use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, GenericArgs, Param, PatKind, QPath, Safety, TyKind}; use rustc_infer::infer::TyCtxtInferExt; @@ -15,7 +16,6 @@ use rustc_middle::ty::{ }; use rustc_session::declare_lint_pass; use rustc_span::symbol::sym; -use rustc_target::spec::abi::Abi; use rustc_trait_selection::error_reporting::InferCtxtErrorExt as _; declare_clippy_lint! { @@ -97,7 +97,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx && matches!(c.fn_decl.output, FnRetTy::DefaultReturn(_)) && !expr.span.from_expansion() { - cx.tcx.hir().body(c.body) + cx.tcx.hir_body(c.body) } else { return; }; @@ -172,7 +172,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx && let output = typeck.expr_ty(body.value) && let ty::Tuple(tys) = *subs.type_at(1).kind() { - cx.tcx.mk_fn_sig(tys, output, false, Safety::Safe, Abi::Rust) + cx.tcx.mk_fn_sig(tys, output, false, Safety::Safe, ExternAbi::Rust) } else { return; } diff --git a/clippy_lints/src/excessive_bools.rs b/clippy_lints/src/excessive_bools.rs index 0011da03dda7..54a1ac21c85c 100644 --- a/clippy_lints/src/excessive_bools.rs +++ b/clippy_lints/src/excessive_bools.rs @@ -1,13 +1,13 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::{get_parent_as_impl, has_repr_attr, is_bool}; +use rustc_abi::ExternAbi; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, Item, ItemKind, TraitFn, TraitItem, TraitItemKind, Ty}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; use rustc_span::Span; use rustc_span::def_id::LocalDefId; -use rustc_target::spec::abi::Abi; declare_clippy_lint! { /// ### What it does @@ -145,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for ExcessiveBools { fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx TraitItem<'tcx>) { // functions with a body are already checked by `check_fn` if let TraitItemKind::Fn(fn_sig, TraitFn::Required(_)) = &trait_item.kind - && fn_sig.header.abi == Abi::Rust + && fn_sig.header.abi == ExternAbi::Rust && fn_sig.decl.inputs.len() as u64 > self.max_fn_params_bools { check_fn_decl(cx, fn_sig.decl, fn_sig.span, self.max_fn_params_bools); @@ -162,7 +162,7 @@ impl<'tcx> LateLintPass<'tcx> for ExcessiveBools { def_id: LocalDefId, ) { if let Some(fn_header) = fn_kind.header() - && fn_header.abi == Abi::Rust + && fn_header.abi == ExternAbi::Rust && fn_decl.inputs.len() as u64 > self.max_fn_params_bools && get_parent_as_impl(cx.tcx, cx.tcx.local_def_id_to_hir_id(def_id)) .is_none_or(|impl_item| impl_item.of_trait.is_none()) diff --git a/clippy_lints/src/extra_unused_type_parameters.rs b/clippy_lints/src/extra_unused_type_parameters.rs index 5d93aceb33ff..6a217b6182ce 100644 --- a/clippy_lints/src/extra_unused_type_parameters.rs +++ b/clippy_lints/src/extra_unused_type_parameters.rs @@ -241,13 +241,13 @@ impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } fn is_empty_body(cx: &LateContext<'_>, body: BodyId) -> bool { - matches!(cx.tcx.hir().body(body).value.kind, ExprKind::Block(b, _) if b.stmts.is_empty() && b.expr.is_none()) + matches!(cx.tcx.hir_body(body).value.kind, ExprKind::Block(b, _) if b.stmts.is_empty() && b.expr.is_none()) } impl<'tcx> LateLintPass<'tcx> for ExtraUnusedTypeParameters { diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index f822432cce63..f67d38d932b9 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -98,10 +98,10 @@ fn lint_impl_body(cx: &LateContext<'_>, impl_span: Span, impl_items: &[hir::Impl for impl_item in impl_items { if impl_item.ident.name == sym::from - && let ImplItemKind::Fn(_, body_id) = cx.tcx.hir().impl_item(impl_item.id).kind + && let ImplItemKind::Fn(_, body_id) = cx.tcx.hir_impl_item(impl_item.id).kind { // check the body for `begin_panic` or `unwrap` - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let mut fpu = FindPanicUnwrap { lcx: cx, typeck_results: cx.tcx.typeck(impl_item.id.owner_id.def_id), diff --git a/clippy_lints/src/format_impl.rs b/clippy_lints/src/format_impl.rs index 5619cb0ab1b0..ff75fcf2b417 100644 --- a/clippy_lints/src/format_impl.rs +++ b/clippy_lints/src/format_impl.rs @@ -262,7 +262,7 @@ fn is_format_trait_impl(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) -> Optio && let Some(name) = cx.tcx.get_diagnostic_name(did) && matches!(name, sym::Debug | sym::Display) { - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let formatter_name = body .params .get(1) diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 9a73d0c0993f..41bf6e81916a 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -134,8 +134,8 @@ impl<'tcx> Visitor<'tcx> for SelfFinder<'_, 'tcx> { type Result = ControlFlow<()>; type NestedFilter = OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_path(&mut self, path: &Path<'tcx>, _id: HirId) -> Self::Result { @@ -175,11 +175,11 @@ fn convert_to_from( // bad suggestion/fix. return None; } - let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id); + let impl_item = cx.tcx.hir_impl_item(impl_item_ref.id); let ImplItemKind::Fn(ref sig, body_id) = impl_item.kind else { return None; }; - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let [input] = body.params else { return None }; let PatKind::Binding(.., self_ident, None) = input.pat.kind else { return None; diff --git a/clippy_lints/src/functions/impl_trait_in_params.rs b/clippy_lints/src/functions/impl_trait_in_params.rs index 752dbc0db4db..cb83b1395d26 100644 --- a/clippy_lints/src/functions/impl_trait_in_params.rs +++ b/clippy_lints/src/functions/impl_trait_in_params.rs @@ -39,7 +39,7 @@ fn report(cx: &LateContext<'_>, param: &GenericParam<'_>, generics: &Generics<'_ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body: &'tcx Body<'_>, hir_id: HirId) { if let FnKind::ItemFn(_, generics, _) = kind - && cx.tcx.visibility(cx.tcx.hir().body_owner_def_id(body.id())).is_public() + && cx.tcx.visibility(cx.tcx.hir_body_owner_def_id(body.id())).is_public() && !is_in_test(cx.tcx, hir_id) { for param in generics.params { @@ -56,8 +56,8 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) { && let hir::ItemKind::Impl(impl_) = item.kind && let hir::Impl { of_trait, .. } = *impl_ && of_trait.is_none() - && let body = cx.tcx.hir().body(body_id) - && cx.tcx.visibility(cx.tcx.hir().body_owner_def_id(body.id())).is_public() + && let body = cx.tcx.hir_body(body_id) + && cx.tcx.visibility(cx.tcx.hir_body_owner_def_id(body.id())).is_public() && !is_in_test(cx.tcx, impl_item.hir_id()) { for param in impl_item.generics.params { diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index e480805cac2f..e6e3ea59a9f6 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -37,7 +37,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_> check_must_use_candidate( cx, sig.decl, - cx.tcx.hir().body(*body_id), + cx.tcx.hir_body(*body_id), item.span, item.owner_id, item.span.with_hi(sig.decl.output.span().hi()), @@ -59,7 +59,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp check_must_use_candidate( cx, sig.decl, - cx.tcx.hir().body(*body_id), + cx.tcx.hir_body(*body_id), item.span, item.owner_id, item.span.with_hi(sig.decl.output.span().hi()), @@ -79,7 +79,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr, attrs, sig); } else if let hir::TraitFn::Provided(eid) = *eid { - let body = cx.tcx.hir().body(eid); + let body = cx.tcx.hir_body(eid); if attr.is_none() && is_public && !is_proc_macro(attrs) { check_must_use_candidate( cx, diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 8a74951ef63e..906bbd006d46 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -30,7 +30,7 @@ pub(super) fn check_fn<'tcx>( pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind { - let body = cx.tcx.hir().body(eid); + let body = cx.tcx.hir_body(eid); check_raw_ptr(cx, sig.header.safety(), sig.decl, body, item.owner_id.def_id); } } diff --git a/clippy_lints/src/functions/renamed_function_params.rs b/clippy_lints/src/functions/renamed_function_params.rs index ac2e866e4ff7..5ad83f886e2e 100644 --- a/clippy_lints/src/functions/renamed_function_params.rs +++ b/clippy_lints/src/functions/renamed_function_params.rs @@ -22,7 +22,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, item: &ImplItem<'_>, ignored && let Some(did) = trait_item_def_id_of_impl(items, item.owner_id) && !is_from_ignored_trait(trait_ref, ignored_traits) { - let mut param_idents_iter = cx.tcx.hir().body_param_names(body_id); + let mut param_idents_iter = cx.tcx.hir_body_param_names(body_id); let mut default_param_idents_iter = cx.tcx.fn_arg_names(did).iter().copied(); let renames = RenamedFnArgs::new(&mut default_param_idents_iter, &mut param_idents_iter); diff --git a/clippy_lints/src/functions/too_many_arguments.rs b/clippy_lints/src/functions/too_many_arguments.rs index e72a2ad49d82..05dc47f6fe58 100644 --- a/clippy_lints/src/functions/too_many_arguments.rs +++ b/clippy_lints/src/functions/too_many_arguments.rs @@ -1,7 +1,7 @@ +use rustc_abi::ExternAbi; use rustc_hir::{self as hir, intravisit}; use rustc_lint::LateContext; use rustc_span::Span; -use rustc_target::spec::abi::Abi; use clippy_utils::diagnostics::span_lint; use clippy_utils::is_trait_impl_item; @@ -23,11 +23,19 @@ pub(super) fn check_fn( intravisit::FnKind::Method( _, &hir::FnSig { - header: hir::FnHeader { abi: Abi::Rust, .. }, + header: hir::FnHeader { + abi: ExternAbi::Rust, .. + }, .. }, ) - | intravisit::FnKind::ItemFn(_, _, hir::FnHeader { abi: Abi::Rust, .. }) => check_arg_number( + | intravisit::FnKind::ItemFn( + _, + _, + hir::FnHeader { + abi: ExternAbi::Rust, .. + }, + ) => check_arg_number( cx, decl, span.with_hi(decl.output.span().hi()), @@ -41,7 +49,7 @@ pub(super) fn check_fn( pub(super) fn check_trait_item(cx: &LateContext<'_>, item: &hir::TraitItem<'_>, too_many_arguments_threshold: u64) { if let hir::TraitItemKind::Fn(ref sig, _) = item.kind { // don't lint extern functions decls, it's not their fault - if sig.header.abi == Abi::Rust { + if sig.header.abi == ExternAbi::Rust { check_arg_number( cx, sig.decl, diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 47a5c19215b8..d2545e57652a 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -130,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { }); let mut ctr_vis = ImplicitHasherConstructorVisitor::new(cx, target); - for item in impl_.items.iter().map(|item| cx.tcx.hir().impl_item(item.id)) { + for item in impl_.items.iter().map(|item| cx.tcx.hir_impl_item(item.id)) { ctr_vis.visit_impl_item(item); } @@ -154,7 +154,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { body: body_id, .. } => { - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); for ty in sig.decl.inputs { let mut vis = ImplicitHasherTypeVisitor::new(cx); @@ -363,7 +363,7 @@ impl<'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'_, '_, 'tcx> { walk_expr(self, e); } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 15650c4f7329..deac51ab4c49 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -223,8 +223,8 @@ struct SliceIndexLintingVisitor<'a, 'tcx> { impl<'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'_, 'tcx> { type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index d3aade31f14f..3cb47d8ef919 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -159,7 +159,7 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { } if method.ident.name.as_str() == "flat_map" && args.len() == 1 { if let ExprKind::Closure(&Closure { body, .. }) = args[0].kind { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); return is_infinite(cx, body.value); } } diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 415b47adac5a..1d582fb0223e 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -1,11 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{implements_trait, is_type_lang_item}; use clippy_utils::{return_ty, trait_ref_of_method}; +use rustc_abi::ExternAbi; use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind, LangItem}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::sym; -use rustc_target::spec::abi::Abi; declare_clippy_lint! { /// ### What it does @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString { // #11201 && let header = signature.header && header.is_safe() - && header.abi == Abi::Rust + && header.abi == ExternAbi::Rust && impl_item.ident.name == sym::to_string && let decl = signature.decl && decl.implicit_self.has_implicit_self() diff --git a/clippy_lints/src/items_after_statements.rs b/clippy_lints/src/items_after_statements.rs index f5ad79a00279..021d43cefdda 100644 --- a/clippy_lints/src/items_after_statements.rs +++ b/clippy_lints/src/items_after_statements.rs @@ -59,7 +59,7 @@ impl LateLintPass<'_> for ItemsAfterStatements { .iter() .skip_while(|stmt| matches!(stmt.kind, StmtKind::Item(..))) .filter_map(|stmt| match stmt.kind { - StmtKind::Item(id) => Some(cx.tcx.hir().item(id)), + StmtKind::Item(id) => Some(cx.tcx.hir_item(id)), _ => None, }) // Ignore macros since they can only see previously defined locals. diff --git a/clippy_lints/src/items_after_test_module.rs b/clippy_lints/src/items_after_test_module.rs index 1ac549b74ac6..9df044f25eb7 100644 --- a/clippy_lints/src/items_after_test_module.rs +++ b/clippy_lints/src/items_after_test_module.rs @@ -58,7 +58,7 @@ fn cfg_test_module<'tcx>(cx: &LateContext<'tcx>, item: &Item<'tcx>) -> bool { impl LateLintPass<'_> for ItemsAfterTestModule { fn check_mod(&mut self, cx: &LateContext<'_>, module: &Mod<'_>, _: HirId) { - let mut items = module.item_ids.iter().map(|&id| cx.tcx.hir().item(id)); + let mut items = module.item_ids.iter().map(|&id| cx.tcx.hir_item(id)); let Some((mod_pos, test_mod)) = items.by_ref().enumerate().find(|(_, item)| cfg_test_module(cx, item)) else { return; @@ -91,7 +91,7 @@ impl LateLintPass<'_> for ItemsAfterTestModule { "items after a test module", |diag| { if let Some(prev) = mod_pos.checked_sub(1) - && let prev = cx.tcx.hir().item(module.item_ids[prev]) + && let prev = cx.tcx.hir_item(module.item_ids[prev]) && let items_span = last.span.with_lo(test_mod.span.hi()) && let Some(items) = items_span.get_source_text(cx) { diff --git a/clippy_lints/src/iter_without_into_iter.rs b/clippy_lints/src/iter_without_into_iter.rs index 238f66d66755..173232c511a5 100644 --- a/clippy_lints/src/iter_without_into_iter.rs +++ b/clippy_lints/src/iter_without_into_iter.rs @@ -142,7 +142,7 @@ impl LateLintPass<'_> for IterWithoutIntoIter { }) && let Some(iter_assoc_span) = imp.items.iter().find_map(|item| { if item.ident.name.as_str() == "IntoIter" { - Some(cx.tcx.hir().impl_item(item.id).expect_type().span) + Some(cx.tcx.hir_impl_item(item.id).expect_type().span) } else { None } diff --git a/clippy_lints/src/large_futures.rs b/clippy_lints/src/large_futures.rs index 593704f206a1..fd7965d564d5 100644 --- a/clippy_lints/src/large_futures.rs +++ b/clippy_lints/src/large_futures.rs @@ -2,11 +2,11 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::implements_trait; +use rustc_abi::Size; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, LangItem, MatchSource, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; -use rustc_target::abi::Size; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 26bea8d633a3..98ba52f12707 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -316,7 +316,7 @@ enum LenOutput { fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> { if let ty::Alias(_, alias_ty) = ty.kind() - && let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir().get_if_local(alias_ty.def_id) + && let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir_get_if_local(alias_ty.def_id) && let OpaqueTyOrigin::AsyncFn { .. } = opaque.origin && let [GenericBound::Trait(trait_ref)] = &opaque.bounds && let Some(segment) = trait_ref.trait_ref.path.segments.last() diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 5349b27de4a3..c9e9a444864b 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -1,4 +1,5 @@ #![feature(array_windows)] +#![feature(binary_heap_into_iter_sorted)] #![feature(box_patterns)] #![feature(macro_metavar_expr_concat)] #![feature(f128)] @@ -125,6 +126,7 @@ mod duplicate_mod; mod else_if_without_else; mod empty_drop; mod empty_enum; +mod empty_line_after; mod empty_with_brackets; mod endian_bytes; mod entry; @@ -973,6 +975,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(move |_| Box::new(unused_trait_names::UnusedTraitNames::new(conf))); store.register_late_pass(|_| Box::new(manual_ignore_case_cmp::ManualIgnoreCaseCmp)); store.register_late_pass(|_| Box::new(unnecessary_literal_bound::UnnecessaryLiteralBound)); + store.register_early_pass(|| Box::new(empty_line_after::EmptyLineAfter::new())); store.register_late_pass(move |_| Box::new(arbitrary_source_item_ordering::ArbitrarySourceItemOrdering::new(conf))); store.register_late_pass(|_| Box::new(unneeded_struct_pattern::UnneededStructPattern)); store.register_late_pass(|_| Box::::default()); diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 860c0584accf..f08812017b9c 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -19,8 +19,8 @@ use rustc_hir::{ WherePredicateKind, lang_items, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; use rustc_middle::hir::nested_filter as middle_nested_filter; +use rustc_middle::ty::TyCtxt; use rustc_session::impl_lint_pass; use rustc_span::Span; use rustc_span::def_id::LocalDefId; @@ -275,7 +275,7 @@ fn could_use_elision<'tcx>( } if let Some(body_id) = body { - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let first_ident = body.params.first().and_then(|param| param.pat.simple_ident()); if non_elidable_self_type(cx, func, first_ident, msrv) { @@ -582,7 +582,7 @@ impl<'tcx, F> Visitor<'tcx> for LifetimeChecker<'_, 'tcx, F> where F: NestedFilter<'tcx>, { - type Map = Map<'tcx>; + type MaybeTyCtxt = TyCtxt<'tcx>; type NestedFilter = F; // for lifetimes as parameters of generics @@ -628,8 +628,8 @@ where self.lifetime_elision_impossible = false; } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/lines_filter_map_ok.rs b/clippy_lints/src/lines_filter_map_ok.rs index 8c237191405a..08548f564009 100644 --- a/clippy_lints/src/lines_filter_map_ok.rs +++ b/clippy_lints/src/lines_filter_map_ok.rs @@ -119,7 +119,7 @@ fn should_lint(cx: &LateContext<'_>, args: &[Expr<'_>], method_str: &str) -> boo ExprKind::Closure(Closure { body, .. }) => { if let Body { params: [param], value, .. - } = cx.tcx.hir().body(*body) + } = cx.tcx.hir_body(*body) && let ExprKind::MethodCall(method, receiver, [], _) = value.kind && path_to_local_id(receiver, param.pat.hir_id) && let Some(method_did) = cx.typeck_results().type_dependent_def_id(value.hir_id) diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 2e6442156ef6..e98c3c9698ba 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -370,7 +370,7 @@ impl<'tcx> Visitor<'tcx> for VarVisitor<'_, 'tcx> { } }, ExprKind::Closure(&Closure { body, .. }) => { - let body = self.cx.tcx.hir().body(body); + let body = self.cx.tcx.hir_body(body); self.visit_expr(body.value); }, _ => walk_expr(self, expr), diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index 51fde5288ab9..a5185d38e7c3 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -240,8 +240,8 @@ impl<'tcx> Visitor<'tcx> for InitializeVisitor<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index b7e37c1a876f..6000ff7a3609 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -245,8 +245,8 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & impl<'tcx> Visitor<'tcx> for AfterLoopVisitor<'_, '_, 'tcx> { type NestedFilter = OnlyBodies; type Result = ControlFlow<()>; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, e: &'tcx Expr<'_>) -> Self::Result { @@ -288,8 +288,8 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & } impl<'tcx> Visitor<'tcx> for NestedLoopVisitor<'_, '_, 'tcx> { type NestedFilter = OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_local(&mut self, l: &'tcx LetStmt<'_>) { @@ -351,7 +351,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & loop_id: loop_expr.hir_id, after_loop: false, }; - v.visit_expr(cx.tcx.hir().body(cx.enclosing_body.unwrap()).value) + v.visit_expr(cx.tcx.hir_body(cx.enclosing_body.unwrap()).value) .is_break() } } diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index ba63f980316e..abd1ac954cda 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -169,7 +169,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) && let ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Block)) = kind { - return Some(cx.tcx.hir().body(body)); + return Some(cx.tcx.hir_body(body)); } None diff --git a/clippy_lints/src/manual_float_methods.rs b/clippy_lints/src/manual_float_methods.rs index 052e6502da92..2a5aa12d126c 100644 --- a/clippy_lints/src/manual_float_methods.rs +++ b/clippy_lints/src/manual_float_methods.rs @@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods { && exprs.iter_mut().partition_in_place(|i| path_to_local(i).is_some()) == 2 && !expr.span.in_external_macro(cx.sess().source_map()) && ( - is_not_const(cx.tcx, cx.tcx.hir().enclosing_body_owner(expr.hir_id).into()) + is_not_const(cx.tcx, cx.tcx.hir_enclosing_body_owner(expr.hir_id).into()) || self.msrv.meets(msrvs::CONST_FLOAT_CLASSIFY) ) && let [first, second, const_1, const_2] = exprs diff --git a/clippy_lints/src/manual_option_as_slice.rs b/clippy_lints/src/manual_option_as_slice.rs index 5c40c945c690..e4360518b66e 100644 --- a/clippy_lints/src/manual_option_as_slice.rs +++ b/clippy_lints/src/manual_option_as_slice.rs @@ -191,7 +191,7 @@ fn check_arms(cx: &LateContext<'_>, none_arm: &Arm<'_>, some_arm: &Arm<'_>) -> b fn returns_empty_slice(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { match expr.kind { ExprKind::Path(_) => clippy_utils::is_path_diagnostic_item(cx, expr, sym::default_fn), - ExprKind::Closure(cl) => is_empty_slice(cx, cx.tcx.hir().body(cl.body).value), + ExprKind::Closure(cl) => is_empty_slice(cx, cx.tcx.hir_body(cl.body).value), _ => false, } } diff --git a/clippy_lints/src/manual_retain.rs b/clippy_lints/src/manual_retain.rs index 708980ac503d..0a4e756096e9 100644 --- a/clippy_lints/src/manual_retain.rs +++ b/clippy_lints/src/manual_retain.rs @@ -92,7 +92,7 @@ fn check_into_iter( && SpanlessEq::new(cx).eq_expr(left_expr, struct_expr) && let hir::ExprKind::MethodCall(_, _, [closure_expr], _) = target_expr.kind && let hir::ExprKind::Closure(closure) = closure_expr.kind - && let filter_body = cx.tcx.hir().body(closure.body) + && let filter_body = cx.tcx.hir_body(closure.body) && let [filter_params] = filter_body.params { if match_map_type(cx, left_expr) { @@ -139,7 +139,7 @@ fn check_iter( && SpanlessEq::new(cx).eq_expr(left_expr, struct_expr) && let hir::ExprKind::MethodCall(_, _, [closure_expr], _) = filter_expr.kind && let hir::ExprKind::Closure(closure) = closure_expr.kind - && let filter_body = cx.tcx.hir().body(closure.body) + && let filter_body = cx.tcx.hir_body(closure.body) && let [filter_params] = filter_body.params { match filter_params.pat.kind { @@ -198,7 +198,7 @@ fn check_to_owned( && SpanlessEq::new(cx).eq_expr(left_expr, str_expr) && let hir::ExprKind::MethodCall(_, _, [closure_expr], _) = filter_expr.kind && let hir::ExprKind::Closure(closure) = closure_expr.kind - && let filter_body = cx.tcx.hir().body(closure.body) + && let filter_body = cx.tcx.hir_body(closure.body) && let [filter_params] = filter_body.params { if let hir::PatKind::Ref(pat, _) = filter_params.pat.kind { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 3221a04d2d03..56aead85e7c4 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -163,7 +163,7 @@ fn unit_closure<'tcx>( expr: &hir::Expr<'_>, ) -> Option<(&'tcx hir::Param<'tcx>, &'tcx hir::Expr<'tcx>)> { if let hir::ExprKind::Closure(&hir::Closure { fn_decl, body, .. }) = expr.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) && let body_expr = &body.value && fn_decl.inputs.len() == 1 && is_unit_expression(cx, body_expr) diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index 91a5de16e967..1e9b29f567f4 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -163,7 +163,7 @@ impl BindInsteadOfMap { match arg.kind { hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }) => { - let closure_body = cx.tcx.hir().body(body); + let closure_body = cx.tcx.hir_body(body); let closure_expr = peel_blocks(closure_body.value); if self.lint_closure_autofixable(cx, expr, recv, closure_expr, fn_decl_span) { diff --git a/clippy_lints/src/methods/bytecount.rs b/clippy_lints/src/methods/bytecount.rs index 687272e550bb..0498f317442a 100644 --- a/clippy_lints/src/methods/bytecount.rs +++ b/clippy_lints/src/methods/bytecount.rs @@ -18,7 +18,7 @@ pub(super) fn check<'tcx>( filter_arg: &'tcx Expr<'_>, ) { if let ExprKind::Closure(&Closure { body, .. }) = filter_arg.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) && let [param] = body.params && let PatKind::Binding(_, arg_id, _, _) = strip_pat_refs(param.pat).kind && let ExprKind::Binary(ref op, l, r) = body.value.kind diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index 15a14c61d2bc..ae300cd5fe56 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -21,7 +21,7 @@ fn is_method(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol) -> bool ExprKind::Path(QPath::Resolved(_, segments)) => segments.segments.last().unwrap().ident.name == method_name, ExprKind::MethodCall(segment, _, _, _) => segment.ident.name == method_name, ExprKind::Closure(Closure { body, .. }) => { - let body = cx.tcx.hir().body(*body); + let body = cx.tcx.hir_body(*body); let closure_expr = peel_blocks(body.value); match closure_expr.kind { ExprKind::MethodCall(PathSegment { ident, .. }, receiver, ..) => { @@ -403,7 +403,7 @@ fn is_find_or_filter<'a>( if is_trait_method(cx, map_recv, sym::Iterator) // filter(|x| ...is_some())... && let ExprKind::Closure(&Closure { body: filter_body_id, .. }) = filter_arg.kind - && let filter_body = cx.tcx.hir().body(filter_body_id) + && let filter_body = cx.tcx.hir_body(filter_body_id) && let [filter_param] = filter_body.params // optional ref pattern: `filter(|&x| ..)` && let (filter_pat, is_filter_param_ref) = if let PatKind::Ref(ref_pat, _) = filter_param.pat.kind { @@ -416,7 +416,7 @@ fn is_find_or_filter<'a>( && let Some(mut offending_expr) = OffendingFilterExpr::hir(cx, filter_body.value, filter_param_id) && let ExprKind::Closure(&Closure { body: map_body_id, .. }) = map_arg.kind - && let map_body = cx.tcx.hir().body(map_body_id) + && let map_body = cx.tcx.hir_body(map_body_id) && let [map_param] = map_body.params && let PatKind::Binding(_, map_param_id, map_param_ident, None) = map_param.pat.kind diff --git a/clippy_lints/src/methods/filter_map_bool_then.rs b/clippy_lints/src/methods/filter_map_bool_then.rs index d550c1454668..f7e116c5310e 100644 --- a/clippy_lints/src/methods/filter_map_bool_then.rs +++ b/clippy_lints/src/methods/filter_map_bool_then.rs @@ -14,7 +14,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: & if !expr.span.in_external_macro(cx.sess().source_map()) && is_trait_method(cx, expr, sym::Iterator) && let ExprKind::Closure(closure) = arg.kind - && let body = cx.tcx.hir().body(closure.body) + && let body = cx.tcx.hir_body(closure.body) && let value = peel_blocks(body.value) // Indexing should be fine as `filter_map` always has 1 input, we unfortunately need both // `inputs` and `params` here as we need both the type and the span @@ -31,7 +31,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: & && is_copy(cx, param_ty) && let ExprKind::MethodCall(_, recv, [then_arg], _) = value.kind && let ExprKind::Closure(then_closure) = then_arg.kind - && let then_body = peel_blocks(cx.tcx.hir().body(then_closure.body).value) + && let then_body = peel_blocks(cx.tcx.hir_body(then_closure.body).value) && let Some(def_id) = cx.typeck_results().type_dependent_def_id(value.hir_id) && cx.tcx.is_diagnostic_item(sym::bool_then, def_id) && !is_from_proc_macro(cx, expr) diff --git a/clippy_lints/src/methods/format_collect.rs b/clippy_lints/src/methods/format_collect.rs index 3e5162ef4580..1b28596d50da 100644 --- a/clippy_lints/src/methods/format_collect.rs +++ b/clippy_lints/src/methods/format_collect.rs @@ -19,7 +19,7 @@ fn peel_non_expn_blocks<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx> pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, map_arg: &Expr<'_>, map_span: Span) { if is_type_lang_item(cx, cx.typeck_results().expr_ty(expr), LangItem::String) && let ExprKind::Closure(closure) = map_arg.kind - && let body = cx.tcx.hir().body(closure.body) + && let body = cx.tcx.hir_body(closure.body) && let Some(value) = peel_non_expn_blocks(body.value) && let Some(mac) = root_macro_call_first_node(cx, value) && is_format_macro(cx, mac.def_id) diff --git a/clippy_lints/src/methods/iter_filter.rs b/clippy_lints/src/methods/iter_filter.rs index a6308dd9be0f..bafabec7e069 100644 --- a/clippy_lints/src/methods/iter_filter.rs +++ b/clippy_lints/src/methods/iter_filter.rs @@ -94,7 +94,7 @@ fn is_method( false }, ExprKind::Closure(&hir::Closure { body, .. }) => { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); let closure_expr = peel_blocks(body.value); let params = body.params.iter().map(|param| param.pat).collect::>(); is_method(cx, closure_expr, type_symbol, method_name, params.as_slice()) diff --git a/clippy_lints/src/methods/iter_kv_map.rs b/clippy_lints/src/methods/iter_kv_map.rs index 299f6d101123..518041177e92 100644 --- a/clippy_lints/src/methods/iter_kv_map.rs +++ b/clippy_lints/src/methods/iter_kv_map.rs @@ -30,7 +30,7 @@ pub(super) fn check<'tcx>( && let Body { params: [p], value: body_expr, - } = cx.tcx.hir().body(c.body) + } = cx.tcx.hir_body(c.body) && let PatKind::Tuple([key_pat, val_pat], _) = p.pat.kind && let (replacement_kind, annotation, bound_ident) = match (&key_pat.kind, &val_pat.kind) { (key, PatKind::Binding(ann, _, value, _)) if pat_is_wild(cx, key, m_arg) => ("value", ann, value), diff --git a/clippy_lints/src/methods/iter_overeager_cloned.rs b/clippy_lints/src/methods/iter_overeager_cloned.rs index 5ccb5243e903..a80977459f21 100644 --- a/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -62,7 +62,7 @@ pub(super) fn check<'tcx>( let ExprKind::Closure(closure) = expr.kind else { return; }; - let body @ Body { params: [p], .. } = cx.tcx.hir().body(closure.body) else { + let body @ Body { params: [p], .. } = cx.tcx.hir_body(closure.body) else { return; }; let mut delegate = MoveDelegate { diff --git a/clippy_lints/src/methods/manual_contains.rs b/clippy_lints/src/methods/manual_contains.rs index 61bf32cc19bb..8ba0f835d3dd 100644 --- a/clippy_lints/src/methods/manual_contains.rs +++ b/clippy_lints/src/methods/manual_contains.rs @@ -19,7 +19,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, clos if !expr.span.from_expansion() // check if `iter().any()` can be replaced with `contains()` && let ExprKind::Closure(closure) = closure_arg.kind - && let Body{params: [param],value} = cx.tcx.hir().body(closure.body) + && let Body{params: [param],value} = cx.tcx.hir_body(closure.body) && let ExprKind::Binary(op, lhs, rhs) = value.kind && let (peeled_ref_pat, _) = peel_hir_pat_refs(param.pat) && let Some((snip,snip_expr)) = can_replace_with_contains(cx, op, lhs, rhs, peeled_ref_pat.hir_id, &mut app) diff --git a/clippy_lints/src/methods/manual_inspect.rs b/clippy_lints/src/methods/manual_inspect.rs index 20e4d233525a..de37df2394d3 100644 --- a/clippy_lints/src/methods/manual_inspect.rs +++ b/clippy_lints/src/methods/manual_inspect.rs @@ -22,7 +22,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name: && (is_diag_trait_item(cx, fn_id, sym::Iterator) || (msrv.meets(msrvs::OPTION_RESULT_INSPECT) && (is_diag_item_method(cx, fn_id, sym::Option) || is_diag_item_method(cx, fn_id, sym::Result)))) - && let body = cx.tcx.hir().body(c.body) + && let body = cx.tcx.hir_body(c.body) && let [param] = body.params && let PatKind::Binding(BindingMode(ByRef::No, Mutability::Not), arg_id, _, None) = param.pat.kind && let arg_ty = typeck.node_type(arg_id) @@ -45,7 +45,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name: let can_lint = for_each_expr_without_closures(block.stmts, |e| { if let ExprKind::Closure(c) = e.kind { // Nested closures don't need to treat returns specially. - let _: Option = for_each_expr(cx, cx.tcx.hir().body(c.body).value, |e| { + let _: Option = for_each_expr(cx, cx.tcx.hir_body(c.body).value, |e| { if path_to_local_id(e, arg_id) { let (kind, same_ctxt) = check_use(cx, e); match (kind, same_ctxt && e.span.ctxt() == ctxt) { diff --git a/clippy_lints/src/methods/manual_ok_or.rs b/clippy_lints/src/methods/manual_ok_or.rs index 8da9c6b38094..c286c5faaed3 100644 --- a/clippy_lints/src/methods/manual_ok_or.rs +++ b/clippy_lints/src/methods/manual_ok_or.rs @@ -44,7 +44,7 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool { match map_expr.kind { ExprKind::Path(ref qpath) if is_res_lang_ctor(cx, cx.qpath_res(qpath, map_expr.hir_id), ResultOk) => true, ExprKind::Closure(closure) => { - let body = cx.tcx.hir().body(closure.body); + let body = cx.tcx.hir_body(closure.body); if let PatKind::Binding(_, param_id, ..) = body.params[0].pat.kind && let ExprKind::Call(callee, [ok_arg]) = body.value.kind && is_res_lang_ctor(cx, path_res(cx, callee), ResultOk) diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index 1252f7ccd357..b2705e1ffc2d 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -47,7 +47,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_ { match arg.kind { hir::ExprKind::Closure(&hir::Closure { body, .. }) => { - let closure_body = cx.tcx.hir().body(body); + let closure_body = cx.tcx.hir_body(body); let closure_expr = peel_blocks(closure_body.value); match closure_body.params[0].pat.kind { hir::PatKind::Ref(inner, Mutability::Not) => { diff --git a/clippy_lints/src/methods/map_err_ignore.rs b/clippy_lints/src/methods/map_err_ignore.rs index 162f0ac564d7..5d0d4dae35fa 100644 --- a/clippy_lints/src/methods/map_err_ignore.rs +++ b/clippy_lints/src/methods/map_err_ignore.rs @@ -16,7 +16,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &Expr<'_>, arg: &Expr<'_>) { fn_decl_span, .. }) = arg.kind - && let closure_body = cx.tcx.hir().body(body) + && let closure_body = cx.tcx.hir_body(body) && let [param] = closure_body.params && let PatKind::Wild = param.pat.kind { diff --git a/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs b/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs index 78656ace831d..35dd7c082c90 100644 --- a/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs +++ b/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs @@ -68,7 +68,7 @@ pub(super) fn check( let mut applicability = Applicability::MaybeIncorrect; if let Some(range) = higher::Range::hir(receiver) && let ExprKind::Closure(Closure { body, .. }) = arg.kind - && let body_hir = cx.tcx.hir().body(*body) + && let body_hir = cx.tcx.hir_body(*body) && let Body { params: [param], value: body_expr, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 7e66016b89d9..7f421d098270 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -150,6 +150,7 @@ use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::ty::{contains_ty_adt_constructor_opaque, implements_trait, is_copy, is_type_diagnostic_item}; use clippy_utils::{contains_return, is_bool, is_trait_method, iter_input_pats, peel_blocks, return_ty}; pub use path_ends_with_ext::DEFAULT_ALLOWED_DOTFILES; +use rustc_abi::ExternAbi; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::{Expr, ExprKind, Node, Stmt, StmtKind, TraitItem, TraitItemKind}; @@ -4749,7 +4750,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if sig.decl.implicit_self.has_implicit_self() && !(self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(impl_item.owner_id.def_id)) - && let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir().body(id)).next() + && let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir_body(id)).next() && let Some(first_arg_ty) = first_arg_ty_opt { wrong_self_convention::check( @@ -4885,7 +4886,7 @@ impl Methods { ), Some(("chars", recv, _, _, _)) if let ExprKind::Closure(arg) = arg.kind - && let body = cx.tcx.hir().body(arg.body) + && let body = cx.tcx.hir_body(arg.body) && let [param] = body.params => { string_lit_chars_any::check(cx, expr, recv, param, peel_blocks(body.value), &self.msrv); @@ -5488,7 +5489,7 @@ const FN_HEADER: hir::FnHeader = hir::FnHeader { safety: hir::HeaderSafety::Normal(hir::Safety::Safe), constness: hir::Constness::NotConst, asyncness: hir::IsAsync::NotAsync, - abi: rustc_target::spec::abi::Abi::Rust, + abi: ExternAbi::Rust, }; struct ShouldImplTraitCase { diff --git a/clippy_lints/src/methods/needless_character_iteration.rs b/clippy_lints/src/methods/needless_character_iteration.rs index 6993150fb57a..743aacf05885 100644 --- a/clippy_lints/src/methods/needless_character_iteration.rs +++ b/clippy_lints/src/methods/needless_character_iteration.rs @@ -99,7 +99,7 @@ fn handle_expr( pub(super) fn check(cx: &LateContext<'_>, call_expr: &Expr<'_>, recv: &Expr<'_>, closure_arg: &Expr<'_>, is_all: bool) { if let ExprKind::Closure(&Closure { body, .. }) = closure_arg.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) && let Some(first_param) = body.params.first() && let ExprKind::MethodCall(method, mut recv, [], _) = recv.kind && method.ident.name.as_str() == "chars" diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 2780c3f8af5c..45f79dd44f2a 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -456,8 +456,8 @@ impl<'tcx> Visitor<'tcx> for UsedCountVisitor<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } @@ -498,7 +498,7 @@ fn get_captured_ids(cx: &LateContext<'_>, ty: Ty<'_>) -> HirIdSet { } }, ty::Closure(def_id, _) => { - let closure_hir_node = cx.tcx.hir().get_if_local(*def_id).unwrap(); + let closure_hir_node = cx.tcx.hir_get_if_local(*def_id).unwrap(); if let Node::Expr(closure_expr) = closure_hir_node { can_move_expr_to_closure(cx, closure_expr) .unwrap() diff --git a/clippy_lints/src/methods/obfuscated_if_else.rs b/clippy_lints/src/methods/obfuscated_if_else.rs index 2272e03ef26e..3ef4906b3c9d 100644 --- a/clippy_lints/src/methods/obfuscated_if_else.rs +++ b/clippy_lints/src/methods/obfuscated_if_else.rs @@ -28,7 +28,7 @@ pub(super) fn check<'tcx>( let if_then = match then_method_name { "then" if let ExprKind::Closure(closure) = then_arg.kind => { - let body = cx.tcx.hir().body(closure.body); + let body = cx.tcx.hir_body(closure.body); snippet_with_applicability(cx, body.value.span, "..", &mut applicability) }, "then_some" => snippet_with_applicability(cx, then_arg.span, "..", &mut applicability), diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index 8d97d1c72a6b..469fcccbe4f6 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -54,7 +54,7 @@ pub(super) fn check( }) }, hir::ExprKind::Closure(&hir::Closure { body, .. }) => { - let closure_body = cx.tcx.hir().body(body); + let closure_body = cx.tcx.hir_body(body); let closure_expr = peel_blocks(closure_body.value); match &closure_expr.kind { diff --git a/clippy_lints/src/methods/option_map_or_none.rs b/clippy_lints/src/methods/option_map_or_none.rs index 193deafccf65..1a273f77fb7d 100644 --- a/clippy_lints/src/methods/option_map_or_none.rs +++ b/clippy_lints/src/methods/option_map_or_none.rs @@ -60,7 +60,7 @@ pub(super) fn check<'tcx>( let self_snippet = snippet(cx, recv.span, ".."); if let hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }) = map_arg.kind && let arg_snippet = snippet(cx, fn_decl_span, "..") - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) && let Some((func, [arg_char])) = reduce_unit_expression(body.value) && let Some(id) = path_def_id(cx, func).map(|ctor_id| cx.tcx.parent(ctor_id)) && Some(id) == cx.tcx.lang_items().option_some_variant() diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 7c4dc4ffb202..b1107d8cc72f 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -58,8 +58,7 @@ pub(super) fn check<'tcx>( unwrap_or_span: unwrap_arg.span, }; - let map = cx.tcx.hir(); - let body = map.body_owned_by(map.enclosing_body_owner(expr.hir_id)); + let body = cx.tcx.hir_body_owned_by(cx.tcx.hir_enclosing_body_owner(expr.hir_id)); // Visit the body, and return if we've found a reference if reference_visitor.visit_body(body).is_break() { @@ -143,8 +142,8 @@ impl<'tcx> Visitor<'tcx> for UnwrapVisitor<'_, 'tcx> { walk_path(self, path); } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } @@ -174,7 +173,7 @@ impl<'tcx> Visitor<'tcx> for ReferenceVisitor<'_, 'tcx> { rustc_hir::intravisit::walk_expr(self, expr) } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index f00e4b87a7df..12b86fd3bcc6 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -253,7 +253,7 @@ pub(super) fn check<'tcx>( fn closure_body_returns_empty_to_string(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> bool { if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = e.kind { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); if body.params.is_empty() && let hir::Expr { kind, .. } = &body.value diff --git a/clippy_lints/src/methods/read_line_without_trim.rs b/clippy_lints/src/methods/read_line_without_trim.rs index 82e66a0500a8..c9251c1b8497 100644 --- a/clippy_lints/src/methods/read_line_without_trim.rs +++ b/clippy_lints/src/methods/read_line_without_trim.rs @@ -1,11 +1,10 @@ use std::ops::ControlFlow; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::paths::STDIN; +use clippy_utils::get_parent_expr; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::visitors::for_each_local_use_after_expr; -use clippy_utils::{get_parent_expr, match_def_path}; use rustc_ast::LitKind; use rustc_errors::Applicability; use rustc_hir::def::Res; @@ -34,7 +33,7 @@ fn parse_fails_on_trailing_newline(ty: Ty<'_>) -> bool { pub fn check(cx: &LateContext<'_>, call: &Expr<'_>, recv: &Expr<'_>, arg: &Expr<'_>) { if let Some(recv_adt) = cx.typeck_results().expr_ty(recv).ty_adt_def() - && match_def_path(cx, recv_adt.did(), &STDIN) + && cx.tcx.is_diagnostic_item(sym::Stdin, recv_adt.did()) && let ExprKind::Path(QPath::Resolved(_, path)) = arg.peel_borrows().kind && let Res::Local(local_id) = path.res { diff --git a/clippy_lints/src/methods/result_map_or_else_none.rs b/clippy_lints/src/methods/result_map_or_else_none.rs index 3b0dc506305b..af619c9e3bb1 100644 --- a/clippy_lints/src/methods/result_map_or_else_none.rs +++ b/clippy_lints/src/methods/result_map_or_else_none.rs @@ -23,7 +23,7 @@ pub(super) fn check<'tcx>( // We check that it is mapped as `Some`. && is_res_lang_ctor(cx, path_res(cx, map_arg), OptionSome) && let hir::ExprKind::Closure(&hir::Closure { body, .. }) = def_arg.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) // And finally we check that we return a `None` in the "else case". && is_res_lang_ctor(cx, path_res(cx, peel_blocks(body.value)), OptionNone) { diff --git a/clippy_lints/src/methods/return_and_then.rs b/clippy_lints/src/methods/return_and_then.rs index 3c7b54dd8db9..e8861935d421 100644 --- a/clippy_lints/src/methods/return_and_then.rs +++ b/clippy_lints/src/methods/return_and_then.rs @@ -44,7 +44,7 @@ pub(super) fn check<'tcx>( }; let closure_arg = fn_decl.inputs[0]; - let closure_expr = peel_blocks(cx.tcx.hir().body(body).value); + let closure_expr = peel_blocks(cx.tcx.hir_body(body).value); let mut applicability = Applicability::MachineApplicable; let arg_snip = snippet_with_applicability(cx, closure_arg.span, "_", &mut applicability); diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index 4ab165a5528b..97c8ce2bcdd2 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -37,7 +37,7 @@ pub(super) fn check<'tcx>( let mut applicability = Applicability::MachineApplicable; let any_search_snippet = if search_method == "find" && let ExprKind::Closure(&hir::Closure { body, .. }) = search_arg.kind - && let closure_body = cx.tcx.hir().body(body) + && let closure_body = cx.tcx.hir_body(body) && let Some(closure_arg) = closure_body.params.first() { if let PatKind::Ref(..) = closure_arg.pat.kind { diff --git a/clippy_lints/src/methods/suspicious_map.rs b/clippy_lints/src/methods/suspicious_map.rs index ed49233acb7f..1bd48525f12d 100644 --- a/clippy_lints/src/methods/suspicious_map.rs +++ b/clippy_lints/src/methods/suspicious_map.rs @@ -10,7 +10,7 @@ use super::SUSPICIOUS_MAP; pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, count_recv: &hir::Expr<'_>, map_arg: &hir::Expr<'_>) { if is_trait_method(cx, count_recv, sym::Iterator) && let hir::ExprKind::Closure(closure) = expr_or_init(cx, map_arg).kind - && let closure_body = cx.tcx.hir().body(closure.body) + && let closure_body = cx.tcx.hir_body(closure.body) && !cx.typeck_results().expr_ty(closure_body.value).is_unit() { if let Some(map_mutated_vars) = mutated_variables(closure_body.value, cx) { diff --git a/clippy_lints/src/methods/unbuffered_bytes.rs b/clippy_lints/src/methods/unbuffered_bytes.rs index 71c23d256ac6..c4d2515a7bcb 100644 --- a/clippy_lints/src/methods/unbuffered_bytes.rs +++ b/clippy_lints/src/methods/unbuffered_bytes.rs @@ -1,7 +1,7 @@ use super::UNBUFFERED_BYTES; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::is_trait_method; use clippy_utils::ty::implements_trait; -use clippy_utils::{get_trait_def_id, is_trait_method, paths}; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::sym; @@ -13,7 +13,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr if is_trait_method(cx, expr, sym::IoRead) { // Retrieve the DefId of the BufRead trait // FIXME: add a diagnostic item for `BufRead` - let Some(buf_read) = get_trait_def_id(cx.tcx, &paths::BUF_READ) else { + let Some(buf_read) = cx.tcx.get_diagnostic_item(sym::IoBufRead) else { return; }; // And the implementor of the trait is not buffered diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 5b9e9e70e477..ca42a9ac04e0 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -20,7 +20,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>, a } if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = arg.kind { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); let arg_id = body.params[0].pat.hir_id; let mutates_arg = mutated_variables(body.value, cx).is_none_or(|used_mutably| used_mutably.contains(&arg_id)); let (clone_or_copy_needed, _) = clone_or_copy_needed(cx, body.params[0].pat, body.value); diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index e7adf3b43ba5..8e3cc9abe832 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -62,7 +62,7 @@ fn check_fold_with_op( ) { if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = acc.kind // Extract the body of the closure passed to fold - && let closure_body = cx.tcx.hir().body(body) + && let closure_body = cx.tcx.hir_body(body) && let closure_expr = peel_blocks(closure_body.value) // Check if the closure body is of the form `acc some_expr(x)` diff --git a/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/clippy_lints/src/methods/unnecessary_lazy_eval.rs index 7af550fa7c68..9f4080100da2 100644 --- a/clippy_lints/src/methods/unnecessary_lazy_eval.rs +++ b/clippy_lints/src/methods/unnecessary_lazy_eval.rs @@ -25,7 +25,7 @@ pub(super) fn check<'tcx>( if is_option || is_result || is_bool { if let hir::ExprKind::Closure(&hir::Closure { body, fn_decl, .. }) = arg.kind { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); let body_expr = &body.value; if usage::BindingUsageFinder::are_params_used(cx, body) || is_from_proc_macro(cx, expr) { diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs index 10112b62878a..fa3a29e36670 100644 --- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs +++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs @@ -98,10 +98,7 @@ pub(super) fn check( ]), ("None", "unwrap_or_else", _) => match args[0].kind { hir::ExprKind::Closure(hir::Closure { body, .. }) => Some(vec![ - ( - expr.span.with_hi(cx.tcx.hir().body(*body).value.span.lo()), - String::new(), - ), + (expr.span.with_hi(cx.tcx.hir_body(*body).value.span.lo()), String::new()), (expr.span.with_lo(args[0].span.hi()), String::new()), ]), _ => None, diff --git a/clippy_lints/src/methods/unnecessary_map_or.rs b/clippy_lints/src/methods/unnecessary_map_or.rs index c307e8c951d0..3a669fca177f 100644 --- a/clippy_lints/src/methods/unnecessary_map_or.rs +++ b/clippy_lints/src/methods/unnecessary_map_or.rs @@ -63,7 +63,7 @@ pub(super) fn check<'a>( let ext_def_span = def.span.until(map.span); let (sugg, method, applicability) = if let ExprKind::Closure(map_closure) = map.kind - && let closure_body = cx.tcx.hir().body(map_closure.body) + && let closure_body = cx.tcx.hir_body(map_closure.body) && let closure_body_value = closure_body.value.peel_blocks() && let ExprKind::Binary(op, l, r) = closure_body_value.kind && let Some(param) = closure_body.params.first() diff --git a/clippy_lints/src/methods/unnecessary_result_map_or_else.rs b/clippy_lints/src/methods/unnecessary_result_map_or_else.rs index dc50717112d8..f84d0d6dff0a 100644 --- a/clippy_lints/src/methods/unnecessary_result_map_or_else.rs +++ b/clippy_lints/src/methods/unnecessary_result_map_or_else.rs @@ -53,7 +53,7 @@ pub(super) fn check<'tcx>( // lint if the caller of `map_or_else()` is a `Result` if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result) && let ExprKind::Closure(&Closure { body, .. }) = map_arg.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) && let Some(first_param) = body.params.first() { let body_expr = peel_blocks(body.value); diff --git a/clippy_lints/src/methods/unnecessary_sort_by.rs b/clippy_lints/src/methods/unnecessary_sort_by.rs index ebc08503decb..235fdac29433 100644 --- a/clippy_lints/src/methods/unnecessary_sort_by.rs +++ b/clippy_lints/src/methods/unnecessary_sort_by.rs @@ -118,7 +118,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Exp && let Some(impl_id) = cx.tcx.impl_of_method(method_id) && cx.tcx.type_of(impl_id).instantiate_identity().is_slice() && let ExprKind::Closure(&Closure { body, .. }) = arg.kind - && let closure_body = cx.tcx.hir().body(body) + && let closure_body = cx.tcx.hir_body(body) && let &[ Param { pat: diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 7d72310c1c44..e80d99dca56d 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -506,7 +506,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< if has_lifetime(output_ty) && has_lifetime(ty) { return false; } - let body = cx.tcx.hir().body(*body_id); + let body = cx.tcx.hir_body(*body_id); let body_expr = &body.value; let mut count = 0; return find_all_ret_expressions(cx, body_expr, |_| { diff --git a/clippy_lints/src/methods/unused_enumerate_index.rs b/clippy_lints/src/methods/unused_enumerate_index.rs index 0aec26f10111..af466fe091c2 100644 --- a/clippy_lints/src/methods/unused_enumerate_index.rs +++ b/clippy_lints/src/methods/unused_enumerate_index.rs @@ -46,7 +46,7 @@ pub(super) fn check(cx: &LateContext<'_>, call_expr: &Expr<'_>, recv: &Expr<'_>, && is_trait_method(cx, call_expr, sym::Iterator) // And the map argument is a closure && let ExprKind::Closure(closure) = closure_arg.kind - && let closure_body = cx.tcx.hir().body(closure.body) + && let closure_body = cx.tcx.hir_body(closure.body) // And that closure has one argument ... && let [closure_param] = closure_body.params // .. which is a tuple of 2 elements diff --git a/clippy_lints/src/methods/useless_asref.rs b/clippy_lints/src/methods/useless_asref.rs index 6d3da42775f4..1d43c585269b 100644 --- a/clippy_lints/src/methods/useless_asref.rs +++ b/clippy_lints/src/methods/useless_asref.rs @@ -120,7 +120,7 @@ fn is_calling_clone(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool { match arg.kind { hir::ExprKind::Closure(&hir::Closure { body, .. }) // If it's a closure, we need to check what is called. - if let closure_body = cx.tcx.hir().body(body) + if let closure_body = cx.tcx.hir_body(body) && let [param] = closure_body.params && let hir::PatKind::Binding(_, local_id, ..) = strip_pat_refs(param.pat).kind => { diff --git a/clippy_lints/src/methods/utils.rs b/clippy_lints/src/methods/utils.rs index 6e39e7be2c43..3611b341897a 100644 --- a/clippy_lints/src/methods/utils.rs +++ b/clippy_lints/src/methods/utils.rs @@ -89,8 +89,8 @@ struct CloneOrCopyVisitor<'cx, 'tcx> { impl<'tcx> Visitor<'tcx> for CloneOrCopyVisitor<'_, 'tcx> { type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 962d85c6a9d3..e551fb9ce0ca 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -3,6 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::qualify_min_const_fn::is_min_const_fn; use clippy_utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, is_from_proc_macro, is_in_test, trait_ref_of_method}; +use rustc_abi::ExternAbi; use rustc_errors::Applicability; use rustc_hir::def_id::CRATE_DEF_ID; use rustc_hir::intravisit::FnKind; @@ -12,7 +13,6 @@ use rustc_middle::ty; use rustc_session::impl_lint_pass; use rustc_span::Span; use rustc_span::def_id::LocalDefId; -use rustc_target::spec::abi::Abi; declare_clippy_lint! { /// ### What it does @@ -183,11 +183,11 @@ fn already_const(header: hir::FnHeader) -> bool { header.constness == Constness::Const } -fn could_be_const_with_abi(msrv: &Msrv, abi: Abi) -> bool { +fn could_be_const_with_abi(msrv: &Msrv, abi: ExternAbi) -> bool { match abi { - Abi::Rust => true, + ExternAbi::Rust => true, // `const extern "C"` was stabilized after 1.62.0 - Abi::C { unwind: false } => msrv.meets(msrvs::CONST_EXTERN_C_FN), + ExternAbi::C { unwind: false } => msrv.meets(msrvs::CONST_EXTERN_C_FN), // Rest ABIs are still unstable and need the `const_extern_fn` feature enabled. _ => msrv.meets(msrvs::CONST_EXTERN_FN), } diff --git a/clippy_lints/src/missing_fields_in_debug.rs b/clippy_lints/src/missing_fields_in_debug.rs index e9ec23b1efa6..675989156cad 100644 --- a/clippy_lints/src/missing_fields_in_debug.rs +++ b/clippy_lints/src/missing_fields_in_debug.rs @@ -213,8 +213,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug { && !item.span.from_expansion() // find `Debug::fmt` function && let Some(fmt_item) = items.iter().find(|i| i.ident.name == sym::fmt) - && let ImplItem { kind: ImplItemKind::Fn(_, body_id), .. } = cx.tcx.hir().impl_item(fmt_item.id) - && let body = cx.tcx.hir().body(*body_id) + && let ImplItem { kind: ImplItemKind::Fn(_, body_id), .. } = cx.tcx.hir_impl_item(fmt_item.id) + && let body = cx.tcx.hir_body(*body_id) && let ExprKind::Block(block, _) = body.value.kind // inspect `self` && let self_ty = cx.tcx.type_of(self_path_did).skip_binder().peel_refs() diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 18385ac92692..fdc0930e957a 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { // note: we need to check if the trait is exported so we can't use // `LateLintPass::check_trait_item` here. for tit in trait_items { - let tit_ = cx.tcx.hir().trait_item(tit.id); + let tit_ = cx.tcx.hir_trait_item(tit.id); match tit_.kind { hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {}, hir::TraitItemKind::Fn(..) => { @@ -113,7 +113,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { // trait method with default body needs inline in case // an impl is not provided let desc = "a default trait method"; - let item = cx.tcx.hir().trait_item(tit.id); + let item = cx.tcx.hir_trait_item(tit.id); let attrs = cx.tcx.hir().attrs(item.hir_id()); check_missing_inline_attrs(cx, attrs, item.span, desc); } diff --git a/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/clippy_lints/src/multiple_unsafe_ops_per_block.rs index 9acede4f32d6..2adc27c0b709 100644 --- a/clippy_lints/src/multiple_unsafe_ops_per_block.rs +++ b/clippy_lints/src/multiple_unsafe_ops_per_block.rs @@ -122,7 +122,7 @@ fn collect_unsafe_exprs<'tcx>( unsafe_ops.push(("access of a mutable static occurs here", expr.span)); }, - ExprKind::Unary(UnOp::Deref, e) if cx.typeck_results().expr_ty_adjusted(e).is_unsafe_ptr() => { + ExprKind::Unary(UnOp::Deref, e) if cx.typeck_results().expr_ty_adjusted(e).is_raw_ptr() => { unsafe_ops.push(("raw pointer dereference occurs here", expr.span)); }, diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index e589b3608b31..3d943bf5b370 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -115,7 +115,7 @@ impl<'tcx> Visitor<'tcx> for MutArgVisitor<'_, 'tcx> { walk_expr(self, expr); } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/needless_borrows_for_generic_args.rs b/clippy_lints/src/needless_borrows_for_generic_args.rs index 7f91e555054d..ea1d7e5d4382 100644 --- a/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowsForGenericArgs<'tcx> { if self .possible_borrowers .last() - .is_some_and(|&(local_def_id, _)| local_def_id == cx.tcx.hir().body_owner_def_id(body.id())) + .is_some_and(|&(local_def_id, _)| local_def_id == cx.tcx.hir_body_owner_def_id(body.id())) { self.possible_borrowers.pop(); } @@ -359,7 +359,7 @@ fn referent_used_exactly_once<'tcx>( && let StatementKind::Assign(box (_, Rvalue::Ref(_, _, place))) = statement.kind && !place.is_indirect_first_projection() { - let body_owner_local_def_id = cx.tcx.hir().enclosing_body_owner(reference.hir_id); + let body_owner_local_def_id = cx.tcx.hir_enclosing_body_owner(reference.hir_id); if possible_borrowers .last() .is_none_or(|&(local_def_id, _)| local_def_id != body_owner_local_def_id) diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index 93e20f37ef8a..90b27f5dbac8 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessForEach { // Skip the lint if the body is not block because this is simpler than `for` loop. // e.g. `v.iter().for_each(f)` is simpler and clearer than using `for` loop. && let ExprKind::Closure(&Closure { body, .. }) = for_each_arg.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) // Skip the lint if the body is not safe, so as not to suggest `for … in … unsafe {}` // and suggesting `for … in … { unsafe { } }` is a little ugly. && let ExprKind::Block(Block { rules: BlockCheckMode::DefaultBlock, .. }, ..) = body.value.kind diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index b7dc269061cf..3bf725dafd8a 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -5,6 +5,7 @@ use clippy_utils::source::snippet; use clippy_utils::visitors::for_each_expr; use clippy_utils::{inherits_cfg, is_from_proc_macro, is_self}; use core::ops::ControlFlow; +use rustc_abi::ExternAbi; use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; @@ -20,7 +21,6 @@ use rustc_session::impl_lint_pass; use rustc_span::Span; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; -use rustc_target::spec::abi::Abi; declare_clippy_lint! { /// ### What it does @@ -103,7 +103,6 @@ fn check_closures<'tcx>( checked_closures: &mut FxHashSet, closures: FxIndexSet, ) { - let hir = cx.tcx.hir(); for closure in closures { if !checked_closures.insert(closure) { continue; @@ -114,7 +113,7 @@ fn check_closures<'tcx>( .tcx .hir_node_by_def_id(closure) .associated_body() - .map(|(_, body_id)| hir.body(body_id)) + .map(|(_, body_id)| cx.tcx.hir_body(body_id)) { euv::ExprUseVisitor::for_clippy(cx, closure, &mut *ctx) .consume_body(body) @@ -149,7 +148,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { return; } let attrs = cx.tcx.hir().attrs(hir_id); - if header.abi != Abi::Rust || requires_exact_signature(attrs) { + if header.abi != ExternAbi::Rust || requires_exact_signature(attrs) { return; } header.is_async() @@ -353,7 +352,7 @@ impl MutablyUsedVariablesCtxt<'_> { fn is_in_unsafe_block(&self, item: HirId) -> bool { let hir = self.tcx.hir(); for (parent, node) in hir.parent_iter(item) { - if let Some(fn_sig) = hir.fn_sig_by_hir_id(parent) { + if let Some(fn_sig) = self.tcx.hir_fn_sig_by_hir_id(parent) { return fn_sig.header.is_unsafe(); } else if let Node::Block(block) = node { if matches!(block.rules, BlockCheckMode::UnsafeBlock(_)) { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 2855703b9d56..380cc380ad0f 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -5,6 +5,7 @@ use clippy_utils::source::{SpanRangeExt, snippet}; use clippy_utils::ty::{ implements_trait, implements_trait_with_env_from_iter, is_copy, is_type_diagnostic_item, is_type_lang_item, }; +use rustc_abi::ExternAbi; use rustc_errors::{Applicability, Diag}; use rustc_hir::intravisit::FnKind; use rustc_hir::{ @@ -19,7 +20,6 @@ use rustc_session::declare_lint_pass; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; use rustc_span::{Span, sym}; -use rustc_target::spec::abi::Abi; use rustc_trait_selection::traits; use rustc_trait_selection::traits::misc::type_allowed_to_implement_copy; @@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { match kind { FnKind::ItemFn(.., header) => { let attrs = cx.tcx.hir().attrs(hir_id); - if header.abi != Abi::Rust || requires_exact_signature(attrs) { + if header.abi != ExternAbi::Rust || requires_exact_signature(attrs) { return; } }, diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index cc56df3a23d7..cf407e51f7af 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { { for assoc_item in *items { if assoc_item.kind == (hir::AssocItemKind::Fn { has_self: false }) { - let impl_item = cx.tcx.hir().impl_item(assoc_item.id); + let impl_item = cx.tcx.hir_impl_item(assoc_item.id); if impl_item.span.in_external_macro(cx.sess().source_map()) { return; } diff --git a/clippy_lints/src/no_mangle_with_rust_abi.rs b/clippy_lints/src/no_mangle_with_rust_abi.rs index 2e2916c957da..ba8399524764 100644 --- a/clippy_lints/src/no_mangle_with_rust_abi.rs +++ b/clippy_lints/src/no_mangle_with_rust_abi.rs @@ -1,11 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::{snippet, snippet_with_applicability}; +use rustc_abi::ExternAbi; use rustc_errors::Applicability; use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::{BytePos, Pos}; -use rustc_target::spec::abi::Abi; declare_clippy_lint! { /// ### What it does @@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for NoMangleWithRustAbi { for attr in attrs { if let Some(ident) = attr.ident() && ident.name == rustc_span::sym::no_mangle - && fn_sig.header.abi == Abi::Rust + && fn_sig.header.abi == ExternAbi::Rust && let Some((fn_attrs, _)) = fn_snippet.rsplit_once("fn") && !fn_attrs.contains("extern") { diff --git a/clippy_lints/src/non_canonical_impls.rs b/clippy_lints/src/non_canonical_impls.rs index dad1e8a3d6a1..448bb603cf2c 100644 --- a/clippy_lints/src/non_canonical_impls.rs +++ b/clippy_lints/src/non_canonical_impls.rs @@ -121,10 +121,10 @@ impl LateLintPass<'_> for NonCanonicalImpls { if cx.tcx.is_automatically_derived(item.owner_id.to_def_id()) { return; } - let ImplItemKind::Fn(_, impl_item_id) = cx.tcx.hir().impl_item(impl_item.impl_item_id()).kind else { + let ImplItemKind::Fn(_, impl_item_id) = cx.tcx.hir_impl_item(impl_item.impl_item_id()).kind else { return; }; - let body = cx.tcx.hir().body(impl_item_id); + let body = cx.tcx.hir_body(impl_item_id); let ExprKind::Block(block, ..) = body.value.kind else { return; }; diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 0d89b4e85350..57161910ff54 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -5,6 +5,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_in_const_context; use clippy_utils::macros::macro_backtrace; use clippy_utils::ty::{InteriorMut, implements_trait}; +use rustc_abi::VariantIdx; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{ @@ -16,7 +17,6 @@ use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_session::impl_lint_pass; use rustc_span::{DUMMY_SP, Span, sym}; -use rustc_target::abi::VariantIdx; // FIXME: this is a correctness problem but there's no suitable // warn-by-default category. @@ -179,8 +179,10 @@ impl<'tcx> NonCopyConst<'tcx> { } fn is_value_unfrozen_raw_inner(cx: &LateContext<'tcx>, val: ty::ValTree<'tcx>, ty: Ty<'tcx>) -> bool { - // No branch that we check (yet) should continue if val isn't a ValTree::Branch - let ty::ValTree::Branch(val) = val else { return false }; + // No branch that we check (yet) should continue if val isn't a branch + let Some(branched_val) = val.try_to_branch() else { + return false; + }; match *ty.kind() { // the fact that we have to dig into every structs to search enums // leads us to the point checking `UnsafeCell` directly is the only option. @@ -188,13 +190,14 @@ impl<'tcx> NonCopyConst<'tcx> { // As of 2022-09-08 miri doesn't track which union field is active so there's no safe way to check the // contained value. ty::Adt(def, ..) if def.is_union() => false, - ty::Array(ty, _) => val + ty::Array(ty, _) => branched_val .iter() .any(|field| Self::is_value_unfrozen_raw_inner(cx, *field, ty)), ty::Adt(def, args) if def.is_enum() => { - let Some((&ty::ValTree::Leaf(variant_index), fields)) = val.split_first() else { + let Some((&variant_valtree, fields)) = branched_val.split_first() else { return false; }; + let variant_index = variant_valtree.unwrap_leaf(); let variant_index = VariantIdx::from_u32(variant_index.to_u32()); fields .iter() @@ -207,18 +210,16 @@ impl<'tcx> NonCopyConst<'tcx> { ) .any(|(field, ty)| Self::is_value_unfrozen_raw_inner(cx, field, ty)) }, - ty::Adt(def, args) => val + ty::Adt(def, args) => branched_val .iter() .zip(def.non_enum_variant().fields.iter().map(|field| field.ty(cx.tcx, args))) .any(|(field, ty)| Self::is_value_unfrozen_raw_inner(cx, *field, ty)), - ty::Tuple(tys) => val + ty::Tuple(tys) => branched_val .iter() .zip(tys) .any(|(field, ty)| Self::is_value_unfrozen_raw_inner(cx, *field, ty)), ty::Alias(ty::Projection, _) => match cx.tcx.try_normalize_erasing_regions(cx.typing_env(), ty) { - Ok(normalized_ty) if ty != normalized_ty => { - Self::is_value_unfrozen_raw_inner(cx, ty::ValTree::Branch(val), normalized_ty) - }, + Ok(normalized_ty) if ty != normalized_ty => Self::is_value_unfrozen_raw_inner(cx, val, normalized_ty), _ => false, }, _ => false, diff --git a/clippy_lints/src/non_std_lazy_statics.rs b/clippy_lints/src/non_std_lazy_statics.rs index 22116505a1c1..774a182d089f 100644 --- a/clippy_lints/src/non_std_lazy_statics.rs +++ b/clippy_lints/src/non_std_lazy_statics.rs @@ -214,7 +214,7 @@ impl LazyInfo { && state.once_cell_sync_lazy.contains(&path_def_id) { let ty_span_no_args = path_span_without_args(path); - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); // visit body to collect `Lazy::new` calls let mut new_fn_calls = FxIndexMap::default(); diff --git a/clippy_lints/src/operators/arithmetic_side_effects.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs index 9d07a14718da..594101427f5a 100644 --- a/clippy_lints/src/operators/arithmetic_side_effects.rs +++ b/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -349,10 +349,10 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects { } fn check_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { - let body_owner = cx.tcx.hir().body_owner(body.id()); - let body_owner_def_id = cx.tcx.hir().body_owner_def_id(body.id()); + let body_owner = cx.tcx.hir_body_owner(body.id()); + let body_owner_def_id = cx.tcx.hir_body_owner_def_id(body.id()); - let body_owner_kind = cx.tcx.hir().body_owner_kind(body_owner_def_id); + let body_owner_kind = cx.tcx.hir_body_owner_kind(body_owner_def_id); if let hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_) = body_owner_kind { let body_span = cx.tcx.hir().span_with_body(body_owner); if let Some(span) = self.const_span @@ -365,7 +365,7 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects { } fn check_body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { - let body_owner = cx.tcx.hir().body_owner(body.id()); + let body_owner = cx.tcx.hir_body_owner(body.id()); let body_span = cx.tcx.hir().span(body_owner); if let Some(span) = self.const_span && span.contains(body_span) diff --git a/clippy_lints/src/operators/numeric_arithmetic.rs b/clippy_lints/src/operators/numeric_arithmetic.rs index 2083f2bf628d..cda99a362dca 100644 --- a/clippy_lints/src/operators/numeric_arithmetic.rs +++ b/clippy_lints/src/operators/numeric_arithmetic.rs @@ -68,10 +68,10 @@ impl Context { } pub fn enter_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { - let body_owner = cx.tcx.hir().body_owner(body.id()); - let body_owner_def_id = cx.tcx.hir().body_owner_def_id(body.id()); + let body_owner = cx.tcx.hir_body_owner(body.id()); + let body_owner_def_id = cx.tcx.hir_body_owner_def_id(body.id()); - match cx.tcx.hir().body_owner_kind(body_owner_def_id) { + match cx.tcx.hir_body_owner_kind(body_owner_def_id) { hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const { .. } => { let body_span = cx.tcx.hir().span_with_body(body_owner); @@ -87,7 +87,7 @@ impl Context { } pub fn body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { - let body_owner = cx.tcx.hir().body_owner(body.id()); + let body_owner = cx.tcx.hir_body_owner(body.id()); let body_span = cx.tcx.hir().span_with_body(body_owner); if let Some(span) = self.const_span { diff --git a/clippy_lints/src/operators/ptr_eq.rs b/clippy_lints/src/operators/ptr_eq.rs index 861564d54569..8118ad59bb71 100644 --- a/clippy_lints/src/operators/ptr_eq.rs +++ b/clippy_lints/src/operators/ptr_eq.rs @@ -53,7 +53,7 @@ fn expr_as_cast_to_usize<'tcx>(cx: &LateContext<'tcx>, cast_expr: &'tcx Expr<'_> // If the given expression is a cast to a `*const` pointer, return the lhs of the cast // E.g., `foo as *const _` returns `foo`. fn expr_as_cast_to_raw_pointer<'tcx>(cx: &LateContext<'tcx>, cast_expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { - if cx.typeck_results().expr_ty(cast_expr).is_unsafe_ptr() { + if cx.typeck_results().expr_ty(cast_expr).is_raw_ptr() { if let ExprKind::Cast(expr, _) = cast_expr.kind { return Some(expr); } diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index fa5b02a5a41b..18019c1ad022 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -1,11 +1,12 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint; +use clippy_utils::is_in_test; use clippy_utils::macros::{is_panic, root_macro_call_first_node}; -use clippy_utils::{is_in_test, match_def_path, paths}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; +use rustc_span::sym; pub struct PanicUnimplemented { allow_panic_in_tests: bool, @@ -137,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented { } else if let ExprKind::Call(func, [_]) = expr.kind && let ExprKind::Path(QPath::Resolved(None, expr_path)) = func.kind && let Res::Def(DefKind::Fn, def_id) = expr_path.res - && match_def_path(cx, def_id, &paths::PANIC_ANY) + && cx.tcx.is_diagnostic_item(sym::panic_any, def_id) { if cx.tcx.hir().is_inside_const_context(expr.hir_id) || self.allow_panic_in_tests && is_in_test(cx.tcx, expr.hir_id) diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index b2089487a9f4..49bc56083468 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -6,6 +6,7 @@ use clippy_utils::source::snippet; use clippy_utils::ty::{for_each_top_level_late_bound_region, is_copy}; use clippy_utils::{is_self, is_self_ty}; use core::ops::ControlFlow; +use rustc_abi::ExternAbi; use rustc_ast::attr; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; @@ -19,7 +20,6 @@ use rustc_middle::ty::{self, RegionKind, TyCtxt}; use rustc_session::impl_lint_pass; use rustc_span::def_id::LocalDefId; use rustc_span::{Span, sym}; -use rustc_target::spec::abi::Abi; declare_clippy_lint! { /// ### What it does @@ -136,7 +136,7 @@ impl PassByRefOrValue { } let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity(); - let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id)); + let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir_body(id)); // Gather all the lifetimes found in the output type which may affect whether // `TRIVIALLY_COPY_PASS_BY_REF` should be linted. @@ -179,10 +179,10 @@ impl PassByRefOrValue { && let hir::TyKind::Ref(_, MutTy { ty: decl_ty, .. }) = input.kind { if let Some(typeck) = cx.maybe_typeck_results() { - // Don't lint if an unsafe pointer is created. - // TODO: Limit the check only to unsafe pointers to the argument (or part of the argument) + // Don't lint if a raw pointer is created. + // TODO: Limit the check only to raw pointers to the argument (or part of the argument) // which escape the current function. - if typeck.node_types().items().any(|(_, &ty)| ty.is_unsafe_ptr()) + if typeck.node_types().items().any(|(_, &ty)| ty.is_raw_ptr()) || typeck .adjustments() .items() @@ -277,7 +277,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { let hir_id = cx.tcx.local_def_id_to_hir_id(def_id); match kind { FnKind::ItemFn(.., header) => { - if header.abi != Abi::Rust { + if header.abi != ExternAbi::Rust { return; } let attrs = cx.tcx.hir().attrs(hir_id); diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 0b67594a9b19..b622c57158ef 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -4,6 +4,7 @@ use clippy_utils::sugg::Sugg; use clippy_utils::visitors::contains_unsafe_block; use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local, std_or_core}; use hir::LifetimeName; +use rustc_abi::ExternAbi; use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::hir_id::{HirId, HirIdMap}; use rustc_hir::intravisit::{Visitor, walk_expr}; @@ -19,7 +20,6 @@ use rustc_middle::ty::{self, Binder, ClauseKind, ExistentialPredicate, List, Pre use rustc_session::declare_lint_pass; use rustc_span::symbol::Symbol; use rustc_span::{Span, sym}; -use rustc_target::spec::abi::Abi; use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use std::{fmt, iter}; @@ -160,7 +160,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { check_mut_from_ref(cx, sig, None); - if !matches!(sig.header.abi, Abi::Rust) { + if !matches!(sig.header.abi, ExternAbi::Rust) { // Ignore `extern` functions with non-Rust calling conventions return; } @@ -220,7 +220,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { check_mut_from_ref(cx, sig, Some(body)); - if !matches!(sig.header.abi, Abi::Rust) { + if !matches!(sig.header.abi, ExternAbi::Rust) { // Ignore `extern` functions with non-Rust calling conventions return; } @@ -583,8 +583,8 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, args: &[ } impl<'tcx> Visitor<'tcx> for V<'_, 'tcx> { type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_anon_const(&mut self, _: &'tcx AnonConst) {} diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index 808a7e005c67..68ae575c9063 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -111,7 +111,7 @@ fn is_expr_ty_usize(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { // Is the type of the expression a raw pointer? fn is_expr_ty_raw_ptr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - cx.typeck_results().expr_ty(expr).is_unsafe_ptr() + cx.typeck_results().expr_ty(expr).is_raw_ptr() } fn build_suggestion( diff --git a/clippy_lints/src/redundant_async_block.rs b/clippy_lints/src/redundant_async_block.rs index 65fd312b3a09..bc5e8fd2c258 100644 --- a/clippy_lints/src/redundant_async_block.rs +++ b/clippy_lints/src/redundant_async_block.rs @@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock { /// any variable by ref. fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { if let ExprKind::Closure(Closure { body, def_id, kind, .. }) = expr.kind - && let body = cx.tcx.hir().body(*body) + && let body = cx.tcx.hir_body(*body) && matches!( kind, ClosureKind::Coroutine(CoroutineKind::Desugared( diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 91d023500ca6..1498a49a7a4a 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -90,7 +90,7 @@ fn find_innermost_closure<'tcx>( let mut data = None; while let ExprKind::Closure(closure) = expr.kind - && let body = cx.tcx.hir().body(closure.body) + && let body = cx.tcx.hir_body(closure.body) && { let mut visitor = ReturnVisitor; !visitor.visit_expr(body.value).is_break() @@ -179,7 +179,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { // Like `async fn`, async closures are wrapped in an additional block // to move all of the closure's arguments into the future. - let async_closure_body = cx.tcx.hir().body(closure.body).value; + let async_closure_body = cx.tcx.hir_body(closure.body).value; let ExprKind::Block(block, _) = async_closure_body.kind else { return; }; @@ -241,8 +241,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { hir_visit::walk_expr(self, expr); } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } let mut closure_usage_count = ClosureUsageCount { cx, path, count: 0 }; diff --git a/clippy_lints/src/redundant_locals.rs b/clippy_lints/src/redundant_locals.rs index ebe3e7c20196..e15e12629209 100644 --- a/clippy_lints/src/redundant_locals.rs +++ b/clippy_lints/src/redundant_locals.rs @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals { /// assert_static(closure); /// ``` fn is_by_value_closure_capture(cx: &LateContext<'_>, redefinition: HirId, root_variable: HirId) -> bool { - let closure_def_id = cx.tcx.hir().enclosing_body_owner(redefinition); + let closure_def_id = cx.tcx.hir_enclosing_body_owner(redefinition); cx.tcx.is_closure_like(closure_def_id.to_def_id()) && cx.tcx.closure_captures(closure_def_id).iter().any(|c| { diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 0286c9843a94..5d1e845b5fcb 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -206,7 +206,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { // Ensure this is not the final stmt, otherwise removing it would cause a compile error && let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id)) && let ItemKind::Fn { body, .. } = item.kind - && let block = cx.tcx.hir().body(body).value + && let block = cx.tcx.hir_body(body).value && let ExprKind::Block(block, _) = block.kind && !is_inside_let_else(cx.tcx, expr) && let [.., final_stmt] = block.stmts diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index 29914d4379fe..552135b15fd8 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -50,9 +50,9 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { fn check_crate_post(&mut self, cx: &LateContext<'tcx>) { let mut map = FxHashMap::::default(); - for id in cx.tcx.hir().items() { + for id in cx.tcx.hir_free_items() { if matches!(cx.tcx.def_kind(id.owner_id), DefKind::Impl { .. }) - && let item = cx.tcx.hir().item(id) + && let item = cx.tcx.hir_item(id) && let ItemKind::Impl(Impl { items, of_trait, diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 83199ba0f707..a931e39bac9c 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -149,17 +149,15 @@ impl<'tcx> LateLintPass<'tcx> for Shadow { } fn check_body(&mut self, cx: &LateContext<'_>, body: &Body<'_>) { - let hir = cx.tcx.hir(); - let owner_id = hir.body_owner_def_id(body.id()); - if !matches!(hir.body_owner_kind(owner_id), BodyOwnerKind::Closure) { + let owner_id = cx.tcx.hir_body_owner_def_id(body.id()); + if !matches!(cx.tcx.hir_body_owner_kind(owner_id), BodyOwnerKind::Closure) { self.bindings.push((FxHashMap::default(), owner_id)); } } fn check_body_post(&mut self, cx: &LateContext<'_>, body: &Body<'_>) { - let hir = cx.tcx.hir(); if !matches!( - hir.body_owner_kind(hir.body_owner_def_id(body.id())), + cx.tcx.hir_body_owner_kind(cx.tcx.hir_body_owner_def_id(body.id())), BodyOwnerKind::Closure ) { self.bindings.pop(); diff --git a/clippy_lints/src/single_call_fn.rs b/clippy_lints/src/single_call_fn.rs index fdbccbaa8a59..1a2fb77acc15 100644 --- a/clippy_lints/src/single_call_fn.rs +++ b/clippy_lints/src/single_call_fn.rs @@ -90,8 +90,7 @@ impl SingleCallFn { || fn_span.in_external_macro(cx.sess().source_map()) || cx .tcx - .hir() - .maybe_body_owned_by(fn_def_id) + .hir_maybe_body_owned_by(fn_def_id) .is_none_or(|body| is_in_test_function(cx.tcx, body.value.hir_id)) || match cx.tcx.hir_node(fn_hir_id) { Node::Item(item) => is_from_proc_macro(cx, item), diff --git a/clippy_lints/src/single_option_map.rs b/clippy_lints/src/single_option_map.rs index ad8463870a68..1fb54950612a 100644 --- a/clippy_lints/src/single_option_map.rs +++ b/clippy_lints/src/single_option_map.rs @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for SingleOptionMap { && !matches!(args[0].kind, ExprKind::Path(_)) { if let ExprKind::Closure(closure) = args[0].kind { - let Body { params: [..], value } = cx.tcx.hir().body(closure.body); + let Body { params: [..], value } = cx.tcx.hir_body(closure.body); if let ExprKind::Call(func, f_args) = value.kind && matches!(func.kind, ExprKind::Path(_)) && f_args.iter().all(|arg| matches!(arg.kind, ExprKind::Path(_))) diff --git a/clippy_lints/src/string_patterns.rs b/clippy_lints/src/string_patterns.rs index 3834087f7977..694ad4f6347b 100644 --- a/clippy_lints/src/string_patterns.rs +++ b/clippy_lints/src/string_patterns.rs @@ -138,7 +138,7 @@ fn get_char_span<'tcx>(cx: &'_ LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Optio fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<'_>, msrv: &Msrv) { if let ExprKind::Closure(closure) = method_arg.kind - && let body = cx.tcx.hir().body(closure.body) + && let body = cx.tcx.hir_body(closure.body) && let Some(PatKind::Binding(_, binding, ..)) = body.params.first().map(|p| p.pat.kind) { let mut set_char_spans: Vec = Vec::new(); diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 6164a6191db0..4a5f143a2d34 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -2,8 +2,8 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_the use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::ty::is_type_lang_item; use clippy_utils::{ - SpanlessEq, get_expr_use_or_unification_node, get_parent_expr, is_lint_allowed, is_path_diagnostic_item, - method_calls, peel_blocks, + SpanlessEq, get_expr_use_or_unification_node, get_parent_expr, is_lint_allowed, method_calls, path_def_id, + peel_blocks, }; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; @@ -253,8 +253,9 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { use rustc_ast::LitKind; if let ExprKind::Call(fun, [bytes_arg]) = e.kind - // Find std::str::converts::from_utf8 - && is_path_diagnostic_item(cx, fun, sym::str_from_utf8) + // Find `std::str::converts::from_utf8` or `std::primitive::str::from_utf8` + && let Some(sym::str_from_utf8 | sym::str_inherent_from_utf8) = + path_def_id(cx, fun).and_then(|id| cx.tcx.get_diagnostic_name(id)) // Find string::as_bytes && let ExprKind::AddrOf(BorrowKind::Ref, _, args) = bytes_arg.kind diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index e9779d437d43..9326b2adaffb 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl { && let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id && let hir::Node::ImplItem(impl_item) = cx.tcx.hir_node_by_def_id(parent_fn) && let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind - && let body = cx.tcx.hir().body(body_id) + && let body = cx.tcx.hir_body(body_id) && let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id && let Some(trait_ref) = trait_ref_of_method(cx, parent_fn) && let trait_id = trait_ref.path.res.def_id() diff --git a/clippy_lints/src/swap_ptr_to_ref.rs b/clippy_lints/src/swap_ptr_to_ref.rs index 8c5cf93ab6e8..ff196355a2e3 100644 --- a/clippy_lints/src/swap_ptr_to_ref.rs +++ b/clippy_lints/src/swap_ptr_to_ref.rs @@ -76,7 +76,7 @@ impl LateLintPass<'_> for SwapPtrToRef { fn is_ptr_to_ref(cx: &LateContext<'_>, e: &Expr<'_>, ctxt: SyntaxContext) -> (bool, Option) { if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, borrowed_expr) = e.kind && let ExprKind::Unary(UnOp::Deref, derefed_expr) = borrowed_expr.kind - && cx.typeck_results().expr_ty(derefed_expr).is_unsafe_ptr() + && cx.typeck_results().expr_ty(derefed_expr).is_raw_ptr() { ( true, diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 790e0965198d..cbf7b126632e 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -135,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { && let Some(Node::Item(Item { kind: ItemKind::Trait(_, _, _, self_bounds, _), .. - })) = cx.tcx.hir().get_if_local(*def_id) + })) = cx.tcx.hir_get_if_local(*def_id) { if self_bounds_map.is_empty() { for bound in *self_bounds { diff --git a/clippy_lints/src/transmute/missing_transmute_annotations.rs b/clippy_lints/src/transmute/missing_transmute_annotations.rs index 4961dd6b280a..0b5d83ef58ca 100644 --- a/clippy_lints/src/transmute/missing_transmute_annotations.rs +++ b/clippy_lints/src/transmute/missing_transmute_annotations.rs @@ -28,8 +28,8 @@ fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId) } fn is_function_block(cx: &LateContext<'_>, expr_hir_id: HirId) -> bool { - let def_id = cx.tcx.hir().enclosing_body_owner(expr_hir_id); - if let Some(body) = cx.tcx.hir().maybe_body_owned_by(def_id) { + let def_id = cx.tcx.hir_enclosing_body_owner(expr_hir_id); + if let Some(body) = cx.tcx.hir_maybe_body_owned_by(def_id) { return body.value.peel_blocks().hir_id == expr_hir_id; } false diff --git a/clippy_lints/src/types/borrowed_box.rs b/clippy_lints/src/types/borrowed_box.rs index 2e97772407fd..004ad03e7085 100644 --- a/clippy_lints/src/types/borrowed_box.rs +++ b/clippy_lints/src/types/borrowed_box.rs @@ -96,10 +96,10 @@ fn is_any_trait(cx: &LateContext<'_>, t: &hir::Ty<'_>) -> bool { fn get_bounds_if_impl_trait<'tcx>(cx: &LateContext<'tcx>, qpath: &QPath<'_>, id: HirId) -> Option> { if let Some(did) = cx.qpath_res(qpath, id).opt_def_id() - && let Some(Node::GenericParam(generic_param)) = cx.tcx.hir().get_if_local(did) + && let Some(Node::GenericParam(generic_param)) = cx.tcx.hir_get_if_local(did) && let GenericParamKind::Type { synthetic, .. } = generic_param.kind && synthetic - && let Some(generics) = cx.tcx.hir().get_generics(id.owner.def_id) + && let Some(generics) = cx.tcx.hir_get_generics(id.owner.def_id) && let Some(pred) = generics.bounds_for_param(did.expect_local()).next() { Some(pred.bounds) diff --git a/clippy_lints/src/types/type_complexity.rs b/clippy_lints/src/types/type_complexity.rs index 7f51660293b5..0704653385f1 100644 --- a/clippy_lints/src/types/type_complexity.rs +++ b/clippy_lints/src/types/type_complexity.rs @@ -1,9 +1,9 @@ use clippy_utils::diagnostics::span_lint; +use rustc_abi::ExternAbi; use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_ty}; use rustc_hir::{self as hir, AmbigArg, GenericParamKind, TyKind}; use rustc_lint::LateContext; use rustc_span::Span; -use rustc_target::spec::abi::Abi; use super::TYPE_COMPLEXITY; @@ -50,7 +50,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { TyKind::Path(..) | TyKind::Slice(..) | TyKind::Tup(..) | TyKind::Array(..) => (10 * self.nest, 1), // function types bring a lot of overhead - TyKind::BareFn(bare) if bare.abi == Abi::Rust => (50 * self.nest, 1), + TyKind::BareFn(bare) if bare.abi == ExternAbi::Rust => (50 * self.nest, 1), TyKind::TraitObject(param_bounds, _) => { let has_lifetime_parameters = param_bounds.iter().any(|bound| { diff --git a/clippy_lints/src/unconditional_recursion.rs b/clippy_lints/src/unconditional_recursion.rs index 207f2ef4563a..76a0b927df42 100644 --- a/clippy_lints/src/unconditional_recursion.rs +++ b/clippy_lints/src/unconditional_recursion.rs @@ -9,7 +9,6 @@ use rustc_hir::intravisit::{FnKind, Visitor, walk_body, walk_expr}; use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, Node, QPath, TyKind}; use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, AssocKind, Ty, TyCtxt}; use rustc_session::impl_lint_pass; @@ -275,7 +274,6 @@ fn is_default_method_on_current_ty<'tcx>(tcx: TyCtxt<'tcx>, qpath: QPath<'tcx>, struct CheckCalls<'a, 'tcx> { cx: &'a LateContext<'tcx>, - map: Map<'tcx>, implemented_ty_id: DefId, method_span: Span, } @@ -287,8 +285,8 @@ where type NestedFilter = nested_filter::OnlyBodies; type Result = ControlFlow<()>; - fn nested_visit_map(&mut self) -> Self::Map { - self.map + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) -> ControlFlow<()> { @@ -326,15 +324,15 @@ impl UnconditionalRecursion { .find(|item| { item.kind == AssocKind::Fn && item.def_id.is_local() && item.name == kw::Default }) - && let Some(body_node) = cx.tcx.hir().get_if_local(assoc_item.def_id) + && let Some(body_node) = cx.tcx.hir_get_if_local(assoc_item.def_id) && let Some(body_id) = body_node.body_id() - && let body = cx.tcx.hir().body(body_id) + && let body = cx.tcx.hir_body(body_id) // We don't want to keep it if it has conditional return. && let [return_expr] = get_return_calls_in_body(body).as_slice() && let ExprKind::Call(call_expr, _) = return_expr.kind // We need to use typeck here to infer the actual function being called. - && let body_def_id = cx.tcx.hir().enclosing_body_owner(call_expr.hir_id) - && let Some(body_owner) = cx.tcx.hir().maybe_body_owned_by(body_def_id) + && let body_def_id = cx.tcx.hir_enclosing_body_owner(call_expr.hir_id) + && let Some(body_owner) = cx.tcx.hir_maybe_body_owned_by(body_def_id) && let typeck = cx.tcx.typeck_body(body_owner.id()) && let Some(call_def_id) = typeck.type_dependent_def_id(call_expr.hir_id) { @@ -380,7 +378,6 @@ impl UnconditionalRecursion { { let mut c = CheckCalls { cx, - map: cx.tcx.hir(), implemented_ty_id, method_span, }; diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index 5e5d6a9e333b..95acb48adb01 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -1,4 +1,5 @@ use std::ops::ControlFlow; +use std::sync::Arc; use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; @@ -6,7 +7,6 @@ use clippy_utils::is_lint_allowed; use clippy_utils::source::walk_span_to_context; use clippy_utils::visitors::{Descend, for_each_expr}; use hir::HirId; -use rustc_data_structures::sync::Lrc; use rustc_hir as hir; use rustc_hir::{Block, BlockCheckMode, ItemKind, Node, UnsafeSource}; use rustc_lexer::{TokenKind, tokenize}; @@ -245,7 +245,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks { // const and static items only need a safety comment if their body is an unsafe block, lint otherwise (&ItemKind::Const(.., body) | &ItemKind::Static(.., body), HasSafetyComment::Yes(pos)) => { if !is_lint_allowed(cx, UNNECESSARY_SAFETY_COMMENT, body.hir_id) { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); if !matches!( body.value.kind, hir::ExprKind::Block(block, _) if block.rules == BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) @@ -480,7 +480,7 @@ fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> HasSaf if let Some(comment_start) = comment_start && let Ok(unsafe_line) = source_map.lookup_line(item.span.lo()) && let Ok(comment_start_line) = source_map.lookup_line(comment_start) - && Lrc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf) + && Arc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf) && let Some(src) = unsafe_line.sf.src.as_deref() { return if comment_start_line.line >= unsafe_line.line { @@ -520,7 +520,7 @@ fn stmt_has_safety_comment(cx: &LateContext<'_>, span: Span, hir_id: HirId) -> H if let Some(comment_start) = comment_start && let Ok(unsafe_line) = source_map.lookup_line(span.lo()) && let Ok(comment_start_line) = source_map.lookup_line(comment_start) - && Lrc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf) + && Arc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf) && let Some(src) = unsafe_line.sf.src.as_deref() { return if comment_start_line.line >= unsafe_line.line { @@ -558,7 +558,7 @@ fn comment_start_before_item_in_mod( // some_item /* comment */ unsafe impl T {} // ^-------^ returns the end of this span // ^---------------^ finally checks comments in this range - let prev_item = cx.tcx.hir().item(parent_mod.item_ids[idx - 1]); + let prev_item = cx.tcx.hir_item(parent_mod.item_ids[idx - 1]); if let Some(sp) = walk_span_to_context(prev_item.span, SyntaxContext::root()) { return Some(sp.hi()); } @@ -580,7 +580,7 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span // ^--------------------------------------------^ if let Ok(unsafe_line) = source_map.lookup_line(span.lo()) && let Ok(macro_line) = source_map.lookup_line(ctxt.outer_expn_data().def_site.lo()) - && Lrc::ptr_eq(&unsafe_line.sf, ¯o_line.sf) + && Arc::ptr_eq(&unsafe_line.sf, ¯o_line.sf) && let Some(src) = unsafe_line.sf.src.as_deref() { if macro_line.line < unsafe_line.line { @@ -605,7 +605,7 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span fn get_body_search_span(cx: &LateContext<'_>) -> Option { let body = cx.enclosing_body?; let map = cx.tcx.hir(); - let mut span = map.body(body).value.span; + let mut span = cx.tcx.hir_body(body).value.span; let mut maybe_global_var = false; for (_, node) in map.parent_iter(body.hir_id) { match node { @@ -641,7 +641,7 @@ fn span_has_safety_comment(cx: &LateContext<'_>, span: Span) -> bool { if let Ok(unsafe_line) = source_map.lookup_line(span.lo()) && let Some(body_span) = walk_span_to_context(search_span, SyntaxContext::root()) && let Ok(body_line) = source_map.lookup_line(body_span.lo()) - && Lrc::ptr_eq(&unsafe_line.sf, &body_line.sf) + && Arc::ptr_eq(&unsafe_line.sf, &body_line.sf) && let Some(src) = unsafe_line.sf.src.as_deref() { // Get the text from the start of function body to the unsafe block. diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 87478a120dd0..67ceac92dbc0 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -123,7 +123,7 @@ fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Spa && let ty = cx.tcx.instantiate_bound_regions_with_erased(ret_ty) && ty.is_unit() { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); if let ExprKind::Block(block, _) = body.value.kind && block.expr.is_none() && let Some(stmt) = block.stmts.last() diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index 00b80e827d8a..87f184e13ce1 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -84,7 +84,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) { if let PatKind::Binding(_, binding_hir_id, ..) = local.pat.kind && let Some(body_id) = cx.enclosing_body.as_ref() { - let body = cx.tcx.hir().body(*body_id); + let body = cx.tcx.hir_body(*body_id); // Collect variable usages let mut visitor = UnitVariableCollector::new(binding_hir_id); diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index d00bd7f2b3db..1c1c841e9641 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -101,8 +101,8 @@ impl<'tcx> Visitor<'tcx> for AsyncFnVisitor<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/unused_peekable.rs b/clippy_lints/src/unused_peekable.rs index 71aa57e0a14c..0f9b05c84d4b 100644 --- a/clippy_lints/src/unused_peekable.rs +++ b/clippy_lints/src/unused_peekable.rs @@ -112,8 +112,8 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> { type NestedFilter = OnlyBodies; type Result = ControlFlow<()>; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) -> ControlFlow<()> { diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index 781f51aa9b07..d8305a628290 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { && assoc_item.fn_has_self_parameter && let ImplItemKind::Fn(.., body_id) = &impl_item.kind && (!cx.effective_visibilities.is_exported(impl_item.owner_id.def_id) || !self.avoid_breaking_exported_api) - && let body = cx.tcx.hir().body(*body_id) + && let body = cx.tcx.hir_body(*body_id) && let [self_param, ..] = body.params && !is_local_used(cx, body, self_param.pat.hir_id) && !contains_todo(cx, body) diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 6a952c0d97aa..76b9bbbd32fd 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -374,8 +374,8 @@ impl<'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index 9b9a2ffbbc80..f870eb71e19b 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for UnwrapInResult { fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tcx hir::ImplItem<'_>) { if let ImplItemKind::Fn(_, body_id) = impl_item.kind { - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let typeck = cx.tcx.typeck(impl_item.owner_id.def_id); let mut result = Vec::new(); let _: Option = for_each_expr(cx, body.value, |e| { diff --git a/clippy_lints/src/utils/attr_collector.rs b/clippy_lints/src/utils/attr_collector.rs index 1522553bbf52..169429811d32 100644 --- a/clippy_lints/src/utils/attr_collector.rs +++ b/clippy_lints/src/utils/attr_collector.rs @@ -1,14 +1,13 @@ use std::mem; -use std::sync::OnceLock; +use std::sync::{Arc, OnceLock}; use rustc_ast::{Attribute, Crate}; -use rustc_data_structures::sync::Lrc; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::impl_lint_pass; use rustc_span::Span; #[derive(Clone, Default)] -pub struct AttrStorage(pub Lrc>>); +pub struct AttrStorage(pub Arc>>); pub struct AttrCollector { storage: AttrStorage, diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 6bad78cf8718..5fc166438e84 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -132,8 +132,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { } fn check_item(cx: &LateContext<'_>, hir_id: HirId) { - let hir = cx.tcx.hir(); - if let Some(body) = hir.maybe_body_owned_by(hir_id.expect_owner().def_id) { + if let Some(body) = cx.tcx.hir_maybe_body_owned_by(hir_id.expect_owner().def_id) { check_node(cx, hir_id, |v| { v.expr(&v.bind("expr", body.value)); }); @@ -637,9 +636,9 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { } fn body(&self, body_id: &Binding) { - let expr = self.cx.tcx.hir().body(body_id.value).value; + let expr = self.cx.tcx.hir_body(body_id.value).value; bind!(self, expr); - chain!(self, "{expr} = &cx.tcx.hir().body({body_id}).value"); + chain!(self, "{expr} = &cx.tcx.hir_body({body_id}).value"); self.expr(expr); } diff --git a/clippy_lints/src/utils/internal_lints/collapsible_calls.rs b/clippy_lints/src/utils/internal_lints/collapsible_calls.rs index eaeb754a23f1..2e6fb7c4ce4d 100644 --- a/clippy_lints/src/utils/internal_lints/collapsible_calls.rs +++ b/clippy_lints/src/utils/internal_lints/collapsible_calls.rs @@ -80,7 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls { if let ExprKind::Call(func, [call_cx, call_lint, call_sp, call_msg, call_f]) = expr.kind && is_expr_path_def_path(cx, func, &["clippy_utils", "diagnostics", "span_lint_and_then"]) && let ExprKind::Closure(&Closure { body, .. }) = call_f.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) && let only_expr = peel_blocks_with_stmt(body.value) && let ExprKind::MethodCall(ps, recv, span_call_args, _) = &only_expr.kind && let ExprKind::Path(..) = recv.kind diff --git a/clippy_lints/src/utils/internal_lints/invalid_paths.rs b/clippy_lints/src/utils/internal_lints/invalid_paths.rs index 08c178ed229f..252ac5e67682 100644 --- a/clippy_lints/src/utils/internal_lints/invalid_paths.rs +++ b/clippy_lints/src/utils/internal_lints/invalid_paths.rs @@ -37,7 +37,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidPaths { ty::TypingEnv::post_analysis(cx.tcx, item.owner_id), cx.tcx.typeck(item.owner_id), ) - .eval_simple(cx.tcx.hir().body(body_id).value) + .eval_simple(cx.tcx.hir_body(body_id).value) && let Some(path) = path .iter() .map(|x| { diff --git a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs index dac1951489ca..713fd07bd278 100644 --- a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs +++ b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs @@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { if is_lint_ref_type(cx, ty) { check_invalid_clippy_version_attribute(cx, item); - let expr = &cx.tcx.hir().body(body_id).value; + let expr = &cx.tcx.hir_body(body_id).value; let fields = if let ExprKind::AddrOf(_, _, inner_exp) = expr.kind && let ExprKind::Struct(_, struct_fields, _) = inner_exp.kind { @@ -156,7 +156,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { output: &mut self.registered_lints, cx, }; - let body = cx.tcx.hir().body_owned_by( + let body = cx.tcx.hir_body_owned_by( impl_item_refs .iter() .find(|iiref| iiref.ident.as_str() == "lint_vec") @@ -277,7 +277,7 @@ impl<'tcx> Visitor<'tcx> for LintCollector<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/zero_repeat_side_effects.rs b/clippy_lints/src/zero_repeat_side_effects.rs index 05f856507697..30fdf22fdbb0 100644 --- a/clippy_lints/src/zero_repeat_side_effects.rs +++ b/clippy_lints/src/zero_repeat_side_effects.rs @@ -47,7 +47,6 @@ declare_lint_pass!(ZeroRepeatSideEffects => [ZERO_REPEAT_SIDE_EFFECTS]); impl LateLintPass<'_> for ZeroRepeatSideEffects { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &rustc_hir::Expr<'_>) { - let hir_map = cx.tcx.hir(); if let Some(args) = VecArgs::hir(cx, expr) && let VecArgs::Repeat(inner_expr, len) = args && let ExprKind::Lit(l) = len.kind @@ -62,7 +61,7 @@ impl LateLintPass<'_> for ZeroRepeatSideEffects { // sessions). else if let ExprKind::Repeat(inner_expr, const_arg) = expr.kind && let ConstArgKind::Anon(anon_const) = const_arg.kind - && let length_expr = hir_map.body(anon_const.body).value + && let length_expr = cx.tcx.hir_body(anon_const.body).value && !length_expr.span.from_expansion() && let ExprKind::Lit(literal) = length_expr.kind && let LitKind::Int(Pu128(0), _) = literal.node diff --git a/clippy_lints/src/zombie_processes.rs b/clippy_lints/src/zombie_processes.rs index 4df34891a2b1..7667db469689 100644 --- a/clippy_lints/src/zombie_processes.rs +++ b/clippy_lints/src/zombie_processes.rs @@ -1,6 +1,6 @@ use ControlFlow::{Break, Continue}; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::{fn_def_id, get_enclosing_block, match_any_def_paths, match_def_path, path_to_local_id, paths}; +use clippy_utils::{fn_def_id, get_enclosing_block, path_to_local_id}; use rustc_ast::Mutability; use rustc_ast::visit::visit_opt; use rustc_errors::Applicability; @@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for ZombieProcesses { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if let ExprKind::Call(..) | ExprKind::MethodCall(..) = expr.kind && let Some(child_adt) = cx.typeck_results().expr_ty(expr).ty_adt_def() - && match_def_path(cx, child_adt.did(), &paths::CHILD) + && cx.tcx.is_diagnostic_item(sym::Child, child_adt.did()) { match cx.tcx.parent_hir_node(expr.hir_id) { Node::LetStmt(local) @@ -178,8 +178,8 @@ impl<'tcx> Visitor<'tcx> for WaitFinder<'_, 'tcx> { Node::Expr(expr) if let ExprKind::AddrOf(_, Mutability::Not, _) = expr.kind => {}, Node::Expr(expr) if let Some(fn_did) = fn_def_id(self.cx, expr) - && match_any_def_paths(self.cx, fn_did, &[&paths::CHILD_ID, &paths::CHILD_KILL]).is_some() => { - }, + && (self.cx.tcx.is_diagnostic_item(sym::child_id, fn_did) + || self.cx.tcx.is_diagnostic_item(sym::child_kill, fn_did)) => {}, // Conservatively assume that all other kinds of nodes call `.wait()` somehow. _ => return Break(MaybeWait(ex.span)), @@ -249,8 +249,8 @@ impl<'tcx> Visitor<'tcx> for WaitFinder<'_, 'tcx> { walk_expr(self, ex) } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } @@ -353,7 +353,7 @@ fn check<'tcx>(cx: &LateContext<'tcx>, spawn_expr: &'tcx Expr<'tcx>, cause: Caus /// Checks if the given expression exits the process. fn is_exit_expression(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { fn_def_id(cx, expr).is_some_and(|fn_did| { - cx.tcx.is_diagnostic_item(sym::process_exit, fn_did) || match_def_path(cx, fn_did, &paths::ABORT) + cx.tcx.is_diagnostic_item(sym::process_exit, fn_did) || cx.tcx.is_diagnostic_item(sym::process_abort, fn_did) }) } diff --git a/clippy_utils/Cargo.toml b/clippy_utils/Cargo.toml index 68b7e1592e2e..ba4bb1d177c5 100644 --- a/clippy_utils/Cargo.toml +++ b/clippy_utils/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_utils" # begin autogenerated version -version = "0.1.86" +version = "0.1.87" # end autogenerated version edition = "2024" description = "Helpful tools for writing lints, provided as they are used in Clippy" diff --git a/clippy_utils/README.md b/clippy_utils/README.md index 41f3b1cbd507..e513d9354507 100644 --- a/clippy_utils/README.md +++ b/clippy_utils/README.md @@ -8,7 +8,7 @@ This crate is only guaranteed to build with this `nightly` toolchain: ``` -nightly-2025-02-06 +nightly-2025-02-20 ``` diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 179d42a8b5dc..4f48fb3b8a96 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -12,6 +12,7 @@ //! code was written, and check if the span contains that text. Note this will only work correctly //! if the span is not from a `macro_rules` based macro. +use rustc_abi::ExternAbi; use rustc_ast::AttrStyle; use rustc_ast::ast::{AttrKind, Attribute, IntTy, LitIntType, LitKind, StrStyle, TraitObjectSyntax, UintTy}; use rustc_ast::token::CommentKind; @@ -26,7 +27,6 @@ use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_span::symbol::{Ident, kw}; use rustc_span::{Span, Symbol}; -use rustc_target::spec::abi::Abi; /// The search pattern to look for. Used by `span_matches_pat` #[derive(Clone)] @@ -192,7 +192,7 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) { }, ExprKind::Closure(&Closure { body, .. }) => ( Pat::Str(""), - expr_search_pat_inner(tcx, tcx.hir().body(body).value, outer_span).1, + expr_search_pat_inner(tcx, tcx.hir_body(body).value, outer_span).1, ), ExprKind::Block( Block { @@ -233,7 +233,7 @@ fn fn_header_search_pat(header: FnHeader) -> Pat { Pat::Str("const") } else if header.is_unsafe() { Pat::Str("unsafe") - } else if header.abi != Abi::Rust { + } else if header.abi != ExternAbi::Rust { Pat::Str("extern") } else { Pat::MultiStr(&["fn", "extern"]) @@ -375,7 +375,7 @@ fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) { TyKind::BareFn(bare_fn) => ( if bare_fn.safety.is_unsafe() { Pat::Str("unsafe") - } else if bare_fn.abi != Abi::Rust { + } else if bare_fn.abi != ExternAbi::Rust { Pat::Str("extern") } else { Pat::MultiStr(&["fn", "extern"]) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index a660623f4185..4f707e34abf9 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -4,13 +4,15 @@ //! executable MIR bodies, so we have to do this instead. #![allow(clippy::float_cmp)] +use std::sync::Arc; + use crate::source::{SpanRangeExt, walk_span_to_context}; use crate::{clip, is_direct_expn_of, sext, unsext}; +use rustc_abi::Size; use rustc_apfloat::Float; use rustc_apfloat::ieee::{Half, Quad}; use rustc_ast::ast::{self, LitFloatType, LitKind}; -use rustc_data_structures::sync::Lrc; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{ BinOp, BinOpKind, Block, ConstBlock, Expr, ExprKind, HirId, Item, ItemKind, Node, PatExpr, PatExprKind, QPath, UnOp, @@ -24,7 +26,6 @@ use rustc_middle::{bug, mir, span_bug}; use rustc_span::def_id::DefId; use rustc_span::symbol::Ident; use rustc_span::{SyntaxContext, sym}; -use rustc_target::abi::Size; use std::cell::Cell; use std::cmp::Ordering; use std::hash::{Hash, Hasher}; @@ -37,7 +38,7 @@ pub enum Constant<'tcx> { /// A `String` (e.g., "abc"). Str(String), /// A binary string (e.g., `b"abc"`). - Binary(Lrc<[u8]>), + Binary(Arc<[u8]>), /// A single `char` (e.g., `'a'`). Char(char), /// An integer's bit representation. @@ -305,7 +306,7 @@ pub fn lit_to_mir_constant<'tcx>(lit: &LitKind, ty: Option>) -> Constan match *lit { LitKind::Str(ref is, _) => Constant::Str(is.to_string()), LitKind::Byte(b) => Constant::Int(u128::from(b)), - LitKind::ByteStr(ref s, _) | LitKind::CStr(ref s, _) => Constant::Binary(Lrc::clone(s)), + LitKind::ByteStr(ref s, _) | LitKind::CStr(ref s, _) => Constant::Binary(Arc::clone(s)), LitKind::Char(c) => Constant::Char(c), LitKind::Int(n, _) => Constant::Int(n.get()), LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { @@ -454,7 +455,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { Some(val) } }, - PatExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.tcx.hir().body(*body).value), + PatExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.tcx.hir_body(*body).value), PatExprKind::Path(qpath) => self.qpath(qpath, pat_expr.hir_id), } } @@ -482,7 +483,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { /// Simple constant folding: Insert an expression, get a constant or none. fn expr(&self, e: &Expr<'_>) -> Option> { match e.kind { - ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.tcx.hir().body(body).value), + ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.tcx.hir_body(body).value), ExprKind::DropTemps(e) => self.expr(e), ExprKind::Path(ref qpath) => self.qpath(qpath, e.hir_id), ExprKind::Block(block, _) => self.block(block), @@ -549,7 +550,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { /// leaves the local crate. pub fn eval_is_empty(&self, e: &Expr<'_>) -> Option { match e.kind { - ExprKind::ConstBlock(ConstBlock { body, .. }) => self.eval_is_empty(self.tcx.hir().body(body).value), + ExprKind::ConstBlock(ConstBlock { body, .. }) => self.eval_is_empty(self.tcx.hir_body(body).value), ExprKind::DropTemps(e) => self.eval_is_empty(e), ExprKind::Path(ref qpath) => { if !self @@ -644,7 +645,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { Res::Def(DefKind::Const | DefKind::AssocConst, def_id) => { // Check if this constant is based on `cfg!(..)`, // which is NOT constant for our purposes. - if let Some(node) = self.tcx.hir().get_if_local(def_id) + if let Some(node) = self.tcx.hir_get_if_local(def_id) && let Node::Item(Item { kind: ItemKind::Const(.., body_id), .. diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index b5bb174e737a..aaea8d71efbe 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -217,7 +217,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS self.eagerness |= NoChange; }, // Dereferences should be cheap, but dereferencing a raw pointer earlier may not be safe. - ExprKind::Unary(UnOp::Deref, e) if !self.cx.typeck_results().expr_ty(e).is_unsafe_ptr() => (), + ExprKind::Unary(UnOp::Deref, e) if !self.cx.typeck_results().expr_ty(e).is_raw_ptr() => (), ExprKind::Unary(UnOp::Deref, _) => self.eagerness |= NoChange, ExprKind::Unary(_, e) if matches!( diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 4bbf28115a68..9ee30094d608 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -273,8 +273,8 @@ impl HirEqInterExpr<'_, '_, '_> { self.inner.cx.tcx.typeck_body(right), )); let res = self.eq_expr( - self.inner.cx.tcx.hir().body(left).value, - self.inner.cx.tcx.hir().body(right).value, + self.inner.cx.tcx.hir_body(left).value, + self.inner.cx.tcx.hir_body(right).value, ); self.inner.maybe_typeck_results = old_maybe_typeck_results; res @@ -906,7 +906,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { }) => { std::mem::discriminant(&capture_clause).hash(&mut self.s); // closures inherit TypeckResults - self.hash_expr(self.cx.tcx.hir().body(body).value); + self.hash_expr(self.cx.tcx.hir_body(body).value); }, ExprKind::ConstBlock(ref l_id) => { self.hash_body(l_id.body); @@ -1316,7 +1316,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { pub fn hash_body(&mut self, body_id: BodyId) { // swap out TypeckResults when hashing a body let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body_id)); - self.hash_expr(self.cx.tcx.hir().body(body_id).value); + self.hash_expr(self.cx.tcx.hir_body(body_id).value); self.maybe_typeck_results = old_maybe_typeck_results; } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 0c6ff4503d07..62f70a5d957f 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -29,6 +29,7 @@ // FIXME: switch to something more ergonomic here, once available. // (Currently there is no way to opt into sysroot crates without `extern crate`.) +extern crate rustc_abi; extern crate rustc_ast; extern crate rustc_ast_pretty; extern crate rustc_attr_parsing; @@ -49,7 +50,6 @@ extern crate rustc_middle; extern crate rustc_mir_dataflow; extern crate rustc_session; extern crate rustc_span; -extern crate rustc_target; extern crate rustc_trait_selection; extern crate smallvec; @@ -93,6 +93,7 @@ use std::iter::{once, repeat_n}; use std::sync::{Mutex, MutexGuard, OnceLock}; use itertools::Itertools; +use rustc_abi::Integer; use rustc_ast::ast::{self, LitKind, RangeLimits}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::packed::Pu128; @@ -125,7 +126,6 @@ use rustc_span::hygiene::{ExpnKind, MacroKind}; use rustc_span::source_map::SourceMap; use rustc_span::symbol::{Ident, Symbol, kw}; use rustc_span::{InnerSpan, Span, sym}; -use rustc_target::abi::Integer; use visitors::{Visitable, for_each_unconsumed_temporary}; use crate::consts::{ConstEvalCtxt, Constant, mir_to_const}; @@ -239,8 +239,7 @@ pub fn is_in_const_context(cx: &LateContext<'_>) -> bool { debug_assert!(cx.enclosing_body.is_some(), "`LateContext` has no enclosing body"); cx.enclosing_body.is_some_and(|id| { cx.tcx - .hir() - .body_const_context(cx.tcx.hir().body_owner_def_id(id)) + .hir_body_const_context(cx.tcx.hir_body_owner_def_id(id)) .is_some() }) } @@ -253,8 +252,7 @@ pub fn is_in_const_context(cx: &LateContext<'_>) -> bool { /// * associated constants pub fn is_inside_always_const_context(tcx: TyCtxt<'_>, hir_id: HirId) -> bool { use ConstContext::{Const, ConstFn, Static}; - let hir = tcx.hir(); - let Some(ctx) = hir.body_const_context(hir.enclosing_body_owner(hir_id)) else { + let Some(ctx) = tcx.hir_body_const_context(tcx.hir_enclosing_body_owner(hir_id)) else { return false; }; match ctx { @@ -654,8 +652,6 @@ fn non_local_item_children_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) } fn local_item_children_by_name(tcx: TyCtxt<'_>, local_id: LocalDefId, name: Symbol) -> Vec { - let hir = tcx.hir(); - let root_mod; let item_kind = match tcx.hir_node_by_def_id(local_id) { Node::Crate(r#mod) => { @@ -679,7 +675,7 @@ fn local_item_children_by_name(tcx: TyCtxt<'_>, local_id: LocalDefId, name: Symb ItemKind::Mod(r#mod) => r#mod .item_ids .iter() - .filter_map(|&item_id| res(hir.item(item_id).ident, item_id.owner_id)) + .filter_map(|&item_id| res(tcx.hir_item(item_id).ident, item_id.owner_id)) .collect(), ItemKind::Impl(r#impl) => r#impl .items @@ -1025,7 +1021,7 @@ pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { ExprKind::Tup(items) | ExprKind::Array(items) => items.iter().all(|x| is_default_equivalent(cx, x)), ExprKind::Repeat(x, len) => { if let ConstArgKind::Anon(anon_const) = len.kind - && let ExprKind::Lit(const_lit) = cx.tcx.hir().body(anon_const.body).value.kind + && let ExprKind::Lit(const_lit) = cx.tcx.hir_body(anon_const.body).value.kind && let LitKind::Int(v, _) = const_lit.node && v <= 32 && is_default_equivalent(cx, x) @@ -1055,7 +1051,7 @@ fn is_default_equivalent_from(cx: &LateContext<'_>, from_func: &Expr<'_>, arg: & ExprKind::Array([]) => return is_path_diagnostic_item(cx, ty, sym::Vec), ExprKind::Repeat(_, len) => { if let ConstArgKind::Anon(anon_const) = len.kind - && let ExprKind::Lit(const_lit) = cx.tcx.hir().body(anon_const.body).value.kind + && let ExprKind::Lit(const_lit) = cx.tcx.hir_body(anon_const.body).value.kind && let LitKind::Int(v, _) = const_lit.node { return v == 0 && is_path_diagnostic_item(cx, ty, sym::Vec); @@ -1453,8 +1449,8 @@ impl<'tcx> Visitor<'tcx> for ContainsName<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } @@ -1509,7 +1505,7 @@ pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio | Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(_, TraitFn::Provided(eid)), .. - }) => match cx.tcx.hir().body(eid).value.kind { + }) => match cx.tcx.hir_body(eid).value.kind { ExprKind::Block(block, _) => Some(block), _ => None, }, @@ -1735,7 +1731,7 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool if is_integer_literal(e, value) { return true; } - let enclosing_body = cx.tcx.hir().enclosing_body_owner(e.hir_id); + let enclosing_body = cx.tcx.hir_enclosing_body_owner(e.hir_id); if let Some(Constant::Int(v)) = ConstEvalCtxt::with_env(cx.tcx, cx.typing_env(), cx.tcx.typeck(enclosing_body)).eval(e) { @@ -1746,6 +1742,7 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool /// Checks whether the given expression is a constant literal of the given value. pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool { + // FIXME: use constant folding if let ExprKind::Lit(spanned) = expr.kind { if let LitKind::Int(v, _) = spanned.node { return v == value; @@ -2151,7 +2148,7 @@ pub fn get_async_fn_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'t .. }, _, - ) = tcx.hir().body(body).value.kind + ) = tcx.hir_body(body).value.kind { return Some(expr); } @@ -2259,7 +2256,7 @@ pub fn is_expr_untyped_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) ExprKind::Closure(&Closure { body, fn_decl, .. }) if fn_decl.inputs.iter().all(|ty| matches!(ty.kind, TyKind::Infer(()))) => { - is_body_identity_function(cx, cx.tcx.hir().body(body)) + is_body_identity_function(cx, cx.tcx.hir_body(body)) }, ExprKind::Path(QPath::Resolved(_, path)) if path.segments.iter().all(|seg| seg.infer_args) @@ -2281,7 +2278,7 @@ pub fn is_expr_untyped_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) /// errors. pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { match expr.kind { - ExprKind::Closure(&Closure { body, .. }) => is_body_identity_function(cx, cx.tcx.hir().body(body)), + ExprKind::Closure(&Closure { body, .. }) => is_body_identity_function(cx, cx.tcx.hir_body(body)), _ => path_def_id(cx, expr).is_some_and(|id| cx.tcx.is_diagnostic_item(sym::convert_identity, id)), } } @@ -2636,9 +2633,9 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl Fn(&[Sym Entry::Occupied(entry) => f(entry.get()), Entry::Vacant(entry) => { let mut names = Vec::new(); - for id in tcx.hir().module_items(module) { + for id in tcx.hir_module_free_items(module) { if matches!(tcx.def_kind(id.owner_id), DefKind::Const) - && let item = tcx.hir().item(id) + && let item = tcx.hir_item(id) && let ItemKind::Const(ty, _generics, _body) = item.kind { if let TyKind::Path(QPath::Resolved(_, path)) = ty.kind { @@ -2848,7 +2845,7 @@ impl<'tcx> ExprUseCtxt<'tcx> { Node::Expr(use_expr) => match use_expr.kind { ExprKind::Ret(_) => ExprUseNode::Return(OwnerId { - def_id: cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()), + def_id: cx.tcx.hir_body_owner_def_id(cx.enclosing_body.unwrap()), }), ExprKind::Closure(closure) => ExprUseNode::Return(OwnerId { def_id: closure.def_id }), @@ -3016,7 +3013,7 @@ pub fn expr_use_ctxt<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> ExprU #[allow(unreachable_patterns)] Some(ControlFlow::Break(_)) => unreachable!("type of node is ControlFlow"), None => ExprUseCtxt { - node: Node::Crate(cx.tcx.hir().root_module()), + node: Node::Crate(cx.tcx.hir_root_module()), child_id: HirId::INVALID, adjustments: &[], is_ty_unified: true, diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index f4c730ef118b..30fd48fc0605 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -1,12 +1,14 @@ #![allow(clippy::similar_names)] // `expr` and `expn` +use std::sync::Arc; + use crate::get_unique_attr; use crate::visitors::{Descend, for_each_expr_without_closures}; use arrayvec::ArrayVec; use rustc_ast::{FormatArgs, FormatArgument, FormatPlaceholder}; use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::sync::{Lrc, OnceLock}; +use rustc_data_structures::sync::OnceLock; use rustc_hir::{self as hir, Expr, ExprKind, HirId, Node, QPath}; use rustc_lint::{LateContext, LintContext}; use rustc_span::def_id::DefId; @@ -393,7 +395,7 @@ fn is_assert_arg(cx: &LateContext<'_>, expr: &Expr<'_>, assert_expn: ExpnId) -> /// Stores AST [`FormatArgs`] nodes for use in late lint passes, as they are in a desugared form in /// the HIR #[derive(Default, Clone)] -pub struct FormatArgsStorage(Lrc>>); +pub struct FormatArgsStorage(Arc>>); impl FormatArgsStorage { /// Returns an AST [`FormatArgs`] node if a `format_args` expansion is found as a descendant of diff --git a/clippy_utils/src/mir/mod.rs b/clippy_utils/src/mir/mod.rs index 85250f81dc47..637c0bafd964 100644 --- a/clippy_utils/src/mir/mod.rs +++ b/clippy_utils/src/mir/mod.rs @@ -136,8 +136,8 @@ pub fn used_exactly_once(mir: &Body<'_>, local: Local) -> Option { /// Returns the `mir::Body` containing the node associated with `hir_id`. #[allow(clippy::module_name_repetitions)] pub fn enclosing_mir(tcx: TyCtxt<'_>, hir_id: HirId) -> Option<&Body<'_>> { - let body_owner_local_def_id = tcx.hir().enclosing_body_owner(hir_id); - if tcx.hir().body_owner_kind(body_owner_local_def_id).is_fn_or_closure() { + let body_owner_local_def_id = tcx.hir_enclosing_body_owner(hir_id); + if tcx.hir_body_owner_kind(body_owner_local_def_id).is_fn_or_closure() { Some(tcx.optimized_mir(body_owner_local_def_id.to_def_id())) } else { None diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 74a392354894..2250d991bd8e 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -28,14 +28,7 @@ pub const SYM_MODULE: [&str; 3] = ["rustc_span", "symbol", "sym"]; pub const SYNTAX_CONTEXT: [&str; 3] = ["rustc_span", "hygiene", "SyntaxContext"]; // Paths in `core`/`alloc`/`std`. This should be avoided and cleaned up by adding diagnostic items. -pub const ABORT: [&str; 3] = ["std", "process", "abort"]; -pub const BUF_READ: [&str; 3] = ["std", "io", "BufRead"]; -pub const CHILD: [&str; 3] = ["std", "process", "Child"]; -pub const CHILD_ID: [&str; 4] = ["std", "process", "Child", "id"]; -pub const CHILD_KILL: [&str; 4] = ["std", "process", "Child", "kill"]; -pub const PANIC_ANY: [&str; 3] = ["std", "panic", "panic_any"]; pub const CHAR_IS_ASCII: [&str; 5] = ["core", "char", "methods", "", "is_ascii"]; -pub const STDIN: [&str; 4] = ["std", "io", "stdio", "Stdin"]; // Paths in clippy itself pub const MSRV: [&str; 3] = ["clippy_utils", "msrvs", "Msrv"]; diff --git a/clippy_utils/src/ptr.rs b/clippy_utils/src/ptr.rs index 273c1b0defab..360c6251a57c 100644 --- a/clippy_utils/src/ptr.rs +++ b/clippy_utils/src/ptr.rs @@ -13,7 +13,7 @@ pub fn get_spans( idx: usize, replacements: &[(&'static str, &'static str)], ) -> Option)>> { - if let Some(body) = opt_body_id.map(|id| cx.tcx.hir().body(id)) { + if let Some(body) = opt_body_id.map(|id| cx.tcx.hir_body(id)) { if let PatKind::Binding(_, binding_id, _, _) = strip_pat_refs(body.params[idx].pat).kind { extract_clone_suggestions(cx, binding_id, replacements, body) } else { diff --git a/clippy_utils/src/source.rs b/clippy_utils/src/source.rs index be1bd5d2e390..80066e9702d3 100644 --- a/clippy_utils/src/source.rs +++ b/clippy_utils/src/source.rs @@ -2,8 +2,9 @@ #![allow(clippy::module_name_repetitions)] +use std::sync::Arc; + use rustc_ast::{LitKind, StrStyle}; -use rustc_data_structures::sync::Lrc; use rustc_errors::Applicability; use rustc_hir::{BlockCheckMode, Expr, ExprKind, UnsafeSource}; use rustc_lint::{EarlyContext, LateContext}; @@ -204,7 +205,7 @@ impl fmt::Display for SourceText { fn get_source_range(sm: &SourceMap, sp: Range) -> Option { let start = sm.lookup_byte_offset(sp.start); let end = sm.lookup_byte_offset(sp.end); - if !Lrc::ptr_eq(&start.sf, &end.sf) || start.pos > end.pos { + if !Arc::ptr_eq(&start.sf, &end.sf) || start.pos > end.pos { return None; } sm.ensure_source_file_source_present(&start.sf); @@ -277,7 +278,7 @@ fn trim_start(sm: &SourceMap, sp: Range) -> Range { } pub struct SourceFileRange { - pub sf: Lrc, + pub sf: Arc, pub range: Range, } impl SourceFileRange { diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 088abd7c4791..d5e0e2e3436e 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -809,7 +809,7 @@ pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Opti fn_decl, def_id, body, .. }) = closure.kind { - let closure_body = cx.tcx.hir().body(body); + let closure_body = cx.tcx.hir_body(body); // is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`) // a type annotation is present if param `kind` is different from `TyKind::Infer` let closure_arg_is_type_annotated_double_ref = if let TyKind::Ref(_, MutTy { ty, .. }) = fn_decl.inputs[0].kind diff --git a/clippy_utils/src/ty/mod.rs b/clippy_utils/src/ty/mod.rs index d2510eeeb0ab..2611fb8a78d8 100644 --- a/clippy_utils/src/ty/mod.rs +++ b/clippy_utils/src/ty/mod.rs @@ -4,6 +4,7 @@ use core::ops::ControlFlow; use itertools::Itertools; +use rustc_abi::VariantIdx; use rustc_ast::ast::Mutability; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; @@ -24,7 +25,6 @@ use rustc_middle::ty::{ }; use rustc_span::symbol::Ident; use rustc_span::{DUMMY_SP, Span, Symbol, sym}; -use rustc_target::abi::VariantIdx; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt; use rustc_trait_selection::traits::{Obligation, ObligationCause}; @@ -281,7 +281,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>( // through calling `body_owner_kind`, which would panic if the callee // does not have a body. if let Some(callee_id) = callee_id { - let _ = tcx.hir().body_owner_kind(callee_id); + let _ = tcx.hir_body_owner_kind(callee_id); } let ty = tcx.erase_regions(ty); @@ -725,7 +725,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option { let decl = id .as_local() - .and_then(|id| cx.tcx.hir().fn_decl_by_hir_id(cx.tcx.local_def_id_to_hir_id(id))); + .and_then(|id| cx.tcx.hir_fn_decl_by_hir_id(cx.tcx.local_def_id_to_hir_id(id))); Some(ExprFnSig::Closure(decl, subs.as_closure().sig())) }, ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).instantiate(cx.tcx, subs), Some(id))), diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index 37f729668925..3bf518f7fe70 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -133,8 +133,8 @@ impl<'tcx> Visitor<'tcx> for BindingUsageFinder<'_, 'tcx> { ControlFlow::Continue(()) } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index 99984c41714b..2ac0efd7e392 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -154,8 +154,8 @@ pub fn for_each_expr<'tcx, B, C: Continue>( type NestedFilter = nested_filter::OnlyBodies; type Result = ControlFlow; - fn nested_visit_map(&mut self) -> Self::Map { - self.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.tcx } fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) -> Self::Result { @@ -296,7 +296,7 @@ where /// Checks if the given resolved path is used in the given body. pub fn is_res_used(cx: &LateContext<'_>, res: Res, body: BodyId) -> bool { - for_each_expr(cx, cx.tcx.hir().body(body).value, |e| { + for_each_expr(cx, cx.tcx.hir_body(body).value, |e| { if let ExprKind::Path(p) = &e.kind { if cx.qpath_res(p, e.hir_id) == res { return ControlFlow::Break(()); @@ -412,12 +412,12 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { type NestedFilter = nested_filter::OnlyBodies; type Result = ControlFlow<()>; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, e: &'tcx Expr<'_>) -> Self::Result { match e.kind { - ExprKind::Unary(UnOp::Deref, e) if self.cx.typeck_results().expr_ty(e).is_unsafe_ptr() => { + ExprKind::Unary(UnOp::Deref, e) if self.cx.typeck_results().expr_ty(e).is_raw_ptr() => { ControlFlow::Break(()) }, ExprKind::MethodCall(..) @@ -456,7 +456,7 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { } } fn visit_nested_item(&mut self, id: ItemId) -> Self::Result { - if let ItemKind::Impl(i) = &self.cx.tcx.hir().item(id).kind + if let ItemKind::Impl(i) = &self.cx.tcx.hir_item(id).kind && i.safety.is_unsafe() { ControlFlow::Break(()) @@ -477,8 +477,8 @@ pub fn contains_unsafe_block<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) impl<'tcx> Visitor<'tcx> for V<'_, 'tcx> { type Result = ControlFlow<()>; type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_block(&mut self, b: &'tcx Block<'_>) -> Self::Result { @@ -544,8 +544,8 @@ pub fn for_each_local_use_after_expr<'tcx, B>( } impl<'tcx, F: FnMut(&'tcx Expr<'tcx>) -> ControlFlow, B> Visitor<'tcx> for V<'_, 'tcx, F, B> { type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) { @@ -729,8 +729,8 @@ pub fn for_each_local_assignment<'tcx, B>( } impl<'tcx, F: FnMut(&'tcx Expr<'tcx>) -> ControlFlow, B> Visitor<'tcx> for V<'_, 'tcx, F, B> { type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) { diff --git a/rust-toolchain b/rust-toolchain index ab760287e83a..4956ab5d3775 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,6 +1,6 @@ [toolchain] # begin autogenerated nightly -channel = "nightly-2025-02-06" +channel = "nightly-2025-02-20" # end autogenerated nightly components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"] profile = "minimal" diff --git a/tests/ui-cargo/lint_groups_priority/fail/Cargo.stderr b/tests/ui-cargo/lint_groups_priority/fail/Cargo.stderr index 4fe7f6f7a9ed..074b1664a8b1 100644 --- a/tests/ui-cargo/lint_groups_priority/fail/Cargo.stderr +++ b/tests/ui-cargo/lint_groups_priority/fail/Cargo.stderr @@ -11,8 +11,9 @@ error: lint group `rust_2018_idioms` has the same priority (0) as a lint = note: `#[deny(clippy::lint_groups_priority)]` on by default help: to have lints override the group set `rust_2018_idioms` to a lower priority | -7 | rust_2018_idioms = { level = "warn", priority = -1 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +7 - rust_2018_idioms = "warn" +7 + rust_2018_idioms = { level = "warn", priority = -1 } + | error: lint group `unused` has the same priority (0) as a lint --> Cargo.toml:10:1 @@ -26,8 +27,9 @@ error: lint group `unused` has the same priority (0) as a lint = note: the order of the lints in the table is ignored by Cargo help: to have lints override the group set `unused` to a lower priority | -10 | unused = { level = "deny", priority = -1 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +10 - unused = { level = "deny" } +10 + unused = { level = "deny", priority = -1 } + | error: lint group `pedantic` has the same priority (-1) as a lint --> Cargo.toml:15:1 @@ -40,8 +42,9 @@ error: lint group `pedantic` has the same priority (-1) as a lint = note: the order of the lints in the table is ignored by Cargo help: to have lints override the group set `pedantic` to a lower priority | -15 | pedantic = { level = "warn", priority = -2 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +15 - pedantic = { level = "warn", priority = -1 } +15 + pedantic = { level = "warn", priority = -2 } + | error: lint group `rust_2018_idioms` has the same priority (0) as a lint --> Cargo.toml:19:1 @@ -54,8 +57,9 @@ error: lint group `rust_2018_idioms` has the same priority (0) as a lint = note: the order of the lints in the table is ignored by Cargo help: to have lints override the group set `rust_2018_idioms` to a lower priority | -19 | rust_2018_idioms = { level = "warn", priority = -1 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +19 - rust_2018_idioms = "warn" +19 + rust_2018_idioms = { level = "warn", priority = -1 } + | error: lint group `pedantic` has the same priority (0) as a lint --> Cargo.toml:23:1 @@ -68,7 +72,8 @@ error: lint group `pedantic` has the same priority (0) as a lint = note: the order of the lints in the table is ignored by Cargo help: to have lints override the group set `pedantic` to a lower priority | -23 | pedantic = { level = "warn", priority = -1 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +23 - pedantic = "warn" +23 + pedantic = { level = "warn", priority = -1 } + | error: could not compile `fail` (lib) due to 5 previous errors diff --git a/tests/ui-internal/custom_ice_message.stderr b/tests/ui-internal/custom_ice_message.stderr index ae5d8ef1d0b5..801b0f340de9 100644 --- a/tests/ui-internal/custom_ice_message.stderr +++ b/tests/ui-internal/custom_ice_message.stderr @@ -14,7 +14,7 @@ note: rustc running on note: compiler flags: -Z ui-testing -Z deduplicate-diagnostics=no query stack during panic: -#0 [early_lint_checks] perform lints prior to macro expansion +#0 [early_lint_checks] perform lints prior to AST lowering #1 [hir_crate] getting the crate HIR ... and 3 other queries... use `env RUST_BACKTRACE=1` to see the full query stack note: Clippy version: foo diff --git a/tests/ui-toml/dbg_macro/dbg_macro.stderr b/tests/ui-toml/dbg_macro/dbg_macro.stderr index 3d869f97c0af..4587d28c3f34 100644 --- a/tests/ui-toml/dbg_macro/dbg_macro.stderr +++ b/tests/ui-toml/dbg_macro/dbg_macro.stderr @@ -8,8 +8,9 @@ LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } = help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]` help: remove the invocation before committing it to a version control system | -LL | if let Some(n) = n.checked_sub(4) { n } else { n } - | ~~~~~~~~~~~~~~~~ +LL - if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } +LL + if let Some(n) = n.checked_sub(4) { n } else { n } + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui-toml/dbg_macro/dbg_macro.rs:11:8 @@ -19,8 +20,9 @@ LL | if dbg!(n <= 1) { | help: remove the invocation before committing it to a version control system | -LL | if n <= 1 { - | ~~~~~~ +LL - if dbg!(n <= 1) { +LL + if n <= 1 { + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui-toml/dbg_macro/dbg_macro.rs:13:9 @@ -30,7 +32,8 @@ LL | dbg!(1) | help: remove the invocation before committing it to a version control system | -LL | 1 +LL - dbg!(1) +LL + 1 | error: the `dbg!` macro is intended as a debugging tool @@ -41,7 +44,8 @@ LL | dbg!(n * factorial(n - 1)) | help: remove the invocation before committing it to a version control system | -LL | n * factorial(n - 1) +LL - dbg!(n * factorial(n - 1)) +LL + n * factorial(n - 1) | error: the `dbg!` macro is intended as a debugging tool @@ -52,8 +56,9 @@ LL | dbg!(42); | help: remove the invocation before committing it to a version control system | -LL | 42; - | ~~ +LL - dbg!(42); +LL + 42; + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui-toml/dbg_macro/dbg_macro.rs:24:14 @@ -63,8 +68,9 @@ LL | foo(3) + dbg!(factorial(4)); | help: remove the invocation before committing it to a version control system | -LL | foo(3) + factorial(4); - | ~~~~~~~~~~~~ +LL - foo(3) + dbg!(factorial(4)); +LL + foo(3) + factorial(4); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui-toml/dbg_macro/dbg_macro.rs:26:5 @@ -74,8 +80,9 @@ LL | dbg!(1, 2, 3, 4, 5); | help: remove the invocation before committing it to a version control system | -LL | (1, 2, 3, 4, 5); - | ~~~~~~~~~~~~~~~ +LL - dbg!(1, 2, 3, 4, 5); +LL + (1, 2, 3, 4, 5); + | error: aborting due to 7 previous errors diff --git a/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr b/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr index a6e0ad0f804c..8ba237ee75cf 100644 --- a/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr +++ b/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr @@ -8,8 +8,9 @@ LL | /// TestItemThingyOfCoolness might sound cool but is not on the list and sh = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | -LL | /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// TestItemThingyOfCoolness might sound cool but is not on the list and should be linted. +LL + /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. + | error: aborting due to 1 previous error diff --git a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr index cb5f5abda6c6..e06b958a1b37 100644 --- a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr +++ b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr @@ -8,8 +8,9 @@ LL | /// OAuth and LaTeX are inside Clippy's default list. = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | -LL | /// `OAuth` and LaTeX are inside Clippy's default list. - | ~~~~~~~ +LL - /// OAuth and LaTeX are inside Clippy's default list. +LL + /// `OAuth` and LaTeX are inside Clippy's default list. + | error: item in documentation is missing backticks --> tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs:6:15 @@ -19,8 +20,9 @@ LL | /// OAuth and LaTeX are inside Clippy's default list. | help: try | -LL | /// OAuth and `LaTeX` are inside Clippy's default list. - | ~~~~~~~ +LL - /// OAuth and LaTeX are inside Clippy's default list. +LL + /// OAuth and `LaTeX` are inside Clippy's default list. + | error: item in documentation is missing backticks --> tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs:11:5 @@ -30,8 +32,9 @@ LL | /// TestItemThingyOfCoolness might sound cool but is not on the list and sh | help: try | -LL | /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// TestItemThingyOfCoolness might sound cool but is not on the list and should be linted. +LL + /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. + | error: aborting due to 3 previous errors diff --git a/tests/ui-toml/enum_variant_size/enum_variant_size.stderr b/tests/ui-toml/enum_variant_size/enum_variant_size.stderr index 8f7ebbd9546c..020b3cc78782 100644 --- a/tests/ui-toml/enum_variant_size/enum_variant_size.stderr +++ b/tests/ui-toml/enum_variant_size/enum_variant_size.stderr @@ -14,8 +14,9 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]` help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box<[u8; 501]>), - | ~~~~~~~~~~~~~~ +LL - B([u8; 501]), +LL + B(Box<[u8; 501]>), + | error: aborting due to 1 previous error diff --git a/tests/ui-toml/renamed_function_params/renamed_function_params.default.stderr b/tests/ui-toml/renamed_function_params/renamed_function_params.default.stderr index e7e526628ce7..7fdaa4420450 100644 --- a/tests/ui-toml/renamed_function_params/renamed_function_params.default.stderr +++ b/tests/ui-toml/renamed_function_params/renamed_function_params.default.stderr @@ -33,8 +33,9 @@ LL | fn hash_slice(date: &[Self], states: &mut H) { | help: consider using the default names | -LL | fn hash_slice(data: &[Self], state: &mut H) { - | ~~~~ ~~~~~ +LL - fn hash_slice(date: &[Self], states: &mut H) { +LL + fn hash_slice(data: &[Self], state: &mut H) { + | error: renamed function parameter of trait impl --> tests/ui-toml/renamed_function_params/renamed_function_params.rs:82:18 diff --git a/tests/ui-toml/renamed_function_params/renamed_function_params.extend.stderr b/tests/ui-toml/renamed_function_params/renamed_function_params.extend.stderr index 46e5f34b1761..d670026b5411 100644 --- a/tests/ui-toml/renamed_function_params/renamed_function_params.extend.stderr +++ b/tests/ui-toml/renamed_function_params/renamed_function_params.extend.stderr @@ -27,8 +27,9 @@ LL | fn hash_slice(date: &[Self], states: &mut H) { | help: consider using the default names | -LL | fn hash_slice(data: &[Self], state: &mut H) { - | ~~~~ ~~~~~ +LL - fn hash_slice(date: &[Self], states: &mut H) { +LL + fn hash_slice(data: &[Self], state: &mut H) { + | error: aborting due to 4 previous errors diff --git a/tests/ui-toml/unwrap_used/unwrap_used.stderr b/tests/ui-toml/unwrap_used/unwrap_used.stderr index cb9a3f6887dc..135e35323fdb 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.stderr +++ b/tests/ui-toml/unwrap_used/unwrap_used.stderr @@ -8,8 +8,9 @@ LL | let _ = boxed_slice.get(1).unwrap(); = help: to override `-D warnings` add `#[allow(clippy::get_unwrap)]` help: using `[]` is clearer and more concise | -LL | let _ = &boxed_slice[1]; - | ~~~~~~~~~~~~~~~ +LL - let _ = boxed_slice.get(1).unwrap(); +LL + let _ = &boxed_slice[1]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:38:17 @@ -30,8 +31,9 @@ LL | let _ = some_slice.get(0).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_slice[0]; - | ~~~~~~~~~~~~~~ +LL - let _ = some_slice.get(0).unwrap(); +LL + let _ = &some_slice[0]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:41:17 @@ -50,8 +52,9 @@ LL | let _ = some_vec.get(0).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_vec[0]; - | ~~~~~~~~~~~~ +LL - let _ = some_vec.get(0).unwrap(); +LL + let _ = &some_vec[0]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:44:17 @@ -70,8 +73,9 @@ LL | let _ = some_vecdeque.get(0).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_vecdeque[0]; - | ~~~~~~~~~~~~~~~~~ +LL - let _ = some_vecdeque.get(0).unwrap(); +LL + let _ = &some_vecdeque[0]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:47:17 @@ -90,8 +94,9 @@ LL | let _ = some_hashmap.get(&1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_hashmap[&1]; - | ~~~~~~~~~~~~~~~~~ +LL - let _ = some_hashmap.get(&1).unwrap(); +LL + let _ = &some_hashmap[&1]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:50:17 @@ -110,8 +115,9 @@ LL | let _ = some_btreemap.get(&1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_btreemap[&1]; - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = some_btreemap.get(&1).unwrap(); +LL + let _ = &some_btreemap[&1]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:53:17 @@ -130,8 +136,9 @@ LL | let _: u8 = *boxed_slice.get(1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _: u8 = boxed_slice[1]; - | ~~~~~~~~~~~~~~ +LL - let _: u8 = *boxed_slice.get(1).unwrap(); +LL + let _: u8 = boxed_slice[1]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:59:22 @@ -150,8 +157,9 @@ LL | *boxed_slice.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | boxed_slice[0] = 1; - | ~~~~~~~~~~~~~~ +LL - *boxed_slice.get_mut(0).unwrap() = 1; +LL + boxed_slice[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:66:10 @@ -170,8 +178,9 @@ LL | *some_slice.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | some_slice[0] = 1; - | ~~~~~~~~~~~~~ +LL - *some_slice.get_mut(0).unwrap() = 1; +LL + some_slice[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:69:10 @@ -190,8 +199,9 @@ LL | *some_vec.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | some_vec[0] = 1; - | ~~~~~~~~~~~ +LL - *some_vec.get_mut(0).unwrap() = 1; +LL + some_vec[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:72:10 @@ -210,8 +220,9 @@ LL | *some_vecdeque.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | some_vecdeque[0] = 1; - | ~~~~~~~~~~~~~~~~ +LL - *some_vecdeque.get_mut(0).unwrap() = 1; +LL + some_vecdeque[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:75:10 @@ -230,8 +241,9 @@ LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | help: using `[]` is clearer and more concise | -LL | let _ = some_vec[0..1].to_vec(); - | ~~~~~~~~~~~~~~ +LL - let _ = some_vec.get(0..1).unwrap().to_vec(); +LL + let _ = some_vec[0..1].to_vec(); + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:89:17 @@ -250,8 +262,9 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | help: using `[]` is clearer and more concise | -LL | let _ = some_vec[0..1].to_vec(); - | ~~~~~~~~~~~~~~ +LL - let _ = some_vec.get_mut(0..1).unwrap().to_vec(); +LL + let _ = some_vec[0..1].to_vec(); + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:92:17 @@ -270,8 +283,9 @@ LL | let _ = boxed_slice.get(1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &boxed_slice[1]; - | ~~~~~~~~~~~~~~~ +LL - let _ = boxed_slice.get(1).unwrap(); +LL + let _ = &boxed_slice[1]; + | error: called `.get().unwrap()` on a slice --> tests/ui-toml/unwrap_used/unwrap_used.rs:121:17 @@ -281,8 +295,9 @@ LL | let _ = Box::new([0]).get(1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &Box::new([0])[1]; - | ~~~~~~~~~~~~~~~~~ +LL - let _ = Box::new([0]).get(1).unwrap(); +LL + let _ = &Box::new([0])[1]; + | error: aborting due to 28 previous errors diff --git a/tests/ui/assign_ops2.stderr b/tests/ui/assign_ops2.stderr index 19deebe17850..d9ecd3f8b230 100644 --- a/tests/ui/assign_ops2.stderr +++ b/tests/ui/assign_ops2.stderr @@ -8,12 +8,14 @@ LL | a += a + 1; = help: to override `-D warnings` add `#[allow(clippy::misrefactored_assign_op)]` help: did you mean `a = a + 1` or `a = a + a + 1`? Consider replacing it with | -LL | a += 1; - | ~~~~~~ +LL - a += a + 1; +LL + a += 1; + | help: or | -LL | a = a + a + 1; - | ~~~~~~~~~~~~~ +LL - a += a + 1; +LL + a = a + a + 1; + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:11:5 @@ -23,12 +25,14 @@ LL | a += 1 + a; | help: did you mean `a = a + 1` or `a = a + 1 + a`? Consider replacing it with | -LL | a += 1; - | ~~~~~~ +LL - a += 1 + a; +LL + a += 1; + | help: or | -LL | a = a + 1 + a; - | ~~~~~~~~~~~~~ +LL - a += 1 + a; +LL + a = a + 1 + a; + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:14:5 @@ -38,12 +42,14 @@ LL | a -= a - 1; | help: did you mean `a = a - 1` or `a = a - (a - 1)`? Consider replacing it with | -LL | a -= 1; - | ~~~~~~ +LL - a -= a - 1; +LL + a -= 1; + | help: or | -LL | a = a - (a - 1); - | ~~~~~~~~~~~~~~~ +LL - a -= a - 1; +LL + a = a - (a - 1); + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:17:5 @@ -53,12 +59,14 @@ LL | a *= a * 99; | help: did you mean `a = a * 99` or `a = a * a * 99`? Consider replacing it with | -LL | a *= 99; - | ~~~~~~~ +LL - a *= a * 99; +LL + a *= 99; + | help: or | -LL | a = a * a * 99; - | ~~~~~~~~~~~~~~ +LL - a *= a * 99; +LL + a = a * a * 99; + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:20:5 @@ -68,12 +76,14 @@ LL | a *= 42 * a; | help: did you mean `a = a * 42` or `a = a * 42 * a`? Consider replacing it with | -LL | a *= 42; - | ~~~~~~~ +LL - a *= 42 * a; +LL + a *= 42; + | help: or | -LL | a = a * 42 * a; - | ~~~~~~~~~~~~~~ +LL - a *= 42 * a; +LL + a = a * 42 * a; + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:23:5 @@ -83,12 +93,14 @@ LL | a /= a / 2; | help: did you mean `a = a / 2` or `a = a / (a / 2)`? Consider replacing it with | -LL | a /= 2; - | ~~~~~~ +LL - a /= a / 2; +LL + a /= 2; + | help: or | -LL | a = a / (a / 2); - | ~~~~~~~~~~~~~~~ +LL - a /= a / 2; +LL + a = a / (a / 2); + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:26:5 @@ -98,12 +110,14 @@ LL | a %= a % 5; | help: did you mean `a = a % 5` or `a = a % (a % 5)`? Consider replacing it with | -LL | a %= 5; - | ~~~~~~ +LL - a %= a % 5; +LL + a %= 5; + | help: or | -LL | a = a % (a % 5); - | ~~~~~~~~~~~~~~~ +LL - a %= a % 5; +LL + a = a % (a % 5); + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:29:5 @@ -113,12 +127,14 @@ LL | a &= a & 1; | help: did you mean `a = a & 1` or `a = a & a & 1`? Consider replacing it with | -LL | a &= 1; - | ~~~~~~ +LL - a &= a & 1; +LL + a &= 1; + | help: or | -LL | a = a & a & 1; - | ~~~~~~~~~~~~~ +LL - a &= a & 1; +LL + a = a & a & 1; + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:32:5 @@ -128,12 +144,14 @@ LL | a *= a * a; | help: did you mean `a = a * a` or `a = a * a * a`? Consider replacing it with | -LL | a *= a; - | ~~~~~~ +LL - a *= a * a; +LL + a *= a; + | help: or | -LL | a = a * a * a; - | ~~~~~~~~~~~~~ +LL - a *= a * a; +LL + a = a * a * a; + | error: manual implementation of an assign operation --> tests/ui/assign_ops2.rs:71:5 diff --git a/tests/ui/author/blocks.stdout b/tests/ui/author/blocks.stdout index 6bf48d5ba4ef..54325f9776c5 100644 --- a/tests/ui/author/blocks.stdout +++ b/tests/ui/author/blocks.stdout @@ -42,10 +42,10 @@ if let ExprKind::Block(block, None) = expr.kind } if let ExprKind::Closure { capture_clause: CaptureBy::Value { .. }, fn_decl: fn_decl, body: body_id, closure_kind: ClosureKind::CoroutineClosure(CoroutineDesugaring::Async), .. } = expr.kind && let FnRetTy::DefaultReturn(_) = fn_decl.output - && expr1 = &cx.tcx.hir().body(body_id).value + && expr1 = &cx.tcx.hir_body(body_id).value && let ExprKind::Closure { capture_clause: CaptureBy::Ref, fn_decl: fn_decl1, body: body_id1, closure_kind: ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Closure)), .. } = expr1.kind && let FnRetTy::DefaultReturn(_) = fn_decl1.output - && expr2 = &cx.tcx.hir().body(body_id1).value + && expr2 = &cx.tcx.hir_body(body_id1).value && let ExprKind::Block(block, None) = expr2.kind && block.stmts.is_empty() && let Some(trailing_expr) = block.expr diff --git a/tests/ui/author/macro_in_closure.stdout b/tests/ui/author/macro_in_closure.stdout index 66caf382d897..3186d0cbc276 100644 --- a/tests/ui/author/macro_in_closure.stdout +++ b/tests/ui/author/macro_in_closure.stdout @@ -2,7 +2,7 @@ if let StmtKind::Let(local) = stmt.kind && let Some(init) = local.init && let ExprKind::Closure { capture_clause: CaptureBy::Ref, fn_decl: fn_decl, body: body_id, closure_kind: ClosureKind::Closure, .. } = init.kind && let FnRetTy::DefaultReturn(_) = fn_decl.output - && expr = &cx.tcx.hir().body(body_id).value + && expr = &cx.tcx.hir_body(body_id).value && let ExprKind::Block(block, None) = expr.kind && block.stmts.len() == 1 && let StmtKind::Semi(e) = block.stmts[0].kind diff --git a/tests/ui/author/repeat.stdout b/tests/ui/author/repeat.stdout index 1a608734ada9..f2c6b3f807f1 100644 --- a/tests/ui/author/repeat.stdout +++ b/tests/ui/author/repeat.stdout @@ -2,7 +2,7 @@ if let ExprKind::Repeat(value, length) = expr.kind && let ExprKind::Lit(ref lit) = value.kind && let LitKind::Int(1, LitIntType::Unsigned(UintTy::U8)) = lit.node && let ConstArgKind::Anon(anon_const) = length.kind - && expr1 = &cx.tcx.hir().body(anon_const.body).value + && expr1 = &cx.tcx.hir_body(anon_const.body).value && let ExprKind::Lit(ref lit1) = expr1.kind && let LitKind::Int(5, LitIntType::Unsuffixed) = lit1.node { diff --git a/tests/ui/bind_instead_of_map_multipart.stderr b/tests/ui/bind_instead_of_map_multipart.stderr index 336b19433a68..3ae11422357c 100644 --- a/tests/ui/bind_instead_of_map_multipart.stderr +++ b/tests/ui/bind_instead_of_map_multipart.stderr @@ -11,8 +11,9 @@ LL | #![deny(clippy::bind_instead_of_map)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `map` instead | -LL | let _ = Some("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); - | ~~~ ~ ~~~~~~~ +LL - let _ = Some("42").and_then(|s| if s.len() < 42 { Some(0) } else { Some(s.len()) }); +LL + let _ = Some("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); + | error: using `Result.and_then(|x| Ok(y))`, which is more succinctly expressed as `map(|x| y)` --> tests/ui/bind_instead_of_map_multipart.rs:9:13 @@ -22,8 +23,9 @@ LL | let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Ok(0) } else { | help: use `map` instead | -LL | let _ = Ok::<_, ()>("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); - | ~~~ ~ ~~~~~~~ +LL - let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Ok(0) } else { Ok(s.len()) }); +LL + let _ = Ok::<_, ()>("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); + | error: using `Result.or_else(|x| Err(y))`, which is more succinctly expressed as `map_err(|x| y)` --> tests/ui/bind_instead_of_map_multipart.rs:13:13 @@ -33,8 +35,9 @@ LL | let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Err(s.len() + | help: use `map_err` instead | -LL | let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } else { s.len() }); - | ~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~ +LL - let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Err(s.len() + 20) } else { Err(s.len()) }); +LL + let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } else { s.len() }); + | error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` --> tests/ui/bind_instead_of_map_multipart.rs:22:5 @@ -84,8 +87,9 @@ LL | let _ = Some("").and_then(|s| if s.len() == 20 { Some(m!()) } else { So | help: use `map` instead | -LL | let _ = Some("").map(|s| if s.len() == 20 { m!() } else { Some(20) }); - | ~~~ ~~~~ ~~~~~~~~ +LL - let _ = Some("").and_then(|s| if s.len() == 20 { Some(m!()) } else { Some(Some(20)) }); +LL + let _ = Some("").map(|s| if s.len() == 20 { m!() } else { Some(20) }); + | error: aborting due to 5 previous errors diff --git a/tests/ui/borrow_deref_ref_unfixable.stderr b/tests/ui/borrow_deref_ref_unfixable.stderr index 7d3a5c84a820..71f43af46c24 100644 --- a/tests/ui/borrow_deref_ref_unfixable.stderr +++ b/tests/ui/borrow_deref_ref_unfixable.stderr @@ -8,12 +8,14 @@ LL | let x: &str = &*s; = help: to override `-D warnings` add `#[allow(clippy::borrow_deref_ref)]` help: if you would like to reborrow, try removing `&*` | -LL | let x: &str = s; - | ~ +LL - let x: &str = &*s; +LL + let x: &str = s; + | help: if you would like to deref, try using `&**` | -LL | let x: &str = &**s; - | ~~~~ +LL - let x: &str = &*s; +LL + let x: &str = &**s; + | error: aborting due to 1 previous error diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index 1c5ff52ae722..4d03282f6676 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -81,8 +81,9 @@ LL | 1i32 as i8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i8::try_from(1i32); - | ~~~~~~~~~~~~~~~~~~ +LL - 1i32 as i8; +LL + i8::try_from(1i32); + | error: casting `i32` to `u8` may truncate the value --> tests/ui/cast.rs:60:5 @@ -93,8 +94,9 @@ LL | 1i32 as u8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | u8::try_from(1i32); - | ~~~~~~~~~~~~~~~~~~ +LL - 1i32 as u8; +LL + u8::try_from(1i32); + | error: casting `f64` to `isize` may truncate the value --> tests/ui/cast.rs:63:5 @@ -127,8 +129,9 @@ LL | 1f32 as u32 as u16; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | u16::try_from(1f32 as u32); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - 1f32 as u32 as u16; +LL + u16::try_from(1f32 as u32); + | error: casting `f32` to `u32` may truncate the value --> tests/ui/cast.rs:70:5 @@ -153,8 +156,9 @@ LL | let _x: i8 = 1i32 as _; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | let _x: i8 = 1i32.try_into(); - | ~~~~~~~~~~~~~~~ +LL - let _x: i8 = 1i32 as _; +LL + let _x: i8 = 1i32.try_into(); + | error: casting `f32` to `i32` may truncate the value --> tests/ui/cast.rs:79:9 @@ -228,8 +232,9 @@ LL | 1usize as i8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i8::try_from(1usize); - | ~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as i8; +LL + i8::try_from(1usize); + | error: casting `usize` to `i16` may truncate the value --> tests/ui/cast.rs:110:5 @@ -240,8 +245,9 @@ LL | 1usize as i16; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i16::try_from(1usize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as i16; +LL + i16::try_from(1usize); + | error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers --> tests/ui/cast.rs:110:5 @@ -261,8 +267,9 @@ LL | 1usize as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i32::try_from(1usize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as i32; +LL + i32::try_from(1usize); + | error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers --> tests/ui/cast.rs:115:5 @@ -300,8 +307,9 @@ LL | 1u64 as isize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | isize::try_from(1u64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1u64 as isize; +LL + isize::try_from(1u64); + | error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers --> tests/ui/cast.rs:134:5 @@ -360,8 +368,9 @@ LL | (-99999999999i64).min(1) as i8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i8::try_from((-99999999999i64).min(1)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - (-99999999999i64).min(1) as i8; +LL + i8::try_from((-99999999999i64).min(1)); + | error: casting `u64` to `u8` may truncate the value --> tests/ui/cast.rs:253:5 @@ -372,8 +381,9 @@ LL | 999999u64.clamp(0, 256) as u8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | u8::try_from(999999u64.clamp(0, 256)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - 999999u64.clamp(0, 256) as u8; +LL + u8::try_from(999999u64.clamp(0, 256)); + | error: casting `main::E2` to `u8` may truncate the value --> tests/ui/cast.rs:276:21 @@ -384,8 +394,9 @@ LL | let _ = self as u8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | let _ = u8::try_from(self); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = self as u8; +LL + let _ = u8::try_from(self); + | error: casting `main::E2::B` to `u8` will truncate the value --> tests/ui/cast.rs:279:21 @@ -405,8 +416,9 @@ LL | let _ = self as i8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | let _ = i8::try_from(self); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = self as i8; +LL + let _ = i8::try_from(self); + | error: casting `main::E5::A` to `i8` will truncate the value --> tests/ui/cast.rs:324:21 @@ -423,8 +435,9 @@ LL | let _ = self as i16; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | let _ = i16::try_from(self); - | ~~~~~~~~~~~~~~~~~~~ +LL - let _ = self as i16; +LL + let _ = i16::try_from(self); + | error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers --> tests/ui/cast.rs:362:21 @@ -435,8 +448,9 @@ LL | let _ = self as usize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | let _ = usize::try_from(self); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = self as usize; +LL + let _ = usize::try_from(self); + | error: casting `main::E10` to `u16` may truncate the value --> tests/ui/cast.rs:410:21 @@ -447,8 +461,9 @@ LL | let _ = self as u16; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | let _ = u16::try_from(self); - | ~~~~~~~~~~~~~~~~~~~ +LL - let _ = self as u16; +LL + let _ = u16::try_from(self); + | error: casting `u32` to `u8` may truncate the value --> tests/ui/cast.rs:422:13 @@ -459,8 +474,9 @@ LL | let c = (q >> 16) as u8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | let c = u8::try_from(q >> 16); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - let c = (q >> 16) as u8; +LL + let c = u8::try_from(q >> 16); + | error: casting `u32` to `u8` may truncate the value --> tests/ui/cast.rs:427:13 @@ -471,8 +487,9 @@ LL | let c = (q / 1000) as u8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | let c = u8::try_from(q / 1000); - | ~~~~~~~~~~~~~~~~~~~~~~ +LL - let c = (q / 1000) as u8; +LL + let c = u8::try_from(q / 1000); + | error: casting `i32` to `u32` may lose the sign of the value --> tests/ui/cast.rs:440:9 @@ -674,8 +691,9 @@ LL | m!(); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) help: ... or use `try_from` and handle the error accordingly | -LL | let _ = u8::try_from(u32::MAX); // cast_possible_truncation - | ~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = u32::MAX as u8; // cast_possible_truncation +LL + let _ = u8::try_from(u32::MAX); // cast_possible_truncation + | error: casting `f64` to `f32` may truncate the value --> tests/ui/cast.rs:540:21 @@ -698,7 +716,8 @@ LL | bar.unwrap().unwrap() as usize = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | usize::try_from(bar.unwrap().unwrap()) +LL - bar.unwrap().unwrap() as usize +LL + usize::try_from(bar.unwrap().unwrap()) | error: casting `i64` to `usize` may lose the sign of the value @@ -716,8 +735,9 @@ LL | (256 & 999999u64) as u8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | u8::try_from(256 & 999999u64); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - (256 & 999999u64) as u8; +LL + u8::try_from(256 & 999999u64); + | error: casting `u64` to `u8` may truncate the value --> tests/ui/cast.rs:571:5 @@ -728,8 +748,9 @@ LL | (255 % 999999u64) as u8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | u8::try_from(255 % 999999u64); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - (255 % 999999u64) as u8; +LL + u8::try_from(255 % 999999u64); + | error: aborting due to 92 previous errors diff --git a/tests/ui/cast_lossless_bool.stderr b/tests/ui/cast_lossless_bool.stderr index 54edab2856cb..802eeaebbbdd 100644 --- a/tests/ui/cast_lossless_bool.stderr +++ b/tests/ui/cast_lossless_bool.stderr @@ -9,8 +9,9 @@ LL | let _ = true as u8; = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` help: use `u8::from` instead | -LL | let _ = u8::from(true); - | ~~~~~~~~~~~~~~ +LL - let _ = true as u8; +LL + let _ = u8::from(true); + | error: casts from `bool` to `u16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:10:13 @@ -21,8 +22,9 @@ LL | let _ = true as u16; = help: an `as` cast can become silently lossy if the types change in the future help: use `u16::from` instead | -LL | let _ = u16::from(true); - | ~~~~~~~~~~~~~~~ +LL - let _ = true as u16; +LL + let _ = u16::from(true); + | error: casts from `bool` to `u32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:12:13 @@ -33,8 +35,9 @@ LL | let _ = true as u32; = help: an `as` cast can become silently lossy if the types change in the future help: use `u32::from` instead | -LL | let _ = u32::from(true); - | ~~~~~~~~~~~~~~~ +LL - let _ = true as u32; +LL + let _ = u32::from(true); + | error: casts from `bool` to `u64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:14:13 @@ -45,8 +48,9 @@ LL | let _ = true as u64; = help: an `as` cast can become silently lossy if the types change in the future help: use `u64::from` instead | -LL | let _ = u64::from(true); - | ~~~~~~~~~~~~~~~ +LL - let _ = true as u64; +LL + let _ = u64::from(true); + | error: casts from `bool` to `u128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:16:13 @@ -57,8 +61,9 @@ LL | let _ = true as u128; = help: an `as` cast can become silently lossy if the types change in the future help: use `u128::from` instead | -LL | let _ = u128::from(true); - | ~~~~~~~~~~~~~~~~ +LL - let _ = true as u128; +LL + let _ = u128::from(true); + | error: casts from `bool` to `usize` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:18:13 @@ -69,8 +74,9 @@ LL | let _ = true as usize; = help: an `as` cast can become silently lossy if the types change in the future help: use `usize::from` instead | -LL | let _ = usize::from(true); - | ~~~~~~~~~~~~~~~~~ +LL - let _ = true as usize; +LL + let _ = usize::from(true); + | error: casts from `bool` to `i8` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:21:13 @@ -81,8 +87,9 @@ LL | let _ = true as i8; = help: an `as` cast can become silently lossy if the types change in the future help: use `i8::from` instead | -LL | let _ = i8::from(true); - | ~~~~~~~~~~~~~~ +LL - let _ = true as i8; +LL + let _ = i8::from(true); + | error: casts from `bool` to `i16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:23:13 @@ -93,8 +100,9 @@ LL | let _ = true as i16; = help: an `as` cast can become silently lossy if the types change in the future help: use `i16::from` instead | -LL | let _ = i16::from(true); - | ~~~~~~~~~~~~~~~ +LL - let _ = true as i16; +LL + let _ = i16::from(true); + | error: casts from `bool` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:25:13 @@ -105,8 +113,9 @@ LL | let _ = true as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | let _ = i32::from(true); - | ~~~~~~~~~~~~~~~ +LL - let _ = true as i32; +LL + let _ = i32::from(true); + | error: casts from `bool` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:27:13 @@ -117,8 +126,9 @@ LL | let _ = true as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | let _ = i64::from(true); - | ~~~~~~~~~~~~~~~ +LL - let _ = true as i64; +LL + let _ = i64::from(true); + | error: casts from `bool` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:29:13 @@ -129,8 +139,9 @@ LL | let _ = true as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | let _ = i128::from(true); - | ~~~~~~~~~~~~~~~~ +LL - let _ = true as i128; +LL + let _ = i128::from(true); + | error: casts from `bool` to `isize` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:31:13 @@ -141,8 +152,9 @@ LL | let _ = true as isize; = help: an `as` cast can become silently lossy if the types change in the future help: use `isize::from` instead | -LL | let _ = isize::from(true); - | ~~~~~~~~~~~~~~~~~ +LL - let _ = true as isize; +LL + let _ = isize::from(true); + | error: casts from `bool` to `u16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:35:13 @@ -153,8 +165,9 @@ LL | let _ = (true | false) as u16; = help: an `as` cast can become silently lossy if the types change in the future help: use `u16::from` instead | -LL | let _ = u16::from(true | false); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = (true | false) as u16; +LL + let _ = u16::from(true | false); + | error: casts from `bool` to `u8` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:38:13 @@ -165,8 +178,9 @@ LL | let _ = true as U8; = help: an `as` cast can become silently lossy if the types change in the future help: use `U8::from` instead | -LL | let _ = U8::from(true); - | ~~~~~~~~~~~~~~ +LL - let _ = true as U8; +LL + let _ = U8::from(true); + | error: casts from `bool` to `u8` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:67:13 @@ -177,8 +191,9 @@ LL | let _ = true as u8; = help: an `as` cast can become silently lossy if the types change in the future help: use `u8::from` instead | -LL | let _ = u8::from(true); - | ~~~~~~~~~~~~~~ +LL - let _ = true as u8; +LL + let _ = u8::from(true); + | error: aborting due to 15 previous errors diff --git a/tests/ui/cast_lossless_float.stderr b/tests/ui/cast_lossless_float.stderr index c983d4ccc6be..35ae38b1d36a 100644 --- a/tests/ui/cast_lossless_float.stderr +++ b/tests/ui/cast_lossless_float.stderr @@ -9,8 +9,9 @@ LL | let _ = x0 as f32; = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` help: use `f32::from` instead | -LL | let _ = f32::from(x0); - | ~~~~~~~~~~~~~ +LL - let _ = x0 as f32; +LL + let _ = f32::from(x0); + | error: casts from `i8` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:14:13 @@ -21,8 +22,9 @@ LL | let _ = x0 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(x0); - | ~~~~~~~~~~~~~ +LL - let _ = x0 as f64; +LL + let _ = f64::from(x0); + | error: casts from `i8` to `f32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:16:13 @@ -33,8 +35,9 @@ LL | let _ = x0 as F32; = help: an `as` cast can become silently lossy if the types change in the future help: use `F32::from` instead | -LL | let _ = F32::from(x0); - | ~~~~~~~~~~~~~ +LL - let _ = x0 as F32; +LL + let _ = F32::from(x0); + | error: casts from `i8` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:18:13 @@ -45,8 +48,9 @@ LL | let _ = x0 as F64; = help: an `as` cast can become silently lossy if the types change in the future help: use `F64::from` instead | -LL | let _ = F64::from(x0); - | ~~~~~~~~~~~~~ +LL - let _ = x0 as F64; +LL + let _ = F64::from(x0); + | error: casts from `u8` to `f32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:21:13 @@ -57,8 +61,9 @@ LL | let _ = x1 as f32; = help: an `as` cast can become silently lossy if the types change in the future help: use `f32::from` instead | -LL | let _ = f32::from(x1); - | ~~~~~~~~~~~~~ +LL - let _ = x1 as f32; +LL + let _ = f32::from(x1); + | error: casts from `u8` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:23:13 @@ -69,8 +74,9 @@ LL | let _ = x1 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(x1); - | ~~~~~~~~~~~~~ +LL - let _ = x1 as f64; +LL + let _ = f64::from(x1); + | error: casts from `i16` to `f32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:26:13 @@ -81,8 +87,9 @@ LL | let _ = x2 as f32; = help: an `as` cast can become silently lossy if the types change in the future help: use `f32::from` instead | -LL | let _ = f32::from(x2); - | ~~~~~~~~~~~~~ +LL - let _ = x2 as f32; +LL + let _ = f32::from(x2); + | error: casts from `i16` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:28:13 @@ -93,8 +100,9 @@ LL | let _ = x2 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(x2); - | ~~~~~~~~~~~~~ +LL - let _ = x2 as f64; +LL + let _ = f64::from(x2); + | error: casts from `u16` to `f32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:31:13 @@ -105,8 +113,9 @@ LL | let _ = x3 as f32; = help: an `as` cast can become silently lossy if the types change in the future help: use `f32::from` instead | -LL | let _ = f32::from(x3); - | ~~~~~~~~~~~~~ +LL - let _ = x3 as f32; +LL + let _ = f32::from(x3); + | error: casts from `u16` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:33:13 @@ -117,8 +126,9 @@ LL | let _ = x3 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(x3); - | ~~~~~~~~~~~~~ +LL - let _ = x3 as f64; +LL + let _ = f64::from(x3); + | error: casts from `i32` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:36:13 @@ -129,8 +139,9 @@ LL | let _ = x4 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(x4); - | ~~~~~~~~~~~~~ +LL - let _ = x4 as f64; +LL + let _ = f64::from(x4); + | error: casts from `u32` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:39:13 @@ -141,8 +152,9 @@ LL | let _ = x5 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(x5); - | ~~~~~~~~~~~~~ +LL - let _ = x5 as f64; +LL + let _ = f64::from(x5); + | error: casts from `f32` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:43:13 @@ -153,8 +165,9 @@ LL | let _ = 1.0f32 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(1.0f32); - | ~~~~~~~~~~~~~~~~~ +LL - let _ = 1.0f32 as f64; +LL + let _ = f64::from(1.0f32); + | error: aborting due to 13 previous errors diff --git a/tests/ui/cast_lossless_integer.stderr b/tests/ui/cast_lossless_integer.stderr index 393c20f68294..9852eca71279 100644 --- a/tests/ui/cast_lossless_integer.stderr +++ b/tests/ui/cast_lossless_integer.stderr @@ -9,8 +9,9 @@ LL | 0u8 as u16; = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` help: use `u16::from` instead | -LL | u16::from(0u8); - | ~~~~~~~~~~~~~~ +LL - 0u8 as u16; +LL + u16::from(0u8); + | error: casts from `u8` to `i16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:11:5 @@ -21,8 +22,9 @@ LL | 0u8 as i16; = help: an `as` cast can become silently lossy if the types change in the future help: use `i16::from` instead | -LL | i16::from(0u8); - | ~~~~~~~~~~~~~~ +LL - 0u8 as i16; +LL + i16::from(0u8); + | error: casts from `u8` to `u32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:14:5 @@ -33,8 +35,9 @@ LL | 0u8 as u32; = help: an `as` cast can become silently lossy if the types change in the future help: use `u32::from` instead | -LL | u32::from(0u8); - | ~~~~~~~~~~~~~~ +LL - 0u8 as u32; +LL + u32::from(0u8); + | error: casts from `u8` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:17:5 @@ -45,8 +48,9 @@ LL | 0u8 as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | i32::from(0u8); - | ~~~~~~~~~~~~~~ +LL - 0u8 as i32; +LL + i32::from(0u8); + | error: casts from `u8` to `u64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:20:5 @@ -57,8 +61,9 @@ LL | 0u8 as u64; = help: an `as` cast can become silently lossy if the types change in the future help: use `u64::from` instead | -LL | u64::from(0u8); - | ~~~~~~~~~~~~~~ +LL - 0u8 as u64; +LL + u64::from(0u8); + | error: casts from `u8` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:23:5 @@ -69,8 +74,9 @@ LL | 0u8 as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | i64::from(0u8); - | ~~~~~~~~~~~~~~ +LL - 0u8 as i64; +LL + i64::from(0u8); + | error: casts from `u8` to `u128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:26:5 @@ -81,8 +87,9 @@ LL | 0u8 as u128; = help: an `as` cast can become silently lossy if the types change in the future help: use `u128::from` instead | -LL | u128::from(0u8); - | ~~~~~~~~~~~~~~~ +LL - 0u8 as u128; +LL + u128::from(0u8); + | error: casts from `u8` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:29:5 @@ -93,8 +100,9 @@ LL | 0u8 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0u8); - | ~~~~~~~~~~~~~~~ +LL - 0u8 as i128; +LL + i128::from(0u8); + | error: casts from `u16` to `u32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:32:5 @@ -105,8 +113,9 @@ LL | 0u16 as u32; = help: an `as` cast can become silently lossy if the types change in the future help: use `u32::from` instead | -LL | u32::from(0u16); - | ~~~~~~~~~~~~~~~ +LL - 0u16 as u32; +LL + u32::from(0u16); + | error: casts from `u16` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:35:5 @@ -117,8 +126,9 @@ LL | 0u16 as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | i32::from(0u16); - | ~~~~~~~~~~~~~~~ +LL - 0u16 as i32; +LL + i32::from(0u16); + | error: casts from `u16` to `u64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:38:5 @@ -129,8 +139,9 @@ LL | 0u16 as u64; = help: an `as` cast can become silently lossy if the types change in the future help: use `u64::from` instead | -LL | u64::from(0u16); - | ~~~~~~~~~~~~~~~ +LL - 0u16 as u64; +LL + u64::from(0u16); + | error: casts from `u16` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:41:5 @@ -141,8 +152,9 @@ LL | 0u16 as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | i64::from(0u16); - | ~~~~~~~~~~~~~~~ +LL - 0u16 as i64; +LL + i64::from(0u16); + | error: casts from `u16` to `u128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:44:5 @@ -153,8 +165,9 @@ LL | 0u16 as u128; = help: an `as` cast can become silently lossy if the types change in the future help: use `u128::from` instead | -LL | u128::from(0u16); - | ~~~~~~~~~~~~~~~~ +LL - 0u16 as u128; +LL + u128::from(0u16); + | error: casts from `u16` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:47:5 @@ -165,8 +178,9 @@ LL | 0u16 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0u16); - | ~~~~~~~~~~~~~~~~ +LL - 0u16 as i128; +LL + i128::from(0u16); + | error: casts from `u32` to `u64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:50:5 @@ -177,8 +191,9 @@ LL | 0u32 as u64; = help: an `as` cast can become silently lossy if the types change in the future help: use `u64::from` instead | -LL | u64::from(0u32); - | ~~~~~~~~~~~~~~~ +LL - 0u32 as u64; +LL + u64::from(0u32); + | error: casts from `u32` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:53:5 @@ -189,8 +204,9 @@ LL | 0u32 as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | i64::from(0u32); - | ~~~~~~~~~~~~~~~ +LL - 0u32 as i64; +LL + i64::from(0u32); + | error: casts from `u32` to `u128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:56:5 @@ -201,8 +217,9 @@ LL | 0u32 as u128; = help: an `as` cast can become silently lossy if the types change in the future help: use `u128::from` instead | -LL | u128::from(0u32); - | ~~~~~~~~~~~~~~~~ +LL - 0u32 as u128; +LL + u128::from(0u32); + | error: casts from `u32` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:59:5 @@ -213,8 +230,9 @@ LL | 0u32 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0u32); - | ~~~~~~~~~~~~~~~~ +LL - 0u32 as i128; +LL + i128::from(0u32); + | error: casts from `u64` to `u128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:62:5 @@ -225,8 +243,9 @@ LL | 0u64 as u128; = help: an `as` cast can become silently lossy if the types change in the future help: use `u128::from` instead | -LL | u128::from(0u64); - | ~~~~~~~~~~~~~~~~ +LL - 0u64 as u128; +LL + u128::from(0u64); + | error: casts from `u64` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:65:5 @@ -237,8 +256,9 @@ LL | 0u64 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0u64); - | ~~~~~~~~~~~~~~~~ +LL - 0u64 as i128; +LL + i128::from(0u64); + | error: casts from `i8` to `i16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:68:5 @@ -249,8 +269,9 @@ LL | 0i8 as i16; = help: an `as` cast can become silently lossy if the types change in the future help: use `i16::from` instead | -LL | i16::from(0i8); - | ~~~~~~~~~~~~~~ +LL - 0i8 as i16; +LL + i16::from(0i8); + | error: casts from `i8` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:71:5 @@ -261,8 +282,9 @@ LL | 0i8 as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | i32::from(0i8); - | ~~~~~~~~~~~~~~ +LL - 0i8 as i32; +LL + i32::from(0i8); + | error: casts from `i8` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:74:5 @@ -273,8 +295,9 @@ LL | 0i8 as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | i64::from(0i8); - | ~~~~~~~~~~~~~~ +LL - 0i8 as i64; +LL + i64::from(0i8); + | error: casts from `i8` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:77:5 @@ -285,8 +308,9 @@ LL | 0i8 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0i8); - | ~~~~~~~~~~~~~~~ +LL - 0i8 as i128; +LL + i128::from(0i8); + | error: casts from `i16` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:80:5 @@ -297,8 +321,9 @@ LL | 0i16 as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | i32::from(0i16); - | ~~~~~~~~~~~~~~~ +LL - 0i16 as i32; +LL + i32::from(0i16); + | error: casts from `i16` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:83:5 @@ -309,8 +334,9 @@ LL | 0i16 as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | i64::from(0i16); - | ~~~~~~~~~~~~~~~ +LL - 0i16 as i64; +LL + i64::from(0i16); + | error: casts from `i16` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:86:5 @@ -321,8 +347,9 @@ LL | 0i16 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0i16); - | ~~~~~~~~~~~~~~~~ +LL - 0i16 as i128; +LL + i128::from(0i16); + | error: casts from `i32` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:89:5 @@ -333,8 +360,9 @@ LL | 0i32 as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | i64::from(0i32); - | ~~~~~~~~~~~~~~~ +LL - 0i32 as i64; +LL + i64::from(0i32); + | error: casts from `i32` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:92:5 @@ -345,8 +373,9 @@ LL | 0i32 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0i32); - | ~~~~~~~~~~~~~~~~ +LL - 0i32 as i128; +LL + i128::from(0i32); + | error: casts from `i64` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:95:5 @@ -357,8 +386,9 @@ LL | 0i64 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0i64); - | ~~~~~~~~~~~~~~~~ +LL - 0i64 as i128; +LL + i128::from(0i64); + | error: casts from `u8` to `u16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:99:13 @@ -369,8 +399,9 @@ LL | let _ = (1u8 + 1u8) as u16; = help: an `as` cast can become silently lossy if the types change in the future help: use `u16::from` instead | -LL | let _ = u16::from(1u8 + 1u8); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _ = (1u8 + 1u8) as u16; +LL + let _ = u16::from(1u8 + 1u8); + | error: casts from `i8` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:102:13 @@ -381,8 +412,9 @@ LL | let _ = 1i8 as I64Alias; = help: an `as` cast can become silently lossy if the types change in the future help: use `I64Alias::from` instead | -LL | let _ = I64Alias::from(1i8); - | ~~~~~~~~~~~~~~~~~~~ +LL - let _ = 1i8 as I64Alias; +LL + let _ = I64Alias::from(1i8); + | error: casts from `u8` to `u16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:105:18 @@ -393,8 +425,9 @@ LL | let _: u16 = 0u8 as _; = help: an `as` cast can become silently lossy if the types change in the future help: use `Into::into` instead | -LL | let _: u16 = 0u8.into(); - | ~~~~~~~~~~ +LL - let _: u16 = 0u8 as _; +LL + let _: u16 = 0u8.into(); + | error: casts from `i8` to `i16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:108:18 @@ -405,8 +438,9 @@ LL | let _: i16 = -1i8 as _; = help: an `as` cast can become silently lossy if the types change in the future help: use `Into::into` instead | -LL | let _: i16 = (-1i8).into(); - | ~~~~~~~~~~~~~ +LL - let _: i16 = -1i8 as _; +LL + let _: i16 = (-1i8).into(); + | error: casts from `u8` to `u16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:111:18 @@ -417,8 +451,9 @@ LL | let _: u16 = (1u8 + 2) as _; = help: an `as` cast can become silently lossy if the types change in the future help: use `Into::into` instead | -LL | let _: u16 = (1u8 + 2).into(); - | ~~~~~~~~~~~~~~~~ +LL - let _: u16 = (1u8 + 2) as _; +LL + let _: u16 = (1u8 + 2).into(); + | error: casts from `u16` to `u32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:114:18 @@ -429,8 +464,9 @@ LL | let _: u32 = 1i8 as u16 as _; = help: an `as` cast can become silently lossy if the types change in the future help: use `Into::into` instead | -LL | let _: u32 = (1i8 as u16).into(); - | ~~~~~~~~~~~~~~~~~~~ +LL - let _: u32 = 1i8 as u16 as _; +LL + let _: u32 = (1i8 as u16).into(); + | error: casts from `i8` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:149:13 @@ -441,8 +477,9 @@ LL | let _ = sign_cast!(x, u8, i8) as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | let _ = i32::from(sign_cast!(x, u8, i8)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = sign_cast!(x, u8, i8) as i32; +LL + let _ = i32::from(sign_cast!(x, u8, i8)); + | error: casts from `i8` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:152:13 @@ -453,8 +490,9 @@ LL | let _ = (sign_cast!(x, u8, i8) + 1) as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | let _ = i32::from(sign_cast!(x, u8, i8) + 1); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = (sign_cast!(x, u8, i8) + 1) as i32; +LL + let _ = i32::from(sign_cast!(x, u8, i8) + 1); + | error: casts from `u8` to `u32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:159:13 @@ -469,7 +507,8 @@ LL | let _ = in_macro!(); = note: this error originates in the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) help: use `u32::from` instead | -LL | u32::from(1u8) +LL - 1u8 as u32 +LL + u32::from(1u8) | error: casts from `u8` to `u32` can be expressed infallibly using `From` @@ -481,8 +520,9 @@ LL | let _ = 0u8 as ty!(); = help: an `as` cast can become silently lossy if the types change in the future help: use `::from` instead | -LL | let _ = ::from(0u8); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = 0u8 as ty!(); +LL + let _ = ::from(0u8); + | error: aborting due to 40 previous errors diff --git a/tests/ui/cast_size.32bit.stderr b/tests/ui/cast_size.32bit.stderr index 637dd6fddea1..cb1620e36a26 100644 --- a/tests/ui/cast_size.32bit.stderr +++ b/tests/ui/cast_size.32bit.stderr @@ -9,8 +9,9 @@ LL | 1isize as i8; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_truncation)]` help: ... or use `try_from` and handle the error accordingly | -LL | i8::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~ +LL - 1isize as i8; +LL + i8::try_from(1isize); + | error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) --> tests/ui/cast_size.rs:24:5 @@ -48,8 +49,9 @@ LL | 1isize as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i32::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1isize as i32; +LL + i32::try_from(1isize); + | error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:37:5 @@ -60,8 +62,9 @@ LL | 1isize as u32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | u32::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1isize as u32; +LL + u32::try_from(1isize); + | error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:39:5 @@ -72,8 +75,9 @@ LL | 1usize as u32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | u32::try_from(1usize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as u32; +LL + u32::try_from(1usize); + | error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:41:5 @@ -84,8 +88,9 @@ LL | 1usize as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i32::try_from(1usize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as i32; +LL + i32::try_from(1usize); + | error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:41:5 @@ -105,8 +110,9 @@ LL | 1i64 as isize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | isize::try_from(1i64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1i64 as isize; +LL + isize::try_from(1i64); + | error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:46:5 @@ -117,8 +123,9 @@ LL | 1i64 as usize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | usize::try_from(1i64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1i64 as usize; +LL + usize::try_from(1i64); + | error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:48:5 @@ -129,8 +136,9 @@ LL | 1u64 as isize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | isize::try_from(1u64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1u64 as isize; +LL + isize::try_from(1u64); + | error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:48:5 @@ -147,8 +155,9 @@ LL | 1u64 as usize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | usize::try_from(1u64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1u64 as usize; +LL + usize::try_from(1u64); + | error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:53:5 diff --git a/tests/ui/cast_size.64bit.stderr b/tests/ui/cast_size.64bit.stderr index 0e12ecb6f2da..b6000a52abb3 100644 --- a/tests/ui/cast_size.64bit.stderr +++ b/tests/ui/cast_size.64bit.stderr @@ -9,8 +9,9 @@ LL | 1isize as i8; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_truncation)]` help: ... or use `try_from` and handle the error accordingly | -LL | i8::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~ +LL - 1isize as i8; +LL + i8::try_from(1isize); + | error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) --> tests/ui/cast_size.rs:24:5 @@ -48,8 +49,9 @@ LL | 1isize as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i32::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1isize as i32; +LL + i32::try_from(1isize); + | error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:37:5 @@ -60,8 +62,9 @@ LL | 1isize as u32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | u32::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1isize as u32; +LL + u32::try_from(1isize); + | error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:39:5 @@ -72,8 +75,9 @@ LL | 1usize as u32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | u32::try_from(1usize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as u32; +LL + u32::try_from(1usize); + | error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:41:5 @@ -84,8 +88,9 @@ LL | 1usize as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i32::try_from(1usize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as i32; +LL + i32::try_from(1usize); + | error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:41:5 @@ -105,8 +110,9 @@ LL | 1i64 as isize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | isize::try_from(1i64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1i64 as isize; +LL + isize::try_from(1i64); + | error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:46:5 @@ -117,8 +123,9 @@ LL | 1i64 as usize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | usize::try_from(1i64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1i64 as usize; +LL + usize::try_from(1i64); + | error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:48:5 @@ -129,8 +136,9 @@ LL | 1u64 as isize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | isize::try_from(1u64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1u64 as isize; +LL + isize::try_from(1u64); + | error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:48:5 @@ -147,8 +155,9 @@ LL | 1u64 as usize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | usize::try_from(1u64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1u64 as usize; +LL + usize::try_from(1u64); + | error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:53:5 diff --git a/tests/ui/create_dir.stderr b/tests/ui/create_dir.stderr index 2aba2944aa60..51d6ac686e02 100644 --- a/tests/ui/create_dir.stderr +++ b/tests/ui/create_dir.stderr @@ -8,8 +8,9 @@ LL | std::fs::create_dir("foo"); = help: to override `-D warnings` add `#[allow(clippy::create_dir)]` help: consider calling `std::fs::create_dir_all` instead | -LL | create_dir_all("foo"); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - std::fs::create_dir("foo"); +LL + create_dir_all("foo"); + | error: calling `std::fs::create_dir` where there may be a better way --> tests/ui/create_dir.rs:12:5 @@ -19,8 +20,9 @@ LL | std::fs::create_dir("bar").unwrap(); | help: consider calling `std::fs::create_dir_all` instead | -LL | create_dir_all("bar").unwrap(); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - std::fs::create_dir("bar").unwrap(); +LL + create_dir_all("bar").unwrap(); + | error: aborting due to 2 previous errors diff --git a/tests/ui/dbg_macro/dbg_macro.stderr b/tests/ui/dbg_macro/dbg_macro.stderr index 83b497a539c0..cd6dce584a2f 100644 --- a/tests/ui/dbg_macro/dbg_macro.stderr +++ b/tests/ui/dbg_macro/dbg_macro.stderr @@ -8,8 +8,9 @@ LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } = help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]` help: remove the invocation before committing it to a version control system | -LL | if let Some(n) = n.checked_sub(4) { n } else { n } - | ~~~~~~~~~~~~~~~~ +LL - if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } +LL + if let Some(n) = n.checked_sub(4) { n } else { n } + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:11:8 @@ -19,8 +20,9 @@ LL | if dbg!(n <= 1) { | help: remove the invocation before committing it to a version control system | -LL | if n <= 1 { - | ~~~~~~ +LL - if dbg!(n <= 1) { +LL + if n <= 1 { + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:14:9 @@ -30,7 +32,8 @@ LL | dbg!(1) | help: remove the invocation before committing it to a version control system | -LL | 1 +LL - dbg!(1) +LL + 1 | error: the `dbg!` macro is intended as a debugging tool @@ -41,7 +44,8 @@ LL | dbg!(n * factorial(n - 1)) | help: remove the invocation before committing it to a version control system | -LL | n * factorial(n - 1) +LL - dbg!(n * factorial(n - 1)) +LL + n * factorial(n - 1) | error: the `dbg!` macro is intended as a debugging tool @@ -52,8 +56,9 @@ LL | dbg!(42); | help: remove the invocation before committing it to a version control system | -LL | 42; - | ~~ +LL - dbg!(42); +LL + 42; + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:26:14 @@ -63,8 +68,9 @@ LL | foo(3) + dbg!(factorial(4)); | help: remove the invocation before committing it to a version control system | -LL | foo(3) + factorial(4); - | ~~~~~~~~~~~~ +LL - foo(3) + dbg!(factorial(4)); +LL + foo(3) + factorial(4); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:29:5 @@ -74,8 +80,9 @@ LL | dbg!(1, 2, 3, 4, 5); | help: remove the invocation before committing it to a version control system | -LL | (1, 2, 3, 4, 5); - | ~~~~~~~~~~~~~~~ +LL - dbg!(1, 2, 3, 4, 5); +LL + (1, 2, 3, 4, 5); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:51:5 @@ -96,8 +103,9 @@ LL | let _ = dbg!(); | help: remove the invocation before committing it to a version control system | -LL | let _ = (); - | ~~ +LL - let _ = dbg!(); +LL + let _ = (); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:58:9 @@ -107,8 +115,9 @@ LL | bar(dbg!()); | help: remove the invocation before committing it to a version control system | -LL | bar(()); - | ~~ +LL - bar(dbg!()); +LL + bar(()); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:61:10 @@ -118,8 +127,9 @@ LL | foo!(dbg!()); | help: remove the invocation before committing it to a version control system | -LL | foo!(()); - | ~~ +LL - foo!(dbg!()); +LL + foo!(()); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:64:16 @@ -129,8 +139,9 @@ LL | foo2!(foo!(dbg!())); | help: remove the invocation before committing it to a version control system | -LL | foo2!(foo!(())); - | ~~ +LL - foo2!(foo!(dbg!())); +LL + foo2!(foo!(())); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:46:13 @@ -155,8 +166,9 @@ LL | dbg!(2); | help: remove the invocation before committing it to a version control system | -LL | 2; - | ~ +LL - dbg!(2); +LL + 2; + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:94:5 @@ -166,8 +178,9 @@ LL | dbg!(1); | help: remove the invocation before committing it to a version control system | -LL | 1; - | ~ +LL - dbg!(1); +LL + 1; + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:100:5 @@ -177,8 +190,9 @@ LL | dbg!(1); | help: remove the invocation before committing it to a version control system | -LL | 1; - | ~ +LL - dbg!(1); +LL + 1; + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:107:9 @@ -188,8 +202,9 @@ LL | dbg!(1); | help: remove the invocation before committing it to a version control system | -LL | 1; - | ~ +LL - dbg!(1); +LL + 1; + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:114:31 @@ -199,8 +214,9 @@ LL | println!("dbg: {:?}", dbg!(s)); | help: remove the invocation before committing it to a version control system | -LL | println!("dbg: {:?}", s); - | ~ +LL - println!("dbg: {:?}", dbg!(s)); +LL + println!("dbg: {:?}", s); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:117:22 @@ -210,8 +226,9 @@ LL | print!("{}", dbg!(s)); | help: remove the invocation before committing it to a version control system | -LL | print!("{}", s); - | ~ +LL - print!("{}", dbg!(s)); +LL + print!("{}", s); + | error: aborting due to 19 previous errors diff --git a/tests/ui/dbg_macro/dbg_macro_unfixable.stderr b/tests/ui/dbg_macro/dbg_macro_unfixable.stderr index df053a7a5f21..afade6f08b3c 100644 --- a/tests/ui/dbg_macro/dbg_macro_unfixable.stderr +++ b/tests/ui/dbg_macro/dbg_macro_unfixable.stderr @@ -19,8 +19,9 @@ LL | dbg!(dbg!(dbg!(42))); | help: remove the invocation before committing it to a version control system | -LL | dbg!(dbg!(42)); - | ~~~~~~~~~~~~~~ +LL - dbg!(dbg!(dbg!(42))); +LL + dbg!(dbg!(42)); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:9:10 @@ -30,8 +31,9 @@ LL | dbg!(dbg!(dbg!(42))); | help: remove the invocation before committing it to a version control system | -LL | dbg!(dbg!(42)); - | ~~~~~~~~ +LL - dbg!(dbg!(dbg!(42))); +LL + dbg!(dbg!(42)); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:9:15 @@ -41,8 +43,9 @@ LL | dbg!(dbg!(dbg!(42))); | help: remove the invocation before committing it to a version control system | -LL | dbg!(dbg!(42)); - | ~~ +LL - dbg!(dbg!(dbg!(42))); +LL + dbg!(dbg!(42)); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:14:5 @@ -52,8 +55,9 @@ LL | dbg!(1, 2, dbg!(3, 4)); | help: remove the invocation before committing it to a version control system | -LL | (1, 2, dbg!(3, 4)); - | ~~~~~~~~~~~~~~~~~~ +LL - dbg!(1, 2, dbg!(3, 4)); +LL + (1, 2, dbg!(3, 4)); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:14:16 @@ -63,8 +67,9 @@ LL | dbg!(1, 2, dbg!(3, 4)); | help: remove the invocation before committing it to a version control system | -LL | dbg!(1, 2, (3, 4)); - | ~~~~~~ +LL - dbg!(1, 2, dbg!(3, 4)); +LL + dbg!(1, 2, (3, 4)); + | error: aborting due to 6 previous errors diff --git a/tests/ui/doc/doc-fixable.stderr b/tests/ui/doc/doc-fixable.stderr index f630f72ca854..d67da75a230c 100644 --- a/tests/ui/doc/doc-fixable.stderr +++ b/tests/ui/doc/doc-fixable.stderr @@ -8,8 +8,9 @@ LL | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot t = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | -LL | /// The `foo_bar` function does _nothing_. See also foo::bar. (note the dot there) - | ~~~~~~~~~ +LL - /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) +LL + /// The `foo_bar` function does _nothing_. See also foo::bar. (note the dot there) + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:9:51 @@ -19,8 +20,9 @@ LL | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot t | help: try | -LL | /// The foo_bar function does _nothing_. See also `foo::bar`. (note the dot there) - | ~~~~~~~~~~ +LL - /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) +LL + /// The foo_bar function does _nothing_. See also `foo::bar`. (note the dot there) + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:12:83 @@ -30,8 +32,9 @@ LL | /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. B | help: try | -LL | /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not `Foo::some_fun` - | ~~~~~~~~~~~~~~~ +LL - /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not Foo::some_fun +LL + /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not `Foo::some_fun` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:15:13 @@ -41,8 +44,9 @@ LL | /// Here be ::a::global:path, and _::another::global::path_. :: is not a p | help: try | -LL | /// Here be `::a::global:path`, and _::another::global::path_. :: is not a path though. - | ~~~~~~~~~~~~~~~~~~ +LL - /// Here be ::a::global:path, and _::another::global::path_. :: is not a path though. +LL + /// Here be `::a::global:path`, and _::another::global::path_. :: is not a path though. + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:15:36 @@ -52,8 +56,9 @@ LL | /// Here be ::a::global:path, and _::another::global::path_. :: is not a p | help: try | -LL | /// Here be ::a::global:path, and _`::another::global::path`_. :: is not a path though. - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// Here be ::a::global:path, and _::another::global::path_. :: is not a path though. +LL + /// Here be ::a::global:path, and _`::another::global::path`_. :: is not a path though. + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:18:25 @@ -63,8 +68,9 @@ LL | /// Import an item from ::awesome::global::blob:: (Intended postfix) | help: try | -LL | /// Import an item from `::awesome::global::blob::` (Intended postfix) - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// Import an item from ::awesome::global::blob:: (Intended postfix) +LL + /// Import an item from `::awesome::global::blob::` (Intended postfix) + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:20:31 @@ -74,8 +80,9 @@ LL | /// These are the options for ::Cat: (Intended trailing single colon, shoul | help: try | -LL | /// These are the options for `::Cat`: (Intended trailing single colon, shouldn't be linted) - | ~~~~~~~ +LL - /// These are the options for ::Cat: (Intended trailing single colon, shouldn't be linted) +LL + /// These are the options for `::Cat`: (Intended trailing single colon, shouldn't be linted) + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:22:22 @@ -85,8 +92,9 @@ LL | /// That's not code ~NotInCodeBlock~. | help: try | -LL | /// That's not code ~`NotInCodeBlock`~. - | ~~~~~~~~~~~~~~~~ +LL - /// That's not code ~NotInCodeBlock~. +LL + /// That's not code ~`NotInCodeBlock`~. + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:24:5 @@ -96,8 +104,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:39:5 @@ -107,8 +116,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:47:5 @@ -118,8 +128,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:62:5 @@ -129,8 +140,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:91:5 @@ -140,8 +152,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:109:5 @@ -151,8 +164,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:118:8 @@ -162,8 +176,9 @@ LL | /// ## CamelCaseThing | help: try | -LL | /// ## `CamelCaseThing` - | ~~~~~~~~~~~~~~~~ +LL - /// ## CamelCaseThing +LL + /// ## `CamelCaseThing` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:122:7 @@ -173,8 +188,9 @@ LL | /// # CamelCaseThing | help: try | -LL | /// # `CamelCaseThing` - | ~~~~~~~~~~~~~~~~ +LL - /// # CamelCaseThing +LL + /// # `CamelCaseThing` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:125:22 @@ -184,8 +200,9 @@ LL | /// Not a title #897 CamelCaseThing | help: try | -LL | /// Not a title #897 `CamelCaseThing` - | ~~~~~~~~~~~~~~~~ +LL - /// Not a title #897 CamelCaseThing +LL + /// Not a title #897 `CamelCaseThing` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:127:5 @@ -195,8 +212,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:135:5 @@ -206,8 +224,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:149:5 @@ -217,8 +236,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:161:43 @@ -228,8 +248,9 @@ LL | /** E.g., serialization of an empty list: FooBar | help: try | -LL | /** E.g., serialization of an empty list: `FooBar` - | ~~~~~~~~ +LL - /** E.g., serialization of an empty list: FooBar +LL + /** E.g., serialization of an empty list: `FooBar` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:166:5 @@ -239,8 +260,9 @@ LL | And BarQuz too. | help: try | -LL | And `BarQuz` too. - | ~~~~~~~~ +LL - And BarQuz too. +LL + And `BarQuz` too. + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:167:1 @@ -250,7 +272,8 @@ LL | be_sure_we_got_to_the_end_of_it | help: try | -LL | `be_sure_we_got_to_the_end_of_it` +LL - be_sure_we_got_to_the_end_of_it +LL + `be_sure_we_got_to_the_end_of_it` | error: item in documentation is missing backticks @@ -261,8 +284,9 @@ LL | /** E.g., serialization of an empty list: FooBar | help: try | -LL | /** E.g., serialization of an empty list: `FooBar` - | ~~~~~~~~ +LL - /** E.g., serialization of an empty list: FooBar +LL + /** E.g., serialization of an empty list: `FooBar` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:180:5 @@ -272,8 +296,9 @@ LL | And BarQuz too. | help: try | -LL | And `BarQuz` too. - | ~~~~~~~~ +LL - And BarQuz too. +LL + And `BarQuz` too. + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:181:1 @@ -283,7 +308,8 @@ LL | be_sure_we_got_to_the_end_of_it | help: try | -LL | `be_sure_we_got_to_the_end_of_it` +LL - be_sure_we_got_to_the_end_of_it +LL + `be_sure_we_got_to_the_end_of_it` | error: item in documentation is missing backticks @@ -294,8 +320,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:215:22 @@ -305,8 +332,9 @@ LL | /// An iterator over mycrate::Collection's values. | help: try | -LL | /// An iterator over `mycrate::Collection`'s values. - | ~~~~~~~~~~~~~~~~~~~~~ +LL - /// An iterator over mycrate::Collection's values. +LL + /// An iterator over `mycrate::Collection`'s values. + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:240:34 @@ -316,8 +344,9 @@ LL | /// Foo \[bar\] \[baz\] \[qux\]. DocMarkdownLint | help: try | -LL | /// Foo \[bar\] \[baz\] \[qux\]. `DocMarkdownLint` - | ~~~~~~~~~~~~~~~~~ +LL - /// Foo \[bar\] \[baz\] \[qux\]. DocMarkdownLint +LL + /// Foo \[bar\] \[baz\] \[qux\]. `DocMarkdownLint` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:264:22 @@ -327,8 +356,9 @@ LL | /// There is no try (do() or do_not()). | help: try | -LL | /// There is no try (`do()` or do_not()). - | ~~~~~~ +LL - /// There is no try (do() or do_not()). +LL + /// There is no try (`do()` or do_not()). + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:264:30 @@ -338,8 +368,9 @@ LL | /// There is no try (do() or do_not()). | help: try | -LL | /// There is no try (do() or `do_not()`). - | ~~~~~~~~~~ +LL - /// There is no try (do() or do_not()). +LL + /// There is no try (do() or `do_not()`). + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:269:5 @@ -349,8 +380,9 @@ LL | /// ABes | help: try | -LL | /// `ABes` - | ~~~~~~ +LL - /// ABes +LL + /// `ABes` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:276:9 @@ -360,8 +392,9 @@ LL | /// foo() | help: try | -LL | /// `foo()` - | ~~~~~~~ +LL - /// foo() +LL + /// `foo()` + | error: you should put bare URLs between `<`/`>` or make a proper Markdown link --> tests/ui/doc/doc-fixable.rs:281:5 diff --git a/tests/ui/doc/doc_markdown-issue_13097.stderr b/tests/ui/doc/doc_markdown-issue_13097.stderr index ae68a767ec93..65b8f2ed80b6 100644 --- a/tests/ui/doc/doc_markdown-issue_13097.stderr +++ b/tests/ui/doc/doc_markdown-issue_13097.stderr @@ -11,8 +11,9 @@ LL | #![deny(clippy::doc_markdown)] | ^^^^^^^^^^^^^^^^^^^^ help: try | -LL | /// `HumaNified` - | ~~~~~~~~~~~~ +LL - /// HumaNified +LL + /// `HumaNified` + | error: aborting due to 1 previous error diff --git a/tests/ui/doc/issue_10262.stderr b/tests/ui/doc/issue_10262.stderr index f43d9551e94e..f9ecb3de219b 100644 --- a/tests/ui/doc/issue_10262.stderr +++ b/tests/ui/doc/issue_10262.stderr @@ -8,8 +8,9 @@ LL | /// AviSynth documentation: = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | -LL | /// `AviSynth` documentation: - | ~~~~~~~~~~ +LL - /// AviSynth documentation: +LL + /// `AviSynth` documentation: + | error: aborting due to 1 previous error diff --git a/tests/ui/doc/issue_12795.stderr b/tests/ui/doc/issue_12795.stderr index 5700145ec8f7..047de915ed4c 100644 --- a/tests/ui/doc/issue_12795.stderr +++ b/tests/ui/doc/issue_12795.stderr @@ -8,8 +8,9 @@ LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b( = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | -LL | //! A comment with `a_b(x)` and a_c in it and (a_b((c)) ) too and (maybe a_b((c))) - | ~~~~~~~~ +LL - //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c))) +LL + //! A comment with `a_b(x)` and a_c in it and (a_b((c)) ) too and (maybe a_b((c))) + | error: item in documentation is missing backticks --> tests/ui/doc/issue_12795.rs:3:31 @@ -19,8 +20,9 @@ LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b( | help: try | -LL | //! A comment with a_b(x) and `a_c` in it and (a_b((c)) ) too and (maybe a_b((c))) - | ~~~~~ +LL - //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c))) +LL + //! A comment with a_b(x) and `a_c` in it and (a_b((c)) ) too and (maybe a_b((c))) + | error: item in documentation is missing backticks --> tests/ui/doc/issue_12795.rs:3:46 @@ -30,8 +32,9 @@ LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b( | help: try | -LL | //! A comment with a_b(x) and a_c in it and (`a_b((c))` ) too and (maybe a_b((c))) - | ~~~~~~~~~~ +LL - //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c))) +LL + //! A comment with a_b(x) and a_c in it and (`a_b((c))` ) too and (maybe a_b((c))) + | error: item in documentation is missing backticks --> tests/ui/doc/issue_12795.rs:3:72 @@ -41,8 +44,9 @@ LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b( | help: try | -LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe `a_b((c))`) - | ~~~~~~~~~~ +LL - //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c))) +LL + //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe `a_b((c))`) + | error: aborting due to 4 previous errors diff --git a/tests/ui/doc/issue_9473.stderr b/tests/ui/doc/issue_9473.stderr index 35aa2884cc11..744c8dc8c838 100644 --- a/tests/ui/doc/issue_9473.stderr +++ b/tests/ui/doc/issue_9473.stderr @@ -8,8 +8,9 @@ LL | /// Blah blah blah [FooBar]<[FooBar]>[FooBar]. = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | -LL | /// Blah blah blah [FooBar]<[FooBar]>[`FooBar`]. - | ~~~~~~~~ +LL - /// Blah blah blah [FooBar]<[FooBar]>[FooBar]. +LL + /// Blah blah blah [FooBar]<[FooBar]>[`FooBar`]. + | error: aborting due to 1 previous error diff --git a/tests/ui/doc/link_adjacent.stderr b/tests/ui/doc/link_adjacent.stderr index f09762fb6a0b..27e8a73c7083 100644 --- a/tests/ui/doc/link_adjacent.stderr +++ b/tests/ui/doc/link_adjacent.stderr @@ -9,8 +9,9 @@ LL | //! This is: [`first`](x)`second` = help: to override `-D warnings` add `#[allow(clippy::doc_link_code)]` help: wrap the entire group in `` tags | -LL | //! This is: [first](x)second - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - //! This is: [`first`](x)`second` +LL + //! This is: [first](x)second + | error: code link adjacent to code text --> tests/ui/doc/link_adjacent.rs:16:16 @@ -21,8 +22,9 @@ LL | //! So is this `first`[`second`](x) = help: separate code snippets will be shown with a gap help: wrap the entire group in `` tags | -LL | //! So is this first[second](x) - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - //! So is this `first`[`second`](x) +LL + //! So is this first[second](x) + | error: code link adjacent to code text --> tests/ui/doc/link_adjacent.rs:19:16 @@ -33,8 +35,9 @@ LL | //! So is this [`first`](x)[`second`](x) = help: separate code snippets will be shown with a gap help: wrap the entire group in `` tags | -LL | //! So is this [first](x)[second](x) - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - //! So is this [`first`](x)[`second`](x) +LL + //! So is this [first](x)[second](x) + | error: code link adjacent to code text --> tests/ui/doc/link_adjacent.rs:22:16 @@ -45,8 +48,9 @@ LL | //! So is this [`first`](x)[`second`](x)[`third`](x) = help: separate code snippets will be shown with a gap help: wrap the entire group in `` tags | -LL | //! So is this [first](x)[second](x)[third](x) - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - //! So is this [`first`](x)[`second`](x)[`third`](x) +LL + //! So is this [first](x)[second](x)[third](x) + | error: code link adjacent to code text --> tests/ui/doc/link_adjacent.rs:25:16 @@ -57,8 +61,9 @@ LL | //! So is this [`first`](x)`second`[`third`](x) = help: separate code snippets will be shown with a gap help: wrap the entire group in `` tags | -LL | //! So is this [first](x)second[third](x) - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - //! So is this [`first`](x)`second`[`third`](x) +LL + //! So is this [first](x)second[third](x) + | error: code link adjacent to code text --> tests/ui/doc/link_adjacent.rs:38:14 @@ -69,8 +74,9 @@ LL | /// This is: [`first`](x)`second` arst = help: separate code snippets will be shown with a gap help: wrap the entire group in `` tags | -LL | /// This is: [first](x)second arst - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// This is: [`first`](x)`second` arst +LL + /// This is: [first](x)second arst + | error: code link adjacent to code text --> tests/ui/doc/link_adjacent.rs:41:16 @@ -81,8 +87,9 @@ LL | /// So is this `first`[`second`](x) arst = help: separate code snippets will be shown with a gap help: wrap the entire group in `` tags | -LL | /// So is this first[second](x) arst - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// So is this `first`[`second`](x) arst +LL + /// So is this first[second](x) arst + | error: code link adjacent to code text --> tests/ui/doc/link_adjacent.rs:44:16 @@ -93,8 +100,9 @@ LL | /// So is this [`first`](x)[`second`](x) arst = help: separate code snippets will be shown with a gap help: wrap the entire group in `` tags | -LL | /// So is this [first](x)[second](x) arst - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// So is this [`first`](x)[`second`](x) arst +LL + /// So is this [first](x)[second](x) arst + | error: code link adjacent to code text --> tests/ui/doc/link_adjacent.rs:47:16 @@ -105,8 +113,9 @@ LL | /// So is this [`first`](x)[`second`](x)[`third`](x) arst = help: separate code snippets will be shown with a gap help: wrap the entire group in `` tags | -LL | /// So is this [first](x)[second](x)[third](x) arst - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// So is this [`first`](x)[`second`](x)[`third`](x) arst +LL + /// So is this [first](x)[second](x)[third](x) arst + | error: code link adjacent to code text --> tests/ui/doc/link_adjacent.rs:50:16 @@ -117,8 +126,9 @@ LL | /// So is this [`first`](x)`second`[`third`](x) arst = help: separate code snippets will be shown with a gap help: wrap the entire group in `` tags | -LL | /// So is this [first](x)second[third](x) arst - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// So is this [`first`](x)`second`[`third`](x) arst +LL + /// So is this [first](x)second[third](x) arst + | error: aborting due to 10 previous errors diff --git a/tests/ui/doc/unbalanced_ticks.rs b/tests/ui/doc/unbalanced_ticks.rs index e8cfe44a6789..76befb15db80 100644 --- a/tests/ui/doc/unbalanced_ticks.rs +++ b/tests/ui/doc/unbalanced_ticks.rs @@ -66,3 +66,20 @@ fn escape_3() {} /// Backslashes ` \` within code blocks don't count. fn escape_4() {} + +trait Foo { + fn bar(); +} + +struct Bar; +impl Foo for Bar { + // NOTE: false positive + /// Returns an `Option` from a i64, assuming a 1-index, January = 1. + /// + /// `Month::from_i64(n: i64)`: | `1` | `2` | ... | `12` + /// ---------------------------| -------------------- | --------------------- | ... | ----- + /// ``: | Some(Month::January) | Some(Month::February) | ... | + /// Some(Month::December) + //~^^^^ doc_markdown + fn bar() {} +} diff --git a/tests/ui/doc/unbalanced_ticks.stderr b/tests/ui/doc/unbalanced_ticks.stderr index 50324010e97f..4114a823822c 100644 --- a/tests/ui/doc/unbalanced_ticks.stderr +++ b/tests/ui/doc/unbalanced_ticks.stderr @@ -29,8 +29,9 @@ LL | /// This paragraph is fine and should_be linted normally. | help: try | -LL | /// This paragraph is fine and `should_be` linted normally. - | ~~~~~~~~~~~ +LL - /// This paragraph is fine and should_be linted normally. +LL + /// This paragraph is fine and `should_be` linted normally. + | error: backticks are unbalanced --> tests/ui/doc/unbalanced_ticks.rs:20:5 @@ -48,8 +49,9 @@ LL | /// ## not_fine | help: try | -LL | /// ## `not_fine` - | ~~~~~~~~~~ +LL - /// ## not_fine +LL + /// ## `not_fine` + | error: backticks are unbalanced --> tests/ui/doc/unbalanced_ticks.rs:37:5 @@ -75,8 +77,9 @@ LL | /// - This item needs backticks_here | help: try | -LL | /// - This item needs `backticks_here` - | ~~~~~~~~~~~~~~~~ +LL - /// - This item needs backticks_here +LL + /// - This item needs `backticks_here` + | error: backticks are unbalanced --> tests/ui/doc/unbalanced_ticks.rs:53:5 @@ -94,5 +97,17 @@ LL | /// Escaped \` ` backticks don't count, but unescaped backticks do. | = help: a backtick may be missing a pair -error: aborting due to 10 previous errors +error: backticks are unbalanced + --> tests/ui/doc/unbalanced_ticks.rs:79:9 + | +LL | /// `Month::from_i64(n: i64)`: | `1` | `2` | ... | `12` + | _________^ +LL | | /// ---------------------------| -------------------- | --------------------- | ... | ----- +LL | | /// ``: | Some(Month::January) | Some(Month::February) | ... | +LL | | /// Some(Month::December) + | |_____________________________^ + | + = help: a backtick may be missing a pair + +error: aborting due to 11 previous errors diff --git a/tests/ui/eager_transmute.stderr b/tests/ui/eager_transmute.stderr index e31c12eb5222..54850d110eb2 100644 --- a/tests/ui/eager_transmute.stderr +++ b/tests/ui/eager_transmute.stderr @@ -8,8 +8,9 @@ LL | (op < 4).then_some(unsafe { std::mem::transmute(op) }) = help: to override `-D warnings` add `#[allow(clippy::eager_transmute)]` help: consider using `bool::then` to only transmute if the condition holds | -LL | (op < 4).then(|| unsafe { std::mem::transmute(op) }) - | ~~~~ ++ +LL - (op < 4).then_some(unsafe { std::mem::transmute(op) }) +LL + (op < 4).then(|| unsafe { std::mem::transmute(op) }) + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:28:33 @@ -19,8 +20,9 @@ LL | (op < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | help: consider using `bool::then` to only transmute if the condition holds | -LL | (op < 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); - | ~~~~ ++ +LL - (op < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); +LL + (op < 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:30:33 @@ -30,8 +32,9 @@ LL | (op > 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | help: consider using `bool::then` to only transmute if the condition holds | -LL | (op > 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); - | ~~~~ ++ +LL - (op > 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); +LL + (op > 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:32:34 @@ -41,8 +44,9 @@ LL | (op == 0).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | help: consider using `bool::then` to only transmute if the condition holds | -LL | (op == 0).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); - | ~~~~ ++ +LL - (op == 0).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); +LL + (op == 0).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:35:68 @@ -52,8 +56,9 @@ LL | let _: Option = (op > 0 && op < 10).then_some(unsafe { std::mem | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (op > 0 && op < 10).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (op > 0 && op < 10).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (op > 0 && op < 10).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:37:86 @@ -63,8 +68,9 @@ LL | let _: Option = (op > 0 && op < 10 && unrelated == 0).then_some | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (op > 0 && op < 10 && unrelated == 0).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (op > 0 && op < 10 && unrelated == 0).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (op > 0 && op < 10 && unrelated == 0).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:41:84 @@ -74,8 +80,9 @@ LL | let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(u | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then(|| unsafe { std::mem::transmute(op2.foo[0]) }); - | ~~~~ ++ +LL - let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(unsafe { std::mem::transmute(op2.foo[0]) }); +LL + let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then(|| unsafe { std::mem::transmute(op2.foo[0]) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:54:70 @@ -85,8 +92,9 @@ LL | let _: Option = (1..=3).contains(&op).then_some(unsafe { std::m | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (1..=3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (1..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (1..=3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:56:83 @@ -96,8 +104,9 @@ LL | let _: Option = ((1..=3).contains(&op) || op == 4).then_some(un | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = ((1..=3).contains(&op) || op == 4).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = ((1..=3).contains(&op) || op == 4).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = ((1..=3).contains(&op) || op == 4).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:58:69 @@ -107,8 +116,9 @@ LL | let _: Option = (1..3).contains(&op).then_some(unsafe { std::me | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (1..3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (1..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (1..3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:60:68 @@ -118,8 +128,9 @@ LL | let _: Option = (1..).contains(&op).then_some(unsafe { std::mem | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (1..).contains(&op).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (1..).contains(&op).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (1..).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:62:68 @@ -129,8 +140,9 @@ LL | let _: Option = (..3).contains(&op).then_some(unsafe { std::mem | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (..3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (..3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:64:69 @@ -140,8 +152,9 @@ LL | let _: Option = (..=3).contains(&op).then_some(unsafe { std::me | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (..=3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (..=3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:74:24 @@ -151,8 +164,9 @@ LL | (op < 4).then_some(std::mem::transmute::<_, Opcode>(op)); | help: consider using `bool::then` to only transmute if the condition holds | -LL | (op < 4).then(|| std::mem::transmute::<_, Opcode>(op)); - | ~~~~ ++ +LL - (op < 4).then_some(std::mem::transmute::<_, Opcode>(op)); +LL + (op < 4).then(|| std::mem::transmute::<_, Opcode>(op)); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:104:62 @@ -162,8 +176,9 @@ LL | let _: Option> = (v1 > 0).then_some(unsafe { std::mem::tran | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) }); - | ~~~~ ++ +LL - let _: Option> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) }); +LL + let _: Option> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:111:86 @@ -173,8 +188,9 @@ LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); - | ~~~~ ++ +LL - let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); +LL + let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:118:93 @@ -184,8 +200,9 @@ LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).th | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); - | ~~~~ ++ +LL - let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); +LL + let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); + | error: aborting due to 17 previous errors diff --git a/tests/ui/empty_line_after/doc_comments.1.fixed b/tests/ui/empty_line_after/doc_comments.1.fixed index fd6a94b6a80c..e4ba09ea1d47 100644 --- a/tests/ui/empty_line_after/doc_comments.1.fixed +++ b/tests/ui/empty_line_after/doc_comments.1.fixed @@ -132,4 +132,14 @@ pub struct BlockComment; ))] fn empty_line_in_cfg_attr() {} +trait Foo { + fn bar(); +} + +impl Foo for LineComment { + /// comment on assoc item + //~^ empty_line_after_doc_comments + fn bar() {} +} + fn main() {} diff --git a/tests/ui/empty_line_after/doc_comments.2.fixed b/tests/ui/empty_line_after/doc_comments.2.fixed index 7a57dcd92332..a20f9bc20eb5 100644 --- a/tests/ui/empty_line_after/doc_comments.2.fixed +++ b/tests/ui/empty_line_after/doc_comments.2.fixed @@ -141,4 +141,15 @@ pub struct BlockComment; ))] fn empty_line_in_cfg_attr() {} +trait Foo { + fn bar(); +} + +impl Foo for LineComment { + // /// comment on assoc item + //~^ empty_line_after_doc_comments + + fn bar() {} +} + fn main() {} diff --git a/tests/ui/empty_line_after/doc_comments.rs b/tests/ui/empty_line_after/doc_comments.rs index 1da761a5c3d5..9e3ddfd5abe1 100644 --- a/tests/ui/empty_line_after/doc_comments.rs +++ b/tests/ui/empty_line_after/doc_comments.rs @@ -144,4 +144,15 @@ pub struct BlockComment; ))] fn empty_line_in_cfg_attr() {} +trait Foo { + fn bar(); +} + +impl Foo for LineComment { + /// comment on assoc item + //~^ empty_line_after_doc_comments + + fn bar() {} +} + fn main() {} diff --git a/tests/ui/empty_line_after/doc_comments.stderr b/tests/ui/empty_line_after/doc_comments.stderr index c5d5f3d37594..fe25ba9afcb9 100644 --- a/tests/ui/empty_line_after/doc_comments.stderr +++ b/tests/ui/empty_line_after/doc_comments.stderr @@ -5,11 +5,11 @@ LL | / /// for the crate LL | | | |_^ LL | fn first_in_crate() {} - | ------------------- the comment documents this function + | ----------------- the comment documents this function | = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_doc_comments)]` - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the comment should document the crate use an inner doc comment | LL ~ //! Meant to be an @@ -24,9 +24,9 @@ LL | / /// for the module LL | | | |_^ LL | fn first_in_module() {} - | -------------------- the comment documents this function + | ------------------ the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the comment should document the parent module use an inner doc comment | LL ~ //! Meant to be an @@ -42,9 +42,9 @@ LL | | | |_^ LL | /// Blank line LL | fn indented() {} - | ------------- the comment documents this function + | ----------- the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the documentation should include the empty line include it in the comment | LL | /// @@ -57,9 +57,9 @@ LL | / /// This should produce a warning LL | | | |_^ LL | fn with_doc_and_newline() {} - | ------------------------- the comment documents this function + | ----------------------- the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty lines after doc comment --> tests/ui/empty_line_after/doc_comments.rs:44:1 @@ -72,9 +72,9 @@ LL | | | |_^ ... LL | fn three_attributes() {} - | --------------------- the comment documents this function + | ------------------- the comment documents this function | - = help: if the empty lines are unintentional remove them + = help: if the empty lines are unintentional, remove them error: empty line after doc comment --> tests/ui/empty_line_after/doc_comments.rs:56:5 @@ -84,9 +84,9 @@ LL | | // fn old_code() {} LL | | | |_^ LL | fn new_code() {} - | ------------- the comment documents this function + | ----------- the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the doc comment should not document `new_code` comment it out | LL | // /// docs for `old_code` @@ -106,7 +106,7 @@ LL | | LL | struct Multiple; | --------------- the comment documents this struct | - = help: if the empty lines are unintentional remove them + = help: if the empty lines are unintentional, remove them help: if the doc comment should not document `Multiple` comment it out | LL ~ // /// Docs @@ -126,13 +126,14 @@ LL | | */ LL | | | |_^ LL | fn first_in_module() {} - | -------------------- the comment documents this function + | ------------------ the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the comment should document the parent module use an inner doc comment | -LL | /*! - | ~ +LL - /** +LL + /*! + | error: empty line after doc comment --> tests/ui/empty_line_after/doc_comments.rs:85:5 @@ -145,9 +146,9 @@ LL | | | |_^ ... LL | fn new_code() {} - | ------------- the comment documents this function + | ----------- the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the doc comment should not document `new_code` comment it out | LL - /** @@ -163,13 +164,29 @@ LL | | | |_^ LL | /// Docs for `new_code2` LL | fn new_code2() {} - | -------------- the comment documents this function + | ------------ the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the doc comment should not document `new_code2` comment it out | LL | // /// Docs for `old_code2` | ++ -error: aborting due to 10 previous errors +error: empty line after doc comment + --> tests/ui/empty_line_after/doc_comments.rs:152:5 + | +LL | / /// comment on assoc item +LL | | +LL | | + | |_^ +LL | fn bar() {} + | ------ the comment documents this function + | + = help: if the empty line is unintentional, remove it +help: if the doc comment should not document `bar` comment it out + | +LL | // /// comment on assoc item + | ++ + +error: aborting due to 11 previous errors diff --git a/tests/ui/empty_line_after/outer_attribute.stderr b/tests/ui/empty_line_after/outer_attribute.stderr index a95306e2fa33..519ba6e67615 100644 --- a/tests/ui/empty_line_after/outer_attribute.stderr +++ b/tests/ui/empty_line_after/outer_attribute.stderr @@ -5,11 +5,11 @@ LL | / #[crate_type = "lib"] LL | | | |_^ LL | fn first_in_crate() {} - | ------------------- the attribute applies to this function + | ----------------- the attribute applies to this function | = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_outer_attr)]` - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the attribute should apply to the crate use an inner attribute | LL | #![crate_type = "lib"] @@ -23,9 +23,9 @@ LL | | | |_^ LL | /// some comment LL | fn with_one_newline_and_comment() {} - | --------------------------------- the attribute applies to this function + | ------------------------------- the attribute applies to this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty line after outer attribute --> tests/ui/empty_line_after/outer_attribute.rs:23:1 @@ -34,9 +34,9 @@ LL | / #[inline] LL | | | |_^ LL | fn with_one_newline() {} - | --------------------- the attribute applies to this function + | ------------------- the attribute applies to this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty lines after outer attribute --> tests/ui/empty_line_after/outer_attribute.rs:30:5 @@ -46,9 +46,9 @@ LL | | LL | | | |_^ LL | fn with_two_newlines() {} - | ---------------------- the attribute applies to this function + | -------------------- the attribute applies to this function | - = help: if the empty lines are unintentional remove them + = help: if the empty lines are unintentional, remove them help: if the attribute should apply to the parent module use an inner attribute | LL | #![crate_type = "lib"] @@ -63,7 +63,7 @@ LL | | LL | enum Baz { | -------- the attribute applies to this enum | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty line after outer attribute --> tests/ui/empty_line_after/outer_attribute.rs:45:1 @@ -74,7 +74,7 @@ LL | | LL | struct Foo { | ---------- the attribute applies to this struct | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty line after outer attribute --> tests/ui/empty_line_after/outer_attribute.rs:53:1 @@ -85,7 +85,7 @@ LL | | LL | mod foo {} | ------- the attribute applies to this module | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty line after outer attribute --> tests/ui/empty_line_after/outer_attribute.rs:58:1 @@ -95,9 +95,9 @@ LL | | // Still lint cases where the empty line does not immediately follow the LL | | | |_^ LL | fn comment_before_empty_line() {} - | ------------------------------ the attribute applies to this function + | ---------------------------- the attribute applies to this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty lines after outer attribute --> tests/ui/empty_line_after/outer_attribute.rs:64:1 @@ -107,9 +107,9 @@ LL | / #[allow(unused)] LL | | | |_^ LL | pub fn isolated_comment() {} - | ------------------------- the attribute applies to this function + | ----------------------- the attribute applies to this function | - = help: if the empty lines are unintentional remove them + = help: if the empty lines are unintentional, remove them error: aborting due to 9 previous errors diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr index 09fe3de4993a..934a367e1065 100644 --- a/tests/ui/excessive_precision.stderr +++ b/tests/ui/excessive_precision.stderr @@ -8,8 +8,9 @@ LL | const BAD32_1: f32 = 0.123_456_789_f32; = help: to override `-D warnings` add `#[allow(clippy::excessive_precision)]` help: consider changing the type or truncating it to | -LL | const BAD32_1: f32 = 0.123_456_79_f32; - | ~~~~~~~~~~~~~~~~ +LL - const BAD32_1: f32 = 0.123_456_789_f32; +LL + const BAD32_1: f32 = 0.123_456_79_f32; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:22:26 @@ -19,8 +20,9 @@ LL | const BAD32_2: f32 = 0.123_456_789; | help: consider changing the type or truncating it to | -LL | const BAD32_2: f32 = 0.123_456_79; - | ~~~~~~~~~~~~ +LL - const BAD32_2: f32 = 0.123_456_789; +LL + const BAD32_2: f32 = 0.123_456_79; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:24:26 @@ -30,8 +32,9 @@ LL | const BAD32_3: f32 = 0.100_000_000_000_1; | help: consider changing the type or truncating it to | -LL | const BAD32_3: f32 = 0.1; - | ~~~ +LL - const BAD32_3: f32 = 0.100_000_000_000_1; +LL + const BAD32_3: f32 = 0.1; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:26:29 @@ -41,8 +44,9 @@ LL | const BAD32_EDGE: f32 = 1.000_000_9; | help: consider changing the type or truncating it to | -LL | const BAD32_EDGE: f32 = 1.000_001; - | ~~~~~~~~~ +LL - const BAD32_EDGE: f32 = 1.000_000_9; +LL + const BAD32_EDGE: f32 = 1.000_001; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:31:26 @@ -52,8 +56,9 @@ LL | const BAD64_3: f64 = 0.100_000_000_000_000_000_1; | help: consider changing the type or truncating it to | -LL | const BAD64_3: f64 = 0.1; - | ~~~ +LL - const BAD64_3: f64 = 0.100_000_000_000_000_000_1; +LL + const BAD64_3: f64 = 0.1; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:35:22 @@ -63,8 +68,9 @@ LL | println!("{:?}", 8.888_888_888_888_888_888_888); | help: consider changing the type or truncating it to | -LL | println!("{:?}", 8.888_888_888_888_89); - | ~~~~~~~~~~~~~~~~~~~~ +LL - println!("{:?}", 8.888_888_888_888_888_888_888); +LL + println!("{:?}", 8.888_888_888_888_89); + | error: float has excessive precision --> tests/ui/excessive_precision.rs:47:22 @@ -74,8 +80,9 @@ LL | let bad32: f32 = 1.123_456_789; | help: consider changing the type or truncating it to | -LL | let bad32: f32 = 1.123_456_8; - | ~~~~~~~~~~~ +LL - let bad32: f32 = 1.123_456_789; +LL + let bad32: f32 = 1.123_456_8; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:49:26 @@ -85,8 +92,9 @@ LL | let bad32_suf: f32 = 1.123_456_789_f32; | help: consider changing the type or truncating it to | -LL | let bad32_suf: f32 = 1.123_456_8_f32; - | ~~~~~~~~~~~~~~~ +LL - let bad32_suf: f32 = 1.123_456_789_f32; +LL + let bad32_suf: f32 = 1.123_456_8_f32; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:51:21 @@ -96,8 +104,9 @@ LL | let bad32_inf = 1.123_456_789_f32; | help: consider changing the type or truncating it to | -LL | let bad32_inf = 1.123_456_8_f32; - | ~~~~~~~~~~~~~~~ +LL - let bad32_inf = 1.123_456_789_f32; +LL + let bad32_inf = 1.123_456_8_f32; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:62:36 @@ -107,8 +116,9 @@ LL | let bad_vec32: Vec = vec![0.123_456_789]; | help: consider changing the type or truncating it to | -LL | let bad_vec32: Vec = vec![0.123_456_79]; - | ~~~~~~~~~~~~ +LL - let bad_vec32: Vec = vec![0.123_456_789]; +LL + let bad_vec32: Vec = vec![0.123_456_79]; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:64:36 @@ -118,8 +128,9 @@ LL | let bad_vec64: Vec = vec![0.123_456_789_123_456_789]; | help: consider changing the type or truncating it to | -LL | let bad_vec64: Vec = vec![0.123_456_789_123_456_78]; - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let bad_vec64: Vec = vec![0.123_456_789_123_456_789]; +LL + let bad_vec64: Vec = vec![0.123_456_789_123_456_78]; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:69:24 @@ -129,8 +140,9 @@ LL | let bad_e32: f32 = 1.123_456_788_888e-10; | help: consider changing the type or truncating it to | -LL | let bad_e32: f32 = 1.123_456_8e-10; - | ~~~~~~~~~~~~~~~ +LL - let bad_e32: f32 = 1.123_456_788_888e-10; +LL + let bad_e32: f32 = 1.123_456_8e-10; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:73:27 @@ -140,8 +152,9 @@ LL | let bad_bige32: f32 = 1.123_456_788_888E-10; | help: consider changing the type or truncating it to | -LL | let bad_bige32: f32 = 1.123_456_8E-10; - | ~~~~~~~~~~~~~~~ +LL - let bad_bige32: f32 = 1.123_456_788_888E-10; +LL + let bad_bige32: f32 = 1.123_456_8E-10; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:83:13 @@ -151,8 +164,9 @@ LL | let _ = 2.225_073_858_507_201_1e-308_f64; | help: consider changing the type or truncating it to | -LL | let _ = 2.225_073_858_507_201e-308_f64; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = 2.225_073_858_507_201_1e-308_f64; +LL + let _ = 2.225_073_858_507_201e-308_f64; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:87:13 @@ -162,8 +176,9 @@ LL | let _ = 1.000_000_000_000_001e-324_f64; | help: consider changing the type or truncating it to | -LL | let _ = 0_f64; - | ~~~~~ +LL - let _ = 1.000_000_000_000_001e-324_f64; +LL + let _ = 0_f64; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:98:20 @@ -173,8 +188,9 @@ LL | const _: f64 = 3.0000000000000000e+00; | help: consider changing the type or truncating it to | -LL | const _: f64 = 3.0; - | ~~~ +LL - const _: f64 = 3.0000000000000000e+00; +LL + const _: f64 = 3.0; + | error: aborting due to 16 previous errors diff --git a/tests/ui/fn_to_numeric_cast_any.stderr b/tests/ui/fn_to_numeric_cast_any.stderr index 0a98952faef1..9e6a10933d0c 100644 --- a/tests/ui/fn_to_numeric_cast_any.stderr +++ b/tests/ui/fn_to_numeric_cast_any.stderr @@ -8,8 +8,9 @@ LL | let _ = foo as i8; = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_any)]` help: did you mean to invoke the function? | -LL | let _ = foo() as i8; - | ~~~~~~~~~~~ +LL - let _ = foo as i8; +LL + let _ = foo() as i8; + | error: casting function pointer `foo` to `i16` --> tests/ui/fn_to_numeric_cast_any.rs:26:13 @@ -19,8 +20,9 @@ LL | let _ = foo as i16; | help: did you mean to invoke the function? | -LL | let _ = foo() as i16; - | ~~~~~~~~~~~~ +LL - let _ = foo as i16; +LL + let _ = foo() as i16; + | error: casting function pointer `foo` to `i32` --> tests/ui/fn_to_numeric_cast_any.rs:29:13 @@ -30,8 +32,9 @@ LL | let _ = foo as i32; | help: did you mean to invoke the function? | -LL | let _ = foo() as i32; - | ~~~~~~~~~~~~ +LL - let _ = foo as i32; +LL + let _ = foo() as i32; + | error: casting function pointer `foo` to `i64` --> tests/ui/fn_to_numeric_cast_any.rs:32:13 @@ -41,8 +44,9 @@ LL | let _ = foo as i64; | help: did you mean to invoke the function? | -LL | let _ = foo() as i64; - | ~~~~~~~~~~~~ +LL - let _ = foo as i64; +LL + let _ = foo() as i64; + | error: casting function pointer `foo` to `i128` --> tests/ui/fn_to_numeric_cast_any.rs:35:13 @@ -52,8 +56,9 @@ LL | let _ = foo as i128; | help: did you mean to invoke the function? | -LL | let _ = foo() as i128; - | ~~~~~~~~~~~~~ +LL - let _ = foo as i128; +LL + let _ = foo() as i128; + | error: casting function pointer `foo` to `isize` --> tests/ui/fn_to_numeric_cast_any.rs:38:13 @@ -63,8 +68,9 @@ LL | let _ = foo as isize; | help: did you mean to invoke the function? | -LL | let _ = foo() as isize; - | ~~~~~~~~~~~~~~ +LL - let _ = foo as isize; +LL + let _ = foo() as isize; + | error: casting function pointer `foo` to `u8` --> tests/ui/fn_to_numeric_cast_any.rs:41:13 @@ -74,8 +80,9 @@ LL | let _ = foo as u8; | help: did you mean to invoke the function? | -LL | let _ = foo() as u8; - | ~~~~~~~~~~~ +LL - let _ = foo as u8; +LL + let _ = foo() as u8; + | error: casting function pointer `foo` to `u16` --> tests/ui/fn_to_numeric_cast_any.rs:44:13 @@ -85,8 +92,9 @@ LL | let _ = foo as u16; | help: did you mean to invoke the function? | -LL | let _ = foo() as u16; - | ~~~~~~~~~~~~ +LL - let _ = foo as u16; +LL + let _ = foo() as u16; + | error: casting function pointer `foo` to `u32` --> tests/ui/fn_to_numeric_cast_any.rs:47:13 @@ -96,8 +104,9 @@ LL | let _ = foo as u32; | help: did you mean to invoke the function? | -LL | let _ = foo() as u32; - | ~~~~~~~~~~~~ +LL - let _ = foo as u32; +LL + let _ = foo() as u32; + | error: casting function pointer `foo` to `u64` --> tests/ui/fn_to_numeric_cast_any.rs:50:13 @@ -107,8 +116,9 @@ LL | let _ = foo as u64; | help: did you mean to invoke the function? | -LL | let _ = foo() as u64; - | ~~~~~~~~~~~~ +LL - let _ = foo as u64; +LL + let _ = foo() as u64; + | error: casting function pointer `foo` to `u128` --> tests/ui/fn_to_numeric_cast_any.rs:53:13 @@ -118,8 +128,9 @@ LL | let _ = foo as u128; | help: did you mean to invoke the function? | -LL | let _ = foo() as u128; - | ~~~~~~~~~~~~~ +LL - let _ = foo as u128; +LL + let _ = foo() as u128; + | error: casting function pointer `foo` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:56:13 @@ -129,8 +140,9 @@ LL | let _ = foo as usize; | help: did you mean to invoke the function? | -LL | let _ = foo() as usize; - | ~~~~~~~~~~~~~~ +LL - let _ = foo as usize; +LL + let _ = foo() as usize; + | error: casting function pointer `Struct::static_method` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:61:13 @@ -140,8 +152,9 @@ LL | let _ = Struct::static_method as usize; | help: did you mean to invoke the function? | -LL | let _ = Struct::static_method() as usize; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = Struct::static_method as usize; +LL + let _ = Struct::static_method() as usize; + | error: casting function pointer `f` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:66:5 @@ -151,7 +164,8 @@ LL | f as usize | help: did you mean to invoke the function? | -LL | f() as usize +LL - f as usize +LL + f() as usize | error: casting function pointer `T::static_method` to `usize` @@ -162,7 +176,8 @@ LL | T::static_method as usize | help: did you mean to invoke the function? | -LL | T::static_method() as usize +LL - T::static_method as usize +LL + T::static_method() as usize | error: casting function pointer `(clos as fn(u32) -> u32)` to `usize` @@ -173,8 +188,9 @@ LL | let _ = (clos as fn(u32) -> u32) as usize; | help: did you mean to invoke the function? | -LL | let _ = (clos as fn(u32) -> u32)() as usize; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = (clos as fn(u32) -> u32) as usize; +LL + let _ = (clos as fn(u32) -> u32)() as usize; + | error: casting function pointer `foo` to `*const ()` --> tests/ui/fn_to_numeric_cast_any.rs:83:13 @@ -184,8 +200,9 @@ LL | let _ = foo as *const (); | help: did you mean to invoke the function? | -LL | let _ = foo() as *const (); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = foo as *const (); +LL + let _ = foo() as *const (); + | error: aborting due to 17 previous errors diff --git a/tests/ui/for_kv_map.stderr b/tests/ui/for_kv_map.stderr index 878c43532194..0bd474a10682 100644 --- a/tests/ui/for_kv_map.stderr +++ b/tests/ui/for_kv_map.stderr @@ -8,8 +8,9 @@ LL | for (_, v) in &m { = help: to override `-D warnings` add `#[allow(clippy::for_kv_map)]` help: use the corresponding method | -LL | for v in m.values() { - | ~ ~~~~~~~~~~ +LL - for (_, v) in &m { +LL + for v in m.values() { + | error: you seem to want to iterate on a map's values --> tests/ui/for_kv_map.rs:16:19 @@ -19,8 +20,9 @@ LL | for (_, v) in &*m { | help: use the corresponding method | -LL | for v in (*m).values() { - | ~ ~~~~~~~~~~~~~ +LL - for (_, v) in &*m { +LL + for v in (*m).values() { + | error: you seem to want to iterate on a map's values --> tests/ui/for_kv_map.rs:26:19 @@ -30,8 +32,9 @@ LL | for (_, v) in &mut m { | help: use the corresponding method | -LL | for v in m.values_mut() { - | ~ ~~~~~~~~~~~~~~ +LL - for (_, v) in &mut m { +LL + for v in m.values_mut() { + | error: you seem to want to iterate on a map's values --> tests/ui/for_kv_map.rs:33:19 @@ -41,8 +44,9 @@ LL | for (_, v) in &mut *m { | help: use the corresponding method | -LL | for v in (*m).values_mut() { - | ~ ~~~~~~~~~~~~~~~~~ +LL - for (_, v) in &mut *m { +LL + for v in (*m).values_mut() { + | error: you seem to want to iterate on a map's keys --> tests/ui/for_kv_map.rs:41:24 @@ -52,8 +56,9 @@ LL | for (k, _value) in rm { | help: use the corresponding method | -LL | for k in rm.keys() { - | ~ ~~~~~~~~~ +LL - for (k, _value) in rm { +LL + for k in rm.keys() { + | error: you seem to want to iterate on a map's keys --> tests/ui/for_kv_map.rs:49:32 @@ -63,8 +68,9 @@ LL | 'label: for (k, _value) in rm { | help: use the corresponding method | -LL | 'label: for k in rm.keys() { - | ~ ~~~~~~~~~ +LL - 'label: for (k, _value) in rm { +LL + 'label: for k in rm.keys() { + | error: aborting due to 6 previous errors diff --git a/tests/ui/four_forward_slashes.stderr b/tests/ui/four_forward_slashes.stderr index 4ac5d13c4fa8..95c860b29fba 100644 --- a/tests/ui/four_forward_slashes.stderr +++ b/tests/ui/four_forward_slashes.stderr @@ -10,6 +10,8 @@ LL | | fn a() {} = help: to override `-D warnings` add `#[allow(clippy::four_forward_slashes)]` help: make this a doc comment by removing one `/` | +LL - //// whoops +LL - LL + /// whoops | @@ -24,6 +26,8 @@ LL | | fn b() {} | help: make this a doc comment by removing one `/` | +LL - //// whoops +LL - LL + /// whoops | @@ -54,6 +58,8 @@ LL | | fn g() {} | help: make this a doc comment by removing one `/` | +LL - //// between attributes +LL - LL + /// between attributes | @@ -67,6 +73,8 @@ LL | | fn h() {} | help: make this a doc comment by removing one `/` | +LL - //// not very start of contents +LL - LL + /// not very start of contents | diff --git a/tests/ui/four_forward_slashes_first_line.stderr b/tests/ui/four_forward_slashes_first_line.stderr index 3cb95797319f..6fcd3e2c1b73 100644 --- a/tests/ui/four_forward_slashes_first_line.stderr +++ b/tests/ui/four_forward_slashes_first_line.stderr @@ -10,6 +10,8 @@ LL | | fn a() {} = help: to override `-D warnings` add `#[allow(clippy::four_forward_slashes)]` help: make this a doc comment by removing one `/` | +LL - //// borked doc comment on the first line. doesn't combust! +LL - LL + /// borked doc comment on the first line. doesn't combust! | diff --git a/tests/ui/get_unwrap.stderr b/tests/ui/get_unwrap.stderr index f663362dbb3e..72a575654af9 100644 --- a/tests/ui/get_unwrap.stderr +++ b/tests/ui/get_unwrap.stderr @@ -11,8 +11,9 @@ LL | #![deny(clippy::get_unwrap)] | ^^^^^^^^^^^^^^^^^^ help: using `[]` is clearer and more concise | -LL | let _ = &boxed_slice[1]; - | ~~~~~~~~~~~~~~~ +LL - let _ = boxed_slice.get(1).unwrap(); +LL + let _ = &boxed_slice[1]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:37:17 @@ -33,8 +34,9 @@ LL | let _ = some_slice.get(0).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_slice[0]; - | ~~~~~~~~~~~~~~ +LL - let _ = some_slice.get(0).unwrap(); +LL + let _ = &some_slice[0]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:40:17 @@ -53,8 +55,9 @@ LL | let _ = some_vec.get(0).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_vec[0]; - | ~~~~~~~~~~~~ +LL - let _ = some_vec.get(0).unwrap(); +LL + let _ = &some_vec[0]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:43:17 @@ -73,8 +76,9 @@ LL | let _ = some_vecdeque.get(0).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_vecdeque[0]; - | ~~~~~~~~~~~~~~~~~ +LL - let _ = some_vecdeque.get(0).unwrap(); +LL + let _ = &some_vecdeque[0]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:46:17 @@ -93,8 +97,9 @@ LL | let _ = some_hashmap.get(&1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_hashmap[&1]; - | ~~~~~~~~~~~~~~~~~ +LL - let _ = some_hashmap.get(&1).unwrap(); +LL + let _ = &some_hashmap[&1]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:49:17 @@ -113,8 +118,9 @@ LL | let _ = some_btreemap.get(&1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_btreemap[&1]; - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = some_btreemap.get(&1).unwrap(); +LL + let _ = &some_btreemap[&1]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:52:17 @@ -133,8 +139,9 @@ LL | let _: u8 = *boxed_slice.get(1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _: u8 = boxed_slice[1]; - | ~~~~~~~~~~~~~~ +LL - let _: u8 = *boxed_slice.get(1).unwrap(); +LL + let _: u8 = boxed_slice[1]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:58:22 @@ -153,8 +160,9 @@ LL | *boxed_slice.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | boxed_slice[0] = 1; - | ~~~~~~~~~~~~~~ +LL - *boxed_slice.get_mut(0).unwrap() = 1; +LL + boxed_slice[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:65:10 @@ -173,8 +181,9 @@ LL | *some_slice.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | some_slice[0] = 1; - | ~~~~~~~~~~~~~ +LL - *some_slice.get_mut(0).unwrap() = 1; +LL + some_slice[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:68:10 @@ -193,8 +202,9 @@ LL | *some_vec.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | some_vec[0] = 1; - | ~~~~~~~~~~~ +LL - *some_vec.get_mut(0).unwrap() = 1; +LL + some_vec[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:71:10 @@ -213,8 +223,9 @@ LL | *some_vecdeque.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | some_vecdeque[0] = 1; - | ~~~~~~~~~~~~~~~~ +LL - *some_vecdeque.get_mut(0).unwrap() = 1; +LL + some_vecdeque[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:74:10 @@ -233,8 +244,9 @@ LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | help: using `[]` is clearer and more concise | -LL | let _ = some_vec[0..1].to_vec(); - | ~~~~~~~~~~~~~~ +LL - let _ = some_vec.get(0..1).unwrap().to_vec(); +LL + let _ = some_vec[0..1].to_vec(); + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:88:17 @@ -253,8 +265,9 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | help: using `[]` is clearer and more concise | -LL | let _ = some_vec[0..1].to_vec(); - | ~~~~~~~~~~~~~~ +LL - let _ = some_vec.get_mut(0..1).unwrap().to_vec(); +LL + let _ = some_vec[0..1].to_vec(); + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:91:17 @@ -273,8 +286,9 @@ LL | let _x: &i32 = f.get(1 + 2).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _x: &i32 = &f[1 + 2]; - | ~~~~~~~~~ +LL - let _x: &i32 = f.get(1 + 2).unwrap(); +LL + let _x: &i32 = &f[1 + 2]; + | error: called `.get().unwrap()` on a slice --> tests/ui/get_unwrap.rs:108:18 @@ -284,8 +298,9 @@ LL | let _x = f.get(1 + 2).unwrap().to_string(); | help: using `[]` is clearer and more concise | -LL | let _x = f[1 + 2].to_string(); - | ~~~~~~~~ +LL - let _x = f.get(1 + 2).unwrap().to_string(); +LL + let _x = f[1 + 2].to_string(); + | error: called `.get().unwrap()` on a slice --> tests/ui/get_unwrap.rs:112:18 @@ -295,8 +310,9 @@ LL | let _x = f.get(1 + 2).unwrap().abs(); | help: using `[]` is clearer and more concise | -LL | let _x = f[1 + 2].abs(); - | ~~~~~~~~ +LL - let _x = f.get(1 + 2).unwrap().abs(); +LL + let _x = f[1 + 2].abs(); + | error: called `.get_mut().unwrap()` on a slice --> tests/ui/get_unwrap.rs:130:33 @@ -306,8 +322,9 @@ LL | let b = rest.get_mut(linidx(j, k) - linidx(i, k) - | help: using `[]` is clearer and more concise | -LL | let b = &mut rest[linidx(j, k) - linidx(i, k) - 1]; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap(); +LL + let b = &mut rest[linidx(j, k) - linidx(i, k) - 1]; + | error: aborting due to 30 previous errors diff --git a/tests/ui/implicit_hasher.stderr b/tests/ui/implicit_hasher.stderr index a4b2b5066daf..f907f5a7a807 100644 --- a/tests/ui/implicit_hasher.stderr +++ b/tests/ui/implicit_hasher.stderr @@ -82,8 +82,9 @@ LL | pub fn map(map: &mut HashMap) {} | help: add a type parameter for `BuildHasher` | -LL | pub fn map(map: &mut HashMap) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ +LL - pub fn map(map: &mut HashMap) {} +LL + pub fn map(map: &mut HashMap) {} + | error: parameter of type `HashSet` should be generalized over different hashers --> tests/ui/implicit_hasher.rs:76:22 @@ -93,8 +94,9 @@ LL | pub fn set(set: &mut HashSet) {} | help: add a type parameter for `BuildHasher` | -LL | pub fn set(set: &mut HashSet) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~ +LL - pub fn set(set: &mut HashSet) {} +LL + pub fn set(set: &mut HashSet) {} + | error: impl for `HashMap` should be generalized over different hashers --> tests/ui/implicit_hasher.rs:83:43 @@ -119,8 +121,9 @@ LL | pub async fn election_vote(_data: HashMap) {} | help: add a type parameter for `BuildHasher` | -LL | pub async fn election_vote(_data: HashMap) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ +LL - pub async fn election_vote(_data: HashMap) {} +LL + pub async fn election_vote(_data: HashMap) {} + | error: aborting due to 9 previous errors diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index 940324c25491..7f964546d58d 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -20,7 +20,7 @@ LL | if true { true } else { false } help: add `return` as shown | LL | if true { return true } else { false } - | ~~~~~~~~~~~ + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:20:29 @@ -31,7 +31,7 @@ LL | if true { true } else { false } help: add `return` as shown | LL | if true { true } else { return false } - | ~~~~~~~~~~~~ + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:28:17 @@ -42,7 +42,7 @@ LL | true => false, help: add `return` as shown | LL | true => return false, - | ~~~~~~~~~~~~ + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:30:20 @@ -53,7 +53,7 @@ LL | false => { true }, help: add `return` as shown | LL | false => { return true }, - | ~~~~~~~~~~~ + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:44:9 @@ -63,8 +63,9 @@ LL | break true; | help: change `break` to `return` as shown | -LL | return true; - | ~~~~~~~~~~~ +LL - break true; +LL + return true; + | error: missing `return` statement --> tests/ui/implicit_return.rs:52:13 @@ -74,8 +75,9 @@ LL | break true; | help: change `break` to `return` as shown | -LL | return true; - | ~~~~~~~~~~~ +LL - break true; +LL + return true; + | error: missing `return` statement --> tests/ui/implicit_return.rs:61:13 @@ -85,8 +87,9 @@ LL | break true; | help: change `break` to `return` as shown | -LL | return true; - | ~~~~~~~~~~~ +LL - break true; +LL + return true; + | error: missing `return` statement --> tests/ui/implicit_return.rs:80:18 @@ -97,7 +100,7 @@ LL | let _ = || { true }; help: add `return` as shown | LL | let _ = || { return true }; - | ~~~~~~~~~~~ + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:82:16 @@ -108,7 +111,7 @@ LL | let _ = || true; help: add `return` as shown | LL | let _ = || return true; - | ~~~~~~~~~~~ + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:91:5 @@ -140,8 +143,9 @@ LL | break true; | help: change `break` to `return` as shown | -LL | return true; - | ~~~~~~~~~~~ +LL - break true; +LL + return true; + | error: missing `return` statement --> tests/ui/implicit_return.rs:114:17 @@ -151,8 +155,9 @@ LL | break 'outer false; | help: change `break` to `return` as shown | -LL | return false; - | ~~~~~~~~~~~~ +LL - break 'outer false; +LL + return false; + | error: missing `return` statement --> tests/ui/implicit_return.rs:130:5 diff --git a/tests/ui/iter_nth.stderr b/tests/ui/iter_nth.stderr index ae6e66f8cbf4..76ddfd9684e2 100644 --- a/tests/ui/iter_nth.stderr +++ b/tests/ui/iter_nth.stderr @@ -8,8 +8,9 @@ LL | let bad_vec = some_vec.iter().nth(3); = help: to override `-D warnings` add `#[allow(clippy::iter_nth)]` help: `get` is equivalent but more concise | -LL | let bad_vec = some_vec.get(3); - | ~~~ +LL - let bad_vec = some_vec.iter().nth(3); +LL + let bad_vec = some_vec.get(3); + | error: called `.iter().nth()` on a slice --> tests/ui/iter_nth.rs:36:26 @@ -19,8 +20,9 @@ LL | let bad_slice = &some_vec[..].iter().nth(3); | help: `get` is equivalent but more concise | -LL | let bad_slice = &some_vec[..].get(3); - | ~~~ +LL - let bad_slice = &some_vec[..].iter().nth(3); +LL + let bad_slice = &some_vec[..].get(3); + | error: called `.iter().nth()` on a slice --> tests/ui/iter_nth.rs:38:31 @@ -30,8 +32,9 @@ LL | let bad_boxed_slice = boxed_slice.iter().nth(3); | help: `get` is equivalent but more concise | -LL | let bad_boxed_slice = boxed_slice.get(3); - | ~~~ +LL - let bad_boxed_slice = boxed_slice.iter().nth(3); +LL + let bad_boxed_slice = boxed_slice.get(3); + | error: called `.iter().nth()` on a `VecDeque` --> tests/ui/iter_nth.rs:40:29 @@ -41,8 +44,9 @@ LL | let bad_vec_deque = some_vec_deque.iter().nth(3); | help: `get` is equivalent but more concise | -LL | let bad_vec_deque = some_vec_deque.get(3); - | ~~~ +LL - let bad_vec_deque = some_vec_deque.iter().nth(3); +LL + let bad_vec_deque = some_vec_deque.get(3); + | error: called `.iter_mut().nth()` on a `Vec` --> tests/ui/iter_nth.rs:46:23 @@ -52,8 +56,9 @@ LL | let bad_vec = some_vec.iter_mut().nth(3); | help: `get_mut` is equivalent but more concise | -LL | let bad_vec = some_vec.get_mut(3); - | ~~~~~~~ +LL - let bad_vec = some_vec.iter_mut().nth(3); +LL + let bad_vec = some_vec.get_mut(3); + | error: called `.iter_mut().nth()` on a slice --> tests/ui/iter_nth.rs:50:26 @@ -63,8 +68,9 @@ LL | let bad_slice = &some_vec[..].iter_mut().nth(3); | help: `get_mut` is equivalent but more concise | -LL | let bad_slice = &some_vec[..].get_mut(3); - | ~~~~~~~ +LL - let bad_slice = &some_vec[..].iter_mut().nth(3); +LL + let bad_slice = &some_vec[..].get_mut(3); + | error: called `.iter_mut().nth()` on a `VecDeque` --> tests/ui/iter_nth.rs:54:29 @@ -74,8 +80,9 @@ LL | let bad_vec_deque = some_vec_deque.iter_mut().nth(3); | help: `get_mut` is equivalent but more concise | -LL | let bad_vec_deque = some_vec_deque.get_mut(3); - | ~~~~~~~ +LL - let bad_vec_deque = some_vec_deque.iter_mut().nth(3); +LL + let bad_vec_deque = some_vec_deque.get_mut(3); + | error: called `.iter().nth()` on a `Vec` --> tests/ui/iter_nth.rs:59:5 @@ -85,8 +92,9 @@ LL | vec_ref.iter().nth(3); | help: `get` is equivalent but more concise | -LL | vec_ref.get(3); - | ~~~ +LL - vec_ref.iter().nth(3); +LL + vec_ref.get(3); + | error: aborting due to 8 previous errors diff --git a/tests/ui/join_absolute_paths.stderr b/tests/ui/join_absolute_paths.stderr index e7fd5508823a..300946bf3b5f 100644 --- a/tests/ui/join_absolute_paths.stderr +++ b/tests/ui/join_absolute_paths.stderr @@ -9,12 +9,14 @@ LL | path.join("/sh"); = help: to override `-D warnings` add `#[allow(clippy::join_absolute_paths)]` help: if this is unintentional, try removing the starting separator | -LL | path.join("sh"); - | ~~~~ +LL - path.join("/sh"); +LL + path.join("sh"); + | help: if this is intentional, consider using `Path::new` | -LL | PathBuf::from("/sh"); - | ~~~~~~~~~~~~~~~~~~~~ +LL - path.join("/sh"); +LL + PathBuf::from("/sh"); + | error: argument to `Path::join` starts with a path separator --> tests/ui/join_absolute_paths.rs:14:15 @@ -25,12 +27,14 @@ LL | path.join("\\user"); = note: joining a path starting with separator will replace the path instead help: if this is unintentional, try removing the starting separator | -LL | path.join("\user"); - | ~~~~~~~ +LL - path.join("\\user"); +LL + path.join("\user"); + | help: if this is intentional, consider using `Path::new` | -LL | PathBuf::from("\\user"); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - path.join("\\user"); +LL + PathBuf::from("\\user"); + | error: argument to `Path::join` starts with a path separator --> tests/ui/join_absolute_paths.rs:18:15 @@ -41,12 +45,14 @@ LL | path.join("/sh"); = note: joining a path starting with separator will replace the path instead help: if this is unintentional, try removing the starting separator | -LL | path.join("sh"); - | ~~~~ +LL - path.join("/sh"); +LL + path.join("sh"); + | help: if this is intentional, consider using `Path::new` | -LL | PathBuf::from("/sh"); - | ~~~~~~~~~~~~~~~~~~~~ +LL - path.join("/sh"); +LL + PathBuf::from("/sh"); + | error: argument to `Path::join` starts with a path separator --> tests/ui/join_absolute_paths.rs:22:15 @@ -57,12 +63,14 @@ LL | path.join(r#"/sh"#); = note: joining a path starting with separator will replace the path instead help: if this is unintentional, try removing the starting separator | -LL | path.join(r#"sh"#); - | ~~~~~~~ +LL - path.join(r#"/sh"#); +LL + path.join(r#"sh"#); + | help: if this is intentional, consider using `Path::new` | -LL | PathBuf::from(r#"/sh"#); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - path.join(r#"/sh"#); +LL + PathBuf::from(r#"/sh"#); + | error: aborting due to 4 previous errors diff --git a/tests/ui/large_enum_variant.32bit.stderr b/tests/ui/large_enum_variant.32bit.stderr index 7f66207ce797..80ca5daa1d57 100644 --- a/tests/ui/large_enum_variant.32bit.stderr +++ b/tests/ui/large_enum_variant.32bit.stderr @@ -14,8 +14,9 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]` help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box<[i32; 8000]>), - | ~~~~~~~~~~~~~~~~ +LL - B([i32; 8000]), +LL + B(Box<[i32; 8000]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:38:1 @@ -31,8 +32,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | ContainingLargeEnum(Box), - | ~~~~~~~~~~~~~~ +LL - ContainingLargeEnum(LargeEnum), +LL + ContainingLargeEnum(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:44:1 @@ -49,8 +51,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), - | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), +LL + ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:51:1 @@ -66,8 +69,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, - | ~~~~~~~~~~~~~~~~ +LL - StructLikeLarge { x: [i32; 8000], y: i32 }, +LL + StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:57:1 @@ -83,8 +87,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, - | ~~~~~~~~~~~~~~~~ +LL - StructLikeLarge2 { x: [i32; 8000] }, +LL + StructLikeLarge2 { x: Box<[i32; 8000]> }, + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:74:1 @@ -101,8 +106,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box<[u8; 1255]>), - | ~~~~~~~~~~~~~~~ +LL - B([u8; 1255]), +LL + B(Box<[u8; 1255]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:81:1 @@ -118,8 +124,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]>, [i32; 30]), - | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]), +LL + ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]>, [i32; 30]), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:87:1 @@ -135,8 +142,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box), - | ~~~~~~~~~~~~ +LL - B(Struct2), +LL + B(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:93:1 @@ -152,8 +160,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box), - | ~~~~~~~~~~~~ +LL - B(Struct2), +LL + B(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:99:1 @@ -169,8 +178,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box), - | ~~~~~~~~~~~~ +LL - B(Struct2), +LL + B(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:115:1 @@ -255,8 +265,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Large(Box<(T, [u8; 512])>), - | ~~~~~~~~~~~~~~~~~~~ +LL - Large((T, [u8; 512])), +LL + Large(Box<(T, [u8; 512])>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:159:1 @@ -272,8 +283,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Large(Box<[Foo; 64]>), - | ~~~~~~~~~~~~~~~~~~~ +LL - Large([Foo; 64]), +LL + Large(Box<[Foo; 64]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:170:1 @@ -289,8 +301,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Error(Box>), - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - Error(PossiblyLargeEnumWithConst<256>), +LL + Error(Box>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:176:1 @@ -306,8 +319,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Large(Box<[u64; 64]>), - | ~~~~~~~~~~~~~~ +LL - Large([u64; 64]), +LL + Large(Box<[u64; 64]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:187:1 @@ -323,8 +337,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Error(Box>), - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - Error(WithRecursionAndGenerics), +LL + Error(Box>), + | error: aborting due to 18 previous errors diff --git a/tests/ui/large_enum_variant.64bit.stderr b/tests/ui/large_enum_variant.64bit.stderr index dbc4c125e610..559bdf2a2f50 100644 --- a/tests/ui/large_enum_variant.64bit.stderr +++ b/tests/ui/large_enum_variant.64bit.stderr @@ -14,8 +14,9 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]` help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box<[i32; 8000]>), - | ~~~~~~~~~~~~~~~~ +LL - B([i32; 8000]), +LL + B(Box<[i32; 8000]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:38:1 @@ -31,8 +32,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | ContainingLargeEnum(Box), - | ~~~~~~~~~~~~~~ +LL - ContainingLargeEnum(LargeEnum), +LL + ContainingLargeEnum(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:44:1 @@ -49,8 +51,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), - | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), +LL + ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:51:1 @@ -66,8 +69,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, - | ~~~~~~~~~~~~~~~~ +LL - StructLikeLarge { x: [i32; 8000], y: i32 }, +LL + StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:57:1 @@ -83,8 +87,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, - | ~~~~~~~~~~~~~~~~ +LL - StructLikeLarge2 { x: [i32; 8000] }, +LL + StructLikeLarge2 { x: Box<[i32; 8000]> }, + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:74:1 @@ -101,8 +106,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box<[u8; 1255]>), - | ~~~~~~~~~~~~~~~ +LL - B([u8; 1255]), +LL + B(Box<[u8; 1255]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:81:1 @@ -118,8 +124,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]>, [i32; 30]), - | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]), +LL + ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]>, [i32; 30]), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:87:1 @@ -135,8 +142,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box), - | ~~~~~~~~~~~~ +LL - B(Struct2), +LL + B(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:93:1 @@ -152,8 +160,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box), - | ~~~~~~~~~~~~ +LL - B(Struct2), +LL + B(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:99:1 @@ -169,8 +178,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box), - | ~~~~~~~~~~~~ +LL - B(Struct2), +LL + B(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:115:1 @@ -255,8 +265,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Large(Box<(T, [u8; 512])>), - | ~~~~~~~~~~~~~~~~~~~ +LL - Large((T, [u8; 512])), +LL + Large(Box<(T, [u8; 512])>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:159:1 @@ -272,8 +283,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Large(Box<[Foo; 64]>), - | ~~~~~~~~~~~~~~~~~~~ +LL - Large([Foo; 64]), +LL + Large(Box<[Foo; 64]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:170:1 @@ -289,8 +301,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Error(Box>), - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - Error(PossiblyLargeEnumWithConst<256>), +LL + Error(Box>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:176:1 @@ -306,8 +319,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Large(Box<[u64; 64]>), - | ~~~~~~~~~~~~~~ +LL - Large([u64; 64]), +LL + Large(Box<[u64; 64]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:187:1 @@ -323,8 +337,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Error(Box>), - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - Error(WithRecursionAndGenerics), +LL + Error(Box>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:223:5 @@ -340,8 +355,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | BigBoi(Box), - | ~~~~~~~~~~~~~~~~~~~~~ +LL - BigBoi(PublishWithBytes), +LL + BigBoi(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:229:5 @@ -357,8 +373,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | BigBoi(Box), - | ~~~~~~~~~~~~~~~~~~~ +LL - BigBoi(PublishWithVec), +LL + BigBoi(Box), + | error: aborting due to 20 previous errors diff --git a/tests/ui/legacy_numeric_constants.stderr b/tests/ui/legacy_numeric_constants.stderr index af9b003ed540..4d69b8165a34 100644 --- a/tests/ui/legacy_numeric_constants.stderr +++ b/tests/ui/legacy_numeric_constants.stderr @@ -8,8 +8,9 @@ LL | std::f32::EPSILON; = help: to override `-D warnings` add `#[allow(clippy::legacy_numeric_constants)]` help: use the associated constant instead | -LL | f32::EPSILON; - | ~~~~~~~~~~~~ +LL - std::f32::EPSILON; +LL + f32::EPSILON; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:35:5 @@ -19,8 +20,9 @@ LL | std::u8::MIN; | help: use the associated constant instead | -LL | u8::MIN; - | ~~~~~~~ +LL - std::u8::MIN; +LL + u8::MIN; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:38:5 @@ -30,8 +32,9 @@ LL | std::usize::MIN; | help: use the associated constant instead | -LL | usize::MIN; - | ~~~~~~~~~~ +LL - std::usize::MIN; +LL + usize::MIN; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:41:5 @@ -41,8 +44,9 @@ LL | std::u32::MAX; | help: use the associated constant instead | -LL | u32::MAX; - | ~~~~~~~~ +LL - std::u32::MAX; +LL + u32::MAX; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:44:5 @@ -52,8 +56,9 @@ LL | core::u32::MAX; | help: use the associated constant instead | -LL | u32::MAX; - | ~~~~~~~~ +LL - core::u32::MAX; +LL + u32::MAX; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:47:5 @@ -64,7 +69,7 @@ LL | MAX; help: use the associated constant instead | LL | u32::MAX; - | ~~~~~~~~ + | +++++ error: usage of a legacy numeric method --> tests/ui/legacy_numeric_constants.rs:50:10 @@ -74,8 +79,9 @@ LL | i32::max_value(); | help: use the associated constant instead | -LL | i32::MAX; - | ~~~ +LL - i32::max_value(); +LL + i32::MAX; + | error: usage of a legacy numeric method --> tests/ui/legacy_numeric_constants.rs:53:9 @@ -85,8 +91,9 @@ LL | u8::max_value(); | help: use the associated constant instead | -LL | u8::MAX; - | ~~~ +LL - u8::max_value(); +LL + u8::MAX; + | error: usage of a legacy numeric method --> tests/ui/legacy_numeric_constants.rs:56:9 @@ -96,8 +103,9 @@ LL | u8::min_value(); | help: use the associated constant instead | -LL | u8::MIN; - | ~~~ +LL - u8::min_value(); +LL + u8::MIN; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:59:5 @@ -107,8 +115,9 @@ LL | ::std::u8::MIN; | help: use the associated constant instead | -LL | u8::MIN; - | ~~~~~~~ +LL - ::std::u8::MIN; +LL + u8::MIN; + | error: usage of a legacy numeric method --> tests/ui/legacy_numeric_constants.rs:62:27 @@ -118,8 +127,9 @@ LL | ::std::primitive::u8::min_value(); | help: use the associated constant instead | -LL | ::std::primitive::u8::MIN; - | ~~~ +LL - ::std::primitive::u8::min_value(); +LL + ::std::primitive::u8::MIN; + | error: usage of a legacy numeric method --> tests/ui/legacy_numeric_constants.rs:65:26 @@ -129,8 +139,9 @@ LL | std::primitive::i32::max_value(); | help: use the associated constant instead | -LL | std::primitive::i32::MAX; - | ~~~ +LL - std::primitive::i32::max_value(); +LL + std::primitive::i32::MAX; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:68:5 @@ -140,8 +151,9 @@ LL | self::a::u128::MAX; | help: use the associated constant instead | -LL | u128::MAX; - | ~~~~~~~~~ +LL - self::a::u128::MAX; +LL + u128::MAX; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:18:25 @@ -155,8 +167,9 @@ LL | b!(); = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info) help: use the associated constant instead | -LL | let x = u64::MAX; - | ~~~~~~~~ +LL - let x = std::u64::MAX; +LL + let x = u64::MAX; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:82:14 @@ -166,8 +179,9 @@ LL | [(0, "", std::i128::MAX)]; | help: use the associated constant instead | -LL | [(0, "", i128::MAX)]; - | ~~~~~~~~~ +LL - [(0, "", std::i128::MAX)]; +LL + [(0, "", i128::MAX)]; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:116:5 @@ -177,8 +191,9 @@ LL | std::u32::MAX; | help: use the associated constant instead | -LL | u32::MAX; - | ~~~~~~~~ +LL - std::u32::MAX; +LL + u32::MAX; + | error: aborting due to 16 previous errors diff --git a/tests/ui/literals.stderr b/tests/ui/literals.stderr index dcee7169c0a8..f7a81f47ff1c 100644 --- a/tests/ui/literals.stderr +++ b/tests/ui/literals.stderr @@ -71,12 +71,14 @@ LL | let fail_multi_zero = 000_123usize; = help: to override `-D warnings` add `#[allow(clippy::zero_prefixed_literal)]` help: if you mean to use a decimal constant, remove the `0` to avoid confusion | -LL | let fail_multi_zero = 123usize; - | ~~~~~~~~ +LL - let fail_multi_zero = 000_123usize; +LL + let fail_multi_zero = 123usize; + | help: if you mean to use an octal constant, use `0o` | -LL | let fail_multi_zero = 0o123usize; - | ~~~~~~~~~~ +LL - let fail_multi_zero = 000_123usize; +LL + let fail_multi_zero = 0o123usize; + | error: integer type suffix should not be separated by an underscore --> tests/ui/literals.rs:38:16 @@ -92,12 +94,14 @@ LL | let fail8 = 0123; | help: if you mean to use a decimal constant, remove the `0` to avoid confusion | -LL | let fail8 = 123; - | ~~~ +LL - let fail8 = 0123; +LL + let fail8 = 123; + | help: if you mean to use an octal constant, use `0o` | -LL | let fail8 = 0o123; - | ~~~~~ +LL - let fail8 = 0123; +LL + let fail8 = 0o123; + | error: integer type suffix should not be separated by an underscore --> tests/ui/literals.rs:51:16 @@ -143,8 +147,9 @@ LL | let _ = 08; | help: if you mean to use a decimal constant, remove the `0` to avoid confusion | -LL | let _ = 8; - | ~ +LL - let _ = 08; +LL + let _ = 8; + | error: this is a decimal constant --> tests/ui/literals.rs:78:13 @@ -154,8 +159,9 @@ LL | let _ = 09; | help: if you mean to use a decimal constant, remove the `0` to avoid confusion | -LL | let _ = 9; - | ~ +LL - let _ = 09; +LL + let _ = 9; + | error: this is a decimal constant --> tests/ui/literals.rs:81:13 @@ -165,8 +171,9 @@ LL | let _ = 089; | help: if you mean to use a decimal constant, remove the `0` to avoid confusion | -LL | let _ = 89; - | ~~ +LL - let _ = 089; +LL + let _ = 89; + | error: aborting due to 20 previous errors diff --git a/tests/ui/lossy_float_literal.stderr b/tests/ui/lossy_float_literal.stderr index a83f9a7aa241..33b650b19c8a 100644 --- a/tests/ui/lossy_float_literal.stderr +++ b/tests/ui/lossy_float_literal.stderr @@ -8,8 +8,9 @@ LL | let _: f32 = 16_777_217.0; = help: to override `-D warnings` add `#[allow(clippy::lossy_float_literal)]` help: consider changing the type or replacing it with | -LL | let _: f32 = 16_777_216.0; - | ~~~~~~~~~~~~ +LL - let _: f32 = 16_777_217.0; +LL + let _: f32 = 16_777_216.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:16:18 @@ -19,8 +20,9 @@ LL | let _: f32 = 16_777_219.0; | help: consider changing the type or replacing it with | -LL | let _: f32 = 16_777_220.0; - | ~~~~~~~~~~~~ +LL - let _: f32 = 16_777_219.0; +LL + let _: f32 = 16_777_220.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:18:18 @@ -30,8 +32,9 @@ LL | let _: f32 = 16_777_219.; | help: consider changing the type or replacing it with | -LL | let _: f32 = 16_777_220.0; - | ~~~~~~~~~~~~ +LL - let _: f32 = 16_777_219.; +LL + let _: f32 = 16_777_220.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:20:18 @@ -41,8 +44,9 @@ LL | let _: f32 = 16_777_219.000; | help: consider changing the type or replacing it with | -LL | let _: f32 = 16_777_220.0; - | ~~~~~~~~~~~~ +LL - let _: f32 = 16_777_219.000; +LL + let _: f32 = 16_777_220.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:22:13 @@ -52,8 +56,9 @@ LL | let _ = 16_777_219f32; | help: consider changing the type or replacing it with | -LL | let _ = 16_777_220_f32; - | ~~~~~~~~~~~~~~ +LL - let _ = 16_777_219f32; +LL + let _ = 16_777_220_f32; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:24:19 @@ -63,8 +68,9 @@ LL | let _: f32 = -16_777_219.0; | help: consider changing the type or replacing it with | -LL | let _: f32 = -16_777_220.0; - | ~~~~~~~~~~~~ +LL - let _: f32 = -16_777_219.0; +LL + let _: f32 = -16_777_220.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:27:18 @@ -74,8 +80,9 @@ LL | let _: f64 = 9_007_199_254_740_993.0; | help: consider changing the type or replacing it with | -LL | let _: f64 = 9_007_199_254_740_992.0; - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: f64 = 9_007_199_254_740_993.0; +LL + let _: f64 = 9_007_199_254_740_992.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:29:18 @@ -85,8 +92,9 @@ LL | let _: f64 = 9_007_199_254_740_993.; | help: consider changing the type or replacing it with | -LL | let _: f64 = 9_007_199_254_740_992.0; - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: f64 = 9_007_199_254_740_993.; +LL + let _: f64 = 9_007_199_254_740_992.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:31:18 @@ -96,8 +104,9 @@ LL | let _: f64 = 9_007_199_254_740_993.00; | help: consider changing the type or replacing it with | -LL | let _: f64 = 9_007_199_254_740_992.0; - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: f64 = 9_007_199_254_740_993.00; +LL + let _: f64 = 9_007_199_254_740_992.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:33:13 @@ -107,8 +116,9 @@ LL | let _ = 9_007_199_254_740_993f64; | help: consider changing the type or replacing it with | -LL | let _ = 9_007_199_254_740_992_f64; - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = 9_007_199_254_740_993f64; +LL + let _ = 9_007_199_254_740_992_f64; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:35:19 @@ -118,8 +128,9 @@ LL | let _: f64 = -9_007_199_254_740_993.0; | help: consider changing the type or replacing it with | -LL | let _: f64 = -9_007_199_254_740_992.0; - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: f64 = -9_007_199_254_740_993.0; +LL + let _: f64 = -9_007_199_254_740_992.0; + | error: aborting due to 11 previous errors diff --git a/tests/ui/manual_assert.edition2018.stderr b/tests/ui/manual_assert.edition2018.stderr index f9fa8cf04d96..8cedf2c68636 100644 --- a/tests/ui/manual_assert.edition2018.stderr +++ b/tests/ui/manual_assert.edition2018.stderr @@ -11,7 +11,11 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::manual_assert)]` help: try instead | -LL | assert!(a.is_empty(), "qaqaq{:?}", a); +LL - if !a.is_empty() { +LL - +LL - panic!("qaqaq{:?}", a); +LL - } +LL + assert!(a.is_empty(), "qaqaq{:?}", a); | error: only a `panic!` in `if`-then statement @@ -25,7 +29,11 @@ LL | | } | help: try instead | -LL | assert!(a.is_empty(), "qwqwq"); +LL - if !a.is_empty() { +LL - +LL - panic!("qwqwq"); +LL - } +LL + assert!(a.is_empty(), "qwqwq"); | error: only a `panic!` in `if`-then statement @@ -39,7 +47,11 @@ LL | | } | help: try instead | -LL | assert!(!b.is_empty(), "panic1"); +LL - if b.is_empty() { +LL - +LL - panic!("panic1"); +LL - } +LL + assert!(!b.is_empty(), "panic1"); | error: only a `panic!` in `if`-then statement @@ -53,7 +65,11 @@ LL | | } | help: try instead | -LL | assert!(!(b.is_empty() && a.is_empty()), "panic2"); +LL - if b.is_empty() && a.is_empty() { +LL - +LL - panic!("panic2"); +LL - } +LL + assert!(!(b.is_empty() && a.is_empty()), "panic2"); | error: only a `panic!` in `if`-then statement @@ -67,7 +83,11 @@ LL | | } | help: try instead | -LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3"); +LL - if a.is_empty() && !b.is_empty() { +LL - +LL - panic!("panic3"); +LL - } +LL + assert!(!(a.is_empty() && !b.is_empty()), "panic3"); | error: only a `panic!` in `if`-then statement @@ -81,7 +101,11 @@ LL | | } | help: try instead | -LL | assert!(!(b.is_empty() || a.is_empty()), "panic4"); +LL - if b.is_empty() || a.is_empty() { +LL - +LL - panic!("panic4"); +LL - } +LL + assert!(!(b.is_empty() || a.is_empty()), "panic4"); | error: only a `panic!` in `if`-then statement @@ -95,7 +119,11 @@ LL | | } | help: try instead | -LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5"); +LL - if a.is_empty() || !b.is_empty() { +LL - +LL - panic!("panic5"); +LL - } +LL + assert!(!(a.is_empty() || !b.is_empty()), "panic5"); | error: only a `panic!` in `if`-then statement @@ -109,7 +137,11 @@ LL | | } | help: try instead | -LL | assert!(!a.is_empty(), "with expansion {}", one!()); +LL - if a.is_empty() { +LL - +LL - panic!("with expansion {}", one!()) +LL - } +LL + assert!(!a.is_empty(), "with expansion {}", one!()); | error: only a `panic!` in `if`-then statement @@ -126,7 +158,16 @@ LL | | } | help: try instead | -LL | assert!(!(a > 2), "panic with comment"); +LL - if a > 2 { +LL - +LL - // comment +LL - /* this is a +LL - multiline +LL - comment */ +LL - /// Doc comment +LL - panic!("panic with comment") // comment after `panic!` +LL - } +LL + assert!(!(a > 2), "panic with comment"); | error: only a `panic!` in `if`-then statement @@ -141,8 +182,12 @@ LL | | }; | help: try instead | -LL | const BAR: () = assert!(!(N == 0), ); - | ~~~~~~~~~~~~~~~~~~~~ +LL - const BAR: () = if N == 0 { +LL - +LL - panic!() +LL - }; +LL + const BAR: () = assert!(!(N == 0), ); + | error: aborting due to 10 previous errors diff --git a/tests/ui/manual_assert.edition2021.stderr b/tests/ui/manual_assert.edition2021.stderr index f9fa8cf04d96..8cedf2c68636 100644 --- a/tests/ui/manual_assert.edition2021.stderr +++ b/tests/ui/manual_assert.edition2021.stderr @@ -11,7 +11,11 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::manual_assert)]` help: try instead | -LL | assert!(a.is_empty(), "qaqaq{:?}", a); +LL - if !a.is_empty() { +LL - +LL - panic!("qaqaq{:?}", a); +LL - } +LL + assert!(a.is_empty(), "qaqaq{:?}", a); | error: only a `panic!` in `if`-then statement @@ -25,7 +29,11 @@ LL | | } | help: try instead | -LL | assert!(a.is_empty(), "qwqwq"); +LL - if !a.is_empty() { +LL - +LL - panic!("qwqwq"); +LL - } +LL + assert!(a.is_empty(), "qwqwq"); | error: only a `panic!` in `if`-then statement @@ -39,7 +47,11 @@ LL | | } | help: try instead | -LL | assert!(!b.is_empty(), "panic1"); +LL - if b.is_empty() { +LL - +LL - panic!("panic1"); +LL - } +LL + assert!(!b.is_empty(), "panic1"); | error: only a `panic!` in `if`-then statement @@ -53,7 +65,11 @@ LL | | } | help: try instead | -LL | assert!(!(b.is_empty() && a.is_empty()), "panic2"); +LL - if b.is_empty() && a.is_empty() { +LL - +LL - panic!("panic2"); +LL - } +LL + assert!(!(b.is_empty() && a.is_empty()), "panic2"); | error: only a `panic!` in `if`-then statement @@ -67,7 +83,11 @@ LL | | } | help: try instead | -LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3"); +LL - if a.is_empty() && !b.is_empty() { +LL - +LL - panic!("panic3"); +LL - } +LL + assert!(!(a.is_empty() && !b.is_empty()), "panic3"); | error: only a `panic!` in `if`-then statement @@ -81,7 +101,11 @@ LL | | } | help: try instead | -LL | assert!(!(b.is_empty() || a.is_empty()), "panic4"); +LL - if b.is_empty() || a.is_empty() { +LL - +LL - panic!("panic4"); +LL - } +LL + assert!(!(b.is_empty() || a.is_empty()), "panic4"); | error: only a `panic!` in `if`-then statement @@ -95,7 +119,11 @@ LL | | } | help: try instead | -LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5"); +LL - if a.is_empty() || !b.is_empty() { +LL - +LL - panic!("panic5"); +LL - } +LL + assert!(!(a.is_empty() || !b.is_empty()), "panic5"); | error: only a `panic!` in `if`-then statement @@ -109,7 +137,11 @@ LL | | } | help: try instead | -LL | assert!(!a.is_empty(), "with expansion {}", one!()); +LL - if a.is_empty() { +LL - +LL - panic!("with expansion {}", one!()) +LL - } +LL + assert!(!a.is_empty(), "with expansion {}", one!()); | error: only a `panic!` in `if`-then statement @@ -126,7 +158,16 @@ LL | | } | help: try instead | -LL | assert!(!(a > 2), "panic with comment"); +LL - if a > 2 { +LL - +LL - // comment +LL - /* this is a +LL - multiline +LL - comment */ +LL - /// Doc comment +LL - panic!("panic with comment") // comment after `panic!` +LL - } +LL + assert!(!(a > 2), "panic with comment"); | error: only a `panic!` in `if`-then statement @@ -141,8 +182,12 @@ LL | | }; | help: try instead | -LL | const BAR: () = assert!(!(N == 0), ); - | ~~~~~~~~~~~~~~~~~~~~ +LL - const BAR: () = if N == 0 { +LL - +LL - panic!() +LL - }; +LL + const BAR: () = assert!(!(N == 0), ); + | error: aborting due to 10 previous errors diff --git a/tests/ui/manual_async_fn.stderr b/tests/ui/manual_async_fn.stderr index 5d063e550f28..54a9b1d40a11 100644 --- a/tests/ui/manual_async_fn.stderr +++ b/tests/ui/manual_async_fn.stderr @@ -8,8 +8,9 @@ LL | fn fut() -> impl Future { = help: to override `-D warnings` add `#[allow(clippy::manual_async_fn)]` help: make the function `async` and return the output of the future directly | -LL | async fn fut() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - fn fut() -> impl Future { +LL + async fn fut() -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:12:1 @@ -19,8 +20,9 @@ LL | fn fut2() ->impl Future { | help: make the function `async` and return the output of the future directly | -LL | async fn fut2() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - fn fut2() ->impl Future { +LL + async fn fut2() -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:18:1 @@ -30,8 +32,9 @@ LL | fn fut3()-> impl Future { | help: make the function `async` and return the output of the future directly | -LL | async fn fut3() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - fn fut3()-> impl Future { +LL + async fn fut3() -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:23:1 @@ -41,8 +44,9 @@ LL | fn empty_fut() -> impl Future { | help: make the function `async` and return the output of the future directly | -LL | async fn empty_fut() {} - | ~~~~~~~~~~~~~~~~~~~~ ~~ +LL - fn empty_fut() -> impl Future { +LL + async fn empty_fut() {} + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:29:1 @@ -52,8 +56,9 @@ LL | fn empty_fut2() ->impl Future { | help: make the function `async` and return the output of the future directly | -LL | async fn empty_fut2() {} - | ~~~~~~~~~~~~~~~~~~~~~ ~~ +LL - fn empty_fut2() ->impl Future { +LL + async fn empty_fut2() {} + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:35:1 @@ -63,8 +68,9 @@ LL | fn empty_fut3()-> impl Future { | help: make the function `async` and return the output of the future directly | -LL | async fn empty_fut3() {} - | ~~~~~~~~~~~~~~~~~~~~~ ~~ +LL - fn empty_fut3()-> impl Future { +LL + async fn empty_fut3() {} + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:40:1 @@ -74,8 +80,9 @@ LL | fn core_fut() -> impl core::future::Future { | help: make the function `async` and return the output of the future directly | -LL | async fn core_fut() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - fn core_fut() -> impl core::future::Future { +LL + async fn core_fut() -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:63:5 @@ -108,8 +115,9 @@ LL | fn elided(_: &i32) -> impl Future + '_ { | help: make the function `async` and return the output of the future directly | -LL | async fn elided(_: &i32) -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - fn elided(_: &i32) -> impl Future + '_ { +LL + async fn elided(_: &i32) -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:110:1 @@ -119,8 +127,9 @@ LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + | help: make the function `async` and return the output of the future directly | -LL | async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { +LL + async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:140:1 @@ -130,8 +139,9 @@ LL | pub fn issue_10450() -> impl Future { | help: make the function `async` and return the output of the future directly | -LL | pub async fn issue_10450() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - pub fn issue_10450() -> impl Future { +LL + pub async fn issue_10450() -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:145:1 @@ -141,8 +151,9 @@ LL | pub(crate) fn issue_10450_2() -> impl Future { | help: make the function `async` and return the output of the future directly | -LL | pub(crate) async fn issue_10450_2() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - pub(crate) fn issue_10450_2() -> impl Future { +LL + pub(crate) async fn issue_10450_2() -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:150:1 @@ -152,8 +163,9 @@ LL | pub(self) fn issue_10450_3() -> impl Future { | help: make the function `async` and return the output of the future directly | -LL | pub(self) async fn issue_10450_3() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - pub(self) fn issue_10450_3() -> impl Future { +LL + pub(self) async fn issue_10450_3() -> i32 { 42 } + | error: aborting due to 13 previous errors diff --git a/tests/ui/manual_float_methods.stderr b/tests/ui/manual_float_methods.stderr index d2ed50642178..352c879c87d7 100644 --- a/tests/ui/manual_float_methods.stderr +++ b/tests/ui/manual_float_methods.stderr @@ -17,16 +17,19 @@ LL | if x != f32::INFINITY && x != f32::NEG_INFINITY {} = help: to override `-D warnings` add `#[allow(clippy::manual_is_finite)]` help: use the dedicated method instead | -LL | if x.is_finite() {} - | ~~~~~~~~~~~~~ +LL - if x != f32::INFINITY && x != f32::NEG_INFINITY {} +LL + if x.is_finite() {} + | help: this will alter how it handles NaN; if that is a problem, use instead | -LL | if x.is_finite() || x.is_nan() {} - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if x != f32::INFINITY && x != f32::NEG_INFINITY {} +LL + if x.is_finite() || x.is_nan() {} + | help: or, for conciseness | -LL | if !x.is_infinite() {} - | ~~~~~~~~~~~~~~~~ +LL - if x != f32::INFINITY && x != f32::NEG_INFINITY {} +LL + if !x.is_infinite() {} + | error: manually checking if a float is infinite --> tests/ui/manual_float_methods.rs:28:8 @@ -42,16 +45,19 @@ LL | if x != INFINITE && x != NEG_INFINITE {} | help: use the dedicated method instead | -LL | if x.is_finite() {} - | ~~~~~~~~~~~~~ +LL - if x != INFINITE && x != NEG_INFINITE {} +LL + if x.is_finite() {} + | help: this will alter how it handles NaN; if that is a problem, use instead | -LL | if x.is_finite() || x.is_nan() {} - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if x != INFINITE && x != NEG_INFINITE {} +LL + if x.is_finite() || x.is_nan() {} + | help: or, for conciseness | -LL | if !x.is_infinite() {} - | ~~~~~~~~~~~~~~~~ +LL - if x != INFINITE && x != NEG_INFINITE {} +LL + if !x.is_infinite() {} + | error: manually checking if a float is infinite --> tests/ui/manual_float_methods.rs:33:8 @@ -67,16 +73,19 @@ LL | if x != f64::INFINITY && x != f64::NEG_INFINITY {} | help: use the dedicated method instead | -LL | if x.is_finite() {} - | ~~~~~~~~~~~~~ +LL - if x != f64::INFINITY && x != f64::NEG_INFINITY {} +LL + if x.is_finite() {} + | help: this will alter how it handles NaN; if that is a problem, use instead | -LL | if x.is_finite() || x.is_nan() {} - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if x != f64::INFINITY && x != f64::NEG_INFINITY {} +LL + if x.is_finite() || x.is_nan() {} + | help: or, for conciseness | -LL | if !x.is_infinite() {} - | ~~~~~~~~~~~~~~~~ +LL - if x != f64::INFINITY && x != f64::NEG_INFINITY {} +LL + if !x.is_infinite() {} + | error: manually checking if a float is infinite --> tests/ui/manual_float_methods.rs:50:12 diff --git a/tests/ui/manual_ignore_case_cmp.stderr b/tests/ui/manual_ignore_case_cmp.stderr index 14cd8cfc1731..47378a65799f 100644 --- a/tests/ui/manual_ignore_case_cmp.stderr +++ b/tests/ui/manual_ignore_case_cmp.stderr @@ -11,8 +11,9 @@ LL | #![deny(clippy::manual_ignore_case_cmp)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.eq_ignore_ascii_case()` instead | -LL | if a.eq_ignore_ascii_case(b) { - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if a.to_ascii_lowercase() == b.to_ascii_lowercase() { +LL + if a.eq_ignore_ascii_case(b) { + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:13:8 @@ -22,8 +23,9 @@ LL | if a.to_ascii_uppercase() == b.to_ascii_uppercase() { | help: consider using `.eq_ignore_ascii_case()` instead | -LL | if a.eq_ignore_ascii_case(b) { - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if a.to_ascii_uppercase() == b.to_ascii_uppercase() { +LL + if a.eq_ignore_ascii_case(b) { + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:17:13 @@ -33,8 +35,9 @@ LL | let r = a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | let r = a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let r = a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + let r = a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:19:18 @@ -44,8 +47,9 @@ LL | let r = r || a.to_ascii_uppercase() == b.to_ascii_uppercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | let r = r || a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let r = r || a.to_ascii_uppercase() == b.to_ascii_uppercase(); +LL + let r = r || a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:21:10 @@ -55,8 +59,9 @@ LL | r && a.to_ascii_lowercase() == b.to_uppercase().to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | r && a.eq_ignore_ascii_case(&b.to_uppercase()); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - r && a.to_ascii_lowercase() == b.to_uppercase().to_ascii_lowercase(); +LL + r && a.eq_ignore_ascii_case(&b.to_uppercase()); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:24:8 @@ -66,8 +71,9 @@ LL | if a.to_ascii_lowercase() != b.to_ascii_lowercase() { | help: consider using `.eq_ignore_ascii_case()` instead | -LL | if !a.eq_ignore_ascii_case(b) { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if a.to_ascii_lowercase() != b.to_ascii_lowercase() { +LL + if !a.eq_ignore_ascii_case(b) { + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:28:8 @@ -77,8 +83,9 @@ LL | if a.to_ascii_uppercase() != b.to_ascii_uppercase() { | help: consider using `.eq_ignore_ascii_case()` instead | -LL | if !a.eq_ignore_ascii_case(b) { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if a.to_ascii_uppercase() != b.to_ascii_uppercase() { +LL + if !a.eq_ignore_ascii_case(b) { + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:32:13 @@ -88,8 +95,9 @@ LL | let r = a.to_ascii_lowercase() != b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | let r = !a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let r = a.to_ascii_lowercase() != b.to_ascii_lowercase(); +LL + let r = !a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:34:18 @@ -99,8 +107,9 @@ LL | let r = r || a.to_ascii_uppercase() != b.to_ascii_uppercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | let r = r || !a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let r = r || a.to_ascii_uppercase() != b.to_ascii_uppercase(); +LL + let r = r || !a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:36:10 @@ -110,8 +119,9 @@ LL | r && a.to_ascii_lowercase() != b.to_uppercase().to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | r && !a.eq_ignore_ascii_case(&b.to_uppercase()); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - r && a.to_ascii_lowercase() != b.to_uppercase().to_ascii_lowercase(); +LL + r && !a.eq_ignore_ascii_case(&b.to_uppercase()); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:48:5 @@ -121,8 +131,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:52:5 @@ -132,8 +143,9 @@ LL | a.to_ascii_lowercase() == 'a'; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(&'a'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == 'a'; +LL + a.eq_ignore_ascii_case(&'a'); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:54:5 @@ -143,8 +155,9 @@ LL | 'a' == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | 'a'.eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - 'a' == b.to_ascii_lowercase(); +LL + 'a'.eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:58:5 @@ -154,8 +167,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:60:5 @@ -165,8 +179,9 @@ LL | a.to_ascii_lowercase() == b'a'; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(&b'a'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b'a'; +LL + a.eq_ignore_ascii_case(&b'a'); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:62:5 @@ -176,8 +191,9 @@ LL | b'a' == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b'a'.eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b'a' == b.to_ascii_lowercase(); +LL + b'a'.eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:66:5 @@ -187,8 +203,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:68:5 @@ -198,8 +215,9 @@ LL | a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.to_uppercase().eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.to_uppercase().eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:70:5 @@ -209,8 +227,9 @@ LL | a.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == "a"; +LL + a.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:72:5 @@ -220,8 +239,9 @@ LL | "a" == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == b.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:76:5 @@ -231,8 +251,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:78:5 @@ -242,8 +263,9 @@ LL | a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.to_uppercase().eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.to_uppercase().eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:80:5 @@ -253,8 +275,9 @@ LL | a.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == "a"; +LL + a.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:82:5 @@ -264,8 +287,9 @@ LL | "a" == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == b.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:86:5 @@ -275,8 +299,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:88:5 @@ -286,8 +311,9 @@ LL | a.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == "a"; +LL + a.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:90:5 @@ -297,8 +323,9 @@ LL | "a" == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == b.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:94:5 @@ -308,8 +335,9 @@ LL | a.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == "a"; +LL + a.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:96:5 @@ -319,8 +347,9 @@ LL | "a" == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == b.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:100:5 @@ -330,8 +359,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:102:5 @@ -341,8 +371,9 @@ LL | a.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == "a"; +LL + a.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:104:5 @@ -352,8 +383,9 @@ LL | "a" == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == b.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:107:5 @@ -363,8 +395,9 @@ LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b.eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b.to_ascii_lowercase() == a.to_ascii_lowercase(); +LL + b.eq_ignore_ascii_case(&a); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:109:5 @@ -374,8 +407,9 @@ LL | b.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b.to_ascii_lowercase() == "a"; +LL + b.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:111:5 @@ -385,8 +419,9 @@ LL | "a" == a.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == a.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(&a); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:115:5 @@ -396,8 +431,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:117:5 @@ -407,8 +443,9 @@ LL | a.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == "a"; +LL + a.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:119:5 @@ -418,8 +455,9 @@ LL | "a" == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == b.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:122:5 @@ -429,8 +467,9 @@ LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b.eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b.to_ascii_lowercase() == a.to_ascii_lowercase(); +LL + b.eq_ignore_ascii_case(&a); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:124:5 @@ -440,8 +479,9 @@ LL | b.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b.to_ascii_lowercase() == "a"; +LL + b.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:126:5 @@ -451,8 +491,9 @@ LL | "a" == a.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == a.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(&a); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:130:5 @@ -462,8 +503,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:134:5 @@ -473,8 +515,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:138:5 @@ -484,8 +527,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:140:5 @@ -495,8 +539,9 @@ LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b.eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b.to_ascii_lowercase() == a.to_ascii_lowercase(); +LL + b.eq_ignore_ascii_case(&a); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:144:5 @@ -506,8 +551,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:148:5 @@ -517,8 +563,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:152:5 @@ -528,8 +575,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:154:5 @@ -539,8 +587,9 @@ LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b.eq_ignore_ascii_case(a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b.to_ascii_lowercase() == a.to_ascii_lowercase(); +LL + b.eq_ignore_ascii_case(a); + | error: aborting due to 49 previous errors diff --git a/tests/ui/manual_is_ascii_check.stderr b/tests/ui/manual_is_ascii_check.stderr index cbb7aa2205b6..9fd7f457b420 100644 --- a/tests/ui/manual_is_ascii_check.stderr +++ b/tests/ui/manual_is_ascii_check.stderr @@ -153,8 +153,9 @@ LL | take_while(|c| ('A'..='Z').contains(&c)); | help: try | -LL | take_while(|c: char| c.is_ascii_uppercase()); - | ~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ +LL - take_while(|c| ('A'..='Z').contains(&c)); +LL + take_while(|c: char| c.is_ascii_uppercase()); + | error: manual check for common ascii range --> tests/ui/manual_is_ascii_check.rs:107:20 @@ -164,8 +165,9 @@ LL | take_while(|c| (b'A'..=b'Z').contains(&c)); | help: try | -LL | take_while(|c: u8| c.is_ascii_uppercase()); - | ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ +LL - take_while(|c| (b'A'..=b'Z').contains(&c)); +LL + take_while(|c: u8| c.is_ascii_uppercase()); + | error: manual check for common ascii range --> tests/ui/manual_is_ascii_check.rs:109:26 @@ -181,8 +183,9 @@ LL | let digits: Vec<&char> = ['1', 'A'].iter().take_while(|c| ('0'..='9').c | help: try | -LL | let digits: Vec<&char> = ['1', 'A'].iter().take_while(|c: &&char| c.is_ascii_digit()).collect(); - | ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ +LL - let digits: Vec<&char> = ['1', 'A'].iter().take_while(|c| ('0'..='9').contains(c)).collect(); +LL + let digits: Vec<&char> = ['1', 'A'].iter().take_while(|c: &&char| c.is_ascii_digit()).collect(); + | error: manual check for common ascii range --> tests/ui/manual_is_ascii_check.rs:116:71 @@ -192,8 +195,9 @@ LL | let digits: Vec<&mut char> = ['1', 'A'].iter_mut().take_while(|c| ('0'. | help: try | -LL | let digits: Vec<&mut char> = ['1', 'A'].iter_mut().take_while(|c: &&mut char| c.is_ascii_digit()).collect(); - | ~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ +LL - let digits: Vec<&mut char> = ['1', 'A'].iter_mut().take_while(|c| ('0'..='9').contains(c)).collect(); +LL + let digits: Vec<&mut char> = ['1', 'A'].iter_mut().take_while(|c: &&mut char| c.is_ascii_digit()).collect(); + | error: aborting due to 29 previous errors diff --git a/tests/ui/map_all_any_identity.stderr b/tests/ui/map_all_any_identity.stderr index 869d81a73d65..24df97d883ac 100644 --- a/tests/ui/map_all_any_identity.stderr +++ b/tests/ui/map_all_any_identity.stderr @@ -8,8 +8,9 @@ LL | let _ = ["foo"].into_iter().map(|s| s == "foo").any(|a| a); = help: to override `-D warnings` add `#[allow(clippy::map_all_any_identity)]` help: use `.any(...)` instead | -LL | let _ = ["foo"].into_iter().any(|s| s == "foo"); - | ~~~~~~~~~~~~~~~~~~~ +LL - let _ = ["foo"].into_iter().map(|s| s == "foo").any(|a| a); +LL + let _ = ["foo"].into_iter().any(|s| s == "foo"); + | error: usage of `.map(...).all(identity)` --> tests/ui/map_all_any_identity.rs:7:33 @@ -19,8 +20,9 @@ LL | let _ = ["foo"].into_iter().map(|s| s == "foo").all(std::convert::ident | help: use `.all(...)` instead | -LL | let _ = ["foo"].into_iter().all(|s| s == "foo"); - | ~~~~~~~~~~~~~~~~~~~ +LL - let _ = ["foo"].into_iter().map(|s| s == "foo").all(std::convert::identity); +LL + let _ = ["foo"].into_iter().all(|s| s == "foo"); + | error: aborting due to 2 previous errors diff --git a/tests/ui/map_with_unused_argument_over_ranges.stderr b/tests/ui/map_with_unused_argument_over_ranges.stderr index ed905b6591c7..e5c93ceac02a 100644 --- a/tests/ui/map_with_unused_argument_over_ranges.stderr +++ b/tests/ui/map_with_unused_argument_over_ranges.stderr @@ -68,8 +68,9 @@ LL | (0..10).map(|_| 3); | help: remove the explicit range and use `repeat_n` | -LL | std::iter::repeat_n(3, 10); - | ~~~~~~~~~~~~~~~~~~~ ~~~~~ +LL - (0..10).map(|_| 3); +LL + std::iter::repeat_n(3, 10); + | error: map of a closure that does not depend on its parameter over a range --> tests/ui/map_with_unused_argument_over_ranges.rs:37:5 @@ -218,8 +219,9 @@ LL | (0..10).map(|_| 3); | help: remove the explicit range and use `repeat` and `take` | -LL | std::iter::repeat(3).take(10); - | ~~~~~~~~~~~~~~~~~ ~ +++++++++ +LL - (0..10).map(|_| 3); +LL + std::iter::repeat(3).take(10); + | error: aborting due to 18 previous errors diff --git a/tests/ui/map_with_unused_argument_over_ranges_nostd.stderr b/tests/ui/map_with_unused_argument_over_ranges_nostd.stderr index d47f3d09175b..975ded83560f 100644 --- a/tests/ui/map_with_unused_argument_over_ranges_nostd.stderr +++ b/tests/ui/map_with_unused_argument_over_ranges_nostd.stderr @@ -8,8 +8,9 @@ LL | let _: Vec<_> = (0..10).map(|_| 3 + 1).collect(); = help: to override `-D warnings` add `#[allow(clippy::map_with_unused_argument_over_ranges)]` help: remove the explicit range and use `repeat_n` | -LL | let _: Vec<_> = core::iter::repeat_n(3 + 1, 10).collect(); - | ~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~ +LL - let _: Vec<_> = (0..10).map(|_| 3 + 1).collect(); +LL + let _: Vec<_> = core::iter::repeat_n(3 + 1, 10).collect(); + | error: aborting due to 1 previous error diff --git a/tests/ui/match_result_ok.stderr b/tests/ui/match_result_ok.stderr index ccdf53230757..822cc4de77f3 100644 --- a/tests/ui/match_result_ok.stderr +++ b/tests/ui/match_result_ok.stderr @@ -8,8 +8,9 @@ LL | if let Some(y) = x.parse().ok() { y } else { 0 } = help: to override `-D warnings` add `#[allow(clippy::match_result_ok)]` help: consider matching on `Ok(y)` and removing the call to `ok` instead | -LL | if let Ok(y) = x.parse() { y } else { 0 } - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if let Some(y) = x.parse().ok() { y } else { 0 } +LL + if let Ok(y) = x.parse() { y } else { 0 } + | error: matching on `Some` with `ok()` is redundant --> tests/ui/match_result_ok.rs:24:9 @@ -19,8 +20,9 @@ LL | if let Some(y) = x . parse() . ok () { | help: consider matching on `Ok(y)` and removing the call to `ok` instead | -LL | if let Ok(y) = x . parse() { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if let Some(y) = x . parse() . ok () { +LL + if let Ok(y) = x . parse() { + | error: matching on `Some` with `ok()` is redundant --> tests/ui/match_result_ok.rs:51:5 @@ -30,8 +32,9 @@ LL | while let Some(a) = wat.next().ok() { | help: consider matching on `Ok(a)` and removing the call to `ok` instead | -LL | while let Ok(a) = wat.next() { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - while let Some(a) = wat.next().ok() { +LL + while let Ok(a) = wat.next() { + | error: aborting due to 3 previous errors diff --git a/tests/ui/match_str_case_mismatch.stderr b/tests/ui/match_str_case_mismatch.stderr index ea461eb510ff..8068edfff947 100644 --- a/tests/ui/match_str_case_mismatch.stderr +++ b/tests/ui/match_str_case_mismatch.stderr @@ -8,8 +8,9 @@ LL | "Bar" => {}, = help: to override `-D warnings` add `#[allow(clippy::match_str_case_mismatch)]` help: consider changing the case of this arm to respect `to_ascii_lowercase` | -LL | "bar" => {}, - | ~~~~~ +LL - "Bar" => {}, +LL + "bar" => {}, + | error: this `match` arm has a differing case than its expression --> tests/ui/match_str_case_mismatch.rs:123:9 @@ -19,8 +20,9 @@ LL | "~!@#$%^&*()-_=+Foo" => {}, | help: consider changing the case of this arm to respect `to_ascii_lowercase` (notice the capitalization difference) | -LL | "~!@#$%^&*()-_=+foo" => {}, - | ~~~~~~~~~~~~~~~~~~~~ +LL - "~!@#$%^&*()-_=+Foo" => {}, +LL + "~!@#$%^&*()-_=+foo" => {}, + | error: this `match` arm has a differing case than its expression --> tests/ui/match_str_case_mismatch.rs:136:9 @@ -30,8 +32,9 @@ LL | "Воды" => {}, | help: consider changing the case of this arm to respect `to_lowercase` | -LL | "воды" => {}, - | ~~~~~~ +LL - "Воды" => {}, +LL + "воды" => {}, + | error: this `match` arm has a differing case than its expression --> tests/ui/match_str_case_mismatch.rs:148:9 @@ -41,8 +44,9 @@ LL | "barDz" => {}, | help: consider changing the case of this arm to respect `to_lowercase` | -LL | "bardz" => {}, - | ~~~~~~ +LL - "barDz" => {}, +LL + "bardz" => {}, + | error: this `match` arm has a differing case than its expression --> tests/ui/match_str_case_mismatch.rs:159:9 @@ -52,8 +56,9 @@ LL | "bARʁ" => {}, | help: consider changing the case of this arm to respect `to_uppercase` | -LL | "BARʁ" => {}, - | ~~~~~~ +LL - "bARʁ" => {}, +LL + "BARʁ" => {}, + | error: this `match` arm has a differing case than its expression --> tests/ui/match_str_case_mismatch.rs:170:9 @@ -63,8 +68,9 @@ LL | "Bar" => {}, | help: consider changing the case of this arm to respect `to_ascii_lowercase` | -LL | "bar" => {}, - | ~~~~~ +LL - "Bar" => {}, +LL + "bar" => {}, + | error: this `match` arm has a differing case than its expression --> tests/ui/match_str_case_mismatch.rs:186:9 @@ -74,8 +80,9 @@ LL | "bAR" => {}, | help: consider changing the case of this arm to respect `to_ascii_uppercase` | -LL | "BAR" => {}, - | ~~~~~ +LL - "bAR" => {}, +LL + "BAR" => {}, + | error: aborting due to 7 previous errors diff --git a/tests/ui/needless_borrow_pat.stderr b/tests/ui/needless_borrow_pat.stderr index 018e74a4f11d..25c570eb7ff7 100644 --- a/tests/ui/needless_borrow_pat.stderr +++ b/tests/ui/needless_borrow_pat.stderr @@ -15,8 +15,9 @@ LL | Some(ref x) => *x, | help: try | -LL | Some(x) => x, - | ~ ~ +LL - Some(ref x) => *x, +LL + Some(x) => x, + | error: this pattern creates a reference to a reference --> tests/ui/needless_borrow_pat.rs:73:14 @@ -73,8 +74,9 @@ LL | E::A(ref x) | E::B(ref x) => *x, | help: try | -LL | E::A(x) | E::B(x) => x, - | ~ ~ ~ +LL - E::A(ref x) | E::B(ref x) => *x, +LL + E::A(x) | E::B(x) => x, + | error: this pattern creates a reference to a reference --> tests/ui/needless_borrow_pat.rs:128:21 diff --git a/tests/ui/needless_for_each_unfixable.stderr b/tests/ui/needless_for_each_unfixable.stderr index 7e42bd133f06..3a3a240c5a3a 100644 --- a/tests/ui/needless_for_each_unfixable.stderr +++ b/tests/ui/needless_for_each_unfixable.stderr @@ -25,8 +25,9 @@ LL + } | help: ...and replace `return` with `continue` | -LL | continue; - | ~~~~~~~~ +LL - return; +LL + continue; + | error: aborting due to 1 previous error diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index 47e008688215..4ac4fdce972d 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -63,12 +63,14 @@ LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | help: consider changing the type to | -LL | fn issue_2114(s: String, t: &str, u: Vec, v: Vec) { - | ~~~~ +LL - fn issue_2114(s: String, t: String, u: Vec, v: Vec) { +LL + fn issue_2114(s: String, t: &str, u: Vec, v: Vec) { + | help: change `t.clone()` to | -LL | let _ = t.to_string(); - | ~~~~~~~~~~~~~ +LL - let _ = t.clone(); +LL + let _ = t.to_string(); + | error: this argument is passed by value, but not consumed in the function body --> tests/ui/needless_pass_by_value.rs:95:40 @@ -84,12 +86,14 @@ LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | help: consider changing the type to | -LL | fn issue_2114(s: String, t: String, u: Vec, v: &[i32]) { - | ~~~~~~ +LL - fn issue_2114(s: String, t: String, u: Vec, v: Vec) { +LL + fn issue_2114(s: String, t: String, u: Vec, v: &[i32]) { + | help: change `v.clone()` to | -LL | let _ = v.to_owned(); - | ~~~~~~~~~~~~ +LL - let _ = v.clone(); +LL + let _ = v.to_owned(); + | error: this argument is passed by value, but not consumed in the function body --> tests/ui/needless_pass_by_value.rs:113:12 diff --git a/tests/ui/needless_range_loop.stderr b/tests/ui/needless_range_loop.stderr index 86c2b550b071..23c085f9d3b2 100644 --- a/tests/ui/needless_range_loop.stderr +++ b/tests/ui/needless_range_loop.stderr @@ -8,8 +8,9 @@ LL | for i in 0..vec.len() { = help: to override `-D warnings` add `#[allow(clippy::needless_range_loop)]` help: consider using an iterator | -LL | for in &vec { - | ~~~~~~ ~~~~ +LL - for i in 0..vec.len() { +LL + for in &vec { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop.rs:27:14 @@ -19,8 +20,9 @@ LL | for i in 0..vec.len() { | help: consider using an iterator | -LL | for in &vec { - | ~~~~~~ ~~~~ +LL - for i in 0..vec.len() { +LL + for in &vec { + | error: the loop variable `j` is only used to index `STATIC` --> tests/ui/needless_range_loop.rs:34:14 @@ -30,8 +32,9 @@ LL | for j in 0..4 { | help: consider using an iterator | -LL | for in &STATIC { - | ~~~~~~ ~~~~~~~ +LL - for j in 0..4 { +LL + for in &STATIC { + | error: the loop variable `j` is only used to index `CONST` --> tests/ui/needless_range_loop.rs:40:14 @@ -41,8 +44,9 @@ LL | for j in 0..4 { | help: consider using an iterator | -LL | for in &CONST { - | ~~~~~~ ~~~~~~ +LL - for j in 0..4 { +LL + for in &CONST { + | error: the loop variable `i` is used to index `vec` --> tests/ui/needless_range_loop.rs:46:14 @@ -52,8 +56,9 @@ LL | for i in 0..vec.len() { | help: consider using an iterator and enumerate() | -LL | for (i, ) in vec.iter().enumerate() { - | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 0..vec.len() { +LL + for (i, ) in vec.iter().enumerate() { + | error: the loop variable `i` is only used to index `vec2` --> tests/ui/needless_range_loop.rs:56:14 @@ -63,8 +68,9 @@ LL | for i in 0..vec.len() { | help: consider using an iterator | -LL | for in vec2.iter().take(vec.len()) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 0..vec.len() { +LL + for in vec2.iter().take(vec.len()) { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop.rs:62:14 @@ -74,8 +80,9 @@ LL | for i in 5..vec.len() { | help: consider using an iterator | -LL | for in vec.iter().skip(5) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~ +LL - for i in 5..vec.len() { +LL + for in vec.iter().skip(5) { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop.rs:68:14 @@ -85,8 +92,9 @@ LL | for i in 0..MAX_LEN { | help: consider using an iterator | -LL | for in vec.iter().take(MAX_LEN) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 0..MAX_LEN { +LL + for in vec.iter().take(MAX_LEN) { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop.rs:74:14 @@ -96,8 +104,9 @@ LL | for i in 0..=MAX_LEN { | help: consider using an iterator | -LL | for in vec.iter().take(MAX_LEN + 1) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 0..=MAX_LEN { +LL + for in vec.iter().take(MAX_LEN + 1) { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop.rs:80:14 @@ -107,8 +116,9 @@ LL | for i in 5..10 { | help: consider using an iterator | -LL | for in vec.iter().take(10).skip(5) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 5..10 { +LL + for in vec.iter().take(10).skip(5) { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop.rs:86:14 @@ -118,8 +128,9 @@ LL | for i in 5..=10 { | help: consider using an iterator | -LL | for in vec.iter().take(10 + 1).skip(5) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 5..=10 { +LL + for in vec.iter().take(10 + 1).skip(5) { + | error: the loop variable `i` is used to index `vec` --> tests/ui/needless_range_loop.rs:92:14 @@ -129,8 +140,9 @@ LL | for i in 5..vec.len() { | help: consider using an iterator and enumerate() | -LL | for (i, ) in vec.iter().enumerate().skip(5) { - | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 5..vec.len() { +LL + for (i, ) in vec.iter().enumerate().skip(5) { + | error: the loop variable `i` is used to index `vec` --> tests/ui/needless_range_loop.rs:98:14 @@ -140,8 +152,9 @@ LL | for i in 5..10 { | help: consider using an iterator and enumerate() | -LL | for (i, ) in vec.iter().enumerate().take(10).skip(5) { - | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 5..10 { +LL + for (i, ) in vec.iter().enumerate().take(10).skip(5) { + | error: the loop variable `i` is used to index `vec` --> tests/ui/needless_range_loop.rs:105:14 @@ -151,8 +164,9 @@ LL | for i in 0..vec.len() { | help: consider using an iterator and enumerate() | -LL | for (i, ) in vec.iter_mut().enumerate() { - | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 0..vec.len() { +LL + for (i, ) in vec.iter_mut().enumerate() { + | error: aborting due to 14 previous errors diff --git a/tests/ui/needless_range_loop2.stderr b/tests/ui/needless_range_loop2.stderr index 0531e8e8f856..cb979b3f3c24 100644 --- a/tests/ui/needless_range_loop2.stderr +++ b/tests/ui/needless_range_loop2.stderr @@ -8,8 +8,9 @@ LL | for i in 3..10 { = help: to override `-D warnings` add `#[allow(clippy::needless_range_loop)]` help: consider using an iterator | -LL | for in ns.iter().take(10).skip(3) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 3..10 { +LL + for in ns.iter().take(10).skip(3) { + | error: the loop variable `i` is only used to index `ms` --> tests/ui/needless_range_loop2.rs:34:14 @@ -19,8 +20,9 @@ LL | for i in 0..ms.len() { | help: consider using an iterator | -LL | for in &mut ms { - | ~~~~~~ ~~~~~~~ +LL - for i in 0..ms.len() { +LL + for in &mut ms { + | error: the loop variable `i` is only used to index `ms` --> tests/ui/needless_range_loop2.rs:42:14 @@ -30,8 +32,9 @@ LL | for i in 0..ms.len() { | help: consider using an iterator | -LL | for in &mut ms { - | ~~~~~~ ~~~~~~~ +LL - for i in 0..ms.len() { +LL + for in &mut ms { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop2.rs:68:14 @@ -41,8 +44,9 @@ LL | for i in x..x + 4 { | help: consider using an iterator | -LL | for in vec.iter_mut().skip(x).take(4) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in x..x + 4 { +LL + for in vec.iter_mut().skip(x).take(4) { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop2.rs:77:14 @@ -52,8 +56,9 @@ LL | for i in x..=x + 4 { | help: consider using an iterator | -LL | for in vec.iter_mut().skip(x).take(4 + 1) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in x..=x + 4 { +LL + for in vec.iter_mut().skip(x).take(4 + 1) { + | error: the loop variable `i` is only used to index `arr` --> tests/ui/needless_range_loop2.rs:85:14 @@ -63,8 +68,9 @@ LL | for i in 0..3 { | help: consider using an iterator | -LL | for in &arr { - | ~~~~~~ ~~~~ +LL - for i in 0..3 { +LL + for in &arr { + | error: the loop variable `i` is only used to index `arr` --> tests/ui/needless_range_loop2.rs:91:14 @@ -74,8 +80,9 @@ LL | for i in 0..2 { | help: consider using an iterator | -LL | for in arr.iter().take(2) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~ +LL - for i in 0..2 { +LL + for in arr.iter().take(2) { + | error: the loop variable `i` is only used to index `arr` --> tests/ui/needless_range_loop2.rs:97:14 @@ -85,8 +92,9 @@ LL | for i in 1..3 { | help: consider using an iterator | -LL | for in arr.iter().skip(1) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~ +LL - for i in 1..3 { +LL + for in arr.iter().skip(1) { + | error: aborting due to 8 previous errors diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr index 3865a7fea6bf..04c97a41d676 100644 --- a/tests/ui/needless_return.stderr +++ b/tests/ui/needless_return.stderr @@ -80,8 +80,9 @@ LL | true => return false, | help: remove `return` | -LL | true => false, - | ~~~~~ +LL - true => return false, +LL + true => false, + | error: unneeded `return` statement --> tests/ui/needless_return.rs:65:13 @@ -115,8 +116,9 @@ LL | let _ = || return true; | help: remove `return` | -LL | let _ = || true; - | ~~~~ +LL - let _ = || return true; +LL + let _ = || true; + | error: unneeded `return` statement --> tests/ui/needless_return.rs:81:5 @@ -183,8 +185,9 @@ LL | _ => return, | help: replace `return` with a unit value | -LL | _ => (), - | ~~ +LL - _ => return, +LL + _ => (), + | error: unneeded `return` statement --> tests/ui/needless_return.rs:112:24 @@ -209,8 +212,9 @@ LL | _ => return, | help: replace `return` with a unit value | -LL | _ => (), - | ~~ +LL - _ => return, +LL + _ => (), + | error: unneeded `return` statement --> tests/ui/needless_return.rs:130:9 @@ -244,8 +248,9 @@ LL | bar.unwrap_or_else(|_| return) | help: replace `return` with an empty block | -LL | bar.unwrap_or_else(|_| {}) - | ~~ +LL - bar.unwrap_or_else(|_| return) +LL + bar.unwrap_or_else(|_| {}) + | error: unneeded `return` statement --> tests/ui/needless_return.rs:161:21 @@ -270,8 +275,9 @@ LL | let _ = || return; | help: replace `return` with an empty block | -LL | let _ = || {}; - | ~~ +LL - let _ = || return; +LL + let _ = || {}; + | error: unneeded `return` statement --> tests/ui/needless_return.rs:172:32 @@ -281,8 +287,9 @@ LL | res.unwrap_or_else(|_| return Foo) | help: remove `return` | -LL | res.unwrap_or_else(|_| Foo) - | ~~~ +LL - res.unwrap_or_else(|_| return Foo) +LL + res.unwrap_or_else(|_| Foo) + | error: unneeded `return` statement --> tests/ui/needless_return.rs:182:5 @@ -340,8 +347,9 @@ LL | true => return false, | help: remove `return` | -LL | true => false, - | ~~~~~ +LL - true => return false, +LL + true => false, + | error: unneeded `return` statement --> tests/ui/needless_return.rs:206:13 @@ -375,8 +383,9 @@ LL | let _ = || return true; | help: remove `return` | -LL | let _ = || true; - | ~~~~ +LL - let _ = || return true; +LL + let _ = || true; + | error: unneeded `return` statement --> tests/ui/needless_return.rs:222:5 @@ -443,8 +452,9 @@ LL | _ => return, | help: replace `return` with a unit value | -LL | _ => (), - | ~~ +LL - _ => return, +LL + _ => (), + | error: unneeded `return` statement --> tests/ui/needless_return.rs:258:9 diff --git a/tests/ui/never_loop.stderr b/tests/ui/never_loop.stderr index 72bf8da51dfe..f6d6d109542b 100644 --- a/tests/ui/never_loop.stderr +++ b/tests/ui/never_loop.stderr @@ -62,8 +62,9 @@ LL | | } | help: if you need the first element of the iterator, try writing | -LL | if let Some(x) = (0..10).next() { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for x in 0..10 { +LL + if let Some(x) = (0..10).next() { + | error: this loop never actually loops --> tests/ui/never_loop.rs:173:5 @@ -129,8 +130,9 @@ LL | | } | help: if you need the first element of the iterator, try writing | -LL | if let Some(_) = (0..20).next() { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for _ in 0..20 { +LL + if let Some(_) = (0..20).next() { + | error: this loop never actually loops --> tests/ui/never_loop.rs:388:13 diff --git a/tests/ui/non_canonical_partial_ord_impl.stderr b/tests/ui/non_canonical_partial_ord_impl.stderr index 12e6bdc7addc..86845df4ea90 100644 --- a/tests/ui/non_canonical_partial_ord_impl.stderr +++ b/tests/ui/non_canonical_partial_ord_impl.stderr @@ -27,8 +27,9 @@ LL | | } | help: change this to | -LL | fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } - | ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - fn partial_cmp(&self, _: &Self) -> Option { +LL + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } + | error: aborting due to 2 previous errors diff --git a/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.stderr b/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.stderr index f956f4b8d52a..333052ae1c11 100644 --- a/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.stderr +++ b/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.stderr @@ -8,8 +8,9 @@ LL | static LAZY_FOO: Lazy = Lazy::new(|| "foo".to_uppercase()); = help: to override `-D warnings` add `#[allow(clippy::non_std_lazy_statics)]` help: use `std::sync::LazyLock` instead | -LL | static LAZY_FOO: std::sync::LazyLock = std::sync::LazyLock::new(|| "foo".to_uppercase()); - | ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - static LAZY_FOO: Lazy = Lazy::new(|| "foo".to_uppercase()); +LL + static LAZY_FOO: std::sync::LazyLock = std::sync::LazyLock::new(|| "foo".to_uppercase()); + | error: this type has been superceded by `LazyLock` in the standard library --> tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.rs:13:18 @@ -19,8 +20,9 @@ LL | static LAZY_BAR: Lazy = Lazy::new(|| { | help: use `std::sync::LazyLock` instead | -LL | static LAZY_BAR: std::sync::LazyLock = std::sync::LazyLock::new(|| { - | ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - static LAZY_BAR: Lazy = Lazy::new(|| { +LL + static LAZY_BAR: std::sync::LazyLock = std::sync::LazyLock::new(|| { + | error: this type has been superceded by `LazyLock` in the standard library --> tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.rs:18:18 @@ -30,8 +32,9 @@ LL | static LAZY_BAZ: Lazy = { Lazy::new(|| "baz".to_uppercase()) }; | help: use `std::sync::LazyLock` instead | -LL | static LAZY_BAZ: std::sync::LazyLock = { std::sync::LazyLock::new(|| "baz".to_uppercase()) }; - | ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - static LAZY_BAZ: Lazy = { Lazy::new(|| "baz".to_uppercase()) }; +LL + static LAZY_BAZ: std::sync::LazyLock = { std::sync::LazyLock::new(|| "baz".to_uppercase()) }; + | error: this type has been superceded by `LazyLock` in the standard library --> tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.rs:20:18 diff --git a/tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.stderr b/tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.stderr index 66dc435f9823..216190ae4ca3 100644 --- a/tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.stderr +++ b/tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.stderr @@ -37,8 +37,9 @@ LL | static LAZY_FOO: Lazy = Lazy::new(|| "foo".to_uppercase()); | help: use `std::sync::LazyLock` instead | -LL | static LAZY_FOO: std::sync::LazyLock = std::sync::LazyLock::new(|| "foo".to_uppercase()); - | ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - static LAZY_FOO: Lazy = Lazy::new(|| "foo".to_uppercase()); +LL + static LAZY_FOO: std::sync::LazyLock = std::sync::LazyLock::new(|| "foo".to_uppercase()); + | error: this type has been superceded by `LazyLock` in the standard library --> tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.rs:13:26 @@ -48,8 +49,9 @@ LL | static mut LAZY_BAR: Lazy = Lazy::new(|| "bar".to_uppercase()); | help: use `std::sync::LazyLock` instead | -LL | static mut LAZY_BAR: std::sync::LazyLock = std::sync::LazyLock::new(|| "bar".to_uppercase()); - | ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - static mut LAZY_BAR: Lazy = Lazy::new(|| "bar".to_uppercase()); +LL + static mut LAZY_BAR: std::sync::LazyLock = std::sync::LazyLock::new(|| "bar".to_uppercase()); + | error: this type has been superceded by `LazyLock` in the standard library --> tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.rs:15:26 @@ -59,8 +61,9 @@ LL | static mut LAZY_BAZ: Lazy = Lazy::new(|| "baz".to_uppercase()); | help: use `std::sync::LazyLock` instead | -LL | static mut LAZY_BAZ: std::sync::LazyLock = std::sync::LazyLock::new(|| "baz".to_uppercase()); - | ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - static mut LAZY_BAZ: Lazy = Lazy::new(|| "baz".to_uppercase()); +LL + static mut LAZY_BAZ: std::sync::LazyLock = std::sync::LazyLock::new(|| "baz".to_uppercase()); + | error: aborting due to 6 previous errors diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index 06d3615c6e26..336cce40abf0 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -51,10 +51,12 @@ LL | let _ = a == b && c == 5 && a == b; | help: try | -LL | let _ = !(a != b || c != 5); - | ~~~~~~~~~~~~~~~~~~~ -LL | let _ = a == b && c == 5; - | ~~~~~~~~~~~~~~~~ +LL - let _ = a == b && c == 5 && a == b; +LL + let _ = !(a != b || c != 5); + | +LL - let _ = a == b && c == 5 && a == b; +LL + let _ = a == b && c == 5; + | error: this boolean expression can be simplified --> tests/ui/nonminimal_bool.rs:50:13 @@ -64,10 +66,12 @@ LL | let _ = a == b || c == 5 || a == b; | help: try | -LL | let _ = !(a != b && c != 5); - | ~~~~~~~~~~~~~~~~~~~ -LL | let _ = a == b || c == 5; - | ~~~~~~~~~~~~~~~~ +LL - let _ = a == b || c == 5 || a == b; +LL + let _ = !(a != b && c != 5); + | +LL - let _ = a == b || c == 5 || a == b; +LL + let _ = a == b || c == 5; + | error: this boolean expression can be simplified --> tests/ui/nonminimal_bool.rs:53:13 @@ -77,10 +81,12 @@ LL | let _ = a == b && c == 5 && b == a; | help: try | -LL | let _ = !(a != b || c != 5); - | ~~~~~~~~~~~~~~~~~~~ -LL | let _ = a == b && c == 5; - | ~~~~~~~~~~~~~~~~ +LL - let _ = a == b && c == 5 && b == a; +LL + let _ = !(a != b || c != 5); + | +LL - let _ = a == b && c == 5 && b == a; +LL + let _ = a == b && c == 5; + | error: this boolean expression can be simplified --> tests/ui/nonminimal_bool.rs:56:13 @@ -90,10 +96,12 @@ LL | let _ = a != b || !(a != b || c == d); | help: try | -LL | let _ = !(a == b && c == d); - | ~~~~~~~~~~~~~~~~~~~ -LL | let _ = a != b || c != d; - | ~~~~~~~~~~~~~~~~ +LL - let _ = a != b || !(a != b || c == d); +LL + let _ = !(a == b && c == d); + | +LL - let _ = a != b || !(a != b || c == d); +LL + let _ = a != b || c != d; + | error: this boolean expression can be simplified --> tests/ui/nonminimal_bool.rs:59:13 @@ -103,10 +111,12 @@ LL | let _ = a != b && !(a != b && c == d); | help: try | -LL | let _ = !(a == b || c == d); - | ~~~~~~~~~~~~~~~~~~~ -LL | let _ = a != b && c != d; - | ~~~~~~~~~~~~~~~~ +LL - let _ = a != b && !(a != b && c == d); +LL + let _ = !(a == b || c == d); + | +LL - let _ = a != b && !(a != b && c == d); +LL + let _ = a != b && c != d; + | error: this boolean expression can be simplified --> tests/ui/nonminimal_bool.rs:90:8 diff --git a/tests/ui/octal_escapes.stderr b/tests/ui/octal_escapes.stderr index 024308cbf429..35dabfed5650 100644 --- a/tests/ui/octal_escapes.stderr +++ b/tests/ui/octal_escapes.stderr @@ -9,12 +9,14 @@ LL | let _bad1 = "\033[0m"; = help: to override `-D warnings` add `#[allow(clippy::octal_escapes)]` help: if an octal escape is intended, use a hex escape instead | -LL | let _bad1 = "\x1b[0m"; - | ~~~~ +LL - let _bad1 = "\033[0m"; +LL + let _bad1 = "\x1b[0m"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad1 = "\x0033[0m"; - | ~~~~~~ +LL - let _bad1 = "\033[0m"; +LL + let _bad1 = "\x0033[0m"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:7:19 @@ -24,12 +26,14 @@ LL | let _bad2 = b"\033[0m"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad2 = b"\x1b[0m"; - | ~~~~ +LL - let _bad2 = b"\033[0m"; +LL + let _bad2 = b"\x1b[0m"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad2 = b"\x0033[0m"; - | ~~~~~~ +LL - let _bad2 = b"\033[0m"; +LL + let _bad2 = b"\x0033[0m"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:9:20 @@ -39,12 +43,14 @@ LL | let _bad3 = "\\\033[0m"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad3 = "\\\x1b[0m"; - | ~~~~ +LL - let _bad3 = "\\\033[0m"; +LL + let _bad3 = "\\\x1b[0m"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad3 = "\\\x0033[0m"; - | ~~~~~~ +LL - let _bad3 = "\\\033[0m"; +LL + let _bad3 = "\\\x0033[0m"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:12:18 @@ -54,12 +60,14 @@ LL | let _bad4 = "\01234567"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad4 = "\x0a34567"; - | ~~~~ +LL - let _bad4 = "\01234567"; +LL + let _bad4 = "\x0a34567"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad4 = "\x001234567"; - | ~~~~~~ +LL - let _bad4 = "\01234567"; +LL + let _bad4 = "\x001234567"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:14:20 @@ -69,12 +77,14 @@ LL | let _bad5 = "\0\03"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad5 = "\0\x03"; - | ~~~~ +LL - let _bad5 = "\0\03"; +LL + let _bad5 = "\0\x03"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad5 = "\0\x0003"; - | ~~~~~~ +LL - let _bad5 = "\0\03"; +LL + let _bad5 = "\0\x0003"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:16:23 @@ -84,12 +94,14 @@ LL | let _bad6 = "Text-\055\077-MoreText"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad6 = "Text-\x2d\077-MoreText"; - | ~~~~ +LL - let _bad6 = "Text-\055\077-MoreText"; +LL + let _bad6 = "Text-\x2d\077-MoreText"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad6 = "Text-\x0055\077-MoreText"; - | ~~~~~~ +LL - let _bad6 = "Text-\055\077-MoreText"; +LL + let _bad6 = "Text-\x0055\077-MoreText"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:16:27 @@ -99,12 +111,14 @@ LL | let _bad6 = "Text-\055\077-MoreText"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad6 = "Text-\055\x3f-MoreText"; - | ~~~~ +LL - let _bad6 = "Text-\055\077-MoreText"; +LL + let _bad6 = "Text-\055\x3f-MoreText"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad6 = "Text-\055\x0077-MoreText"; - | ~~~~~~ +LL - let _bad6 = "Text-\055\077-MoreText"; +LL + let _bad6 = "Text-\055\x0077-MoreText"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:20:31 @@ -114,12 +128,14 @@ LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad7 = "EvenMoreText-\x01\02-ShortEscapes"; - | ~~~~ +LL - let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; +LL + let _bad7 = "EvenMoreText-\x01\02-ShortEscapes"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad7 = "EvenMoreText-\x0001\02-ShortEscapes"; - | ~~~~~~ +LL - let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; +LL + let _bad7 = "EvenMoreText-\x0001\02-ShortEscapes"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:20:34 @@ -129,12 +145,14 @@ LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad7 = "EvenMoreText-\01\x02-ShortEscapes"; - | ~~~~ +LL - let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; +LL + let _bad7 = "EvenMoreText-\01\x02-ShortEscapes"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad7 = "EvenMoreText-\01\x0002-ShortEscapes"; - | ~~~~~~ +LL - let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; +LL + let _bad7 = "EvenMoreText-\01\x0002-ShortEscapes"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:24:19 @@ -144,12 +162,14 @@ LL | let _bad8 = "锈\01锈"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad8 = "锈\x01锈"; - | ~~~~ +LL - let _bad8 = "锈\01锈"; +LL + let _bad8 = "锈\x01锈"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad8 = "锈\x0001锈"; - | ~~~~~~ +LL - let _bad8 = "锈\01锈"; +LL + let _bad8 = "锈\x0001锈"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:26:19 @@ -159,12 +179,14 @@ LL | let _bad9 = "锈\011锈"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad9 = "锈\x09锈"; - | ~~~~ +LL - let _bad9 = "锈\011锈"; +LL + let _bad9 = "锈\x09锈"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad9 = "锈\x0011锈"; - | ~~~~~~ +LL - let _bad9 = "锈\011锈"; +LL + let _bad9 = "锈\x0011锈"; + | error: aborting due to 11 previous errors diff --git a/tests/ui/op_ref.stderr b/tests/ui/op_ref.stderr index f3fb3920ee1f..51c2963a9eed 100644 --- a/tests/ui/op_ref.stderr +++ b/tests/ui/op_ref.stderr @@ -8,8 +8,9 @@ LL | let foo = &5 - &6; = help: to override `-D warnings` add `#[allow(clippy::op_ref)]` help: use the values directly | -LL | let foo = 5 - 6; - | ~ ~ +LL - let foo = &5 - &6; +LL + let foo = 5 - 6; + | error: taken reference of right operand --> tests/ui/op_ref.rs:57:13 diff --git a/tests/ui/option_as_ref_cloned.stderr b/tests/ui/option_as_ref_cloned.stderr index d0f5747420bc..9f650b90d539 100644 --- a/tests/ui/option_as_ref_cloned.stderr +++ b/tests/ui/option_as_ref_cloned.stderr @@ -8,8 +8,9 @@ LL | let _: Option = x.as_ref().cloned(); = help: to override `-D warnings` add `#[allow(clippy::option_as_ref_cloned)]` help: this can be written more concisely by cloning the `Option<_>` directly | -LL | let _: Option = x.clone(); - | ~~~~~ +LL - let _: Option = x.as_ref().cloned(); +LL + let _: Option = x.clone(); + | error: cloning an `Option<_>` using `.as_mut().cloned()` --> tests/ui/option_as_ref_cloned.rs:9:31 @@ -19,8 +20,9 @@ LL | let _: Option = x.as_mut().cloned(); | help: this can be written more concisely by cloning the `Option<_>` directly | -LL | let _: Option = x.clone(); - | ~~~~~ +LL - let _: Option = x.as_mut().cloned(); +LL + let _: Option = x.clone(); + | error: cloning an `Option<_>` using `.as_ref().cloned()` --> tests/ui/option_as_ref_cloned.rs:13:32 @@ -30,8 +32,9 @@ LL | let _: Option<&String> = y.as_ref().cloned(); | help: this can be written more concisely by cloning the `Option<_>` directly | -LL | let _: Option<&String> = y.clone(); - | ~~~~~ +LL - let _: Option<&String> = y.as_ref().cloned(); +LL + let _: Option<&String> = y.clone(); + | error: aborting due to 3 previous errors diff --git a/tests/ui/redundant_guards.stderr b/tests/ui/redundant_guards.stderr index 2a3d8901066d..cb7b9b119e20 100644 --- a/tests/ui/redundant_guards.stderr +++ b/tests/ui/redundant_guards.stderr @@ -44,8 +44,9 @@ LL | Some(x) if matches!(x, Some(1) if true) => .., | help: try | -LL | Some(Some(1)) if true => .., - | ~~~~~~~ ~~~~~~~ +LL - Some(x) if matches!(x, Some(1) if true) => .., +LL + Some(Some(1)) if true => .., + | error: redundant guard --> tests/ui/redundant_guards.rs:54:20 diff --git a/tests/ui/ref_binding_to_reference.stderr b/tests/ui/ref_binding_to_reference.stderr index d245355c139d..c1adfab12bcb 100644 --- a/tests/ui/ref_binding_to_reference.stderr +++ b/tests/ui/ref_binding_to_reference.stderr @@ -8,8 +8,9 @@ LL | Some(ref x) => x, = help: to override `-D warnings` add `#[allow(clippy::ref_binding_to_reference)]` help: try | -LL | Some(x) => &x, - | ~ ~~ +LL - Some(ref x) => x, +LL + Some(x) => &x, + | error: this pattern creates a reference to a reference --> tests/ui/ref_binding_to_reference.rs:37:14 @@ -35,8 +36,9 @@ LL | Some(ref x) => m2!(x), | help: try | -LL | Some(x) => m2!(&x), - | ~ ~~ +LL - Some(ref x) => m2!(x), +LL + Some(x) => m2!(&x), + | error: this pattern creates a reference to a reference --> tests/ui/ref_binding_to_reference.rs:55:15 diff --git a/tests/ui/ref_option/ref_option.all.stderr b/tests/ui/ref_option/ref_option.all.stderr index 7eb425548745..bd43c28336eb 100644 --- a/tests/ui/ref_option/ref_option.all.stderr +++ b/tests/ui/ref_option/ref_option.all.stderr @@ -57,8 +57,9 @@ LL | fn mult_string(a: &Option, b: &Option>) {} | help: change this to | -LL | fn mult_string(a: Option<&String>, b: Option<&Vec>) {} - | ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - fn mult_string(a: &Option, b: &Option>) {} +LL + fn mult_string(a: Option<&String>, b: Option<&Vec>) {} + | error: it is more idiomatic to use `Option<&T>` instead of `&Option` --> tests/ui/ref_option/ref_option.rs:24:1 @@ -88,8 +89,9 @@ LL | pub fn pub_mult_string(a: &Option, b: &Option>) {} | help: change this to | -LL | pub fn pub_mult_string(a: Option<&String>, b: Option<&Vec>) {} - | ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - pub fn pub_mult_string(a: &Option, b: &Option>) {} +LL + pub fn pub_mult_string(a: Option<&String>, b: Option<&Vec>) {} + | error: it is more idiomatic to use `Option<&T>` instead of `&Option` --> tests/ui/ref_option/ref_option.rs:35:5 diff --git a/tests/ui/ref_option/ref_option.private.stderr b/tests/ui/ref_option/ref_option.private.stderr index f608092161bb..88c65e429d87 100644 --- a/tests/ui/ref_option/ref_option.private.stderr +++ b/tests/ui/ref_option/ref_option.private.stderr @@ -57,8 +57,9 @@ LL | fn mult_string(a: &Option, b: &Option>) {} | help: change this to | -LL | fn mult_string(a: Option<&String>, b: Option<&Vec>) {} - | ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - fn mult_string(a: &Option, b: &Option>) {} +LL + fn mult_string(a: Option<&String>, b: Option<&Vec>) {} + | error: it is more idiomatic to use `Option<&T>` instead of `&Option` --> tests/ui/ref_option/ref_option.rs:24:1 diff --git a/tests/ui/repeat_vec_with_capacity.stderr b/tests/ui/repeat_vec_with_capacity.stderr index 43027c9cb892..05513a8859a4 100644 --- a/tests/ui/repeat_vec_with_capacity.stderr +++ b/tests/ui/repeat_vec_with_capacity.stderr @@ -9,8 +9,9 @@ LL | vec![Vec::<()>::with_capacity(42); 123]; = help: to override `-D warnings` add `#[allow(clippy::repeat_vec_with_capacity)]` help: if you intended to initialize multiple `Vec`s with an initial capacity, try | -LL | (0..123).map(|_| Vec::<()>::with_capacity(42)).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![Vec::<()>::with_capacity(42); 123]; +LL + (0..123).map(|_| Vec::<()>::with_capacity(42)).collect::>(); + | error: repeating `Vec::with_capacity` using `vec![x; n]`, which does not retain capacity --> tests/ui/repeat_vec_with_capacity.rs:12:9 @@ -21,8 +22,9 @@ LL | vec![Vec::<()>::with_capacity(42); n]; = note: only the last `Vec` will have the capacity help: if you intended to initialize multiple `Vec`s with an initial capacity, try | -LL | (0..n).map(|_| Vec::<()>::with_capacity(42)).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![Vec::<()>::with_capacity(42); n]; +LL + (0..n).map(|_| Vec::<()>::with_capacity(42)).collect::>(); + | error: repeating `Vec::with_capacity` using `iter::repeat`, which does not retain capacity --> tests/ui/repeat_vec_with_capacity.rs:27:9 @@ -33,8 +35,9 @@ LL | std::iter::repeat(Vec::<()>::with_capacity(42)); = note: none of the yielded `Vec`s will have the requested capacity help: if you intended to create an iterator that yields `Vec`s with an initial capacity, try | -LL | std::iter::repeat_with(|| Vec::<()>::with_capacity(42)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - std::iter::repeat(Vec::<()>::with_capacity(42)); +LL + std::iter::repeat_with(|| Vec::<()>::with_capacity(42)); + | error: aborting due to 3 previous errors diff --git a/tests/ui/repeat_vec_with_capacity_nostd.stderr b/tests/ui/repeat_vec_with_capacity_nostd.stderr index 39364d09b961..092167485ced 100644 --- a/tests/ui/repeat_vec_with_capacity_nostd.stderr +++ b/tests/ui/repeat_vec_with_capacity_nostd.stderr @@ -9,8 +9,9 @@ LL | let _: Vec> = iter::repeat(Vec::with_capacity(42)).take(123).co = help: to override `-D warnings` add `#[allow(clippy::repeat_vec_with_capacity)]` help: if you intended to create an iterator that yields `Vec`s with an initial capacity, try | -LL | let _: Vec> = core::iter::repeat_with(|| Vec::with_capacity(42)).take(123).collect(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: Vec> = iter::repeat(Vec::with_capacity(42)).take(123).collect(); +LL + let _: Vec> = core::iter::repeat_with(|| Vec::with_capacity(42)).take(123).collect(); + | error: aborting due to 1 previous error diff --git a/tests/ui/reversed_empty_ranges_fixable.stderr b/tests/ui/reversed_empty_ranges_fixable.stderr index 706413726a12..3fadc4c169f1 100644 --- a/tests/ui/reversed_empty_ranges_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_fixable.stderr @@ -8,8 +8,9 @@ LL | (42..=21).for_each(|x| println!("{}", x)); = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` help: consider using the following if you are attempting to iterate over this range in reverse | -LL | (21..=42).rev().for_each(|x| println!("{}", x)); - | ~~~~~~~~~~~~~~~ +LL - (42..=21).for_each(|x| println!("{}", x)); +LL + (21..=42).rev().for_each(|x| println!("{}", x)); + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_fixable.rs:11:13 @@ -19,8 +20,9 @@ LL | let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::>( | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect::>(); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::>(); +LL + let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect::>(); + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_fixable.rs:14:14 @@ -30,8 +32,9 @@ LL | for _ in -21..=-42 {} | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for _ in (-42..=-21).rev() {} - | ~~~~~~~~~~~~~~~~~ +LL - for _ in -21..=-42 {} +LL + for _ in (-42..=-21).rev() {} + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_fixable.rs:16:14 @@ -41,8 +44,9 @@ LL | for _ in 42u32..21u32 {} | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for _ in (21u32..42u32).rev() {} - | ~~~~~~~~~~~~~~~~~~~~ +LL - for _ in 42u32..21u32 {} +LL + for _ in (21u32..42u32).rev() {} + | error: aborting due to 4 previous errors diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.stderr b/tests/ui/reversed_empty_ranges_loops_fixable.stderr index 0c05f351b46f..eadd9d3675e1 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_loops_fixable.stderr @@ -8,8 +8,9 @@ LL | for i in 10..0 { = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for i in (0..10).rev() { - | ~~~~~~~~~~~~~ +LL - for i in 10..0 { +LL + for i in (0..10).rev() { + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_loops_fixable.rs:12:14 @@ -19,8 +20,9 @@ LL | for i in 10..=0 { | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for i in (0..=10).rev() { - | ~~~~~~~~~~~~~~ +LL - for i in 10..=0 { +LL + for i in (0..=10).rev() { + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_loops_fixable.rs:17:14 @@ -30,8 +32,9 @@ LL | for i in MAX_LEN..0 { | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for i in (0..MAX_LEN).rev() { - | ~~~~~~~~~~~~~~~~~~ +LL - for i in MAX_LEN..0 { +LL + for i in (0..MAX_LEN).rev() { + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_loops_fixable.rs:37:14 @@ -41,8 +44,9 @@ LL | for i in (10..0).map(|x| x * 2) { | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for i in (0..10).rev().map(|x| x * 2) { - | ~~~~~~~~~~~~~ +LL - for i in (10..0).map(|x| x * 2) { +LL + for i in (0..10).rev().map(|x| x * 2) { + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_loops_fixable.rs:43:14 @@ -52,8 +56,9 @@ LL | for i in 10..5 + 4 { | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for i in (5 + 4..10).rev() { - | ~~~~~~~~~~~~~~~~~ +LL - for i in 10..5 + 4 { +LL + for i in (5 + 4..10).rev() { + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_loops_fixable.rs:48:14 @@ -63,8 +68,9 @@ LL | for i in (5 + 2)..(3 - 1) { | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for i in ((3 - 1)..(5 + 2)).rev() { - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in (5 + 2)..(3 - 1) { +LL + for i in ((3 - 1)..(5 + 2)).rev() { + | error: aborting due to 6 previous errors diff --git a/tests/ui/single_range_in_vec_init.stderr b/tests/ui/single_range_in_vec_init.stderr index 48f5a94826c6..a99127a7606f 100644 --- a/tests/ui/single_range_in_vec_init.stderr +++ b/tests/ui/single_range_in_vec_init.stderr @@ -8,12 +8,14 @@ LL | [0..200]; = help: to override `-D warnings` add `#[allow(clippy::single_range_in_vec_init)]` help: if you wanted a `Vec` that contains the entire range, try | -LL | (0..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - [0..200]; +LL + (0..200).collect::>(); + | help: if you wanted an array of len 200, try | -LL | [0; 200]; - | ~~~~~~ +LL - [0..200]; +LL + [0; 200]; + | error: a `Vec` of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:28:5 @@ -23,12 +25,14 @@ LL | vec![0..200]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![0..200]; +LL + (0..200).collect::>(); + | help: if you wanted a `Vec` of len 200, try | -LL | vec![0; 200]; - | ~~~~~~ +LL - vec![0..200]; +LL + vec![0; 200]; + | error: an array of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:30:5 @@ -38,12 +42,14 @@ LL | [0u8..200]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0u8..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - [0u8..200]; +LL + (0u8..200).collect::>(); + | help: if you wanted an array of len 200, try | -LL | [0u8; 200]; - | ~~~~~~~~ +LL - [0u8..200]; +LL + [0u8; 200]; + | error: an array of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:32:5 @@ -53,12 +59,14 @@ LL | [0usize..200]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0usize..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - [0usize..200]; +LL + (0usize..200).collect::>(); + | help: if you wanted an array of len 200, try | -LL | [0usize; 200]; - | ~~~~~~~~~~~ +LL - [0usize..200]; +LL + [0usize; 200]; + | error: an array of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:34:5 @@ -68,12 +76,14 @@ LL | [0..200usize]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0..200usize).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - [0..200usize]; +LL + (0..200usize).collect::>(); + | help: if you wanted an array of len 200usize, try | -LL | [0; 200usize]; - | ~~~~~~~~~~~ +LL - [0..200usize]; +LL + [0; 200usize]; + | error: a `Vec` of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:36:5 @@ -83,12 +93,14 @@ LL | vec![0u8..200]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0u8..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![0u8..200]; +LL + (0u8..200).collect::>(); + | help: if you wanted a `Vec` of len 200, try | -LL | vec![0u8; 200]; - | ~~~~~~~~ +LL - vec![0u8..200]; +LL + vec![0u8; 200]; + | error: a `Vec` of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:38:5 @@ -98,12 +110,14 @@ LL | vec![0usize..200]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0usize..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![0usize..200]; +LL + (0usize..200).collect::>(); + | help: if you wanted a `Vec` of len 200, try | -LL | vec![0usize; 200]; - | ~~~~~~~~~~~ +LL - vec![0usize..200]; +LL + vec![0usize; 200]; + | error: a `Vec` of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:40:5 @@ -113,12 +127,14 @@ LL | vec![0..200usize]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0..200usize).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![0..200usize]; +LL + (0..200usize).collect::>(); + | help: if you wanted a `Vec` of len 200usize, try | -LL | vec![0; 200usize]; - | ~~~~~~~~~~~ +LL - vec![0..200usize]; +LL + vec![0; 200usize]; + | error: an array of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:43:5 @@ -128,8 +144,9 @@ LL | [0..200isize]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0..200isize).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - [0..200isize]; +LL + (0..200isize).collect::>(); + | error: a `Vec` of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:45:5 @@ -139,8 +156,9 @@ LL | vec![0..200isize]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0..200isize).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![0..200isize]; +LL + (0..200isize).collect::>(); + | error: aborting due to 10 previous errors diff --git a/tests/ui/string_lit_chars_any.stderr b/tests/ui/string_lit_chars_any.stderr index b6bfb8d4b791..3ba447b3c36b 100644 --- a/tests/ui/string_lit_chars_any.stderr +++ b/tests/ui/string_lit_chars_any.stderr @@ -8,8 +8,9 @@ LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c); = help: to override `-D warnings` add `#[allow(clippy::string_lit_chars_any)]` help: use `matches!(...)` instead | -LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c); +LL + matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + | error: usage of `.chars().any(...)` to check if a char matches any from a string literal --> tests/ui/string_lit_chars_any.rs:20:5 @@ -19,8 +20,9 @@ LL | r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c); | help: use `matches!(...)` instead | -LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c); +LL + matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + | error: usage of `.chars().any(...)` to check if a char matches any from a string literal --> tests/ui/string_lit_chars_any.rs:22:5 @@ -30,8 +32,9 @@ LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| c == x); | help: use `matches!(...)` instead | -LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "\\.+*?()|[]{}^$#&-~".chars().any(|x| c == x); +LL + matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + | error: usage of `.chars().any(...)` to check if a char matches any from a string literal --> tests/ui/string_lit_chars_any.rs:24:5 @@ -41,8 +44,9 @@ LL | r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x); | help: use `matches!(...)` instead | -LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x); +LL + matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + | error: usage of `.chars().any(...)` to check if a char matches any from a string literal --> tests/ui/string_lit_chars_any.rs:27:5 @@ -52,8 +56,9 @@ LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| { x == c }); | help: use `matches!(...)` instead | -LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "\\.+*?()|[]{}^$#&-~".chars().any(|x| { x == c }); +LL + matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + | error: aborting due to 5 previous errors diff --git a/tests/ui/suspicious_command_arg_space.stderr b/tests/ui/suspicious_command_arg_space.stderr index 6fd07d07d7be..8952a3ffe4b8 100644 --- a/tests/ui/suspicious_command_arg_space.stderr +++ b/tests/ui/suspicious_command_arg_space.stderr @@ -8,8 +8,9 @@ LL | std::process::Command::new("echo").arg("-n hello").spawn().unwrap(); = help: to override `-D warnings` add `#[allow(clippy::suspicious_command_arg_space)]` help: consider splitting the argument | -LL | std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap(); - | ~~~~ ~~~~~~~~~~~~~~~ +LL - std::process::Command::new("echo").arg("-n hello").spawn().unwrap(); +LL + std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap(); + | error: single argument that looks like it should be multiple arguments --> tests/ui/suspicious_command_arg_space.rs:7:43 @@ -19,8 +20,9 @@ LL | std::process::Command::new("cat").arg("--number file").spawn().unwrap() | help: consider splitting the argument | -LL | std::process::Command::new("cat").args(["--number", "file"]).spawn().unwrap(); - | ~~~~ ~~~~~~~~~~~~~~~~~~~~ +LL - std::process::Command::new("cat").arg("--number file").spawn().unwrap(); +LL + std::process::Command::new("cat").args(["--number", "file"]).spawn().unwrap(); + | error: aborting due to 2 previous errors diff --git a/tests/ui/suspicious_doc_comments.fixed b/tests/ui/suspicious_doc_comments.fixed index 0c878afc66e1..3696b0e066d2 100644 --- a/tests/ui/suspicious_doc_comments.fixed +++ b/tests/ui/suspicious_doc_comments.fixed @@ -1,5 +1,6 @@ #![allow(unused)] #![warn(clippy::suspicious_doc_comments)] +#![allow(clippy::empty_line_after_doc_comments)] //! Real module documentation. //! Fake module documentation. diff --git a/tests/ui/suspicious_doc_comments.rs b/tests/ui/suspicious_doc_comments.rs index d89fe4f1bec7..4107f5526d13 100644 --- a/tests/ui/suspicious_doc_comments.rs +++ b/tests/ui/suspicious_doc_comments.rs @@ -1,5 +1,6 @@ #![allow(unused)] #![warn(clippy::suspicious_doc_comments)] +#![allow(clippy::empty_line_after_doc_comments)] //! Real module documentation. ///! Fake module documentation. diff --git a/tests/ui/suspicious_doc_comments.stderr b/tests/ui/suspicious_doc_comments.stderr index 61363ff9bd20..df04d08537c9 100644 --- a/tests/ui/suspicious_doc_comments.stderr +++ b/tests/ui/suspicious_doc_comments.stderr @@ -1,5 +1,5 @@ error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:5:1 + --> tests/ui/suspicious_doc_comments.rs:6:1 | LL | ///! Fake module documentation. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,22 +8,24 @@ LL | ///! Fake module documentation. = help: to override `-D warnings` add `#[allow(clippy::suspicious_doc_comments)]` help: use an inner doc comment to document the parent module or crate | -LL | //! Fake module documentation. +LL - ///! Fake module documentation. +LL + //! Fake module documentation. | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:10:5 + --> tests/ui/suspicious_doc_comments.rs:11:5 | LL | ///! This module contains useful functions. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use an inner doc comment to document the parent module or crate | -LL | //! This module contains useful functions. +LL - ///! This module contains useful functions. +LL + //! This module contains useful functions. | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:23:5 + --> tests/ui/suspicious_doc_comments.rs:24:5 | LL | / /**! This module contains useful functions. LL | | */ @@ -36,7 +38,7 @@ LL + */ | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:38:5 + --> tests/ui/suspicious_doc_comments.rs:39:5 | LL | / ///! This module LL | | @@ -53,7 +55,7 @@ LL ~ //! useful functions. | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:47:5 + --> tests/ui/suspicious_doc_comments.rs:48:5 | LL | / ///! a LL | | @@ -68,18 +70,19 @@ LL ~ //! b | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:56:5 + --> tests/ui/suspicious_doc_comments.rs:57:5 | LL | ///! a | ^^^^^^ | help: use an inner doc comment to document the parent module or crate | -LL | //! a +LL - ///! a +LL + //! a | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:63:5 + --> tests/ui/suspicious_doc_comments.rs:64:5 | LL | / ///! a ... | @@ -95,25 +98,27 @@ LL ~ //! b | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:76:5 + --> tests/ui/suspicious_doc_comments.rs:77:5 | LL | ///! Very cool macro | ^^^^^^^^^^^^^^^^^^^^ | help: use an inner doc comment to document the parent module or crate | -LL | //! Very cool macro +LL - ///! Very cool macro +LL + //! Very cool macro | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:84:5 + --> tests/ui/suspicious_doc_comments.rs:85:5 | LL | ///! Huh. | ^^^^^^^^^ | help: use an inner doc comment to document the parent module or crate | -LL | //! Huh. +LL - ///! Huh. +LL + //! Huh. | error: aborting due to 9 previous errors diff --git a/tests/ui/suspicious_doc_comments_unfixable.rs b/tests/ui/suspicious_doc_comments_unfixable.rs index e526de5ca2c3..17c7cc15b170 100644 --- a/tests/ui/suspicious_doc_comments_unfixable.rs +++ b/tests/ui/suspicious_doc_comments_unfixable.rs @@ -1,4 +1,4 @@ -#![allow(unused)] +#![allow(unused, clippy::empty_line_after_doc_comments)] #![warn(clippy::suspicious_doc_comments)] //@no-rustfix ///! a diff --git a/tests/ui/suspicious_to_owned.stderr b/tests/ui/suspicious_to_owned.stderr index cc6f5b7d3a5a..2dc82055264b 100644 --- a/tests/ui/suspicious_to_owned.stderr +++ b/tests/ui/suspicious_to_owned.stderr @@ -8,12 +8,14 @@ LL | let _ = cow.to_owned(); = help: to override `-D warnings` add `#[allow(clippy::suspicious_to_owned)]` help: depending on intent, either make the Cow an Owned variant | -LL | let _ = cow.into_owned(); - | ~~~~~~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +LL + let _ = cow.into_owned(); + | help: or clone the Cow itself | -LL | let _ = cow.clone(); - | ~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +LL + let _ = cow.clone(); + | error: this `to_owned` call clones the Cow<'_, [char; 3]> itself and does not cause the Cow<'_, [char; 3]> contents to become owned --> tests/ui/suspicious_to_owned.rs:29:13 @@ -23,12 +25,14 @@ LL | let _ = cow.to_owned(); | help: depending on intent, either make the Cow an Owned variant | -LL | let _ = cow.into_owned(); - | ~~~~~~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +LL + let _ = cow.into_owned(); + | help: or clone the Cow itself | -LL | let _ = cow.clone(); - | ~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +LL + let _ = cow.clone(); + | error: this `to_owned` call clones the Cow<'_, Vec> itself and does not cause the Cow<'_, Vec> contents to become owned --> tests/ui/suspicious_to_owned.rs:41:13 @@ -38,12 +42,14 @@ LL | let _ = cow.to_owned(); | help: depending on intent, either make the Cow an Owned variant | -LL | let _ = cow.into_owned(); - | ~~~~~~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +LL + let _ = cow.into_owned(); + | help: or clone the Cow itself | -LL | let _ = cow.clone(); - | ~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +LL + let _ = cow.clone(); + | error: this `to_owned` call clones the Cow<'_, str> itself and does not cause the Cow<'_, str> contents to become owned --> tests/ui/suspicious_to_owned.rs:53:13 @@ -53,12 +59,14 @@ LL | let _ = cow.to_owned(); | help: depending on intent, either make the Cow an Owned variant | -LL | let _ = cow.into_owned(); - | ~~~~~~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +LL + let _ = cow.into_owned(); + | help: or clone the Cow itself | -LL | let _ = cow.clone(); - | ~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +LL + let _ = cow.clone(); + | error: implicitly cloning a `String` by calling `to_owned` on its dereferenced type --> tests/ui/suspicious_to_owned.rs:69:13 diff --git a/tests/ui/suspicious_xor_used_as_pow.stderr b/tests/ui/suspicious_xor_used_as_pow.stderr index 0913154a26e2..efeafdb94acb 100644 --- a/tests/ui/suspicious_xor_used_as_pow.stderr +++ b/tests/ui/suspicious_xor_used_as_pow.stderr @@ -8,8 +8,9 @@ LL | let _ = 2 ^ 5; = help: to override `-D warnings` add `#[allow(clippy::suspicious_xor_used_as_pow)]` help: did you mean to write | -LL | let _ = 2.pow(5); - | ~~~~~~~~ +LL - let _ = 2 ^ 5; +LL + let _ = 2.pow(5); + | error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:24:13 @@ -19,8 +20,9 @@ LL | let _ = 2i32 ^ 9i32; | help: did you mean to write | -LL | let _ = 2i32.pow(9i32); - | ~~~~~~~~~~~~~~ +LL - let _ = 2i32 ^ 9i32; +LL + let _ = 2i32.pow(9i32); + | error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:27:13 @@ -30,8 +32,9 @@ LL | let _ = 2i32 ^ 2i32; | help: did you mean to write | -LL | let _ = 2i32.pow(2i32); - | ~~~~~~~~~~~~~~ +LL - let _ = 2i32 ^ 2i32; +LL + let _ = 2i32.pow(2i32); + | error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:30:13 @@ -41,8 +44,9 @@ LL | let _ = 50i32 ^ 3i32; | help: did you mean to write | -LL | let _ = 50i32.pow(3i32); - | ~~~~~~~~~~~~~~~ +LL - let _ = 50i32 ^ 3i32; +LL + let _ = 50i32.pow(3i32); + | error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:33:13 @@ -52,8 +56,9 @@ LL | let _ = 5i32 ^ 8i32; | help: did you mean to write | -LL | let _ = 5i32.pow(8i32); - | ~~~~~~~~~~~~~~ +LL - let _ = 5i32 ^ 8i32; +LL + let _ = 5i32.pow(8i32); + | error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:36:13 @@ -63,8 +68,9 @@ LL | let _ = 2i32 ^ 32i32; | help: did you mean to write | -LL | let _ = 2i32.pow(32i32); - | ~~~~~~~~~~~~~~~ +LL - let _ = 2i32 ^ 32i32; +LL + let _ = 2i32.pow(32i32); + | error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:13:9 @@ -78,8 +84,9 @@ LL | macro_test_inside!(); = note: this error originates in the macro `macro_test_inside` (in Nightly builds, run with -Z macro-backtrace for more info) help: did you mean to write | -LL | 1.pow(2) // should warn even if inside macro - | ~~~~~~~~ +LL - 1 ^ 2 // should warn even if inside macro +LL + 1.pow(2) // should warn even if inside macro + | error: aborting due to 7 previous errors diff --git a/tests/ui/transmute_ptr_to_ptr.stderr b/tests/ui/transmute_ptr_to_ptr.stderr index 0ff1cd3c090b..c8db4fe214fd 100644 --- a/tests/ui/transmute_ptr_to_ptr.stderr +++ b/tests/ui/transmute_ptr_to_ptr.stderr @@ -8,8 +8,9 @@ LL | let _: *const f32 = transmute(ptr); = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ptr)]` help: use `pointer::cast` instead | -LL | let _: *const f32 = ptr.cast::(); - | ~~~~~~~~~~~~~~~~~ +LL - let _: *const f32 = transmute(ptr); +LL + let _: *const f32 = ptr.cast::(); + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:35:27 @@ -19,8 +20,9 @@ LL | let _: *mut f32 = transmute(mut_ptr); | help: use `pointer::cast` instead | -LL | let _: *mut f32 = mut_ptr.cast::(); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - let _: *mut f32 = transmute(mut_ptr); +LL + let _: *mut f32 = mut_ptr.cast::(); + | error: transmute from a reference to a reference --> tests/ui/transmute_ptr_to_ptr.rs:39:23 @@ -60,8 +62,9 @@ LL | let _: *const u32 = transmute(mut_ptr); | help: use `pointer::cast_const` instead | -LL | let _: *const u32 = mut_ptr.cast_const(); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _: *const u32 = transmute(mut_ptr); +LL + let _: *const u32 = mut_ptr.cast_const(); + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:60:27 @@ -71,8 +74,9 @@ LL | let _: *mut u32 = transmute(ptr); | help: use `pointer::cast_mut` instead | -LL | let _: *mut u32 = ptr.cast_mut(); - | ~~~~~~~~~~~~~~ +LL - let _: *mut u32 = transmute(ptr); +LL + let _: *mut u32 = ptr.cast_mut(); + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:72:14 @@ -82,8 +86,9 @@ LL | unsafe { transmute(v) } | help: use an `as` cast instead | -LL | unsafe { v as *const &() } - | ~~~~~~~~~~~~~~~ +LL - unsafe { transmute(v) } +LL + unsafe { v as *const &() } + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:87:28 @@ -93,8 +98,9 @@ LL | let _: *const i8 = transmute(ptr); | help: use an `as` cast instead | -LL | let _: *const i8 = ptr as *const i8; - | ~~~~~~~~~~~~~~~~ +LL - let _: *const i8 = transmute(ptr); +LL + let _: *const i8 = ptr as *const i8; + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:95:28 @@ -104,8 +110,9 @@ LL | let _: *const i8 = transmute(ptr); | help: use `pointer::cast` instead | -LL | let _: *const i8 = ptr.cast::(); - | ~~~~~~~~~~~~~~~~ +LL - let _: *const i8 = transmute(ptr); +LL + let _: *const i8 = ptr.cast::(); + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:103:26 @@ -115,8 +122,9 @@ LL | let _: *mut u8 = transmute(ptr); | help: use an `as` cast instead | -LL | let _: *mut u8 = ptr as *mut u8; - | ~~~~~~~~~~~~~~ +LL - let _: *mut u8 = transmute(ptr); +LL + let _: *mut u8 = ptr as *mut u8; + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:105:28 @@ -126,8 +134,9 @@ LL | let _: *const u8 = transmute(mut_ptr); | help: use an `as` cast instead | -LL | let _: *const u8 = mut_ptr as *const u8; - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _: *const u8 = transmute(mut_ptr); +LL + let _: *const u8 = mut_ptr as *const u8; + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:113:26 @@ -137,8 +146,9 @@ LL | let _: *mut u8 = transmute(ptr); | help: use `pointer::cast_mut` instead | -LL | let _: *mut u8 = ptr.cast_mut(); - | ~~~~~~~~~~~~~~ +LL - let _: *mut u8 = transmute(ptr); +LL + let _: *mut u8 = ptr.cast_mut(); + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:115:28 @@ -148,8 +158,9 @@ LL | let _: *const u8 = transmute(mut_ptr); | help: use `pointer::cast_const` instead | -LL | let _: *const u8 = mut_ptr.cast_const(); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _: *const u8 = transmute(mut_ptr); +LL + let _: *const u8 = mut_ptr.cast_const(); + | error: aborting due to 16 previous errors diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr index 1dab24a78d87..7746f087cc71 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ b/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -17,8 +17,9 @@ LL | let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ptr)]` help: use `pointer::cast` instead | -LL | let _ptr_i8_transmute = unsafe { ptr_i32.cast::() }; - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr_i32) }; +LL + let _ptr_i8_transmute = unsafe { ptr_i32.cast::() }; + | error: transmute from a pointer to a pointer --> tests/ui/transmutes_expressible_as_ptr_casts.rs:29:46 @@ -28,8 +29,9 @@ LL | let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *con | help: use an `as` cast instead | -LL | let _ptr_to_unsized_transmute = unsafe { slice_ptr as *const [u32] }; - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *const [u32]>(slice_ptr) }; +LL + let _ptr_to_unsized_transmute = unsafe { slice_ptr as *const [u32] }; + | error: transmute from `*const i32` to `usize` which could be expressed as a pointer cast instead --> tests/ui/transmutes_expressible_as_ptr_casts.rs:36:50 diff --git a/tests/ui/unit_arg.stderr b/tests/ui/unit_arg.stderr index 2ddb28bd4cc4..6c333d9792d4 100644 --- a/tests/ui/unit_arg.stderr +++ b/tests/ui/unit_arg.stderr @@ -11,7 +11,8 @@ LL | | }); = help: to override `-D warnings` add `#[allow(clippy::unit_arg)]` help: remove the semicolon from the last statement in the block | -LL | 1 +LL - 1; +LL + 1 | help: or move the expression in front of the call and replace it with the unit literal `()` | @@ -46,7 +47,8 @@ LL | | }); | help: remove the semicolon from the last statement in the block | -LL | foo(2) +LL - foo(2); +LL + foo(2) | help: or move the expression in front of the call and replace it with the unit literal `()` | @@ -69,7 +71,8 @@ LL | | }); | help: remove the semicolon from the last statement in the block | -LL | 1 +LL - 1; +LL + 1 | help: or move the expression in front of the call and replace it with the unit literal `()` | @@ -105,7 +108,8 @@ LL | | }); | help: remove the semicolon from the last statement in the block | -LL | foo(2) +LL - foo(2); +LL + foo(2) | help: or move the expressions in front of the call and replace them with the unit literal `()` | @@ -132,11 +136,13 @@ LL | | ); | help: remove the semicolon from the last statement in the block | -LL | foo(1) +LL - foo(1); +LL + foo(1) | help: remove the semicolon from the last statement in the block | -LL | foo(3) +LL - foo(3); +LL + foo(3) | help: or move the expressions in front of the call and replace them with the unit literal `()` | diff --git a/tests/ui/unknown_clippy_lints.stderr b/tests/ui/unknown_clippy_lints.stderr index 96a35312755c..592fdfbebd43 100644 --- a/tests/ui/unknown_clippy_lints.stderr +++ b/tests/ui/unknown_clippy_lints.stderr @@ -39,8 +39,9 @@ LL | #[warn(clippy::dead_cod)] | help: a lint with a similar name exists in `rustc` lints | -LL | #[warn(dead_code)] - | ~~~~~~~~~ +LL - #[warn(clippy::dead_cod)] +LL + #[warn(dead_code)] + | error: unknown lint: `clippy::unused_colle` --> tests/ui/unknown_clippy_lints.rs:19:8 @@ -62,8 +63,9 @@ LL | #[warn(clippy::missing_docs)] | help: a lint with a similar name exists in `rustc` lints | -LL | #[warn(missing_docs)] - | ~~~~~~~~~~~~ +LL - #[warn(clippy::missing_docs)] +LL + #[warn(missing_docs)] + | error: aborting due to 9 previous errors diff --git a/tests/ui/unnecessary_lazy_eval.stderr b/tests/ui/unnecessary_lazy_eval.stderr index d1bb08cceadf..75a06a419c71 100644 --- a/tests/ui/unnecessary_lazy_eval.stderr +++ b/tests/ui/unnecessary_lazy_eval.stderr @@ -8,8 +8,9 @@ LL | let _ = opt.unwrap_or_else(|| 2); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_lazy_evaluations)]` help: use `unwrap_or` instead | -LL | let _ = opt.unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = opt.unwrap_or_else(|| 2); +LL + let _ = opt.unwrap_or(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:85:13 @@ -19,8 +20,9 @@ LL | let _ = opt.unwrap_or_else(|| astronomers_pi); | help: use `unwrap_or` instead | -LL | let _ = opt.unwrap_or(astronomers_pi); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = opt.unwrap_or_else(|| astronomers_pi); +LL + let _ = opt.unwrap_or(astronomers_pi); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:87:13 @@ -30,8 +32,9 @@ LL | let _ = opt.unwrap_or_else(|| ext_str.some_field); | help: use `unwrap_or` instead | -LL | let _ = opt.unwrap_or(ext_str.some_field); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = opt.unwrap_or_else(|| ext_str.some_field); +LL + let _ = opt.unwrap_or(ext_str.some_field); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:90:13 @@ -41,8 +44,9 @@ LL | let _ = opt.and_then(|_| ext_opt); | help: use `and` instead | -LL | let _ = opt.and(ext_opt); - | ~~~~~~~~~~~~ +LL - let _ = opt.and_then(|_| ext_opt); +LL + let _ = opt.and(ext_opt); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:92:13 @@ -52,8 +56,9 @@ LL | let _ = opt.or_else(|| ext_opt); | help: use `or` instead | -LL | let _ = opt.or(ext_opt); - | ~~~~~~~~~~~ +LL - let _ = opt.or_else(|| ext_opt); +LL + let _ = opt.or(ext_opt); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:94:13 @@ -63,8 +68,9 @@ LL | let _ = opt.or_else(|| None); | help: use `or` instead | -LL | let _ = opt.or(None); - | ~~~~~~~~ +LL - let _ = opt.or_else(|| None); +LL + let _ = opt.or(None); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:96:13 @@ -74,8 +80,9 @@ LL | let _ = opt.get_or_insert_with(|| 2); | help: use `get_or_insert` instead | -LL | let _ = opt.get_or_insert(2); - | ~~~~~~~~~~~~~~~~ +LL - let _ = opt.get_or_insert_with(|| 2); +LL + let _ = opt.get_or_insert(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:98:13 @@ -85,8 +92,9 @@ LL | let _ = opt.ok_or_else(|| 2); | help: use `ok_or` instead | -LL | let _ = opt.ok_or(2); - | ~~~~~~~~ +LL - let _ = opt.ok_or_else(|| 2); +LL + let _ = opt.ok_or(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:100:13 @@ -96,8 +104,9 @@ LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); | help: use `unwrap_or` instead | -LL | let _ = nested_tuple_opt.unwrap_or(Some((1, 2))); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); +LL + let _ = nested_tuple_opt.unwrap_or(Some((1, 2))); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:102:13 @@ -107,8 +116,9 @@ LL | let _ = cond.then(|| astronomers_pi); | help: use `then_some` instead | -LL | let _ = cond.then_some(astronomers_pi); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = cond.then(|| astronomers_pi); +LL + let _ = cond.then_some(astronomers_pi); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:104:13 @@ -118,8 +128,9 @@ LL | let _ = true.then(|| -> _ {}); | help: use `then_some` instead | -LL | let _ = true.then_some({}); - | ~~~~~~~~~~~~~ +LL - let _ = true.then(|| -> _ {}); +LL + let _ = true.then_some({}); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:106:13 @@ -129,8 +140,9 @@ LL | let _ = true.then(|| {}); | help: use `then_some` instead | -LL | let _ = true.then_some({}); - | ~~~~~~~~~~~~~ +LL - let _ = true.then(|| {}); +LL + let _ = true.then_some({}); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:111:13 @@ -140,8 +152,9 @@ LL | let _ = Some(1).unwrap_or_else(|| *r); | help: use `unwrap_or` instead | -LL | let _ = Some(1).unwrap_or(*r); - | ~~~~~~~~~~~~~ +LL - let _ = Some(1).unwrap_or_else(|| *r); +LL + let _ = Some(1).unwrap_or(*r); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:114:13 @@ -151,8 +164,9 @@ LL | let _ = Some(1).unwrap_or_else(|| *b); | help: use `unwrap_or` instead | -LL | let _ = Some(1).unwrap_or(*b); - | ~~~~~~~~~~~~~ +LL - let _ = Some(1).unwrap_or_else(|| *b); +LL + let _ = Some(1).unwrap_or(*b); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:117:13 @@ -162,8 +176,9 @@ LL | let _ = Some(1).as_ref().unwrap_or_else(|| &r); | help: use `unwrap_or` instead | -LL | let _ = Some(1).as_ref().unwrap_or(&r); - | ~~~~~~~~~~~~~ +LL - let _ = Some(1).as_ref().unwrap_or_else(|| &r); +LL + let _ = Some(1).as_ref().unwrap_or(&r); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:119:13 @@ -173,8 +188,9 @@ LL | let _ = Some(1).as_ref().unwrap_or_else(|| &b); | help: use `unwrap_or` instead | -LL | let _ = Some(1).as_ref().unwrap_or(&b); - | ~~~~~~~~~~~~~ +LL - let _ = Some(1).as_ref().unwrap_or_else(|| &b); +LL + let _ = Some(1).as_ref().unwrap_or(&b); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:123:13 @@ -184,8 +200,9 @@ LL | let _ = Some(10).unwrap_or_else(|| 2); | help: use `unwrap_or` instead | -LL | let _ = Some(10).unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = Some(10).unwrap_or_else(|| 2); +LL + let _ = Some(10).unwrap_or(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:125:13 @@ -195,8 +212,9 @@ LL | let _ = Some(10).and_then(|_| ext_opt); | help: use `and` instead | -LL | let _ = Some(10).and(ext_opt); - | ~~~~~~~~~~~~ +LL - let _ = Some(10).and_then(|_| ext_opt); +LL + let _ = Some(10).and(ext_opt); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:127:28 @@ -206,8 +224,9 @@ LL | let _: Option = None.or_else(|| ext_opt); | help: use `or` instead | -LL | let _: Option = None.or(ext_opt); - | ~~~~~~~~~~~ +LL - let _: Option = None.or_else(|| ext_opt); +LL + let _: Option = None.or(ext_opt); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:129:13 @@ -217,8 +236,9 @@ LL | let _ = None.get_or_insert_with(|| 2); | help: use `get_or_insert` instead | -LL | let _ = None.get_or_insert(2); - | ~~~~~~~~~~~~~~~~ +LL - let _ = None.get_or_insert_with(|| 2); +LL + let _ = None.get_or_insert(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:131:35 @@ -228,8 +248,9 @@ LL | let _: Result = None.ok_or_else(|| 2); | help: use `ok_or` instead | -LL | let _: Result = None.ok_or(2); - | ~~~~~~~~ +LL - let _: Result = None.ok_or_else(|| 2); +LL + let _: Result = None.ok_or(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:133:28 @@ -239,8 +260,9 @@ LL | let _: Option = None.or_else(|| None); | help: use `or` instead | -LL | let _: Option = None.or(None); - | ~~~~~~~~ +LL - let _: Option = None.or_else(|| None); +LL + let _: Option = None.or(None); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:137:13 @@ -250,8 +272,9 @@ LL | let _ = deep.0.unwrap_or_else(|| 2); | help: use `unwrap_or` instead | -LL | let _ = deep.0.unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = deep.0.unwrap_or_else(|| 2); +LL + let _ = deep.0.unwrap_or(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:139:13 @@ -261,8 +284,9 @@ LL | let _ = deep.0.and_then(|_| ext_opt); | help: use `and` instead | -LL | let _ = deep.0.and(ext_opt); - | ~~~~~~~~~~~~ +LL - let _ = deep.0.and_then(|_| ext_opt); +LL + let _ = deep.0.and(ext_opt); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:141:13 @@ -272,8 +296,9 @@ LL | let _ = deep.0.or_else(|| None); | help: use `or` instead | -LL | let _ = deep.0.or(None); - | ~~~~~~~~ +LL - let _ = deep.0.or_else(|| None); +LL + let _ = deep.0.or(None); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:143:13 @@ -283,8 +308,9 @@ LL | let _ = deep.0.get_or_insert_with(|| 2); | help: use `get_or_insert` instead | -LL | let _ = deep.0.get_or_insert(2); - | ~~~~~~~~~~~~~~~~ +LL - let _ = deep.0.get_or_insert_with(|| 2); +LL + let _ = deep.0.get_or_insert(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:145:13 @@ -294,8 +320,9 @@ LL | let _ = deep.0.ok_or_else(|| 2); | help: use `ok_or` instead | -LL | let _ = deep.0.ok_or(2); - | ~~~~~~~~ +LL - let _ = deep.0.ok_or_else(|| 2); +LL + let _ = deep.0.ok_or(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:177:28 @@ -305,8 +332,9 @@ LL | let _: Option = None.or_else(|| Some(3)); | help: use `or` instead | -LL | let _: Option = None.or(Some(3)); - | ~~~~~~~~~~~ +LL - let _: Option = None.or_else(|| Some(3)); +LL + let _: Option = None.or(Some(3)); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:179:13 @@ -316,8 +344,9 @@ LL | let _ = deep.0.or_else(|| Some(3)); | help: use `or` instead | -LL | let _ = deep.0.or(Some(3)); - | ~~~~~~~~~~~ +LL - let _ = deep.0.or_else(|| Some(3)); +LL + let _ = deep.0.or(Some(3)); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:181:13 @@ -327,8 +356,9 @@ LL | let _ = opt.or_else(|| Some(3)); | help: use `or` instead | -LL | let _ = opt.or(Some(3)); - | ~~~~~~~~~~~ +LL - let _ = opt.or_else(|| Some(3)); +LL + let _ = opt.or(Some(3)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:188:13 @@ -338,8 +368,9 @@ LL | let _ = res2.unwrap_or_else(|_| 2); | help: use `unwrap_or` instead | -LL | let _ = res2.unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = res2.unwrap_or_else(|_| 2); +LL + let _ = res2.unwrap_or(2); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:190:13 @@ -349,8 +380,9 @@ LL | let _ = res2.unwrap_or_else(|_| astronomers_pi); | help: use `unwrap_or` instead | -LL | let _ = res2.unwrap_or(astronomers_pi); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = res2.unwrap_or_else(|_| astronomers_pi); +LL + let _ = res2.unwrap_or(astronomers_pi); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:192:13 @@ -360,8 +392,9 @@ LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field); | help: use `unwrap_or` instead | -LL | let _ = res2.unwrap_or(ext_str.some_field); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = res2.unwrap_or_else(|_| ext_str.some_field); +LL + let _ = res2.unwrap_or(ext_str.some_field); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:215:35 @@ -371,8 +404,9 @@ LL | let _: Result = res.and_then(|_| Err(2)); | help: use `and` instead | -LL | let _: Result = res.and(Err(2)); - | ~~~~~~~~~~~ +LL - let _: Result = res.and_then(|_| Err(2)); +LL + let _: Result = res.and(Err(2)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:217:35 @@ -382,8 +416,9 @@ LL | let _: Result = res.and_then(|_| Err(astronomers_pi)); | help: use `and` instead | -LL | let _: Result = res.and(Err(astronomers_pi)); - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: Result = res.and_then(|_| Err(astronomers_pi)); +LL + let _: Result = res.and(Err(astronomers_pi)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:219:35 @@ -393,8 +428,9 @@ LL | let _: Result = res.and_then(|_| Err(ext_str.some_field)) | help: use `and` instead | -LL | let _: Result = res.and(Err(ext_str.some_field)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: Result = res.and_then(|_| Err(ext_str.some_field)); +LL + let _: Result = res.and(Err(ext_str.some_field)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:222:35 @@ -404,8 +440,9 @@ LL | let _: Result = res.or_else(|_| Ok(2)); | help: use `or` instead | -LL | let _: Result = res.or(Ok(2)); - | ~~~~~~~~~ +LL - let _: Result = res.or_else(|_| Ok(2)); +LL + let _: Result = res.or(Ok(2)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:224:35 @@ -415,8 +452,9 @@ LL | let _: Result = res.or_else(|_| Ok(astronomers_pi)); | help: use `or` instead | -LL | let _: Result = res.or(Ok(astronomers_pi)); - | ~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: Result = res.or_else(|_| Ok(astronomers_pi)); +LL + let _: Result = res.or(Ok(astronomers_pi)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:226:35 @@ -426,8 +464,9 @@ LL | let _: Result = res.or_else(|_| Ok(ext_str.some_field)); | help: use `or` instead | -LL | let _: Result = res.or(Ok(ext_str.some_field)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: Result = res.or_else(|_| Ok(ext_str.some_field)); +LL + let _: Result = res.or(Ok(ext_str.some_field)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:228:35 @@ -440,8 +479,9 @@ LL | | or_else(|_| Ok(ext_str.some_field)); | help: use `or` instead | -LL | or(Ok(ext_str.some_field)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - or_else(|_| Ok(ext_str.some_field)); +LL + or(Ok(ext_str.some_field)); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:259:14 @@ -451,8 +491,9 @@ LL | let _x = false.then(|| i32::MAX + 1); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MAX + 1); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MAX + 1); +LL + let _x = false.then_some(i32::MAX + 1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:261:14 @@ -462,8 +503,9 @@ LL | let _x = false.then(|| i32::MAX * 2); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MAX * 2); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MAX * 2); +LL + let _x = false.then_some(i32::MAX * 2); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:263:14 @@ -473,8 +515,9 @@ LL | let _x = false.then(|| i32::MAX - 1); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MAX - 1); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MAX - 1); +LL + let _x = false.then_some(i32::MAX - 1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:265:14 @@ -484,8 +527,9 @@ LL | let _x = false.then(|| i32::MIN - 1); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MIN - 1); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MIN - 1); +LL + let _x = false.then_some(i32::MIN - 1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:267:14 @@ -495,8 +539,9 @@ LL | let _x = false.then(|| (1 + 2 * 3 - 2 / 3 + 9) << 2); | help: use `then_some` instead | -LL | let _x = false.then_some((1 + 2 * 3 - 2 / 3 + 9) << 2); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| (1 + 2 * 3 - 2 / 3 + 9) << 2); +LL + let _x = false.then_some((1 + 2 * 3 - 2 / 3 + 9) << 2); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:269:14 @@ -506,8 +551,9 @@ LL | let _x = false.then(|| 255u8 << 7); | help: use `then_some` instead | -LL | let _x = false.then_some(255u8 << 7); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 255u8 << 7); +LL + let _x = false.then_some(255u8 << 7); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:271:14 @@ -517,8 +563,9 @@ LL | let _x = false.then(|| 255u8 << 8); | help: use `then_some` instead | -LL | let _x = false.then_some(255u8 << 8); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 255u8 << 8); +LL + let _x = false.then_some(255u8 << 8); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:273:14 @@ -528,8 +575,9 @@ LL | let _x = false.then(|| 255u8 >> 8); | help: use `then_some` instead | -LL | let _x = false.then_some(255u8 >> 8); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 255u8 >> 8); +LL + let _x = false.then_some(255u8 >> 8); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:276:14 @@ -539,8 +587,9 @@ LL | let _x = false.then(|| i32::MAX + -1); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MAX + -1); - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MAX + -1); +LL + let _x = false.then_some(i32::MAX + -1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:278:14 @@ -550,8 +599,9 @@ LL | let _x = false.then(|| -i32::MAX); | help: use `then_some` instead | -LL | let _x = false.then_some(-i32::MAX); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| -i32::MAX); +LL + let _x = false.then_some(-i32::MAX); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:280:14 @@ -561,8 +611,9 @@ LL | let _x = false.then(|| -i32::MIN); | help: use `then_some` instead | -LL | let _x = false.then_some(-i32::MIN); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| -i32::MIN); +LL + let _x = false.then_some(-i32::MIN); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:283:14 @@ -572,8 +623,9 @@ LL | let _x = false.then(|| 255 >> -7); | help: use `then_some` instead | -LL | let _x = false.then_some(255 >> -7); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 255 >> -7); +LL + let _x = false.then_some(255 >> -7); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:285:14 @@ -583,8 +635,9 @@ LL | let _x = false.then(|| 255 << -1); | help: use `then_some` instead | -LL | let _x = false.then_some(255 << -1); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 255 << -1); +LL + let _x = false.then_some(255 << -1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:287:14 @@ -594,8 +647,9 @@ LL | let _x = false.then(|| 1 / 0); | help: use `then_some` instead | -LL | let _x = false.then_some(1 / 0); - | ~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 1 / 0); +LL + let _x = false.then_some(1 / 0); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:289:14 @@ -605,8 +659,9 @@ LL | let _x = false.then(|| x << -1); | help: use `then_some` instead | -LL | let _x = false.then_some(x << -1); - | ~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| x << -1); +LL + let _x = false.then_some(x << -1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:291:14 @@ -616,8 +671,9 @@ LL | let _x = false.then(|| x << 2); | help: use `then_some` instead | -LL | let _x = false.then_some(x << 2); - | ~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| x << 2); +LL + let _x = false.then_some(x << 2); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:301:14 @@ -627,8 +683,9 @@ LL | let _x = false.then(|| x / 0); | help: use `then_some` instead | -LL | let _x = false.then_some(x / 0); - | ~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| x / 0); +LL + let _x = false.then_some(x / 0); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:303:14 @@ -638,8 +695,9 @@ LL | let _x = false.then(|| x % 0); | help: use `then_some` instead | -LL | let _x = false.then_some(x % 0); - | ~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| x % 0); +LL + let _x = false.then_some(x % 0); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:306:14 @@ -649,8 +707,9 @@ LL | let _x = false.then(|| 1 / -1); | help: use `then_some` instead | -LL | let _x = false.then_some(1 / -1); - | ~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 1 / -1); +LL + let _x = false.then_some(1 / -1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:308:14 @@ -660,8 +719,9 @@ LL | let _x = false.then(|| i32::MIN / -1); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MIN / -1); - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MIN / -1); +LL + let _x = false.then_some(i32::MIN / -1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:311:14 @@ -671,8 +731,9 @@ LL | let _x = false.then(|| i32::MIN / 0); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MIN / 0); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MIN / 0); +LL + let _x = false.then_some(i32::MIN / 0); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:313:14 @@ -682,8 +743,9 @@ LL | let _x = false.then(|| 4 / 2); | help: use `then_some` instead | -LL | let _x = false.then_some(4 / 2); - | ~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 4 / 2); +LL + let _x = false.then_some(4 / 2); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:321:14 @@ -693,8 +755,9 @@ LL | let _x = false.then(|| f1 + f2); | help: use `then_some` instead | -LL | let _x = false.then_some(f1 + f2); - | ~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| f1 + f2); +LL + let _x = false.then_some(f1 + f2); + | error: aborting due to 63 previous errors diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.stderr b/tests/ui/unnecessary_lazy_eval_unfixable.stderr index 0a62b312f71c..5174acc1e9f9 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.stderr +++ b/tests/ui/unnecessary_lazy_eval_unfixable.stderr @@ -8,8 +8,9 @@ LL | let _ = Ok(1).unwrap_or_else(|()| 2); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_lazy_evaluations)]` help: use `unwrap_or` instead | -LL | let _ = Ok(1).unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = Ok(1).unwrap_or_else(|()| 2); +LL + let _ = Ok(1).unwrap_or(2); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval_unfixable.rs:19:13 @@ -19,8 +20,9 @@ LL | let _ = Ok(1).unwrap_or_else(|e::E| 2); | help: use `unwrap_or` instead | -LL | let _ = Ok(1).unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = Ok(1).unwrap_or_else(|e::E| 2); +LL + let _ = Ok(1).unwrap_or(2); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval_unfixable.rs:22:13 @@ -30,8 +32,9 @@ LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); | help: use `unwrap_or` instead | -LL | let _ = Ok(1).unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); +LL + let _ = Ok(1).unwrap_or(2); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval_unfixable.rs:32:13 @@ -41,8 +44,9 @@ LL | let _ = true.then(|| -> &[u8] { &[] }); | help: use `then_some` instead | -LL | let _ = true.then_some({ &[] }); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = true.then(|| -> &[u8] { &[] }); +LL + let _ = true.then_some({ &[] }); + | error: aborting due to 4 previous errors diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr index 7d6e096a1c93..cd90763263e9 100644 --- a/tests/ui/unnecessary_literal_unwrap.stderr +++ b/tests/ui/unnecessary_literal_unwrap.stderr @@ -62,8 +62,9 @@ LL | let _val = None::<()>.expect("this always happens"); | help: remove the `None` and `expect()` | -LL | let _val = panic!("this always happens"); - | ~~~~~~~ +LL - let _val = None::<()>.expect("this always happens"); +LL + let _val = panic!("this always happens"); + | error: used `unwrap_or_default()` on `None` value --> tests/ui/unnecessary_literal_unwrap.rs:28:24 @@ -133,8 +134,9 @@ LL | None::<()>.expect("this always happens"); | help: remove the `None` and `expect()` | -LL | panic!("this always happens"); - | ~~~~~~~ +LL - None::<()>.expect("this always happens"); +LL + panic!("this always happens"); + | error: used `unwrap_or_default()` on `None` value --> tests/ui/unnecessary_literal_unwrap.rs:43:5 @@ -222,8 +224,9 @@ LL | let _val = Ok::<_, ()>(1).unwrap_err(); | help: remove the `Ok` and `unwrap_err()` | -LL | let _val = panic!("{:?}", 1); - | ~~~~~~~~~~~~~~ ~ +LL - let _val = Ok::<_, ()>(1).unwrap_err(); +LL + let _val = panic!("{:?}", 1); + | error: used `expect_err()` on `Ok` value --> tests/ui/unnecessary_literal_unwrap.rs:62:16 @@ -233,8 +236,9 @@ LL | let _val = Ok::<_, ()>(1).expect_err("this always happens"); | help: remove the `Ok` and `expect_err()` | -LL | let _val = panic!("{1}: {:?}", 1, "this always happens"); - | ~~~~~~~~~~~~~~~~~~~ ~ +LL - let _val = Ok::<_, ()>(1).expect_err("this always happens"); +LL + let _val = panic!("{1}: {:?}", 1, "this always happens"); + | error: used `unwrap()` on `Ok` value --> tests/ui/unnecessary_literal_unwrap.rs:65:5 @@ -268,8 +272,9 @@ LL | Ok::<_, ()>(1).unwrap_err(); | help: remove the `Ok` and `unwrap_err()` | -LL | panic!("{:?}", 1); - | ~~~~~~~~~~~~~~ ~ +LL - Ok::<_, ()>(1).unwrap_err(); +LL + panic!("{:?}", 1); + | error: used `expect_err()` on `Ok` value --> tests/ui/unnecessary_literal_unwrap.rs:71:5 @@ -279,8 +284,9 @@ LL | Ok::<_, ()>(1).expect_err("this always happens"); | help: remove the `Ok` and `expect_err()` | -LL | panic!("{1}: {:?}", 1, "this always happens"); - | ~~~~~~~~~~~~~~~~~~~ ~ +LL - Ok::<_, ()>(1).expect_err("this always happens"); +LL + panic!("{1}: {:?}", 1, "this always happens"); + | error: used `unwrap_err()` on `Err` value --> tests/ui/unnecessary_literal_unwrap.rs:76:16 @@ -314,8 +320,9 @@ LL | let _val = Err::<(), _>(1).unwrap(); | help: remove the `Err` and `unwrap()` | -LL | let _val = panic!("{:?}", 1); - | ~~~~~~~~~~~~~~ ~ +LL - let _val = Err::<(), _>(1).unwrap(); +LL + let _val = panic!("{:?}", 1); + | error: used `expect()` on `Err` value --> tests/ui/unnecessary_literal_unwrap.rs:82:16 @@ -325,8 +332,9 @@ LL | let _val = Err::<(), _>(1).expect("this always happens"); | help: remove the `Err` and `expect()` | -LL | let _val = panic!("{1}: {:?}", 1, "this always happens"); - | ~~~~~~~~~~~~~~~~~~~ ~ +LL - let _val = Err::<(), _>(1).expect("this always happens"); +LL + let _val = panic!("{1}: {:?}", 1, "this always happens"); + | error: used `unwrap_err()` on `Err` value --> tests/ui/unnecessary_literal_unwrap.rs:85:5 @@ -360,8 +368,9 @@ LL | Err::<(), _>(1).unwrap(); | help: remove the `Err` and `unwrap()` | -LL | panic!("{:?}", 1); - | ~~~~~~~~~~~~~~ ~ +LL - Err::<(), _>(1).unwrap(); +LL + panic!("{:?}", 1); + | error: used `expect()` on `Err` value --> tests/ui/unnecessary_literal_unwrap.rs:91:5 @@ -371,8 +380,9 @@ LL | Err::<(), _>(1).expect("this always happens"); | help: remove the `Err` and `expect()` | -LL | panic!("{1}: {:?}", 1, "this always happens"); - | ~~~~~~~~~~~~~~~~~~~ ~ +LL - Err::<(), _>(1).expect("this always happens"); +LL + panic!("{1}: {:?}", 1, "this always happens"); + | error: used `unwrap_or()` on `Some` value --> tests/ui/unnecessary_literal_unwrap.rs:96:16 diff --git a/tests/ui/unnecessary_map_or.stderr b/tests/ui/unnecessary_map_or.stderr index fb469e1f472e..0f9466a6a6b3 100644 --- a/tests/ui/unnecessary_map_or.stderr +++ b/tests/ui/unnecessary_map_or.stderr @@ -8,8 +8,9 @@ LL | let _ = Some(5).map_or(false, |n| n == 5); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_map_or)]` help: use a standard comparison instead | -LL | let _ = Some(5) == Some(5); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = Some(5).map_or(false, |n| n == 5); +LL + let _ = Some(5) == Some(5); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:15:13 @@ -19,8 +20,9 @@ LL | let _ = Some(5).map_or(true, |n| n != 5); | help: use a standard comparison instead | -LL | let _ = Some(5) != Some(5); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = Some(5).map_or(true, |n| n != 5); +LL + let _ = Some(5) != Some(5); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:17:13 @@ -35,8 +37,13 @@ LL | | }); | help: use a standard comparison instead | -LL | let _ = Some(5) == Some(5); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = Some(5).map_or(false, |n| { +LL - +LL - let _ = 1; +LL - n == 5 +LL - }); +LL + let _ = Some(5) == Some(5); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:22:13 @@ -123,8 +130,9 @@ LL | let _ = Ok::(5).map_or(false, |n| n == 5); | help: use a standard comparison instead | -LL | let _ = Ok::(5) == Ok(5); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = Ok::(5).map_or(false, |n| n == 5); +LL + let _ = Ok::(5) == Ok(5); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:39:13 @@ -134,8 +142,9 @@ LL | let _ = Some(5).map_or(false, |n| n == 5).then(|| 1); | help: use a standard comparison instead | -LL | let _ = (Some(5) == Some(5)).then(|| 1); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _ = Some(5).map_or(false, |n| n == 5).then(|| 1); +LL + let _ = (Some(5) == Some(5)).then(|| 1); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:41:13 @@ -169,8 +178,9 @@ LL | let _ = !Some(5).map_or(false, |n| n == 5); | help: use a standard comparison instead | -LL | let _ = !(Some(5) == Some(5)); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _ = !Some(5).map_or(false, |n| n == 5); +LL + let _ = !(Some(5) == Some(5)); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:47:13 @@ -180,8 +190,9 @@ LL | let _ = Some(5).map_or(false, |n| n == 5) || false; | help: use a standard comparison instead | -LL | let _ = (Some(5) == Some(5)) || false; - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _ = Some(5).map_or(false, |n| n == 5) || false; +LL + let _ = (Some(5) == Some(5)) || false; + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:49:13 @@ -191,8 +202,9 @@ LL | let _ = Some(5).map_or(false, |n| n == 5) as usize; | help: use a standard comparison instead | -LL | let _ = (Some(5) == Some(5)) as usize; - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _ = Some(5).map_or(false, |n| n == 5) as usize; +LL + let _ = (Some(5) == Some(5)) as usize; + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:74:13 @@ -250,8 +262,9 @@ LL | let _ = r.map_or(false, |x| x == 8); | help: use a standard comparison instead | -LL | let _ = r == Ok(8); - | ~~~~~~~~~~ +LL - let _ = r.map_or(false, |x| x == 8); +LL + let _ = r == Ok(8); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:111:5 diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr index 53fd8bd44146..ba562f5a50be 100644 --- a/tests/ui/unnecessary_wraps.stderr +++ b/tests/ui/unnecessary_wraps.stderr @@ -13,8 +13,9 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::unnecessary_wraps)]` help: remove `Option` from the return type... | -LL | fn func1(a: bool, b: bool) -> i32 { - | ~~~ +LL - fn func1(a: bool, b: bool) -> Option { +LL + fn func1(a: bool, b: bool) -> i32 { + | help: ...and then change returning expressions | LL ~ return 42; @@ -40,8 +41,9 @@ LL | | } | help: remove `Option` from the return type... | -LL | fn func2(a: bool, b: bool) -> i32 { - | ~~~ +LL - fn func2(a: bool, b: bool) -> Option { +LL + fn func2(a: bool, b: bool) -> i32 { + | help: ...and then change returning expressions | LL ~ return 10; @@ -61,11 +63,13 @@ LL | | } | help: remove `Option` from the return type... | -LL | fn func5() -> i32 { - | ~~~ +LL - fn func5() -> Option { +LL + fn func5() -> i32 { + | help: ...and then change returning expressions | -LL | 1 +LL - Some(1) +LL + 1 | error: this function's return value is unnecessarily wrapped by `Result` @@ -80,11 +84,13 @@ LL | | } | help: remove `Result` from the return type... | -LL | fn func7() -> i32 { - | ~~~ +LL - fn func7() -> Result { +LL + fn func7() -> i32 { + | help: ...and then change returning expressions | -LL | 1 +LL - Ok(1) +LL + 1 | error: this function's return value is unnecessarily wrapped by `Option` @@ -99,11 +105,13 @@ LL | | } | help: remove `Option` from the return type... | -LL | fn func12() -> i32 { - | ~~~ +LL - fn func12() -> Option { +LL + fn func12() -> i32 { + | help: ...and then change returning expressions | -LL | 1 +LL - Some(1) +LL + 1 | error: this function's return value is unnecessary @@ -119,8 +127,9 @@ LL | | } | help: remove the return type... | -LL | fn issue_6640_1(a: bool, b: bool) -> () { - | ~~ +LL - fn issue_6640_1(a: bool, b: bool) -> Option<()> { +LL + fn issue_6640_1(a: bool, b: bool) -> () { + | help: ...and then remove returned values | LL ~ return ; @@ -145,8 +154,9 @@ LL | | } | help: remove the return type... | -LL | fn issue_6640_2(a: bool, b: bool) -> () { - | ~~ +LL - fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { +LL + fn issue_6640_2(a: bool, b: bool) -> () { + | help: ...and then remove returned values | LL ~ return ; diff --git a/tests/ui/unnested_or_patterns.stderr b/tests/ui/unnested_or_patterns.stderr index 3dfd34df4efc..ec5eb983c5a0 100644 --- a/tests/ui/unnested_or_patterns.stderr +++ b/tests/ui/unnested_or_patterns.stderr @@ -8,8 +8,9 @@ LL | if let box 0 | box 2 = Box::new(0) {} = help: to override `-D warnings` add `#[allow(clippy::unnested_or_patterns)]` help: nest the patterns | -LL | if let box (0 | 2) = Box::new(0) {} - | ~~~~~~~~~~~ +LL - if let box 0 | box 2 = Box::new(0) {} +LL + if let box (0 | 2) = Box::new(0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:18:12 @@ -19,8 +20,9 @@ LL | if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} | help: nest the patterns | -LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} +LL + if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:21:12 @@ -30,8 +32,9 @@ LL | if let Some(1) | C0 | Some(2) = None {} | help: nest the patterns | -LL | if let Some(1 | 2) | C0 = None {} - | ~~~~~~~~~~~~~~~~ +LL - if let Some(1) | C0 | Some(2) = None {} +LL + if let Some(1 | 2) | C0 = None {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:23:12 @@ -41,8 +44,9 @@ LL | if let &mut 0 | &mut 2 = &mut 0 {} | help: nest the patterns | -LL | if let &mut (0 | 2) = &mut 0 {} - | ~~~~~~~~~~~~ +LL - if let &mut 0 | &mut 2 = &mut 0 {} +LL + if let &mut (0 | 2) = &mut 0 {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:25:12 @@ -52,8 +56,9 @@ LL | if let x @ 0 | x @ 2 = 0 {} | help: nest the patterns | -LL | if let x @ (0 | 2) = 0 {} - | ~~~~~~~~~~~ +LL - if let x @ 0 | x @ 2 = 0 {} +LL + if let x @ (0 | 2) = 0 {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:27:12 @@ -63,8 +68,9 @@ LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} | help: nest the patterns | -LL | if let (0, 1 | 2 | 3) = (0, 0) {} - | ~~~~~~~~~~~~~~ +LL - if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} +LL + if let (0, 1 | 2 | 3) = (0, 0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:29:12 @@ -74,8 +80,9 @@ LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} | help: nest the patterns | -LL | if let (1 | 2 | 3, 0) = (0, 0) {} - | ~~~~~~~~~~~~~~ +LL - if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} +LL + if let (1 | 2 | 3, 0) = (0, 0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:31:12 @@ -85,8 +92,9 @@ LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} | help: nest the patterns | -LL | if let (x, ..) | (x, 1 | 2) = (0, 1) {} - | ~~~~~~~~~~~~~~~~~~~~ +LL - if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} +LL + if let (x, ..) | (x, 1 | 2) = (0, 1) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:33:12 @@ -96,8 +104,9 @@ LL | if let [0] | [1] = [0] {} | help: nest the patterns | -LL | if let [0 | 1] = [0] {} - | ~~~~~~~ +LL - if let [0] | [1] = [0] {} +LL + if let [0 | 1] = [0] {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:35:12 @@ -107,8 +116,9 @@ LL | if let [x, 0] | [x, 1] = [0, 1] {} | help: nest the patterns | -LL | if let [x, 0 | 1] = [0, 1] {} - | ~~~~~~~~~~ +LL - if let [x, 0] | [x, 1] = [0, 1] {} +LL + if let [x, 0 | 1] = [0, 1] {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:37:12 @@ -118,8 +128,9 @@ LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} | help: nest the patterns | -LL | if let [x, 0 | 1 | 2] = [0, 1] {} - | ~~~~~~~~~~~~~~ +LL - if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} +LL + if let [x, 0 | 1 | 2] = [0, 1] {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:39:12 @@ -129,8 +140,9 @@ LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} | help: nest the patterns | -LL | if let [x, ..] | [x, 1 | 2] = [0, 1] {} - | ~~~~~~~~~~~~~~~~~~~~ +LL - if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} +LL + if let [x, ..] | [x, 1 | 2] = [0, 1] {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:42:12 @@ -140,8 +152,9 @@ LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {} | help: nest the patterns | -LL | if let TS(0 | 1, x) = TS(0, 0) {} - | ~~~~~~~~~~~~ +LL - if let TS(0, x) | TS(1, x) = TS(0, 0) {} +LL + if let TS(0 | 1, x) = TS(0, 0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:44:12 @@ -151,8 +164,9 @@ LL | if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} | help: nest the patterns | -LL | if let TS(1 | 2 | 3, 0) = TS(0, 0) {} - | ~~~~~~~~~~~~~~~~ +LL - if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} +LL + if let TS(1 | 2 | 3, 0) = TS(0, 0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:46:12 @@ -162,8 +176,9 @@ LL | if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} | help: nest the patterns | -LL | if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} +LL + if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:52:12 @@ -173,8 +188,9 @@ LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} | help: nest the patterns | -LL | if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {} - | ~~~~~~~~~~~~~~~~~ +LL - if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} +LL + if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:64:12 @@ -184,8 +200,9 @@ LL | if let [1] | [53] = [0] {} | help: nest the patterns | -LL | if let [1 | 53] = [0] {} - | ~~~~~~~~ +LL - if let [1] | [53] = [0] {} +LL + if let [1 | 53] = [0] {} + | error: aborting due to 17 previous errors diff --git a/tests/ui/unnested_or_patterns2.stderr b/tests/ui/unnested_or_patterns2.stderr index 040bb46b0847..3fc8fa174c93 100644 --- a/tests/ui/unnested_or_patterns2.stderr +++ b/tests/ui/unnested_or_patterns2.stderr @@ -8,8 +8,9 @@ LL | if let Some(Some(0)) | Some(Some(1)) = None {} = help: to override `-D warnings` add `#[allow(clippy::unnested_or_patterns)]` help: nest the patterns | -LL | if let Some(Some(0 | 1)) = None {} - | ~~~~~~~~~~~~~~~~~ +LL - if let Some(Some(0)) | Some(Some(1)) = None {} +LL + if let Some(Some(0 | 1)) = None {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:14:12 @@ -19,8 +20,9 @@ LL | if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} | help: nest the patterns | -LL | if let Some(Some(0 | 1 | 2)) = None {} - | ~~~~~~~~~~~~~~~~~~~~~ +LL - if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} +LL + if let Some(Some(0 | 1 | 2)) = None {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:16:12 @@ -30,8 +32,9 @@ LL | if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} | help: nest the patterns | -LL | if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} +LL + if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:18:12 @@ -41,8 +44,9 @@ LL | if let Some(Some(0) | Some(1 | 2)) = None {} | help: nest the patterns | -LL | if let Some(Some(0 | 1 | 2)) = None {} - | ~~~~~~~~~~~~~~~~~~~~~ +LL - if let Some(Some(0) | Some(1 | 2)) = None {} +LL + if let Some(Some(0 | 1 | 2)) = None {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:20:12 @@ -52,8 +56,9 @@ LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {} | help: nest the patterns | -LL | if let ((0 | 1 | 2,),) = ((0,),) {} - | ~~~~~~~~~~~~~~~ +LL - if let ((0,),) | ((1,) | (2,),) = ((0,),) {} +LL + if let ((0 | 1 | 2,),) = ((0,),) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:22:12 @@ -63,8 +68,9 @@ LL | if let 0 | (1 | 2) = 0 {} | help: nest the patterns | -LL | if let 0 | 1 | 2 = 0 {} - | ~~~~~~~~~ +LL - if let 0 | (1 | 2) = 0 {} +LL + if let 0 | 1 | 2 = 0 {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:24:12 @@ -74,8 +80,9 @@ LL | if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} | help: nest the patterns | -LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} +LL + if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:26:12 @@ -85,8 +92,9 @@ LL | if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} | help: nest the patterns | -LL | if let box box (0 | 2 | 4) = Box::new(Box::new(0)) {} - | ~~~~~~~~~~~~~~~~~~~ +LL - if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} +LL + if let box box (0 | 2 | 4) = Box::new(Box::new(0)) {} + | error: aborting due to 8 previous errors diff --git a/tests/ui/unused_enumerate_index.stderr b/tests/ui/unused_enumerate_index.stderr index 9ea65631a5f2..14d1d20a66e4 100644 --- a/tests/ui/unused_enumerate_index.stderr +++ b/tests/ui/unused_enumerate_index.stderr @@ -8,8 +8,9 @@ LL | for (_, x) in v.iter().enumerate() { = help: to override `-D warnings` add `#[allow(clippy::unused_enumerate_index)]` help: remove the `.enumerate()` call | -LL | for x in v.iter() { - | ~ ~~~~~~~~ +LL - for (_, x) in v.iter().enumerate() { +LL + for x in v.iter() { + | error: you seem to use `.enumerate()` and immediately discard the index --> tests/ui/unused_enumerate_index.rs:60:19 @@ -19,8 +20,9 @@ LL | for (_, x) in dummy.enumerate() { | help: remove the `.enumerate()` call | -LL | for x in dummy { - | ~ ~~~~~ +LL - for (_, x) in dummy.enumerate() { +LL + for x in dummy { + | error: you seem to use `.enumerate()` and immediately discard the index --> tests/ui/unused_enumerate_index.rs:65:39 diff --git a/tests/ui/unused_format_specs.stderr b/tests/ui/unused_format_specs.stderr index 704e4987ec4a..b07058fd568d 100644 --- a/tests/ui/unused_format_specs.stderr +++ b/tests/ui/unused_format_specs.stderr @@ -8,8 +8,9 @@ LL | println!("{:5}.", format_args!("")); = help: to override `-D warnings` add `#[allow(clippy::unused_format_specs)]` help: for the width to apply consider using `format!()` | -LL | println!("{:5}.", format!("")); - | ~~~~~~ +LL - println!("{:5}.", format_args!("")); +LL + println!("{:5}.", format!("")); + | help: if the current behavior is intentional, remove the format specifiers | LL - println!("{:5}.", format_args!("")); @@ -24,8 +25,9 @@ LL | println!("{:.3}", format_args!("abcde")); | help: for the precision to apply consider using `format!()` | -LL | println!("{:.3}", format!("abcde")); - | ~~~~~~ +LL - println!("{:.3}", format_args!("abcde")); +LL + println!("{:.3}", format!("abcde")); + | help: if the current behavior is intentional, remove the format specifiers | LL - println!("{:.3}", format_args!("abcde")); @@ -66,8 +68,9 @@ LL | usr_println!(true, "{:5}.", format_args!("")); | help: for the width to apply consider using `format!()` | -LL | usr_println!(true, "{:5}.", format!("")); - | ~~~~~~ +LL - usr_println!(true, "{:5}.", format_args!("")); +LL + usr_println!(true, "{:5}.", format!("")); + | help: if the current behavior is intentional, remove the format specifiers | LL - usr_println!(true, "{:5}.", format_args!("")); @@ -82,8 +85,9 @@ LL | usr_println!(true, "{:.3}", format_args!("abcde")); | help: for the precision to apply consider using `format!()` | -LL | usr_println!(true, "{:.3}", format!("abcde")); - | ~~~~~~ +LL - usr_println!(true, "{:.3}", format_args!("abcde")); +LL + usr_println!(true, "{:.3}", format!("abcde")); + | help: if the current behavior is intentional, remove the format specifiers | LL - usr_println!(true, "{:.3}", format_args!("abcde")); diff --git a/tests/ui/unused_result_ok.stderr b/tests/ui/unused_result_ok.stderr index e6fbd8666514..0e134ba3ccba 100644 --- a/tests/ui/unused_result_ok.stderr +++ b/tests/ui/unused_result_ok.stderr @@ -8,8 +8,9 @@ LL | x.parse::().ok(); = help: to override `-D warnings` add `#[allow(clippy::unused_result_ok)]` help: consider using `let _ =` and removing the call to `.ok()` instead | -LL | let _ = x.parse::(); - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - x.parse::().ok(); +LL + let _ = x.parse::(); + | error: ignoring a result with `.ok()` is misleading --> tests/ui/unused_result_ok.rs:19:5 @@ -19,8 +20,9 @@ LL | x . parse::() . ok (); | help: consider using `let _ =` and removing the call to `.ok()` instead | -LL | let _ = x . parse::(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - x . parse::() . ok (); +LL + let _ = x . parse::(); + | error: ignoring a result with `.ok()` is misleading --> tests/ui/unused_result_ok.rs:37:5 @@ -30,8 +32,9 @@ LL | v!().ok(); | help: consider using `let _ =` and removing the call to `.ok()` instead | -LL | let _ = v!(); - | ~~~~~~~~~~~~ +LL - v!().ok(); +LL + let _ = v!(); + | error: ignoring a result with `.ok()` is misleading --> tests/ui/unused_result_ok.rs:31:9 @@ -45,8 +48,9 @@ LL | w!(); = note: this error originates in the macro `w` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider using `let _ =` and removing the call to `.ok()` instead | -LL | let _ = Ok::<(), ()>(()); - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - Ok::<(), ()>(()).ok(); +LL + let _ = Ok::<(), ()>(()); + | error: aborting due to 4 previous errors