mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
feat: IDE features for primitive tuple fields
This commit is contained in:
parent
59457091bb
commit
963568b46f
25 changed files with 242 additions and 96 deletions
|
@ -55,7 +55,7 @@ use hir_def::{
|
|||
AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId, CrateRootModuleId, DefWithBodyId,
|
||||
EnumId, EnumVariantId, ExternCrateId, FunctionId, GenericDefId, GenericParamId, HasModule,
|
||||
ImplId, InTypeConstId, ItemContainerId, LifetimeParamId, LocalEnumVariantId, LocalFieldId,
|
||||
Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId, TraitAliasId, TraitId,
|
||||
Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId, TraitAliasId, TraitId, TupleId,
|
||||
TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
|
||||
};
|
||||
use hir_expand::{attrs::collect_attrs, name::name, proc_macro::ProcMacroKind, MacroCallKind};
|
||||
|
@ -1038,6 +1038,29 @@ pub struct Field {
|
|||
pub(crate) id: LocalFieldId,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
|
||||
pub struct TupleField {
|
||||
pub owner: DefWithBodyId,
|
||||
pub tuple: TupleId,
|
||||
pub index: u32,
|
||||
}
|
||||
|
||||
impl TupleField {
|
||||
pub fn name(&self) -> Name {
|
||||
Name::new_tuple_field(self.index as usize)
|
||||
}
|
||||
|
||||
pub fn ty(&self, db: &dyn HirDatabase) -> Type {
|
||||
let ty = db.infer(self.owner).tuple_field_access_types[&self.tuple]
|
||||
.as_slice(Interner)
|
||||
.get(self.index as usize)
|
||||
.and_then(|arg| arg.ty(Interner))
|
||||
.cloned()
|
||||
.unwrap_or_else(|| TyKind::Error.intern(Interner));
|
||||
Type { env: db.trait_environment_for_body(self.owner), ty }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum FieldSource {
|
||||
Named(ast::RecordField),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue