Skip to content

Commit 8752a56

Browse files
committed
Lift: take self by value
1 parent 1d27267 commit 8752a56

File tree

15 files changed

+138
-151
lines changed

15 files changed

+138
-151
lines changed

Diff for: 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
}

Diff for: 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
)

Diff for: 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
)+

Diff for: 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)?;

Diff for: 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

Diff for: compiler/rustc_middle/src/ty/context.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ impl<'tcx> TyCtxt<'tcx> {
10571057
)
10581058
}
10591059

1060-
pub fn lift<T: ?Sized + Lift<'tcx>>(self, value: &T) -> Option<T::Lifted> {
1060+
pub fn lift<T: Lift<'tcx>>(self, value: T) -> Option<T::Lifted> {
10611061
value.lift_to_tcx(self)
10621062
}
10631063

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

15711571
macro_rules! nop_lift {
15721572
($set:ident; $ty:ty => $lifted:ty) => {
15731573
impl<'a, 'tcx> Lift<'tcx> for $ty {
15741574
type Lifted = $lifted;
1575-
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
1576-
if tcx.interners.$set.contains_pointer_to(&Interned(*self)) {
1577-
Some(unsafe { mem::transmute(*self) })
1575+
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
1576+
if tcx.interners.$set.contains_pointer_to(&Interned(self)) {
1577+
Some(unsafe { mem::transmute(self) })
15781578
} else {
15791579
None
15801580
}
@@ -1587,12 +1587,12 @@ macro_rules! nop_list_lift {
15871587
($set:ident; $ty:ty => $lifted:ty) => {
15881588
impl<'a, 'tcx> Lift<'tcx> for &'a List<$ty> {
15891589
type Lifted = &'tcx List<$lifted>;
1590-
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
1590+
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
15911591
if self.is_empty() {
15921592
return Some(List::empty());
15931593
}
1594-
if tcx.interners.$set.contains_pointer_to(&Interned(*self)) {
1595-
Some(unsafe { mem::transmute(*self) })
1594+
if tcx.interners.$set.contains_pointer_to(&Interned(self)) {
1595+
Some(unsafe { mem::transmute(self) })
15961596
} else {
15971597
None
15981598
}

Diff for: 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(),

Diff for: 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(())

Diff for: 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)