diff options
| author | bors <bors@rust-lang.org> | 2022-09-13 18:15:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-13 18:15:06 +0000 |
| commit | c84083b08e2db69fcf270c4045837fa02663a3bf (patch) | |
| tree | 277677faf6f1f7a00a808329f8d15cfd05f77829 /compiler/rustc_middle | |
| parent | 1ce51982b8550c782ded466c1abff0d2b2e21c4e (diff) | |
| parent | ce9daa2f914dd48adef4e9e661391f6cb40e9893 (diff) | |
| download | rust-c84083b08e2db69fcf270c4045837fa02663a3bf.tar.gz rust-c84083b08e2db69fcf270c4045837fa02663a3bf.zip | |
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.
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/mir/mod.rs | 18 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/thir.rs | 27 |
2 files changed, 28 insertions, 17 deletions
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index dd768c5358d..9a6d34c8ddd 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -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 { diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index c50f8b0eebe..165b9103968 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -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)] |
