Skip to content

Commit 8347f78

Browse files
authored
Rollup merge of #93363 - lcnr:pass-by-value, r=petrochenkov
`#[rustc_pass_by_value]` cleanup
2 parents 5d79874 + 2684dfe commit 8347f78

File tree

10 files changed

+35
-26
lines changed

10 files changed

+35
-26
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_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
625625
),
626626
rustc_attr!(
627627
rustc_pass_by_value, Normal,
628-
template!(Word), WarnFollowing,
628+
template!(Word), ErrorFollowing,
629629
"#[rustc_pass_by_value] is used to mark types that must be passed by value instead of reference."
630630
),
631631
BuiltinAttribute {

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_lint/src/pass_by_value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ fn gen_args(cx: &LateContext<'_>, segment: &PathSegment<'_>) -> String {
7676
.map(|arg| match arg {
7777
GenericArg::Lifetime(lt) => lt.name.ident().to_string(),
7878
GenericArg::Type(ty) => {
79-
cx.tcx.sess.source_map().span_to_snippet(ty.span).unwrap_or_default()
79+
cx.tcx.sess.source_map().span_to_snippet(ty.span).unwrap_or_else(|_| "_".into())
8080
}
8181
GenericArg::Const(c) => {
82-
cx.tcx.sess.source_map().span_to_snippet(c.span).unwrap_or_default()
82+
cx.tcx.sess.source_map().span_to_snippet(c.span).unwrap_or_else(|_| "_".into())
8383
}
8484
GenericArg::Infer(_) => String::from("_"),
8585
})

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
@@ -612,7 +612,7 @@ impl Span {
612612

613613
#[inline]
614614
/// Returns `true` if `hi == lo`.
615-
pub fn is_empty(&self) -> bool {
615+
pub fn is_empty(self) -> bool {
616616
let span = self.data_untracked();
617617
span.hi == span.lo
618618
}
@@ -640,7 +640,7 @@ impl Span {
640640
///
641641
/// Use this instead of `==` when either span could be generated code,
642642
/// and you only care that they point to the same bytes of source text.
643-
pub fn source_equal(&self, other: &Span) -> bool {
643+
pub fn source_equal(self, other: Span) -> bool {
644644
let span = self.data();
645645
let other = other.data();
646646
span.lo == other.lo && span.hi == other.hi
@@ -681,17 +681,17 @@ impl Span {
681681
}
682682

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

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

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

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

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

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

@@ -752,7 +752,7 @@ impl Span {
752752
return None;
753753
}
754754

755-
let is_recursive = expn_data.call_site.source_equal(&prev_span);
755+
let is_recursive = expn_data.call_site.source_equal(prev_span);
756756

757757
prev_span = self;
758758
self = expn_data.call_site;
@@ -866,13 +866,13 @@ impl Span {
866866

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

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

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)