Auto merge of #56759 - petrochenkov:prestabuni, r=nikomatsakis

Stabilize `uniform_paths`

Address all the things described in https://github.com/rust-lang/rust/issues/56417.

Assign visibilities to `macro_rules` items - `pub` to `macro_export`-ed macros and `pub(crate)` to non-exported macros, these visibilities determine how far these macros can be reexported with `use`.

Prohibit use of reexported inert attributes and "tool modules", after renaming (e.g. `use inline as imported_inline`) their respective tools and even compiler passes won't be able to recognize and properly check them.

Also turn use of uniform paths in 2015 macros into an error, I'd prefer to neither remove nor stabilize them right away because I still want to make some experiments in this area (uniform path fallback was added to 2015 macros used on 2018 edition in https://github.com/rust-lang/rust/pull/56053#issuecomment-441405140).

UPDATE: The last commit also stabilizes the feature `uniform_paths`.

Closes https://github.com/rust-lang/rust/issues/53130
Closes https://github.com/rust-lang/rust/issues/55618
Closes https://github.com/rust-lang/rust/issues/56326
Closes https://github.com/rust-lang/rust/issues/56398
Closes https://github.com/rust-lang/rust/issues/56417
Closes https://github.com/rust-lang/rust/issues/56821
Closes https://github.com/rust-lang/rust/issues/57252
Closes https://github.com/rust-lang/rust/issues/57422
This commit is contained in:
bors 2019-01-12 20:11:36 +00:00
commit 75a369c5b1
38 changed files with 229 additions and 263 deletions

View File

