about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/async-await/pin-sugar-ambiguity.rs15
-rw-r--r--tests/ui/async-await/pin-sugar-no-const.rs8
-rw-r--r--tests/ui/async-await/pin-sugar-no-const.stderr15
-rw-r--r--tests/ui/async-await/pin-sugar.rs51
-rw-r--r--tests/ui/feature-gates/feature-gate-pin_ergonomics.rs11
-rw-r--r--tests/ui/feature-gates/feature-gate-pin_ergonomics.stderr45
6 files changed, 135 insertions, 10 deletions
diff --git a/tests/ui/async-await/pin-sugar-ambiguity.rs b/tests/ui/async-await/pin-sugar-ambiguity.rs
new file mode 100644
index 00000000000..d183000931e
--- /dev/null
+++ b/tests/ui/async-await/pin-sugar-ambiguity.rs
@@ -0,0 +1,15 @@
+//@ check-pass
+#![feature(pin_ergonomics)]
+#![allow(dead_code, incomplete_features)]
+
+// Handle the case where there's ambiguity between pin as a contextual keyword and pin as a path.
+
+struct Foo;
+
+mod pin {
+    pub struct Foo;
+}
+
+fn main() {
+    let _x: &pin ::Foo = &pin::Foo;
+}
diff --git a/tests/ui/async-await/pin-sugar-no-const.rs b/tests/ui/async-await/pin-sugar-no-const.rs
new file mode 100644
index 00000000000..dd6456b6034
--- /dev/null
+++ b/tests/ui/async-await/pin-sugar-no-const.rs
@@ -0,0 +1,8 @@
+#![feature(pin_ergonomics)]
+#![allow(incomplete_features)]
+
+// Makes sure we don't accidentally accept `&pin Foo` without the `const` keyword.
+
+fn main() {
+    let _x: &pin i32 = todo!(); //~ ERROR found `i32`
+}
diff --git a/tests/ui/async-await/pin-sugar-no-const.stderr b/tests/ui/async-await/pin-sugar-no-const.stderr
new file mode 100644
index 00000000000..5f01156c1f0
--- /dev/null
+++ b/tests/ui/async-await/pin-sugar-no-const.stderr
@@ -0,0 +1,15 @@
+error: expected one of `!`, `(`, `::`, `;`, `<`, or `=`, found `i32`
+  --> $DIR/pin-sugar-no-const.rs:7:18
+   |
+LL |     let _x: &pin i32 = todo!();
+   |           -      ^^^ expected one of `!`, `(`, `::`, `;`, `<`, or `=`
+   |           |
+   |           while parsing the type for `_x`
+   |
+help: there is a keyword `in` with a similar name
+   |
+LL |     let _x: &in i32 = todo!();
+   |              ~~
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/async-await/pin-sugar.rs b/tests/ui/async-await/pin-sugar.rs
new file mode 100644
index 00000000000..8dbdec418b1
--- /dev/null
+++ b/tests/ui/async-await/pin-sugar.rs
@@ -0,0 +1,51 @@
+//@ check-pass
+
+#![feature(pin_ergonomics)]
+#![allow(dead_code, incomplete_features)]
+
+// Makes sure we can handle `&pin mut T` and `&pin const T` as sugar for `Pin<&mut T>` and
+// `Pin<&T>`.
+
+use std::pin::Pin;
+
+struct Foo;
+
+impl Foo {
+    fn baz(self: &pin mut Self) {
+    }
+
+    fn baz_const(self: &pin const Self) {
+    }
+
+    fn baz_lt<'a>(self: &'a pin mut Self) {
+    }
+
+    fn baz_const_lt(self: &'_ pin const Self) {
+    }
+}
+
+fn foo(_: &pin mut Foo) {
+}
+
+fn foo_const(x: &pin const Foo) {
+}
+
+fn bar(x: &pin mut Foo) {
+    foo(x);
+    foo(x); // for this to work we need to automatically reborrow,
+            // as if the user had written `foo(x.as_mut())`.
+
+    Foo::baz(x);
+    Foo::baz(x);
+
+    // make sure we can reborrow &mut as &.
+    foo_const(x);
+    Foo::baz_const(x);
+
+    let x: &pin const _ = Pin::new(&Foo);
+
+    foo_const(x); // make sure reborrowing from & to & works.
+    foo_const(x);
+}
+
+fn main() {}
diff --git a/tests/ui/feature-gates/feature-gate-pin_ergonomics.rs b/tests/ui/feature-gates/feature-gate-pin_ergonomics.rs
index 3382504af9d..4624faf1e53 100644
--- a/tests/ui/feature-gates/feature-gate-pin_ergonomics.rs
+++ b/tests/ui/feature-gates/feature-gate-pin_ergonomics.rs
@@ -1,4 +1,4 @@
-#![allow(dead_code, incomplete_features)]
+#![allow(dead_code)]
 
 use std::pin::Pin;
 
@@ -9,10 +9,13 @@ impl Foo {
     }
 }
 
-fn foo(_: Pin<&mut Foo>) {
+fn foo(x: Pin<&mut Foo>) {
+    let _y: &pin mut Foo = x; //~ ERROR pinned reference syntax is experimental
 }
 
-fn bar(mut x: Pin<&mut Foo>) {
+fn foo_sugar(_: &pin mut Foo) {} //~ ERROR pinned reference syntax is experimental
+
+fn bar(x: Pin<&mut Foo>) {
     foo(x);
     foo(x); //~ ERROR use of moved value: `x`
 }
@@ -22,4 +25,6 @@ fn baz(mut x: Pin<&mut Foo>) {
     x.foo(); //~ ERROR use of moved value: `x`
 }
 
+fn baz_sugar(_: &pin const Foo) {} //~ ERROR pinned reference syntax is experimental
+
 fn main() {}
diff --git a/tests/ui/feature-gates/feature-gate-pin_ergonomics.stderr b/tests/ui/feature-gates/feature-gate-pin_ergonomics.stderr
index 430b7866241..dd93a7be1ad 100644
--- a/tests/ui/feature-gates/feature-gate-pin_ergonomics.stderr
+++ b/tests/ui/feature-gates/feature-gate-pin_ergonomics.stderr
@@ -1,8 +1,38 @@
+error[E0658]: pinned reference syntax is experimental
+  --> $DIR/feature-gate-pin_ergonomics.rs:13:14
+   |
+LL |     let _y: &pin mut Foo = x;
+   |              ^^^
+   |
+   = note: see issue #130494 <https://github.com/rust-lang/rust/issues/130494> for more information
+   = help: add `#![feature(pin_ergonomics)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error[E0658]: pinned reference syntax is experimental
+  --> $DIR/feature-gate-pin_ergonomics.rs:16:18
+   |
+LL | fn foo_sugar(_: &pin mut Foo) {}
+   |                  ^^^
+   |
+   = note: see issue #130494 <https://github.com/rust-lang/rust/issues/130494> for more information
+   = help: add `#![feature(pin_ergonomics)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error[E0658]: pinned reference syntax is experimental
+  --> $DIR/feature-gate-pin_ergonomics.rs:28:18
+   |
+LL | fn baz_sugar(_: &pin const Foo) {}
+   |                  ^^^
+   |
+   = note: see issue #130494 <https://github.com/rust-lang/rust/issues/130494> for more information
+   = help: add `#![feature(pin_ergonomics)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
 error[E0382]: use of moved value: `x`
-  --> $DIR/feature-gate-pin_ergonomics.rs:17:9
+  --> $DIR/feature-gate-pin_ergonomics.rs:20:9
    |
-LL | fn bar(mut x: Pin<&mut Foo>) {
-   |        ----- move occurs because `x` has type `Pin<&mut Foo>`, which does not implement the `Copy` trait
+LL | fn bar(x: Pin<&mut Foo>) {
+   |        - move occurs because `x` has type `Pin<&mut Foo>`, which does not implement the `Copy` trait
 LL |     foo(x);
    |         - value moved here
 LL |     foo(x);
@@ -11,13 +41,13 @@ LL |     foo(x);
 note: consider changing this parameter type in function `foo` to borrow instead if owning the value isn't necessary
   --> $DIR/feature-gate-pin_ergonomics.rs:12:11
    |
-LL | fn foo(_: Pin<&mut Foo>) {
+LL | fn foo(x: Pin<&mut Foo>) {
    |    ---    ^^^^^^^^^^^^^ this parameter takes ownership of the value
    |    |
    |    in this function
 
 error[E0382]: use of moved value: `x`
-  --> $DIR/feature-gate-pin_ergonomics.rs:22:5
+  --> $DIR/feature-gate-pin_ergonomics.rs:25:5
    |
 LL | fn baz(mut x: Pin<&mut Foo>) {
    |        ----- move occurs because `x` has type `Pin<&mut Foo>`, which does not implement the `Copy` trait
@@ -36,6 +66,7 @@ help: consider reborrowing the `Pin` instead of moving it
 LL |     x.as_mut().foo();
    |      +++++++++
 
-error: aborting due to 2 previous errors
+error: aborting due to 5 previous errors
 
-For more information about this error, try `rustc --explain E0382`.
+Some errors have detailed explanations: E0382, E0658.
+For more information about an error, try `rustc --explain E0382`.