From 4b9bc2e8f268dfe2a2462c4e378e5a0eeefa2cf4 Mon Sep 17 00:00:00 2001 From: Jakub Wieczorek Date: Fri, 18 Jul 2014 00:56:56 +0200 Subject: Implement new mod import sugar Implements RFC #168. --- src/test/compile-fail/use-mod-2.rs | 19 +++++++++++++++++++ src/test/compile-fail/use-mod-3.rs | 24 ++++++++++++++++++++++++ src/test/compile-fail/use-mod.rs | 32 ++++++++++++++++++++++++++++++++ src/test/run-pass/use-mod.rs | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 src/test/compile-fail/use-mod-2.rs create mode 100644 src/test/compile-fail/use-mod-3.rs create mode 100644 src/test/compile-fail/use-mod.rs create mode 100644 src/test/run-pass/use-mod.rs (limited to 'src/test') diff --git a/src/test/compile-fail/use-mod-2.rs b/src/test/compile-fail/use-mod-2.rs new file mode 100644 index 00000000000..12d4531078d --- /dev/null +++ b/src/test/compile-fail/use-mod-2.rs @@ -0,0 +1,19 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +mod foo { + use self::{mod}; + //~^ ERROR unresolved import `self`. There is no `self` in `???` + + use super::{mod}; + //~^ ERROR unresolved import `super`. There is no `super` in `???` +} + +fn main() {} diff --git a/src/test/compile-fail/use-mod-3.rs b/src/test/compile-fail/use-mod-3.rs new file mode 100644 index 00000000000..0263dc392f1 --- /dev/null +++ b/src/test/compile-fail/use-mod-3.rs @@ -0,0 +1,24 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use foo::bar::{ + mod //~ ERROR module `bar` is private +}; +use foo::bar::{ + Bar, //~ ERROR type `Bar` is inaccessible + //~^ NOTE module `bar` is private + mod //~ ERROR module `bar` is private +}; + +mod foo { + mod bar { pub type Bar = int; } +} + +fn main() {} diff --git a/src/test/compile-fail/use-mod.rs b/src/test/compile-fail/use-mod.rs new file mode 100644 index 00000000000..b2b0eb21ace --- /dev/null +++ b/src/test/compile-fail/use-mod.rs @@ -0,0 +1,32 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use foo::bar::{ + mod, +//~^ ERROR `mod` import can only appear once in the list + Bar, + mod +//~^ NOTE another `mod` import appears here +}; + +use {mod}; +//~^ ERROR `mod` import can only appear in an import list with a non-empty prefix + +use foo::mod; +//~^ ERROR `mod` imports are only allowed within a { } list + +mod foo { + pub mod bar { + pub struct Bar; + pub struct Baz; + } +} + +fn main() {} diff --git a/src/test/run-pass/use-mod.rs b/src/test/run-pass/use-mod.rs new file mode 100644 index 00000000000..34c9f581f07 --- /dev/null +++ b/src/test/run-pass/use-mod.rs @@ -0,0 +1,38 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub use foo::bar::{mod, First}; +use self::bar::Second; + +mod foo { + pub use self::bar::baz::{mod}; + + pub mod bar { + pub mod baz { + pub struct Fourth; + } + pub struct First; + pub struct Second; + } + + pub struct Third; +} + +mod baz { + use super::foo::{bar, mod}; + pub use foo::Third; +} + +fn main() { + let _ = First; + let _ = Second; + let _ = baz::Third; + let _ = foo::baz::Fourth; +} -- cgit 1.4.1-3-g733a5