@ -240,7 +240,7 @@ impl CtorKind {
}
impl NonMacroAttrKind {
fn descr(self) -> &'static str {
pub fn descr(self) -> &'static str {
match self {
NonMacroAttrKind::Builtin => "built-in attribute",
NonMacroAttrKind::Tool => "tool attribute",

View File

@ -67,7 +67,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
use std::cell::{Cell, RefCell};
use std::{cmp, fmt, iter, ptr};
use std::{cmp, fmt, iter, mem, ptr};
use std::collections::BTreeSet;
use std::mem::replace;
use rustc_data_structures::ptr_key::PtrKey;
@ -2375,11 +2375,27 @@ impl<'a> Resolver<'a> {
ast::UseTreeKind::Simple(..) if segments.len() == 1 => &[TypeNS, ValueNS][..],
_ => &[TypeNS],
};
for &ns in nss {
if let Some(LexicalScopeBinding::Def(..)) =
self.resolve_ident_in_lexical_scope(ident, ns, None, use_tree.prefix.span) {
let report_error = |this: &Self, ns| {
let what = if ns == TypeNS { "type parameters" } else { "local variables" };
self.session.span_err(ident.span, &format!("imports cannot refer to {}", what));
this.session.span_err(ident.span, &format!("imports cannot refer to {}", what));
};
for &ns in nss {
match self.resolve_ident_in_lexical_scope(ident, ns, None, use_tree.prefix.span) {
Some(LexicalScopeBinding::Def(..)) => {
report_error(self, ns);
}
Some(LexicalScopeBinding::Item(binding)) => {
let orig_blacklisted_binding =
mem::replace(&mut self.blacklisted_binding, Some(binding));
if let Some(LexicalScopeBinding::Def(..)) =
self.resolve_ident_in_lexical_scope(ident, ns, None,
use_tree.prefix.span) {
report_error(self, ns);
}
self.blacklisted_binding = orig_blacklisted_binding;
}
None => {}
}
}
} else if let ast::UseTreeKind::Nested(use_trees) = &use_tree.kind {
@ -3874,6 +3890,13 @@ impl<'a> Resolver<'a> {
module = Some(ModuleOrUniformRoot::Module(next_module));
record_segment_def(self, def);
} else if def == Def::ToolMod && i + 1 != path.len() {
if binding.is_import() {
self.session.struct_span_err(
ident.span, "cannot use a tool module through an import"
).span_note(
binding.span, "the tool module imported here"
).emit();
}
let def = Def::NonMacroAttr(NonMacroAttrKind::Tool);
return PathResult::NonModule(PathResolution::new(def));
} else if def == Def::Err {

View File

@ -376,6 +376,7 @@ impl<'a> Resolver<'a> {
.push((path, path_span, kind, parent_scope.clone(), def.ok()));
}
self.prohibit_imported_non_macro_attrs(None, def.ok(), path_span);
def
} else {
let binding = self.early_resolve_ident_in_lexical_scope(
@ -390,7 +391,9 @@ impl<'a> Resolver<'a> {
.push((path[0].ident, kind, parent_scope.clone(), binding.ok()));
}
binding.map(|binding| binding.def())
let def = binding.map(|binding| binding.def());
self.prohibit_imported_non_macro_attrs(binding.ok(), def.ok(), path_span);
def
}
}
@ -828,13 +831,12 @@ impl<'a> Resolver<'a> {
// but its `Def` should coincide with a crate passed with `--extern`
// (otherwise there would be ambiguity) and we can skip feature error in this case.
'ok: {
if !is_import || self.session.features_untracked().uniform_paths {
if !is_import || !rust_2015 {
break 'ok;
}
if ns == TypeNS && use_prelude && self.extern_prelude_get(ident, true).is_some() {
break 'ok;
}
if rust_2015 {
let root_ident = Ident::new(keywords::PathRoot.name(), orig_ident.span);
let root_module = self.resolve_crate_root(root_ident);
if self.resolve_ident_in_module_ext(ModuleOrUniformRoot::Module(root_module),
@ -842,13 +844,10 @@ impl<'a> Resolver<'a> {
.is_ok() {
break 'ok;
}
}
let msg = "imports can only refer to extern crate names \
passed with `--extern` on stable channel";
let mut err = feature_err(&self.session.parse_sess, "uniform_paths",
ident.span, GateIssue::Language, msg);
let msg = "imports can only refer to extern crate names passed with \
`--extern` in macros originating from 2015 edition";
let mut err = self.session.struct_span_err(ident.span, msg);
let what = self.binding_description(binding, ident,
flags.contains(Flags::MISC_FROM_PRELUDE));
let note_msg = format!("this import refers to {what}", what = what);
@ -977,6 +976,20 @@ impl<'a> Resolver<'a> {
}
}
fn prohibit_imported_non_macro_attrs(&self, binding: Option<&'a NameBinding<'a>>,
def: Option<Def>, span: Span) {
if let Some(Def::NonMacroAttr(kind)) = def {
if kind != NonMacroAttrKind::Tool && binding.map_or(true, |b| b.is_import()) {
let msg = format!("cannot use a {} through an import", kind.descr());
let mut err = self.session.struct_span_err(span, &msg);
if let Some(binding) = binding {
err.span_note(binding.span, &format!("the {} imported here", kind.descr()));
}
err.emit();
}
}
}
fn suggest_macro_name(&mut self, name: &str, kind: MacroKind,
err: &mut DiagnosticBuilder<'a>, span: Span) {
// First check if this is a locally-defined bang macro.
@ -1073,7 +1086,12 @@ impl<'a> Resolver<'a> {
let ident = ident.modern();
self.macro_names.insert(ident);
let def = Def::Macro(def_id, MacroKind::Bang);
let vis = ty::Visibility::Invisible; // Doesn't matter for legacy bindings
let is_macro_export = attr::contains_name(&item.attrs, "macro_export");
let vis = if is_macro_export {
ty::Visibility::Public
} else {
ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX))
};
let binding = (def, vis, item.span, expansion).to_name_binding(self.arenas);
self.set_binding_parent_module(binding, self.current_module);
let legacy_binding = self.arenas.alloc_legacy_binding(LegacyBinding {
@ -1081,9 +1099,8 @@ impl<'a> Resolver<'a> {
});
*current_legacy_scope = LegacyScope::Binding(legacy_binding);
self.all_macros.insert(ident.name, def);
if attr::contains_name(&item.attrs, "macro_export") {
if is_macro_export {
let module = self.graph_root;
let vis = ty::Visibility::Public;
self.define(module, ident, MacroNS,
(def, vis, item.span, expansion, IsMacroExport));
} else {

View File

@ -223,6 +223,11 @@ impl<'a> Resolver<'a> {
}
let check_usable = |this: &mut Self, binding: &'a NameBinding<'a>| {
if let Some(blacklisted_binding) = this.blacklisted_binding {
if ptr::eq(binding, blacklisted_binding) {
return Err((Determined, Weak::No));
}
}
// `extern crate` are always usable for backwards compatibility, see issue #37020,
// remove this together with `PUB_USE_OF_PRIVATE_EXTERN_CRATE`.
let usable = this.is_accessible(binding.vis) || binding.is_extern_crate();

View File

@ -434,9 +434,6 @@ declare_features! (
// support for arbitrary delimited token streams in non-macro attributes
(active, unrestricted_attribute_tokens, "1.30.0", Some(55208), None),
// Allows `use x::y;` to resolve through `self::x`, not just `::x`.
(active, uniform_paths, "1.30.0", Some(53130), None),
// Allows unsized rvalues at arguments and parameters.
(active, unsized_locals, "1.30.0", Some(48055), None),
@ -687,6 +684,8 @@ declare_features! (
(accepted, cfg_attr_multi, "1.33.0", Some(54881), None),
// Top level or-patterns (`p | q`) in `if let` and `while let`.
(accepted, if_while_or_patterns, "1.33.0", Some(48215), None),
// Allows `use x::y;` to search `x` in the current scope.
(accepted, uniform_paths, "1.32.0", Some(53130), None),
);
// If you change this, please modify `src/doc/unstable-book` as well. You must

View File

@ -1,7 +1,5 @@
// edition:2018
#![feature(uniform_paths)]
mod m { pub fn f() {} }
mod n { pub fn g() {} }

View File

@ -1,12 +1,12 @@
// run-pass
#![allow(unused_imports)]
#![allow(non_camel_case_types)]
// This test is similar to `basic.rs`, but nested in modules.
// run-pass
// edition:2018
#![feature(decl_macro, uniform_paths)]
#![feature(decl_macro)]
// This test is similar to `basic.rs`, but nested in modules.
#![allow(unused_imports)]
#![allow(non_camel_case_types)]
mod foo {
// Test that ambiguity errors are not emitted between `self::test` and

View File

@ -1,10 +1,8 @@
// run-pass
#![allow(unused_imports)]
#![allow(non_camel_case_types)]
// edition:2018
#![feature(uniform_paths)]
#![allow(unused_imports)]
#![allow(non_camel_case_types)]
// Test that ambiguity errors are not emitted between `self::test` and
// `::test`, assuming the latter (crate) is not in `extern_prelude`.

View File

@ -1,11 +1,9 @@
// run-pass
#![allow(non_camel_case_types)]
// This test is similar to `macros.rs`, but nested in modules.
// run-pass
// edition:2018
#![feature(uniform_paths)]
// This test is similar to `macros.rs`, but nested in modules.
#![allow(non_camel_case_types)]
mod foo {
// Test that ambiguity errors are not emitted between `self::test` and

View File

@ -1,11 +1,9 @@
// run-pass
#![allow(non_camel_case_types)]
// This test is similar to `basic.rs`, but with macros defining local items.
// run-pass
// edition:2018
#![feature(uniform_paths)]
// This test is similar to `basic.rs`, but with macros defining local items.
#![allow(non_camel_case_types)]
// Test that ambiguity errors are not emitted between `self::test` and
// `::test`, assuming the latter (crate) is not in `extern_prelude`.

View File

@ -1,9 +1,6 @@
// run-pass
// edition:2018
#![feature(uniform_paths)]
pub const A: usize = 0;
pub mod foo {

View File

@ -3,8 +3,6 @@
// aux-build:edition-imports-2018.rs
// aux-build:absolute.rs
#![feature(uniform_paths)]
#[macro_use]
extern crate edition_imports_2018;

View File

@ -1,5 +1,5 @@
error: cannot glob-import all possible crates
--> $DIR/edition-imports-2015.rs:25:5
--> $DIR/edition-imports-2015.rs:23:5
|
LL | gen_glob!(); //~ ERROR cannot glob-import all possible crates
| ^^^^^^^^^^^^

View File

@ -1,4 +1,4 @@
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)
error: imports can only refer to extern crate names passed with `--extern` in macros originating from 2015 edition
--> <::edition_imports_2015::gen_gated macros>:1:50
|
LL | ( ) => { fn check_gated ( ) { enum E { A } use E :: * ; } }
@ -9,7 +9,6 @@ LL | ( ) => { fn check_gated ( ) { enum E { A } use E :: * ; } }
LL | gen_gated!();
| ------------- not an extern crate passed with `--extern`
|
= help: add #![feature(uniform_paths)] to the crate attributes to enable
note: this import refers to the enum defined here
--> $DIR/edition-imports-virtual-2015-gated.rs:9:5
|
@ -19,4 +18,3 @@ LL | gen_gated!();
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,19 +0,0 @@
// edition:2018
pub mod foo {
pub use bar::Bar; //~ ERROR imports can only refer to extern crate names
pub mod bar {
pub struct Bar;
}
}
use inline; //~ ERROR imports can only refer to extern crate names
use Vec; //~ ERROR imports can only refer to extern crate names
use vec; //~ ERROR imports can only refer to extern crate names
fn main() {
let _ = foo::Bar;
}

View File

@ -1,50 +0,0 @@
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)
--> $DIR/feature-gate-uniform-paths.rs:4:13
|
LL | pub use bar::Bar; //~ ERROR imports can only refer to extern crate names
| ^^^
LL |
LL | / pub mod bar {
LL | | pub struct Bar;
LL | | }
| |_____- not an extern crate passed with `--extern`
|
= help: add #![feature(uniform_paths)] to the crate attributes to enable
note: this import refers to the module defined here
--> $DIR/feature-gate-uniform-paths.rs:6:5
|
LL | / pub mod bar {
LL | | pub struct Bar;
LL | | }
| |_____^
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)
--> $DIR/feature-gate-uniform-paths.rs:11:5
|
LL | use inline; //~ ERROR imports can only refer to extern crate names
| ^^^^^^ not an extern crate passed with `--extern`
|
= help: add #![feature(uniform_paths)] to the crate attributes to enable
= note: this import refers to a built-in attribute
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)
--> $DIR/feature-gate-uniform-paths.rs:13:5
|
LL | use Vec; //~ ERROR imports can only refer to extern crate names
| ^^^ not an extern crate passed with `--extern`
|
= help: add #![feature(uniform_paths)] to the crate attributes to enable
= note: this import refers to a struct from prelude
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)
--> $DIR/feature-gate-uniform-paths.rs:15:5
|
LL | use vec; //~ ERROR imports can only refer to extern crate names
| ^^^ not an extern crate passed with `--extern`
|
= help: add #![feature(uniform_paths)] to the crate attributes to enable
= note: this import refers to a macro from prelude
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0658`.

View File

@ -2,8 +2,6 @@
// compile-flags:--extern issue_56125
// aux-build:issue-56125.rs
#![feature(uniform_paths)]
mod m1 {
use issue_56125::last_segment::*;
//~^ ERROR `issue_56125` is ambiguous

View File

@ -1,11 +1,11 @@
error[E0432]: unresolved import `empty::issue_56125`
--> $DIR/issue-56125.rs:19:9
--> $DIR/issue-56125.rs:17:9
|
LL | use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
| ^^^^^^^^^^^^^^^^^^ no `issue_56125` in `m3::empty`
error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
--> $DIR/issue-56125.rs:8:9
--> $DIR/issue-56125.rs:6:9
|
LL | use issue_56125::last_segment::*;
| ^^^^^^^^^^^ ambiguous name
@ -13,14 +13,14 @@ LL | use issue_56125::last_segment::*;
= note: `issue_56125` could refer to an extern crate passed with `--extern`
= help: use `::issue_56125` to refer to this extern crate unambiguously
note: `issue_56125` could also refer to the module imported here
--> $DIR/issue-56125.rs:8:9
--> $DIR/issue-56125.rs:6:9
|
LL | use issue_56125::last_segment::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use `self::issue_56125` to refer to this module unambiguously
error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
--> $DIR/issue-56125.rs:13:9
--> $DIR/issue-56125.rs:11:9
|
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^ ambiguous name
@ -28,14 +28,14 @@ LL | use issue_56125::non_last_segment::non_last_segment::*;
= note: `issue_56125` could refer to an extern crate passed with `--extern`
= help: use `::issue_56125` to refer to this extern crate unambiguously
note: `issue_56125` could also refer to the module imported here
--> $DIR/issue-56125.rs:13:9
--> $DIR/issue-56125.rs:11:9
|
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use `self::issue_56125` to refer to this module unambiguously
error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
--> $DIR/issue-56125.rs:20:9
--> $DIR/issue-56125.rs:18:9
|
LL | use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
| ^^^^^^^^^^^ ambiguous name
@ -43,7 +43,7 @@ LL | use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
= note: `issue_56125` could refer to an extern crate passed with `--extern`
= help: use `::issue_56125` to refer to this extern crate unambiguously
note: `issue_56125` could also refer to the module imported here
--> $DIR/issue-56125.rs:20:9
--> $DIR/issue-56125.rs:18:9
|
LL | use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
| ^^^^^^^^^^^^^^

View File

@ -5,6 +5,26 @@ use derive_helper_shadowing::*;
#[my_attr] //~ ERROR `my_attr` is ambiguous
#[derive(MyTrait)]
struct S;
struct S {
// FIXME No ambiguity, attributes in non-macro positions are not resolved properly
#[my_attr]
field: [u8; {
// FIXME No ambiguity, derive helpers are not put into scope for non-attributes
use my_attr;
fn main() {}
// FIXME No ambiguity, derive helpers are not put into scope for inner items
#[my_attr]
struct U;
mod inner {
#[my_attr] //~ ERROR attribute `my_attr` is currently unknown
struct V;
}
0
}]
}
fn main() {
let s = S { field: [] };
}

View File

@ -1,3 +1,11 @@
error[E0658]: The attribute `my_attr` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
--> $DIR/derive-helper-shadowing.rs:20:15
|
LL | #[my_attr] //~ ERROR attribute `my_attr` is currently unknown
| ^^^^^^^
|
= help: add #![feature(custom_attribute)] to the crate attributes to enable
error[E0659]: `my_attr` is ambiguous (derive helper attribute vs any other name)
--> $DIR/derive-helper-shadowing.rs:6:3
|
@ -16,6 +24,7 @@ LL | use derive_helper_shadowing::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use `crate::my_attr` to refer to this attribute macro unambiguously
error: aborting due to previous error
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0659`.
Some errors occurred: E0658, E0659.
For more information about an error, try `rustc --explain E0658`.

View File

@ -1,7 +1,5 @@
// edition:2018
#![feature(uniform_paths)]
// Tests that arbitrary crates (other than `core`, `std` and `meta`)
// aren't allowed without `--extern`, even if they're in the sysroot.
use alloc; //~ ERROR unresolved import `alloc`

View File

@ -1,11 +1,11 @@
error: cannot import a built-in macro
--> $DIR/not-whitelisted.rs:8:5
--> $DIR/not-whitelisted.rs:6:5
|
LL | use test; //~ ERROR cannot import a built-in macro
| ^^^^
error[E0432]: unresolved import `alloc`
--> $DIR/not-whitelisted.rs:7:5
--> $DIR/not-whitelisted.rs:5:5
|
LL | use alloc; //~ ERROR unresolved import `alloc`
| ^^^^^ no `alloc` external crate

View File

@ -1,6 +1,5 @@
// edition:2018
#![feature(uniform_paths)]
#![allow(non_camel_case_types)]
mod T {
@ -17,7 +16,7 @@ fn type_param<T>() {
}
fn self_import<T>() {
use T; // FIXME Should be an error, but future-proofing fails due to `T` being "self-shadowed"
use T; //~ ERROR imports cannot refer to type parameters
}
fn let_binding() {

View File

@ -1,50 +1,56 @@
error: imports cannot refer to type parameters
--> $DIR/future-proofing-locals.rs:14:9
--> $DIR/future-proofing-locals.rs:13:9
|
LL | use T as _; //~ ERROR imports cannot refer to type parameters
| ^
error: imports cannot refer to type parameters
--> $DIR/future-proofing-locals.rs:15:9
--> $DIR/future-proofing-locals.rs:14:9
|
LL | use T::U; //~ ERROR imports cannot refer to type parameters
| ^
error: imports cannot refer to type parameters
--> $DIR/future-proofing-locals.rs:16:9
--> $DIR/future-proofing-locals.rs:15:9
|
LL | use T::*; //~ ERROR imports cannot refer to type parameters
| ^
error: imports cannot refer to type parameters
--> $DIR/future-proofing-locals.rs:19:9
|
LL | use T; //~ ERROR imports cannot refer to type parameters
| ^
error: imports cannot refer to local variables
--> $DIR/future-proofing-locals.rs:26:9
--> $DIR/future-proofing-locals.rs:25:9
|
LL | use x as _; //~ ERROR imports cannot refer to local variables
| ^
error: imports cannot refer to local variables
--> $DIR/future-proofing-locals.rs:32:9
--> $DIR/future-proofing-locals.rs:31:9
|
LL | use x; //~ ERROR imports cannot refer to local variables
| ^
error: imports cannot refer to local variables
--> $DIR/future-proofing-locals.rs:38:17
--> $DIR/future-proofing-locals.rs:37:17
|
LL | use x; //~ ERROR imports cannot refer to local variables
| ^
error: imports cannot refer to type parameters
--> $DIR/future-proofing-locals.rs:46:10
--> $DIR/future-proofing-locals.rs:45:10
|
LL | use {T as _, x}; //~ ERROR imports cannot refer to type parameters
| ^
error: imports cannot refer to local variables
--> $DIR/future-proofing-locals.rs:46:18
--> $DIR/future-proofing-locals.rs:45:18
|
LL | use {T as _, x}; //~ ERROR imports cannot refer to type parameters
| ^
error: aborting due to 8 previous errors
error: aborting due to 9 previous errors

View File

@ -2,8 +2,6 @@
// compile-flags:--extern baz
// edition:2018
#![feature(uniform_paths)]
mod foo {
pub type Bar = u32;
}

View File

@ -1,5 +1,5 @@
error[E0432]: unresolved import `foo`
--> $DIR/local-path-suggestions-2018.rs:12:9
--> $DIR/local-path-suggestions-2018.rs:10:9
|
LL | use foo::Bar; //~ ERROR unresolved import `foo`
| ^^^ did you mean `crate::foo`?
@ -7,7 +7,7 @@ LL | use foo::Bar; //~ ERROR unresolved import `foo`
= note: `use` statements changed in Rust 2018; read more at <https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html>
error[E0432]: unresolved import `foobar`
--> $DIR/local-path-suggestions-2018.rs:21:5
--> $DIR/local-path-suggestions-2018.rs:19:5
|
LL | use foobar::Baz; //~ ERROR unresolved import `foobar`
| ^^^^^^ did you mean `baz::foobar`?

View File

@ -1,7 +1,5 @@
// edition:2018
#![feature(uniform_paths)]
mod my {
pub mod sub {
pub fn bar() {}

View File

@ -1,16 +1,16 @@
error[E0659]: `sub` is ambiguous (name vs any other name during import resolution)
--> $DIR/block-scoped-shadow-nested.rs:18:13
--> $DIR/block-scoped-shadow-nested.rs:16:13
|
LL | use sub::bar; //~ ERROR `sub` is ambiguous
| ^^^ ambiguous name
|
note: `sub` could refer to the module imported here
--> $DIR/block-scoped-shadow-nested.rs:16:9
--> $DIR/block-scoped-shadow-nested.rs:14:9
|
LL | use my::sub;
| ^^^^^^^
note: `sub` could also refer to the module defined here
--> $DIR/block-scoped-shadow-nested.rs:11:1
--> $DIR/block-scoped-shadow-nested.rs:9:1
|
LL | / mod sub {
LL | | pub fn bar() {}

View File

@ -1,8 +1,6 @@
// compile-pass
// edition:2018
#![feature(uniform_paths)]
fn main() {
enum E { A, B, C }

View File

@ -1,11 +0,0 @@
// edition:2018
#![deny(unused)]
use std::fmt;
// No "unresolved import" + "unused import" combination here.
use fmt::Write; //~ ERROR imports can only refer to extern crate names
//~| ERROR unused import: `fmt::Write`
fn main() {}

View File

@ -1,32 +0,0 @@
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)
--> $DIR/issue-54390.rs:8:5
|
LL | use std::fmt;
| -------- not an extern crate passed with `--extern`
...
LL | use fmt::Write; //~ ERROR imports can only refer to extern crate names
| ^^^
|
= help: add #![feature(uniform_paths)] to the crate attributes to enable
note: this import refers to the module imported here
--> $DIR/issue-54390.rs:5:5
|
LL | use std::fmt;
| ^^^^^^^^
error: unused import: `fmt::Write`
--> $DIR/issue-54390.rs:8:5
|
LL | use fmt::Write; //~ ERROR imports can only refer to extern crate names
| ^^^^^^^^^^
|
note: lint level defined here
--> $DIR/issue-54390.rs:3:9
|
LL | #![deny(unused)]
| ^^^^^^
= note: #[deny(unused_imports)] implied by #[deny(unused)]
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,23 +1,23 @@
// edition:2018
// For the time being `macro_rules` items are treated as *very* private...
#![feature(decl_macro, uniform_paths)]
#![allow(non_camel_case_types)]
#![feature(decl_macro)]
mod m1 {
// Non-exported legacy macros are treated as `pub(crate)`.
macro_rules! legacy_macro { () => () }
// ... so they can't be imported by themselves, ...
use legacy_macro as _; //~ ERROR `legacy_macro` is private, and cannot be re-exported
use legacy_macro as _; // OK
pub(crate) use legacy_macro as _; // OK
pub use legacy_macro as _; //~ ERROR `legacy_macro` is private, and cannot be re-exported
}
mod m2 {
macro_rules! legacy_macro { () => () }
#[allow(non_camel_case_types)]
type legacy_macro = u8;
// ... but don't prevent names from other namespaces from being imported, ...
// Legacy macro imports don't prevent names from other namespaces from being imported.
use legacy_macro as _; // OK
}
@ -27,19 +27,17 @@ mod m3 {
fn f() {
macro_rules! legacy_macro { () => () }
// ... but still create ambiguities with other names in the same namespace.
// Legacy macro imports create ambiguities with other names in the same namespace.
use legacy_macro as _; //~ ERROR `legacy_macro` is ambiguous
//~| ERROR `legacy_macro` is private, and cannot be re-exported
}
}
mod exported {
// Exported macros are treated as private as well,
// some better rules need to be figured out later.
// Exported legacy macros are treated as `pub`.
#[macro_export]
macro_rules! legacy_macro { () => () }
use legacy_macro as _; //~ ERROR `legacy_macro` is private, and cannot be re-exported
pub use legacy_macro as _; // OK
}
fn main() {}

View File

@ -1,37 +1,13 @@
error[E0364]: `legacy_macro` is private, and cannot be re-exported
--> $DIR/macro-rules.rs:12:9
--> $DIR/macro-rules.rs:11:13
|
LL | use legacy_macro as _; //~ ERROR `legacy_macro` is private, and cannot be re-exported
LL | pub use legacy_macro as _; //~ ERROR `legacy_macro` is private, and cannot be re-exported
| ^^^^^^^^^^^^^^^^^
|
note: consider marking `legacy_macro` as `pub` in the imported module
--> $DIR/macro-rules.rs:12:9
--> $DIR/macro-rules.rs:11:13
|
LL | use legacy_macro as _; //~ ERROR `legacy_macro` is private, and cannot be re-exported
| ^^^^^^^^^^^^^^^^^
error[E0364]: `legacy_macro` is private, and cannot be re-exported
--> $DIR/macro-rules.rs:31:13
|
LL | use legacy_macro as _; //~ ERROR `legacy_macro` is ambiguous
| ^^^^^^^^^^^^^^^^^
|
note: consider marking `legacy_macro` as `pub` in the imported module
--> $DIR/macro-rules.rs:31:13
|
LL | use legacy_macro as _; //~ ERROR `legacy_macro` is ambiguous
| ^^^^^^^^^^^^^^^^^
error[E0364]: `legacy_macro` is private, and cannot be re-exported
--> $DIR/macro-rules.rs:42:9
|
LL | use legacy_macro as _; //~ ERROR `legacy_macro` is private, and cannot be re-exported
| ^^^^^^^^^^^^^^^^^
|
note: consider marking `legacy_macro` as `pub` in the imported module
--> $DIR/macro-rules.rs:42:9
|
LL | use legacy_macro as _; //~ ERROR `legacy_macro` is private, and cannot be re-exported
LL | pub use legacy_macro as _; //~ ERROR `legacy_macro` is private, and cannot be re-exported
| ^^^^^^^^^^^^^^^^^
error[E0659]: `legacy_macro` is ambiguous (name vs any other name during import resolution)
@ -52,7 +28,7 @@ LL | macro legacy_macro() {}
| ^^^^^^^^^^^^^^^^^^^^^^^
= help: use `self::legacy_macro` to refer to this macro unambiguously
error: aborting due to 4 previous errors
error: aborting due to 2 previous errors
Some errors occurred: E0364, E0659.
For more information about an error, try `rustc --explain E0364`.

View File

@ -0,0 +1,19 @@
// edition:2018
// Built-in attribute
use inline as imported_inline;
mod builtin {
pub use inline as imported_inline;
}
// Tool module
use rustfmt as imported_rustfmt;
mod tool_mod {
pub use rustfmt as imported_rustfmt;
}
#[imported_inline] //~ ERROR cannot use a built-in attribute through an import
#[builtin::imported_inline] //~ ERROR cannot use a built-in attribute through an import
#[imported_rustfmt::skip] //~ ERROR cannot use a tool module through an import
#[tool_mod::imported_rustfmt::skip] //~ ERROR cannot use a tool module through an import
fn main() {}

View File

@ -0,0 +1,44 @@
error: cannot use a built-in attribute through an import
--> $DIR/prelude-fail-2.rs:15:3
|
LL | #[imported_inline] //~ ERROR cannot use a built-in attribute through an import
| ^^^^^^^^^^^^^^^
|
note: the built-in attribute imported here
--> $DIR/prelude-fail-2.rs:4:5
|
LL | use inline as imported_inline;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: cannot use a built-in attribute through an import
--> $DIR/prelude-fail-2.rs:16:3
|
LL | #[builtin::imported_inline] //~ ERROR cannot use a built-in attribute through an import
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: cannot use a tool module through an import
--> $DIR/prelude-fail-2.rs:17:3
|
LL | #[imported_rustfmt::skip] //~ ERROR cannot use a tool module through an import
| ^^^^^^^^^^^^^^^^
|
note: the tool module imported here
--> $DIR/prelude-fail-2.rs:10:5
|
LL | use rustfmt as imported_rustfmt;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: cannot use a tool module through an import
--> $DIR/prelude-fail-2.rs:18:13
|
LL | #[tool_mod::imported_rustfmt::skip] //~ ERROR cannot use a tool module through an import
| ^^^^^^^^^^^^^^^^
|
note: the tool module imported here
--> $DIR/prelude-fail-2.rs:12:13
|
LL | pub use rustfmt as imported_rustfmt;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors

View File

@ -1,7 +1,5 @@
// edition:2018
#![feature(uniform_paths)]
// Built-in macro
use env as env_imported; //~ ERROR cannot import a built-in macro

View File

@ -1,11 +1,11 @@
error: cannot import a built-in macro
--> $DIR/prelude-fail.rs:6:5
--> $DIR/prelude-fail.rs:4:5
|
LL | use env as env_imported; //~ ERROR cannot import a built-in macro
| ^^^^^^^^^^^^^^^^^^^
error[E0432]: unresolved import `rustfmt`
--> $DIR/prelude-fail.rs:9:5
--> $DIR/prelude-fail.rs:7:5
|
LL | use rustfmt::skip as imported_rustfmt_skip; //~ ERROR unresolved import `rustfmt`
| ^^^^^^^ not a module `rustfmt`

View File

@ -1,17 +1,9 @@
// compile-pass
// edition:2018
#![feature(uniform_paths)]
// Macro imported with `#[macro_use] extern crate`
use vec as imported_vec;
// Built-in attribute
use inline as imported_inline;
// Tool module
use rustfmt as imported_rustfmt;
// Standard library prelude
use Vec as ImportedVec;
@ -20,8 +12,6 @@ use u8 as imported_u8;
type A = imported_u8;
#[imported_inline]
#[imported_rustfmt::skip]
fn main() {
imported_vec![0];
ImportedVec::<u8>::new();