about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr2
-rw-r--r--src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs18
-rw-r--r--src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr93
-rw-r--r--src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs15
-rw-r--r--src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr24
-rw-r--r--src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs58
-rw-r--r--src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr107
7 files changed, 316 insertions, 1 deletions
diff --git a/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr b/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr
index 30a96af583a..1a022c30938 100644
--- a/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr
+++ b/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr
@@ -71,7 +71,7 @@ LL |
 LL | / extern "C" {
 LL | |     fn foo();
 LL | | }
-   | |_- rustdoc does not generate documentation for extern block
+   | |_- rustdoc does not generate documentation for extern blocks
    |
    = help: use `//` for a plain comment
 
diff --git a/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs
new file mode 100644
index 00000000000..b280c8ab6e2
--- /dev/null
+++ b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs
@@ -0,0 +1,18 @@
+// compile-flags: -Wrust-2021-incompatible-closure-captures
+
+pub struct A {}
+
+impl A {
+    async fn create(path: impl AsRef<std::path::Path>)  { //~ ERROR  `async fn` is not permitted in Rust 2015
+    //~^ WARN changes to closure capture in Rust 2021 will affect drop order [rust_2021_incompatible_closure_captures]
+    ;
+    crate(move || {} ).await //~ ERROR expected function, found module `crate`
+    }
+}
+
+trait C{async fn new(val: T) {} //~ ERROR  `async fn` is not permitted in Rust 2015
+//~^ ERROR functions in traits cannot be declared `async`
+//~^^ ERROR cannot find type `T` in this scope
+//~^^^ WARN changes to closure capture in Rust 2021 will affect drop order [rust_2021_incompatible_closure_captures]
+
+//~ ERROR  this file contains an unclosed delimiter
diff --git a/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr
new file mode 100644
index 00000000000..50de2322907
--- /dev/null
+++ b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr
@@ -0,0 +1,93 @@
+error: this file contains an unclosed delimiter
+  --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:18:53
+   |
+LL | trait C{async fn new(val: T) {}
+   |        - unclosed delimiter
+...
+LL |
+   |                                                     ^
+
+error[E0670]: `async fn` is not permitted in Rust 2015
+  --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:6:5
+   |
+LL |     async fn create(path: impl AsRef<std::path::Path>)  {
+   |     ^^^^^ 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[E0670]: `async fn` is not permitted in Rust 2015
+  --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:9
+   |
+LL | trait C{async fn new(val: T) {}
+   |         ^^^^^ 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[E0706]: functions in traits cannot be declared `async`
+  --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:9
+   |
+LL | trait C{async fn new(val: T) {}
+   |         -----^^^^^^^^^^^^^^^^^^
+   |         |
+   |         `async` because of this
+   |
+   = note: `async` trait functions are not currently supported
+   = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
+
+error[E0423]: expected function, found module `crate`
+  --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:9:5
+   |
+LL |     crate(move || {} ).await
+   |     ^^^^^ not a function
+
+error[E0412]: cannot find type `T` in this scope
+  --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:27
+   |
+LL | pub struct A {}
+   | ------------ similarly named struct `A` defined here
+...
+LL | trait C{async fn new(val: T) {}
+   |                           ^ help: a struct with a similar name exists: `A`
+
+warning: changes to closure capture in Rust 2021 will affect drop order
+  --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:6:57
+   |
+LL |       async fn create(path: impl AsRef<std::path::Path>)  {
+   |  _____________________----_____________________________-__^
+   | |                     |                                |
+   | |                     |                                in Rust 2018, `path` is dropped here along with the closure, but in Rust 2021 `path` is not part of the closure
+   | |                     in Rust 2018, this causes the closure to capture `path`, but in Rust 2021, it has no effect
+LL | |
+LL | |     ;
+LL | |     crate(move || {} ).await
+LL | |     }
+   | |_____^
+   |
+   = note: requested on the command line with `-W rust-2021-incompatible-closure-captures`
+   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
+help: add a dummy let to cause `path` to be fully captured
+   |
+LL |     async fn create(path: impl AsRef<std::path::Path>)  { let _ = &path;
+   |                                                           ++++++++++++++
+
+warning: changes to closure capture in Rust 2021 will affect drop order
+  --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:30
+   |
+LL | trait C{async fn new(val: T) {}
+   |                      ---   - ^^
+   |                      |     |
+   |                      |     in Rust 2018, `val` is dropped here along with the closure, but in Rust 2021 `val` is not part of the closure
+   |                      in Rust 2018, this causes the closure to capture `val`, but in Rust 2021, it has no effect
+   |
+   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
+help: add a dummy let to cause `val` to be fully captured
+   |
+LL | trait C{async fn new(val: T) { let _ = &val;}
+   |                                +++++++++++++
+
+error: aborting due to 6 previous errors; 2 warnings emitted
+
+Some errors have detailed explanations: E0412, E0423, E0670, E0706.
+For more information about an error, try `rustc --explain E0412`.
diff --git a/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs
new file mode 100644
index 00000000000..a776e508907
--- /dev/null
+++ b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs
@@ -0,0 +1,15 @@
+// compile-flags -Wrust-2021-incompatible-closure-captures
+
+fn main() {}
+
+pub(crate) struct Numberer {}
+
+impl Numberer {
+    pub(crate) async fn new(
+    //~^ ERROR `async fn` is not permitted in Rust 2015
+        interval: Duration,
+        //~^ ERROR cannot find type `Duration` in this scope
+    ) -> Numberer {
+        Numberer {}
+    }
+}
diff --git a/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr
new file mode 100644
index 00000000000..37b2f413860
--- /dev/null
+++ b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr
@@ -0,0 +1,24 @@
+error[E0670]: `async fn` is not permitted in Rust 2015
+  --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs:8:16
+   |
+LL |     pub(crate) async fn new(
+   |                ^^^^^ 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[E0412]: cannot find type `Duration` in this scope
+  --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs:10:19
+   |
+LL |         interval: Duration,
+   |                   ^^^^^^^^ not found in this scope
+   |
+help: consider importing this struct
+   |
+LL | use std::time::Duration;
+   |
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0412, E0670.
+For more information about an error, try `rustc --explain E0412`.
diff --git a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs
new file mode 100644
index 00000000000..7cf536f7966
--- /dev/null
+++ b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs
@@ -0,0 +1,58 @@
+// Ensure that the compiler include the blanklet implementation suggestion
+// when inside a `impl` statment are used two local traits.
+//
+// edition:2021
+use std::fmt;
+
+trait LocalTraitOne { }
+
+trait LocalTraitTwo { }
+
+trait GenericTrait<T> {}
+
+impl LocalTraitTwo for LocalTraitOne {}
+//~^ ERROR trait objects must include the `dyn` keyword
+//~| HELP add `dyn` keyword before this trait
+//~| HELP alternatively use a blanket implementation to implement `LocalTraitTwo` for all types that also implement `LocalTraitOne`
+
+impl fmt::Display for LocalTraitOne {
+//~^ ERROR trait objects must include the `dyn` keyword
+//~| HELP add `dyn` keyword before this trait
+    fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        todo!();
+    }
+}
+
+impl fmt::Display for LocalTraitTwo + Send {
+//~^ ERROR trait objects must include the `dyn` keyword
+//~| HELP add `dyn` keyword before this trait
+    fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        todo!();
+    }
+}
+
+impl LocalTraitOne for fmt::Display {}
+//~^ ERROR trait objects must include the `dyn` keyword
+//~| HELP add `dyn` keyword before this trait
+//~| HELP alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display`
+
+
+impl LocalTraitOne for fmt::Display + Send {}
+//~^ ERROR trait objects must include the `dyn` keyword
+//~| HELP add `dyn` keyword before this trait
+//~| HELP alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display + Send`
+
+
+impl<E> GenericTrait<E> for LocalTraitOne {}
+//~^ ERROR trait objects must include the `dyn` keyword
+//~| HELP add `dyn` keyword before this trait
+//~| HELP alternatively use a blanket implementation to implement `GenericTrait<E>` for all types that also implement `LocalTraitOne`
+
+trait GenericTraitTwo<T> {}
+
+impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {}
+//~^ ERROR trait objects must include the `dyn` keyword
+//~| HELP add `dyn` keyword before this trait
+//~| HELP alternatively use a blanket implementation to implement `GenericTraitTwo<E>` for all types that also implement `GenericTrait<T>`
+
+fn main() {}
diff --git a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr
new file mode 100644
index 00000000000..d739a8272f1
--- /dev/null
+++ b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr
@@ -0,0 +1,107 @@
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:13:24
+   |
+LL | impl LocalTraitTwo for LocalTraitOne {}
+   |                        ^^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl LocalTraitTwo for LocalTraitOne {}
+LL + impl LocalTraitTwo for dyn LocalTraitOne {}
+   |
+help: alternatively use a blanket implementation to implement `LocalTraitTwo` for all types that also implement `LocalTraitOne`
+   |
+LL | impl<T: LocalTraitOne> LocalTraitTwo for T {}
+   |     ++++++++++++++++++                   ~
+
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:18:23
+   |
+LL | impl fmt::Display for LocalTraitOne {
+   |                       ^^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl fmt::Display for LocalTraitOne {
+LL + impl fmt::Display for dyn LocalTraitOne {
+   |
+
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:26:23
+   |
+LL | impl fmt::Display for LocalTraitTwo + Send {
+   |                       ^^^^^^^^^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl fmt::Display for LocalTraitTwo + Send {
+LL + impl fmt::Display for dyn LocalTraitTwo + Send {
+   |
+
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:34:24
+   |
+LL | impl LocalTraitOne for fmt::Display {}
+   |                        ^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl LocalTraitOne for fmt::Display {}
+LL + impl LocalTraitOne for dyn fmt::Display {}
+   |
+help: alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display`
+   |
+LL | impl<T: fmt::Display> LocalTraitOne for T {}
+   |     +++++++++++++++++                   ~
+
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:40:24
+   |
+LL | impl LocalTraitOne for fmt::Display + Send {}
+   |                        ^^^^^^^^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl LocalTraitOne for fmt::Display + Send {}
+LL + impl LocalTraitOne for dyn fmt::Display + Send {}
+   |
+help: alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display + Send`
+   |
+LL | impl<T: fmt::Display + Send> LocalTraitOne for T {}
+   |     ++++++++++++++++++++++++                   ~
+
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:46:29
+   |
+LL | impl<E> GenericTrait<E> for LocalTraitOne {}
+   |                             ^^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl<E> GenericTrait<E> for LocalTraitOne {}
+LL + impl<E> GenericTrait<E> for dyn LocalTraitOne {}
+   |
+help: alternatively use a blanket implementation to implement `GenericTrait<E>` for all types that also implement `LocalTraitOne`
+   |
+LL | impl<E, T: LocalTraitOne> GenericTrait<E> for T {}
+   |       ++++++++++++++++++                      ~
+
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:53:35
+   |
+LL | impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {}
+   |                                   ^^^^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {}
+LL + impl<T, E> GenericTraitTwo<E> for dyn GenericTrait<T> {}
+   |
+help: alternatively use a blanket implementation to implement `GenericTraitTwo<E>` for all types that also implement `GenericTrait<T>`
+   |
+LL | impl<T, E, U: GenericTrait<T>> GenericTraitTwo<E> for U {}
+   |          ++++++++++++++++++++                         ~
+
+error: aborting due to 7 previous errors
+
+For more information about this error, try `rustc --explain E0782`.