Skip to content

Commit a1e8535

Browse files
committed
Auto merge of rust-lang#14518 - Veykril:hir-def-refac, r=Veykril
internal: Remove unnecessary Names from FunctionData::params
2 parents 58da3fc + b7c4435 commit a1e8535

File tree

7 files changed

+17
-16
lines changed

7 files changed

+17
-16
lines changed

crates/hir-def/src/body/lower.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -973,10 +973,10 @@ impl ExprCollector<'_> {
973973
block: ast::BlockExpr,
974974
mk_block: impl FnOnce(Option<BlockId>, Box<[Statement]>, Option<ExprId>) -> Expr,
975975
) -> ExprId {
976-
let file_local_id = self.ast_id_map.ast_id(&block);
977-
let ast_id = AstId::new(self.expander.current_file_id, file_local_id);
978-
979-
let block_id = if ItemTree::block_has_items(self.db, ast_id.file_id, &block) {
976+
let block_id = if ItemTree::block_has_items(self.db, self.expander.current_file_id, &block)
977+
{
978+
let file_local_id = self.ast_id_map.ast_id(&block);
979+
let ast_id = AstId::new(self.expander.current_file_id, file_local_id);
980980
Some(self.db.intern_block(BlockLoc {
981981
ast_id,
982982
module: self.expander.def_map.module_id(self.expander.module),

crates/hir-def/src/data.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::{
3030
#[derive(Debug, Clone, PartialEq, Eq)]
3131
pub struct FunctionData {
3232
pub name: Name,
33-
pub params: Vec<(Option<Name>, Interned<TypeRef>)>,
33+
pub params: Vec<Interned<TypeRef>>,
3434
pub ret_type: Interned<TypeRef>,
3535
pub attrs: Attrs,
3636
pub visibility: RawVisibility,
@@ -100,7 +100,7 @@ impl FunctionData {
100100
params: enabled_params
101101
.clone()
102102
.filter_map(|id| match &item_tree[id] {
103-
Param::Normal(name, ty) => Some((name.clone(), ty.clone())),
103+
Param::Normal(_, ty) => Some(ty.clone()),
104104
Param::Varargs => None,
105105
})
106106
.collect(),

crates/hir-def/src/generics.rs

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

crates/hir-ty/src/infer.rs

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

crates/hir-ty/src/lower.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig {
16341634
let ctx_params = TyLoweringContext::new(db, &resolver)
16351635
.with_impl_trait_mode(ImplTraitLoweringMode::Variable)
16361636
.with_type_param_mode(ParamLoweringMode::Variable);
1637-
let params = data.params.iter().map(|(_, tr)| ctx_params.lower_ty(tr)).collect::<Vec<_>>();
1637+
let params = data.params.iter().map(|tr| ctx_params.lower_ty(tr)).collect::<Vec<_>>();
16381638
let ctx_ret = TyLoweringContext::new(db, &resolver)
16391639
.with_impl_trait_mode(ImplTraitLoweringMode::Opaque)
16401640
.with_type_param_mode(ParamLoweringMode::Variable);

crates/hir/src/display.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use hir_def::{
88
type_ref::{TypeBound, TypeRef},
99
AdtId, GenericDefId,
1010
};
11+
use hir_expand::name;
1112
use hir_ty::{
1213
display::{
1314
write_bounds_like_dyn_trait_with_prefix, write_visibility, HirDisplay, HirDisplayError,
@@ -76,22 +77,22 @@ impl HirDisplay for Function {
7677
};
7778

7879
let mut first = true;
79-
for (name, type_ref) in &data.params {
80+
// FIXME: Use resolved `param.ty` once we no longer discard lifetimes
81+
for (type_ref, param) in data.params.iter().zip(self.assoc_fn_params(db)) {
82+
let local = param.as_local(db).map(|it| it.name(db));
8083
if !first {
8184
f.write_str(", ")?;
8285
} else {
8386
first = false;
84-
if data.has_self_param() {
87+
if local == Some(name!(self)) {
8588
write_self_param(type_ref, f)?;
8689
continue;
8790
}
8891
}
89-
match name {
92+
match local {
9093
Some(name) => write!(f, "{name}: ")?,
9194
None => f.write_str("_: ")?,
9295
}
93-
// FIXME: Use resolved `param.ty` or raw `type_ref`?
94-
// The former will ignore lifetime arguments currently.
9596
type_ref.hir_fmt(f)?;
9697
}
9798

crates/hir/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ impl Param {
18441844
}
18451845

18461846
pub fn name(&self, db: &dyn HirDatabase) -> Option<Name> {
1847-
db.function_data(self.func.id).params[self.idx].0.clone()
1847+
Some(self.as_local(db)?.name(db))
18481848
}
18491849

18501850
pub fn as_local(&self, db: &dyn HirDatabase) -> Option<Local> {
@@ -1885,7 +1885,7 @@ impl SelfParam {
18851885
func_data
18861886
.params
18871887
.first()
1888-
.map(|(_, param)| match &**param {
1888+
.map(|param| match &**param {
18891889
TypeRef::Reference(.., mutability) => match mutability {
18901890
hir_def::type_ref::Mutability::Shared => Access::Shared,
18911891
hir_def::type_ref::Mutability::Mut => Access::Exclusive,

0 commit comments

Comments
 (0)