Skip to content

Commit c4fe25d

Browse files
committed
Auto merge of rust-lang#78027 - lcnr:lift-by-value, r=varkor
Lift: take self by value seems small enough to not warrant an MCP 🤷
2 parents 1eaadeb + 17825c9 commit c4fe25d

File tree

15 files changed

+139
-167
lines changed

15 files changed

+139
-167
lines changed

compiler/rustc_infer/src/infer/free_regions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'tcx> FreeRegionRelations<'tcx> for FreeRegionMap<'tcx> {
157157

158158
impl<'a, 'tcx> Lift<'tcx> for FreeRegionMap<'a> {
159159
type Lifted = FreeRegionMap<'tcx>;
160-
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<FreeRegionMap<'tcx>> {
161-
self.relation.maybe_map(|&fr| tcx.lift(&fr)).map(|relation| FreeRegionMap { relation })
160+
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<FreeRegionMap<'tcx>> {
161+
self.relation.maybe_map(|&fr| tcx.lift(fr)).map(|relation| FreeRegionMap { relation })
162162
}
163163
}

compiler/rustc_macros/src/lift.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use syn::{self, parse_quote};
33

44
pub fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
55
s.add_bounds(synstructure::AddBounds::Generics);
6+
s.bind_with(|_| synstructure::BindStyle::Move);
67

