1
Fork 0

Rollup merge of #93363 - lcnr:pass-by-value, r=petrochenkov

`#[rustc_pass_by_value]` cleanup
This commit is contained in:
Matthias Krüger 2022-01-27 22:32:29 +01:00 committed by GitHub
commit 8347f7851a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 35 additions and 26 deletions

View file

@ -612,7 +612,7 @@ impl Span {
#[inline]
/// Returns `true` if `hi == lo`.
pub fn is_empty(&self) -> bool {
pub fn is_empty(self) -> bool {
let span = self.data_untracked();
span.hi == span.lo
}
@ -640,7 +640,7 @@ impl Span {
///
/// Use this instead of `==` when either span could be generated code,
/// and you only care that they point to the same bytes of source text.
pub fn source_equal(&self, other: &Span) -> bool {
pub fn source_equal(self, other: Span) -> bool {
let span = self.data();
let other = other.data();
span.lo == other.lo && span.hi == other.hi
@ -681,17 +681,17 @@ impl Span {
}
#[inline]
pub fn rust_2015(&self) -> bool {
pub fn rust_2015(self) -> bool {
self.edition() == edition::Edition::Edition2015
}
#[inline]
pub fn rust_2018(&self) -> bool {
pub fn rust_2018(self) -> bool {
self.edition() >= edition::Edition::Edition2018
}
#[inline]
pub fn rust_2021(&self) -> bool {
pub fn rust_2021(self) -> bool {
self.edition() >= edition::Edition::Edition2021
}
@ -712,7 +712,7 @@ impl Span {
/// Checks if a span is "internal" to a macro in which `#[unstable]`
/// items can be used (that is, a macro marked with
/// `#[allow_internal_unstable]`).
pub fn allows_unstable(&self, feature: Symbol) -> bool {
pub fn allows_unstable(self, feature: Symbol) -> bool {
self.ctxt()
.outer_expn_data()
.allow_internal_unstable
@ -720,7 +720,7 @@ impl Span {
}
/// Checks if this span arises from a compiler desugaring of kind `kind`.
pub fn is_desugaring(&self, kind: DesugaringKind) -> bool {
pub fn is_desugaring(self, kind: DesugaringKind) -> bool {
match self.ctxt().outer_expn_data().kind {
ExpnKind::Desugaring(k) => k == kind,
_ => false,
@ -729,7 +729,7 @@ impl Span {
/// Returns the compiler desugaring that created this span, or `None`
/// if this span is not from a desugaring.
pub fn desugaring_kind(&self) -> Option<DesugaringKind> {
pub fn desugaring_kind(self) -> Option<DesugaringKind> {
match self.ctxt().outer_expn_data().kind {
ExpnKind::Desugaring(k) => Some(k),
_ => None,
@ -739,7 +739,7 @@ impl Span {
/// Checks if a span is "internal" to a macro in which `unsafe`
/// can be used without triggering the `unsafe_code` lint.
// (that is, a macro marked with `#[allow_internal_unsafe]`).
pub fn allows_unsafe(&self) -> bool {
pub fn allows_unsafe(self) -> bool {
self.ctxt().outer_expn_data().allow_internal_unsafe
}
@ -752,7 +752,7 @@ impl Span {
return None;
}
let is_recursive = expn_data.call_site.source_equal(&prev_span);
let is_recursive = expn_data.call_site.source_equal(prev_span);
prev_span = self;
self = expn_data.call_site;
@ -866,13 +866,13 @@ impl Span {
/// Equivalent of `Span::call_site` from the proc macro API,
/// except that the location is taken from the `self` span.
pub fn with_call_site_ctxt(&self, expn_id: ExpnId) -> Span {
pub fn with_call_site_ctxt(self, expn_id: ExpnId) -> Span {
self.with_ctxt_from_mark(expn_id, Transparency::Transparent)
}
/// Equivalent of `Span::mixed_site` from the proc macro API,
/// except that the location is taken from the `self` span.
pub fn with_mixed_site_ctxt(&self, expn_id: ExpnId) -> Span {
pub fn with_mixed_site_ctxt(self, expn_id: ExpnId) -> Span {
self.with_ctxt_from_mark(expn_id, Transparency::SemiTransparent)
}

View file

@ -61,6 +61,15 @@ use rustc_data_structures::fx::FxIndexSet;
/// using the callback `SPAN_TRACK` to access the query engine.
///
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
// FIXME(@lcnr): Enable this attribute once the bootstrap
// compiler knows of `rustc_pass_by_value`.
//
// Right now, this lint would only trigger when compiling the
// stage 2 compiler, which is fairly annoying as there are
// a lot of places using `&Span` right now. After the next bootstrap bump,
// the lint will already trigger when using stage 1, which is a lot less annoying.
//
// #[cfg_attr(not(bootstrap), rustc_pass_by_value)]
pub struct Span {
base_or_index: u32,
len_or_tag: u16,