diff options
| author | bors <bors@rust-lang.org> | 2023-04-06 18:20:32 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-04-06 18:20:32 +0000 |
| commit | a1e8535f4418ed48d4ca6d1019b0b9ea7e87145e (patch) | |
| tree | 8beaac6eb56550c047357b716bcca566f9e1c8e4 | |
| parent | 58da3fc24073e58f5fd002fbf602729b6efe979f (diff) | |
| parent | b7c443569a53e624c250058c2181d2c1d299c46f (diff) | |
| download | rust-a1e8535f4418ed48d4ca6d1019b0b9ea7e87145e.tar.gz rust-a1e8535f4418ed48d4ca6d1019b0b9ea7e87145e.zip | |
Auto merge of #14518 - Veykril:hir-def-refac, r=Veykril
internal: Remove unnecessary Names from FunctionData::params
| -rw-r--r-- | crates/hir-def/src/body/lower.rs | 8 | ||||
| -rw-r--r-- | crates/hir-def/src/data.rs | 4 | ||||
| -rw-r--r-- | crates/hir-def/src/generics.rs | 2 | ||||
| -rw-r--r-- | crates/hir-ty/src/infer.rs | 2 | ||||
| -rw-r--r-- | crates/hir-ty/src/lower.rs | 2 | ||||
| -rw-r--r-- | crates/hir/src/display.rs | 11 | ||||
| -rw-r--r-- | crates/hir/src/lib.rs | 4 |
7 files changed, 17 insertions, 16 deletions
diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs index 8d12d728f7c..8a773899cfc 100644 --- a/crates/hir-def/src/body/lower.rs +++ b/crates/hir-def/src/body/lower.rs @@ -973,10 +973,10 @@ impl ExprCollector<'_> { block: ast::BlockExpr, mk_block: impl FnOnce(Option<BlockId>, Box<[Statement]>, Option<ExprId>) -> Expr, ) -> ExprId { - 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 block_id = if ItemTree::block_has_items(self.db, ast_id.file_id, &block) { + 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 ast_id = AstId::new(self.expander.current_file_id, file_local_id); Some(self.db.intern_block(BlockLoc { ast_id, module: self.expander.def_map.module_id(self.expander.module), diff --git a/crates/hir-def/src/data.rs b/crates/hir-def/src/data.rs index 9d368911a4c..de1e10ae2b0 100644 --- a/crates/hir-def/src/data.rs +++ b/crates/hir-def/src/data.rs @@ -30,7 +30,7 @@ use crate::{ #[derive(Debug, Clone, PartialEq, Eq)] pub struct FunctionData { pub name: Name, - pub params: Vec<(Option<Name>, Interned<TypeRef>)>, + pub params: Vec<Interned<TypeRef>>, pub ret_type: Interned<TypeRef>, pub attrs: Attrs, pub visibility: RawVisibility, @@ -100,7 +100,7 @@ impl FunctionData { params: enabled_params .clone() .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, }) .collect(), diff --git a/crates/hir-def/src/generics.rs b/crates/hir-def/src/generics.rs index 354b8fd0af4..4285a0ca72c 100644 --- a/crates/hir-def/src/generics.rs +++ b/crates/hir-def/src/generics.rs @@ -176,7 +176,7 @@ impl GenericParams { // Don't create an `Expander` nor call `loc.source(db)` if not needed since this // causes a reparse after the `ItemTree` has been created. 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); } diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs index 76fd3effc05..c34b24bee82 100644 --- a/crates/hir-ty/src/infer.rs +++ b/crates/hir-ty/src/infer.rs @@ -618,7 +618,7 @@ impl<'a> InferenceContext<'a> { let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver) .with_impl_trait_mode(ImplTraitLoweringMode::Param); 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 // that are collected from the function data if data.is_varargs() { diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index c4326f98cd7..d69fd8c8110 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -1634,7 +1634,7 @@ fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig { let ctx_params = TyLoweringContext::new(db, &resolver) .with_impl_trait_mode(ImplTraitLoweringMode::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) .with_impl_trait_mode(ImplTraitLoweringMode::Opaque) .with_type_param_mode(ParamLoweringMode::Variable); diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 7cb29114d7f..49165ca70ec 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -8,6 +8,7 @@ use hir_def::{ type_ref::{TypeBound, TypeRef}, AdtId, GenericDefId, }; +use hir_expand::name; use hir_ty::{ display::{ write_bounds_like_dyn_trait_with_prefix, write_visibility, HirDisplay, HirDisplayError, @@ -76,22 +77,22 @@ impl HirDisplay for Function { }; 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 { f.write_str(", ")?; } else { first = false; - if data.has_self_param() { + if local == Some(name!(self)) { write_self_param(type_ref, f)?; continue; } } - match name { + match local { Some(name) => write!(f, "{name}: ")?, 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)?; } diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index a355ea16422..fad9f19d253 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1844,7 +1844,7 @@ impl Param { } 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> { @@ -1885,7 +1885,7 @@ impl SelfParam { func_data .params .first() - .map(|(_, param)| match &**param { + .map(|param| match &**param { TypeRef::Reference(.., mutability) => match mutability { hir_def::type_ref::Mutability::Shared => Access::Shared, hir_def::type_ref::Mutability::Mut => Access::Exclusive, |
