|
1 | 1 | //! Miscellaneous type-system utilities that are too small to deserve their own modules. |
2 | 2 |
|
3 | | -use crate::hir::def::Def; |
| 3 | +use crate::hir; |
4 | 4 | use crate::hir::def_id::DefId; |
5 | 5 | use crate::hir::map::DefPathData; |
6 | | -use crate::hir::{self, Node}; |
7 | 6 | use crate::mir::interpret::{sign_extend, truncate}; |
8 | 7 | use crate::ich::NodeIdHashingMode; |
9 | 8 | use crate::traits::{self, ObligationCause}; |
@@ -613,34 +612,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { |
613 | 612 | }) |
614 | 613 | } |
615 | 614 |
|
616 | | - /// Returns `true` if the node pointed to by `def_id` is a static item, and its mutability. |
617 | | - pub fn is_static(&self, def_id: DefId) -> Option<hir::Mutability> { |
618 | | - if let Some(node) = self.hir().get_if_local(def_id) { |
619 | | - match node { |
620 | | - Node::Item(&hir::Item { |
621 | | - node: hir::ItemKind::Static(_, mutbl, _), .. |
622 | | - }) => Some(mutbl), |
623 | | - Node::ForeignItem(&hir::ForeignItem { |
624 | | - node: hir::ForeignItemKind::Static(_, is_mutbl), .. |
625 | | - }) => |
626 | | - Some(if is_mutbl { |
627 | | - hir::Mutability::MutMutable |
628 | | - } else { |
629 | | - hir::Mutability::MutImmutable |
630 | | - }), |
631 | | - _ => None |
632 | | - } |
633 | | - } else { |
634 | | - match self.describe_def(def_id) { |
635 | | - Some(Def::Static(_, is_mutbl)) => |
636 | | - Some(if is_mutbl { |
637 | | - hir::Mutability::MutMutable |
638 | | - } else { |
639 | | - hir::Mutability::MutImmutable |
640 | | - }), |
641 | | - _ => None |
642 | | - } |
643 | | - } |
| 615 | + /// Returns `true` if the node pointed to by `def_id` is a `static` item. |
| 616 | + pub fn is_static(&self, def_id: DefId) -> bool { |
| 617 | + self.static_mutability(def_id).is_some() |
| 618 | + } |
| 619 | + |
| 620 | + /// Returns `true` if the node pointed to by `def_id` is a mutable `static` item. |
| 621 | + pub fn is_mutable_static(&self, def_id: DefId) -> bool { |
| 622 | + self.static_mutability(def_id) == Some(hir::MutMutable) |
644 | 623 | } |
645 | 624 |
|
646 | 625 | /// Expands the given impl trait type, stopping if the type is recursive. |
|
0 commit comments