Auto merge of #101228 - nnethercote:simplify-hir-PathSegment, r=petrochenkov
Simplify `hir::PathSegment` r? `@petrochenkov`
This commit is contained in:
commit
2dc703fd6e
28 changed files with 172 additions and 194 deletions
|
@ -308,6 +308,7 @@ pub enum Res<Id = hir::HirId> {
|
|||
///
|
||||
/// **Belongs to the type namespace.**
|
||||
PrimTy(hir::PrimTy),
|
||||
|
||||
/// The `Self` type, optionally with the [`DefId`] of the trait it belongs to and
|
||||
/// optionally with the [`DefId`] of the item introducing the `Self` type alias.
|
||||
///
|
||||
|
@ -355,7 +356,8 @@ pub enum Res<Id = hir::HirId> {
|
|||
/// const fn baz<T>() -> usize { 10 }
|
||||
/// ```
|
||||
/// We do however allow `Self` in repeat expression even if it is generic to not break code
|
||||
/// which already works on stable while causing the `const_evaluatable_unchecked` future compat lint:
|
||||
/// which already works on stable while causing the `const_evaluatable_unchecked` future compat
|
||||
/// lint:
|
||||
/// ```
|
||||
/// fn foo<T>() {
|
||||
/// let _bar = [1_u8; std::mem::size_of::<*mut T>()];
|
||||
|
@ -370,6 +372,7 @@ pub enum Res<Id = hir::HirId> {
|
|||
/// from mentioning generics (i.e. when used in an anonymous constant).
|
||||
alias_to: Option<(DefId, bool)>,
|
||||
},
|
||||
|
||||
/// A tool attribute module; e.g., the `rustfmt` in `#[rustfmt::skip]`.
|
||||
///
|
||||
/// **Belongs to the type namespace.**
|
||||
|
@ -383,6 +386,7 @@ pub enum Res<Id = hir::HirId> {
|
|||
///
|
||||
/// *See also [`Res::SelfTy`].*
|
||||
SelfCtor(DefId),
|
||||
|
||||
/// A local variable or function parameter.
|
||||
///
|
||||
/// **Belongs to the value namespace.**
|
||||
|
|
|
@ -202,13 +202,8 @@ impl Path<'_> {
|
|||
pub struct PathSegment<'hir> {
|
||||
/// The identifier portion of this path segment.
|
||||
pub ident: Ident,
|
||||
// `id` and `res` are optional. We currently only use these in save-analysis,
|
||||
// any path segments without these will not have save-analysis info and
|
||||
// therefore will not have 'jump to def' in IDEs, but otherwise will not be
|
||||
// affected. (In general, we don't bother to get the defs for synthesized
|
||||
// segments, only for segments which have come from the AST).
|
||||
pub hir_id: Option<HirId>,
|
||||
pub res: Option<Res>,
|
||||
pub hir_id: HirId,
|
||||
pub res: Res,
|
||||
|
||||
/// Type/lifetime parameters attached to this path. They come in
|
||||
/// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`. Note that
|
||||
|
@ -226,12 +221,12 @@ pub struct PathSegment<'hir> {
|
|||
|
||||
impl<'hir> PathSegment<'hir> {
|
||||
/// Converts an identifier to the corresponding segment.
|
||||
pub fn from_ident(ident: Ident) -> PathSegment<'hir> {
|
||||
PathSegment { ident, hir_id: None, res: None, infer_args: true, args: None }
|
||||
pub fn new(ident: Ident, hir_id: HirId, res: Res) -> PathSegment<'hir> {
|
||||
PathSegment { ident, hir_id, res, infer_args: true, args: None }
|
||||
}
|
||||
|
||||
pub fn invalid() -> Self {
|
||||
Self::from_ident(Ident::empty())
|
||||
Self::new(Ident::empty(), HirId::INVALID, Res::Err)
|
||||
}
|
||||
|
||||
pub fn args(&self) -> &GenericArgs<'hir> {
|
||||
|
|
|
@ -20,6 +20,9 @@ pub struct HirId {
|
|||
}
|
||||
|
||||
impl HirId {
|
||||
/// Signal local id which should never be used.
|
||||
pub const INVALID: HirId = HirId { owner: CRATE_DEF_ID, local_id: ItemLocalId::INVALID };
|
||||
|
||||
#[inline]
|
||||
pub fn expect_owner(self) -> LocalDefId {
|
||||
assert_eq!(self.local_id.index(), 0);
|
||||
|
|
|
@ -724,7 +724,7 @@ pub fn walk_path_segment<'v, V: Visitor<'v>>(
|
|||
segment: &'v PathSegment<'v>,
|
||||
) {
|
||||
visitor.visit_ident(segment.ident);
|
||||
walk_list!(visitor, visit_id, segment.hir_id);
|
||||
visitor.visit_id(segment.hir_id);
|
||||
if let Some(ref args) = segment.args {
|
||||
visitor.visit_generic_args(path_span, args);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue