Auto merge of #45846 - pietroalbini:use-nested-groups, r=petrochenkov
Add nested groups in imports This PR adds support for nested groups in imports (rust-lang/rfcs#2128, tracking issue #44494). r? @petrochenkov
This commit is contained in:
commit
804b15be82
30 changed files with 962 additions and 591 deletions
22
src/test/compile-fail/absolute-paths-in-nested-use-groups.rs
Normal file
22
src/test/compile-fail/absolute-paths-in-nested-use-groups.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2017 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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(use_nested_groups)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
mod foo {}
|
||||
|
||||
use foo::{
|
||||
::bar, //~ ERROR crate root in paths can only be used in start position
|
||||
super::bar, //~ ERROR `super` in paths can only be used in start position
|
||||
self::bar, //~ ERROR `self` in paths can only be used in start position
|
||||
};
|
||||
|
||||
fn main() {}
|
||||
31
src/test/compile-fail/feature-gate-use_nested_groups.rs
Normal file
31
src/test/compile-fail/feature-gate-use_nested_groups.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2017 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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![allow(unused_imports, dead_code)]
|
||||
|
||||
mod a {
|
||||
pub enum B {}
|
||||
pub enum C {}
|
||||
|
||||
pub mod d {
|
||||
pub enum E {}
|
||||
pub enum F {}
|
||||
|
||||
pub mod g {
|
||||
pub enum H {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use a::{B, d::{*, g::H}}; //~ ERROR glob imports in `use` groups are experimental
|
||||
//~^ ERROR nested groups in `use` are experimental
|
||||
//~^^ ERROR paths in `use` groups are experimental
|
||||
|
||||
fn main() {}
|
||||
35
src/test/run-pass/use-nested-groups.rs
Normal file
35
src/test/run-pass/use-nested-groups.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright 2017 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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(use_nested_groups)]
|
||||
|
||||
mod a {
|
||||
pub enum B {}
|
||||
|
||||
pub mod d {
|
||||
pub enum E {}
|
||||
pub enum F {}
|
||||
|
||||
pub mod g {
|
||||
pub enum H {}
|
||||
pub enum I {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use a::{B, d::{self, *, g::H}};
|
||||
|
||||
fn main() {
|
||||
let _: B;
|
||||
let _: E;
|
||||
let _: F;
|
||||
let _: H;
|
||||
let _: d::g::I;
|
||||
}
|
||||
22
src/test/ui/owl-import-generates-unused-import-lint.rs
Normal file
22
src/test/ui/owl-import-generates-unused-import-lint.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2017 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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(use_nested_groups)]
|
||||
#![deny(unused_imports)]
|
||||
|
||||
mod foo {
|
||||
pub enum Bar {}
|
||||
}
|
||||
|
||||
use foo::{*, *}; //~ ERROR unused import: `*`
|
||||
|
||||
fn main() {
|
||||
let _: Bar;
|
||||
}
|
||||
14
src/test/ui/owl-import-generates-unused-import-lint.stderr
Normal file
14
src/test/ui/owl-import-generates-unused-import-lint.stderr
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
error: unused import: `*`
|
||||
--> $DIR/owl-import-generates-unused-import-lint.rs:18:14
|
||||
|
|
||||
18 | use foo::{*, *}; //~ ERROR unused import: `*`
|
||||
| ^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/owl-import-generates-unused-import-lint.rs:12:9
|
||||
|
|
||||
12 | #![deny(unused_imports)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -14,6 +14,6 @@ mod x {
|
|||
}
|
||||
|
||||
// `.` is similar to `,` so list parsing should continue to closing `}`
|
||||
use x::{A. B}; //~ ERROR expected one of `,` or `as`, found `.`
|
||||
use x::{A. B}; //~ ERROR expected one of `,`, `::`, or `as`, found `.`
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
error: expected one of `,` or `as`, found `.`
|
||||
error: expected one of `,`, `::`, or `as`, found `.`
|
||||
--> $DIR/similar-tokens.rs:17:10
|
||||
|
|
||||
17 | use x::{A. B}; //~ ERROR expected one of `,` or `as`, found `.`
|
||||
| ^ expected one of `,` or `as` here
|
||||
17 | use x::{A. B}; //~ ERROR expected one of `,`, `::`, or `as`, found `.`
|
||||
| ^ expected one of `,`, `::`, or `as` here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue