diff options
| author | bors <bors@rust-lang.org> | 2018-01-07 00:51:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-01-07 00:51:42 +0000 |
| commit | a704583d43dda19c2542845d8efd61bd4e1d82f1 (patch) | |
| tree | 7f934100750e46fe9662f968413c5a99afd181a6 /src/test | |
| parent | 6828cf90146c7fefc4ba4f16dffe75f763f2d910 (diff) | |
| parent | ef2b131144bc0d3d7814c9967e47a8d4e834caa5 (diff) | |
Auto merge of #47156 - petrochenkov:extpath, r=nikomatsakis
Support `extern` in paths Implement the primary alternative to https://github.com/rust-lang/rust/pull/46613 + https://github.com/rust-lang/rust/pull/45771, achieving the same effect without requiring changes to other imports. Both need to be experimentally evaluated before making further progress. The PR also adds docs for all these related features into the unstable book. cc https://github.com/rust-lang/rust/issues/44660 r? @nikomatsakis
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/keyword-extern-as-identifier.rs (renamed from src/test/parse-fail/keyword-extern-as-identifier.rs) | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/rfc-2126-extern-in-paths/auxiliary/xcrate.rs | 15 | ||||
| -rw-r--r-- | src/test/compile-fail/rfc-2126-extern-in-paths/non-existent-1.rs | 15 | ||||
| -rw-r--r-- | src/test/compile-fail/rfc-2126-extern-in-paths/non-existent-2.rs | 15 | ||||
| -rw-r--r-- | src/test/compile-fail/rfc-2126-extern-in-paths/non-existent-3.rs | 15 | ||||
| -rw-r--r-- | src/test/compile-fail/rfc-2126-extern-in-paths/single-segment.rs | 23 | ||||
| -rw-r--r-- | src/test/run-pass/rfc-2126-extern-absolute-paths/extern.rs | 31 | ||||
| -rw-r--r-- | src/test/ui/feature-gate-extern_in_paths.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/feature-gate-extern_in_paths.stderr | 10 |
9 files changed, 141 insertions, 4 deletions
diff --git a/src/test/parse-fail/keyword-extern-as-identifier.rs b/src/test/compile-fail/keyword-extern-as-identifier.rs index 3bbe24ed56c..e5927d09b41 100644 --- a/src/test/parse-fail/keyword-extern-as-identifier.rs +++ b/src/test/compile-fail/keyword-extern-as-identifier.rs @@ -8,10 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: -Z parse-only - -// This file was auto-generated using 'src/etc/generate-keyword-tests.py extern' +#![feature(extern_in_paths)] fn main() { - let extern = "foo"; //~ error: expected pattern, found keyword `extern` + let extern = 0; //~ ERROR expected unit struct/variant or constant, found module `extern` } diff --git a/src/test/compile-fail/rfc-2126-extern-in-paths/auxiliary/xcrate.rs b/src/test/compile-fail/rfc-2126-extern-in-paths/auxiliary/xcrate.rs new file mode 100644 index 00000000000..c3da4a51872 --- /dev/null +++ b/src/test/compile-fail/rfc-2126-extern-in-paths/auxiliary/xcrate.rs @@ -0,0 +1,15 @@ +// 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. + +#[derive(Debug)] +pub struct S; + +#[derive(Debug)] +pub struct Z; diff --git a/src/test/compile-fail/rfc-2126-extern-in-paths/non-existent-1.rs b/src/test/compile-fail/rfc-2126-extern-in-paths/non-existent-1.rs new file mode 100644 index 00000000000..7eba02ed444 --- /dev/null +++ b/src/test/compile-fail/rfc-2126-extern-in-paths/non-existent-1.rs @@ -0,0 +1,15 @@ +// 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(extern_in_paths)] + +use extern::xcrate::S; //~ ERROR can't find crate for `xcrate` + +fn main() {} diff --git a/src/test/compile-fail/rfc-2126-extern-in-paths/non-existent-2.rs b/src/test/compile-fail/rfc-2126-extern-in-paths/non-existent-2.rs new file mode 100644 index 00000000000..4d09a05253e --- /dev/null +++ b/src/test/compile-fail/rfc-2126-extern-in-paths/non-existent-2.rs @@ -0,0 +1,15 @@ +// 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(extern_in_paths)] + +fn main() { + let s = extern::xcrate::S; //~ ERROR can't find crate for `xcrate` +} diff --git a/src/test/compile-fail/rfc-2126-extern-in-paths/non-existent-3.rs b/src/test/compile-fail/rfc-2126-extern-in-paths/non-existent-3.rs new file mode 100644 index 00000000000..402d294b2e3 --- /dev/null +++ b/src/test/compile-fail/rfc-2126-extern-in-paths/non-existent-3.rs @@ -0,0 +1,15 @@ +// 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(extern_in_paths)] + +use extern::ycrate; //~ ERROR can't find crate for `ycrate` + +fn main() {} diff --git a/src/test/compile-fail/rfc-2126-extern-in-paths/single-segment.rs b/src/test/compile-fail/rfc-2126-extern-in-paths/single-segment.rs new file mode 100644 index 00000000000..ebc42aa9d44 --- /dev/null +++ b/src/test/compile-fail/rfc-2126-extern-in-paths/single-segment.rs @@ -0,0 +1,23 @@ +// 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. + +// aux-build:xcrate.rs + +#![feature(extern_in_paths)] + +use extern; //~ ERROR unresolved import `extern` + //~^ NOTE no `extern` in the root +use extern::*; //~ ERROR unresolved import `extern::*` + //~^ NOTE cannot glob-import all possible crates + +fn main() { + let s = extern::xcrate; //~ ERROR expected value, found module `extern::xcrate` + //~^ NOTE not a value +} diff --git a/src/test/run-pass/rfc-2126-extern-absolute-paths/extern.rs b/src/test/run-pass/rfc-2126-extern-absolute-paths/extern.rs new file mode 100644 index 00000000000..52b52b23c87 --- /dev/null +++ b/src/test/run-pass/rfc-2126-extern-absolute-paths/extern.rs @@ -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. + +// aux-build:xcrate.rs + +#![feature(extern_in_paths)] + +use extern::xcrate::Z; + +fn f() { + use extern::xcrate; + use extern::xcrate as ycrate; + let s = xcrate::S; + assert_eq!(format!("{:?}", s), "S"); + let z = ycrate::Z; + assert_eq!(format!("{:?}", z), "Z"); +} + +fn main() { + let s = extern::xcrate::S; + assert_eq!(format!("{:?}", s), "S"); + let z = Z; + assert_eq!(format!("{:?}", z), "Z"); +} diff --git a/src/test/ui/feature-gate-extern_in_paths.rs b/src/test/ui/feature-gate-extern_in_paths.rs new file mode 100644 index 00000000000..3c01fcf6833 --- /dev/null +++ b/src/test/ui/feature-gate-extern_in_paths.rs @@ -0,0 +1,15 @@ +// 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. + +struct S; + +fn main() { + let _ = extern::std::vec::Vec::new(); //~ ERROR `extern` in paths is experimental +} diff --git a/src/test/ui/feature-gate-extern_in_paths.stderr b/src/test/ui/feature-gate-extern_in_paths.stderr new file mode 100644 index 00000000000..ac68e79e1ca --- /dev/null +++ b/src/test/ui/feature-gate-extern_in_paths.stderr @@ -0,0 +1,10 @@ +error: `extern` in paths is experimental (see issue #44660) + --> $DIR/feature-gate-extern_in_paths.rs:14:13 + | +14 | let _ = extern::std::vec::Vec::new(); //~ ERROR `extern` in paths is experimental + | ^^^^^^ + | + = help: add #![feature(extern_in_paths)] to the crate attributes to enable + +error: aborting due to previous error + |
