Auto merge of #14518 - Veykril:hir-def-refac, r=Veykril

internal: Remove unnecessary Names from FunctionData::params
This commit is contained in:
bors 2023-04-06 18:20:32 +00:00
commit a1e8535f44
7 changed files with 17 additions and 16 deletions

View File

@ -973,10 +973,10 @@ impl ExprCollector<'_> {
block: ast::BlockExpr, block: ast::BlockExpr,
mk_block: impl FnOnce(Option<BlockId>, Box<[Statement]>, Option<ExprId>) -> Expr, mk_block: impl FnOnce(Option<BlockId>, Box<[Statement]>, Option<ExprId>) -> Expr,
) -> ExprId { ) -> ExprId {
let block_id = if ItemTree::block_has_items(self.db, self.expander.current_file_id, &block)
{
let file_local_id = self.ast_id_map.ast_id(&block); let file_local_id = self.ast_id_map.ast_id(&block);
let ast_id = AstId::new(self.expander.current_file_id, file_local_id); let ast_id = AstId::new(self.expander.current_file_id, file_local_id);
let block_id = if ItemTree::block_has_items(self.db, ast_id.file_id, &block) {
Some(self.db.intern_block(BlockLoc { Some(self.db.intern_block(BlockLoc {
ast_id, ast_id,
module: self.expander.def_map.module_id(self.expander.module), module: self.expander.def_map.module_id(self.expander.module),

View File

@ -30,7 +30,7 @@ use crate::{
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct FunctionData { pub struct FunctionData {
pub name: Name, pub name: Name,
pub params: Vec<(Option<Name>, Interned<TypeRef>)>, pub params: Vec<Interned<TypeRef>>,
pub ret_type: Interned<TypeRef>, pub ret_type: Interned<TypeRef>,
pub attrs: Attrs, pub attrs: Attrs,
pub visibility: RawVisibility, pub visibility: RawVisibility,
@ -100,7 +100,7 @@ impl FunctionData {
params: enabled_params params: enabled_params
.clone() .clone()
.filter_map(|id| match &item_tree[id] { .filter_map(|id| match &item_tree[id] {
Param::Normal(name, ty) => Some((name.clone(), ty.clone())), Param::Normal(_, ty) => Some(ty.clone()),
Param::Varargs => None, Param::Varargs => None,
}) })
.collect(), .collect(),

View File

@ -176,7 +176,7 @@ impl GenericParams {
// Don't create an `Expander` nor call `loc.source(db)` if not needed since this // Don't create an `Expander` nor call `loc.source(db)` if not needed since this
// causes a reparse after the `ItemTree` has been created. // causes a reparse after the `ItemTree` has been created.
let mut expander = Lazy::new(|| Expander::new(db, loc.source(db).file_id, module)); let mut expander = Lazy::new(|| Expander::new(db, loc.source(db).file_id, module));
for (_, param) in &func_data.params { for param in &func_data.params {
generic_params.fill_implicit_impl_trait_args(db, &mut expander, param); generic_params.fill_implicit_impl_trait_args(db, &mut expander, param);
} }

View File

@ -618,7 +618,7 @@ impl<'a> InferenceContext<'a> {
let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver) let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver)
.with_impl_trait_mode(ImplTraitLoweringMode::Param); .with_impl_trait_mode(ImplTraitLoweringMode::Param);
let mut param_tys = let mut param_tys =
data.params.iter().map(|(_, type_ref)| ctx.lower_ty(type_ref)).collect::<Vec<_>>(); data.params.iter().map(|type_ref| ctx.lower_ty(type_ref)).collect::<Vec<_>>();
// Check if function contains a va_list, if it does then we append it to the parameter types // Check if function contains a va_list, if it does then we append it to the parameter types
// that are collected from the function data // that are collected from the function data
if data.is_varargs() { if data.is_varargs() {

View File

@ -1634,7 +1634,7 @@ fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig {
let ctx_params = TyLoweringContext::new(db, &resolver) let ctx_params = TyLoweringContext::new(db, &resolver)
.with_impl_trait_mode(ImplTraitLoweringMode::Variable) .with_impl_trait_mode(ImplTraitLoweringMode::Variable)
.with_type_param_mode(ParamLoweringMode::Variable); .with_type_param_mode(ParamLoweringMode::Variable);
let params = data.params.iter().map(|(_, tr)| ctx_params.lower_ty(tr)).collect::<Vec<_>>(); let params = data.params.iter().map(|tr| ctx_params.lower_ty(tr)).collect::<Vec<_>>();
let ctx_ret = TyLoweringContext::new(db, &resolver) let ctx_ret = TyLoweringContext::new(db, &resolver)
.with_impl_trait_mode(ImplTraitLoweringMode::Opaque) .with_impl_trait_mode(ImplTraitLoweringMode::Opaque)
.with_type_param_mode(ParamLoweringMode::Variable); .with_type_param_mode(ParamLoweringMode::Variable);

View File

@ -8,6 +8,7 @@ use hir_def::{
type_ref::{TypeBound, TypeRef}, type_ref::{TypeBound, TypeRef},
AdtId, GenericDefId, AdtId, GenericDefId,
}; };
use hir_expand::name;
use hir_ty::{ use hir_ty::{
display::{ display::{
write_bounds_like_dyn_trait_with_prefix, write_visibility, HirDisplay, HirDisplayError, write_bounds_like_dyn_trait_with_prefix, write_visibility, HirDisplay, HirDisplayError,
@ -76,22 +77,22 @@ impl HirDisplay for Function {
}; };
let mut first = true; let mut first = true;
for (name, type_ref) in &data.params { // FIXME: Use resolved `param.ty` once we no longer discard lifetimes
for (type_ref, param) in data.params.iter().zip(self.assoc_fn_params(db)) {
let local = param.as_local(db).map(|it| it.name(db));
if !first { if !first {
f.write_str(", ")?; f.write_str(", ")?;
} else { } else {
first = false; first = false;
if data.has_self_param() { if local == Some(name!(self)) {
write_self_param(type_ref, f)?; write_self_param(type_ref, f)?;
continue; continue;
} }
} }
match name { match local {
Some(name) => write!(f, "{name}: ")?, Some(name) => write!(f, "{name}: ")?,
None => f.write_str("_: ")?, None => f.write_str("_: ")?,
} }
// FIXME: Use resolved `param.ty` or raw `type_ref`?
// The former will ignore lifetime arguments currently.
type_ref.hir_fmt(f)?; type_ref.hir_fmt(f)?;
} }

View File

@ -1844,7 +1844,7 @@ impl Param {
} }
pub fn name(&self, db: &dyn HirDatabase) -> Option<Name> { pub fn name(&self, db: &dyn HirDatabase) -> Option<Name> {
db.function_data(self.func.id).params[self.idx].0.clone() Some(self.as_local(db)?.name(db))
} }
pub fn as_local(&self, db: &dyn HirDatabase) -> Option<Local> { pub fn as_local(&self, db: &dyn HirDatabase) -> Option<Local> {
@ -1885,7 +1885,7 @@ impl SelfParam {
func_data func_data
.params .params
.first() .first()
.map(|(_, param)| match &**param { .map(|param| match &**param {
TypeRef::Reference(.., mutability) => match mutability { TypeRef::Reference(.., mutability) => match mutability {
hir_def::type_ref::Mutability::Shared => Access::Shared, hir_def::type_ref::Mutability::Shared => Access::Shared,
hir_def::type_ref::Mutability::Mut => Access::Exclusive, hir_def::type_ref::Mutability::Mut => Access::Exclusive,