diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 4d6afd2fe0d08..b118c0eaed4f3 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -260,9 +260,9 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_unop(&mut self, u: UnOp) -> hir::UnOp { match u { - UnOp::Deref => hir::UnOp::UnDeref, - UnOp::Not => hir::UnOp::UnNot, - UnOp::Neg => hir::UnOp::UnNeg, + UnOp::Deref => hir::UnOp::Deref, + UnOp::Not => hir::UnOp::Not, + UnOp::Neg => hir::UnOp::Neg, } } diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index 849ef18fb90cb..d01c162b0c864 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -287,6 +287,7 @@ E0539: include_str!("./error_codes/E0539.md"), E0541: include_str!("./error_codes/E0541.md"), E0542: include_str!("./error_codes/E0542.md"), E0546: include_str!("./error_codes/E0546.md"), +E0547: include_str!("./error_codes/E0547.md"), E0550: include_str!("./error_codes/E0550.md"), E0551: include_str!("./error_codes/E0551.md"), E0552: include_str!("./error_codes/E0552.md"), @@ -606,7 +607,6 @@ E0781: include_str!("./error_codes/E0781.md"), E0543, // missing 'reason' E0544, // multiple stability levels E0545, // incorrect 'issue' - E0547, // missing 'issue' // E0548, // replaced with a generic attribute input check // rustc_deprecated attribute must be paired with either stable or unstable // attribute diff --git a/compiler/rustc_error_codes/src/error_codes/E0547.md b/compiler/rustc_error_codes/src/error_codes/E0547.md new file mode 100644 index 0000000000000..1aa4b35424884 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0547.md @@ -0,0 +1,37 @@ +The `issue` value is missing in a stability attribute. + +Erroneous code example: + +```compile_fail,E0547 +#![feature(staged_api)] +#![stable(since = "1.0.0", feature = "test")] + +#[unstable(feature = "_unstable_fn")] // invalid +fn _unstable_fn() {} + +#[rustc_const_unstable(feature = "_unstable_const_fn")] // invalid +fn _unstable_const_fn() {} +``` + +To fix this issue, you need to provide the `issue` field. Example: + +``` +#![feature(staged_api)] +#![stable(since = "1.0.0", feature = "test")] + +#[unstable(feature = "_unstable_fn", issue = "none")] // ok! +fn _unstable_fn() {} + +#[rustc_const_unstable( + feature = "_unstable_const_fn", + issue = "none" +)] // ok! +fn _unstable_const_fn() {} +``` + +See the [How Rust is Made and “Nightly Rust”][how-rust-made-nightly] appendix +of the Book and the [Stability attributes][stability-attributes] section of the +Rustc Dev Guide for more details. + +[how-rust-made-nightly]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html +[stability-attributes]: https://rustc-dev-guide.rust-lang.org/stability.html diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 49d9e3b60b492..9609510d0af6b 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1112,25 +1112,25 @@ pub type BinOp = Spanned; #[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)] pub enum UnOp { /// The `*` operator (deferencing). - UnDeref, + Deref, /// The `!` operator (logical negation). - UnNot, + Not, /// The `-` operator (negation). - UnNeg, + Neg, } impl UnOp { pub fn as_str(self) -> &'static str { match self { - Self::UnDeref => "*", - Self::UnNot => "!", - Self::UnNeg => "-", + Self::Deref => "*", + Self::Not => "!", + Self::Neg => "-", } } /// Returns `true` if the unary operator takes its argument by value. pub fn is_by_value(self) -> bool { - matches!(self, Self::UnNeg | Self::UnNot) + matches!(self, Self::Neg | Self::Not) } } @@ -1477,7 +1477,7 @@ impl Expr<'_> { // https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md#type-ascription-and-temporaries ExprKind::Type(ref e, _) => e.is_place_expr(allow_projections_from), - ExprKind::Unary(UnOp::UnDeref, _) => true, + ExprKind::Unary(UnOp::Deref, _) => true, ExprKind::Field(ref base, _) | ExprKind::Index(ref base, _) => { allow_projections_from(base) || base.is_place_expr(allow_projections_from) diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 1e879d2937060..784b36c2837b7 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -472,7 +472,7 @@ fn lint_literal<'tcx>( impl<'tcx> LateLintPass<'tcx> for TypeLimits { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx hir::Expr<'tcx>) { match e.kind { - hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => { + hir::ExprKind::Unary(hir::UnOp::Neg, ref expr) => { // propagate negation, if the negation itself isn't negated if self.negated_expr_id != Some(e.hir_id) { self.negated_expr_id = Some(expr.hir_id); diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 041c040f0b7e2..ed953b981130a 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -55,7 +55,7 @@ impl<'tcx> Const<'tcx> { let lit_input = match expr.kind { hir::ExprKind::Lit(ref lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }), - hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => match expr.kind { + hir::ExprKind::Unary(hir::UnOp::Neg, ref expr) => match expr.kind { hir::ExprKind::Lit(ref lit) => { Some(LitToConstInput { lit: &lit.node, ty, neg: true }) } diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs index 333ac0738d45b..0467bf76afecc 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs @@ -376,15 +376,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { opt_assignment_rhs_span.and_then(|span| span.desugaring_kind()); match opt_desugaring_kind { // on for loops, RHS points to the iterator part - Some(DesugaringKind::ForLoop(_)) => Some(( - false, - opt_assignment_rhs_span.unwrap(), - format!( - "this iterator yields `{SIGIL}` {DESC}s", - SIGIL = pointer_sigil, - DESC = pointer_desc - ), - )), + Some(DesugaringKind::ForLoop(_)) => { + self.suggest_similar_mut_method_for_for_loop(&mut err); + Some(( + false, + opt_assignment_rhs_span.unwrap(), + format!( + "this iterator yields `{SIGIL}` {DESC}s", + SIGIL = pointer_sigil, + DESC = pointer_desc + ), + )) + } // don't create labels for compiler-generated spans Some(_) => None, None => { @@ -537,6 +540,79 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { ); } + // Attempt to search similar mutable assosiated items for suggestion. + // In the future, attempt in all path but initially for RHS of for_loop + fn suggest_similar_mut_method_for_for_loop(&self, err: &mut DiagnosticBuilder<'_>) { + let hir = self.infcx.tcx.hir(); + let node = hir.item(self.mir_hir_id()); + use hir::{ + Expr, + ExprKind::{Block, Call, DropTemps, Match, MethodCall}, + }; + if let hir::ItemKind::Fn(_, _, body_id) = node.kind { + if let Block( + hir::Block { + expr: + Some(Expr { + kind: + DropTemps(Expr { + kind: + Match( + Expr { + kind: + Call( + _, + [Expr { + kind: MethodCall(path_segment, ..), + hir_id, + .. + }, ..], + ), + .. + }, + .., + ), + .. + }), + .. + }), + .. + }, + _, + ) = hir.body(body_id).value.kind + { + let opt_suggestions = path_segment + .hir_id + .map(|path_hir_id| self.infcx.tcx.typeck(path_hir_id.owner)) + .and_then(|typeck| typeck.type_dependent_def_id(*hir_id)) + .and_then(|def_id| self.infcx.tcx.impl_of_method(def_id)) + .map(|def_id| self.infcx.tcx.associated_items(def_id)) + .map(|assoc_items| { + assoc_items + .in_definition_order() + .map(|assoc_item_def| assoc_item_def.ident) + .filter(|&ident| { + let original_method_ident = path_segment.ident; + original_method_ident != ident + && ident + .as_str() + .starts_with(&original_method_ident.name.to_string()) + }) + .map(|ident| format!("{}()", ident)) + }); + + if let Some(suggestions) = opt_suggestions { + err.span_suggestions( + path_segment.ident.span, + &format!("use mutable method"), + suggestions, + Applicability::MaybeIncorrect, + ); + } + } + }; + } + /// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected. fn expected_fn_found_fn_mut_call(&self, err: &mut DiagnosticBuilder<'_>, sp: Span, act: &str) { err.span_label(sp, format!("cannot {}", act)); diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 2962cbe8157f6..620ce360e7d91 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -299,7 +299,7 @@ fn make_mirror_unadjusted<'a, 'tcx>( } } - hir::ExprKind::Unary(hir::UnOp::UnDeref, ref arg) => { + hir::ExprKind::Unary(hir::UnOp::Deref, ref arg) => { if cx.typeck_results().is_method_call(expr) { overloaded_place(cx, expr, expr_ty, None, vec![arg.to_ref()], expr.span) } else { @@ -307,7 +307,7 @@ fn make_mirror_unadjusted<'a, 'tcx>( } } - hir::ExprKind::Unary(hir::UnOp::UnNot, ref arg) => { + hir::ExprKind::Unary(hir::UnOp::Not, ref arg) => { if cx.typeck_results().is_method_call(expr) { overloaded_operator(cx, expr, vec![arg.to_ref()]) } else { @@ -315,7 +315,7 @@ fn make_mirror_unadjusted<'a, 'tcx>( } } - hir::ExprKind::Unary(hir::UnOp::UnNeg, ref arg) => { + hir::ExprKind::Unary(hir::UnOp::Neg, ref arg) => { if cx.typeck_results().is_method_call(expr) { overloaded_operator(cx, expr, vec![arg.to_ref()]) } else if let hir::ExprKind::Lit(ref lit) = arg.kind { diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 7186e26be800e..6e29e60b3034d 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -866,7 +866,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { return *self.const_to_pat(value, expr.hir_id, expr.span, false).kind; } hir::ExprKind::Lit(ref lit) => (lit, false), - hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => { + hir::ExprKind::Unary(hir::UnOp::Neg, ref expr) => { let lit = match expr.kind { hir::ExprKind::Lit(ref lit) => lit, _ => span_bug!(expr.span, "not a literal: {:?}", expr), diff --git a/compiler/rustc_passes/src/region.rs b/compiler/rustc_passes/src/region.rs index 64356f73f6c65..b532021bed2e9 100644 --- a/compiler/rustc_passes/src/region.rs +++ b/compiler/rustc_passes/src/region.rs @@ -664,7 +664,7 @@ fn resolve_local<'tcx>( match expr.kind { hir::ExprKind::AddrOf(_, _, ref subexpr) - | hir::ExprKind::Unary(hir::UnOp::UnDeref, ref subexpr) + | hir::ExprKind::Unary(hir::UnOp::Deref, ref subexpr) | hir::ExprKind::Field(ref subexpr, _) | hir::ExprKind::Index(ref subexpr, _) => { expr = &subexpr; diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index 5f27355f0bab1..114fe969edd8d 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -1505,6 +1505,9 @@ fn async_opaque_type_cycle_error(tcx: TyCtxt<'tcx>, span: Span) { struct_span_err!(tcx.sess, span, E0733, "recursion in an `async fn` requires boxing") .span_label(span, "recursive `async fn`") .note("a recursive `async fn` must be rewritten to return a boxed `dyn Future`") + .note( + "consider using the `async_recursion` crate: https://crates.io/crates/async_recursion", + ) .emit(); } diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index 3c9c683f4b0cb..8d2004a543b7b 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -773,7 +773,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let hir::ExprKind::Lit(lit) = &expr.kind { lit.node.is_suffixed() } else { false } }; let is_negative_int = - |expr: &hir::Expr<'_>| matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::UnNeg, ..)); + |expr: &hir::Expr<'_>| matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::Neg, ..)); let is_uint = |ty: Ty<'_>| matches!(ty.kind(), ty::Uint(..)); let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id); diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 9692b0524e7ec..fa09c26c800ae 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -168,7 +168,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // without the final expr (e.g. `try { return; }`). We don't want to generate an // unreachable_code lint for it since warnings for autogenerated code are confusing. let is_try_block_generated_unit_expr = match expr.kind { - ExprKind::Call(_, ref args) if expr.span.is_desugaring(DesugaringKind::TryBlock) => { + ExprKind::Call(_, args) if expr.span.is_desugaring(DesugaringKind::TryBlock) => { args.len() == 1 && args[0].span.is_desugaring(DesugaringKind::TryBlock) } @@ -193,9 +193,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // diverging expression (e.g. it arose from desugaring of `try { return }`), // we skip issuing a warning because it is autogenerated code. ExprKind::Call(..) if expr.span.is_desugaring(DesugaringKind::TryBlock) => {} - ExprKind::Call(ref callee, _) => { - self.warn_if_unreachable(expr.hir_id, callee.span, "call") - } + ExprKind::Call(callee, _) => self.warn_if_unreachable(expr.hir_id, callee.span, "call"), ExprKind::MethodCall(_, ref span, _, _) => { self.warn_if_unreachable(expr.hir_id, *span, "call") } @@ -231,15 +229,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let tcx = self.tcx; match expr.kind { - ExprKind::Box(ref subexpr) => self.check_expr_box(subexpr, expected), + ExprKind::Box(subexpr) => self.check_expr_box(subexpr, expected), ExprKind::Lit(ref lit) => self.check_lit(&lit, expected), - ExprKind::Binary(op, ref lhs, ref rhs) => self.check_binop(expr, op, lhs, rhs), - ExprKind::Assign(ref lhs, ref rhs, ref span) => { + ExprKind::Binary(op, lhs, rhs) => self.check_binop(expr, op, lhs, rhs), + ExprKind::Assign(lhs, rhs, ref span) => { self.check_expr_assign(expr, expected, lhs, rhs, span) } - ExprKind::AssignOp(op, ref lhs, ref rhs) => self.check_binop_assign(expr, op, lhs, rhs), - ExprKind::Unary(unop, ref oprnd) => self.check_expr_unary(unop, oprnd, expected, expr), - ExprKind::AddrOf(kind, mutbl, ref oprnd) => { + ExprKind::AssignOp(op, lhs, rhs) => self.check_binop_assign(expr, op, lhs, rhs), + ExprKind::Unary(unop, oprnd) => self.check_expr_unary(unop, oprnd, expected, expr), + ExprKind::AddrOf(kind, mutbl, oprnd) => { self.check_expr_addr_of(kind, mutbl, oprnd, expected, expr) } ExprKind::Path(QPath::LangItem(lang_item, _)) => { @@ -247,7 +245,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } ExprKind::Path(ref qpath) => self.check_expr_path(qpath, expr), ExprKind::InlineAsm(asm) => self.check_expr_asm(asm), - ExprKind::LlvmInlineAsm(ref asm) => { + ExprKind::LlvmInlineAsm(asm) => { for expr in asm.outputs_exprs.iter().chain(asm.inputs_exprs.iter()) { self.check_expr(expr); } @@ -265,22 +263,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } ExprKind::Ret(ref expr_opt) => self.check_expr_return(expr_opt.as_deref(), expr), - ExprKind::Loop(ref body, _, source, _) => { + ExprKind::Loop(body, _, source, _) => { self.check_expr_loop(body, source, expected, expr) } - ExprKind::Match(ref discrim, ref arms, match_src) => { + ExprKind::Match(discrim, arms, match_src) => { self.check_match(expr, &discrim, arms, expected, match_src) } - ExprKind::Closure(capture, ref decl, body_id, _, gen) => { + ExprKind::Closure(capture, decl, body_id, _, gen) => { self.check_expr_closure(expr, capture, &decl, body_id, gen, expected) } - ExprKind::Block(ref body, _) => self.check_block_with_expected(&body, expected), - ExprKind::Call(ref callee, ref args) => self.check_call(expr, &callee, args, expected), - ExprKind::MethodCall(ref segment, span, ref args, _) => { + ExprKind::Block(body, _) => self.check_block_with_expected(&body, expected), + ExprKind::Call(callee, args) => self.check_call(expr, &callee, args, expected), + ExprKind::MethodCall(segment, span, args, _) => { self.check_method_call(expr, segment, span, args, expected) } - ExprKind::Cast(ref e, ref t) => self.check_expr_cast(e, t, expr), - ExprKind::Type(ref e, ref t) => { + ExprKind::Cast(e, t) => self.check_expr_cast(e, t, expr), + ExprKind::Type(e, t) => { let ty = self.to_ty_saving_user_provided_ty(&t); self.check_expr_eq_type(&e, ty); ty @@ -288,19 +286,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ExprKind::If(cond, then_expr, opt_else_expr) => { self.check_then_else(cond, then_expr, opt_else_expr, expr.span, expected) } - ExprKind::DropTemps(ref e) => self.check_expr_with_expectation(e, expected), - ExprKind::Array(ref args) => self.check_expr_array(args, expected, expr), + ExprKind::DropTemps(e) => self.check_expr_with_expectation(e, expected), + ExprKind::Array(args) => self.check_expr_array(args, expected, expr), ExprKind::ConstBlock(ref anon_const) => self.to_const(anon_const).ty, - ExprKind::Repeat(ref element, ref count) => { + ExprKind::Repeat(element, ref count) => { self.check_expr_repeat(element, count, expected, expr) } - ExprKind::Tup(ref elts) => self.check_expr_tuple(elts, expected, expr), - ExprKind::Struct(ref qpath, fields, ref base_expr) => { + ExprKind::Tup(elts) => self.check_expr_tuple(elts, expected, expr), + ExprKind::Struct(qpath, fields, ref base_expr) => { self.check_expr_struct(expr, expected, qpath, fields, base_expr) } - ExprKind::Field(ref base, field) => self.check_field(expr, &base, field), - ExprKind::Index(ref base, ref idx) => self.check_expr_index(base, idx, expr), - ExprKind::Yield(ref value, ref src) => self.check_expr_yield(value, expr, src), + ExprKind::Field(base, field) => self.check_field(expr, &base, field), + ExprKind::Index(base, idx) => self.check_expr_index(base, idx, expr), + ExprKind::Yield(value, ref src) => self.check_expr_yield(value, expr, src), hir::ExprKind::Err => tcx.ty_error(), } } @@ -323,15 +321,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> Ty<'tcx> { let tcx = self.tcx; let expected_inner = match unop { - hir::UnOp::UnNot | hir::UnOp::UnNeg => expected, - hir::UnOp::UnDeref => NoExpectation, + hir::UnOp::Not | hir::UnOp::Neg => expected, + hir::UnOp::Deref => NoExpectation, }; let mut oprnd_t = self.check_expr_with_expectation(&oprnd, expected_inner); if !oprnd_t.references_error() { oprnd_t = self.structurally_resolved_type(expr.span, oprnd_t); match unop { - hir::UnOp::UnDeref => { + hir::UnOp::Deref => { if let Some(ty) = self.lookup_derefing(expr, oprnd, oprnd_t) { oprnd_t = ty; } else { @@ -353,14 +351,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { oprnd_t = tcx.ty_error(); } } - hir::UnOp::UnNot => { + hir::UnOp::Not => { let result = self.check_user_unop(expr, oprnd_t, unop); // If it's builtin, we can reuse the type, this helps inference. if !(oprnd_t.is_integral() || *oprnd_t.kind() == ty::Bool) { oprnd_t = result; } } - hir::UnOp::UnNeg => { + hir::UnOp::Neg => { let result = self.check_user_unop(expr, oprnd_t, unop); // If it's builtin, we can reuse the type, this helps inference. if !oprnd_t.is_numeric() { @@ -541,7 +539,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let tcx = self.tcx; if let Ok(target_id) = destination.target_id { let (e_ty, cause); - if let Some(ref e) = expr_opt { + if let Some(e) = expr_opt { // If this is a break with a value, we need to type-check // the expression. Get an expected type from the loop context. let opt_coerce_to = { @@ -650,12 +648,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // We still need to assign a type to the inner expression to // prevent the ICE in #43162. - if let Some(ref e) = expr_opt { + if let Some(e) = expr_opt { self.check_expr_with_hint(e, err); // ... except when we try to 'break rust;'. // ICE this expression in particular (see #43162). - if let ExprKind::Path(QPath::Resolved(_, ref path)) = e.kind { + if let ExprKind::Path(QPath::Resolved(_, path)) = e.kind { if path.segments.len() == 1 && path.segments[0].ident.name == sym::rust { fatally_break_rust(self.tcx.sess); } @@ -674,7 +672,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> Ty<'tcx> { if self.ret_coercion.is_none() { self.tcx.sess.emit_err(ReturnStmtOutsideOfFnBody { span: expr.span }); - } else if let Some(ref e) = expr_opt { + } else if let Some(e) = expr_opt { if self.ret_coercion_span.get().is_none() { self.ret_coercion_span.set(Some(e.span)); } @@ -1133,13 +1131,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let flds = expected.only_has_type(self).and_then(|ty| { let ty = self.resolve_vars_with_obligations(ty); match ty.kind() { - ty::Tuple(ref flds) => Some(&flds[..]), + ty::Tuple(flds) => Some(&flds[..]), _ => None, } }); let elt_ts_iter = elts.iter().enumerate().map(|(i, e)| match flds { - Some(ref fs) if i < fs.len() => { + Some(fs) if i < fs.len() => { let ety = fs[i].expect_ty(); self.check_expr_coercable_to_type(&e, ety, None); ety @@ -1328,7 +1326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { for field in fields { self.check_expr(&field.expr); } - if let Some(ref base) = *base_expr { + if let Some(base) = *base_expr { self.check_expr(&base); } } @@ -1488,7 +1486,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }, _ => { // prevent all specified fields from being suggested - let skip_fields = skip_fields.iter().map(|ref x| x.ident.name); + let skip_fields = skip_fields.iter().map(|x| x.ident.name); if let Some(field_name) = Self::suggest_field_name(variant, field.ident.name, skip_fields.collect()) { @@ -1617,7 +1615,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { private_candidate = Some((base_def.did, field_ty)); } } - ty::Tuple(ref tys) => { + ty::Tuple(tys) => { let fstr = field.as_str(); if let Ok(index) = fstr.parse::() { if fstr == index.to_string() { diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index 9ab056c0d74b3..567cb1a90d0d9 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -681,7 +681,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { format!("cannot apply unary operator `{}`", op.as_str()), ); match actual.kind() { - Uint(_) if op == hir::UnOp::UnNeg => { + Uint(_) if op == hir::UnOp::Neg => { err.note("unsigned values cannot be negated"); if let hir::ExprKind::Unary( @@ -711,9 +711,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Ref(_, ref lty, _) if *lty.kind() == Str => {} _ => { let missing_trait = match op { - hir::UnOp::UnNeg => "std::ops::Neg", - hir::UnOp::UnNot => "std::ops::Not", - hir::UnOp::UnDeref => "std::ops::UnDerf", + hir::UnOp::Neg => "std::ops::Neg", + hir::UnOp::Not => "std::ops::Not", + hir::UnOp::Deref => "std::ops::UnDerf", }; suggest_impl_missing(&mut err, operand_ty, &missing_trait); } @@ -782,9 +782,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span_bug!(span, "&& and || are not overloadable") } } - } else if let Op::Unary(hir::UnOp::UnNot, _) = op { + } else if let Op::Unary(hir::UnOp::Not, _) = op { (sym::not, lang.not_trait()) - } else if let Op::Unary(hir::UnOp::UnNeg, _) = op { + } else if let Op::Unary(hir::UnOp::Neg, _) = op { (sym::neg, lang.neg_trait()) } else { bug!("lookup_op_method: op not supported: {:?}", op) diff --git a/compiler/rustc_typeck/src/check/place_op.rs b/compiler/rustc_typeck/src/check/place_op.rs index 502cb562385e0..254e41706f90b 100644 --- a/compiler/rustc_typeck/src/check/place_op.rs +++ b/compiler/rustc_typeck/src/check/place_op.rs @@ -203,7 +203,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { while let hir::ExprKind::Field(ref expr, _) | hir::ExprKind::Index(ref expr, _) - | hir::ExprKind::Unary(hir::UnOp::UnDeref, ref expr) = exprs.last().unwrap().kind + | hir::ExprKind::Unary(hir::UnOp::Deref, ref expr) = exprs.last().unwrap().kind { exprs.push(&expr); } @@ -216,7 +216,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { debug!("convert_place_derefs_to_mutable: i={} expr={:?}", i, expr); let mut source = self.node_ty(expr.hir_id); - if matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::UnDeref, _)) { + if matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::Deref, _)) { // Clear previous flag; after a pointer indirection it does not apply any more. inside_union = false; } @@ -270,7 +270,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { hir::ExprKind::Index(ref base_expr, ..) => { self.convert_place_op_to_mutable(PlaceOp::Index, expr, base_expr); } - hir::ExprKind::Unary(hir::UnOp::UnDeref, ref base_expr) => { + hir::ExprKind::Unary(hir::UnOp::Deref, ref base_expr) => { self.convert_place_op_to_mutable(PlaceOp::Deref, expr, base_expr); } _ => {} diff --git a/compiler/rustc_typeck/src/check/writeback.rs b/compiler/rustc_typeck/src/check/writeback.rs index 4d18b2cb3fc49..4f78598215077 100644 --- a/compiler/rustc_typeck/src/check/writeback.rs +++ b/compiler/rustc_typeck/src/check/writeback.rs @@ -138,7 +138,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { // operating on scalars, we clear the overload. fn fix_scalar_builtin_expr(&mut self, e: &hir::Expr<'_>) { match e.kind { - hir::ExprKind::Unary(hir::UnOp::UnNeg | hir::UnOp::UnNot, ref inner) => { + hir::ExprKind::Unary(hir::UnOp::Neg | hir::UnOp::Not, ref inner) => { let inner_ty = self.fcx.node_ty(inner.hir_id); let inner_ty = self.fcx.resolve_vars_if_possible(inner_ty); diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index bd2c266d93dca..52110af47929e 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -184,7 +184,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { hir::ExprKind::Type(ref subexpr, _) => self.walk_expr(subexpr), - hir::ExprKind::Unary(hir::UnOp::UnDeref, ref base) => { + hir::ExprKind::Unary(hir::UnOp::Deref, ref base) => { // *base self.select_from_expr(base); } diff --git a/compiler/rustc_typeck/src/mem_categorization.rs b/compiler/rustc_typeck/src/mem_categorization.rs index fef52a3f87c95..14af11097cf8b 100644 --- a/compiler/rustc_typeck/src/mem_categorization.rs +++ b/compiler/rustc_typeck/src/mem_categorization.rs @@ -303,7 +303,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { let expr_ty = self.expr_ty(expr)?; match expr.kind { - hir::ExprKind::Unary(hir::UnOp::UnDeref, ref e_base) => { + hir::ExprKind::Unary(hir::UnOp::Deref, ref e_base) => { if self.typeck_results.is_method_call(expr) { self.cat_overloaded_place(expr, e_base) } else { diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index e87303749b423..354efdefc2103 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -509,6 +509,23 @@ impl Box { let (raw, alloc) = Box::into_raw_with_allocator(boxed); unsafe { Box::from_raw_in(raw as *mut [T; 1], alloc) } } + + /// Consumes the `Box`, returning the wrapped value. + /// + /// # Examples + /// + /// ``` + /// #![feature(box_into_inner)] + /// + /// let c = Box::new(5); + /// + /// assert_eq!(Box::into_inner(c), 5); + /// ``` + #[unstable(feature = "box_into_inner", issue = "80437")] + #[inline] + pub fn into_inner(boxed: Self) -> T { + *boxed + } } impl Box<[T]> { diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index ede1601fa33cc..c7b4c98041b2e 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1828,8 +1828,60 @@ impl Vec { self.split_at_spare_mut().1 } + /// Returns vector content as a slice of `T`, along with the remaining spare + /// capacity of the vector as a slice of `MaybeUninit`. + /// + /// The returned spare capacity slice can be used to fill the vector with data + /// (e.g. by reading from a file) before marking the data as initialized using + /// the [`set_len`] method. + /// + /// [`set_len`]: Vec::set_len + /// + /// Note that this is a low-level API, which should be used with care for + /// optimization purposes. If you need to append data to a `Vec` + /// you can use [`push`], [`extend`], [`extend_from_slice`], + /// [`extend_from_within`], [`insert`], [`append`], [`resize`] or + /// [`resize_with`], depending on your exact needs. + /// + /// [`push`]: Vec::push + /// [`extend`]: Vec::extend + /// [`extend_from_slice`]: Vec::extend_from_slice + /// [`extend_from_within`]: Vec::extend_from_within + /// [`insert`]: Vec::insert + /// [`append`]: Vec::append + /// [`resize`]: Vec::resize + /// [`resize_with`]: Vec::resize_with + /// + /// # Examples + /// + /// ``` + /// #![feature(vec_split_at_spare, maybe_uninit_extra)] + /// + /// let mut v = vec![1, 1, 2]; + /// + /// // Reserve additional space big enough for 10 elements. + /// v.reserve(10); + /// + /// let (init, uninit) = v.split_at_spare_mut(); + /// let sum = init.iter().copied().sum::(); + /// + /// // Fill in the next 4 elements. + /// uninit[0].write(sum); + /// uninit[1].write(sum * 2); + /// uninit[2].write(sum * 3); + /// uninit[3].write(sum * 4); + /// + /// // Mark the 4 elements of the vector as being initialized. + /// unsafe { + /// let len = v.len(); + /// v.set_len(len + 4); + /// } + /// + /// assert_eq!(&v, &[1, 1, 2, 4, 8, 12, 16]); + /// ``` + #[unstable(feature = "vec_split_at_spare", issue = "81944")] #[inline] - fn split_at_spare_mut(&mut self) -> (&mut [T], &mut [MaybeUninit]) { + pub fn split_at_spare_mut(&mut self) -> (&mut [T], &mut [MaybeUninit]) { let ptr = self.as_mut_ptr(); // Safety: diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 080a0a21188ea..c12770fb8b6d7 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1586,7 +1586,7 @@ extern "rust-intrinsic" { /// Safe wrappers for this intrinsic are available on the integer /// primitives via the `checked_div` method. For example, /// [`u32::checked_div`] - #[rustc_const_stable(feature = "const_int_unchecked_arith", since = "1.51.0")] + #[rustc_const_stable(feature = "const_int_unchecked_arith", since = "1.52.0")] pub fn unchecked_div(x: T, y: T) -> T; /// Returns the remainder of an unchecked division, resulting in /// undefined behavior when `y == 0` or `x == T::MIN && y == -1` @@ -1594,7 +1594,7 @@ extern "rust-intrinsic" { /// Safe wrappers for this intrinsic are available on the integer /// primitives via the `checked_rem` method. For example, /// [`u32::checked_rem`] - #[rustc_const_stable(feature = "const_int_unchecked_arith", since = "1.51.0")] + #[rustc_const_stable(feature = "const_int_unchecked_arith", since = "1.52.0")] pub fn unchecked_rem(x: T, y: T) -> T; /// Performs an unchecked left shift, resulting in undefined behavior when diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 1a60c3c7b7eab..709ed26d2a39f 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -513,7 +513,7 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_div(0), None);")] /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -539,7 +539,7 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_div_euclid(0), None);")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -565,7 +565,7 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_rem(-1), None);")] /// ``` #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -591,7 +591,7 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_rem_euclid(-1), None);")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -949,7 +949,7 @@ macro_rules! int_impl { /// assert_eq!((-128i8).wrapping_div(-1), -128); /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] - #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -977,7 +977,7 @@ macro_rules! int_impl { /// assert_eq!((-128i8).wrapping_div_euclid(-1), -128); /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1005,7 +1005,7 @@ macro_rules! int_impl { /// assert_eq!((-128i8).wrapping_rem(-1), 0); /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] - #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1032,7 +1032,7 @@ macro_rules! int_impl { /// assert_eq!((-128i8).wrapping_rem_euclid(-1), 0); /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1299,7 +1299,7 @@ macro_rules! int_impl { /// ``` #[inline] #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) { @@ -1329,7 +1329,7 @@ macro_rules! int_impl { /// ``` #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) { @@ -1360,7 +1360,7 @@ macro_rules! int_impl { /// ``` #[inline] #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) { @@ -1390,7 +1390,7 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem_euclid(-1), (0, true));")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1615,7 +1615,7 @@ macro_rules! int_impl { /// assert_eq!((-a).div_euclid(-b), 2); // -7 >= -4 * 2 /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1653,7 +1653,7 @@ macro_rules! int_impl { /// assert_eq!((-a).rem_euclid(-b), 1); /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index ff5f432acd8ac..bf5331a01d58e 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -522,7 +522,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_div(0), None);")] /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -548,7 +548,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_div_euclid(0), None);")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -573,7 +573,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem(0), None);")] /// ``` #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -599,7 +599,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(0), None);")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -876,7 +876,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_div(10), 10);")] /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] - #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -901,7 +901,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_div_euclid(10), 10);")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -924,7 +924,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_rem(10), 0);")] /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] - #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -950,7 +950,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_rem_euclid(10), 0);")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1185,7 +1185,7 @@ macro_rules! uint_impl { /// ``` #[inline] #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) { @@ -1215,7 +1215,7 @@ macro_rules! uint_impl { /// ``` #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) { @@ -1242,7 +1242,7 @@ macro_rules! uint_impl { /// ``` #[inline] #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) { @@ -1272,7 +1272,7 @@ macro_rules! uint_impl { /// ``` #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) { @@ -1456,7 +1456,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(7", stringify!($SelfT), ".div_euclid(4), 1); // or any other integer type")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1484,7 +1484,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(7", stringify!($SelfT), ".rem_euclid(4), 3); // or any other integer type")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 0d004a516f594..0ef848ff0c4c1 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -775,6 +775,15 @@ pub fn sleep_ms(ms: u32) { /// Platforms which do not support nanosecond precision for sleeping will /// have `dur` rounded up to the nearest granularity of time they can sleep for. /// +/// Currently, specifying a zero duration on Unix platforms returns immediately +/// without invoking the underlying [`nanosleep`] syscall, whereas on Windows +/// platforms the underlying [`Sleep`] syscall is always invoked. +/// If the intention is to yield the current time-slice you may want to use +/// [`yield_now`] instead. +/// +/// [`nanosleep`]: https://linux.die.net/man/2/nanosleep +/// [`Sleep`]: https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleep +/// /// # Examples /// /// ```no_run diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 6ab106f302465..8fddd8cba08de 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1512,7 +1512,7 @@ impl<'a> Builder<'a> { for el in stack.iter().rev() { out += &format!("\t{:?}\n", el); } - panic!(out); + panic!("{}", out); } if let Some(out) = self.cache.get(&step) { self.verbose(&format!("{}c {:?}", " ".repeat(stack.len()), step)); diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 2c829c49953ff..8f005be7cf789 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -316,7 +316,7 @@ crate fn is_literal_expr(cx: &DocContext<'_>, hir_id: hir::HirId) -> bool { return true; } - if let hir::ExprKind::Unary(hir::UnOp::UnNeg, expr) = &expr.kind { + if let hir::ExprKind::Unary(hir::UnOp::Neg, expr) = &expr.kind { if let hir::ExprKind::Lit(_) = &expr.kind { return true; } diff --git a/src/test/ui/async-await/mutually-recursive-async-impl-trait-type.stderr b/src/test/ui/async-await/mutually-recursive-async-impl-trait-type.stderr index f6e4c8be29260..f789ad2a05c7d 100644 --- a/src/test/ui/async-await/mutually-recursive-async-impl-trait-type.stderr +++ b/src/test/ui/async-await/mutually-recursive-async-impl-trait-type.stderr @@ -5,6 +5,7 @@ LL | async fn rec_1() { | ^ recursive `async fn` | = note: a recursive `async fn` must be rewritten to return a boxed `dyn Future` + = note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion error[E0733]: recursion in an `async fn` requires boxing --> $DIR/mutually-recursive-async-impl-trait-type.rs:9:18 @@ -13,6 +14,7 @@ LL | async fn rec_2() { | ^ recursive `async fn` | = note: a recursive `async fn` must be rewritten to return a boxed `dyn Future` + = note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion error: aborting due to 2 previous errors diff --git a/src/test/ui/async-await/recursive-async-impl-trait-type.stderr b/src/test/ui/async-await/recursive-async-impl-trait-type.stderr index 892d91e3a4992..63f64f4455749 100644 --- a/src/test/ui/async-await/recursive-async-impl-trait-type.stderr +++ b/src/test/ui/async-await/recursive-async-impl-trait-type.stderr @@ -5,6 +5,7 @@ LL | async fn recursive_async_function() -> () { | ^^ recursive `async fn` | = note: a recursive `async fn` must be rewritten to return a boxed `dyn Future` + = note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion error: aborting due to previous error diff --git a/src/test/ui/stability-attribute/stability-attribute-sanity.stderr b/src/test/ui/stability-attribute/stability-attribute-sanity.stderr index 151b96b8b5a66..674139f4afcce 100644 --- a/src/test/ui/stability-attribute/stability-attribute-sanity.stderr +++ b/src/test/ui/stability-attribute/stability-attribute-sanity.stderr @@ -116,5 +116,5 @@ LL | #[rustc_deprecated(since = "a", reason = "text")] error: aborting due to 19 previous errors -Some errors have detailed explanations: E0539, E0541, E0542, E0546, E0550. +Some errors have detailed explanations: E0539, E0541, E0542, E0546, E0547, E0550. For more information about an error, try `rustc --explain E0539`. diff --git a/src/test/ui/suggestions/suggest-mut-method-for-loop.rs b/src/test/ui/suggestions/suggest-mut-method-for-loop.rs new file mode 100644 index 0000000000000..756768bce4650 --- /dev/null +++ b/src/test/ui/suggestions/suggest-mut-method-for-loop.rs @@ -0,0 +1,17 @@ +use std::collections::HashMap; +struct X(usize); +struct Y { + v: u32 +} + +fn main() { + let mut buzz = HashMap::new(); + buzz.insert("a", Y { v: 0 }); + + for mut t in buzz.values() { + //~^ HELP + //~| SUGGESTION values_mut() + t.v += 1; + //~^ ERROR cannot assign + } +} diff --git a/src/test/ui/suggestions/suggest-mut-method-for-loop.stderr b/src/test/ui/suggestions/suggest-mut-method-for-loop.stderr new file mode 100644 index 0000000000000..6ab08197441c3 --- /dev/null +++ b/src/test/ui/suggestions/suggest-mut-method-for-loop.stderr @@ -0,0 +1,15 @@ +error[E0594]: cannot assign to `t.v` which is behind a `&` reference + --> $DIR/suggest-mut-method-for-loop.rs:14:9 + | +LL | for mut t in buzz.values() { + | ------------- + | | | + | | help: use mutable method: `values_mut()` + | this iterator yields `&` references +... +LL | t.v += 1; + | ^^^^^^^^ `t` is a `&` reference, so the data it refers to cannot be written + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0594`. diff --git a/src/tools/cargo b/src/tools/cargo index 34170fcd6e094..ab64d1393b5b7 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 34170fcd6e0947808a1ac63ac85ffc0da7dace2f +Subproject commit ab64d1393b5b77c66b6534ef5023a1b89ee7bf64 diff --git a/src/tools/clippy/clippy_lints/src/arithmetic.rs b/src/tools/clippy/clippy_lints/src/arithmetic.rs index 9861d8cfc4e5f..61fdf9495b918 100644 --- a/src/tools/clippy/clippy_lints/src/arithmetic.rs +++ b/src/tools/clippy/clippy_lints/src/arithmetic.rs @@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic { match op.node { hir::BinOpKind::Div | hir::BinOpKind::Rem => match &r.kind { hir::ExprKind::Lit(_lit) => (), - hir::ExprKind::Unary(hir::UnOp::UnNeg, expr) => { + hir::ExprKind::Unary(hir::UnOp::Neg, expr) => { if let hir::ExprKind::Lit(lit) = &expr.kind { if let rustc_ast::ast::LitKind::Int(1, _) = lit.node { span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected"); @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic { self.expr_span = Some(expr.span); } }, - hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => { + hir::ExprKind::Unary(hir::UnOp::Neg, arg) => { let ty = cx.typeck_results().expr_ty(arg); if constant_simple(cx, cx.typeck_results(), expr).is_none() { if ty.is_integral() { diff --git a/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs b/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs index aa431f0596cca..77b26faaa586a 100644 --- a/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs +++ b/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs @@ -112,7 +112,7 @@ enum AssertKind { fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { if_chain! { if let ExprKind::If(ref cond, ref then, _) = expr.kind; - if let ExprKind::Unary(UnOp::UnNot, ref expr) = cond.kind; + if let ExprKind::Unary(UnOp::Not, ref expr) = cond.kind; // bind the first argument of the `assert!` macro if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr); // block diff --git a/src/tools/clippy/clippy_lints/src/booleans.rs b/src/tools/clippy/clippy_lints/src/booleans.rs index 90bb0bd555f27..0713303ec4b67 100644 --- a/src/tools/clippy/clippy_lints/src/booleans.rs +++ b/src/tools/clippy/clippy_lints/src/booleans.rs @@ -110,7 +110,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> { // prevent folding of `cfg!` macros and the like if !e.span.from_expansion() { match &e.kind { - ExprKind::Unary(UnOp::UnNot, inner) => return Ok(Bool::Not(box self.run(inner)?)), + ExprKind::Unary(UnOp::Not, inner) => return Ok(Bool::Not(box self.run(inner)?)), ExprKind::Binary(binop, lhs, rhs) => match &binop.node { BinOpKind::Or => { return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?)); @@ -454,7 +454,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => { self.bool_expr(e) }, - ExprKind::Unary(UnOp::UnNot, inner) => { + ExprKind::Unary(UnOp::Not, inner) => { if self.cx.typeck_results().node_types()[inner.hir_id].is_bool() { self.bool_expr(e); } else { @@ -482,7 +482,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> { type Map = Map<'tcx>; fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if let ExprKind::Unary(UnOp::UnNot, inner) = &expr.kind { + if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind { if let Some(suggestion) = simplify_not(self.cx, inner) { span_lint_and_sugg( self.cx, diff --git a/src/tools/clippy/clippy_lints/src/bytecount.rs b/src/tools/clippy/clippy_lints/src/bytecount.rs index ac9098a7584d6..b8828719f627c 100644 --- a/src/tools/clippy/clippy_lints/src/bytecount.rs +++ b/src/tools/clippy/clippy_lints/src/bytecount.rs @@ -101,7 +101,7 @@ fn check_arg(name: Symbol, arg: Symbol, needle: &Expr<'_>) -> bool { fn get_path_name(expr: &Expr<'_>) -> Option { match expr.kind { - ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => { + ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::Deref, ref e) => { get_path_name(e) }, ExprKind::Block(ref b, _) => { diff --git a/src/tools/clippy/clippy_lints/src/collapsible_match.rs b/src/tools/clippy/clippy_lints/src/collapsible_match.rs index 604ba10204697..b83aae0e5719c 100644 --- a/src/tools/clippy/clippy_lints/src/collapsible_match.rs +++ b/src/tools/clippy/clippy_lints/src/collapsible_match.rs @@ -186,7 +186,7 @@ fn addr_adjusted_binding(mut expr: &Expr<'_>, cx: &LateContext<'_>) -> Option break Some(binding_id), _ => break None, }, - ExprKind::Unary(UnOp::UnDeref, e) if cx.typeck_results().expr_ty(e).is_ref() => expr = e, + ExprKind::Unary(UnOp::Deref, e) if cx.typeck_results().expr_ty(e).is_ref() => expr = e, _ => break None, } } diff --git a/src/tools/clippy/clippy_lints/src/consts.rs b/src/tools/clippy/clippy_lints/src/consts.rs index 640cffd24a701..1b89d0bbe3862 100644 --- a/src/tools/clippy/clippy_lints/src/consts.rs +++ b/src/tools/clippy/clippy_lints/src/consts.rs @@ -242,9 +242,9 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { self.expr(value).map(|v| Constant::Repeat(Box::new(v), n)) }, ExprKind::Unary(op, ref operand) => self.expr(operand).and_then(|o| match op { - UnOp::UnNot => self.constant_not(&o, self.typeck_results.expr_ty(e)), - UnOp::UnNeg => self.constant_negate(&o, self.typeck_results.expr_ty(e)), - UnOp::UnDeref => Some(if let Constant::Ref(r) = o { *r } else { o }), + UnOp::Not => self.constant_not(&o, self.typeck_results.expr_ty(e)), + UnOp::Neg => self.constant_negate(&o, self.typeck_results.expr_ty(e)), + UnOp::Deref => Some(if let Constant::Ref(r) = o { *r } else { o }), }), ExprKind::If(ref cond, ref then, ref otherwise) => self.ifthenelse(cond, then, *otherwise), ExprKind::Binary(op, ref left, ref right) => self.binop(op, left, right), diff --git a/src/tools/clippy/clippy_lints/src/entry.rs b/src/tools/clippy/clippy_lints/src/entry.rs index 37948e06869c3..6b9f9a5675481 100644 --- a/src/tools/clippy/clippy_lints/src/entry.rs +++ b/src/tools/clippy/clippy_lints/src/entry.rs @@ -55,7 +55,7 @@ declare_lint_pass!(HashMapPass => [MAP_ENTRY]); impl<'tcx> LateLintPass<'tcx> for HashMapPass { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::If(ref check, ref then_block, ref else_block) = expr.kind { - if let ExprKind::Unary(UnOp::UnNot, ref check) = check.kind { + if let ExprKind::Unary(UnOp::Not, ref check) = check.kind { if let Some((ty, map, key)) = check_cond(cx, check) { // in case of `if !m.contains_key(&k) { m.insert(k, v); }` // we can give a better error message diff --git a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs index ffef78aac8067..086a791520fa8 100644 --- a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs +++ b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs @@ -129,7 +129,7 @@ fn get_specialized_log_method(cx: &LateContext<'_>, base: &Expr<'_>) -> Option<& fn prepare_receiver_sugg<'a>(cx: &LateContext<'_>, mut expr: &'a Expr<'a>) -> Sugg<'a> { let mut suggestion = Sugg::hir(cx, expr, ".."); - if let ExprKind::Unary(UnOp::UnNeg, inner_expr) = &expr.kind { + if let ExprKind::Unary(UnOp::Neg, inner_expr) = &expr.kind { expr = &inner_expr; } @@ -541,12 +541,12 @@ fn is_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { /// If the two expressions are not negations of each other, then it /// returns None. fn are_negated<'a>(cx: &LateContext<'_>, expr1: &'a Expr<'a>, expr2: &'a Expr<'a>) -> Option<(bool, &'a Expr<'a>)> { - if let ExprKind::Unary(UnOp::UnNeg, expr1_negated) = &expr1.kind { + if let ExprKind::Unary(UnOp::Neg, expr1_negated) = &expr1.kind { if eq_expr_value(cx, expr1_negated, expr2) { return Some((false, expr2)); } } - if let ExprKind::Unary(UnOp::UnNeg, expr2_negated) = &expr2.kind { + if let ExprKind::Unary(UnOp::Neg, expr2_negated) = &expr2.kind { if eq_expr_value(cx, expr1, expr2_negated) { return Some((true, expr1)); } diff --git a/src/tools/clippy/clippy_lints/src/functions.rs b/src/tools/clippy/clippy_lints/src/functions.rs index 8795425461033..71a146cc29805 100644 --- a/src/tools/clippy/clippy_lints/src/functions.rs +++ b/src/tools/clippy/clippy_lints/src/functions.rs @@ -644,7 +644,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { } } }, - hir::ExprKind::Unary(hir::UnOp::UnDeref, ref ptr) => self.check_arg(ptr), + hir::ExprKind::Unary(hir::UnOp::Deref, ref ptr) => self.check_arg(ptr), _ => (), } diff --git a/src/tools/clippy/clippy_lints/src/map_clone.rs b/src/tools/clippy/clippy_lints/src/map_clone.rs index 1818836d5d5e8..bd0be88028904 100644 --- a/src/tools/clippy/clippy_lints/src/map_clone.rs +++ b/src/tools/clippy/clippy_lints/src/map_clone.rs @@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { }, hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, .., name, None) => { match closure_expr.kind { - hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => { + hir::ExprKind::Unary(hir::UnOp::Deref, ref inner) => { if ident_eq(name, inner) { if let ty::Ref(.., Mutability::Not) = cx.typeck_results().expr_ty(inner).kind() { lint(cx, e.span, args[0].span, true); diff --git a/src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs index 44c974b9d9857..eaa604c2ae63e 100644 --- a/src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -148,7 +148,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) -> Option) -> Option { - if let hir::ExprKind::Unary(hir::UnOp::UnNeg, inner) = &expr.kind { + if let hir::ExprKind::Unary(hir::UnOp::Neg, inner) = &expr.kind { if let hir::ExprKind::Lit(..) = &inner.kind { return Some(Sign::Neg); } diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index 4ee423b383b0f..0918843294d47 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -2619,7 +2619,7 @@ fn lint_get_unwrap<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, get_args: if_chain! { if needs_ref; if let Some(parent) = get_parent_expr(cx, expr); - if let hir::ExprKind::Unary(hir::UnOp::UnDeref, _) = parent.kind; + if let hir::ExprKind::Unary(hir::UnOp::Deref, _) = parent.kind; then { needs_ref = false; span = parent.span; @@ -3063,7 +3063,7 @@ fn lint_filter_map<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, is_f // in `filter(|x| ..)`, replace `*x` with `x` let a_path = if_chain! { if !is_filter_param_ref; - if let ExprKind::Unary(UnOp::UnDeref, expr_path) = a.kind; + if let ExprKind::Unary(UnOp::Deref, expr_path) = a.kind; then { expr_path } else { a } }; // let the filter closure arg and the map closure arg be equal @@ -3708,8 +3708,8 @@ fn lint_option_as_ref_deref<'tcx>( }, hir::ExprKind::AddrOf(hir::BorrowKind::Ref, m, ref inner) if same_mutability(m) => { if_chain! { - if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner1) = inner.kind; - if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner2) = inner1.kind; + if let hir::ExprKind::Unary(hir::UnOp::Deref, ref inner1) = inner.kind; + if let hir::ExprKind::Unary(hir::UnOp::Deref, ref inner2) = inner1.kind; if let hir::ExprKind::Path(ref qpath) = inner2.kind; if let hir::def::Res::Local(local_id) = cx.qpath_res(qpath, inner2.hir_id); then { @@ -4065,7 +4065,7 @@ fn lint_filetype_is_file(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir if_chain! { if let Some(parent) = get_parent_expr(cx, expr); if let hir::ExprKind::Unary(op, _) = parent.kind; - if op == hir::UnOp::UnNot; + if op == hir::UnOp::Not; then { lint_unary = "!"; verb = "denies"; diff --git a/src/tools/clippy/clippy_lints/src/misc.rs b/src/tools/clippy/clippy_lints/src/misc.rs index 0512d74c7b1c8..2ef5c6aa2a4e2 100644 --- a/src/tools/clippy/clippy_lints/src/misc.rs +++ b/src/tools/clippy/clippy_lints/src/misc.rs @@ -502,7 +502,7 @@ fn is_allowed<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool { // Return true if `expr` is the result of `signum()` invoked on a float value. fn is_signum(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { // The negation of a signum is still a signum - if let ExprKind::Unary(UnOp::UnNeg, ref child_expr) = expr.kind { + if let ExprKind::Unary(UnOp::Neg, ref child_expr) = expr.kind { return is_signum(cx, &child_expr); } @@ -586,7 +586,7 @@ fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: return; } - let other_gets_derefed = matches!(other.kind, ExprKind::Unary(UnOp::UnDeref, _)); + let other_gets_derefed = matches!(other.kind, ExprKind::Unary(UnOp::Deref, _)); let lint_span = if other_gets_derefed { expr.span.to(other.span) diff --git a/src/tools/clippy/clippy_lints/src/needless_bool.rs b/src/tools/clippy/clippy_lints/src/needless_bool.rs index d795f12645794..f283ff1715fb6 100644 --- a/src/tools/clippy/clippy_lints/src/needless_bool.rs +++ b/src/tools/clippy/clippy_lints/src/needless_bool.rs @@ -195,7 +195,7 @@ struct ExpressionInfoWithSpan { } fn is_unary_not(e: &Expr<'_>) -> (bool, Span) { - if let ExprKind::Unary(UnOp::UnNot, operand) = e.kind { + if let ExprKind::Unary(UnOp::Not, operand) = e.kind { return (true, operand.span); } (false, e.span) diff --git a/src/tools/clippy/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/src/tools/clippy/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index 4fb899125e8ad..ec0ad58ca9c3e 100644 --- a/src/tools/clippy/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/src/tools/clippy/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd { if_chain! { if !in_external_macro(cx.sess(), expr.span); - if let ExprKind::Unary(UnOp::UnNot, ref inner) = expr.kind; + if let ExprKind::Unary(UnOp::Not, ref inner) = expr.kind; if let ExprKind::Binary(ref op, ref left, _) = inner.kind; if let BinOpKind::Le | BinOpKind::Ge | BinOpKind::Lt | BinOpKind::Gt = op.node; diff --git a/src/tools/clippy/clippy_lints/src/neg_multiply.rs b/src/tools/clippy/clippy_lints/src/neg_multiply.rs index aa550510867f9..ef7cc65cfcf0a 100644 --- a/src/tools/clippy/clippy_lints/src/neg_multiply.rs +++ b/src/tools/clippy/clippy_lints/src/neg_multiply.rs @@ -32,8 +32,8 @@ impl<'tcx> LateLintPass<'tcx> for NegMultiply { if BinOpKind::Mul == op.node { match (&left.kind, &right.kind) { (&ExprKind::Unary(..), &ExprKind::Unary(..)) => {}, - (&ExprKind::Unary(UnOp::UnNeg, ref lit), _) => check_mul(cx, e.span, lit, right), - (_, &ExprKind::Unary(UnOp::UnNeg, ref lit)) => check_mul(cx, e.span, lit, left), + (&ExprKind::Unary(UnOp::Neg, ref lit), _) => check_mul(cx, e.span, lit, right), + (_, &ExprKind::Unary(UnOp::Neg, ref lit)) => check_mul(cx, e.span, lit, left), _ => {}, } } diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index f57d753631755..0b2262d849076 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -383,7 +383,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { needs_check_adjustment = false; break; }, - ExprKind::Unary(UnOp::UnDeref, _) => { + ExprKind::Unary(UnOp::Deref, _) => { // `*e` => desugared to `*Deref::deref(&e)`, // meaning `e` must be referenced. // no need to go further up since a method call is involved now. diff --git a/src/tools/clippy/clippy_lints/src/option_if_let_else.rs b/src/tools/clippy/clippy_lints/src/option_if_let_else.rs index 7bdf975ffd446..9ef0d267b0b20 100644 --- a/src/tools/clippy/clippy_lints/src/option_if_let_else.rs +++ b/src/tools/clippy/clippy_lints/src/option_if_let_else.rs @@ -181,7 +181,7 @@ fn detect_option_if_let_else<'tcx>( }; let cond_expr = match &cond_expr.kind { // Pointer dereferencing happens automatically, so we can omit it in the suggestion - ExprKind::Unary(UnOp::UnDeref, expr) | ExprKind::AddrOf(_, _, expr) => expr, + ExprKind::Unary(UnOp::Deref, expr) | ExprKind::AddrOf(_, _, expr) => expr, _ => cond_expr, }; Some(OptionIfLetElseOccurence { diff --git a/src/tools/clippy/clippy_lints/src/shadow.rs b/src/tools/clippy/clippy_lints/src/shadow.rs index d5b1767e945b9..32f6bc74642ca 100644 --- a/src/tools/clippy/clippy_lints/src/shadow.rs +++ b/src/tools/clippy/clippy_lints/src/shadow.rs @@ -389,7 +389,7 @@ fn is_self_shadow(name: Symbol, expr: &Expr<'_>) -> bool { ExprKind::Block(ref block, _) => { block.stmts.is_empty() && block.expr.as_ref().map_or(false, |e| is_self_shadow(name, e)) }, - ExprKind::Unary(op, ref inner) => (UnOp::UnDeref == op) && is_self_shadow(name, inner), + ExprKind::Unary(op, ref inner) => (UnOp::Deref == op) && is_self_shadow(name, inner), ExprKind::Path(QPath::Resolved(_, ref path)) => path_eq_name(name, path), _ => false, } diff --git a/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs b/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs index 3a688a7bbef32..0b7d08cb1645a 100644 --- a/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs +++ b/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs @@ -194,7 +194,7 @@ impl<'tcx> Visitor<'tcx> for BinaryExprVisitor { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { match expr.kind { hir::ExprKind::Binary(..) - | hir::ExprKind::Unary(hir::UnOp::UnNot | hir::UnOp::UnNeg, _) + | hir::ExprKind::Unary(hir::UnOp::Not | hir::UnOp::Neg, _) | hir::ExprKind::AssignOp(..) => self.nb_binops += 1, _ => {}, } diff --git a/src/tools/clippy/clippy_lints/src/transmute.rs b/src/tools/clippy/clippy_lints/src/transmute.rs index d977cea4da50b..dc938ed02383d 100644 --- a/src/tools/clippy/clippy_lints/src/transmute.rs +++ b/src/tools/clippy/clippy_lints/src/transmute.rs @@ -586,7 +586,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { let mut expr = &args[0]; let mut arg = sugg::Sugg::hir(cx, expr, ".."); - if let ExprKind::Unary(UnOp::UnNeg, inner_expr) = &expr.kind { + if let ExprKind::Unary(UnOp::Neg, inner_expr) = &expr.kind { expr = &inner_expr; } diff --git a/src/tools/clippy/clippy_lints/src/types.rs b/src/tools/clippy/clippy_lints/src/types.rs index 04c32ce9e8f2c..58af5b12c3735 100644 --- a/src/tools/clippy/clippy_lints/src/types.rs +++ b/src/tools/clippy/clippy_lints/src/types.rs @@ -1706,13 +1706,13 @@ impl<'tcx> LateLintPass<'tcx> for Casts { } fn is_unary_neg(expr: &Expr<'_>) -> bool { - matches!(expr.kind, ExprKind::Unary(UnOp::UnNeg, _)) + matches!(expr.kind, ExprKind::Unary(UnOp::Neg, _)) } fn get_numeric_literal<'e>(expr: &'e Expr<'e>) -> Option<&'e Lit> { match expr.kind { ExprKind::Lit(ref lit) => Some(lit), - ExprKind::Unary(UnOp::UnNeg, e) => { + ExprKind::Unary(UnOp::Neg, e) => { if let ExprKind::Lit(ref lit) = e.kind { Some(lit) } else { @@ -2868,7 +2868,7 @@ declare_lint_pass!(RefToMut => [CAST_REF_TO_MUT]); impl<'tcx> LateLintPass<'tcx> for RefToMut { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { - if let ExprKind::Unary(UnOp::UnDeref, e) = &expr.kind; + if let ExprKind::Unary(UnOp::Deref, e) = &expr.kind; if let ExprKind::Cast(e, t) = &e.kind; if let TyKind::Ptr(MutTy { mutbl: Mutability::Mut, .. }) = t.kind; if let ExprKind::Cast(e, t) = &e.kind; diff --git a/src/tools/clippy/clippy_lints/src/unwrap.rs b/src/tools/clippy/clippy_lints/src/unwrap.rs index b82909eaea604..2fb0463c5a6c2 100644 --- a/src/tools/clippy/clippy_lints/src/unwrap.rs +++ b/src/tools/clippy/clippy_lints/src/unwrap.rs @@ -108,7 +108,7 @@ fn collect_unwrap_info<'tcx>( }, _ => (), } - } else if let ExprKind::Unary(UnOp::UnNot, expr) = &expr.kind { + } else if let ExprKind::Unary(UnOp::Not, expr) = &expr.kind { return collect_unwrap_info(cx, expr, branch, !invert); } else { if_chain! { diff --git a/src/tools/clippy/clippy_lints/src/utils/higher.rs b/src/tools/clippy/clippy_lints/src/utils/higher.rs index 340d340d6d340..145703d1bdc3f 100644 --- a/src/tools/clippy/clippy_lints/src/utils/higher.rs +++ b/src/tools/clippy/clippy_lints/src/utils/higher.rs @@ -243,7 +243,7 @@ pub fn extract_assert_macro_args<'tcx>(e: &'tcx Expr<'tcx>) -> Option Self { - Bar(self.0 & !other.0) // OK: UnNot part of BiExpr as child node + Bar(self.0 & !other.0) // OK: Not part of BiExpr as child node } } @@ -126,7 +126,7 @@ impl Sub for Bar { fn sub(self, other: Self) -> Self { if self.0 <= other.0 { - Bar(-(self.0 & other.0)) // OK: UnNeg part of BiExpr as parent node + Bar(-(self.0 & other.0)) // OK: Neg part of BiExpr as parent node } else { Bar(0) }