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/borrowck/issue-64453.stderr1
-rw-r--r--src/test/ui/borrowck/suggest-as-ref-on-mut-closure.stderr5
-rw-r--r--src/test/ui/check-static-values-constraints.stderr1
-rw-r--r--src/test/ui/consts/issue-32829-2.stderr2
-rw-r--r--src/test/ui/consts/mir_check_nonconst.stderr1
-rw-r--r--src/test/ui/issues/issue-100605.rs9
-rw-r--r--src/test/ui/issues/issue-100605.stderr46
-rw-r--r--src/test/ui/issues/issue-16538.mir.stderr1
-rw-r--r--src/test/ui/issues/issue-16538.thir.stderr1
-rw-r--r--src/test/ui/issues/issue-25901.stderr1
-rw-r--r--src/test/ui/parser/fn-defined-using-def.rs10
-rw-r--r--src/test/ui/parser/fn-defined-using-def.stderr10
-rw-r--r--src/test/ui/parser/fn-defined-using-fun.rs10
-rw-r--r--src/test/ui/parser/fn-defined-using-fun.stderr10
-rw-r--r--src/test/ui/parser/fn-defined-using-func.rs10
-rw-r--r--src/test/ui/parser/fn-defined-using-func.stderr10
-rw-r--r--src/test/ui/parser/fn-defined-using-function.rs10
-rw-r--r--src/test/ui/parser/fn-defined-using-function.stderr10
-rw-r--r--src/test/ui/static/static-vec-repeat-not-constant.stderr1
-rw-r--r--src/test/ui/suggestions/as-ref-2.fixed13
-rw-r--r--src/test/ui/suggestions/as-ref-2.rs2
-rw-r--r--src/test/ui/suggestions/as-ref-2.stderr10
-rw-r--r--src/test/ui/suggestions/option-content-move.fixed39
-rw-r--r--src/test/ui/suggestions/option-content-move.rs2
-rw-r--r--src/test/ui/suggestions/option-content-move.stderr14
25 files changed, 153 insertions, 76 deletions
diff --git a/src/test/ui/borrowck/issue-64453.stderr b/src/test/ui/borrowck/issue-64453.stderr
index 1f8a1acb89f..245c3a40e05 100644
--- a/src/test/ui/borrowck/issue-64453.stderr
+++ b/src/test/ui/borrowck/issue-64453.stderr
@@ -14,6 +14,7 @@ LL | static settings_dir: String = format!("");
    |                               ^^^^^^^^^^^
    |
    = note: calls in statics are limited to constant functions, tuple structs and tuple variants
+   = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
    = note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error[E0507]: cannot move out of static item `settings_dir`
diff --git a/src/test/ui/borrowck/suggest-as-ref-on-mut-closure.stderr b/src/test/ui/borrowck/suggest-as-ref-on-mut-closure.stderr
index af26169c806..b1af090aec2 100644
--- a/src/test/ui/borrowck/suggest-as-ref-on-mut-closure.stderr
+++ b/src/test/ui/borrowck/suggest-as-ref-on-mut-closure.stderr
@@ -5,6 +5,7 @@ LL |     cb.map(|cb| cb());
    |     ^^^--------------
    |     |  |
    |     |  `*cb` moved due to this method call
+   |     help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents
    |     move occurs because `*cb` has type `Option<&mut dyn FnMut()>`, which does not implement the `Copy` trait
    |
 note: this function takes ownership of the receiver `self`, which moves `*cb`
@@ -12,10 +13,6 @@ note: this function takes ownership of the receiver `self`, which moves `*cb`
    |
 LL |     pub const fn map<U, F>(self, f: F) -> Option<U>
    |                            ^^^^
-help: consider calling `.as_ref()` to borrow the type's contents
-   |
-LL |     cb.as_ref().map(|cb| cb());
-   |        +++++++++
 
 error[E0596]: cannot borrow `*cb` as mutable, as it is behind a `&` reference
   --> $DIR/suggest-as-ref-on-mut-closure.rs:12:26
diff --git a/src/test/ui/check-static-values-constraints.stderr b/src/test/ui/check-static-values-constraints.stderr
index b28cf0d6bd0..3c193ca34ac 100644
--- a/src/test/ui/check-static-values-constraints.stderr
+++ b/src/test/ui/check-static-values-constraints.stderr
@@ -22,6 +22,7 @@ LL |     field2: SafeEnum::Variant4("str".to_string())
    |                                      ^^^^^^^^^^^
    |
    = note: calls in statics are limited to constant functions, tuple structs and tuple variants
