aboutsummaryrefslogtreecommitdiff
path: root/crates/hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir')
-rw-r--r--crates/hir/src/lib.rs50
1 files changed, 15 insertions, 35 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index d5a3d9034..58adc8fd3 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -305,7 +305,6 @@ impl ModuleDef {
305 ModuleDef::Module(it) => it.name(db), 305 ModuleDef::Module(it) => it.name(db),
306 ModuleDef::Const(it) => it.name(db), 306 ModuleDef::Const(it) => it.name(db),
307 ModuleDef::Static(it) => it.name(db), 307 ModuleDef::Static(it) => it.name(db),
308
309 ModuleDef::BuiltinType(it) => Some(it.name()), 308 ModuleDef::BuiltinType(it) => Some(it.name()),
310 } 309 }
311 } 310 }
@@ -535,7 +534,7 @@ pub struct Struct {
535 534
536impl Struct { 535impl Struct {
537 pub fn module(self, db: &dyn HirDatabase) -> Module { 536 pub fn module(self, db: &dyn HirDatabase) -> Module {
538 Module { id: self.id.lookup(db.upcast()).container.module(db.upcast()) } 537 Module { id: self.id.lookup(db.upcast()).container }
539 } 538 }
540 539
541 pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { 540 pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
@@ -556,11 +555,7 @@ impl Struct {
556 } 555 }
557 556
558 pub fn ty(self, db: &dyn HirDatabase) -> Type { 557 pub fn ty(self, db: &dyn HirDatabase) -> Type {
559 Type::from_def( 558 Type::from_def(db, self.id.lookup(db.upcast()).container.krate(), self.id)
560 db,
561 self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
562 self.id,
563 )
564 } 559 }
565 560
566 pub fn repr(self, db: &dyn HirDatabase) -> Option<ReprKind> { 561 pub fn repr(self, db: &dyn HirDatabase) -> Option<ReprKind> {
@@ -587,15 +582,11 @@ impl Union {
587 } 582 }
588 583
589 pub fn module(self, db: &dyn HirDatabase) -> Module { 584 pub fn module(self, db: &dyn HirDatabase) -> Module {
590 Module { id: self.id.lookup(db.upcast()).container.module(db.upcast()) } 585 Module { id: self.id.lookup(db.upcast()).container }
591 } 586 }
592 587
593 pub fn ty(self, db: &dyn HirDatabase) -> Type { 588 pub fn ty(self, db: &dyn HirDatabase) -> Type {
594 Type::from_def( 589 Type::from_def(db, self.id.lookup(db.upcast()).container.krate(), self.id)
595 db,
596 self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
597 self.id,
598 )
599 } 590 }
600 591
601 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> { 592 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
@@ -619,7 +610,7 @@ pub struct Enum {
619 610
620impl Enum { 611impl Enum {
621 pub fn module(self, db: &dyn HirDatabase) -> Module { 612 pub fn module(self, db: &dyn HirDatabase) -> Module {
622 Module { id: self.id.lookup(db.upcast()).container.module(db.upcast()) } 613 Module { id: self.id.lookup(db.upcast()).container }
623 } 614 }
624 615
625 pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { 616 pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
@@ -635,11 +626,7 @@ impl Enum {
635 } 626 }
636 627
637 pub fn ty(self, db: &dyn HirDatabase) -> Type { 628 pub fn ty(self, db: &dyn HirDatabase) -> Type {
638 Type::from_def( 629 Type::from_def(db, self.id.lookup(db.upcast()).container.krate(), self.id)
639 db,
640 self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
641 self.id,
642 )
643 } 630 }
644} 631}
645 632
@@ -1001,7 +988,7 @@ pub struct Trait {
1001 988
1002impl Trait { 989impl Trait {
1003 pub fn module(self, db: &dyn HirDatabase) -> Module { 990 pub fn module(self, db: &dyn HirDatabase) -> Module {
1004 Module { id: self.id.lookup(db.upcast()).container.module(db.upcast()) } 991 Module { id: self.id.lookup(db.upcast()).container }
1005 } 992 }
1006 993
1007 pub fn name(self, db: &dyn HirDatabase) -> Name { 994 pub fn name(self, db: &dyn HirDatabase) -> Name {
@@ -1157,7 +1144,7 @@ where
1157{ 1144{
1158 match id.lookup(db.upcast()).container { 1145 match id.lookup(db.upcast()).container {
1159 AssocContainerId::TraitId(_) | AssocContainerId::ImplId(_) => Some(ctor(DEF::from(id))), 1146 AssocContainerId::TraitId(_) | AssocContainerId::ImplId(_) => Some(ctor(DEF::from(id))),
1160 AssocContainerId::ContainerId(_) => None, 1147 AssocContainerId::ModuleId(_) => None,
1161 } 1148 }
1162} 1149}
1163 1150
@@ -1185,7 +1172,7 @@ impl AssocItem {
1185 match container { 1172 match container {
1186 AssocContainerId::TraitId(id) => AssocItemContainer::Trait(id.into()), 1173 AssocContainerId::TraitId(id) => AssocItemContainer::Trait(id.into()),
1187 AssocContainerId::ImplId(id) => AssocItemContainer::Impl(id.into()), 1174 AssocContainerId::ImplId(id) => AssocItemContainer::Impl(id.into()),
1188 AssocContainerId::ContainerId(_) => panic!("invalid AssocItem"), 1175 AssocContainerId::ModuleId(_) => panic!("invalid AssocItem"),
1189 } 1176 }
1190 } 1177 }
1191 1178
@@ -1296,13 +1283,7 @@ impl Local {
1296 1283
1297 pub fn is_mut(self, db: &dyn HirDatabase) -> bool { 1284 pub fn is_mut(self, db: &dyn HirDatabase) -> bool {
1298 let body = db.body(self.parent.into()); 1285 let body = db.body(self.parent.into());
1299 match &body[self.pat_id] { 1286 matches!(&body[self.pat_id], Pat::Bind { mode: BindingAnnotation::Mutable, .. })
1300 Pat::Bind { mode, .. } => match mode {
1301 BindingAnnotation::Mutable | BindingAnnotation::RefMut => true,
1302 _ => false,
1303 },
1304 _ => false,
1305 }
1306 } 1287 }
1307 1288
1308 pub fn parent(self, _db: &dyn HirDatabase) -> DefWithBody { 1289 pub fn parent(self, _db: &dyn HirDatabase) -> DefWithBody {
@@ -1516,7 +1497,7 @@ impl Impl {
1516 pub fn target_ty(self, db: &dyn HirDatabase) -> Type { 1497 pub fn target_ty(self, db: &dyn HirDatabase) -> Type {
1517 let impl_data = db.impl_data(self.id); 1498 let impl_data = db.impl_data(self.id);
1518 let resolver = self.id.resolver(db.upcast()); 1499 let resolver = self.id.resolver(db.upcast());
1519 let krate = self.id.lookup(db.upcast()).container.module(db.upcast()).krate(); 1500 let krate = self.id.lookup(db.upcast()).container.krate();
1520 let ctx = hir_ty::TyLoweringContext::new(db, &resolver); 1501 let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
1521 let ty = Ty::from_hir(&ctx, &impl_data.target_type); 1502 let ty = Ty::from_hir(&ctx, &impl_data.target_type);
1522 Type::new_with_resolver_inner(db, krate, &resolver, ty) 1503 Type::new_with_resolver_inner(db, krate, &resolver, ty)
@@ -1531,7 +1512,7 @@ impl Impl {
1531 } 1512 }
1532 1513
1533 pub fn module(self, db: &dyn HirDatabase) -> Module { 1514 pub fn module(self, db: &dyn HirDatabase) -> Module {
1534 self.id.lookup(db.upcast()).container.module(db.upcast()).into() 1515 self.id.lookup(db.upcast()).container.into()
1535 } 1516 }
1536 1517
1537 pub fn krate(self, db: &dyn HirDatabase) -> Crate { 1518 pub fn krate(self, db: &dyn HirDatabase) -> Crate {
@@ -1614,10 +1595,9 @@ impl Type {
1614 } 1595 }
1615 1596
1616 pub fn remove_ref(&self) -> Option<Type> { 1597 pub fn remove_ref(&self) -> Option<Type> {
1617 if let Ty::Ref(.., substs) = &self.ty.value { 1598 match &self.ty.value {
1618 Some(self.derived(substs[0].clone())) 1599 Ty::Ref(.., substs) => Some(self.derived(substs[0].clone())),
1619 } else { 1600 _ => None,
1620 None
1621 } 1601 }
1622 } 1602 }
1623 1603