Fix Stable trait and its impls to work with the new with_tables

This commit is contained in:
Oli Scherer 2024-01-19 09:42:51 +00:00
parent 06a9dbe5e8
commit 61361c16aa
9 changed files with 173 additions and 132 deletions

View File

@ -484,6 +484,19 @@ impl DroplessArena {
}
}
/// Used by `Lift` to check whether this slice is allocated
/// in this arena.
#[inline]
pub fn contains_slice<T>(&self, slice: &[T]) -> bool {
for chunk in self.chunks.borrow_mut().iter_mut() {
let ptr = slice.as_ptr().cast::<u8>().cast_mut();
if chunk.start() <= ptr && chunk.end() >= ptr {
return true;
}
}
false
}
/// Allocates a string slice that is copied into the `DroplessArena`, returning a
/// reference to it. Will panic if passed an empty string.
///

View File

@ -195,7 +195,7 @@ impl<'tcx> ConstValue<'tcx> {
/// Constants
#[derive(Clone, Copy, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable, Debug)]
#[derive(TypeFoldable, TypeVisitable)]
#[derive(TypeFoldable, TypeVisitable, Lift)]
pub enum Const<'tcx> {
/// This constant came from the type system.
///
@ -456,7 +456,7 @@ impl<'tcx> Const<'tcx> {
/// An unevaluated (potentially generic) constant used in MIR.
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)]
#[derive(Hash, HashStable, TypeFoldable, TypeVisitable)]
#[derive(Hash, HashStable, TypeFoldable, TypeVisitable, Lift)]
pub struct UnevaluatedConst<'tcx> {
pub def: DefId,
pub args: GenericArgsRef<'tcx>,

View File

