1
Fork 0

Auto merge of #101086 - cjgillot:thir-param, r=oli-obk

Compute information about function parameters on THIR

This avoids some manipulation of typeck results while building MIR.
This commit is contained in:
bors 2022-09-13 18:15:06 +00:00
commit c84083b08e
70 changed files with 682 additions and 917 deletions

View file

@ -18,7 +18,7 @@ use rustc_data_structures::captures::Captures;
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::{CtorKind, Namespace};
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_session::Session;
use rustc_target::abi::{Size, VariantIdx};
@ -653,22 +653,6 @@ pub enum BindingForm<'tcx> {
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>, }
mod binding_form_impl {

View file

@ -73,11 +73,29 @@ macro_rules! thir_with_elements {
}
}
pub const UPVAR_ENV_PARAM: ParamId = ParamId::from_u32(0);
thir_with_elements! {
arms: ArmId => Arm<'tcx> => "a{}",
blocks: BlockId => Block => "b{}",
exprs: ExprId => Expr<'tcx> => "e{}",
stmts: StmtId => Stmt<'tcx> => "s{}",
params: ParamId => Param<'tcx> => "p{}",
}
/// Description of a type-checked function parameter.
#[derive(Clone, Debug, HashStable)]
pub struct Param<'tcx> {
/// The pattern that appears in the parameter list, or None for implicit parameters.
pub pat: Option<Box<Pat<'tcx>>>,
/// The possibly inferred type.
pub ty: Ty<'tcx>,
/// Span of the explicitly provided type, or None if inferred for closures.
pub ty_span: Option<Span>,
/// Whether this param is `self`, and how it is bound.
pub self_kind: Option<hir::ImplicitSelfKind>,
/// HirId for lints.
pub hir_id: Option<hir::HirId>,
}
#[derive(Copy, Clone, Debug, HashStable)]
@ -548,6 +566,15 @@ impl<'tcx> Pat<'tcx> {
pub fn wildcard_from_ty(ty: Ty<'tcx>) -> Self {
Pat { ty, span: DUMMY_SP, kind: PatKind::Wild }
}
pub fn simple_ident(&self) -> Option<Symbol> {
match self.kind {
PatKind::Binding { name, mode: BindingMode::ByValue, subpattern: None, .. } => {
Some(name)
}
_ => None,
}
}
}
#[derive(Clone, Debug, HashStable)]