+   = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
 
 error[E0010]: allocations are not allowed in statics
   --> $DIR/check-static-values-constraints.rs:94:5
diff --git a/src/test/ui/consts/issue-32829-2.stderr b/src/test/ui/consts/issue-32829-2.stderr
index b94bdc0e3df..0fec3581873 100644
--- a/src/test/ui/consts/issue-32829-2.stderr
+++ b/src/test/ui/consts/issue-32829-2.stderr
@@ -13,6 +13,7 @@ LL |         invalid();
    |         ^^^^^^^^^
    |
    = note: calls in statics are limited to constant functions, tuple structs and tuple variants
+   = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
 
 error[E0015]: cannot call non-const fn `invalid` in statics
   --> $DIR/issue-32829-2.rs:54:9
@@ -21,6 +22,7 @@ LL |         invalid();
    |         ^^^^^^^^^
    |
    = note: calls in statics are limited to constant functions, tuple structs and tuple variants
+   = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
 
 error: aborting due to 3 previous errors
 
diff --git a/src/test/ui/consts/mir_check_nonconst.stderr b/src/test/ui/consts/mir_check_nonconst.stderr
index 2bac995eebf..1e0652722ff 100644
--- a/src/test/ui/consts/mir_check_nonconst.stderr
+++ b/src/test/ui/consts/mir_check_nonconst.stderr
@@ -5,6 +5,7 @@ LL | static foo: Foo = bar();
    |                   ^^^^^
    |
    = note: calls in statics are limited to constant functions, tuple structs and tuple variants
+   = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/issues/issue-100605.rs b/src/test/ui/issues/issue-100605.rs
new file mode 100644
index 00000000000..917a45c15bb
--- /dev/null
+++ b/src/test/ui/issues/issue-100605.rs
@@ -0,0 +1,9 @@
+fn takes_option(_arg: Option<&String>) {}
+
+fn main() {
+    takes_option(&None); //~ ERROR 4:18: 4:23: mismatched types [E0308]
+
+    let x = String::from("x");
+    let res = Some(x);
+    takes_option(&res); //~ ERROR 8:18: 8:22: mismatched types [E0308]
+}
diff --git a/src/test/ui/issues/issue-100605.stderr b/src/test/ui/issues/issue-100605.stderr
new file mode 100644
index 00000000000..886e3cd6bb7
--- /dev/null
+++ b/src/test/ui/issues/issue-100605.stderr
@@ -0,0 +1,46 @@
+error[E0308]: mismatched types
+  --> $DIR/issue-100605.rs:4:18
+   |
+LL |     takes_option(&None);
+   |     ------------ ^^^^^ expected enum `Option`, found `&Option<_>`
+   |     |
+   |     arguments to this function are incorrect
+   |
+   = note:   expected enum `Option<&String>`
+           found reference `&Option<_>`
+note: function defined here
+  --> $DIR/issue-100605.rs:1:4
+   |
+LL | fn takes_option(_arg: Option<&String>) {}
+   |    ^^^^^^^^^^^^ ---------------------
+help: you can convert from `&Option<T>` to `Option<&T>` using `.as_ref()`
+   |
+LL |     takes_option(None.as_ref());
+   |                  ~~~~~~~~~~~~~
+help: consider removing the borrow
+   |
+LL -     takes_option(&None);
+LL +     takes_option(None);
+   |
+
+error[E0308]: mismatched types
+  --> $DIR/issue-100605.rs:8:18
+   |
+LL |     takes_option(&res);
+   |     ------------ ^^^^
+   |     |            |
+   |     |            expected enum `Option`, found `&Option<String>`
+   |     |            help: you can convert from `&Option<T>` to `Option<&T>` using `.as_ref()`: `res.as_ref()`
+   |     arguments to this function are incorrect
+   |
+   = note:   expected enum `Option<&String>`
+           found reference `&Option<String>`
+note: function defined here
+  --> $DIR/issue-100605.rs:1:4
+   |
+LL | fn takes_option(_arg: Option<&String>) {}
+   |    ^^^^^^^^^^^^ ---------------------
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/issues/issue-16538.mir.stderr b/src/test/ui/issues/issue-16538.mir.stderr
index 7dab7de7619..e320df4b7ad 100644
--- a/src/test/ui/issues/issue-16538.mir.stderr
+++ b/src/test/ui/issues/issue-16538.mir.stderr
@@ -5,6 +5,7 @@ LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X);
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: calls in statics are limited to constant functions, tuple structs and tuple variants
+   = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
 
 error[E0133]: use of extern static is unsafe and requires unsafe function or block
   --> $DIR/issue-16538.rs:14:30