@ -1416,6 +1416,7 @@ nop_lift! {const_; Const<'a> => Const<'tcx>}
nop_lift! {const_allocation; ConstAllocation<'a> => ConstAllocation<'tcx>}
nop_lift! {predicate; Predicate<'a> => Predicate<'tcx>}
nop_lift! {predicate; Clause<'a> => Clause<'tcx>}
nop_lift! {layout; Layout<'a> => Layout<'tcx>}
nop_list_lift! {type_lists; Ty<'a> => Ty<'tcx>}
nop_list_lift! {poly_existential_predicates; PolyExistentialPredicate<'a> => PolyExistentialPredicate<'tcx>}
@ -1424,8 +1425,28 @@ nop_list_lift! {bound_variable_kinds; ty::BoundVariableKind => ty::BoundVariable
// This is the impl for `&'a GenericArgs<'a>`.
nop_list_lift! {args; GenericArg<'a> => GenericArg<'tcx>}
macro_rules! nop_slice_lift {
($ty:ty => $lifted:ty) => {
impl<'a, 'tcx> Lift<'tcx> for &'a [$ty] {
type Lifted = &'tcx [$lifted];
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
if self.is_empty() {
return Some(&[]);
}
tcx.interners
.arena
.dropless
.contains_slice(self)
.then(|| unsafe { mem::transmute(self) })
}
}
};
}
nop_slice_lift! {ty::ValTree<'a> => ty::ValTree<'tcx>}
TrivialLiftImpls! {
ImplPolarity,
ImplPolarity, Promoted
}
macro_rules! sty_debug_print {

View File

@ -14,7 +14,7 @@ use stable_mir::{opaque, Opaque};
impl<'tcx> Stable<'tcx> for rustc_target::abi::VariantIdx {
type T = VariantIdx;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
VariantIdx::to_val(self.as_usize())
}
}
@ -22,7 +22,7 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::VariantIdx {
impl<'tcx> Stable<'tcx> for rustc_abi::Endian {
type T = stable_mir::target::Endian;
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
match self {
rustc_abi::Endian::Little => stable_mir::target::Endian::Little,
rustc_abi::Endian::Big => stable_mir::target::Endian::Big,
@ -33,7 +33,7 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Endian {
impl<'tcx> Stable<'tcx> for rustc_target::abi::TyAndLayout<'tcx, ty::Ty<'tcx>> {
type T = TyAndLayout;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
TyAndLayout { ty: self.ty.stable(tables), layout: self.layout.stable(tables) }
}
}
@ -41,8 +41,8 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::TyAndLayout<'tcx, ty::Ty<'tcx>> {
impl<'tcx> Stable<'tcx> for rustc_target::abi::Layout<'tcx> {
type T = Layout;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
tables.layout_id(*self)
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
tables.layout_id(tables.tcx.lift(*self).unwrap())
}
}
@ -51,7 +51,7 @@ impl<'tcx> Stable<'tcx>
{
type T = LayoutShape;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
LayoutShape {
fields: self.fields.stable(tables),
variants: self.variants.stable(tables),
@ -65,7 +65,7 @@ impl<'tcx> Stable<'tcx>
impl<'tcx> Stable<'tcx> for rustc_target::abi::call::FnAbi<'tcx, ty::Ty<'tcx>> {
type T = FnAbi;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
assert!(self.args.len() >= self.fixed_count as usize);
assert!(!self.c_variadic || matches!(self.conv, Conv::C));
FnAbi {
@ -81,7 +81,7 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::call::FnAbi<'tcx, ty::Ty<'tcx>> {
impl<'tcx> Stable<'tcx> for rustc_target::abi::call::ArgAbi<'tcx, ty::Ty<'tcx>> {
type T = ArgAbi;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
ArgAbi {
ty: self.layout.ty.stable(tables),
layout: self.layout.layout.stable(tables),
@ -93,7 +93,7 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::call::ArgAbi<'tcx, ty::Ty<'tcx>>
impl<'tcx> Stable<'tcx> for rustc_target::abi::call::Conv {
type T = CallConvention;
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
match self {
Conv::C => CallConvention::C,
Conv::Rust => CallConvention::Rust,
@ -122,7 +122,7 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::call::Conv {
impl<'tcx> Stable<'tcx> for rustc_target::abi::call::PassMode {
type T = PassMode;
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
match self {
rustc_target::abi::call::PassMode::Ignore => PassMode::Ignore,
rustc_target::abi::call::PassMode::Direct(attr) => PassMode::Direct(opaque(attr)),
@ -146,7 +146,7 @@ impl<'tcx> Stable<'tcx> for rustc_target::abi::call::PassMode {
impl<'tcx> Stable<'tcx> for rustc_abi::FieldsShape<rustc_target::abi::FieldIdx> {
type T = FieldsShape;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
match self {
rustc_abi::FieldsShape::Primitive => FieldsShape::Primitive,
rustc_abi::FieldsShape::Union(count) => FieldsShape::Union(*count),
@ -165,7 +165,7 @@ impl<'tcx> Stable<'tcx>
{
type T = VariantsShape;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
match self {
rustc_abi::Variants::Single { index } => {
VariantsShape::Single { index: index.stable(tables) }
@ -185,7 +185,7 @@ impl<'tcx> Stable<'tcx>
impl<'tcx> Stable<'tcx> for rustc_abi::TagEncoding<rustc_target::abi::VariantIdx> {
type T = TagEncoding;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
match self {
rustc_abi::TagEncoding::Direct => TagEncoding::Direct,
rustc_abi::TagEncoding::Niche { untagged_variant, niche_variants, niche_start } => {
@ -202,7 +202,7 @@ impl<'tcx> Stable<'tcx> for rustc_abi::TagEncoding<rustc_target::abi::VariantIdx
impl<'tcx> Stable<'tcx> for rustc_abi::Abi {
type T = ValueAbi;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
match *self {
rustc_abi::Abi::Uninhabited => ValueAbi::Uninhabited,
rustc_abi::Abi::Scalar(scalar) => ValueAbi::Scalar(scalar.stable(tables)),
@ -220,7 +220,7 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Abi {
impl<'tcx> Stable<'tcx> for rustc_abi::Size {
type T = Size;
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
self.bytes_usize()
}
}
@ -228,7 +228,7 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Size {
impl<'tcx> Stable<'tcx> for rustc_abi::Align {
type T = Align;
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
self.bytes()
}
}
@ -236,7 +236,7 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Align {
impl<'tcx> Stable<'tcx> for rustc_abi::Scalar {
type T = Opaque;
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
opaque(self)
}
}

View File

@ -8,7 +8,7 @@ use rustc_middle::ty::layout::LayoutError;
impl<'tcx> Stable<'tcx> for LayoutError<'tcx> {
type T = stable_mir::Error;
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
stable_mir::Error::new(format!("{self:?}"))
}
}
@ -16,7 +16,7 @@ impl<'tcx> Stable<'tcx> for LayoutError<'tcx> {
impl<'tcx> Stable<'tcx> for AllocError {
type T = stable_mir::Error;
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
stable_mir::Error::new(format!("{self:?}"))
}
}

View File

@ -13,7 +13,7 @@ use crate::rustc_smir::{alloc, Stable, Tables};
impl<'tcx> Stable<'tcx> for mir::Body<'tcx> {
type T = stable_mir::mir::Body;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
stable_mir::mir::Body::new(
self.basic_blocks
.iter()
@ -44,7 +44,7 @@ impl<'tcx> Stable<'tcx> for mir::Body<'tcx> {
impl<'tcx> Stable<'tcx> for mir::VarDebugInfo<'tcx> {
type T = stable_mir::mir::VarDebugInfo;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
stable_mir::mir::VarDebugInfo {
name: self.name.to_string(),
source_info: self.source_info.stable(tables),
@ -57,21 +57,21 @@ impl<'tcx> Stable<'tcx> for mir::VarDebugInfo<'tcx> {
impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> {
type T = stable_mir::mir::Statement;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
Statement { kind: self.kind.stable(tables), span: self.source_info.span.stable(tables) }
}
}
impl<'tcx> Stable<'tcx> for mir::SourceInfo {
type T = stable_mir::mir::SourceInfo;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
stable_mir::mir::SourceInfo { span: self.span.stable(tables), scope: self.scope.into() }
}
}
impl<'tcx> Stable<'tcx> for mir::VarDebugInfoFragment<'tcx> {
type T = stable_mir::mir::VarDebugInfoFragment;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
VarDebugInfoFragment {
ty: self.ty.stable(tables),
projection: self.projection.iter().map(|e| e.stable(tables)).collect(),
@ -81,7 +81,7 @@ impl<'tcx> Stable<'tcx> for mir::VarDebugInfoFragment<'tcx> {
impl<'tcx> Stable<'tcx> for mir::VarDebugInfoContents<'tcx> {
type T = stable_mir::mir::VarDebugInfoContents;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
match self {
mir::VarDebugInfoContents::Place(place) => {
stable_mir::mir::VarDebugInfoContents::Place(place.stable(tables))
@ -100,7 +100,7 @@ impl<'tcx> Stable<'tcx> for mir::VarDebugInfoContents<'tcx> {
impl<'tcx> Stable<'tcx> for mir::StatementKind<'tcx> {
type T = stable_mir::mir::StatementKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
match self {
mir::StatementKind::Assign(assign) => stable_mir::mir::StatementKind::Assign(
assign.0.stable(tables),
@ -158,7 +158,7 @@ impl<'tcx> Stable<'tcx> for mir::StatementKind<'tcx> {
impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
type T = stable_mir::mir::Rvalue;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::Rvalue::*;
match self {
Use(op) => stable_mir::mir::Rvalue::Use(op.stable(tables)),
@ -214,7 +214,7 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
impl<'tcx> Stable<'tcx> for mir::Mutability {
type T = stable_mir::mir::Mutability;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use rustc_hir::Mutability::*;
match *self {
Not => stable_mir::mir::Mutability::Not,
@ -225,7 +225,7 @@ impl<'tcx> Stable<'tcx> for mir::Mutability {
impl<'tcx> Stable<'tcx> for mir::BorrowKind {
type T = stable_mir::mir::BorrowKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::BorrowKind::*;
match *self {
Shared => stable_mir::mir::BorrowKind::Shared,
@ -237,7 +237,7 @@ impl<'tcx> Stable<'tcx> for mir::BorrowKind {
impl<'tcx> Stable<'tcx> for mir::MutBorrowKind {
type T = stable_mir::mir::MutBorrowKind;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::MutBorrowKind::*;
match *self {
Default => stable_mir::mir::MutBorrowKind::Default,
@ -249,7 +249,7 @@ impl<'tcx> Stable<'tcx> for mir::MutBorrowKind {
impl<'tcx> Stable<'tcx> for mir::NullOp<'tcx> {
type T = stable_mir::mir::NullOp;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::NullOp::*;
match self {
SizeOf => stable_mir::mir::NullOp::SizeOf,
@ -263,7 +263,7 @@ impl<'tcx> Stable<'tcx> for mir::NullOp<'tcx> {
impl<'tcx> Stable<'tcx> for mir::CastKind {
type T = stable_mir::mir::CastKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::CastKind::*;
match self {
PointerExposeAddress => stable_mir::mir::CastKind::PointerExposeAddress,
@ -283,7 +283,7 @@ impl<'tcx> Stable<'tcx> for mir::CastKind {
impl<'tcx> Stable<'tcx> for mir::FakeReadCause {
type T = stable_mir::mir::FakeReadCause;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::FakeReadCause::*;
match self {
ForMatchGuard => stable_mir::mir::FakeReadCause::ForMatchGuard,
@ -299,7 +299,7 @@ impl<'tcx> Stable<'tcx> for mir::FakeReadCause {
impl<'tcx> Stable<'tcx> for mir::Operand<'tcx> {
type T = stable_mir::mir::Operand;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::Operand::*;
match self {
Copy(place) => stable_mir::mir::Operand::Copy(place.stable(tables)),
@ -312,7 +312,7 @@ impl<'tcx> Stable<'tcx> for mir::Operand<'tcx> {
impl<'tcx> Stable<'tcx> for mir::ConstOperand<'tcx> {
type T = stable_mir::mir::Constant;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
stable_mir::mir::Constant {
span: self.span.stable(tables),
user_ty: self.user_ty.map(|u| u.as_usize()).or(None),
@ -323,7 +323,7 @@ impl<'tcx> Stable<'tcx> for mir::ConstOperand<'tcx> {
impl<'tcx> Stable<'tcx> for mir::Place<'tcx> {
type T = stable_mir::mir::Place;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
stable_mir::mir::Place {
local: self.local.as_usize(),
projection: self.projection.iter().map(|e| e.stable(tables)).collect(),
@ -333,7 +333,7 @@ impl<'tcx> Stable<'tcx> for mir::Place<'tcx> {
impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> {
type T = stable_mir::mir::ProjectionElem;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::ProjectionElem::*;
match self {
Deref => stable_mir::mir::ProjectionElem::Deref,
@ -368,21 +368,21 @@ impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> {
impl<'tcx> Stable<'tcx> for mir::UserTypeProjection {
type T = stable_mir::mir::UserTypeProjection;
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
UserTypeProjection { base: self.base.as_usize(), projection: opaque(&self.projs) }
}
}
impl<'tcx> Stable<'tcx> for mir::Local {
type T = stable_mir::mir::Local;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
self.as_usize()
}
}
impl<'tcx> Stable<'tcx> for mir::RetagKind {
type T = stable_mir::mir::RetagKind;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::RetagKind;
match self {
RetagKind::FnEntry => stable_mir::mir::RetagKind::FnEntry,
@ -395,7 +395,7 @@ impl<'tcx> Stable<'tcx> for mir::RetagKind {
impl<'tcx> Stable<'tcx> for mir::UnwindAction {
type T = stable_mir::mir::UnwindAction;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::UnwindAction;
match self {
UnwindAction::Continue => stable_mir::mir::UnwindAction::Continue,
@ -409,7 +409,7 @@ impl<'tcx> Stable<'tcx> for mir::UnwindAction {
impl<'tcx> Stable<'tcx> for mir::NonDivergingIntrinsic<'tcx> {
type T = stable_mir::mir::NonDivergingIntrinsic;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::NonDivergingIntrinsic;
use stable_mir::mir::CopyNonOverlapping;
match self {
@ -429,7 +429,7 @@ impl<'tcx> Stable<'tcx> for mir::NonDivergingIntrinsic<'tcx> {
impl<'tcx> Stable<'tcx> for mir::AssertMessage<'tcx> {
type T = stable_mir::mir::AssertMessage;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::AssertKind;
match self {
AssertKind::BoundsCheck { len, index } => stable_mir::mir::AssertMessage::BoundsCheck {
@ -468,7 +468,7 @@ impl<'tcx> Stable<'tcx> for mir::AssertMessage<'tcx> {
impl<'tcx> Stable<'tcx> for mir::BinOp {
type T = stable_mir::mir::BinOp;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::BinOp;
match self {
BinOp::Add => stable_mir::mir::BinOp::Add,
@ -499,7 +499,7 @@ impl<'tcx> Stable<'tcx> for mir::BinOp {
impl<'tcx> Stable<'tcx> for mir::UnOp {
type T = stable_mir::mir::UnOp;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::UnOp;
match self {
UnOp::Not => stable_mir::mir::UnOp::Not,
@ -510,7 +510,7 @@ impl<'tcx> Stable<'tcx> for mir::UnOp {
impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> {
type T = stable_mir::mir::AggregateKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
match self {
mir::AggregateKind::Array(ty) => {
stable_mir::mir::AggregateKind::Array(ty.stable(tables))
@ -544,7 +544,7 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> {
impl<'tcx> Stable<'tcx> for mir::InlineAsmOperand<'tcx> {
type T = stable_mir::mir::InlineAsmOperand;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_middle::mir::InlineAsmOperand;
let (in_value, out_place) = match self {
@ -564,7 +564,7 @@ impl<'tcx> Stable<'tcx> for mir::InlineAsmOperand<'tcx> {
impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
type T = stable_mir::mir::Terminator;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::mir::Terminator;
Terminator { kind: self.kind.stable(tables), span: self.source_info.span.stable(tables) }
}
@ -572,7 +572,7 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
impl<'tcx> Stable<'tcx> for mir::TerminatorKind<'tcx> {
type T = stable_mir::mir::TerminatorKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::mir::TerminatorKind;
match self {
mir::TerminatorKind::Goto { target } => {
@ -649,7 +649,7 @@ impl<'tcx> Stable<'tcx> for mir::TerminatorKind<'tcx> {
impl<'tcx> Stable<'tcx> for mir::interpret::ConstAllocation<'tcx> {
type T = Allocation;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
self.inner().stable(tables)
}
}
@ -657,7 +657,7 @@ impl<'tcx> Stable<'tcx> for mir::interpret::ConstAllocation<'tcx> {
impl<'tcx> Stable<'tcx> for mir::interpret::Allocation {
type T = stable_mir::ty::Allocation;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
alloc::allocation_filter(
self,
alloc_range(rustc_target::abi::Size::ZERO, self.size()),
@ -668,7 +668,7 @@ impl<'tcx> Stable<'tcx> for mir::interpret::Allocation {
impl<'tcx> Stable<'tcx> for mir::interpret::AllocId {
type T = stable_mir::mir::alloc::AllocId;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
tables.create_alloc_id(*self)
}
}
@ -676,7 +676,7 @@ impl<'tcx> Stable<'tcx> for mir::interpret::AllocId {
impl<'tcx> Stable<'tcx> for mir::interpret::GlobalAlloc<'tcx> {
type T = GlobalAlloc;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
match self {
mir::interpret::GlobalAlloc::Function(instance) => {
GlobalAlloc::Function(instance.stable(tables))
@ -695,7 +695,7 @@ impl<'tcx> Stable<'tcx> for mir::interpret::GlobalAlloc<'tcx> {
impl<'tcx> Stable<'tcx> for rustc_middle::mir::Const<'tcx> {
type T = stable_mir::ty::Const;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
match *self {
mir::Const::Ty(c) => c.stable(tables),
mir::Const::Unevaluated(unev_const, ty) => {
@ -706,18 +706,20 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::Const<'tcx> {
promoted: unev_const.promoted.map(|u| u.as_u32()),
});
let ty = ty.stable(tables);
let id = tables.intern_const(*self);
let id = tables.intern_const(tables.tcx.lift(*self).unwrap());
Const::new(kind, ty, id)
}
mir::Const::Val(mir::ConstValue::ZeroSized, ty) => {
let ty = ty.stable(tables);
let id = tables.intern_const(*self);
let id = tables.intern_const(tables.tcx.lift(*self).unwrap());
Const::new(ConstantKind::ZeroSized, ty, id)
}
mir::Const::Val(val, ty) => {
let ty = tables.tcx.lift(ty).unwrap();
let val = tables.tcx.lift(val).unwrap();
let kind = ConstantKind::Allocated(alloc::new_allocation(ty, val, tables));
let ty = ty.stable(tables);
let id = tables.intern_const(*self);
let id = tables.intern_const(tables.tcx.lift(*self).unwrap());
Const::new(kind, ty, id)
}
}
@ -727,7 +729,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::Const<'tcx> {
impl<'tcx> Stable<'tcx> for mir::interpret::ErrorHandled {
type T = Error;
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
Error::new(format!("{self:?}"))
}
}
@ -735,7 +737,7 @@ impl<'tcx> Stable<'tcx> for mir::interpret::ErrorHandled {
impl<'tcx> Stable<'tcx> for MonoItem<'tcx> {
type T = stable_mir::mir::mono::MonoItem;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::mir::mono::MonoItem as StableMonoItem;
match self {
MonoItem::Fn(instance) => StableMonoItem::Fn(instance.stable(tables)),

View File

@ -11,7 +11,7 @@ mod ty;
impl<'tcx> Stable<'tcx> for rustc_hir::Unsafety {
type T = stable_mir::mir::Safety;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
match self {
rustc_hir::Unsafety::Unsafe => stable_mir::mir::Safety::Unsafe,
rustc_hir::Unsafety::Normal => stable_mir::mir::Safety::Normal,
@ -21,14 +21,14 @@ impl<'tcx> Stable<'tcx> for rustc_hir::Unsafety {
impl<'tcx> Stable<'tcx> for FieldIdx {
type T = usize;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
self.as_usize()
}
}
impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineSource {
type T = stable_mir::mir::CoroutineSource;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use rustc_hir::CoroutineSource;
match self {
CoroutineSource::Block => stable_mir::mir::CoroutineSource::Block,
@ -40,7 +40,7 @@ impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineSource {
impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineKind {
type T = stable_mir::mir::CoroutineKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_hir::{CoroutineDesugaring, CoroutineKind};
match *self {
CoroutineKind::Desugared(CoroutineDesugaring::Async, source) => {
@ -71,7 +71,7 @@ impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineKind {
impl<'tcx> Stable<'tcx> for rustc_span::Symbol {
type T = stable_mir::Symbol;
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
self.to_string()
}
}
@ -79,7 +79,7 @@ impl<'tcx> Stable<'tcx> for rustc_span::Symbol {
impl<'tcx> Stable<'tcx> for rustc_span::Span {
type T = stable_mir::ty::Span;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
tables.create_span(*self)
}
}

View File

@ -11,7 +11,7 @@ use crate::rustc_smir::{alloc, Stable, Tables};
impl<'tcx> Stable<'tcx> for ty::AliasKind {
type T = stable_mir::ty::AliasKind;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
match self {
ty::Projection => stable_mir::ty::AliasKind::Projection,
ty::Inherent => stable_mir::ty::AliasKind::Inherent,
@ -23,7 +23,7 @@ impl<'tcx> Stable<'tcx> for ty::AliasKind {
impl<'tcx> Stable<'tcx> for ty::AliasTy<'tcx> {
type T = stable_mir::ty::AliasTy;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
let ty::AliasTy { args, def_id, .. } = self;
stable_mir::ty::AliasTy { def_id: tables.alias_def(*def_id), args: args.stable(tables) }
}
@ -32,7 +32,7 @@ impl<'tcx> Stable<'tcx> for ty::AliasTy<'tcx> {
impl<'tcx> Stable<'tcx> for ty::DynKind {
type T = stable_mir::ty::DynKind;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
match self {
ty::Dyn => stable_mir::ty::DynKind::Dyn,
ty::DynStar => stable_mir::ty::DynKind::DynStar,
@ -43,7 +43,7 @@ impl<'tcx> Stable<'tcx> for ty::DynKind {
impl<'tcx> Stable<'tcx> for ty::ExistentialPredicate<'tcx> {
type T = stable_mir::ty::ExistentialPredicate;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::ExistentialPredicate::*;
match self {
ty::ExistentialPredicate::Trait(existential_trait_ref) => {
@ -60,7 +60,7 @@ impl<'tcx> Stable<'tcx> for ty::ExistentialPredicate<'tcx> {
impl<'tcx> Stable<'tcx> for ty::ExistentialTraitRef<'tcx> {
type T = stable_mir::ty::ExistentialTraitRef;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
let ty::ExistentialTraitRef { def_id, args } = self;
stable_mir::ty::ExistentialTraitRef {
def_id: tables.trait_def(*def_id),
@ -72,7 +72,7 @@ impl<'tcx> Stable<'tcx> for ty::ExistentialTraitRef<'tcx> {
impl<'tcx> Stable<'tcx> for ty::TermKind<'tcx> {
type T = stable_mir::ty::TermKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::TermKind;
match self {
ty::TermKind::Ty(ty) => TermKind::Type(ty.stable(tables)),
@ -87,7 +87,7 @@ impl<'tcx> Stable<'tcx> for ty::TermKind<'tcx> {
impl<'tcx> Stable<'tcx> for ty::ExistentialProjection<'tcx> {
type T = stable_mir::ty::ExistentialProjection;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
let ty::ExistentialProjection { def_id, args, term } = self;
stable_mir::ty::ExistentialProjection {
def_id: tables.trait_def(*def_id),
@ -99,7 +99,7 @@ impl<'tcx> Stable<'tcx> for ty::ExistentialProjection<'tcx> {
impl<'tcx> Stable<'tcx> for ty::adjustment::PointerCoercion {
type T = stable_mir::mir::PointerCoercion;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_middle::ty::adjustment::PointerCoercion;
match self {
PointerCoercion::ReifyFnPointer => stable_mir::mir::PointerCoercion::ReifyFnPointer,
@ -118,7 +118,7 @@ impl<'tcx> Stable<'tcx> for ty::adjustment::PointerCoercion {
impl<'tcx> Stable<'tcx> for ty::UserTypeAnnotationIndex {
type T = usize;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
self.as_usize()
}
}
@ -126,7 +126,7 @@ impl<'tcx> Stable<'tcx> for ty::UserTypeAnnotationIndex {
impl<'tcx> Stable<'tcx> for ty::AdtKind {
type T = AdtKind;
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
match self {
ty::AdtKind::Struct => AdtKind::Struct,
ty::AdtKind::Union => AdtKind::Union,
@ -138,7 +138,7 @@ impl<'tcx> Stable<'tcx> for ty::AdtKind {
impl<'tcx> Stable<'tcx> for ty::FieldDef {
type T = stable_mir::ty::FieldDef;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
stable_mir::ty::FieldDef {
def: tables.create_def_id(self.did),
name: self.name.stable(tables),
@ -148,7 +148,7 @@ impl<'tcx> Stable<'tcx> for ty::FieldDef {
impl<'tcx> Stable<'tcx> for ty::GenericArgs<'tcx> {
type T = stable_mir::ty::GenericArgs;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
GenericArgs(self.iter().map(|arg| arg.unpack().stable(tables)).collect())
}
}
@ -156,7 +156,7 @@ impl<'tcx> Stable<'tcx> for ty::GenericArgs<'tcx> {
impl<'tcx> Stable<'tcx> for ty::GenericArgKind<'tcx> {
type T = stable_mir::ty::GenericArgKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::GenericArgKind;
match self {
ty::GenericArgKind::Lifetime(region) => GenericArgKind::Lifetime(region.stable(tables)),
@ -172,7 +172,7 @@ where
{
type T = stable_mir::ty::Binder<V>;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::Binder;
Binder {
@ -192,7 +192,7 @@ where
{
type T = stable_mir::ty::EarlyBinder<V>;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::EarlyBinder;
EarlyBinder { value: self.as_ref().skip_binder().stable(tables) }
@ -201,7 +201,7 @@ where
impl<'tcx> Stable<'tcx> for ty::FnSig<'tcx> {
type T = stable_mir::ty::FnSig;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_target::spec::abi;
use stable_mir::ty::{Abi, FnSig};
@ -245,7 +245,7 @@ impl<'tcx> Stable<'tcx> for ty::FnSig<'tcx> {
impl<'tcx> Stable<'tcx> for ty::BoundTyKind {
type T = stable_mir::ty::BoundTyKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::BoundTyKind;
match self {
@ -260,7 +260,7 @@ impl<'tcx> Stable<'tcx> for ty::BoundTyKind {
impl<'tcx> Stable<'tcx> for ty::BoundRegionKind {
type T = stable_mir::ty::BoundRegionKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::BoundRegionKind;
match self {
@ -276,7 +276,7 @@ impl<'tcx> Stable<'tcx> for ty::BoundRegionKind {
impl<'tcx> Stable<'tcx> for ty::BoundVariableKind {
type T = stable_mir::ty::BoundVariableKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::BoundVariableKind;
match self {
@ -294,7 +294,7 @@ impl<'tcx> Stable<'tcx> for ty::BoundVariableKind {
impl<'tcx> Stable<'tcx> for ty::IntTy {
type T = IntTy;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
match self {
ty::IntTy::Isize => IntTy::Isize,
ty::IntTy::I8 => IntTy::I8,
@ -309,7 +309,7 @@ impl<'tcx> Stable<'tcx> for ty::IntTy {
impl<'tcx> Stable<'tcx> for ty::UintTy {
type T = UintTy;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
match self {
ty::UintTy::Usize => UintTy::Usize,
ty::UintTy::U8 => UintTy::U8,
@ -324,7 +324,7 @@ impl<'tcx> Stable<'tcx> for ty::UintTy {
impl<'tcx> Stable<'tcx> for ty::FloatTy {
type T = FloatTy;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
match self {
ty::FloatTy::F32 => FloatTy::F32,
ty::FloatTy::F64 => FloatTy::F64,
@ -334,14 +334,14 @@ impl<'tcx> Stable<'tcx> for ty::FloatTy {
impl<'tcx> Stable<'tcx> for Ty<'tcx> {
type T = stable_mir::ty::Ty;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
tables.intern_ty(*self)
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
tables.intern_ty(tables.tcx.lift(*self).unwrap())
}
}
impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
type T = stable_mir::ty::TyKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
match self {
ty::Bool => TyKind::RigidTy(RigidTy::Bool),
ty::Char => TyKind::RigidTy(RigidTy::Char),
@ -414,17 +414,22 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
type T = stable_mir::ty::Const;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
let kind = match self.kind() {
ty::Value(val) => {
let const_val = tables.tcx.valtree_to_const_val((self.ty(), val));
let val = match val {
ty::ValTree::Leaf(scalar) => ty::ValTree::Leaf(scalar),
ty::ValTree::Branch(branch) => {
ty::ValTree::Branch(tables.tcx.lift(branch).unwrap())
}
};
let ty = tables.tcx.lift(self.ty()).unwrap();
let const_val = tables.tcx.valtree_to_const_val((ty, val));
if matches!(const_val, mir::ConstValue::ZeroSized) {
ConstantKind::ZeroSized
} else {
stable_mir::ty::ConstantKind::Allocated(alloc::new_allocation(
self.ty(),
const_val,
tables,
ty, const_val, tables,
))
}
}
@ -443,14 +448,14 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
ty::ExprCt(_) => unimplemented!(),
};
let ty = self.ty().stable(tables);
let id = tables.intern_const(mir::Const::Ty(*self));
let id = tables.intern_const(mir::Const::Ty(tables.tcx.lift(*self).unwrap()));
Const::new(kind, ty, id)
}
}
impl<'tcx> Stable<'tcx> for ty::ParamConst {
type T = stable_mir::ty::ParamConst;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::ParamConst;
ParamConst { index: self.index, name: self.name.to_string() }
}
@ -458,7 +463,7 @@ impl<'tcx> Stable<'tcx> for ty::ParamConst {
impl<'tcx> Stable<'tcx> for ty::ParamTy {
type T = stable_mir::ty::ParamTy;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::ParamTy;
ParamTy { index: self.index, name: self.name.to_string() }
}
@ -466,7 +471,7 @@ impl<'tcx> Stable<'tcx> for ty::ParamTy {
impl<'tcx> Stable<'tcx> for ty::BoundTy {
type T = stable_mir::ty::BoundTy;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::BoundTy;
BoundTy { var: self.var.as_usize(), kind: self.kind.stable(tables) }
}
@ -474,7 +479,7 @@ impl<'tcx> Stable<'tcx> for ty::BoundTy {
impl<'tcx> Stable<'tcx> for ty::trait_def::TraitSpecializationKind {
type T = stable_mir::ty::TraitSpecializationKind;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::TraitSpecializationKind;
match self {
@ -489,7 +494,7 @@ impl<'tcx> Stable<'tcx> for ty::trait_def::TraitSpecializationKind {
impl<'tcx> Stable<'tcx> for ty::TraitDef {
type T = stable_mir::ty::TraitDecl;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::opaque;
use stable_mir::ty::TraitDecl;
@ -514,7 +519,7 @@ impl<'tcx> Stable<'tcx> for ty::TraitDef {
impl<'tcx> Stable<'tcx> for ty::TraitRef<'tcx> {
type T = stable_mir::ty::TraitRef;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::TraitRef;
TraitRef::try_new(tables.trait_def(self.def_id), self.args.stable(tables)).unwrap()
@ -524,7 +529,7 @@ impl<'tcx> Stable<'tcx> for ty::TraitRef<'tcx> {
impl<'tcx> Stable<'tcx> for ty::Generics {
type T = stable_mir::ty::Generics;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::Generics;
let params: Vec<_> = self.params.iter().map(|param| param.stable(tables)).collect();
@ -549,7 +554,7 @@ impl<'tcx> Stable<'tcx> for ty::Generics {
impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind {
type T = stable_mir::ty::GenericParamDefKind;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::GenericParamDefKind;
match self {
ty::GenericParamDefKind::Lifetime => GenericParamDefKind::Lifetime,
@ -566,7 +571,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind {
impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDef {
type T = stable_mir::ty::GenericParamDef;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
GenericParamDef {
name: self.name.to_string(),
def_id: tables.generic_def(self.def_id),
@ -580,7 +585,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDef {
impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> {
type T = stable_mir::ty::PredicateKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_middle::ty::PredicateKind;
match self {
PredicateKind::Clause(clause_kind) => {
@ -614,7 +619,7 @@ impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> {
impl<'tcx> Stable<'tcx> for ty::ClauseKind<'tcx> {
type T = stable_mir::ty::ClauseKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use rustc_middle::ty::ClauseKind;
match *self {
ClauseKind::Trait(trait_object) => {
@ -650,7 +655,7 @@ impl<'tcx> Stable<'tcx> for ty::ClauseKind<'tcx> {
impl<'tcx> Stable<'tcx> for ty::ClosureKind {
type T = stable_mir::ty::ClosureKind;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use rustc_middle::ty::ClosureKind::*;
match self {
Fn => stable_mir::ty::ClosureKind::Fn,
@ -663,7 +668,7 @@ impl<'tcx> Stable<'tcx> for ty::ClosureKind {
impl<'tcx> Stable<'tcx> for ty::SubtypePredicate<'tcx> {
type T = stable_mir::ty::SubtypePredicate;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
let ty::SubtypePredicate { a, b, a_is_expected: _ } = self;
stable_mir::ty::SubtypePredicate { a: a.stable(tables), b: b.stable(tables) }
}
@ -672,7 +677,7 @@ impl<'tcx> Stable<'tcx> for ty::SubtypePredicate<'tcx> {
impl<'tcx> Stable<'tcx> for ty::CoercePredicate<'tcx> {
type T = stable_mir::ty::CoercePredicate;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
let ty::CoercePredicate { a, b } = self;
stable_mir::ty::CoercePredicate { a: a.stable(tables), b: b.stable(tables) }
}
@ -681,7 +686,7 @@ impl<'tcx> Stable<'tcx> for ty::CoercePredicate<'tcx> {
impl<'tcx> Stable<'tcx> for ty::AliasRelationDirection {
type T = stable_mir::ty::AliasRelationDirection;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use rustc_middle::ty::AliasRelationDirection::*;
match self {
Equate => stable_mir::ty::AliasRelationDirection::Equate,
@ -693,7 +698,7 @@ impl<'tcx> Stable<'tcx> for ty::AliasRelationDirection {
impl<'tcx> Stable<'tcx> for ty::TraitPredicate<'tcx> {
type T = stable_mir::ty::TraitPredicate;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
let ty::TraitPredicate { trait_ref, polarity } = self;
stable_mir::ty::TraitPredicate {
trait_ref: trait_ref.stable(tables),
@ -709,7 +714,7 @@ where
{
type T = stable_mir::ty::OutlivesPredicate<U, V>;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
let ty::OutlivesPredicate(a, b) = self;
stable_mir::ty::OutlivesPredicate(a.stable(tables), b.stable(tables))
}
@ -718,7 +723,7 @@ where
impl<'tcx> Stable<'tcx> for ty::ProjectionPredicate<'tcx> {
type T = stable_mir::ty::ProjectionPredicate;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
let ty::ProjectionPredicate { projection_ty, term } = self;
stable_mir::ty::ProjectionPredicate {
projection_ty: projection_ty.stable(tables),
@ -730,7 +735,7 @@ impl<'tcx> Stable<'tcx> for ty::ProjectionPredicate<'tcx> {
impl<'tcx> Stable<'tcx> for ty::ImplPolarity {
type T = stable_mir::ty::ImplPolarity;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
use rustc_middle::ty::ImplPolarity::*;
match self {
Positive => stable_mir::ty::ImplPolarity::Positive,
@ -743,7 +748,7 @@ impl<'tcx> Stable<'tcx> for ty::ImplPolarity {
impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
type T = stable_mir::ty::Region;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
Region { kind: self.kind().stable(tables) }
}
}
@ -751,7 +756,7 @@ impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
type T = stable_mir::ty::RegionKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::{BoundRegion, EarlyParamRegion, RegionKind};
match self {
ty::ReEarlyParam(early_reg) => RegionKind::ReEarlyParam(EarlyParamRegion {
@ -782,8 +787,8 @@ impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
impl<'tcx> Stable<'tcx> for ty::Instance<'tcx> {
type T = stable_mir::mir::mono::Instance;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
let def = tables.instance_def(*self);
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
let def = tables.instance_def(tables.tcx.lift(*self).unwrap());
let kind = match self.def {
ty::InstanceDef::Item(..) => stable_mir::mir::mono::InstanceKind::Item,
ty::InstanceDef::Intrinsic(..) => stable_mir::mir::mono::InstanceKind::Intrinsic,
@ -805,7 +810,7 @@ impl<'tcx> Stable<'tcx> for ty::Instance<'tcx> {
impl<'tcx> Stable<'tcx> for ty::Variance {
type T = stable_mir::mir::Variance;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
match self {
ty::Variance::Bivariant => stable_mir::mir::Variance::Bivariant,
ty::Variance::Contravariant => stable_mir::mir::Variance::Contravariant,
@ -818,7 +823,7 @@ impl<'tcx> Stable<'tcx> for ty::Variance {
impl<'tcx> Stable<'tcx> for ty::Movability {
type T = stable_mir::ty::Movability;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
match self {
ty::Movability::Static => stable_mir::ty::Movability::Static,
ty::Movability::Movable => stable_mir::ty::Movability::Movable,

View File

@ -102,11 +102,11 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind {
}
/// Trait used to convert between an internal MIR type to a Stable MIR type.
pub trait Stable<'tcx> {
pub trait Stable<'cx> {
/// The stable representation of the type implementing Stable.
type T;
/// Converts an object to the equivalent Stable MIR representation.
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T;
fn stable(&self, tables: &mut Tables<'_>) -> Self::T;
}
impl<'tcx, T> Stable<'tcx> for &T
@ -115,7 +115,7 @@ where
{
type T = T::T;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
(*self).stable(tables)
}
}
@ -126,7 +126,7 @@ where
{
type T = Option<T::T>;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
self.as_ref().map(|value| value.stable(tables))
}
}
@ -138,7 +138,7 @@ where
{
type T = Result<T::T, E::T>;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
match self {
Ok(val) => Ok(val.stable(tables)),
Err(error) => Err(error.stable(tables)),
@ -151,7 +151,7 @@ where
T: Stable<'tcx>,
{
type T = Vec<T::T>;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
self.iter().map(|e| e.stable(tables)).collect()
}
}
@ -162,7 +162,7 @@ where
U: Stable<'tcx>,
{
type T = (T::T, U::T);
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
(self.0.stable(tables), self.1.stable(tables))
}
}
@ -172,7 +172,7 @@ where
T: Stable<'tcx>,
{
type T = RangeInclusive<T::T>;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
RangeInclusive::new(self.start().stable(tables), self.end().stable(tables))
}
}