Skip to content

Commit 2684dfe

Browse files
committed
try apply rustc_pass_by_value to Span
1 parent e680838 commit 2684dfe

File tree

8 files changed

+32
-23
lines changed

8 files changed

+32
-23
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
607607
&mut self,
608608
macro_def: &ast::MacroDef,
609609
ident: &Ident,
610-
sp: &Span,
610+
sp: Span,
611611
print_visibility: impl FnOnce(&mut Self),
612612
) {
613613
let (kw, has_bang) = if macro_def.macro_rules {
@@ -623,7 +623,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
623623
macro_def.body.delim(),
624624
&macro_def.body.inner_tokens(),
625625
true,
626-
*sp,
626+
sp,
627627
);
628628
if macro_def.body.need_semicolon() {
629629
self.word(";");

compiler/rustc_ast_pretty/src/pprust/state/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'a> State<'a> {
347347
}
348348
}
349349
ast::ItemKind::MacroDef(ref macro_def) => {
350-
self.print_mac_def(macro_def, &item.ident, &item.span, |state| {
350+
self.print_mac_def(macro_def, &item.ident, item.span, |state| {
351351
state.print_visibility(&item.vis)
352352
});
353353
}

compiler/rustc_hir_pretty/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ impl<'a> State<'a> {
571571
self.ann.nested(self, Nested::Body(body));
572572
}
573573
hir::ItemKind::Macro(ref macro_def) => {
574-
self.print_mac_def(macro_def, &item.ident, &item.span, |state| {
574+
self.print_mac_def(macro_def, &item.ident, item.span, |state| {
575575
state.print_visibility(&item.vis)
576576
});
577577
}

compiler/rustc_lint/src/non_fmt_panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,5 +336,5 @@ fn is_arg_inside_call(arg: Span, call: Span) -> bool {
336336
// panic call in the source file, to avoid invalid suggestions when macros are involved.
337337
// We specifically check for the spans to not be identical, as that happens sometimes when
338338
// proc_macros lie about spans and apply the same span to all the tokens they produce.
339-
call.contains(arg) && !call.source_equal(&arg)
339+
call.contains(arg) && !call.source_equal(arg)
340340
}

compiler/rustc_middle/src/mir/spanview.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ where
230230
}
231231

232232
/// Format a string showing the start line and column, and end line and column within a file.
233-
pub fn source_range_no_file<'tcx>(tcx: TyCtxt<'tcx>, span: &Span) -> String {
233+
pub fn source_range_no_file<'tcx>(tcx: TyCtxt<'tcx>, span: Span) -> String {
234234
let source_map = tcx.sess.source_map();
235235
let start = source_map.lookup_char_pos(span.lo());
236236
let end = source_map.lookup_char_pos(span.hi());
@@ -629,7 +629,7 @@ fn tooltip<'tcx>(
629629
let mut text = Vec::new();
630630
text.push(format!("{}: {}:", spanview_id, &source_map.span_to_embeddable_string(span)));
631631
for statement in statements {
632-
let source_range = source_range_no_file(tcx, &statement.source_info.span);
632+
let source_range = source_range_no_file(tcx, statement.source_info.span);
633633
text.push(format!(
634634
"\n{}{}: {}: {:?}",
635635
TOOLTIP_INDENT,
@@ -639,7 +639,7 @@ fn tooltip<'tcx>(
639639
));
640640
}
641641
if let Some(term) = terminator {
642-
let source_range = source_range_no_file(tcx, &term.source_info.span);
642+
let source_range = source_range_no_file(tcx, term.source_info.span);
643643
text.push(format!(
644644
"\n{}{}: {}: {:?}",
645645
TOOLTIP_INDENT,

compiler/rustc_mir_transform/src/coverage/spans.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl CoverageStatement {
2828
let stmt = &mir_body[bb].statements[stmt_index];
2929
format!(
3030
"{}: @{}[{}]: {:?}",
31-
source_range_no_file(tcx, &span),
31+
source_range_no_file(tcx, span),
3232
bb.index(),
3333
stmt_index,
3434
stmt
@@ -38,7 +38,7 @@ impl CoverageStatement {
3838
let term = mir_body[bb].terminator();
3939
format!(
4040
"{}: @{}.{}: {:?}",
41-
source_range_no_file(tcx, &span),
41+
source_range_no_file(tcx, span),
4242
bb.index(),
4343
term_type(&term.kind),
4444
term.kind
@@ -155,7 +155,7 @@ impl CoverageSpan {
155155
pub fn format<'tcx>(&self, tcx: TyCtxt<'tcx>, mir_body: &mir::Body<'tcx>) -> String {
156156
format!(
157157
"{}\n {}",
158-
source_range_no_file(tcx, &self.span),
158+
source_range_no_file(tcx, self.span),
159159
self.format_coverage_statements(tcx, mir_body).replace('\n', "\n "),
160160
)
161161
}

compiler/rustc_span/src/lib.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ impl Span {
611611

612612
#[inline]
613613
/// Returns `true` if `hi == lo`.
614-
pub fn is_empty(&self) -> bool {
614+
pub fn is_empty(self) -> bool {
615615
let span = self.data_untracked();
616616
span.hi == span.lo
617617
}
@@ -639,7 +639,7 @@ impl Span {
639639
///
640640
/// Use this instead of `==` when either span could be generated code,
641641
/// and you only care that they point to the same bytes of source text.
642-
pub fn source_equal(&self, other: &Span) -> bool {
642+
pub fn source_equal(self, other: Span) -> bool {
643643
let span = self.data();
644644
let other = other.data();
645645
span.lo == other.lo && span.hi == other.hi
@@ -680,17 +680,17 @@ impl Span {
680680
}
681681

682682
#[inline]
683-
pub fn rust_2015(&self) -> bool {
683+
pub fn rust_2015(self) -> bool {
684684
self.edition() == edition::Edition::Edition2015
685685
}
686686

687687
#[inline]
688-
pub fn rust_2018(&self) -> bool {
688+
pub fn rust_2018(self) -> bool {
689689
self.edition() >= edition::Edition::Edition2018
690690
}
691691

692692
#[inline]
693-
pub fn rust_2021(&self) -> bool {
693+
pub fn rust_2021(self) -> bool {
694694
self.edition() >= edition::Edition::Edition2021
695695
}
696696

@@ -711,15 +711,15 @@ impl Span {
711711
/// Checks if a span is "internal" to a macro in which `#[unstable]`
712712
/// items can be used (that is, a macro marked with
713713
/// `#[allow_internal_unstable]`).
714-
pub fn allows_unstable(&self, feature: Symbol) -> bool {
714+
pub fn allows_unstable(self, feature: Symbol) -> bool {
715715
self.ctxt()
716716
.outer_expn_data()
717717
.allow_internal_unstable
718718
.map_or(false, |features| features.iter().any(|&f| f == feature))
719719
}
720720

721721
/// Checks if this span arises from a compiler desugaring of kind `kind`.
722-
pub fn is_desugaring(&self, kind: DesugaringKind) -> bool {
722+
pub fn is_desugaring(self, kind: DesugaringKind) -> bool {
723723
match self.ctxt().outer_expn_data().kind {
724724
ExpnKind::Desugaring(k) => k == kind,
725725
_ => false,
@@ -728,7 +728,7 @@ impl Span {
728728

729729
/// Returns the compiler desugaring that created this span, or `None`
730730
/// if this span is not from a desugaring.
731-
pub fn desugaring_kind(&self) -> Option<DesugaringKind> {
731+
pub fn desugaring_kind(self) -> Option<DesugaringKind> {
732732
match self.ctxt().outer_expn_data().kind {
733733
ExpnKind::Desugaring(k) => Some(k),
734734
_ => None,
@@ -738,7 +738,7 @@ impl Span {
738738
/// Checks if a span is "internal" to a macro in which `unsafe`
739739
/// can be used without triggering the `unsafe_code` lint.
740740
// (that is, a macro marked with `#[allow_internal_unsafe]`).
741-
pub fn allows_unsafe(&self) -> bool {
741+
pub fn allows_unsafe(self) -> bool {
742742
self.ctxt().outer_expn_data().allow_internal_unsafe
743743
}
744744

@@ -751,7 +751,7 @@ impl Span {
751751
return None;
752752
}
753753

754-
let is_recursive = expn_data.call_site.source_equal(&prev_span);
754+
let is_recursive = expn_data.call_site.source_equal(prev_span);
755755

756756
prev_span = self;
757757
self = expn_data.call_site;
@@ -865,13 +865,13 @@ impl Span {
865865

866866
/// Equivalent of `Span::call_site` from the proc macro API,
867867
/// except that the location is taken from the `self` span.
868-
pub fn with_call_site_ctxt(&self, expn_id: ExpnId) -> Span {
868+
pub fn with_call_site_ctxt(self, expn_id: ExpnId) -> Span {
869869
self.with_ctxt_from_mark(expn_id, Transparency::Transparent)
870870
}
871871

872872
/// Equivalent of `Span::mixed_site` from the proc macro API,
873873
/// except that the location is taken from the `self` span.
874-
pub fn with_mixed_site_ctxt(&self, expn_id: ExpnId) -> Span {
874+
pub fn with_mixed_site_ctxt(self, expn_id: ExpnId) -> Span {
875875
self.with_ctxt_from_mark(expn_id, Transparency::SemiTransparent)
876876
}
877877

compiler/rustc_span/src/span_encoding.rs

+9
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ 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(@lcnr): Enable this attribute once the bootstrap
65+
// compiler knows of `rustc_pass_by_value`.
66+
//
67+
// Right now, this lint would only trigger when compiling the
68+
// stage 2 compiler, which is fairly annoying as there are
69+
// a lot of places using `&Span` right now. After the next bootstrap bump,
70+
// the lint will already trigger when using stage 1, which is a lot less annoying.
71+
//
72+
// #[cfg_attr(not(bootstrap), rustc_pass_by_value)]
6473
pub struct Span {
6574
base_or_index: u32,
6675
len_or_tag: u16,

0 commit comments

Comments
 (0)