1
Fork 0

Only keep one version of ImplicitSelfKind.

This commit is contained in:
Camille GILLOT 2022-08-27 14:07:59 +02:00
parent 5338f5f1d4
commit ffe20d61d6
5 changed files with 13 additions and 38 deletions

View file

@ -9,10 +9,7 @@ use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::{ use rustc_middle::{
hir::place::PlaceBase, hir::place::PlaceBase,
mir::{ mir::{self, BindingForm, ClearCrossCrate, Local, LocalDecl, LocalInfo, LocalKind, Location},
self, BindingForm, ClearCrossCrate, ImplicitSelfKind, Local, LocalDecl, LocalInfo,
LocalKind, Location,
},
}; };
use rustc_span::source_map::DesugaringKind; use rustc_span::source_map::DesugaringKind;
use rustc_span::symbol::{kw, Symbol}; use rustc_span::symbol::{kw, Symbol};
@ -312,7 +309,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
&& !matches!( && !matches!(
decl.local_info, decl.local_info,
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf( Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(
ImplicitSelfKind::MutRef hir::ImplicitSelfKind::MutRef
)))) ))))
) )
{ {
@ -1074,7 +1071,7 @@ fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<Symb
// //
// Deliberately fall into this case for all implicit self types, // Deliberately fall into this case for all implicit self types,
// so that we don't fall in to the next case with them. // so that we don't fall in to the next case with them.
*kind == mir::ImplicitSelfKind::MutRef *kind == hir::ImplicitSelfKind::MutRef
} }
_ if Some(kw::SelfLower) == local_name => { _ if Some(kw::SelfLower) == local_name => {
// Otherwise, check if the name is the `self` keyword - in which case // Otherwise, check if the name is the `self` keyword - in which case

View file

@ -2661,7 +2661,7 @@ pub struct FnDecl<'hir> {
} }
/// Represents what type of implicit self a function has, if any. /// Represents what type of implicit self a function has, if any.
#[derive(Copy, Clone, Encodable, Decodable, Debug, HashStable_Generic)] #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
pub enum ImplicitSelfKind { pub enum ImplicitSelfKind {
/// Represents a `fn x(self);`. /// Represents a `fn x(self);`.
Imm, Imm,

View file

@ -18,7 +18,7 @@ use rustc_data_structures::captures::Captures;
use rustc_errors::ErrorGuaranteed; use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::{CtorKind, Namespace}; use rustc_hir::def::{CtorKind, Namespace};
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID}; use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
use rustc_hir::{self, GeneratorKind}; use rustc_hir::{self, GeneratorKind, ImplicitSelfKind};
use rustc_hir::{self as hir, HirId}; use rustc_hir::{self as hir, HirId};
use rustc_session::Session; use rustc_session::Session;
use rustc_target::abi::{Size, VariantIdx}; use rustc_target::abi::{Size, VariantIdx};
@ -653,22 +653,6 @@ pub enum BindingForm<'tcx> {
RefForGuard, RefForGuard,
} }
/// Represents what type of implicit self a function has, if any.
#[derive(Clone, Copy, PartialEq, Debug, TyEncodable, TyDecodable, HashStable)]
pub enum ImplicitSelfKind {
/// Represents a `fn x(self);`.
Imm,
/// Represents a `fn x(mut self);`.
Mut,
/// Represents a `fn x(&self);`.
ImmRef,
/// Represents a `fn x(&mut self);`.
MutRef,
/// Represents when a function does not have a self argument or
/// when a function has a `self: X` argument.
None,
}
TrivialTypeTraversalAndLiftImpls! { BindingForm<'tcx>, } TrivialTypeTraversalAndLiftImpls! { BindingForm<'tcx>, }
mod binding_form_impl { mod binding_form_impl {

View file

@ -11,7 +11,7 @@ use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_hir::{GeneratorKind, Node}; use rustc_hir::{GeneratorKind, ImplicitSelfKind, Node};
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexVec};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_middle::hir::place::PlaceBase as HirPlaceBase; use rustc_middle::hir::place::PlaceBase as HirPlaceBase;
@ -170,13 +170,7 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
// Make sure that inferred closure args have no type span // Make sure that inferred closure args have no type span
.and_then(|ty| if arg.pat.span != ty.span { Some(ty.span) } else { None }); .and_then(|ty| if arg.pat.span != ty.span { Some(ty.span) } else { None });
self_arg = if index == 0 && fn_decl.implicit_self.has_implicit_self() { self_arg = if index == 0 && fn_decl.implicit_self.has_implicit_self() {
match fn_decl.implicit_self { Some(fn_decl.implicit_self)
hir::ImplicitSelfKind::Imm => Some(ImplicitSelfKind::Imm),
hir::ImplicitSelfKind::Mut => Some(ImplicitSelfKind::Mut),
hir::ImplicitSelfKind::ImmRef => Some(ImplicitSelfKind::ImmRef),
hir::ImplicitSelfKind::MutRef => Some(ImplicitSelfKind::MutRef),
_ => None,
}
} else { } else {
None None
}; };

View file

@ -1,10 +1,10 @@
pub use crate::very_unstable::hir::ImplicitSelfKind;
pub use crate::very_unstable::middle::mir::{ pub use crate::very_unstable::middle::mir::{
visit::MutVisitor, AggregateKind, AssertKind, BasicBlock, BasicBlockData, BinOp, BindingForm, visit::MutVisitor, AggregateKind, AssertKind, BasicBlock, BasicBlockData, BinOp, BindingForm,
BlockTailInfo, Body, BorrowKind, CastKind, ClearCrossCrate, Constant, ConstantKind, BlockTailInfo, Body, BorrowKind, CastKind, ClearCrossCrate, Constant, ConstantKind,
CopyNonOverlapping, Coverage, FakeReadCause, Field, GeneratorInfo, ImplicitSelfKind, CopyNonOverlapping, Coverage, FakeReadCause, Field, GeneratorInfo, InlineAsmOperand, Local,
InlineAsmOperand, Local, LocalDecl, LocalInfo, LocalKind, Location, MirPhase, MirSource, LocalDecl, LocalInfo, LocalKind, Location, MirPhase, MirSource, NullOp, Operand, Place,
NullOp, Operand, Place, PlaceRef, ProjectionElem, ProjectionKind, Promoted, RetagKind, Rvalue, PlaceRef, ProjectionElem, ProjectionKind, Promoted, RetagKind, Rvalue, Safety, SourceInfo,
Safety, SourceInfo, SourceScope, SourceScopeData, SourceScopeLocalData, Statement, SourceScope, SourceScopeData, SourceScopeLocalData, Statement, StatementKind, UnOp,
StatementKind, UnOp, UserTypeProjection, UserTypeProjections, VarBindingForm, VarDebugInfo, UserTypeProjection, UserTypeProjections, VarBindingForm, VarDebugInfo, VarDebugInfoContents,
VarDebugInfoContents,
}; };