diff --git a/src/test/ui/issues/issue-16538.thir.stderr b/src/test/ui/issues/issue-16538.thir.stderr
index a18b0197d87..4a862869274 100644
--- a/src/test/ui/issues/issue-16538.thir.stderr
+++ b/src/test/ui/issues/issue-16538.thir.stderr
@@ -21,6 +21,7 @@ LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X);
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: calls in statics are limited to constant functions, tuple structs and tuple variants
+   = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
 
 error: aborting due to 3 previous errors
 
diff --git a/src/test/ui/issues/issue-25901.stderr b/src/test/ui/issues/issue-25901.stderr
index e933745c44e..c6c80e41cf6 100644
--- a/src/test/ui/issues/issue-25901.stderr
+++ b/src/test/ui/issues/issue-25901.stderr
@@ -16,6 +16,7 @@ note: impl defined here, but it is not `const`
 LL | impl Deref for A {
    | ^^^^^^^^^^^^^^^^
    = note: calls in statics are limited to constant functions, tuple structs and tuple variants
+   = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/parser/fn-defined-using-def.rs b/src/test/ui/parser/fn-defined-using-def.rs
new file mode 100644
index 00000000000..21da34c47c9
--- /dev/null
+++ b/src/test/ui/parser/fn-defined-using-def.rs
@@ -0,0 +1,10 @@
+// Check what happens when `def` is used to define a function, instead of `fn`
+// edition:2021
+
+#![allow(dead_code)]
+
+def foo() {}
+//~^ ERROR expected one of `!` or `::`, found `foo`
+//~^^ HELP write `fn` instead of `def` to declare a function
+
+fn main() {}
diff --git a/src/test/ui/parser/fn-defined-using-def.stderr b/src/test/ui/parser/fn-defined-using-def.stderr
new file mode 100644
index 00000000000..f34329012a0
--- /dev/null
+++ b/src/test/ui/parser/fn-defined-using-def.stderr
@@ -0,0 +1,10 @@
+error: expected one of `!` or `::`, found `foo`
+  --> $DIR/fn-defined-using-def.rs:6:5
+   |
+LL | def foo() {}
+   | --- ^^^ expected one of `!` or `::`
+   | |
+   | help: write `fn` instead of `def` to declare a function
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/fn-defined-using-fun.rs b/src/test/ui/parser/fn-defined-using-fun.rs
new file mode 100644
index 00000000000..4f74605043e
--- /dev/null
+++ b/src/test/ui/parser/fn-defined-using-fun.rs
@@ -0,0 +1,10 @@
+// Check what happens when `fun` is used to define a function, instead of `fn`
+// edition:2021
+
+#![allow(dead_code)]
+
+fun foo() {}
+//~^ ERROR expected one of `!` or `::`, found `foo`
+//~^^ HELP write `fn` instead of `fun` to declare a function
+
+fn main() {}
diff --git a/src/test/ui/parser/fn-defined-using-fun.stderr b/src/test/ui/parser/fn-defined-using-fun.stderr
new file mode 100644
index 00000000000..2f6cfff350c
--- /dev/null
+++ b/src/test/ui/parser/fn-defined-using-fun.stderr
@@ -0,0 +1,10 @@
+error: expected one of `!` or `::`, found `foo`
+  --> $DIR/fn-defined-using-fun.rs:6:5
+   |
+LL | fun foo() {}
+   | --- ^^^ expected one of `!` or `::`
+   | |
+   | help: write `fn` instead of `fun` to declare a function
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/fn-defined-using-func.rs b/src/test/ui/parser/fn-defined-using-func.rs
new file mode 100644
index 00000000000..2dce96fdce0
--- /dev/null
+++ b/src/test/ui/parser/fn-defined-using-func.rs
@@ -0,0 +1,10 @@
+// Check what happens when `func` is used to define a function, instead of `fn`
+// edition:2021
+
+#![allow(dead_code)]
+
+func foo() {}
+//~^ ERROR expected one of `!` or `::`, found `foo`
+//~^^ HELP write `fn` instead of `func` to declare a function
+
+fn main() {}
diff --git a/src/test/ui/parser/fn-defined-using-func.stderr b/src/test/ui/parser/fn-defined-using-func.stderr
new file mode 100644
index 00000000000..355741e8949
--- /dev/null
+++ b/src/test/ui/parser/fn-defined-using-func.stderr
@@ -0,0 +1,10 @@
+error: expected one of `!` or `::`, found `foo`
+  --> $DIR/fn-defined-using-func.rs:6:6
+   |
+LL | func foo() {}
+   | ---- ^^^ expected one of `!` or `::`
+   | |
+   | help: write `fn` instead of `func` to declare a function
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/fn-defined-using-function.rs b/src/test/ui/parser/fn-defined-using-function.rs
new file mode 100644
index 00000000000..fd8782728e2
--- /dev/null
+++ b/src/test/ui/parser/fn-defined-using-function.rs
@@ -0,0 +1,10 @@
+// Check what happens when `function` is used to define a function, instead of `fn`
+// edition:2021
+
+#![allow(dead_code)]
+
+function foo() {}
+//~^ ERROR expected one of `!` or `::`, found `foo`
+//~^^ HELP write `fn` instead of `function` to declare a function
+
+fn main() {}
diff --git a/src/test/ui/parser/fn-defined-using-function.stderr b/src/test/ui/parser/fn-defined-using-function.stderr
new file mode 100644
index 00000000000..43c33a2cdd7
--- /dev/null
+++ b/src/test/ui/parser/fn-defined-using-function.stderr
@@ -0,0 +1,10 @@
+error: expected one of `!` or `::`, found `foo`
+  --> $DIR/fn-defined-using-function.rs:6:10
+   |
+LL | function foo() {}
+   | -------- ^^^ expected one of `!` or `::`
+   | |
+   | help: write `fn` instead of `function` to declare a function
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/static/static-vec-repeat-not-constant.stderr b/src/test/ui/static/static-vec-repeat-not-constant.stderr
index 84fc638a973..dec0123184d 100644
--- a/src/test/ui/static/static-vec-repeat-not-constant.stderr
+++ b/src/test/ui/static/static-vec-repeat-not-constant.stderr
@@ -5,6 +5,7 @@ LL | static a: [isize; 2] = [foo(); 2];
    |                         ^^^^^
    |
    = note: calls in statics are limited to constant functions, tuple structs and tuple variants
+   = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/suggestions/as-ref-2.fixed b/src/test/ui/suggestions/as-ref-2.fixed
deleted file mode 100644
index 13bbb233f39..00000000000
--- a/src/test/ui/suggestions/as-ref-2.fixed
+++ /dev/null
@@ -1,13 +0,0 @@
-// run-rustfix
-
-struct Struct;
-
-fn bar(_: &Struct) -> Struct {
-    Struct
-}
-
-fn main() {
-    let foo = Some(Struct);
-    let _x: Option<Struct> = foo.as_ref().map(|s| bar(&s));
-    let _y = foo; //~ERROR use of moved value: `foo`
-}
diff --git a/src/test/ui/suggestions/as-ref-2.rs b/src/test/ui/suggestions/as-ref-2.rs
index 74d61cdd95f..b22f409b44a 100644
--- a/src/test/ui/suggestions/as-ref-2.rs
+++ b/src/test/ui/suggestions/as-ref-2.rs
@@ -1,5 +1,3 @@
-// run-rustfix
-
 struct Struct;
 
 fn bar(_: &Struct) -> Struct {
diff --git a/src/test/ui/suggestions/as-ref-2.stderr b/src/test/ui/suggestions/as-ref-2.stderr
index 3c9d0f72abe..e15e45d86b9 100644
--- a/src/test/ui/suggestions/as-ref-2.stderr
+++ b/src/test/ui/suggestions/as-ref-2.stderr
@@ -1,10 +1,12 @@
 error[E0382]: use of moved value: `foo`
-  --> $DIR/as-ref-2.rs:12:14
+  --> $DIR/as-ref-2.rs:10:14
    |
 LL |     let foo = Some(Struct);
    |         --- move occurs because `foo` has type `Option<Struct>`, which does not implement the `Copy` trait
 LL |     let _x: Option<Struct> = foo.map(|s| bar(&s));
-   |                                  ---------------- `foo` moved due to this method call
+   |                              --- ---------------- `foo` moved due to this method call
+   |                              |
+   |                              help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents
 LL |     let _y = foo;
    |              ^^^ value used here after move
    |
@@ -13,10 +15,6 @@ note: this function takes ownership of the receiver `self`, which moves `foo`
    |
 LL |     pub const fn map<U, F>(self, f: F) -> Option<U>
    |                            ^^^^
-help: consider calling `.as_ref()` to borrow the type's contents
-   |
-LL |     let _x: Option<Struct> = foo.as_ref().map(|s| bar(&s));
-   |                                  +++++++++
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/suggestions/option-content-move.fixed b/src/test/ui/suggestions/option-content-move.fixed
deleted file mode 100644
index ba16bcc8a33..00000000000
--- a/src/test/ui/suggestions/option-content-move.fixed
+++ /dev/null
@@ -1,39 +0,0 @@
-//run-rustfix
-
-pub struct LipogramCorpora {
-    selections: Vec<(char, Option<String>)>,
-}
-
-impl LipogramCorpora {
-    pub fn validate_all(&mut self) -> Result<(), char> {
-        for selection in &self.selections {
-            if selection.1.is_some() {
-                if selection.1.as_ref().unwrap().contains(selection.0) {
-                //~^ ERROR cannot move out of `selection.1`
-                    return Err(selection.0);
-                }
-            }
-        }
-        Ok(())
-    }
-}
-
-pub struct LipogramCorpora2 {
-    selections: Vec<(char, Result<String, String>)>,
-}
-
-impl LipogramCorpora2 {
-    pub fn validate_all(&mut self) -> Result<(), char> {
-        for selection in &self.selections {
-            if selection.1.is_ok() {
-                if selection.1.as_ref().unwrap().contains(selection.0) {
-                //~^ ERROR cannot move out of `selection.1`
-                    return Err(selection.0);
-                }
-            }
-        }
-        Ok(())
-    }
-}
-
-fn main() {}
diff --git a/src/test/ui/suggestions/option-content-move.rs b/src/test/ui/suggestions/option-content-move.rs
index ef38f114eca..46c895b95f5 100644
--- a/src/test/ui/suggestions/option-content-move.rs
+++ b/src/test/ui/suggestions/option-content-move.rs
@@ -1,5 +1,3 @@
-//run-rustfix
-
 pub struct LipogramCorpora {
     selections: Vec<(char, Option<String>)>,
 }
diff --git a/src/test/ui/suggestions/option-content-move.stderr b/src/test/ui/suggestions/option-content-move.stderr
index fccfbe1d744..a6f1ebc975f 100644
--- a/src/test/ui/suggestions/option-content-move.stderr
+++ b/src/test/ui/suggestions/option-content-move.stderr
@@ -1,9 +1,10 @@
 error[E0507]: cannot move out of `selection.1` which is behind a shared reference
-  --> $DIR/option-content-move.rs:11:20
+  --> $DIR/option-content-move.rs:9:20
    |
 LL |                 if selection.1.unwrap().contains(selection.0) {
    |                    ^^^^^^^^^^^ -------- `selection.1` moved due to this method call
    |                    |
+   |                    help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents
    |                    move occurs because `selection.1` has type `Option<String>`, which does not implement the `Copy` trait
    |
 note: this function takes ownership of the receiver `self`, which moves `selection.1`
@@ -11,17 +12,14 @@ note: this function takes ownership of the receiver `self`, which moves `selecti
    |
 LL |     pub const fn unwrap(self) -> T {
    |                         ^^^^
-help: consider calling `.as_ref()` to borrow the type's contents
-   |
-LL |                 if selection.1.as_ref().unwrap().contains(selection.0) {
-   |                                +++++++++
 
 error[E0507]: cannot move out of `selection.1` which is behind a shared reference
-  --> $DIR/option-content-move.rs:29:20
+  --> $DIR/option-content-move.rs:27:20
    |
 LL |                 if selection.1.unwrap().contains(selection.0) {
    |                    ^^^^^^^^^^^ -------- `selection.1` moved due to this method call
    |                    |
+   |                    help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents
    |                    move occurs because `selection.1` has type `Result<String, String>`, which does not implement the `Copy` trait
    |
 note: this function takes ownership of the receiver `self`, which moves `selection.1`
@@ -29,10 +27,6 @@ note: this function takes ownership of the receiver `self`, which moves `selecti
    |
 LL |     pub fn unwrap(self) -> T
    |                   ^^^^
-help: consider calling `.as_ref()` to borrow the type's contents
-   |
-LL |                 if selection.1.as_ref().unwrap().contains(selection.0) {
-   |                                +++++++++
 
 error: aborting due to 2 previous errors