1
Fork 0

Do not store visibility in *ItemRef.

This commit is contained in:
Camille GILLOT 2021-07-15 22:19:39 +02:00
parent 5ecc8ad846
commit d7795d302a
16 changed files with 49 additions and 70 deletions

View file

@ -55,7 +55,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
0,
ParenthesizedGenericArgs::Err,
ImplTraitContext::disallowed(),
None,
));
let args = self.lower_exprs(args);
hir::ExprKind::MethodCall(

View file

@ -188,7 +188,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
pub fn lower_item(&mut self, i: &Item) -> hir::Item<'hir> {
let mut ident = i.ident;
let mut vis = self.lower_visibility(&i.vis, None);
let mut vis = self.lower_visibility(&i.vis);
let hir_id = self.lower_node_id(i.id);
let attrs = self.lower_attrs(hir_id, &i.attrs);
let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, &mut vis, &i.kind);
@ -493,7 +493,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.with_hir_id_owner(new_node_id, |this| {
let res = this.lower_res(res);
let path = this.lower_path_extra(res, &path, ParamMode::Explicit, None);
let path = this.lower_path_extra(res, &path, ParamMode::Explicit);
let kind = hir::ItemKind::Use(path, hir::UseKind::Single);
let vis = this.rebuild_vis(&vis);
if let Some(attrs) = attrs {
@ -510,7 +510,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
});
}
let path = self.lower_path_extra(ret_res, &path, ParamMode::Explicit, None);
let path = self.lower_path_extra(ret_res, &path, ParamMode::Explicit);
hir::ItemKind::Use(path, hir::UseKind::Single)
}
UseTreeKind::Glob => {
@ -610,7 +610,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let res = self.expect_full_res_from_use(id).next().unwrap_or(Res::Err);
let res = self.lower_res(res);
let path = self.lower_path_extra(res, &prefix, ParamMode::Explicit, None);
let path = self.lower_path_extra(res, &prefix, ParamMode::Explicit);
hir::ItemKind::Use(path, hir::UseKind::ListStem)
}
}
@ -679,17 +679,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
ForeignItemKind::MacCall(_) => panic!("macro shouldn't exist here"),
},
vis: self.lower_visibility(&i.vis, None),
vis: self.lower_visibility(&i.vis),
span: self.lower_span(i.span),
}
}
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef<'hir> {
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef {
hir::ForeignItemRef {
id: hir::ForeignItemId { def_id: self.allocate_hir_id_counter(i.id) },
ident: self.lower_ident(i.ident),
span: self.lower_span(i.span),
vis: self.lower_visibility(&i.vis, Some(i.id)),
}
}
@ -757,7 +756,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// FIXME(jseyfried): positional field hygiene.
None => Ident::new(sym::integer(index), self.lower_span(f.span)),
},
vis: self.lower_visibility(&f.vis, None),
vis: self.lower_visibility(&f.vis),
ty,
}
}
@ -899,14 +898,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
def_id: hir_id.expect_owner(),
ident: self.lower_ident(i.ident),
generics,
vis: self.lower_visibility(&i.vis, None),
vis: self.lower_visibility(&i.vis),
defaultness,
kind,
span: self.lower_span(i.span),
}
}
fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef<'hir> {
fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef {
// Since `default impl` is not yet implemented, this is always true in impls.
let has_value = true;
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
@ -914,7 +913,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
id: hir::ImplItemId { def_id: self.allocate_hir_id_counter(i.id) },
ident: self.lower_ident(i.ident),
span: self.lower_span(i.span),
vis: self.lower_visibility(&i.vis, Some(i.id)),
defaultness,
kind: match &i.kind {
AssocItemKind::Const(..) => hir::AssocItemKind::Const,
@ -932,25 +930,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
/// lowered. This can happen during `lower_impl_item_ref()` where we need to
/// lower a `Visibility` value although we haven't lowered the owning
/// `ImplItem` in question yet.
fn lower_visibility(
&mut self,
v: &Visibility,
explicit_owner: Option<NodeId>,
) -> hir::Visibility<'hir> {
fn lower_visibility(&mut self, v: &Visibility) -> hir::Visibility<'hir> {
let node = match v.kind {
VisibilityKind::Public => hir::VisibilityKind::Public,
VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
VisibilityKind::Restricted { ref path, id } => {
debug!("lower_visibility: restricted path id = {:?}", id);
let lowered_id = if let Some(owner) = explicit_owner {
self.lower_node_id_with_owner(id, owner)
} else {
self.lower_node_id(id)
};
let res = self.expect_full_res(id);
let res = self.lower_res(res);
let lowered_id = self.lower_node_id(id);
hir::VisibilityKind::Restricted {
path: self.lower_path_extra(res, path, ParamMode::Explicit, explicit_owner),
path: self.lower_path(id, path, ParamMode::Explicit),
hir_id: lowered_id,
}
}

View file

@ -99,7 +99,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
num_lifetimes,
parenthesized_generic_args,
itctx.reborrow(),
None,
)
},
)),
@ -147,7 +146,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
0,
ParenthesizedGenericArgs::Err,
itctx.reborrow(),
None,
));
let qpath = hir::QPath::TypeRelative(ty, hir_segment);
@ -178,7 +176,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
res: Res,
p: &Path,
param_mode: ParamMode,
explicit_owner: Option<NodeId>,
) -> &'hir hir::Path<'hir> {
self.arena.alloc(hir::Path {
res,
@ -190,7 +187,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
0,
ParenthesizedGenericArgs::Err,
ImplTraitContext::disallowed(),
explicit_owner,
)
})),
span: self.lower_span(p.span),
@ -205,7 +201,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
) -> &'hir hir::Path<'hir> {
let res = self.expect_full_res(id);
let res = self.lower_res(res);
self.lower_path_extra(res, p, param_mode, None)
self.lower_path_extra(res, p, param_mode)
}
crate fn lower_path_segment(
@ -216,7 +212,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
expected_lifetimes: usize,
parenthesized_generic_args: ParenthesizedGenericArgs,
itctx: ImplTraitContext<'_, 'hir>,
explicit_owner: Option<NodeId>,
) -> hir::PathSegment<'hir> {
debug!(
"path_span: {:?}, lower_path_segment(segment: {:?}, expected_lifetimes: {:?})",
@ -354,11 +349,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
let res = self.expect_full_res(segment.id);
let id = if let Some(owner) = explicit_owner {
self.lower_node_id_with_owner(segment.id, owner)
} else {
self.lower_node_id(segment.id)
};
let id = self.lower_node_id(segment.id);
debug!(
"lower_path_segment: ident={:?} original-id={:?} new-id={:?}",
segment.ident, segment.id, id,