diff options
Diffstat (limited to 'src/test/ui/editions')
45 files changed, 912 insertions, 0 deletions
diff --git a/src/test/ui/editions/async-block-2015.rs b/src/test/ui/editions/async-block-2015.rs new file mode 100644 index 000000000..3daf4930c --- /dev/null +++ b/src/test/ui/editions/async-block-2015.rs @@ -0,0 +1,30 @@ +async fn foo() { +//~^ ERROR `async fn` is not permitted in Rust 2015 +//~| NOTE to use `async fn`, switch to Rust 2018 or later +//~| HELP pass `--edition 2021` to `rustc` +//~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide + + let x = async {}; + //~^ ERROR cannot find struct, variant or union type `async` in this scope + //~| NOTE `async` blocks are only allowed in Rust 2018 or later + let y = async { //~ NOTE `async` blocks are only allowed in Rust 2018 or later + let x = 42; + //~^ ERROR expected identifier, found keyword `let` + //~| NOTE expected identifier, found keyword + //~| HELP pass `--edition 2021` to `rustc` + //~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide + 42 + }; + let z = async { //~ NOTE `async` blocks are only allowed in Rust 2018 or later + 42 + //~^ ERROR expected identifier, found `42` + //~| NOTE expected identifier + //~| HELP pass `--edition 2021` to `rustc` + //~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide + }; + y.await; + z.await; + x +} + +fn main() {} diff --git a/src/test/ui/editions/async-block-2015.stderr b/src/test/ui/editions/async-block-2015.stderr new file mode 100644 index 000000000..b792b8c1e --- /dev/null +++ b/src/test/ui/editions/async-block-2015.stderr @@ -0,0 +1,41 @@ +error[E0670]: `async fn` is not permitted in Rust 2015 + --> $DIR/async-block-2015.rs:1:1 + | +LL | async fn foo() { + | ^^^^^ to use `async fn`, switch to Rust 2018 or later + | + = help: pass `--edition 2021` to `rustc` + = note: for more on editions, read https://doc.rust-lang.org/edition-guide + +error: expected identifier, found keyword `let` + --> $DIR/async-block-2015.rs:11:9 + | +LL | let y = async { + | ----- `async` blocks are only allowed in Rust 2018 or later +LL | let x = 42; + | ^^^ expected identifier, found keyword + | + = help: pass `--edition 2021` to `rustc` + = note: for more on editions, read https://doc.rust-lang.org/edition-guide + +error: expected identifier, found `42` + --> $DIR/async-block-2015.rs:19:9 + | +LL | let z = async { + | ----- `async` blocks are only allowed in Rust 2018 or later +LL | 42 + | ^^ expected identifier + | + = help: pass `--edition 2021` to `rustc` + = note: for more on editions, read https://doc.rust-lang.org/edition-guide + +error[E0422]: cannot find struct, variant or union type `async` in this scope + --> $DIR/async-block-2015.rs:7:13 + | +LL | let x = async {}; + | ^^^^^ `async` blocks are only allowed in Rust 2018 or later + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0422, E0670. +For more information about an error, try `rustc --explain E0422`. diff --git a/src/test/ui/editions/auxiliary/absolute.rs b/src/test/ui/editions/auxiliary/absolute.rs new file mode 100644 index 000000000..d596f9735 --- /dev/null +++ b/src/test/ui/editions/auxiliary/absolute.rs @@ -0,0 +1 @@ +pub struct Path; diff --git a/src/test/ui/editions/auxiliary/edition-extern-crate-allowed.rs b/src/test/ui/editions/auxiliary/edition-extern-crate-allowed.rs new file mode 100644 index 000000000..d11c69f81 --- /dev/null +++ b/src/test/ui/editions/auxiliary/edition-extern-crate-allowed.rs @@ -0,0 +1 @@ +// intentionally empty diff --git a/src/test/ui/editions/auxiliary/edition-imports-2015.rs b/src/test/ui/editions/auxiliary/edition-imports-2015.rs new file mode 100644 index 000000000..c72331ca2 --- /dev/null +++ b/src/test/ui/editions/auxiliary/edition-imports-2015.rs @@ -0,0 +1,31 @@ +// edition:2015 + +#[macro_export] +macro_rules! gen_imports { () => { + use import::Path; + use std::collections::LinkedList; + + fn check_absolute() { + ::absolute::Path; + ::std::collections::LinkedList::<u8>::new(); + } +}} + +#[macro_export] +macro_rules! gen_glob { () => { + use *; +}} + +#[macro_export] +macro_rules! gen_gated { () => { + fn check_gated() { + enum E { A } + use E::*; + } +}} + +#[macro_export] +macro_rules! gen_ambiguous { () => { + use Ambiguous; + type A = ::edition_imports_2015::Path; +}} diff --git a/src/test/ui/editions/auxiliary/edition-imports-2018.rs b/src/test/ui/editions/auxiliary/edition-imports-2018.rs new file mode 100644 index 000000000..b08dc499a --- /dev/null +++ b/src/test/ui/editions/auxiliary/edition-imports-2018.rs @@ -0,0 +1,17 @@ +// edition:2018 + +#[macro_export] +macro_rules! gen_imports { () => { + use import::Path; + use std::collections::LinkedList; + + fn check_absolute() { + ::absolute::Path; + ::std::collections::LinkedList::<u8>::new(); + } +}} + +#[macro_export] +macro_rules! gen_glob { () => { + use *; +}} diff --git a/src/test/ui/editions/auxiliary/edition-kw-macro-2015.rs b/src/test/ui/editions/auxiliary/edition-kw-macro-2015.rs new file mode 100644 index 000000000..7cfd128f2 --- /dev/null +++ b/src/test/ui/editions/auxiliary/edition-kw-macro-2015.rs @@ -0,0 +1,28 @@ +// edition:2015 + +#![allow(keyword_idents)] + +#[macro_export] +macro_rules! produces_async { + () => (pub fn async() {}) +} + +#[macro_export] +macro_rules! produces_async_raw { + () => (pub fn r#async() {}) +} + +#[macro_export] +macro_rules! consumes_async { + (async) => (1) +} + +#[macro_export] +macro_rules! consumes_async_raw { + (r#async) => (1) +} + +#[macro_export] +macro_rules! passes_ident { + ($i: ident) => ($i) +} diff --git a/src/test/ui/editions/auxiliary/edition-kw-macro-2018.rs b/src/test/ui/editions/auxiliary/edition-kw-macro-2018.rs new file mode 100644 index 000000000..d07c0218d --- /dev/null +++ b/src/test/ui/editions/auxiliary/edition-kw-macro-2018.rs @@ -0,0 +1,28 @@ +// edition:2018 + +#![allow(keyword_idents)] + +#[macro_export] +macro_rules! produces_async { + () => (pub fn async() {}) +} + +#[macro_export] +macro_rules! produces_async_raw { + () => (pub fn r#async() {}) +} + +#[macro_export] +macro_rules! consumes_async { + (async) => (1) +} + +#[macro_export] +macro_rules! consumes_async_raw { + (r#async) => (1) +} + +#[macro_export] +macro_rules! passes_ident { + ($i: ident) => ($i) +} diff --git a/src/test/ui/editions/dyn-trait-sugg-2021.rs b/src/test/ui/editions/dyn-trait-sugg-2021.rs new file mode 100644 index 000000000..de0444b63 --- /dev/null +++ b/src/test/ui/editions/dyn-trait-sugg-2021.rs @@ -0,0 +1,12 @@ +// edition:2021 + +trait Foo<T> {} + +impl<T> dyn Foo<T> { + fn hi(_x: T) {} +} + +fn main() { + Foo::hi(123); + //~^ ERROR trait objects must include the `dyn` keyword +} diff --git a/src/test/ui/editions/dyn-trait-sugg-2021.stderr b/src/test/ui/editions/dyn-trait-sugg-2021.stderr new file mode 100644 index 000000000..8c68dec1d --- /dev/null +++ b/src/test/ui/editions/dyn-trait-sugg-2021.stderr @@ -0,0 +1,14 @@ +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/dyn-trait-sugg-2021.rs:10:5 + | +LL | Foo::hi(123); + | ^^^ + | +help: add `dyn` keyword before this trait + | +LL | <dyn Foo>::hi(123); + | ++++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0782`. diff --git a/src/test/ui/editions/edition-extern-crate-allowed.rs b/src/test/ui/editions/edition-extern-crate-allowed.rs new file mode 100644 index 000000000..8d142cea5 --- /dev/null +++ b/src/test/ui/editions/edition-extern-crate-allowed.rs @@ -0,0 +1,10 @@ +// aux-build:edition-extern-crate-allowed.rs +// edition:2015 +// check-pass + +#![warn(rust_2018_idioms)] + +extern crate edition_extern_crate_allowed; +//~^ WARNING unused extern crate + +fn main() {} diff --git a/src/test/ui/editions/edition-extern-crate-allowed.stderr b/src/test/ui/editions/edition-extern-crate-allowed.stderr new file mode 100644 index 000000000..dde774c52 --- /dev/null +++ b/src/test/ui/editions/edition-extern-crate-allowed.stderr @@ -0,0 +1,15 @@ +warning: unused extern crate + --> $DIR/edition-extern-crate-allowed.rs:7:1 + | +LL | extern crate edition_extern_crate_allowed; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it + | +note: the lint level is defined here + --> $DIR/edition-extern-crate-allowed.rs:5:9 + | +LL | #![warn(rust_2018_idioms)] + | ^^^^^^^^^^^^^^^^ + = note: `#[warn(unused_extern_crates)]` implied by `#[warn(rust_2018_idioms)]` + +warning: 1 warning emitted + diff --git a/src/test/ui/editions/edition-feature-ok.rs b/src/test/ui/editions/edition-feature-ok.rs new file mode 100644 index 000000000..69242fd71 --- /dev/null +++ b/src/test/ui/editions/edition-feature-ok.rs @@ -0,0 +1,5 @@ +// check-pass + +#![feature(rust_2018_preview)] + +fn main() {} diff --git a/src/test/ui/editions/edition-feature-redundant.rs b/src/test/ui/editions/edition-feature-redundant.rs new file mode 100644 index 000000000..1049a2da8 --- /dev/null +++ b/src/test/ui/editions/edition-feature-redundant.rs @@ -0,0 +1,7 @@ +// edition:2018 +// check-pass + +#![feature(rust_2018_preview)] +//~^ WARN the feature `rust_2018_preview` is included in the Rust 2018 edition + +fn main() {} diff --git a/src/test/ui/editions/edition-feature-redundant.stderr b/src/test/ui/editions/edition-feature-redundant.stderr new file mode 100644 index 000000000..b11e616d7 --- /dev/null +++ b/src/test/ui/editions/edition-feature-redundant.stderr @@ -0,0 +1,9 @@ +warning[E0705]: the feature `rust_2018_preview` is included in the Rust 2018 edition + --> $DIR/edition-feature-redundant.rs:4:12 + | +LL | #![feature(rust_2018_preview)] + | ^^^^^^^^^^^^^^^^^ + +warning: 1 warning emitted + +For more information about this error, try `rustc --explain E0705`. diff --git a/src/test/ui/editions/edition-imports-2015.rs b/src/test/ui/editions/edition-imports-2015.rs new file mode 100644 index 000000000..5ba45b19d --- /dev/null +++ b/src/test/ui/editions/edition-imports-2015.rs @@ -0,0 +1,26 @@ +// edition:2015 +// compile-flags:--extern absolute +// aux-build:edition-imports-2018.rs +// aux-build:absolute.rs + +#[macro_use] +extern crate edition_imports_2018; + +mod check { + mod import { + pub struct Path; + } + + gen_imports!(); // OK + + fn check() { + Path; + LinkedList::<u8>::new(); + } +} + +mod check_glob { + gen_glob!(); //~ ERROR cannot glob-import all possible crates +} + +fn main() {} diff --git a/src/test/ui/editions/edition-imports-2015.stderr b/src/test/ui/editions/edition-imports-2015.stderr new file mode 100644 index 000000000..3f38e6f8e --- /dev/null +++ b/src/test/ui/editions/edition-imports-2015.stderr @@ -0,0 +1,10 @@ +error: cannot glob-import all possible crates + --> $DIR/edition-imports-2015.rs:23:5 + | +LL | gen_glob!(); + | ^^^^^^^^^^^ + | + = note: this error originates in the macro `gen_glob` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + diff --git a/src/test/ui/editions/edition-imports-2018.rs b/src/test/ui/editions/edition-imports-2018.rs new file mode 100644 index 000000000..dcdbf0d05 --- /dev/null +++ b/src/test/ui/editions/edition-imports-2018.rs @@ -0,0 +1,27 @@ +// edition:2018 +// aux-build:edition-imports-2015.rs + +#[macro_use] +extern crate edition_imports_2015; + +mod import { + pub struct Path; +} +mod absolute { + pub struct Path; +} + +mod check { + gen_imports!(); // OK + + fn check() { + Path; + LinkedList::<u8>::new(); + } +} + +mod check_glob { + gen_glob!(); //~ ERROR cannot glob-import all possible crates +} + +fn main() {} diff --git a/src/test/ui/editions/edition-imports-2018.stderr b/src/test/ui/editions/edition-imports-2018.stderr new file mode 100644 index 000000000..e7f760e49 --- /dev/null +++ b/src/test/ui/editions/edition-imports-2018.stderr @@ -0,0 +1,10 @@ +error: cannot glob-import all possible crates + --> $DIR/edition-imports-2018.rs:24:5 + | +LL | gen_glob!(); + | ^^^^^^^^^^^ + | + = note: this error originates in the macro `gen_glob` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + diff --git a/src/test/ui/editions/edition-imports-virtual-2015-ambiguity.rs b/src/test/ui/editions/edition-imports-virtual-2015-ambiguity.rs new file mode 100644 index 000000000..3fffb30c6 --- /dev/null +++ b/src/test/ui/editions/edition-imports-virtual-2015-ambiguity.rs @@ -0,0 +1,20 @@ +// check-pass +// edition:2018 +// compile-flags:--extern edition_imports_2015 +// aux-build:edition-imports-2015.rs + +mod edition_imports_2015 { + pub struct Path; +} + +pub struct Ambiguous {} + +mod check { + pub struct Ambiguous {} + + fn check() { + edition_imports_2015::gen_ambiguous!(); // OK + } +} + +fn main() {} diff --git a/src/test/ui/editions/edition-imports-virtual-2015-gated.rs b/src/test/ui/editions/edition-imports-virtual-2015-gated.rs new file mode 100644 index 000000000..634d3e9a4 --- /dev/null +++ b/src/test/ui/editions/edition-imports-virtual-2015-gated.rs @@ -0,0 +1,11 @@ +// edition:2018 +// aux-build:edition-imports-2015.rs + +#[macro_use] +extern crate edition_imports_2015; + +mod check { + gen_gated!(); //~ ERROR unresolved import `E` +} + +fn main() {} diff --git a/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr b/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr new file mode 100644 index 000000000..e4bdd2821 --- /dev/null +++ b/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr @@ -0,0 +1,11 @@ +error[E0432]: unresolved import `E` + --> $DIR/edition-imports-virtual-2015-gated.rs:8:5 + | +LL | gen_gated!(); + | ^^^^^^^^^^^^ could not find `E` in the list of imported crates + | + = note: this error originates in the macro `gen_gated` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/editions/edition-keywords-2015-2015-expansion.rs b/src/test/ui/editions/edition-keywords-2015-2015-expansion.rs new file mode 100644 index 000000000..b2695bea5 --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2015-2015-expansion.rs @@ -0,0 +1,17 @@ +// edition:2015 +// aux-build:edition-kw-macro-2015.rs +// check-pass + +#![allow(keyword_idents)] + +#[macro_use] +extern crate edition_kw_macro_2015; + +mod one_async { + produces_async! {} // OK +} +mod two_async { + produces_async_raw! {} // OK +} + +fn main() {} diff --git a/src/test/ui/editions/edition-keywords-2015-2015-parsing.rs b/src/test/ui/editions/edition-keywords-2015-2015-parsing.rs new file mode 100644 index 000000000..d1752a7ec --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2015-2015-parsing.rs @@ -0,0 +1,26 @@ +// edition:2015 +// aux-build:edition-kw-macro-2015.rs + +#[macro_use] +extern crate edition_kw_macro_2015; + +mod module { + pub fn async() {} +} + +pub fn check_async() { + let mut async = 1; // OK + let mut r#async = 1; // OK + + r#async = consumes_async!(async); // OK + r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async` + r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` + r#async = consumes_async_raw!(r#async); // OK + + if passes_ident!(async) == 1 {} // OK + if passes_ident!(r#async) == 1 {} // OK + module::async(); // OK + module::r#async(); // OK +} + +fn main() {} diff --git a/src/test/ui/editions/edition-keywords-2015-2015-parsing.stderr b/src/test/ui/editions/edition-keywords-2015-2015-parsing.stderr new file mode 100644 index 000000000..3435fdfd7 --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2015-2015-parsing.stderr @@ -0,0 +1,14 @@ +error: no rules expected the token `r#async` + --> $DIR/edition-keywords-2015-2015-parsing.rs:16:31 + | +LL | r#async = consumes_async!(r#async); + | ^^^^^^^ no rules expected this token in macro call + +error: no rules expected the token `async` + --> $DIR/edition-keywords-2015-2015-parsing.rs:17:35 + | +LL | r#async = consumes_async_raw!(async); + | ^^^^^ no rules expected this token in macro call + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/editions/edition-keywords-2015-2015.rs b/src/test/ui/editions/edition-keywords-2015-2015.rs new file mode 100644 index 000000000..943d203b8 --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2015-2015.rs @@ -0,0 +1,36 @@ +// run-pass + +#![allow(unused_mut)] +#![allow(unused_assignments)] +#![allow(unused_variables)] +// edition:2015 +// aux-build:edition-kw-macro-2015.rs + +#[macro_use] +extern crate edition_kw_macro_2015; + +pub fn check_async() { + let mut async = 1; // OK + let mut r#async = 1; // OK + + r#async = consumes_async!(async); // OK + // r#async = consumes_async!(r#async); // ERROR, not a match + // r#async = consumes_async_raw!(async); // ERROR, not a match + r#async = consumes_async_raw!(r#async); // OK + + if passes_ident!(async) == 1 {} // OK + if passes_ident!(r#async) == 1 {} // OK + one_async::async(); // OK + one_async::r#async(); // OK + two_async::async(); // OK + two_async::r#async(); // OK +} + +mod one_async { + produces_async! {} // OK +} +mod two_async { + produces_async_raw! {} // OK +} + +fn main() {} diff --git a/src/test/ui/editions/edition-keywords-2015-2018-expansion.rs b/src/test/ui/editions/edition-keywords-2015-2018-expansion.rs new file mode 100644 index 000000000..9f34a3887 --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2015-2018-expansion.rs @@ -0,0 +1,14 @@ +// edition:2015 +// aux-build:edition-kw-macro-2018.rs + +#[macro_use] +extern crate edition_kw_macro_2018; + +mod one_async { + produces_async! {} //~ ERROR expected identifier, found keyword +} +mod two_async { + produces_async_raw! {} // OK +} + +fn main() {} diff --git a/src/test/ui/editions/edition-keywords-2015-2018-expansion.stderr b/src/test/ui/editions/edition-keywords-2015-2018-expansion.stderr new file mode 100644 index 000000000..570bbac2b --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2015-2018-expansion.stderr @@ -0,0 +1,15 @@ +error: expected identifier, found keyword `async` + --> $DIR/edition-keywords-2015-2018-expansion.rs:8:5 + | +LL | produces_async! {} + | ^^^^^^^^^^^^^^^^^^ expected identifier, found keyword + | + = note: this error originates in the macro `produces_async` (in Nightly builds, run with -Z macro-backtrace for more info) +help: escape `async` to use it as an identifier + --> $DIR/auxiliary/edition-kw-macro-2018.rs:7:19 + | +LL | () => (pub fn r#async() {}) + | ++ + +error: aborting due to previous error + diff --git a/src/test/ui/editions/edition-keywords-2015-2018-parsing.rs b/src/test/ui/editions/edition-keywords-2015-2018-parsing.rs new file mode 100644 index 000000000..44455f438 --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2015-2018-parsing.rs @@ -0,0 +1,26 @@ +// edition:2015 +// aux-build:edition-kw-macro-2018.rs + +#[macro_use] +extern crate edition_kw_macro_2018; + +mod module { + pub fn async() {} +} + +pub fn check_async() { + let mut async = 1; // OK + let mut r#async = 1; // OK + + r#async = consumes_async!(async); // OK + r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async` + r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` + r#async = consumes_async_raw!(r#async); // OK + + if passes_ident!(async) == 1 {} // OK + if passes_ident!(r#async) == 1 {} // OK + module::async(); // OK + module::r#async(); // OK +} + +fn main() {} diff --git a/src/test/ui/editions/edition-keywords-2015-2018-parsing.stderr b/src/test/ui/editions/edition-keywords-2015-2018-parsing.stderr new file mode 100644 index 000000000..6e86d746f --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2015-2018-parsing.stderr @@ -0,0 +1,14 @@ +error: no rules expected the token `r#async` + --> $DIR/edition-keywords-2015-2018-parsing.rs:16:31 + | +LL | r#async = consumes_async!(r#async); + | ^^^^^^^ no rules expected this token in macro call + +error: no rules expected the token `async` + --> $DIR/edition-keywords-2015-2018-parsing.rs:17:35 + | +LL | r#async = consumes_async_raw!(async); + | ^^^^^ no rules expected this token in macro call + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/editions/edition-keywords-2015-2018.rs b/src/test/ui/editions/edition-keywords-2015-2018.rs new file mode 100644 index 000000000..8c3397c95 --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2015-2018.rs @@ -0,0 +1,36 @@ +// run-pass + +#![allow(unused_mut)] +#![allow(unused_assignments)] +#![allow(unused_variables)] +// edition:2015 +// aux-build:edition-kw-macro-2018.rs + +#[macro_use] +extern crate edition_kw_macro_2018; + +pub fn check_async() { + let mut async = 1; // OK + let mut r#async = 1; // OK + + r#async = consumes_async!(async); // OK + // r#async = consumes_async!(r#async); // ERROR, not a match + // r#async = consumes_async_raw!(async); // ERROR, not a match + r#async = consumes_async_raw!(r#async); // OK + + if passes_ident!(async) == 1 {} // OK + if passes_ident!(r#async) == 1 {} // OK + // one_async::async(); // ERROR, unresolved name + // one_async::r#async(); // ERROR, unresolved name + two_async::async(); // OK + two_async::r#async(); // OK +} + +mod one_async { + // produces_async! {} // ERROR, reserved +} +mod two_async { + produces_async_raw! {} // OK +} + +fn main() {} diff --git a/src/test/ui/editions/edition-keywords-2018-2015-expansion.rs b/src/test/ui/editions/edition-keywords-2018-2015-expansion.rs new file mode 100644 index 000000000..707d8e95c --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2018-2015-expansion.rs @@ -0,0 +1,17 @@ +// edition:2018 +// aux-build:edition-kw-macro-2015.rs +// check-pass + +#![allow(keyword_idents)] + +#[macro_use] +extern crate edition_kw_macro_2015; + +mod one_async { + produces_async! {} // OK +} +mod two_async { + produces_async_raw! {} // OK +} + +fn main() {} diff --git a/src/test/ui/editions/edition-keywords-2018-2015-parsing.rs b/src/test/ui/editions/edition-keywords-2018-2015-parsing.rs new file mode 100644 index 000000000..d5ed9fb9a --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2018-2015-parsing.rs @@ -0,0 +1,30 @@ +// edition:2018 +// aux-build:edition-kw-macro-2015.rs + +#![feature(async_closure)] + +fn main() {} + +#[macro_use] +extern crate edition_kw_macro_2015; + +mod module { + pub fn r#async() {} +} + +pub fn check_async() { + let mut async = 1; //~ ERROR expected identifier, found keyword `async` + let mut r#async = 1; // OK + + r#async = consumes_async!(async); // OK + r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async` + r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` + r#async = consumes_async_raw!(r#async); // OK + + if passes_ident!(async) == 1 {} + if passes_ident!(r#async) == 1 {} // OK + module::async(); //~ ERROR expected identifier, found keyword `async` + module::r#async(); // OK + + let _recovery_witness: () = 0; //~ ERROR mismatched types +} diff --git a/src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr b/src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr new file mode 100644 index 000000000..e1eea725b --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr @@ -0,0 +1,56 @@ +error: expected identifier, found keyword `async` + --> $DIR/edition-keywords-2018-2015-parsing.rs:16:13 + | +LL | let mut async = 1; + | ^^^^^ expected identifier, found keyword + | +help: escape `async` to use it as an identifier + | +LL | let mut r#async = 1; + | ++ + +error: expected identifier, found keyword `async` + --> $DIR/edition-keywords-2018-2015-parsing.rs:26:13 + | +LL | module::async(); + | ^^^^^ expected identifier, found keyword + | +help: escape `async` to use it as an identifier + | +LL | module::r#async(); + | ++ + +error: no rules expected the token `r#async` + --> $DIR/edition-keywords-2018-2015-parsing.rs:20:31 + | +LL | r#async = consumes_async!(r#async); + | ^^^^^^^ no rules expected this token in macro call + +error: no rules expected the token `async` + --> $DIR/edition-keywords-2018-2015-parsing.rs:21:35 + | +LL | r#async = consumes_async_raw!(async); + | ^^^^^ no rules expected this token in macro call + +error: macro expansion ends with an incomplete expression: expected one of `move`, `|`, or `||` + --> $DIR/auxiliary/edition-kw-macro-2015.rs:27:23 + | +LL | ($i: ident) => ($i) + | ^ expected one of `move`, `|`, or `||` + | + ::: $DIR/edition-keywords-2018-2015-parsing.rs:24:8 + | +LL | if passes_ident!(async) == 1 {} + | -------------------- in this macro invocation + +error[E0308]: mismatched types + --> $DIR/edition-keywords-2018-2015-parsing.rs:29:33 + | +LL | let _recovery_witness: () = 0; + | -- ^ expected `()`, found integer + | | + | expected due to this + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/editions/edition-keywords-2018-2015.rs b/src/test/ui/editions/edition-keywords-2018-2015.rs new file mode 100644 index 000000000..2cb2dfb18 --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2018-2015.rs @@ -0,0 +1,34 @@ +// run-pass + +#![allow(unused_assignments)] +// edition:2018 +// aux-build:edition-kw-macro-2015.rs + +#[macro_use] +extern crate edition_kw_macro_2015; + +pub fn check_async() { + // let mut async = 1; // ERROR, reserved + let mut r#async = 1; // OK + + r#async = consumes_async!(async); // OK + // r#async = consumes_async!(r#async); // ERROR, not a match + // r#async = consumes_async_raw!(async); // ERROR, not a match + r#async = consumes_async_raw!(r#async); // OK + + // if passes_ident!(async) == 1 {} // ERROR, reserved + if passes_ident!(r#async) == 1 {} // OK + // one_async::async(); // ERROR, reserved + one_async::r#async(); // OK + // two_async::async(); // ERROR, reserved + two_async::r#async(); // OK +} + +mod one_async { + produces_async! {} // OK +} +mod two_async { + produces_async_raw! {} // OK +} + +fn main() {} diff --git a/src/test/ui/editions/edition-keywords-2018-2018-expansion.rs b/src/test/ui/editions/edition-keywords-2018-2018-expansion.rs new file mode 100644 index 000000000..a8e69fed6 --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2018-2018-expansion.rs @@ -0,0 +1,14 @@ +// edition:2018 +// aux-build:edition-kw-macro-2018.rs + +#[macro_use] +extern crate edition_kw_macro_2018; + +mod one_async { + produces_async! {} //~ ERROR expected identifier, found keyword `async` +} +mod two_async { + produces_async_raw! {} // OK +} + +fn main() {} diff --git a/src/test/ui/editions/edition-keywords-2018-2018-expansion.stderr b/src/test/ui/editions/edition-keywords-2018-2018-expansion.stderr new file mode 100644 index 000000000..69f275746 --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2018-2018-expansion.stderr @@ -0,0 +1,15 @@ +error: expected identifier, found keyword `async` + --> $DIR/edition-keywords-2018-2018-expansion.rs:8:5 + | +LL | produces_async! {} + | ^^^^^^^^^^^^^^^^^^ expected identifier, found keyword + | + = note: this error originates in the macro `produces_async` (in Nightly builds, run with -Z macro-backtrace for more info) +help: escape `async` to use it as an identifier + --> $DIR/auxiliary/edition-kw-macro-2018.rs:7:19 + | +LL | () => (pub fn r#async() {}) + | ++ + +error: aborting due to previous error + diff --git a/src/test/ui/editions/edition-keywords-2018-2018-parsing.rs b/src/test/ui/editions/edition-keywords-2018-2018-parsing.rs new file mode 100644 index 000000000..044ab249f --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2018-2018-parsing.rs @@ -0,0 +1,30 @@ +// edition:2018 +// aux-build:edition-kw-macro-2018.rs + +#![feature(async_closure)] + +fn main() {} + +#[macro_use] +extern crate edition_kw_macro_2018; + +mod module { + pub fn r#async() {} +} + +pub fn check_async() { + let mut async = 1; //~ ERROR expected identifier, found keyword `async` + let mut r#async = 1; // OK + + r#async = consumes_async!(async); // OK + r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async` + r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` + r#async = consumes_async_raw!(r#async); // OK + + if passes_ident!(async) == 1 {} + if passes_ident!(r#async) == 1 {} // OK + module::async(); //~ ERROR expected identifier, found keyword `async` + module::r#async(); // OK + + let _recovery_witness: () = 0; //~ ERROR mismatched types +} diff --git a/src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr b/src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr new file mode 100644 index 000000000..0af4da09c --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr @@ -0,0 +1,56 @@ +error: expected identifier, found keyword `async` + --> $DIR/edition-keywords-2018-2018-parsing.rs:16:13 + | +LL | let mut async = 1; + | ^^^^^ expected identifier, found keyword + | +help: escape `async` to use it as an identifier + | +LL | let mut r#async = 1; + | ++ + +error: expected identifier, found keyword `async` + --> $DIR/edition-keywords-2018-2018-parsing.rs:26:13 + | +LL | module::async(); + | ^^^^^ expected identifier, found keyword + | +help: escape `async` to use it as an identifier + | +LL | module::r#async(); + | ++ + +error: no rules expected the token `r#async` + --> $DIR/edition-keywords-2018-2018-parsing.rs:20:31 + | +LL | r#async = consumes_async!(r#async); + | ^^^^^^^ no rules expected this token in macro call + +error: no rules expected the token `async` + --> $DIR/edition-keywords-2018-2018-parsing.rs:21:35 + | +LL | r#async = consumes_async_raw!(async); + | ^^^^^ no rules expected this token in macro call + +error: macro expansion ends with an incomplete expression: expected one of `move`, `|`, or `||` + --> $DIR/auxiliary/edition-kw-macro-2018.rs:27:23 + | +LL | ($i: ident) => ($i) + | ^ expected one of `move`, `|`, or `||` + | + ::: $DIR/edition-keywords-2018-2018-parsing.rs:24:8 + | +LL | if passes_ident!(async) == 1 {} + | -------------------- in this macro invocation + +error[E0308]: mismatched types + --> $DIR/edition-keywords-2018-2018-parsing.rs:29:33 + | +LL | let _recovery_witness: () = 0; + | -- ^ expected `()`, found integer + | | + | expected due to this + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/editions/edition-keywords-2018-2018.rs b/src/test/ui/editions/edition-keywords-2018-2018.rs new file mode 100644 index 000000000..5043440aa --- /dev/null +++ b/src/test/ui/editions/edition-keywords-2018-2018.rs @@ -0,0 +1,34 @@ +// run-pass + +#![allow(unused_assignments)] +// edition:2018 +// aux-build:edition-kw-macro-2018.rs + +#[macro_use] +extern crate edition_kw_macro_2018; + +pub fn check_async() { + // let mut async = 1; // ERROR, reserved + let mut r#async = 1; // OK + + r#async = consumes_async!(async); // OK + // r#async = consumes_async!(r#async); // ERROR, not a match + // r#async = consumes_async_raw!(async); // ERROR, not a match + r#async = consumes_async_raw!(r#async); // OK + + // if passes_ident!(async) == 1 {} // ERROR, reserved + if passes_ident!(r#async) == 1 {} // OK + // one_async::async(); // ERROR, reserved + // one_async::r#async(); // ERROR, unresolved name + // two_async::async(); // ERROR, reserved + two_async::r#async(); // OK +} + +mod one_async { + // produces_async! {} // ERROR, reserved +} +mod two_async { + produces_async_raw! {} // OK +} + +fn main() {} diff --git a/src/test/ui/editions/edition-raw-pointer-method-2015.rs b/src/test/ui/editions/edition-raw-pointer-method-2015.rs new file mode 100644 index 000000000..fcfe493c1 --- /dev/null +++ b/src/test/ui/editions/edition-raw-pointer-method-2015.rs @@ -0,0 +1,12 @@ +// edition:2015 + +// tests that editions work with the tyvar warning-turned-error + +#[deny(warnings)] +fn main() { + let x = 0; + let y = &x as *const _; + let _ = y.is_null(); + //~^ error: type annotations needed [tyvar_behind_raw_pointer] + //~^^ warning: this is accepted in the current edition +} diff --git a/src/test/ui/editions/edition-raw-pointer-method-2015.stderr b/src/test/ui/editions/edition-raw-pointer-method-2015.stderr new file mode 100644 index 000000000..417daf36f --- /dev/null +++ b/src/test/ui/editions/edition-raw-pointer-method-2015.stderr @@ -0,0 +1,17 @@ +error: type annotations needed + --> $DIR/edition-raw-pointer-method-2015.rs:9:15 + | +LL | let _ = y.is_null(); + | ^^^^^^^ + | +note: the lint level is defined here + --> $DIR/edition-raw-pointer-method-2015.rs:5:8 + | +LL | #[deny(warnings)] + | ^^^^^^^^ + = note: `#[deny(tyvar_behind_raw_pointer)]` implied by `#[deny(warnings)]` + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #46906 <https://github.com/rust-lang/rust/issues/46906> + +error: aborting due to previous error + diff --git a/src/test/ui/editions/edition-raw-pointer-method-2018.rs b/src/test/ui/editions/edition-raw-pointer-method-2018.rs new file mode 100644 index 000000000..af0b2d6bd --- /dev/null +++ b/src/test/ui/editions/edition-raw-pointer-method-2018.rs @@ -0,0 +1,11 @@ +// edition:2018 + +// tests that editions work with the tyvar warning-turned-error + +#[deny(warnings)] +fn main() { + let x = 0; + let y = &x as *const _; + let _ = y.is_null(); + //~^ error: the type of this value must be known to call a method on a raw pointer on it [E0699] +} diff --git a/src/test/ui/editions/edition-raw-pointer-method-2018.stderr b/src/test/ui/editions/edition-raw-pointer-method-2018.stderr new file mode 100644 index 000000000..23452495b --- /dev/null +++ b/src/test/ui/editions/edition-raw-pointer-method-2018.stderr @@ -0,0 +1,9 @@ +error[E0699]: the type of this value must be known to call a method on a raw pointer on it + --> $DIR/edition-raw-pointer-method-2018.rs:9:15 + | +LL | let _ = y.is_null(); + | ^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0699`. diff --git a/src/test/ui/editions/epoch-gate-feature.rs b/src/test/ui/editions/epoch-gate-feature.rs new file mode 100644 index 000000000..5f7feb534 --- /dev/null +++ b/src/test/ui/editions/epoch-gate-feature.rs @@ -0,0 +1,15 @@ +// run-pass + +#![allow(dead_code)] +#![allow(unused_variables)] +// Checks if the correct registers are being used to pass arguments +// when the sysv64 ABI is specified. + +#![feature(rust_2018_preview)] + +pub trait Foo {} + +// should compile without the dyn trait feature flag +fn foo(x: &dyn Foo) {} + +pub fn main() {} |