mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Merge #7021
7021: Track labels in the HIR r=matklad a=Veykril Groundwork for #6966 Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
06320015af
9 changed files with 167 additions and 68 deletions
|
@ -9,7 +9,7 @@ use hir_def::{
|
|||
adt::StructKind,
|
||||
adt::VariantData,
|
||||
builtin_type::BuiltinType,
|
||||
expr::{BindingAnnotation, Pat, PatId},
|
||||
expr::{BindingAnnotation, LabelId, Pat, PatId},
|
||||
import_map,
|
||||
item_tree::ItemTreeNode,
|
||||
lang_item::LangItemTarget,
|
||||
|
@ -1205,6 +1205,34 @@ impl Local {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Label {
|
||||
pub(crate) parent: DefWithBodyId,
|
||||
pub(crate) label_id: LabelId,
|
||||
}
|
||||
|
||||
impl Label {
|
||||
pub fn module(self, db: &dyn HirDatabase) -> Module {
|
||||
self.parent(db).module(db)
|
||||
}
|
||||
|
||||
pub fn parent(self, _db: &dyn HirDatabase) -> DefWithBody {
|
||||
self.parent.into()
|
||||
}
|
||||
|
||||
pub fn name(self, db: &dyn HirDatabase) -> Name {
|
||||
let body = db.body(self.parent.into());
|
||||
body[self.label_id].name.clone()
|
||||
}
|
||||
|
||||
pub fn source(self, db: &dyn HirDatabase) -> InFile<ast::Label> {
|
||||
let (_body, source_map) = db.body_with_source_map(self.parent.into());
|
||||
let src = source_map.label_syntax(self.label_id);
|
||||
let root = src.file_syntax(db.upcast());
|
||||
src.map(|ast| ast.to_node(&root))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum GenericParam {
|
||||
TypeParam(TypeParam),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue