Skip to content

Commit 76b13c9

Browse files
Enable rustc_pass_by_value for Span
1 parent 22c3a71 commit 76b13c9

File tree

8 files changed

+28
-22
lines changed

8 files changed

+28
-22
lines changed

compiler/rustc_middle/src/mir/visit.rs

+6
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ macro_rules! make_mir_visitor {
162162
self.super_constant(constant, location);
163163
}
164164

165+
// The macro results in a false positive of sorts, where &mut Span
166+
// is fine, but &Span is not; just allow the lint.
167+
#[allow(rustc::pass_by_value)]
165168
fn visit_span(&mut self,
166169
span: & $($mutability)? Span) {
167170
self.super_span(span);
@@ -869,6 +872,9 @@ macro_rules! make_mir_visitor {
869872
}
870873
}
871874

875+
// The macro results in a false positive of sorts, where &mut Span
876+
// is fine, but &Span is not; just allow the lint.
877+
#[allow(rustc::pass_by_value)]
872878
fn super_span(&mut self, _span: & $($mutability)? Span) {
873879
}
874880

compiler/rustc_mir_build/src/build/scope.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
671671
// a Coverage code region can be generated, `continue` needs no `Assign`; but
672672
// without one, the `InstrumentCoverage` MIR pass cannot generate a code region for
673673
// `continue`. Coverage will be missing unless we add a dummy `Assign` to MIR.
674-
self.add_dummy_assignment(&span, block, source_info);
674+
self.add_dummy_assignment(span, block, source_info);
675675
}
676676
}
677677

@@ -730,8 +730,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
730730

731731
// Add a dummy `Assign` statement to the CFG, with the span for the source code's `continue`
732732
// statement.
733-
fn add_dummy_assignment(&mut self, span: &Span, block: BasicBlock, source_info: SourceInfo) {
734-
let local_decl = LocalDecl::new(self.tcx.mk_unit(), *span).internal();
733+
fn add_dummy_assignment(&mut self, span: Span, block: BasicBlock, source_info: SourceInfo) {
734+
let local_decl = LocalDecl::new(self.tcx.mk_unit(), span).internal();
735735
let temp_place = Place::from(self.local_decls.push(local_decl));
736736
self.cfg.push_assign_unit(block, source_info, temp_place, self.tcx);
737737
}

compiler/rustc_mir_transform/src/coverage/spans.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ impl CoverageStatement {
4747
}
4848
}
4949

50-
pub fn span(&self) -> &Span {
50+
pub fn span(&self) -> Span {
5151
match self {
52-
Self::Statement(_, span, _) | Self::Terminator(_, span) => span,
52+
Self::Statement(_, span, _) | Self::Terminator(_, span) => *span,
5353
}
5454
}
5555
}

compiler/rustc_span/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#![feature(negative_impls)]
2323
#![feature(nll)]
2424
#![feature(min_specialization)]
25+
#![feature(rustc_attrs)]
2526
#![allow(rustc::potential_query_instability)]
2627

2728
#[macro_use]

