]> git.lizzy.rs Git - rust.git/commitdiff
Enable rustc_pass_by_value for Span
authorMark Rousskov <mark.simulacrum@gmail.com>
Wed, 23 Feb 2022 13:11:17 +0000 (08:11 -0500)
committerMark Rousskov <mark.simulacrum@gmail.com>
Fri, 25 Feb 2022 13:00:53 +0000 (08:00 -0500)
compiler/rustc_middle/src/mir/visit.rs
compiler/rustc_mir_build/src/build/scope.rs
compiler/rustc_mir_transform/src/coverage/spans.rs
compiler/rustc_span/src/lib.rs
compiler/rustc_span/src/span_encoding.rs
compiler/rustc_typeck/src/check/expr.rs
compiler/rustc_typeck/src/check/op.rs
src/tools/rustfmt/src/expr.rs

index a618800cc1bd2c12a51a8b830f77ad276227f834..7320a5690693b732ae617afeb3cc980446eb8885 100644 (file)
@@ -162,6 +162,9 @@ fn visit_constant(&mut self,
                 self.super_constant(constant, location);
             }
 
+            // The macro results in a false positive of sorts, where &mut Span
+            // is fine, but &Span is not; just allow the lint.
+            #[allow(rustc::pass_by_value)]
             fn visit_span(&mut self,
                           span: & $($mutability)? Span) {
                 self.super_span(span);
@@ -869,6 +872,9 @@ fn super_constant(&mut self,
                 }
             }
 
+            // The macro results in a false positive of sorts, where &mut Span
+            // is fine, but &Span is not; just allow the lint.
+            #[allow(rustc::pass_by_value)]
             fn super_span(&mut self, _span: & $($mutability)? Span) {
             }
 
index 84d6c1d2db87f1c3834a2cafb9b5d121af446d97..b2ea2889b3e048b55d13783b7a2d1f5ecb1edac7 100644 (file)
@@ -671,7 +671,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                 // a Coverage code region can be generated, `continue` needs no `Assign`; but
                 // without one, the `InstrumentCoverage` MIR pass cannot generate a code region for
                 // `continue`. Coverage will be missing unless we add a dummy `Assign` to MIR.
-                self.add_dummy_assignment(&span, block, source_info);
+                self.add_dummy_assignment(span, block, source_info);
             }
         }
 
@@ -730,8 +730,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
 
     // Add a dummy `Assign` statement to the CFG, with the span for the source code's `continue`
     // statement.
-    fn add_dummy_assignment(&mut self, span: &Span, block: BasicBlock, source_info: SourceInfo) {
-        let local_decl = LocalDecl::new(self.tcx.mk_unit(), *span).internal();
+    fn add_dummy_assignment(&mut self, span: Span, block: BasicBlock, source_info: SourceInfo) {
+        let local_decl = LocalDecl::new(self.tcx.mk_unit(), span).internal();
         let temp_place = Place::from(self.local_decls.push(local_decl));
         self.cfg.push_assign_unit(block, source_info, temp_place, self.tcx);
     }
index d1cb2826dedfcffb90990613206039496703b06b..27b9b6c2fa3e76872c627e1d32f43203a2993125 100644 (file)
@@ -47,9 +47,9 @@ pub fn format<'tcx>(&self, tcx: TyCtxt<'tcx>, mir_body: &mir::Body<'tcx>) -> Str
         }
     }
 
-    pub fn span(&self) -> &Span {
+    pub fn span(&self) -> Span {
         match self {
-            Self::Statement(_, span, _) | Self::Terminator(_, span) => span,
+            Self::Statement(_, span, _) | Self::Terminator(_, span) => *span,
         }
     }
 }
index 9d4c2e3bb84a3d7c133d896b404beba581db4523..6d7377927c2910df4f9cc7fda27ddc7244b1e3eb 100644 (file)
@@ -22,6 +22,7 @@
 #![feature(negative_impls)]
 #![feature(nll)]
 #![feature(min_specialization)]
+#![feature(rustc_attrs)]
 #![allow(rustc::potential_query_instability)]
 
 #[macro_use]
index cd382d6c956cad8d51e90c748c8a4933c22910e0..3ee329e9736f2570e47c4e771da6cbd8a72921a0 100644 (file)
@@ -61,8 +61,7 @@
 /// using the callback `SPAN_TRACK` to access the query engine.
 ///
 #[derive(Clone, Copy, Eq, PartialEq, Hash)]
