Implement RFC 2128 (use_nested_groups)

This commit adds support for nested groups inside `use` declarations,
such as `use foo::{bar, sub::{baz::Foo, *}};`.
This commit is contained in:
Pietro Albini 2017-09-26 23:04:00 +02:00
parent d6b010f98b
commit 91ba8b42fc
No known key found for this signature in database
GPG key ID: E8C1042DD1624519
29 changed files with 960 additions and 589 deletions

View 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() {}

View 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() {}

View 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;
}

View 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;
}

View 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

View file

@ -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() {}

View file

@ -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