From dd3738a2ba63d6ba2d8359c90732c994abeaf4be Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 22 Oct 2018 01:28:59 +0300 Subject: [PATCH 1/6] resolve: Record full parent scope data for imports --- src/librustc_resolve/build_reduced_graph.rs | 41 ++++++++++-------- src/librustc_resolve/macros.rs | 9 ++-- src/librustc_resolve/resolve_imports.rs | 48 ++++++++++----------- 3 files changed, 52 insertions(+), 46 deletions(-) diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index a43a3c6ac5a60..c98ea76bfa65a 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -126,7 +126,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { mut uniform_paths_canary_emitted: bool, nested: bool, item: &Item, - expansion: Mark, + parent_scope: ParentScope<'a>, ) { debug!("build_reduced_graph_for_use_tree(parent_prefix={:?}, \ uniform_paths_canary_emitted={}, \ @@ -224,7 +224,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { root_use_tree.span, root_id, ty::Visibility::Invisible, - expansion, + parent_scope.clone(), true, // is_uniform_paths_canary ); }; @@ -354,7 +354,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { root_use_tree.span, root_id, vis, - expansion, + parent_scope, false, // is_uniform_paths_canary ); } @@ -371,7 +371,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { root_use_tree.span, root_id, vis, - expansion, + parent_scope, false, // is_uniform_paths_canary ); } @@ -409,7 +409,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { uniform_paths_canary_emitted, true, item, - expansion, + parent_scope.clone(), ); } } @@ -417,8 +417,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } /// Constructs the reduced graph for one item. - fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) { - let parent = self.current_module; + fn build_reduced_graph_for_item(&mut self, item: &Item, parent_scope: ParentScope<'a>) { + let parent = parent_scope.module; + let expansion = parent_scope.expansion; let ident = item.ident; let sp = item.span; let vis = self.resolve_visibility(&item.vis); @@ -435,7 +436,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { false, // uniform_paths_canary_emitted false, item, - expansion, + parent_scope, ); } @@ -448,7 +449,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { self.injected_crate = Some(module); } - let used = self.process_legacy_macro_imports(item, module, expansion); + let used = self.process_legacy_macro_imports(item, module, &parent_scope); let binding = (module, ty::Visibility::Public, sp, expansion).to_name_binding(self.arenas); if ptr::eq(self.current_module, self.graph_root) { @@ -473,7 +474,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { let directive = self.arenas.alloc_import_directive(ImportDirective { root_id: item.id, id: item.id, - parent, + parent_scope, imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))), subclass: ImportDirectiveSubclass::ExternCrate { source: orig_name, @@ -483,7 +484,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> { span: item.span, module_path: Vec::new(), vis: Cell::new(vis), - expansion, used: Cell::new(used), is_uniform_paths_canary: false, }); @@ -856,9 +856,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } // This returns true if we should consider the underlying `extern crate` to be used. - fn process_legacy_macro_imports(&mut self, item: &Item, module: Module<'a>, expansion: Mark) - -> bool { - let allow_shadowing = expansion == Mark::root(); + fn process_legacy_macro_imports(&mut self, item: &Item, module: Module<'a>, + parent_scope: &ParentScope<'a>) -> bool { + let allow_shadowing = parent_scope.expansion == Mark::root(); let legacy_imports = self.legacy_macro_imports(&item.attrs); let used = legacy_imports != LegacyMacroImports::default(); @@ -868,18 +868,17 @@ impl<'a, 'cl> Resolver<'a, 'cl> { "an `extern crate` loading macros must be at the crate root"); } - let (graph_root, arenas) = (self.graph_root, self.arenas); + let arenas = self.arenas; let macro_use_directive = |span| arenas.alloc_import_directive(ImportDirective { root_id: item.id, id: item.id, - parent: graph_root, + parent_scope: parent_scope.clone(), imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))), subclass: ImportDirectiveSubclass::MacroUse, root_span: span, span, module_path: Vec::new(), vis: Cell::new(ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX))), - expansion, used: Cell::new(false), is_uniform_paths_canary: false, }); @@ -1010,7 +1009,13 @@ impl<'a, 'b, 'cl> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b, 'cl> { let orig_current_module = self.resolver.current_module; let orig_current_legacy_scope = self.current_legacy_scope; - self.resolver.build_reduced_graph_for_item(item, self.expansion); + let parent_scope = ParentScope { + module: self.resolver.current_module, + expansion: self.expansion, + legacy: self.current_legacy_scope, + derives: Vec::new(), + }; + self.resolver.build_reduced_graph_for_item(item, parent_scope); visit::walk_item(self, item); self.resolver.current_module = orig_current_module; if !macro_use { diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 68b3a6be29282..6a9aaa4ea710c 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -43,7 +43,7 @@ use std::cell::Cell; use std::mem; use rustc_data_structures::sync::Lrc; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct InvocationData<'a> { def_index: DefIndex, /// Module in which the macro was invoked. @@ -70,6 +70,7 @@ impl<'a> InvocationData<'a> { /// Binding produced by a `macro_rules` item. /// Not modularized, can shadow previous legacy bindings, etc. +#[derive(Debug)] pub struct LegacyBinding<'a> { binding: &'a NameBinding<'a>, /// Legacy scope into which the `macro_rules` item was planted. @@ -82,7 +83,7 @@ pub struct LegacyBinding<'a> { /// (named or unnamed), or even further if it escapes with `#[macro_use]`. /// Some macro invocations need to introduce legacy scopes too because they /// potentially can expand into macro definitions. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub enum LegacyScope<'a> { /// Created when invocation data is allocated in the arena, /// must be replaced with a proper scope later. @@ -96,8 +97,8 @@ pub enum LegacyScope<'a> { Invocation(&'a InvocationData<'a>), } -/// Everything you need to resolve a macro path. -#[derive(Clone)] +/// Everything you need to resolve a macro or import path. +#[derive(Clone, Debug)] pub struct ParentScope<'a> { crate module: Module<'a>, crate expansion: Mark, diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 810aff7f9b0a8..2b1279ba202c6 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -16,6 +16,7 @@ use {NameBinding, NameBindingKind, ToNameBinding, PathResult, PrivacyError}; use {Resolver, Segment}; use {names_to_string, module_to_string}; use {resolve_error, ResolutionError}; +use macros::ParentScope; use rustc_data_structures::ptr_key::PtrKey; use rustc::ty; @@ -88,13 +89,12 @@ pub struct ImportDirective<'a> { /// Span of the *root* use tree (see `root_id`). pub root_span: Span, - pub parent: Module<'a>, + pub parent_scope: ParentScope<'a>, pub module_path: Vec, /// The resolution of `module_path`. pub imported_module: Cell>>, pub subclass: ImportDirectiveSubclass<'a>, pub vis: Cell, - pub expansion: Mark, pub used: Cell, /// Whether this import is a "canary" for the `uniform_paths` feature, @@ -307,8 +307,9 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { }; match self.resolve_ident_in_module(module, ident, ns, false, path_span) { Err(Determined) => continue, - Ok(binding) - if !self.is_accessible_from(binding.vis, single_import.parent) => continue, + Ok(binding) if !self.is_accessible_from( + binding.vis, single_import.parent_scope.module + ) => continue, Ok(_) | Err(Undetermined) => return Err(Undetermined), } } @@ -381,8 +382,9 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { match result { Err(Determined) => continue, - Ok(binding) - if !self.is_accessible_from(binding.vis, glob_import.parent) => continue, + Ok(binding) if !self.is_accessible_from( + binding.vis, glob_import.parent_scope.module + ) => continue, Ok(_) | Err(Undetermined) => return Err(Undetermined), } } @@ -400,11 +402,11 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { root_span: Span, root_id: NodeId, vis: ty::Visibility, - expansion: Mark, + parent_scope: ParentScope<'a>, is_uniform_paths_canary: bool) { - let current_module = self.current_module; + let current_module = parent_scope.module; let directive = self.arenas.alloc_import_directive(ImportDirective { - parent: current_module, + parent_scope, module_path, imported_module: Cell::new(None), subclass, @@ -413,7 +415,6 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { root_span, root_id, vis: Cell::new(vis), - expansion, used: Cell::new(false), is_uniform_paths_canary, }); @@ -431,7 +432,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { // We don't add prelude imports to the globs since they only affect lexical scopes, // which are not relevant to import resolution. GlobImport { is_prelude: true, .. } => {} - GlobImport { .. } => self.current_module.globs.borrow_mut().push(directive), + GlobImport { .. } => current_module.globs.borrow_mut().push(directive), _ => unreachable!(), } } @@ -462,7 +463,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { }, span: directive.span, vis, - expansion: directive.expansion, + expansion: directive.parent_scope.expansion, }) } @@ -568,12 +569,12 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { let scope = match ident.span.reverse_glob_adjust(module.expansion, directive.span.ctxt().modern()) { Some(Some(def)) => self.macro_def_scope(def), - Some(None) => directive.parent, + Some(None) => directive.parent_scope.module, None => continue, }; if self.is_accessible_from(binding.vis, scope) { let imported_binding = self.import(binding, directive); - let _ = self.try_define(directive.parent, ident, ns, imported_binding); + let _ = self.try_define(directive.parent_scope.module, ident, ns, imported_binding); } } @@ -587,7 +588,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { let dummy_binding = self.dummy_binding; let dummy_binding = self.import(dummy_binding, directive); self.per_ns(|this, ns| { - let _ = this.try_define(directive.parent, target, ns, dummy_binding); + let _ = this.try_define(directive.parent_scope.module, target, ns, dummy_binding); }); } } @@ -856,8 +857,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { Segment::names_to_string(&directive.module_path[..]), module_to_string(self.current_module).unwrap_or_else(|| "???".to_string())); - - self.current_module = directive.parent; + self.current_module = directive.parent_scope.module; let module = if let Some(module) = directive.imported_module.get() { module @@ -868,7 +868,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { directive.vis.set(ty::Visibility::Invisible); let result = self.resolve_path( Some(if directive.is_uniform_paths_canary { - ModuleOrUniformRoot::Module(directive.parent) + ModuleOrUniformRoot::Module(directive.parent_scope.module) } else { ModuleOrUniformRoot::UniformRoot(keywords::Invalid.name()) }), @@ -910,7 +910,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { return }; - let parent = directive.parent; + let parent = directive.parent_scope.module; match result[ns].get() { Err(Undetermined) => indeterminate = true, Err(Determined) => { @@ -942,12 +942,12 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { // If appropriate, returns an error to report. fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> Option<(Span, String)> { - self.current_module = directive.parent; + self.current_module = directive.parent_scope.module; let ImportDirective { ref module_path, span, .. } = *directive; let module_result = self.resolve_path( Some(if directive.is_uniform_paths_canary { - ModuleOrUniformRoot::Module(directive.parent) + ModuleOrUniformRoot::Module(directive.parent_scope.module) } else { ModuleOrUniformRoot::UniformRoot(keywords::Invalid.name()) }), @@ -995,7 +995,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { } if let ModuleOrUniformRoot::Module(module) = module { - if module.def_id() == directive.parent.def_id() { + if module.def_id() == directive.parent_scope.module.def_id() { // Importing a module into itself is not allowed. return Some((directive.span, "Cannot glob-import a module into itself.".to_string())); @@ -1189,7 +1189,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { if let Some(Def::Trait(_)) = module.def() { self.session.span_err(directive.span, "items in traits are not importable."); return; - } else if module.def_id() == directive.parent.def_id() { + } else if module.def_id() == directive.parent_scope.module.def_id() { return; } else if let GlobImport { is_prelude: true, .. } = directive.subclass { self.prelude = Some(module); @@ -1213,7 +1213,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { }; if self.is_accessible_from(binding.pseudo_vis(), scope) { let imported_binding = self.import(binding, directive); - let _ = self.try_define(directive.parent, ident, ns, imported_binding); + let _ = self.try_define(directive.parent_scope.module, ident, ns, imported_binding); } } From 171df347ff564ef4d406042227d071515e799113 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 26 Oct 2018 01:15:51 +0300 Subject: [PATCH 2/6] resolve: Refactor away `legacy_macro_imports`/`LegacyMacroImports` --- src/librustc_resolve/build_reduced_graph.rs | 68 +++++++++---------- .../macros/macro-use-all-and-none.stderr | 8 +++ 2 files changed, 39 insertions(+), 37 deletions(-) create mode 100644 src/test/run-pass/macros/macro-use-all-and-none.stderr diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index c98ea76bfa65a..6c7398e17530a 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -35,7 +35,7 @@ use syntax::ast::{Name, Ident}; use syntax::attr; use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId}; -use syntax::ast::{Mutability, StmtKind, TraitItem, TraitItemKind, Variant}; +use syntax::ast::{MetaItemKind, Mutability, StmtKind, TraitItem, TraitItemKind, Variant}; use syntax::ext::base::{MacroKind, SyntaxExtension}; use syntax::ext::base::Determinacy::Undetermined; use syntax::ext::hygiene::Mark; @@ -83,12 +83,6 @@ impl<'a> ToNameBinding<'a> for (Def, ty::Visibility, Span, Mark, IsMacroExport) } } -#[derive(Default, PartialEq, Eq)] -struct LegacyMacroImports { - import_all: Option, - imports: Vec<(Name, Span)>, -} - impl<'a, 'cl> Resolver<'a, 'cl> { /// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined; /// otherwise, reports an error. @@ -858,14 +852,32 @@ impl<'a, 'cl> Resolver<'a, 'cl> { // This returns true if we should consider the underlying `extern crate` to be used. fn process_legacy_macro_imports(&mut self, item: &Item, module: Module<'a>, parent_scope: &ParentScope<'a>) -> bool { - let allow_shadowing = parent_scope.expansion == Mark::root(); - let legacy_imports = self.legacy_macro_imports(&item.attrs); - let used = legacy_imports != LegacyMacroImports::default(); - - // `#[macro_use]` is only allowed at the crate root. - if self.current_module.parent.is_some() && used { - span_err!(self.session, item.span, E0468, - "an `extern crate` loading macros must be at the crate root"); + let mut import_all = None; + let mut single_imports = Vec::new(); + for attr in &item.attrs { + if attr.check_name("macro_use") { + if self.current_module.parent.is_some() { + span_err!(self.session, item.span, E0468, + "an `extern crate` loading macros must be at the crate root"); + } + let ill_formed = |span| span_err!(self.session, span, E0466, "bad macro import"); + match attr.meta() { + Some(meta) => match meta.node { + MetaItemKind::Word => { + import_all = Some(meta.span); + break; + } + MetaItemKind::List(nested_metas) => for nested_meta in nested_metas { + match nested_meta.word() { + Some(word) => single_imports.push((word.name(), word.span)), + None => ill_formed(nested_meta.span), + } + } + MetaItemKind::NameValue(..) => ill_formed(meta.span), + } + None => ill_formed(attr.span()), + } + } } let arenas = self.arenas; @@ -883,7 +895,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> { is_uniform_paths_canary: false, }); - if let Some(span) = legacy_imports.import_all { + let allow_shadowing = parent_scope.expansion == Mark::root(); + if let Some(span) = import_all { let directive = macro_use_directive(span); self.potentially_unused_imports.push(directive); module.for_each_child(|ident, ns, binding| if ns == MacroNS { @@ -891,7 +904,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { self.legacy_import_macro(ident.name, imported_binding, span, allow_shadowing); }); } else { - for (name, span) in legacy_imports.imports { + for (name, span) in single_imports.iter().cloned() { let ident = Ident::with_empty_ctxt(name); let result = self.resolve_ident_in_module( ModuleOrUniformRoot::Module(module), @@ -910,7 +923,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } } } - used + import_all.is_some() || !single_imports.is_empty() } // does this attribute list contain "macro_use"? @@ -936,25 +949,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> { false } - - fn legacy_macro_imports(&mut self, attrs: &[ast::Attribute]) -> LegacyMacroImports { - let mut imports = LegacyMacroImports::default(); - for attr in attrs { - if attr.check_name("macro_use") { - match attr.meta_item_list() { - Some(names) => for attr in names { - if let Some(word) = attr.word() { - imports.imports.push((word.name(), attr.span())); - } else { - span_err!(self.session, attr.span(), E0466, "bad macro import"); - } - }, - None => imports.import_all = Some(attr.span), - } - } - } - imports - } } pub struct BuildReducedGraphVisitor<'a, 'b: 'a, 'c: 'b> { diff --git a/src/test/run-pass/macros/macro-use-all-and-none.stderr b/src/test/run-pass/macros/macro-use-all-and-none.stderr new file mode 100644 index 0000000000000..fc4b33bafa40a --- /dev/null +++ b/src/test/run-pass/macros/macro-use-all-and-none.stderr @@ -0,0 +1,8 @@ +warning: unused attribute + --> $DIR/macro-use-all-and-none.rs:15:1 + | +LL | #[macro_use()] + | ^^^^^^^^^^^^^^ + | + = note: #[warn(unused_attributes)] on by default + From b45b4daba75eb6d48ebd86ac56c5ff29c3637a12 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 27 Oct 2018 16:46:48 +0300 Subject: [PATCH 3/6] resolve: Absolute paths may be undetermined on 2018 edition due to macro-expanded `extern crate` items adding names to extern prelude. --- src/librustc_resolve/resolve_imports.rs | 3 +++ ...n-prelude-extern-crate-absolute-expanded.rs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/test/ui/imports/extern-prelude-extern-crate-absolute-expanded.rs diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 2b1279ba202c6..2faed4ad5c994 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -226,6 +226,9 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { let module = self.get_module(binding.def().def_id()); self.populate_module_if_necessary(module); return Ok(binding); + } else if !self.graph_root.unresolved_invocations.borrow().is_empty() { + // Macro-expanded `extern crate`items still can add names to extern prelude. + return Err(Undetermined); } else { return Err(Determined); } diff --git a/src/test/ui/imports/extern-prelude-extern-crate-absolute-expanded.rs b/src/test/ui/imports/extern-prelude-extern-crate-absolute-expanded.rs new file mode 100644 index 0000000000000..b1154f2076b80 --- /dev/null +++ b/src/test/ui/imports/extern-prelude-extern-crate-absolute-expanded.rs @@ -0,0 +1,18 @@ +// compile-pass +// edition:2018 + +#![feature(extern_crate_item_prelude)] + +macro_rules! define_iso { () => { + extern crate std as iso; +}} + +::iso::thread_local! { + static S: u8 = 0; +} + +define_iso!(); + +fn main() { + let s = S; +} From acdbd0643cc3d7bd74826c0f13746c81c08d6cc1 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 27 Oct 2018 20:21:34 +0300 Subject: [PATCH 4/6] resolve: More precise spans for privacy errors --- src/librustc_resolve/lib.rs | 10 +- src/librustc_resolve/resolve_imports.rs | 2 +- src/test/ui/error-codes/E0603.stderr | 4 +- src/test/ui/error-festival.stderr | 4 +- src/test/ui/export-import.stderr | 4 +- src/test/ui/export-tag-variant.stderr | 4 +- src/test/ui/export.stderr | 4 +- .../ui/extern/extern-crate-visibility.stderr | 8 +- src/test/ui/hygiene/privacy.stderr | 4 +- src/test/ui/import.stderr | 4 +- src/test/ui/imports/reexports.stderr | 8 +- src/test/ui/issues/issue-10545.stderr | 4 +- src/test/ui/issues/issue-11593.stderr | 4 +- src/test/ui/issues/issue-11680.stderr | 8 +- src/test/ui/issues/issue-13407.stderr | 4 +- src/test/ui/issues/issue-13641.stderr | 8 +- src/test/ui/issues/issue-16725.stderr | 4 +- .../issues/issue-17718-const-privacy.stderr | 4 +- src/test/ui/issues/issue-28388-2.stderr | 4 +- src/test/ui/issues/issue-29161.stderr | 4 +- src/test/ui/issues/issue-38857.stderr | 4 +- src/test/ui/issues/issue-3993.stderr | 4 +- .../macros/macro-local-data-key-priv.stderr | 4 +- src/test/ui/privacy/privacy-in-paths.stderr | 12 +- src/test/ui/privacy/privacy-ns2.stderr | 8 +- src/test/ui/privacy/privacy-ufcs.stderr | 4 +- src/test/ui/privacy/privacy1.rs | 1 - src/test/ui/privacy/privacy1.stderr | 56 +++-- src/test/ui/privacy/privacy2.stderr | 4 +- src/test/ui/privacy/privacy4.stderr | 4 +- src/test/ui/privacy/privacy5.stderr | 192 +++++++++--------- .../ui/privacy/private-item-simple.stderr | 4 +- src/test/ui/privacy/restricted/test.stderr | 8 +- src/test/ui/resolve/privacy-enum-ctor.stderr | 16 +- .../ui/resolve/privacy-struct-ctor.stderr | 24 +-- .../ui/rfc-2008-non-exhaustive/structs.stderr | 8 +- .../shadowed/shadowed-use-visibility.stderr | 8 +- .../ui/static/static-priv-by-default2.stderr | 8 +- .../structs/struct-variant-privacy-xc.stderr | 8 +- .../ui/structs/struct-variant-privacy.stderr | 8 +- .../ui/unreachable/unreachable-variant.stderr | 4 +- src/test/ui/use/use-from-trait-xc.stderr | 8 +- src/test/ui/use/use-mod/use-mod-3.rs | 8 +- src/test/ui/use/use-mod/use-mod-3.stderr | 12 +- .../xcrate/xcrate-private-by-default.stderr | 40 ++-- 45 files changed, 276 insertions(+), 281 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 546c5a5ed3d6c..9d3f64e5b2a42 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1207,7 +1207,7 @@ enum NameBindingKind<'a> { } } -struct PrivacyError<'a>(Span, Name, &'a NameBinding<'a>); +struct PrivacyError<'a>(Span, Ident, &'a NameBinding<'a>); struct UseError<'a> { err: DiagnosticBuilder<'a>, @@ -4743,9 +4743,11 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { } } - for &PrivacyError(span, name, binding) in &self.privacy_errors { - if !reported_spans.insert(span) { continue } - span_err!(self.session, span, E0603, "{} `{}` is private", binding.descr(), name); + for &PrivacyError(dedup_span, ident, binding) in &self.privacy_errors { + if reported_spans.insert(dedup_span) { + span_err!(self.session, ident.span, E0603, "{} `{}` is private", + binding.descr(), ident.name); + } } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 2faed4ad5c994..2ee0b564dc423 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -275,7 +275,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { return Ok(self.dummy_binding); } if !self.is_accessible(binding.vis) { - self.privacy_errors.push(PrivacyError(path_span, ident.name, binding)); + self.privacy_errors.push(PrivacyError(path_span, ident, binding)); } } diff --git a/src/test/ui/error-codes/E0603.stderr b/src/test/ui/error-codes/E0603.stderr index 3447f3378294e..1159348d3db35 100644 --- a/src/test/ui/error-codes/E0603.stderr +++ b/src/test/ui/error-codes/E0603.stderr @@ -1,8 +1,8 @@ error[E0603]: constant `PRIVATE` is private - --> $DIR/E0603.rs:16:5 + --> $DIR/E0603.rs:16:17 | LL | SomeModule::PRIVATE; //~ ERROR E0603 - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/error-festival.stderr b/src/test/ui/error-festival.stderr index 69f11b4b7c08c..5f1e677ca6708 100644 --- a/src/test/ui/error-festival.stderr +++ b/src/test/ui/error-festival.stderr @@ -5,10 +5,10 @@ LL | y = 2; | ^ did you mean `x`? error[E0603]: constant `FOO` is private - --> $DIR/error-festival.rs:32:5 + --> $DIR/error-festival.rs:32:10 | LL | foo::FOO; - | ^^^^^^^^ + | ^^^ error[E0368]: binary assignment operation `+=` cannot be applied to type `&str` --> $DIR/error-festival.rs:22:5 diff --git a/src/test/ui/export-import.stderr b/src/test/ui/export-import.stderr index 2f12485f123b6..dcadad82f29ba 100644 --- a/src/test/ui/export-import.stderr +++ b/src/test/ui/export-import.stderr @@ -1,8 +1,8 @@ error[E0603]: function `unexported` is private - --> $DIR/export-import.rs:11:5 + --> $DIR/export-import.rs:11:8 | LL | use m::unexported; - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/export-tag-variant.stderr b/src/test/ui/export-tag-variant.stderr index da67e2c41990b..e835c29fda34a 100644 --- a/src/test/ui/export-tag-variant.stderr +++ b/src/test/ui/export-tag-variant.stderr @@ -1,8 +1,8 @@ error[E0603]: enum `y` is private - --> $DIR/export-tag-variant.rs:17:21 + --> $DIR/export-tag-variant.rs:17:26 | LL | fn main() { let z = foo::y::y1; } //~ ERROR: enum `y` is private - | ^^^^^^^^^^ + | ^ error: aborting due to previous error diff --git a/src/test/ui/export.stderr b/src/test/ui/export.stderr index dd19e83750b5f..bed650b8c511e 100644 --- a/src/test/ui/export.stderr +++ b/src/test/ui/export.stderr @@ -23,10 +23,10 @@ LL | fn z(y: isize) { log(debug, y); } | ^^^^^ not found in this scope error[E0603]: function `z` is private - --> $DIR/export.rs:20:13 + --> $DIR/export.rs:20:18 | LL | fn main() { foo::z(10); } //~ ERROR function `z` is private - | ^^^^^^ + | ^ error: aborting due to 5 previous errors diff --git a/src/test/ui/extern/extern-crate-visibility.stderr b/src/test/ui/extern/extern-crate-visibility.stderr index cadb636bf0d97..02ecf0ce6f27c 100644 --- a/src/test/ui/extern/extern-crate-visibility.stderr +++ b/src/test/ui/extern/extern-crate-visibility.stderr @@ -1,14 +1,14 @@ error[E0603]: extern crate `core` is private - --> $DIR/extern-crate-visibility.rs:16:5 + --> $DIR/extern-crate-visibility.rs:16:10 | LL | use foo::core::cell; //~ ERROR extern crate `core` is private - | ^^^^^^^^^^^^^^^ + | ^^^^ error[E0603]: extern crate `core` is private - --> $DIR/extern-crate-visibility.rs:19:5 + --> $DIR/extern-crate-visibility.rs:19:10 | LL | foo::core::cell::Cell::new(0); //~ ERROR extern crate `core` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/hygiene/privacy.stderr b/src/test/ui/hygiene/privacy.stderr index 808d244e9cdb6..b93d4da3a867b 100644 --- a/src/test/ui/hygiene/privacy.stderr +++ b/src/test/ui/hygiene/privacy.stderr @@ -1,8 +1,8 @@ error[E0603]: function `f` is private - --> $DIR/privacy.rs:26:9 + --> $DIR/privacy.rs:26:14 | LL | foo::f() //~ ERROR `f` is private - | ^^^^^^ + | ^ error: aborting due to previous error diff --git a/src/test/ui/import.stderr b/src/test/ui/import.stderr index 896655868441c..4cd559f5f4a46 100644 --- a/src/test/ui/import.stderr +++ b/src/test/ui/import.stderr @@ -11,10 +11,10 @@ LL | use foo; //~ ERROR unresolved import `foo` [E0432] | ^^^ no `foo` in the root error[E0603]: unresolved item `foo` is private - --> $DIR/import.rs:23:5 + --> $DIR/import.rs:23:10 | LL | zed::foo(); //~ ERROR `foo` is private - | ^^^^^^^^ + | ^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/imports/reexports.stderr b/src/test/ui/imports/reexports.stderr index a166344314b90..9ed3b02591c2d 100644 --- a/src/test/ui/imports/reexports.stderr +++ b/src/test/ui/imports/reexports.stderr @@ -17,16 +17,16 @@ LL | pub use super::*; //~ ERROR must import something with the glob's v | ^^^^^^^^ error[E0603]: module `foo` is private - --> $DIR/reexports.rs:38:9 + --> $DIR/reexports.rs:38:15 | LL | use b::a::foo::S; //~ ERROR `foo` - | ^^^^^^^^^^^^ + | ^^^ error[E0603]: module `foo` is private - --> $DIR/reexports.rs:39:9 + --> $DIR/reexports.rs:39:15 | LL | use b::b::foo::S as T; //~ ERROR `foo` - | ^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 4 previous errors diff --git a/src/test/ui/issues/issue-10545.stderr b/src/test/ui/issues/issue-10545.stderr index 28f95dff3bc0a..93a098432534b 100644 --- a/src/test/ui/issues/issue-10545.stderr +++ b/src/test/ui/issues/issue-10545.stderr @@ -1,8 +1,8 @@ error[E0603]: struct `S` is private - --> $DIR/issue-10545.rs:17:11 + --> $DIR/issue-10545.rs:17:14 | LL | fn foo(_: a::S) { //~ ERROR: struct `S` is private - | ^^^^ + | ^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-11593.stderr b/src/test/ui/issues/issue-11593.stderr index 24e1a5eb6f46e..bb5303cb581a1 100644 --- a/src/test/ui/issues/issue-11593.stderr +++ b/src/test/ui/issues/issue-11593.stderr @@ -1,8 +1,8 @@ error[E0603]: trait `Foo` is private - --> $DIR/issue-11593.rs:17:6 + --> $DIR/issue-11593.rs:17:24 | LL | impl private_trait_xc::Foo for Bar {} - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-11680.stderr b/src/test/ui/issues/issue-11680.stderr index 37cfe960600b0..4dfd0bf15b92a 100644 --- a/src/test/ui/issues/issue-11680.stderr +++ b/src/test/ui/issues/issue-11680.stderr @@ -1,14 +1,14 @@ error[E0603]: enum `Foo` is private - --> $DIR/issue-11680.rs:16:14 + --> $DIR/issue-11680.rs:16:21 | LL | let _b = other::Foo::Bar(1); - | ^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: enum `Foo` is private - --> $DIR/issue-11680.rs:19:14 + --> $DIR/issue-11680.rs:19:27 | LL | let _b = other::test::Foo::Bar(1); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-13407.stderr b/src/test/ui/issues/issue-13407.stderr index e5ef50e984a76..90d5ca59e1e25 100644 --- a/src/test/ui/issues/issue-13407.stderr +++ b/src/test/ui/issues/issue-13407.stderr @@ -1,8 +1,8 @@ error[E0603]: unit struct `C` is private - --> $DIR/issue-13407.rs:16:5 + --> $DIR/issue-13407.rs:16:8 | LL | A::C = 1; - | ^^^^ + | ^ error[E0308]: mismatched types --> $DIR/issue-13407.rs:16:12 diff --git a/src/test/ui/issues/issue-13641.stderr b/src/test/ui/issues/issue-13641.stderr index 0f96b5f66b1b8..cbbceb72af392 100644 --- a/src/test/ui/issues/issue-13641.stderr +++ b/src/test/ui/issues/issue-13641.stderr @@ -1,14 +1,14 @@ error[E0603]: struct `Foo` is private - --> $DIR/issue-13641.rs:19:5 + --> $DIR/issue-13641.rs:19:8 | LL | a::Foo::new(); - | ^^^^^^^^^^^ + | ^^^ error[E0603]: enum `Bar` is private - --> $DIR/issue-13641.rs:21:5 + --> $DIR/issue-13641.rs:21:8 | LL | a::Bar::new(); - | ^^^^^^^^^^^ + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-16725.stderr b/src/test/ui/issues/issue-16725.stderr index 709f3cf50b992..ba36f9b5582e5 100644 --- a/src/test/ui/issues/issue-16725.stderr +++ b/src/test/ui/issues/issue-16725.stderr @@ -1,8 +1,8 @@ error[E0603]: function `bar` is private - --> $DIR/issue-16725.rs:16:14 + --> $DIR/issue-16725.rs:16:19 | LL | unsafe { foo::bar(); } - | ^^^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-17718-const-privacy.stderr b/src/test/ui/issues/issue-17718-const-privacy.stderr index a453e599c8b43..7d65a97ec1d5a 100644 --- a/src/test/ui/issues/issue-17718-const-privacy.stderr +++ b/src/test/ui/issues/issue-17718-const-privacy.stderr @@ -1,8 +1,8 @@ error[E0603]: constant `B` is private - --> $DIR/issue-17718-const-privacy.rs:15:5 + --> $DIR/issue-17718-const-privacy.rs:15:8 | LL | use a::B; //~ ERROR: constant `B` is private - | ^^^^ + | ^ error[E0603]: constant `BAR` is private --> $DIR/issue-17718-const-privacy.rs:18:5 diff --git a/src/test/ui/issues/issue-28388-2.stderr b/src/test/ui/issues/issue-28388-2.stderr index 7809934942c26..02ffc4b1758f6 100644 --- a/src/test/ui/issues/issue-28388-2.stderr +++ b/src/test/ui/issues/issue-28388-2.stderr @@ -1,8 +1,8 @@ error[E0603]: module `n` is private - --> $DIR/issue-28388-2.rs:17:5 + --> $DIR/issue-28388-2.rs:17:8 | LL | use m::n::{}; - | ^^^^^^^^ + | ^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-29161.stderr b/src/test/ui/issues/issue-29161.stderr index fb6a41d2eca09..7d3bd03ba230b 100644 --- a/src/test/ui/issues/issue-29161.stderr +++ b/src/test/ui/issues/issue-29161.stderr @@ -5,10 +5,10 @@ LL | pub fn default() -> A { //~ ERROR unnecessary visibility qualifier | ^^^ `pub` not permitted here because it's implied error[E0603]: struct `A` is private - --> $DIR/issue-29161.rs:23:5 + --> $DIR/issue-29161.rs:23:8 | LL | a::A::default(); - | ^^^^^^^^^^^^^ + | ^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-38857.stderr b/src/test/ui/issues/issue-38857.stderr index 985927c25a1ae..f6ed320267179 100644 --- a/src/test/ui/issues/issue-38857.stderr +++ b/src/test/ui/issues/issue-38857.stderr @@ -5,10 +5,10 @@ LL | let a = std::sys::imp::process::process_common::StdioPipes { ..panic!() | ^^^ Could not find `imp` in `sys` error[E0603]: module `sys` is private - --> $DIR/issue-38857.rs:12:13 + --> $DIR/issue-38857.rs:12:18 | LL | let a = std::sys::imp::process::process_common::StdioPipes { ..panic!() }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-3993.stderr b/src/test/ui/issues/issue-3993.stderr index 4b569f2dea957..52f1985c4fbf4 100644 --- a/src/test/ui/issues/issue-3993.stderr +++ b/src/test/ui/issues/issue-3993.stderr @@ -1,8 +1,8 @@ error[E0603]: function `fly` is private - --> $DIR/issue-3993.rs:11:5 + --> $DIR/issue-3993.rs:11:10 | LL | use zoo::fly; //~ ERROR: function `fly` is private - | ^^^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/macros/macro-local-data-key-priv.stderr b/src/test/ui/macros/macro-local-data-key-priv.stderr index 57f4f790cb11c..b5ad50fbebab2 100644 --- a/src/test/ui/macros/macro-local-data-key-priv.stderr +++ b/src/test/ui/macros/macro-local-data-key-priv.stderr @@ -1,8 +1,8 @@ error[E0603]: constant `baz` is private - --> $DIR/macro-local-data-key-priv.rs:18:5 + --> $DIR/macro-local-data-key-priv.rs:18:10 | LL | bar::baz.with(|_| ()); - | ^^^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/privacy/privacy-in-paths.stderr b/src/test/ui/privacy/privacy-in-paths.stderr index f0aa3d36479e4..7b72c634ebf9b 100644 --- a/src/test/ui/privacy/privacy-in-paths.stderr +++ b/src/test/ui/privacy/privacy-in-paths.stderr @@ -1,20 +1,20 @@ error[E0603]: module `bar` is private - --> $DIR/privacy-in-paths.rs:34:9 + --> $DIR/privacy-in-paths.rs:34:16 | LL | ::foo::bar::baz::f(); //~ERROR module `bar` is private - | ^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `bar` is private - --> $DIR/privacy-in-paths.rs:35:9 + --> $DIR/privacy-in-paths.rs:35:16 | LL | ::foo::bar::S::f(); //~ERROR module `bar` is private - | ^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: trait `T` is private - --> $DIR/privacy-in-paths.rs:36:9 + --> $DIR/privacy-in-paths.rs:36:23 | LL | <() as ::foo::T>::Assoc::f(); //~ERROR trait `T` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error: aborting due to 3 previous errors diff --git a/src/test/ui/privacy/privacy-ns2.stderr b/src/test/ui/privacy/privacy-ns2.stderr index 0cd341d9a58b5..9243bc2459f91 100644 --- a/src/test/ui/privacy/privacy-ns2.stderr +++ b/src/test/ui/privacy/privacy-ns2.stderr @@ -55,16 +55,16 @@ LL | use foo3::Bar; | error[E0603]: trait `Bar` is private - --> $DIR/privacy-ns2.rs:70:9 + --> $DIR/privacy-ns2.rs:70:15 | LL | use foo3::Bar; //~ ERROR `Bar` is private - | ^^^^^^^^^ + | ^^^ error[E0603]: trait `Bar` is private - --> $DIR/privacy-ns2.rs:74:9 + --> $DIR/privacy-ns2.rs:74:15 | LL | use foo3::Bar; //~ ERROR `Bar` is private - | ^^^^^^^^^ + | ^^^ error[E0603]: trait `Bar` is private --> $DIR/privacy-ns2.rs:81:16 diff --git a/src/test/ui/privacy/privacy-ufcs.stderr b/src/test/ui/privacy/privacy-ufcs.stderr index 2030e2e0f1b9e..5989c79bc85d3 100644 --- a/src/test/ui/privacy/privacy-ufcs.stderr +++ b/src/test/ui/privacy/privacy-ufcs.stderr @@ -1,8 +1,8 @@ error[E0603]: trait `Bar` is private - --> $DIR/privacy-ufcs.rs:22:5 + --> $DIR/privacy-ufcs.rs:22:20 | LL | ::baz(); //~ERROR trait `Bar` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/privacy/privacy1.rs b/src/test/ui/privacy/privacy1.rs index afe8c2fda3d4c..9aff4bbc41c9c 100644 --- a/src/test/ui/privacy/privacy1.rs +++ b/src/test/ui/privacy/privacy1.rs @@ -127,7 +127,6 @@ mod foo { fn test2() { use bar::baz::{foo, bar}; //~^ ERROR: module `baz` is private - //~| ERROR: module `baz` is private foo(); bar(); diff --git a/src/test/ui/privacy/privacy1.stderr b/src/test/ui/privacy/privacy1.stderr index 344f990699f45..d6197575447e6 100644 --- a/src/test/ui/privacy/privacy1.stderr +++ b/src/test/ui/privacy/privacy1.stderr @@ -1,80 +1,74 @@ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:128:24 + --> $DIR/privacy1.rs:128:18 | LL | use bar::baz::{foo, bar}; - | ^^^ + | ^^^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:128:29 - | -LL | use bar::baz::{foo, bar}; - | ^^^ - -error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:137:13 + --> $DIR/privacy1.rs:136:18 | LL | use bar::baz; - | ^^^^^^^^ + | ^^^ error[E0603]: module `i` is private - --> $DIR/privacy1.rs:161:9 + --> $DIR/privacy1.rs:160:20 | LL | use self::foo::i::A; //~ ERROR: module `i` is private - | ^^^^^^^^^^^^^^^ + | ^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:100:9 + --> $DIR/privacy1.rs:100:16 | LL | ::bar::baz::A::foo(); //~ ERROR: module `baz` is private - | ^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:101:9 + --> $DIR/privacy1.rs:101:16 | LL | ::bar::baz::A::bar(); //~ ERROR: module `baz` is private - | ^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:103:9 + --> $DIR/privacy1.rs:103:16 | LL | ::bar::baz::A.foo2(); //~ ERROR: module `baz` is private - | ^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:104:9 + --> $DIR/privacy1.rs:104:16 | LL | ::bar::baz::A.bar2(); //~ ERROR: module `baz` is private - | ^^^^^^^^^^^^^ + | ^^^ error[E0603]: trait `B` is private - --> $DIR/privacy1.rs:108:9 + --> $DIR/privacy1.rs:108:16 | LL | ::bar::B::foo(); //~ ERROR: trait `B` is private - | ^^^^^^^^^^^^^ + | ^ error[E0603]: function `epriv` is private - --> $DIR/privacy1.rs:114:13 + --> $DIR/privacy1.rs:114:20 | LL | ::bar::epriv(); //~ ERROR: function `epriv` is private - | ^^^^^^^^^^^^ + | ^^^^^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:123:9 + --> $DIR/privacy1.rs:123:16 | LL | ::bar::baz::foo(); //~ ERROR: module `baz` is private - | ^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `baz` is private - --> $DIR/privacy1.rs:124:9 + --> $DIR/privacy1.rs:124:16 | LL | ::bar::baz::bar(); //~ ERROR: module `baz` is private - | ^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: trait `B` is private - --> $DIR/privacy1.rs:153:10 + --> $DIR/privacy1.rs:152:17 | LL | impl ::bar::B for f32 { fn foo() -> f32 { 1.0 } } - | ^^^^^^^^ + | ^ error[E0624]: method `bar` is private --> $DIR/privacy1.rs:73:9 @@ -106,7 +100,7 @@ error[E0624]: method `bar2` is private LL | ::bar::baz::A.bar2(); //~ ERROR: module `baz` is private | ^^^^ -error: aborting due to 18 previous errors +error: aborting due to 17 previous errors Some errors occurred: E0603, E0624. For more information about an error, try `rustc --explain E0603`. diff --git a/src/test/ui/privacy/privacy2.stderr b/src/test/ui/privacy/privacy2.stderr index ec5567b25e443..fa4da7f5181b0 100644 --- a/src/test/ui/privacy/privacy2.stderr +++ b/src/test/ui/privacy/privacy2.stderr @@ -5,10 +5,10 @@ LL | use bar::foo; | ^^^^^^^^ no `foo` in `bar` error[E0603]: function `foo` is private - --> $DIR/privacy2.rs:33:9 + --> $DIR/privacy2.rs:33:20 | LL | use bar::glob::foo; - | ^^^^^^^^^^^^^^ + | ^^^ error: requires `sized` lang_item diff --git a/src/test/ui/privacy/privacy4.stderr b/src/test/ui/privacy/privacy4.stderr index 811f5d5942a7a..8a4b7401de01a 100644 --- a/src/test/ui/privacy/privacy4.stderr +++ b/src/test/ui/privacy/privacy4.stderr @@ -1,8 +1,8 @@ error[E0603]: module `glob` is private - --> $DIR/privacy4.rs:31:9 + --> $DIR/privacy4.rs:31:14 | LL | use bar::glob::gpriv; //~ ERROR: module `glob` is private - | ^^^^^^^^^^^^^^^^ + | ^^^^ error: aborting due to previous error diff --git a/src/test/ui/privacy/privacy5.stderr b/src/test/ui/privacy/privacy5.stderr index bcb6315136273..23682575cf183 100644 --- a/src/test/ui/privacy/privacy5.stderr +++ b/src/test/ui/privacy/privacy5.stderr @@ -1,290 +1,290 @@ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:61:13 + --> $DIR/privacy5.rs:61:16 | LL | let a = a::A(()); //~ ERROR tuple struct `A` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:62:13 + --> $DIR/privacy5.rs:62:16 | LL | let b = a::B(2); //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:63:13 + --> $DIR/privacy5.rs:63:16 | LL | let c = a::C(2, 3); //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:66:9 + --> $DIR/privacy5.rs:66:12 | LL | let a::A(()) = a; //~ ERROR tuple struct `A` is private - | ^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:67:9 + --> $DIR/privacy5.rs:67:12 | LL | let a::A(_) = a; //~ ERROR tuple struct `A` is private - | ^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:68:15 + --> $DIR/privacy5.rs:68:18 | LL | match a { a::A(()) => {} } //~ ERROR tuple struct `A` is private - | ^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:69:15 + --> $DIR/privacy5.rs:69:18 | LL | match a { a::A(_) => {} } //~ ERROR tuple struct `A` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:71:9 + --> $DIR/privacy5.rs:71:12 | LL | let a::B(_) = b; //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:72:9 + --> $DIR/privacy5.rs:72:12 | LL | let a::B(_b) = b; //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:73:15 + --> $DIR/privacy5.rs:73:18 | LL | match b { a::B(_) => {} } //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:74:15 + --> $DIR/privacy5.rs:74:18 | LL | match b { a::B(_b) => {} } //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:75:15 + --> $DIR/privacy5.rs:75:18 | LL | match b { a::B(1) => {} a::B(_) => {} } //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:75:29 + --> $DIR/privacy5.rs:75:32 | LL | match b { a::B(1) => {} a::B(_) => {} } //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:78:9 + --> $DIR/privacy5.rs:78:12 | LL | let a::C(_, _) = c; //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:79:9 + --> $DIR/privacy5.rs:79:12 | LL | let a::C(_a, _) = c; //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:80:9 + --> $DIR/privacy5.rs:80:12 | LL | let a::C(_, _b) = c; //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:81:9 + --> $DIR/privacy5.rs:81:12 | LL | let a::C(_a, _b) = c; //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:82:15 + --> $DIR/privacy5.rs:82:18 | LL | match c { a::C(_, _) => {} } //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:83:15 + --> $DIR/privacy5.rs:83:18 | LL | match c { a::C(_a, _) => {} } //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:84:15 + --> $DIR/privacy5.rs:84:18 | LL | match c { a::C(_, _b) => {} } //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:85:15 + --> $DIR/privacy5.rs:85:18 | LL | match c { a::C(_a, _b) => {} } //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:93:14 + --> $DIR/privacy5.rs:93:17 | LL | let a2 = a::A; //~ ERROR tuple struct `A` is private - | ^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:94:14 + --> $DIR/privacy5.rs:94:17 | LL | let b2 = a::B; //~ ERROR tuple struct `B` is private - | ^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:95:14 + --> $DIR/privacy5.rs:95:17 | LL | let c2 = a::C; //~ ERROR tuple struct `C` is private - | ^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:100:13 + --> $DIR/privacy5.rs:100:20 | LL | let a = other::A(()); //~ ERROR tuple struct `A` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:101:13 + --> $DIR/privacy5.rs:101:20 | LL | let b = other::B(2); //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:102:13 + --> $DIR/privacy5.rs:102:20 | LL | let c = other::C(2, 3); //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:105:9 + --> $DIR/privacy5.rs:105:16 | LL | let other::A(()) = a; //~ ERROR tuple struct `A` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:106:9 + --> $DIR/privacy5.rs:106:16 | LL | let other::A(_) = a; //~ ERROR tuple struct `A` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:107:15 + --> $DIR/privacy5.rs:107:22 | LL | match a { other::A(()) => {} } //~ ERROR tuple struct `A` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:108:15 + --> $DIR/privacy5.rs:108:22 | LL | match a { other::A(_) => {} } //~ ERROR tuple struct `A` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:110:9 + --> $DIR/privacy5.rs:110:16 | LL | let other::B(_) = b; //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:111:9 + --> $DIR/privacy5.rs:111:16 | LL | let other::B(_b) = b; //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:112:15 + --> $DIR/privacy5.rs:112:22 | LL | match b { other::B(_) => {} } //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:113:15 + --> $DIR/privacy5.rs:113:22 | LL | match b { other::B(_b) => {} } //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:114:15 + --> $DIR/privacy5.rs:114:22 | LL | match b { other::B(1) => {} other::B(_) => {} } //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:114:33 + --> $DIR/privacy5.rs:114:40 | LL | match b { other::B(1) => {} other::B(_) => {} } //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:117:9 + --> $DIR/privacy5.rs:117:16 | LL | let other::C(_, _) = c; //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:118:9 + --> $DIR/privacy5.rs:118:16 | LL | let other::C(_a, _) = c; //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:119:9 + --> $DIR/privacy5.rs:119:16 | LL | let other::C(_, _b) = c; //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:120:9 + --> $DIR/privacy5.rs:120:16 | LL | let other::C(_a, _b) = c; //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:121:15 + --> $DIR/privacy5.rs:121:22 | LL | match c { other::C(_, _) => {} } //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:122:15 + --> $DIR/privacy5.rs:122:22 | LL | match c { other::C(_a, _) => {} } //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:123:15 + --> $DIR/privacy5.rs:123:22 | LL | match c { other::C(_, _b) => {} } //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:124:15 + --> $DIR/privacy5.rs:124:22 | LL | match c { other::C(_a, _b) => {} } //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `A` is private - --> $DIR/privacy5.rs:132:14 + --> $DIR/privacy5.rs:132:21 | LL | let a2 = other::A; //~ ERROR tuple struct `A` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `B` is private - --> $DIR/privacy5.rs:133:14 + --> $DIR/privacy5.rs:133:21 | LL | let b2 = other::B; //~ ERROR tuple struct `B` is private - | ^^^^^^^^ + | ^ error[E0603]: tuple struct `C` is private - --> $DIR/privacy5.rs:134:14 + --> $DIR/privacy5.rs:134:21 | LL | let c2 = other::C; //~ ERROR tuple struct `C` is private - | ^^^^^^^^ + | ^ error: aborting due to 48 previous errors diff --git a/src/test/ui/privacy/private-item-simple.stderr b/src/test/ui/privacy/private-item-simple.stderr index 811b026eab9e3..468bfeaf32e9d 100644 --- a/src/test/ui/privacy/private-item-simple.stderr +++ b/src/test/ui/privacy/private-item-simple.stderr @@ -1,8 +1,8 @@ error[E0603]: function `f` is private - --> $DIR/private-item-simple.rs:16:5 + --> $DIR/private-item-simple.rs:16:8 | LL | a::f(); //~ ERROR function `f` is private - | ^^^^ + | ^ error: aborting due to previous error diff --git a/src/test/ui/privacy/restricted/test.stderr b/src/test/ui/privacy/restricted/test.stderr index 67a95c3559018..afc3ee2db4b8f 100644 --- a/src/test/ui/privacy/restricted/test.stderr +++ b/src/test/ui/privacy/restricted/test.stderr @@ -23,16 +23,16 @@ LL | pub(super) use foo::bar::f as g; //~ ERROR cannot be re-exported | ^^^^^^^^^^^^^^^^ error[E0603]: struct `Crate` is private - --> $DIR/test.rs:48:9 + --> $DIR/test.rs:48:25 | LL | use pub_restricted::Crate; //~ ERROR private - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^ error[E0603]: function `f` is private - --> $DIR/test.rs:40:9 + --> $DIR/test.rs:40:19 | LL | use foo::bar::f; //~ ERROR private - | ^^^^^^^^^^^ + | ^ error[E0616]: field `x` of struct `foo::bar::S` is private --> $DIR/test.rs:41:5 diff --git a/src/test/ui/resolve/privacy-enum-ctor.stderr b/src/test/ui/resolve/privacy-enum-ctor.stderr index d8ab21ddb5f39..8e08f124d6807 100644 --- a/src/test/ui/resolve/privacy-enum-ctor.stderr +++ b/src/test/ui/resolve/privacy-enum-ctor.stderr @@ -132,28 +132,28 @@ LL | use m::n::Z; | error[E0603]: enum `Z` is private - --> $DIR/privacy-enum-ctor.rs:67:16 + --> $DIR/privacy-enum-ctor.rs:67:22 | LL | let _: Z = m::n::Z; - | ^^^^^^^ + | ^ error[E0603]: enum `Z` is private - --> $DIR/privacy-enum-ctor.rs:71:16 + --> $DIR/privacy-enum-ctor.rs:71:22 | LL | let _: Z = m::n::Z::Fn; - | ^^^^^^^^^^^ + | ^ error[E0603]: enum `Z` is private - --> $DIR/privacy-enum-ctor.rs:74:16 + --> $DIR/privacy-enum-ctor.rs:74:22 | LL | let _: Z = m::n::Z::Struct; - | ^^^^^^^^^^^^^^^ + | ^ error[E0603]: enum `Z` is private - --> $DIR/privacy-enum-ctor.rs:78:16 + --> $DIR/privacy-enum-ctor.rs:78:22 | LL | let _: Z = m::n::Z::Unit {}; - | ^^^^^^^^^^^^^ + | ^ error[E0308]: mismatched types --> $DIR/privacy-enum-ctor.rs:37:20 diff --git a/src/test/ui/resolve/privacy-struct-ctor.stderr b/src/test/ui/resolve/privacy-struct-ctor.stderr index 6ea5241fff00c..c4713bd77a87a 100644 --- a/src/test/ui/resolve/privacy-struct-ctor.stderr +++ b/src/test/ui/resolve/privacy-struct-ctor.stderr @@ -38,40 +38,40 @@ LL | use m::S; | error[E0603]: tuple struct `Z` is private - --> $DIR/privacy-struct-ctor.rs:28:9 + --> $DIR/privacy-struct-ctor.rs:28:12 | LL | n::Z; - | ^^^^ + | ^ error[E0603]: tuple struct `S` is private - --> $DIR/privacy-struct-ctor.rs:39:5 + --> $DIR/privacy-struct-ctor.rs:39:8 | LL | m::S; - | ^^^^ + | ^ error[E0603]: tuple struct `S` is private - --> $DIR/privacy-struct-ctor.rs:41:16 + --> $DIR/privacy-struct-ctor.rs:41:19 | LL | let _: S = m::S(2); - | ^^^^ + | ^ error[E0603]: tuple struct `Z` is private - --> $DIR/privacy-struct-ctor.rs:45:5 + --> $DIR/privacy-struct-ctor.rs:45:11 | LL | m::n::Z; - | ^^^^^^^ + | ^ error[E0603]: tuple struct `S` is private - --> $DIR/privacy-struct-ctor.rs:51:5 + --> $DIR/privacy-struct-ctor.rs:51:16 | LL | xcrate::m::S; - | ^^^^^^^^^^^^ + | ^ error[E0603]: tuple struct `Z` is private - --> $DIR/privacy-struct-ctor.rs:55:5 + --> $DIR/privacy-struct-ctor.rs:55:19 | LL | xcrate::m::n::Z; - | ^^^^^^^^^^^^^^^ + | ^ error: aborting due to 10 previous errors diff --git a/src/test/ui/rfc-2008-non-exhaustive/structs.stderr b/src/test/ui/rfc-2008-non-exhaustive/structs.stderr index c0f7e2786716e..141e4b73b58af 100644 --- a/src/test/ui/rfc-2008-non-exhaustive/structs.stderr +++ b/src/test/ui/rfc-2008-non-exhaustive/structs.stderr @@ -11,16 +11,16 @@ LL | let us = UnitStruct; | ^^^^^^^^^^ constructor is not visible here due to private fields error[E0603]: tuple struct `TupleStruct` is private - --> $DIR/structs.rs:33:23 + --> $DIR/structs.rs:33:32 | LL | let ts_explicit = structs::TupleStruct(640, 480); - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^ error[E0603]: unit struct `UnitStruct` is private - --> $DIR/structs.rs:42:23 + --> $DIR/structs.rs:42:32 | LL | let us_explicit = structs::UnitStruct; - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ error[E0639]: cannot create non-exhaustive struct using struct expression --> $DIR/structs.rs:17:14 diff --git a/src/test/ui/shadowed/shadowed-use-visibility.stderr b/src/test/ui/shadowed/shadowed-use-visibility.stderr index 5764ed76ef418..4faaf6cce2435 100644 --- a/src/test/ui/shadowed/shadowed-use-visibility.stderr +++ b/src/test/ui/shadowed/shadowed-use-visibility.stderr @@ -1,14 +1,14 @@ error[E0603]: module `bar` is private - --> $DIR/shadowed-use-visibility.rs:19:9 + --> $DIR/shadowed-use-visibility.rs:19:14 | LL | use foo::bar::f as g; //~ ERROR module `bar` is private - | ^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `f` is private - --> $DIR/shadowed-use-visibility.rs:25:5 + --> $DIR/shadowed-use-visibility.rs:25:10 | LL | use bar::f::f; //~ ERROR module `f` is private - | ^^^^^^^^^ + | ^ error: aborting due to 2 previous errors diff --git a/src/test/ui/static/static-priv-by-default2.stderr b/src/test/ui/static/static-priv-by-default2.stderr index 0f749b0e4f37a..2631e99a9b77d 100644 --- a/src/test/ui/static/static-priv-by-default2.stderr +++ b/src/test/ui/static/static-priv-by-default2.stderr @@ -1,14 +1,14 @@ error[E0603]: static `private` is private - --> $DIR/static-priv-by-default2.rs:25:9 + --> $DIR/static-priv-by-default2.rs:25:30 | LL | use child::childs_child::private; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ error[E0603]: static `private` is private - --> $DIR/static-priv-by-default2.rs:33:9 + --> $DIR/static-priv-by-default2.rs:33:33 | LL | use static_priv_by_default::private; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/structs/struct-variant-privacy-xc.stderr b/src/test/ui/structs/struct-variant-privacy-xc.stderr index 731d23e6a978d..7c214f9dcea0d 100644 --- a/src/test/ui/structs/struct-variant-privacy-xc.stderr +++ b/src/test/ui/structs/struct-variant-privacy-xc.stderr @@ -1,14 +1,14 @@ error[E0603]: enum `Bar` is private - --> $DIR/struct-variant-privacy-xc.rs:14:9 + --> $DIR/struct-variant-privacy-xc.rs:14:33 | LL | fn f(b: struct_variant_privacy::Bar) { //~ ERROR enum `Bar` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: enum `Bar` is private - --> $DIR/struct-variant-privacy-xc.rs:16:9 + --> $DIR/struct-variant-privacy-xc.rs:16:33 | LL | struct_variant_privacy::Bar::Baz { a: _a } => {} //~ ERROR enum `Bar` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/structs/struct-variant-privacy.stderr b/src/test/ui/structs/struct-variant-privacy.stderr index a82ac8ab31867..ffecd88006949 100644 --- a/src/test/ui/structs/struct-variant-privacy.stderr +++ b/src/test/ui/structs/struct-variant-privacy.stderr @@ -1,14 +1,14 @@ error[E0603]: enum `Bar` is private - --> $DIR/struct-variant-privacy.rs:16:9 + --> $DIR/struct-variant-privacy.rs:16:14 | LL | fn f(b: foo::Bar) { //~ ERROR enum `Bar` is private - | ^^^^^^^^ + | ^^^ error[E0603]: enum `Bar` is private - --> $DIR/struct-variant-privacy.rs:18:9 + --> $DIR/struct-variant-privacy.rs:18:14 | LL | foo::Bar::Baz { a: _a } => {} //~ ERROR enum `Bar` is private - | ^^^^^^^^^^^^^ + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/unreachable/unreachable-variant.stderr b/src/test/ui/unreachable/unreachable-variant.stderr index fff77586549d3..a998f6b0b8f22 100644 --- a/src/test/ui/unreachable/unreachable-variant.stderr +++ b/src/test/ui/unreachable/unreachable-variant.stderr @@ -1,8 +1,8 @@ error[E0603]: module `super_sekrit` is private - --> $DIR/unreachable-variant.rs:16:14 + --> $DIR/unreachable-variant.rs:16:21 | LL | let _x = other::super_sekrit::sooper_sekrit::baz; //~ ERROR is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/use/use-from-trait-xc.stderr b/src/test/ui/use/use-from-trait-xc.stderr index 130aca8162a43..f8e5e18097ba4 100644 --- a/src/test/ui/use/use-from-trait-xc.stderr +++ b/src/test/ui/use/use-from-trait-xc.stderr @@ -41,16 +41,16 @@ LL | use use_from_trait_xc::Baz::new as baznew; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `new` in `Baz` error[E0603]: struct `Foo` is private - --> $DIR/use-from-trait-xc.rs:24:5 + --> $DIR/use-from-trait-xc.rs:24:24 | LL | use use_from_trait_xc::Foo::new; //~ ERROR struct `Foo` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: struct `Foo` is private - --> $DIR/use-from-trait-xc.rs:27:5 + --> $DIR/use-from-trait-xc.rs:27:24 | LL | use use_from_trait_xc::Foo::C; //~ ERROR struct `Foo` is private - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 9 previous errors diff --git a/src/test/ui/use/use-mod/use-mod-3.rs b/src/test/ui/use/use-mod/use-mod-3.rs index cce500800caca..2ef5fe7947e77 100644 --- a/src/test/ui/use/use-mod/use-mod-3.rs +++ b/src/test/ui/use/use-mod/use-mod-3.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use foo::bar::{ - self //~ ERROR module `bar` is private +use foo::bar::{ //~ ERROR module `bar` is private + self }; -use foo::bar::{ - Bar //~ ERROR module `bar` is private +use foo::bar::{ //~ ERROR module `bar` is private + Bar }; mod foo { diff --git a/src/test/ui/use/use-mod/use-mod-3.stderr b/src/test/ui/use/use-mod/use-mod-3.stderr index 619239846419a..9284091dfa878 100644 --- a/src/test/ui/use/use-mod/use-mod-3.stderr +++ b/src/test/ui/use/use-mod/use-mod-3.stderr @@ -1,14 +1,14 @@ error[E0603]: module `bar` is private - --> $DIR/use-mod-3.rs:12:5 + --> $DIR/use-mod-3.rs:11:10 | -LL | self //~ ERROR module `bar` is private - | ^^^^ +LL | use foo::bar::{ //~ ERROR module `bar` is private + | ^^^ error[E0603]: module `bar` is private - --> $DIR/use-mod-3.rs:15:5 + --> $DIR/use-mod-3.rs:14:10 | -LL | Bar //~ ERROR module `bar` is private - | ^^^ +LL | use foo::bar::{ //~ ERROR module `bar` is private + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/xcrate/xcrate-private-by-default.stderr b/src/test/ui/xcrate/xcrate-private-by-default.stderr index c4560b9ca7752..ea1f6aaa7d2fc 100644 --- a/src/test/ui/xcrate/xcrate-private-by-default.stderr +++ b/src/test/ui/xcrate/xcrate-private-by-default.stderr @@ -1,62 +1,62 @@ error[E0603]: static `j` is private - --> $DIR/xcrate-private-by-default.rs:33:5 + --> $DIR/xcrate-private-by-default.rs:33:29 | LL | static_priv_by_default::j; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error[E0603]: function `k` is private - --> $DIR/xcrate-private-by-default.rs:35:5 + --> $DIR/xcrate-private-by-default.rs:35:29 | LL | static_priv_by_default::k; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error[E0603]: unit struct `l` is private - --> $DIR/xcrate-private-by-default.rs:37:5 + --> $DIR/xcrate-private-by-default.rs:37:29 | LL | static_priv_by_default::l; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error[E0603]: enum `m` is private - --> $DIR/xcrate-private-by-default.rs:39:11 + --> $DIR/xcrate-private-by-default.rs:39:35 | LL | foo::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error[E0603]: type alias `n` is private - --> $DIR/xcrate-private-by-default.rs:41:11 + --> $DIR/xcrate-private-by-default.rs:41:35 | LL | foo::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error[E0603]: module `foo` is private - --> $DIR/xcrate-private-by-default.rs:45:5 + --> $DIR/xcrate-private-by-default.rs:45:29 | LL | static_priv_by_default::foo::a; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `foo` is private - --> $DIR/xcrate-private-by-default.rs:47:5 + --> $DIR/xcrate-private-by-default.rs:47:29 | LL | static_priv_by_default::foo::b; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `foo` is private - --> $DIR/xcrate-private-by-default.rs:49:5 + --> $DIR/xcrate-private-by-default.rs:49:29 | LL | static_priv_by_default::foo::c; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `foo` is private - --> $DIR/xcrate-private-by-default.rs:51:11 + --> $DIR/xcrate-private-by-default.rs:51:35 | LL | foo::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error[E0603]: module `foo` is private - --> $DIR/xcrate-private-by-default.rs:53:11 + --> $DIR/xcrate-private-by-default.rs:53:35 | LL | foo::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 10 previous errors From 1f257bd022389e21b8f165a055b854c7195d7e45 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 27 Oct 2018 20:23:54 +0300 Subject: [PATCH 5/6] resolve: Make sure macros and imports are resolved in full parent scope Slightly simplify `fn build_reduced_graph_for_use_tree` --- src/librustc_resolve/build_reduced_graph.rs | 54 ++++++++------------- src/librustc_resolve/error_reporting.rs | 35 ++++++++----- src/librustc_resolve/lib.rs | 47 +++++++++--------- src/librustc_resolve/macros.rs | 29 +++++------ src/librustc_resolve/resolve_imports.rs | 4 +- 5 files changed, 83 insertions(+), 86 deletions(-) diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 6c7398e17530a..328d5bb3af069 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -111,23 +111,23 @@ impl<'a, 'cl> Resolver<'a, 'cl> { fn build_reduced_graph_for_use_tree( &mut self, - root_use_tree: &ast::UseTree, - root_id: NodeId, + // This particular use tree use_tree: &ast::UseTree, id: NodeId, - vis: ty::Visibility, parent_prefix: &[Segment], - mut uniform_paths_canary_emitted: bool, nested: bool, - item: &Item, + mut uniform_paths_canary_emitted: bool, + // The whole `use` item parent_scope: ParentScope<'a>, + item: &Item, + vis: ty::Visibility, + root_span: Span, ) { debug!("build_reduced_graph_for_use_tree(parent_prefix={:?}, \ uniform_paths_canary_emitted={}, \ use_tree={:?}, nested={})", parent_prefix, uniform_paths_canary_emitted, use_tree, nested); - let is_prelude = attr::contains_name(&item.attrs, "prelude_import"); let uniform_paths = self.session.rust_2018() && self.session.features_untracked().uniform_paths; @@ -215,8 +215,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> { subclass, source.ident.span, id, - root_use_tree.span, - root_id, + root_span, + item.id, ty::Visibility::Invisible, parent_scope.clone(), true, // is_uniform_paths_canary @@ -345,8 +345,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> { subclass, use_tree.span, id, - root_use_tree.span, - root_id, + root_span, + item.id, vis, parent_scope, false, // is_uniform_paths_canary @@ -354,7 +354,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } ast::UseTreeKind::Glob => { let subclass = GlobImport { - is_prelude, + is_prelude: attr::contains_name(&item.attrs, "prelude_import"), max_vis: Cell::new(ty::Visibility::Invisible), }; self.add_import_directive( @@ -362,8 +362,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> { subclass, use_tree.span, id, - root_use_tree.span, - root_id, + root_span, + item.id, vis, parent_scope, false, // is_uniform_paths_canary @@ -394,16 +394,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> { for &(ref tree, id) in items { self.build_reduced_graph_for_use_tree( - root_use_tree, - root_id, - tree, - id, - vis, - &prefix, - uniform_paths_canary_emitted, - true, - item, - parent_scope.clone(), + // This particular use tree + tree, id, &prefix, true, uniform_paths_canary_emitted, + // The whole `use` item + parent_scope.clone(), item, vis, root_span, ); } } @@ -421,16 +415,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> { match item.node { ItemKind::Use(ref use_tree) => { self.build_reduced_graph_for_use_tree( - use_tree, - item.id, - use_tree, - item.id, - vis, - &[], - false, // uniform_paths_canary_emitted - false, - item, - parent_scope, + // This particular use tree + use_tree, item.id, &[], false, false, + // The whole `use` item + parent_scope, item, vis, use_tree.span, ); } diff --git a/src/librustc_resolve/error_reporting.rs b/src/librustc_resolve/error_reporting.rs index d77b1868ed72e..def67923322aa 100644 --- a/src/librustc_resolve/error_reporting.rs +++ b/src/librustc_resolve/error_reporting.rs @@ -9,6 +9,7 @@ // except according to those terms. use {CrateLint, PathResult, Segment}; +use macros::ParentScope; use std::collections::BTreeSet; @@ -23,7 +24,8 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { pub(crate) fn make_path_suggestion( &mut self, span: Span, - path: Vec + path: Vec, + parent_scope: &ParentScope<'b>, ) -> Option> { debug!("make_path_suggestion: span={:?} path={:?}", span, path); // If we don't have a path to suggest changes to, then return. @@ -40,10 +42,12 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { (Some(fst), Some(snd)) if !is_special(fst.ident) && !is_special(snd.ident) => { debug!("make_path_suggestion: fst={:?} snd={:?}", fst, snd); - self.make_missing_self_suggestion(span, path.clone()) - .or_else(|| self.make_missing_crate_suggestion(span, path.clone())) - .or_else(|| self.make_missing_super_suggestion(span, path.clone())) - .or_else(|| self.make_external_crate_suggestion(span, path)) + self.make_missing_self_suggestion(span, path.clone(), parent_scope) + .or_else(|| self.make_missing_crate_suggestion(span, path.clone(), + parent_scope)) + .or_else(|| self.make_missing_super_suggestion(span, path.clone(), + parent_scope)) + .or_else(|| self.make_external_crate_suggestion(span, path, parent_scope)) }, _ => None, } @@ -59,11 +63,12 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { fn make_missing_self_suggestion( &mut self, span: Span, - mut path: Vec + mut path: Vec, + parent_scope: &ParentScope<'b>, ) -> Option> { // Replace first ident with `self` and check if that is valid. path[0].ident.name = keywords::SelfValue.name(); - let result = self.resolve_path(None, &path, None, false, span, CrateLint::No); + let result = self.resolve_path(None, &path, None, parent_scope, false, span, CrateLint::No); debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result); if let PathResult::Module(..) = result { Some(path) @@ -82,11 +87,12 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { fn make_missing_crate_suggestion( &mut self, span: Span, - mut path: Vec + mut path: Vec, + parent_scope: &ParentScope<'b>, ) -> Option> { // Replace first ident with `crate` and check if that is valid. path[0].ident.name = keywords::Crate.name(); - let result = self.resolve_path(None, &path, None, false, span, CrateLint::No); + let result = self.resolve_path(None, &path, None, parent_scope, false, span, CrateLint::No); debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result); if let PathResult::Module(..) = result { Some(path) @@ -105,11 +111,12 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { fn make_missing_super_suggestion( &mut self, span: Span, - mut path: Vec + mut path: Vec, + parent_scope: &ParentScope<'b>, ) -> Option> { // Replace first ident with `crate` and check if that is valid. path[0].ident.name = keywords::Super.name(); - let result = self.resolve_path(None, &path, None, false, span, CrateLint::No); + let result = self.resolve_path(None, &path, None, parent_scope, false, span, CrateLint::No); debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result); if let PathResult::Module(..) = result { Some(path) @@ -131,7 +138,8 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { fn make_external_crate_suggestion( &mut self, span: Span, - mut path: Vec + mut path: Vec, + parent_scope: &ParentScope<'b>, ) -> Option> { // Need to clone else we can't call `resolve_path` without a borrow error. We also store // into a `BTreeMap` so we can get consistent ordering (and therefore the same diagnostic) @@ -149,7 +157,8 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { // Replace the first after root (a placeholder we inserted) with a crate name // and check if that is valid. path[1].ident.name = *name; - let result = self.resolve_path(None, &path, None, false, span, CrateLint::No); + let result = + self.resolve_path(None, &path, None, parent_scope, false, span, CrateLint::No); debug!("make_external_crate_suggestion: name={:?} path={:?} result={:?}", name, path, result); if let PathResult::Module(..) = result { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 9d3f64e5b2a42..397c67e7587b9 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1054,7 +1054,7 @@ pub struct ModuleData<'a> { resolutions: RefCell>>>, legacy_macro_resolutions: RefCell, Option<&'a NameBinding<'a>>)>>, - macro_resolutions: RefCell, Span)>>, + macro_resolutions: RefCell, ParentScope<'a>, Span)>>, builtin_attrs: RefCell)>>, // Macro invocations that can expand into items in this module. @@ -1668,22 +1668,15 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> { let segments = &path.segments; let path = Segment::from_path(&path); // FIXME (Manishearth): Intra doc links won't get warned of epoch changes - let def = match self.resolve_path(None, &path, Some(namespace), true, span, CrateLint::No) { + let def = match self.resolve_path_without_parent_scope(None, &path, Some(namespace), + true, span, CrateLint::No) { PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.def().unwrap(), PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => path_res.base_def(), PathResult::NonModule(..) => { - if let PathResult::Failed(span, msg, _) = self.resolve_path( - None, - &path, - None, - true, - span, - CrateLint::No, - ) { - error_callback(self, span, ResolutionError::FailedToResolve(&msg)); - } + let msg = "type-relative paths are not supported in this context"; + error_callback(self, span, ResolutionError::FailedToResolve(msg)); Def::Err } PathResult::Module(ModuleOrUniformRoot::UniformRoot(_)) | @@ -2530,10 +2523,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { new_id = Some(def.def_id()); let span = trait_ref.path.span; if let PathResult::Module(ModuleOrUniformRoot::Module(module)) = - self.resolve_path( + self.resolve_path_without_parent_scope( None, &path, - None, + Some(TypeNS), false, span, CrateLint::SimplePath(trait_ref.ref_id), @@ -3055,8 +3048,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { (String::new(), "the crate root".to_string()) } else { let mod_path = &path[..path.len() - 1]; - let mod_prefix = match this.resolve_path(None, mod_path, Some(TypeNS), - false, span, CrateLint::No) { + let mod_prefix = match this.resolve_path_without_parent_scope( + None, mod_path, Some(TypeNS), false, span, CrateLint::No + ) { PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.def(), _ => None, @@ -3540,7 +3534,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { )); } - let result = match self.resolve_path( + let result = match self.resolve_path_without_parent_scope( None, &path, Some(ns), @@ -3587,7 +3581,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { path[0].ident.name != keywords::CrateRoot.name() && path[0].ident.name != keywords::DollarCrate.name() { let unqualified_result = { - match self.resolve_path( + match self.resolve_path_without_parent_scope( None, &[*path.last().unwrap()], Some(ns), @@ -3610,7 +3604,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { Some(result) } - fn resolve_path( + fn resolve_path_without_parent_scope( &mut self, base_module: Option>, path: &[Segment], @@ -3619,12 +3613,15 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { path_span: Span, crate_lint: CrateLint, ) -> PathResult<'a> { + // Macro and import paths must have full parent scope available during resolution, + // other paths will do okay with parent module alone. + assert!(opt_ns != None && opt_ns != Some(MacroNS)); let parent_scope = ParentScope { module: self.current_module, ..self.dummy_parent_scope() }; - self.resolve_path_with_parent_scope(base_module, path, opt_ns, &parent_scope, - record_used, path_span, crate_lint) + self.resolve_path(base_module, path, opt_ns, &parent_scope, + record_used, path_span, crate_lint) } - fn resolve_path_with_parent_scope( + fn resolve_path( &mut self, base_module: Option>, path: &[Segment], @@ -3820,7 +3817,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { PathResult::Module(module.unwrap_or_else(|| { span_bug!(path_span, "resolve_path: empty(?) path {:?} has no module", path); })) - } fn lint_if_path_starts_with_module( @@ -4104,8 +4100,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { } else { // Search in module. let mod_path = &path[..path.len() - 1]; - if let PathResult::Module(module) = self.resolve_path(None, mod_path, Some(TypeNS), - false, span, CrateLint::No) { + if let PathResult::Module(module) = self.resolve_path_without_parent_scope( + None, mod_path, Some(TypeNS), false, span, CrateLint::No + ) { if let ModuleOrUniformRoot::Module(module) = module { add_module_candidates(module, &mut names); } diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 6a9aaa4ea710c..d5f344346c2d1 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -462,7 +462,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { parent_scope: &ParentScope<'a>, force: bool, ) -> Result { - let span = path.span; + let path_span = path.span; let mut path = Segment::from_path(path); // Possibly apply the macro helper hack @@ -474,15 +474,15 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } if path.len() > 1 { - let def = match self.resolve_path_with_parent_scope(None, &path, Some(MacroNS), - parent_scope, false, span, - CrateLint::No) { + let def = match self.resolve_path(None, &path, Some(MacroNS), parent_scope, + false, path_span, CrateLint::No) { PathResult::NonModule(path_res) => match path_res.base_def() { Def::Err => Err(Determinacy::Determined), def @ _ => { if path_res.unresolved_segments() > 0 { self.found_unresolved_macro = true; - self.session.span_err(span, "fail to resolve non-ident macro path"); + self.session.span_err(path_span, + "fail to resolve non-ident macro path"); Err(Determinacy::Determined) } else { Ok(def) @@ -498,16 +498,12 @@ impl<'a, 'cl> Resolver<'a, 'cl> { }; parent_scope.module.macro_resolutions.borrow_mut() - .push((path - .iter() - .map(|seg| seg.ident) - .collect::>() - .into_boxed_slice(), span)); + .push((path, parent_scope.clone(), path_span)); def } else { let binding = self.early_resolve_ident_in_lexical_scope( - path[0].ident, MacroNS, Some(kind), parent_scope, false, force, span + path[0].ident, MacroNS, Some(kind), parent_scope, false, force, path_span ); match binding { Ok(..) => {} @@ -851,9 +847,14 @@ impl<'a, 'cl> Resolver<'a, 'cl> { pub fn finalize_current_module_macro_resolutions(&mut self) { let module = self.current_module; - for &(ref path, span) in module.macro_resolutions.borrow().iter() { - let path: Vec<_> = path.iter().map(|&ident| Segment::from_ident(ident)).collect(); - match self.resolve_path(None, &path, Some(MacroNS), true, span, CrateLint::No) { + + let macro_resolutions = + mem::replace(&mut *module.macro_resolutions.borrow_mut(), Vec::new()); + for (mut path, parent_scope, path_span) in macro_resolutions { + // FIXME: Path resolution will ICE if segment IDs present. + for seg in &mut path { seg.id = None; } + match self.resolve_path(None, &path, Some(MacroNS), &parent_scope, + true, path_span, CrateLint::No) { PathResult::NonModule(_) => {}, PathResult::Failed(span, msg, _) => { resolve_error(self, span, ResolutionError::FailedToResolve(&msg)); diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 2ee0b564dc423..3ca0a9f7f1b97 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -877,6 +877,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { }), &directive.module_path[..], None, + &directive.parent_scope, false, directive.span, directive.crate_lint(), @@ -956,6 +957,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { }), &module_path, None, + &directive.parent_scope, true, span, directive.crate_lint(), @@ -968,7 +970,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { } PathResult::Failed(span, msg, true) => { return if let Some(suggested_path) = self.make_path_suggestion( - span, module_path.clone() + span, module_path.clone(), &directive.parent_scope ) { Some(( span, From c57f0a7201860eb87ad8df1f3e63ea1ed03dcb40 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 27 Oct 2018 23:38:09 +0300 Subject: [PATCH 6/6] resolve: Desugar empty import groups into synthetic dummy imports so that they are correctly resolved on 2018 edition --- src/librustc/hir/lowering.rs | 3 +- src/librustc_resolve/build_reduced_graph.rs | 33 +++++++-- src/librustc_resolve/lib.rs | 72 ++----------------- src/test/ui/issues/issue-28388-1.rs | 2 +- src/test/ui/issues/issue-28388-1.stderr | 8 +-- .../ui/resolve/resolve-bad-import-prefix.rs | 6 +- .../resolve/resolve-bad-import-prefix.stderr | 25 ++----- 7 files changed, 51 insertions(+), 98 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 6370a52018338..9795c0cba6154 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -3133,7 +3133,8 @@ impl<'a> LoweringContext<'a> { // Privatize the degenerate import base, used only to check // the stability of `use a::{};`, to avoid it showing up as // a re-export by accident when `pub`, e.g. in documentation. - let path = P(self.lower_path(id, &prefix, ParamMode::Explicit)); + let def = self.expect_full_def_from_use(id).next().unwrap_or(Def::Err); + let path = P(self.lower_path_extra(def, &prefix, None, ParamMode::Explicit, None)); *vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityKind::Inherited); hir::ItemKind::Use(path, hir::UseKind::ListStem) } diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 328d5bb3af069..bb451f554d697 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -253,6 +253,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> { uniform_paths_canary_emitted = true; } + let empty_for_self = |prefix: &[Segment]| { + prefix.is_empty() || + prefix.len() == 1 && prefix[0].ident.name == keywords::CrateRoot.name() + }; match use_tree.kind { ast::UseTreeKind::Simple(rename, ..) => { let mut ident = use_tree.ident(); @@ -265,10 +269,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { if source.ident.name == keywords::SelfValue.name() { type_ns_only = true; - let empty_prefix = module_path.last().map_or(true, |seg| { - seg.ident.name == keywords::CrateRoot.name() - }); - if empty_prefix { + if empty_for_self(&module_path) { resolve_error( self, use_tree.span, @@ -400,6 +401,30 @@ impl<'a, 'cl> Resolver<'a, 'cl> { parent_scope.clone(), item, vis, root_span, ); } + + // Empty groups `a::b::{}` are turned into synthetic `self` imports + // `a::b::c::{self as _}`, so that their prefixes are correctly + // resolved and checked for privacy/stability/etc. + if items.is_empty() && !empty_for_self(&prefix) { + let new_span = prefix[prefix.len() - 1].ident.span; + let tree = ast::UseTree { + prefix: ast::Path::from_ident( + Ident::new(keywords::SelfValue.name(), new_span) + ), + kind: ast::UseTreeKind::Simple( + Some(Ident::new(keywords::Underscore.name().gensymed(), new_span)), + ast::DUMMY_NODE_ID, + ast::DUMMY_NODE_ID, + ), + span: use_tree.span, + }; + self.build_reduced_graph_for_use_tree( + // This particular use tree + &tree, id, &prefix, true, uniform_paths_canary_emitted, + // The whole `use` item + parent_scope.clone(), item, ty::Visibility::Invisible, root_span, + ); + } } } } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 397c67e7587b9..ebd87e87ff60a 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -482,15 +482,13 @@ enum PathSource<'a> { TraitItem(Namespace), // Path in `pub(path)` Visibility, - // Path in `use a::b::{...};` - ImportPrefix, } impl<'a> PathSource<'a> { fn namespace(self) -> Namespace { match self { PathSource::Type | PathSource::Trait(_) | PathSource::Struct | - PathSource::Visibility | PathSource::ImportPrefix => TypeNS, + PathSource::Visibility => TypeNS, PathSource::Expr(..) | PathSource::Pat | PathSource::TupleStruct => ValueNS, PathSource::TraitItem(ns) => ns, } @@ -498,7 +496,7 @@ impl<'a> PathSource<'a> { fn global_by_default(self) -> bool { match self { - PathSource::Visibility | PathSource::ImportPrefix => true, + PathSource::Visibility => true, PathSource::Type | PathSource::Expr(..) | PathSource::Pat | PathSource::Struct | PathSource::TupleStruct | PathSource::Trait(_) | PathSource::TraitItem(..) => false, @@ -510,7 +508,7 @@ impl<'a> PathSource<'a> { PathSource::Type | PathSource::Expr(..) | PathSource::Pat | PathSource::Struct | PathSource::TupleStruct => true, PathSource::Trait(_) | PathSource::TraitItem(..) | - PathSource::Visibility | PathSource::ImportPrefix => false, + PathSource::Visibility => false, } } @@ -522,7 +520,6 @@ impl<'a> PathSource<'a> { PathSource::Struct => "struct, variant or union type", PathSource::TupleStruct => "tuple struct/variant", PathSource::Visibility => "module", - PathSource::ImportPrefix => "module or enum", PathSource::TraitItem(ns) => match ns { TypeNS => "associated type", ValueNS => "method or associated constant", @@ -587,10 +584,6 @@ impl<'a> PathSource<'a> { Def::AssociatedTy(..) if ns == TypeNS => true, _ => false, }, - PathSource::ImportPrefix => match def { - Def::Mod(..) | Def::Enum(..) => true, - _ => false, - }, PathSource::Visibility => match def { Def::Mod(..) => true, _ => false, @@ -626,8 +619,8 @@ impl<'a> PathSource<'a> { (PathSource::Pat, false) | (PathSource::TupleStruct, false) => "E0531", (PathSource::TraitItem(..), true) => "E0575", (PathSource::TraitItem(..), false) => "E0576", - (PathSource::Visibility, true) | (PathSource::ImportPrefix, true) => "E0577", - (PathSource::Visibility, false) | (PathSource::ImportPrefix, false) => "E0578", + (PathSource::Visibility, true) => "E0577", + (PathSource::Visibility, false) => "E0578", } } } @@ -2350,16 +2343,8 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { }); } - ItemKind::Use(ref use_tree) => { - // Imports are resolved as global by default, add starting root segment. - let path = Path { - segments: use_tree.prefix.make_root().into_iter().collect(), - span: use_tree.span, - }; - self.resolve_use_tree(item.id, use_tree.span, item.id, use_tree, &path); - } - - ItemKind::ExternCrate(_) | ItemKind::MacroDef(..) | ItemKind::GlobalAsm(_) => { + ItemKind::Use(..) | ItemKind::ExternCrate(..) | + ItemKind::MacroDef(..) | ItemKind::GlobalAsm(..) => { // do nothing, these are just around to be encoded } @@ -2367,49 +2352,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { } } - /// For the most part, use trees are desugared into `ImportDirective` instances - /// when building the reduced graph (see `build_reduced_graph_for_use_tree`). But - /// there is one special case we handle here: an empty nested import like - /// `a::{b::{}}`, which desugares into...no import directives. - fn resolve_use_tree( - &mut self, - root_id: NodeId, - root_span: Span, - id: NodeId, - use_tree: &ast::UseTree, - prefix: &Path, - ) { - match use_tree.kind { - ast::UseTreeKind::Nested(ref items) => { - let path = Path { - segments: prefix.segments - .iter() - .chain(use_tree.prefix.segments.iter()) - .cloned() - .collect(), - span: prefix.span.to(use_tree.prefix.span), - }; - - if items.is_empty() { - // Resolve prefix of an import with empty braces (issue #28388). - self.smart_resolve_path_with_crate_lint( - id, - None, - &path, - PathSource::ImportPrefix, - CrateLint::UsePath { root_id, root_span }, - ); - } else { - for &(ref tree, nested_id) in items { - self.resolve_use_tree(root_id, root_span, nested_id, tree, &path); - } - } - } - ast::UseTreeKind::Simple(..) => {}, - ast::UseTreeKind::Glob => {}, - } - } - fn with_type_parameter_rib<'b, F>(&'b mut self, type_parameters: TypeParameters<'a, 'b>, f: F) where F: FnOnce(&mut Resolver) { diff --git a/src/test/ui/issues/issue-28388-1.rs b/src/test/ui/issues/issue-28388-1.rs index 187d91731d0d6..b0418a513e31c 100644 --- a/src/test/ui/issues/issue-28388-1.rs +++ b/src/test/ui/issues/issue-28388-1.rs @@ -10,6 +10,6 @@ // Prefix in imports with empty braces should be resolved and checked privacy, stability, etc. -use foo::{}; //~ ERROR cannot find module or enum `foo` in the crate root +use foo::{}; //~ ERROR unresolved import `foo` fn main() {} diff --git a/src/test/ui/issues/issue-28388-1.stderr b/src/test/ui/issues/issue-28388-1.stderr index 9f4b6cb56e727..f93252f1d7dec 100644 --- a/src/test/ui/issues/issue-28388-1.stderr +++ b/src/test/ui/issues/issue-28388-1.stderr @@ -1,9 +1,9 @@ -error[E0578]: cannot find module or enum `foo` in the crate root +error[E0432]: unresolved import `foo` --> $DIR/issue-28388-1.rs:13:5 | -LL | use foo::{}; //~ ERROR cannot find module or enum `foo` in the crate root - | ^^^ not found in the crate root +LL | use foo::{}; //~ ERROR unresolved import `foo` + | ^^^^^^^ no `foo` in the root error: aborting due to previous error -For more information about this error, try `rustc --explain E0578`. +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/resolve/resolve-bad-import-prefix.rs b/src/test/ui/resolve/resolve-bad-import-prefix.rs index 370782fc7d9e9..5da5a8c3fef62 100644 --- a/src/test/ui/resolve/resolve-bad-import-prefix.rs +++ b/src/test/ui/resolve/resolve-bad-import-prefix.rs @@ -17,8 +17,8 @@ use {}; // OK use ::{}; // OK use m::{}; // OK use E::{}; // OK -use S::{}; //~ ERROR expected module or enum, found struct `S` -use Tr::{}; //~ ERROR expected module or enum, found trait `Tr` -use Nonexistent::{}; //~ ERROR cannot find module or enum `Nonexistent` in the crate root +use S::{}; // FIXME, this and `use S::{self};` should be an error +use Tr::{}; // FIXME, this and `use Tr::{self};` should be an error +use Nonexistent::{}; //~ ERROR unresolved import `Nonexistent` fn main () {} diff --git a/src/test/ui/resolve/resolve-bad-import-prefix.stderr b/src/test/ui/resolve/resolve-bad-import-prefix.stderr index 76d0c035335c5..c4d9b1d0075d5 100644 --- a/src/test/ui/resolve/resolve-bad-import-prefix.stderr +++ b/src/test/ui/resolve/resolve-bad-import-prefix.stderr @@ -1,24 +1,9 @@ -error[E0577]: expected module or enum, found struct `S` - --> $DIR/resolve-bad-import-prefix.rs:20:5 - | -LL | use S::{}; //~ ERROR expected module or enum, found struct `S` - | -^^^^ - | | - | did you mean `E`? - -error[E0577]: expected module or enum, found trait `Tr` - --> $DIR/resolve-bad-import-prefix.rs:21:5 - | -LL | use Tr::{}; //~ ERROR expected module or enum, found trait `Tr` - | ^^^^^^ not a module or enum - -error[E0578]: cannot find module or enum `Nonexistent` in the crate root +error[E0432]: unresolved import `Nonexistent` --> $DIR/resolve-bad-import-prefix.rs:22:5 | -LL | use Nonexistent::{}; //~ ERROR cannot find module or enum `Nonexistent` in the crate root - | ^^^^^^^^^^^ not found in the crate root +LL | use Nonexistent::{}; //~ ERROR unresolved import `Nonexistent` + | ^^^^^^^^^^^^^^^ no `Nonexistent` in the root -error: aborting due to 3 previous errors +error: aborting due to previous error -Some errors occurred: E0577, E0578. -For more information about an error, try `rustc --explain E0577`. +For more information about this error, try `rustc --explain E0432`.