X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_resolve%2Fsrc%2Fbuild_reduced_graph.rs;h=81b67b758f7e12393262b31a362252a180032a29;hb=d5b86d5ee912407aef6af3a152a94bde70bacb7a;hp=51e8c24b9c25a51066088753bf4ec5b00a261798;hpb=8521a8c92da6c0c845d4f6394e903651a227946a;p=rust.git diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 51e8c24b9c2..81b67b758f7 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -39,24 +39,26 @@ type Res = def::Res; -impl<'a> ToNameBinding<'a> for (Module<'a>, ty::Visibility, Span, LocalExpnId) { +impl<'a, Id: Into> ToNameBinding<'a> + for (Module<'a>, ty::Visibility, Span, LocalExpnId) +{ fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> { arenas.alloc_name_binding(NameBinding { kind: NameBindingKind::Module(self.0), ambiguity: None, - vis: self.1, + vis: self.1.to_def_id(), span: self.2, expansion: self.3, }) } } -impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, LocalExpnId) { +impl<'a, Id: Into> ToNameBinding<'a> for (Res, ty::Visibility, Span, LocalExpnId) { fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> { arenas.alloc_name_binding(NameBinding { kind: NameBindingKind::Res(self.0, false), ambiguity: None, - vis: self.1, + vis: self.1.to_def_id(), span: self.2, expansion: self.3, }) @@ -70,7 +72,7 @@ fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> arenas.alloc_name_binding(NameBinding { kind: NameBindingKind::Res(self.0, true), ambiguity: None, - vis: self.1, + vis: self.1.to_def_id(), span: self.2, expansion: self.3, }) @@ -260,7 +262,9 @@ fn try_resolve_visibility<'ast>( self.r.visibilities[&def_id.expect_local()] } // Otherwise, the visibility is restricted to the nearest parent `mod` item. - _ => ty::Visibility::Restricted(self.parent_scope.module.nearest_parent_mod()), + _ => ty::Visibility::Restricted( + self.parent_scope.module.nearest_parent_mod().expect_local(), + ), }) } ast::VisibilityKind::Restricted { ref path, id, .. } => { @@ -311,7 +315,7 @@ fn try_resolve_visibility<'ast>( } else { let vis = ty::Visibility::Restricted(res.def_id()); if self.r.is_accessible_from(vis, parent_scope.module) { - Ok(vis) + Ok(vis.expect_local()) } else { Err(VisResolutionError::AncestorOnly(path.span)) } @@ -649,7 +653,9 @@ fn build_reduced_graph_for_use_tree( true, // The whole `use` item item, - ty::Visibility::Restricted(self.parent_scope.module.nearest_parent_mod()), + ty::Visibility::Restricted( + self.parent_scope.module.nearest_parent_mod().expect_local(), + ), root_span, ); } @@ -765,10 +771,10 @@ fn build_reduced_graph_for_item(&mut self, item: &'b Item) { if let Some(ctor_node_id) = vdata.ctor_id() { // If the structure is marked as non_exhaustive then lower the visibility // to within the crate. - let mut ctor_vis = if vis == ty::Visibility::Public + let mut ctor_vis = if vis.is_public() && self.r.session.contains_name(&item.attrs, sym::non_exhaustive) { - ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()) + ty::Visibility::Restricted(CRATE_DEF_ID) } else { vis }; @@ -785,7 +791,7 @@ fn build_reduced_graph_for_item(&mut self, item: &'b Item) { if ctor_vis.is_at_least(field_vis, &*self.r) { ctor_vis = field_vis; } - ret_fields.push(field_vis); + ret_fields.push(field_vis.to_def_id()); } let ctor_def_id = self.r.local_def_id(ctor_node_id); let ctor_res = Res::Def( @@ -795,7 +801,9 @@ fn build_reduced_graph_for_item(&mut self, item: &'b Item) { self.r.define(parent, ident, ValueNS, (ctor_res, ctor_vis, sp, expansion)); self.r.visibilities.insert(ctor_def_id, ctor_vis); - self.r.struct_constructors.insert(def_id, (ctor_res, ctor_vis, ret_fields)); + self.r + .struct_constructors + .insert(def_id, (ctor_res, ctor_vis.to_def_id(), ret_fields)); } } @@ -867,8 +875,8 @@ fn build_reduced_graph_for_extern_crate( } .map(|module| { let used = self.process_macro_use_imports(item, module); - let binding = - (module, ty::Visibility::Public, sp, expansion).to_name_binding(self.r.arenas); + let vis = ty::Visibility::::Public; + let binding = (module, vis, sp, expansion).to_name_binding(self.r.arenas); (used, Some(ModuleOrUniformRoot::Module(module)), binding) }) .unwrap_or((true, None, self.r.dummy_binding)); @@ -964,6 +972,7 @@ fn build_reduced_graph_for_external_crate_res(&mut self, child: ModChild) { | DefKind::TyAlias | DefKind::ForeignTy | DefKind::OpaqueTy + | DefKind::ImplTraitPlaceholder | DefKind::TraitAlias | DefKind::AssocTy, _, @@ -1117,7 +1126,7 @@ fn process_macro_use_imports(&mut self, item: &Item, module: Module<'a>) -> bool root_span: span, span, module_path: Vec::new(), - vis: Cell::new(Some(ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()))), + vis: Cell::new(Some(ty::Visibility::Restricted(CRATE_DEF_ID))), used: Cell::new(false), }) }; @@ -1263,7 +1272,7 @@ fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'a> { let vis = if is_macro_export { ty::Visibility::Public } else { - ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()) + ty::Visibility::Restricted(CRATE_DEF_ID) }; let binding = (res, vis, span, expansion).to_name_binding(self.r.arenas); self.r.set_binding_parent_module(binding, parent_scope.module); @@ -1294,7 +1303,7 @@ fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'a> { } _ => self.resolve_visibility(&item.vis), }; - if vis != ty::Visibility::Public { + if !vis.is_public() { self.insert_unused_macro(ident, def_id, item.id, &rule_spans); } self.r.define(module, ident, MacroNS, (res, vis, span, expansion)); @@ -1507,10 +1516,10 @@ fn visit_variant(&mut self, variant: &'b ast::Variant) { self.r.visibilities.insert(def_id, vis); // If the variant is marked as non_exhaustive then lower the visibility to within the crate. - let ctor_vis = if vis == ty::Visibility::Public + let ctor_vis = if vis.is_public() && self.r.session.contains_name(&variant.attrs, sym::non_exhaustive) { - ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()) + ty::Visibility::Restricted(CRATE_DEF_ID) } else { vis };