compiler/rustc_span/src/span_encoding.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ use rustc_data_structures::fx::FxIndexSet;
6161
/// using the callback `SPAN_TRACK` to access the query engine.
6262
///
6363
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
64-
// FIXME: Enable this in the bootstrap bump, but separate commit.
65-
// #[rustc_pass_by_value]
64+
#[rustc_pass_by_value]
6665
pub struct Span {
6766
base_or_index: u32,
6867
len_or_tag: u16,

compiler/rustc_typeck/src/check/expr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
271271
ExprKind::Box(subexpr) => self.check_expr_box(subexpr, expected),
272272
ExprKind::Lit(ref lit) => self.check_lit(&lit, expected),
273273
ExprKind::Binary(op, lhs, rhs) => self.check_binop(expr, op, lhs, rhs),
274-
ExprKind::Assign(lhs, rhs, ref span) => {
274+
ExprKind::Assign(lhs, rhs, span) => {
275275
self.check_expr_assign(expr, expected, lhs, rhs, span)
276276
}
277277
ExprKind::AssignOp(op, lhs, rhs) => self.check_binop_assign(expr, op, lhs, rhs),
@@ -982,7 +982,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
982982
expected: Expectation<'tcx>,
983983
lhs: &'tcx hir::Expr<'tcx>,
984984
rhs: &'tcx hir::Expr<'tcx>,
985-
span: &Span,
985+
span: Span,
986986
) -> Ty<'tcx> {
987987
let expected_ty = expected.coercion_target_type(self, expr.span);
988988
if expected_ty == self.tcx.types.bool {
@@ -1014,7 +1014,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10141014
}
10151015
if eq {
10161016
err.span_suggestion_verbose(
1017-
*span,
1017+
span,
10181018
"you might have meant to compare for equality",
10191019
"==".to_string(),
10201020
applicability,
@@ -1031,7 +1031,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10311031
return self.tcx.ty_error();
10321032
}
10331033

1034-
self.check_lhs_assignable(lhs, "E0070", *span);
1034+
self.check_lhs_assignable(lhs, "E0070", span);
10351035

10361036
let lhs_ty = self.check_expr_with_needs(&lhs, Needs::MutPlace);
10371037
let rhs_ty = self.check_expr_coercable_to_type(&rhs, lhs_ty, Some(lhs));

compiler/rustc_typeck/src/check/op.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3636

3737
let ty =
3838
if !lhs_ty.is_ty_var() && !rhs_ty.is_ty_var() && is_builtin_binop(lhs_ty, rhs_ty, op) {
39-
self.enforce_builtin_binop_types(&lhs.span, lhs_ty, &rhs.span, rhs_ty, op);
39+
self.enforce_builtin_binop_types(lhs.span, lhs_ty, rhs.span, rhs_ty, op);
4040
self.tcx.mk_unit()
4141
} else {
4242
return_ty
@@ -98,9 +98,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9898
&& is_builtin_binop(lhs_ty, rhs_ty, op)
9999
{
100100
let builtin_return_ty = self.enforce_builtin_binop_types(
101-
&lhs_expr.span,
101+
lhs_expr.span,
102102
lhs_ty,
103-
&rhs_expr.span,
103+
rhs_expr.span,
104104
rhs_ty,
105105
op,
106106
);
@@ -114,9 +114,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
114114

115115
fn enforce_builtin_binop_types(
116116
&self,
117-
lhs_span: &Span,
117+
lhs_span: Span,
118118
lhs_ty: Ty<'tcx>,
119-
rhs_span: &Span,
119+
rhs_span: Span,
120120
rhs_ty: Ty<'tcx>,
121121
op: hir::BinOp,
122122
) -> Ty<'tcx> {
@@ -129,8 +129,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
129129
let tcx = self.tcx;
130130
match BinOpCategory::from(op) {
131131
BinOpCategory::Shortcircuit => {
132-
self.demand_suptype(*lhs_span, tcx.types.bool, lhs_ty);
133-
self.demand_suptype(*rhs_span, tcx.types.bool, rhs_ty);
132+
self.demand_suptype(lhs_span, tcx.types.bool, lhs_ty);
133+
self.demand_suptype(rhs_span, tcx.types.bool, rhs_ty);
134134
tcx.types.bool
135135
}
136136

@@ -141,13 +141,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
141141

142142
BinOpCategory::Math | BinOpCategory::Bitwise => {
143143
// both LHS and RHS and result will have the same type
144-
self.demand_suptype(*rhs_span, lhs_ty, rhs_ty);
144+
self.demand_suptype(rhs_span, lhs_ty, rhs_ty);
145145
lhs_ty
146146
}
147147

148148
BinOpCategory::Comparison => {
149149
// both LHS and RHS and result will have the same type
150-
self.demand_suptype(*rhs_span, lhs_ty, rhs_ty);
150+
self.demand_suptype(rhs_span, lhs_ty, rhs_ty);
151151
tcx.types.bool
152152
}
153153
}

src/tools/rustfmt/src/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ fn rewrite_struct_lit<'a>(
15331533
enum StructLitField<'a> {
15341534
Regular(&'a ast::ExprField),
15351535
Base(&'a ast::Expr),
1536-
Rest(&'a Span),
1536+
Rest(Span),
15371537
}
15381538

15391539
// 2 = " {".len()
@@ -1568,7 +1568,7 @@ fn rewrite_struct_lit<'a>(
15681568
let field_iter = fields.iter().map(StructLitField::Regular).chain(
15691569
match struct_rest {
15701570
ast::StructRest::Base(expr) => Some(StructLitField::Base(&**expr)),
1571-
ast::StructRest::Rest(span) => Some(StructLitField::Rest(span)),
1571+
ast::StructRest::Rest(span) => Some(StructLitField::Rest(*span)),
15721572
ast::StructRest::None => None,
15731573
}
15741574
.into_iter(),

0 commit comments

Comments
 (0)