-// FIXME: Enable this in the bootstrap bump, but separate commit.
-// #[rustc_pass_by_value]
+#[rustc_pass_by_value]
 pub struct Span {
     base_or_index: u32,
     len_or_tag: u16,
index f84036a7a39909a21f6c058d8ce10f01bc5414c4..8d4ffefda73bb41d03c1b58b882d0cf4afb65307 100644 (file)
@@ -271,7 +271,7 @@ fn check_expr_kind(
             ExprKind::Box(subexpr) => self.check_expr_box(subexpr, expected),
             ExprKind::Lit(ref lit) => self.check_lit(&lit, expected),
             ExprKind::Binary(op, lhs, rhs) => self.check_binop(expr, op, lhs, rhs),
-            ExprKind::Assign(lhs, rhs, ref span) => {
+            ExprKind::Assign(lhs, rhs, span) => {
                 self.check_expr_assign(expr, expected, lhs, rhs, span)
             }
             ExprKind::AssignOp(op, lhs, rhs) => self.check_binop_assign(expr, op, lhs, rhs),
@@ -982,7 +982,7 @@ fn check_expr_assign(
         expected: Expectation<'tcx>,
         lhs: &'tcx hir::Expr<'tcx>,
         rhs: &'tcx hir::Expr<'tcx>,
-        span: &Span,
+        span: Span,
     ) -> Ty<'tcx> {
         let expected_ty = expected.coercion_target_type(self, expr.span);
         if expected_ty == self.tcx.types.bool {
@@ -1014,7 +1014,7 @@ fn check_expr_assign(
             }
             if eq {
                 err.span_suggestion_verbose(
-                    *span,
+                    span,
                     "you might have meant to compare for equality",
                     "==".to_string(),
                     applicability,
@@ -1031,7 +1031,7 @@ fn check_expr_assign(
             return self.tcx.ty_error();
         }
 
-        self.check_lhs_assignable(lhs, "E0070", *span);
+        self.check_lhs_assignable(lhs, "E0070", span);
 
         let lhs_ty = self.check_expr_with_needs(&lhs, Needs::MutPlace);
         let rhs_ty = self.check_expr_coercable_to_type(&rhs, lhs_ty, Some(lhs));
index 5873b0f52a60eac6f1dbbb017cf21714841974dc..5dd5e71656d2317fd13a85667a3e8064520ab1ce 100644 (file)
@@ -36,7 +36,7 @@ pub fn check_binop_assign(
 
         let ty =
             if !lhs_ty.is_ty_var() && !rhs_ty.is_ty_var() && is_builtin_binop(lhs_ty, rhs_ty, op) {
-                self.enforce_builtin_binop_types(&lhs.span, lhs_ty, &rhs.span, rhs_ty, op);
+                self.enforce_builtin_binop_types(lhs.span, lhs_ty, rhs.span, rhs_ty, op);
                 self.tcx.mk_unit()
             } else {
                 return_ty
@@ -98,9 +98,9 @@ pub fn check_binop(
                     && is_builtin_binop(lhs_ty, rhs_ty, op)
                 {
                     let builtin_return_ty = self.enforce_builtin_binop_types(
-                        &lhs_expr.span,
+                        lhs_expr.span,
                         lhs_ty,
-                        &rhs_expr.span,
+                        rhs_expr.span,
                         rhs_ty,
                         op,
                     );
@@ -114,9 +114,9 @@ pub fn check_binop(
 
     fn enforce_builtin_binop_types(
         &self,
-        lhs_span: &Span,
+        lhs_span: Span,
         lhs_ty: Ty<'tcx>,
-        rhs_span: &Span,
+        rhs_span: Span,
         rhs_ty: Ty<'tcx>,
         op: hir::BinOp,
     ) -> Ty<'tcx> {
@@ -129,8 +129,8 @@ fn enforce_builtin_binop_types(
         let tcx = self.tcx;
         match BinOpCategory::from(op) {
             BinOpCategory::Shortcircuit => {
-                self.demand_suptype(*lhs_span, tcx.types.bool, lhs_ty);
-                self.demand_suptype(*rhs_span, tcx.types.bool, rhs_ty);
+                self.demand_suptype(lhs_span, tcx.types.bool, lhs_ty);
+                self.demand_suptype(rhs_span, tcx.types.bool, rhs_ty);
                 tcx.types.bool
             }
 
@@ -141,13 +141,13 @@ fn enforce_builtin_binop_types(
 
             BinOpCategory::Math | BinOpCategory::Bitwise => {
                 // both LHS and RHS and result will have the same type
-                self.demand_suptype(*rhs_span, lhs_ty, rhs_ty);
+                self.demand_suptype(rhs_span, lhs_ty, rhs_ty);
                 lhs_ty
             }
 
             BinOpCategory::Comparison => {
                 // both LHS and RHS and result will have the same type
-                self.demand_suptype(*rhs_span, lhs_ty, rhs_ty);
+                self.demand_suptype(rhs_span, lhs_ty, rhs_ty);
                 tcx.types.bool
             }
         }
index e1865c8afc2f0c753c73297989f94e8ced5efd1f..4f333cd27cefe5c9a70d1a7e883819f126dcf8de 100644 (file)
@@ -1533,7 +1533,7 @@ fn rewrite_struct_lit<'a>(
     enum StructLitField<'a> {
         Regular(&'a ast::ExprField),
         Base(&'a ast::Expr),
-        Rest(&'a Span),
+        Rest(Span),
     }
 
     // 2 = " {".len()
@@ -1568,7 +1568,7 @@ enum StructLitField<'a> {
         let field_iter = fields.iter().map(StructLitField::Regular).chain(
             match struct_rest {
                 ast::StructRest::Base(expr) => Some(StructLitField::Base(&**expr)),
-                ast::StructRest::Rest(span) => Some(StructLitField::Rest(span)),
+                ast::StructRest::Rest(span) => Some(StructLitField::Rest(*span)),
                 ast::StructRest::None => None,
             }
             .into_iter(),