78
let tcx: syn::Lifetime = parse_quote!('tcx);
89
let newtcx: syn::GenericParam = parse_quote!('__lifted);
@@ -43,8 +44,8 @@ pub fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStre
4344
quote! {
4445
type Lifted = #lifted;
4546

46-
fn lift_to_tcx(&self, __tcx: ::rustc_middle::ty::TyCtxt<'__lifted>) -> Option<#lifted> {
47-
Some(match *self { #body })
47+
fn lift_to_tcx(self, __tcx: ::rustc_middle::ty::TyCtxt<'__lifted>) -> Option<#lifted> {
48+
Some(match self { #body })
4849
}
4950
},
5051
)

compiler/rustc_middle/src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ macro_rules! CloneLiftImpls {
2929
$(
3030
impl<$tcx> $crate::ty::Lift<$tcx> for $ty {
3131
type Lifted = Self;
32-
fn lift_to_tcx(&self, _: $crate::ty::TyCtxt<$tcx>) -> Option<Self> {
33-
Some(Clone::clone(self))
32+
fn lift_to_tcx(self, _: $crate::ty::TyCtxt<$tcx>) -> Option<Self> {
33+
Some(self)
3434
}
3535
}
3636
)+

compiler/rustc_middle/src/mir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
22102210

22112211
let name = ty::tls::with(|tcx| {
22122212
let mut name = String::new();
2213-
let substs = tcx.lift(&substs).expect("could not lift for printing");
2213+
let substs = tcx.lift(substs).expect("could not lift for printing");
22142214
FmtPrinter::new(tcx, &mut name, Namespace::ValueNS)
22152215
.print_def_path(variant_def.def_id, substs)?;
22162216
Ok(name)
@@ -2233,7 +2233,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
22332233
if let Some(def_id) = def_id.as_local() {
22342234
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
22352235
let name = if tcx.sess.opts.debugging_opts.span_free_formats {
2236-
let substs = tcx.lift(&substs).unwrap();
2236+
let substs = tcx.lift(substs).unwrap();
22372237
format!(
22382238
"[closure@{}]",
22392239
tcx.def_path_str_with_substs(def_id.to_def_id(), substs),
@@ -2527,7 +2527,7 @@ fn pretty_print_const(
25272527
) -> fmt::Result {
25282528
use crate::ty::print::PrettyPrinter;
25292529
ty::tls::with(|tcx| {
2530-
let literal = tcx.lift(&c).unwrap();
2530+
let literal = tcx.lift(c).unwrap();
25312531
let mut cx = FmtPrinter::new(tcx, fmt, Namespace::ValueNS);
25322532
cx.print_alloc_ids = true;
25332533
cx.pretty_print_const(literal, print_types)?;

compiler/rustc_middle/src/mir/terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl<'tcx> TerminatorKind<'tcx> {
535535
Goto { .. } => vec!["".into()],
536536
SwitchInt { ref targets, switch_ty, .. } => ty::tls::with(|tcx| {
537537
let param_env = ty::ParamEnv::empty();
538-
let switch_ty = tcx.lift(&switch_ty).unwrap();
538+
let switch_ty = tcx.lift(switch_ty).unwrap();
539539
let size = tcx.layout_of(param_env.and(switch_ty)).unwrap().size;
540540
targets
541541
.values

compiler/rustc_middle/src/ty/context.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ impl<'tcx> TyCtxt<'tcx> {
10601060
)
10611061
}
10621062

1063-
pub fn lift<T: ?Sized + Lift<'tcx>>(self, value: &T) -> Option<T::Lifted> {
1063+
pub fn lift<T: Lift<'tcx>>(self, value: T) -> Option<T::Lifted> {
10641064
value.lift_to_tcx(self)
10651065
}
10661066

@@ -1569,16 +1569,16 @@ impl<'tcx> TyCtxt<'tcx> {
15691569
/// e.g., `()` or `u8`, was interned in a different context.
15701570
pub trait Lift<'tcx>: fmt::Debug {
15711571
type Lifted: fmt::Debug + 'tcx;
1572-
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted>;
1572+
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted>;
15731573
}
15741574

15751575
macro_rules! nop_lift {
15761576
($set:ident; $ty:ty => $lifted:ty) => {
15771577
impl<'a, 'tcx> Lift<'tcx> for $ty {
15781578
type Lifted = $lifted;
1579-
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
1580-
if tcx.interners.$set.contains_pointer_to(&Interned(*self)) {
1581-
Some(unsafe { mem::transmute(*self) })
1579+
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
1580+
if tcx.interners.$set.contains_pointer_to(&Interned(self)) {
1581+
Some(unsafe { mem::transmute(self) })
15821582
} else {
15831583
None
15841584
}
@@ -1591,12 +1591,12 @@ macro_rules! nop_list_lift {
15911591
($set:ident; $ty:ty => $lifted:ty) => {
15921592
impl<'a, 'tcx> Lift<'tcx> for &'a List<$ty> {
15931593
type Lifted = &'tcx List<$lifted>;
1594-
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
1594+
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
15951595
if self.is_empty() {
15961596
return Some(List::empty());
15971597
}
1598-
if tcx.interners.$set.contains_pointer_to(&Interned(*self)) {
1599-
Some(unsafe { mem::transmute(*self) })
1598+
if tcx.interners.$set.contains_pointer_to(&Interned(self)) {
1599+
Some(unsafe { mem::transmute(self) })
16001600
} else {
16011601
None
16021602
}

compiler/rustc_middle/src/ty/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<'tcx> ty::TyS<'tcx> {
229229
ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(),
230230
ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(),
231231
ty::Array(t, n) => {
232-
let n = tcx.lift(&n).unwrap();
232+
let n = tcx.lift(n).unwrap();
233233
match n.try_eval_usize(tcx, ty::ParamEnv::empty()) {
234234
_ if t.is_simple_ty() => format!("array `{}`", self).into(),
235235
Some(n) => format!("array of {} element{}", n, pluralize!(n)).into(),

compiler/rustc_middle/src/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<'tcx> InstanceDef<'tcx> {
258258
impl<'tcx> fmt::Display for Instance<'tcx> {
259259
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
260260
ty::tls::with(|tcx| {
261-
let substs = tcx.lift(&self.substs).expect("could not lift for printing");
261+
let substs = tcx.lift(self.substs).expect("could not lift for printing");
262262
FmtPrinter::new(tcx, &mut *f, Namespace::ValueNS)
263263
.print_def_path(self.def_id(), substs)?;
264264
Ok(())

compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ macro_rules! forward_display_to_print {
18481848
$(impl fmt::Display for $ty {
18491849
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18501850
ty::tls::with(|tcx| {
1851-
tcx.lift(self)
1851+
tcx.lift(*self)
18521852
.expect("could not lift for printing")
18531853
.print(FmtPrinter::new(tcx, f, Namespace::TypeNS))?;
18541854
Ok(())

0 commit comments

Comments
 (0)