about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/incremental/hygiene/load_cached_hygiene.rs2
-rw-r--r--tests/rustdoc-js/trailing.js7
-rw-r--r--tests/rustdoc-js/trailing.rs3
-rw-r--r--tests/ui/bootstrap/rustc_bootstap.force_stable.stderr10
-rw-r--r--tests/ui/bootstrap/rustc_bootstap.rs47
-rw-r--r--tests/ui/coercion/unboxing-needing-parenthases-issue-132924.rs18
-rw-r--r--tests/ui/coercion/unboxing-needing-parenthases-issue-132924.stderr59
-rw-r--r--tests/ui/impl-trait/in-trait/refine-captures.rs36
-rw-r--r--tests/ui/impl-trait/in-trait/refine-captures.stderr52
-rw-r--r--tests/ui/moves/moved-value-on-as-ref-arg.fixed4
-rw-r--r--tests/ui/moves/moved-value-on-as-ref-arg.rs4
-rw-r--r--tests/ui/moves/region-var-in-moved-ty-issue-133118.rs25
-rw-r--r--tests/ui/moves/region-var-in-moved-ty-issue-133118.stderr21
-rw-r--r--tests/ui/parser/suggest-const-for-global-var.stderr7
-rw-r--r--tests/ui/parser/suggest-static-for-global-var-mut.rs5
-rw-r--r--tests/ui/parser/suggest-static-for-global-var-mut.stderr11
-rw-r--r--tests/ui/symbol-names/basic.rs2
-rw-r--r--tests/ui/symbol-names/impl1.rs2
-rw-r--r--tests/ui/symbol-names/issue-60925.rs2
19 files changed, 308 insertions, 9 deletions
diff --git a/tests/incremental/hygiene/load_cached_hygiene.rs b/tests/incremental/hygiene/load_cached_hygiene.rs
index 4ad9c7d49fd..101d280cd49 100644
--- a/tests/incremental/hygiene/load_cached_hygiene.rs
+++ b/tests/incremental/hygiene/load_cached_hygiene.rs
@@ -7,7 +7,7 @@
 //    This causes hygiene information to be saved to the incr cache.
 // 2. One function is the foreign crate is modified. This causes the
 //    optimized mir for an unmodified function to be loaded from the
-//@    incremental cache and written out to the crate metadata.
+//    incremental cache and written out to the crate metadata.
 // 3. In the process of loading and writing out this function's MIR,
 //    we load hygiene information from the incremental cache and
 //    write it to our metadata.
diff --git a/tests/rustdoc-js/trailing.js b/tests/rustdoc-js/trailing.js
new file mode 100644
index 00000000000..df5dd22ca4e
--- /dev/null
+++ b/tests/rustdoc-js/trailing.js
@@ -0,0 +1,7 @@
+// exact-check
+const EXPECTED = {
+    'query': 'inner::',
+    'others': [
+        { 'path': 'trailing::inner', 'name': 'function' },
+    ],
+}
diff --git a/tests/rustdoc-js/trailing.rs b/tests/rustdoc-js/trailing.rs
new file mode 100644
index 00000000000..5c7c9362ffb
--- /dev/null
+++ b/tests/rustdoc-js/trailing.rs
@@ -0,0 +1,3 @@
+pub mod inner {
+    pub fn function() {}
+}
diff --git a/tests/ui/bootstrap/rustc_bootstap.force_stable.stderr b/tests/ui/bootstrap/rustc_bootstap.force_stable.stderr
new file mode 100644
index 00000000000..f378f3c70dd
--- /dev/null
+++ b/tests/ui/bootstrap/rustc_bootstap.force_stable.stderr
@@ -0,0 +1,10 @@
+error: the option `Z` is only accepted on the nightly compiler
+
+help: consider switching to a nightly toolchain: `rustup default nightly`
+
+note: selecting a toolchain with `+toolchain` arguments require a rustup proxy; see <https://rust-lang.github.io/rustup/concepts/index.html>
+
+note: for more information about Rust's stability policy, see <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html#unstable-features>
+
+error: 1 nightly option were parsed
+
diff --git a/tests/ui/bootstrap/rustc_bootstap.rs b/tests/ui/bootstrap/rustc_bootstap.rs
new file mode 100644
index 00000000000..3d792ef4be4
--- /dev/null
+++ b/tests/ui/bootstrap/rustc_bootstap.rs
@@ -0,0 +1,47 @@
+//! Check `RUSTC_BOOTSTRAP`'s behavior in relation to feature stability and what rustc considers
+//! itself to be (stable vs non-stable ).
+//!
+//! `RUSTC_BOOTSTRAP` accepts:
+//!
+//! - `1`: cheat, allow usage of unstable features even if rustc thinks it is a stable compiler.
+//! - `x,y,z`: comma-delimited list of crates.
+//! - `-1`: force rustc to think it is a stable compiler.
+
+// ignore-tidy-linelength
+
+//@ revisions: default_nightly cheat cheat_single_crate cheat_multi_crate force_stable invalid_zero invalid_junk
+//@ only-nightly
+
+//@[default_nightly] unset-rustc-env:RUSTC_BOOTSTRAP
+//@[default_nightly] check-pass
+
+// For a nightly compiler, this is same as `default_nightly` as if `RUSTC_BOOTSTRAP` was unset.
+//@[invalid_zero] rustc-env:RUSTC_BOOTSTRAP=0
+//@[invalid_zero] check-pass
+
+// Invalid values are silently discarded, same as `default_nightly`, i.e. as if `RUSTC_BOOTSTRAP`
+// was unset.
+//@[invalid_junk] rustc-env:RUSTC_BOOTSTRAP=*
+//@[invalid_junk] check-pass
+
+//@[cheat] rustc-env:RUSTC_BOOTSTRAP=1
+//@[cheat] check-pass
+
+//@[cheat_single_crate] rustc-env:RUSTC_BOOTSTRAP=x
+//@[cheat_single_crate] check-pass
+
+//@[cheat_multi_crate] rustc-env:RUSTC_BOOTSTRAP=x,y,z
+//@[cheat_multi_crate] check-pass
+
+// Note: compiletest passes some `-Z` flags to the compiler for ui testing purposes, so here we
+// instead abuse the fact that `-Z unstable-options` is also part of rustc's stability story and is
+// also affected by `RUSTC_BOOTSTRAP`.
+//@[force_stable] rustc-env:RUSTC_BOOTSTRAP=-1
+//@[force_stable] compile-flags: -Z unstable-options
+//@[force_stable] regex-error-pattern: error: the option `Z` is only accepted on the nightly compiler
+
+#![crate_type = "lib"]
+
+// Note: `rustc_attrs` is a perma-unstable internal feature that is unlikely to change, which is
+// used as a proxy to check `RUSTC_BOOTSTRAP` versus stability checking logic.
+#![feature(rustc_attrs)]
diff --git a/tests/ui/coercion/unboxing-needing-parenthases-issue-132924.rs b/tests/ui/coercion/unboxing-needing-parenthases-issue-132924.rs
new file mode 100644
index 00000000000..fc4258fc0af
--- /dev/null
+++ b/tests/ui/coercion/unboxing-needing-parenthases-issue-132924.rs
@@ -0,0 +1,18 @@
+//@ check-fail
+fn main() {
+    let x = Box::new(Some(1));
+
+    let test: Option<i32> = x;
+    //~^ ERROR mismatched types
+    let x = Box::new(Some(1));
+    let test: Option<i32> = { x as Box<Option<i32>> };
+    //~^ ERROR mismatched types
+
+    let x = Box::new(Some(1));
+    let test: Option<i32> = if true { x as Box<Option<i32>> } else { None };
+    //~^ ERROR mismatched types
+
+    let x = std::rc::Rc::new(Some(1));
+    let test: Option<i32> = x as std::rc::Rc<Option<i32>>;
+    //~^ ERROR mismatched types
+}
diff --git a/tests/ui/coercion/unboxing-needing-parenthases-issue-132924.stderr b/tests/ui/coercion/unboxing-needing-parenthases-issue-132924.stderr
new file mode 100644
index 00000000000..429b1b87357
--- /dev/null
+++ b/tests/ui/coercion/unboxing-needing-parenthases-issue-132924.stderr
@@ -0,0 +1,59 @@
+error[E0308]: mismatched types
+  --> $DIR/unboxing-needing-parenthases-issue-132924.rs:5:29
+   |
+LL |     let test: Option<i32> = x;
+   |               -----------   ^ expected `Option<i32>`, found `Box<Option<{integer}>>`
+   |               |
+   |               expected due to this
+   |
+   = note: expected enum `Option<i32>`
+            found struct `Box<Option<{integer}>>`
+help: consider unboxing the value
+   |
+LL |     let test: Option<i32> = *x;
+   |                             +
+
+error[E0308]: mismatched types
+  --> $DIR/unboxing-needing-parenthases-issue-132924.rs:8:31
+   |
+LL |     let test: Option<i32> = { x as Box<Option<i32>> };
+   |                               ^^^^^^^^^^^^^^^^^^^^^ expected `Option<i32>`, found `Box<Option<i32>>`
+   |
+   = note: expected enum `Option<_>`
+            found struct `Box<Option<_>>`
+help: consider unboxing the value
+   |
+LL |     let test: Option<i32> = { *(x as Box<Option<i32>>) };
+   |                               ++                     +
+
+error[E0308]: mismatched types
+  --> $DIR/unboxing-needing-parenthases-issue-132924.rs:12:39
+   |
+LL |     let test: Option<i32> = if true { x as Box<Option<i32>> } else { None };
+   |                                       ^^^^^^^^^^^^^^^^^^^^^ expected `Option<i32>`, found `Box<Option<i32>>`
+   |
+   = note: expected enum `Option<_>`
+            found struct `Box<Option<_>>`
+help: consider unboxing the value
+   |
+LL |     let test: Option<i32> = if true { *(x as Box<Option<i32>>) } else { None };
+   |                                       ++                     +
+
+error[E0308]: mismatched types
+  --> $DIR/unboxing-needing-parenthases-issue-132924.rs:16:29
+   |
+LL |     let test: Option<i32> = x as std::rc::Rc<Option<i32>>;
+   |               -----------   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Option<i32>`, found `Rc<Option<i32>>`
+   |               |
+   |               expected due to this
+   |
+   = note: expected enum `Option<_>`
+            found struct `Rc<Option<_>>`
+help: consider dereferencing the type
+   |
+LL |     let test: Option<i32> = *(x as std::rc::Rc<Option<i32>>);
+   |                             ++                             +
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/impl-trait/in-trait/refine-captures.rs b/tests/ui/impl-trait/in-trait/refine-captures.rs
new file mode 100644
index 00000000000..e7dffcb52aa
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/refine-captures.rs
@@ -0,0 +1,36 @@
+#![feature(precise_capturing_in_traits)]
+
+trait LifetimeParam<'a> {
+    fn test() -> impl Sized;
+}
+// Refining via capturing fewer lifetimes than the trait definition.
+impl<'a> LifetimeParam<'a> for i32 {
+    fn test() -> impl Sized + use<> {}
+    //~^ WARN impl trait in impl method captures fewer lifetimes than in trait
+}
+// If the lifetime is substituted, then we don't refine anything.
+impl LifetimeParam<'static> for u32 {
+    fn test() -> impl Sized + use<> {}
+    // Ok
+}
+
+trait TypeParam<T> {
+    fn test() -> impl Sized;
+}
+// Indirectly capturing a lifetime param through a type param substitution.
+impl<'a> TypeParam<&'a ()> for i32 {
+    fn test() -> impl Sized + use<> {}
+    //~^ WARN impl trait in impl method captures fewer lifetimes than in trait
+}
+// Two of them, but only one is captured...
+impl<'a, 'b> TypeParam<(&'a (), &'b ())> for u32 {
+    fn test() -> impl Sized + use<'b> {}
+    //~^ WARN impl trait in impl method captures fewer lifetimes than in trait
+}
+// What if we don't capture a type param? That should be an error otherwise.
+impl<T> TypeParam<T> for u64 {
+    fn test() -> impl Sized + use<> {}
+    //~^ ERROR `impl Trait` must mention all type parameters in scope in `use<...>`
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/in-trait/refine-captures.stderr b/tests/ui/impl-trait/in-trait/refine-captures.stderr
new file mode 100644
index 00000000000..ad2c2a11601
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/refine-captures.stderr
@@ -0,0 +1,52 @@
+warning: impl trait in impl method captures fewer lifetimes than in trait
+  --> $DIR/refine-captures.rs:8:31
+   |
+LL |     fn test() -> impl Sized + use<> {}
+   |                               ^^^^^
+   |
+   = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
+   = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
+   = note: `#[warn(refining_impl_trait_internal)]` on by default
+help: modify the `use<..>` bound to capture the same lifetimes that the trait does
+   |
+LL |     fn test() -> impl Sized + use<'a> {}
+   |                               ~~~~~~~
+
+warning: impl trait in impl method captures fewer lifetimes than in trait
+  --> $DIR/refine-captures.rs:22:31
+   |
+LL |     fn test() -> impl Sized + use<> {}
+   |                               ^^^^^
+   |
+   = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
+   = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
+help: modify the `use<..>` bound to capture the same lifetimes that the trait does
+   |
+LL |     fn test() -> impl Sized + use<'a> {}
+   |                               ~~~~~~~
+
+warning: impl trait in impl method captures fewer lifetimes than in trait
+  --> $DIR/refine-captures.rs:27:31
+   |
+LL |     fn test() -> impl Sized + use<'b> {}
+   |                               ^^^^^^^
+   |
+   = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
+   = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
+help: modify the `use<..>` bound to capture the same lifetimes that the trait does
+   |
+LL |     fn test() -> impl Sized + use<'a, 'b> {}
+   |                               ~~~~~~~~~~~
+
+error: `impl Trait` must mention all type parameters in scope in `use<...>`
+  --> $DIR/refine-captures.rs:32:18
+   |
+LL | impl<T> TypeParam<T> for u64 {
+   |      - type parameter is implicitly captured by this `impl Trait`
+LL |     fn test() -> impl Sized + use<> {}
+   |                  ^^^^^^^^^^^^^^^^^^
+   |
+   = note: currently, all type parameters are required to be mentioned in the precise captures list
+
+error: aborting due to 1 previous error; 3 warnings emitted
+
diff --git a/tests/ui/moves/moved-value-on-as-ref-arg.fixed b/tests/ui/moves/moved-value-on-as-ref-arg.fixed
index 292fa98a3f7..97bfe094ce5 100644
--- a/tests/ui/moves/moved-value-on-as-ref-arg.fixed
+++ b/tests/ui/moves/moved-value-on-as-ref-arg.fixed
@@ -18,8 +18,8 @@ impl AsMut<Bar> for Bar {
 
 fn foo<T: AsRef<Bar>>(_: T) {}
 fn qux<T: AsMut<Bar>>(_: T) {}
-fn bat<T: Borrow<T>>(_: T) {}
-fn baz<T: BorrowMut<T>>(_: T) {}
+fn bat<T: Borrow<Bar>>(_: T) {}
+fn baz<T: BorrowMut<Bar>>(_: T) {}
 
 pub fn main() {
     let bar = Bar;
diff --git a/tests/ui/moves/moved-value-on-as-ref-arg.rs b/tests/ui/moves/moved-value-on-as-ref-arg.rs
index 632af9efcda..fed41cf710d 100644
--- a/tests/ui/moves/moved-value-on-as-ref-arg.rs
+++ b/tests/ui/moves/moved-value-on-as-ref-arg.rs
@@ -18,8 +18,8 @@ impl AsMut<Bar> for Bar {
 
 fn foo<T: AsRef<Bar>>(_: T) {}
 fn qux<T: AsMut<Bar>>(_: T) {}
-fn bat<T: Borrow<T>>(_: T) {}
-fn baz<T: BorrowMut<T>>(_: T) {}
+fn bat<T: Borrow<Bar>>(_: T) {}
+fn baz<T: BorrowMut<Bar>>(_: T) {}
 
 pub fn main() {
     let bar = Bar;
diff --git a/tests/ui/moves/region-var-in-moved-ty-issue-133118.rs b/tests/ui/moves/region-var-in-moved-ty-issue-133118.rs
new file mode 100644
index 00000000000..a49370e315d
--- /dev/null
+++ b/tests/ui/moves/region-var-in-moved-ty-issue-133118.rs
@@ -0,0 +1,25 @@
+//! regression test for #133118
+
+pub trait Alpha {
+    fn y(self) -> usize;
+}
+
+pub trait Beta {
+    type Gamma;
+    fn gamma(&self) -> Self::Gamma;
+}
+
+pub fn a<T: Alpha>(_x: T) -> usize {
+    todo!();
+}
+
+pub fn x<B>(beta: &B) -> usize
+where
+    for<'a> &'a B: Beta,
+    for<'a> <&'a B as Beta>::Gamma: Alpha,
+{
+    let g1 = beta.gamma();
+    a(g1) + a(g1) //~ ERROR use of moved value: `g1` [E0382]
+}
+
+pub fn main() {}
diff --git a/tests/ui/moves/region-var-in-moved-ty-issue-133118.stderr b/tests/ui/moves/region-var-in-moved-ty-issue-133118.stderr
new file mode 100644
index 00000000000..691625d042d
--- /dev/null
+++ b/tests/ui/moves/region-var-in-moved-ty-issue-133118.stderr
@@ -0,0 +1,21 @@
+error[E0382]: use of moved value: `g1`
+  --> $DIR/region-var-in-moved-ty-issue-133118.rs:22:15
+   |
+LL |     let g1 = beta.gamma();
+   |         -- move occurs because `g1` has type `<&B as Beta>::Gamma`, which does not implement the `Copy` trait
+LL |     a(g1) + a(g1)
+   |       --      ^^ value used here after move
+   |       |
+   |       value moved here
+   |
+note: consider changing this parameter type in function `a` to borrow instead if owning the value isn't necessary
+  --> $DIR/region-var-in-moved-ty-issue-133118.rs:12:24
+   |
+LL | pub fn a<T: Alpha>(_x: T) -> usize {
+   |        -               ^ this parameter takes ownership of the value
+   |        |
+   |        in this function
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0382`.
diff --git a/tests/ui/parser/suggest-const-for-global-var.stderr b/tests/ui/parser/suggest-const-for-global-var.stderr
index 235e621d882..6ac7fe8f092 100644
--- a/tests/ui/parser/suggest-const-for-global-var.stderr
+++ b/tests/ui/parser/suggest-const-for-global-var.stderr
@@ -2,7 +2,12 @@ error: expected item, found keyword `let`
   --> $DIR/suggest-const-for-global-var.rs:1:1
    |
 LL | let X: i32 = 12;
-   | ^^^ consider using `const` or `static` instead of `let` for global variables
+   | ^^^
+   | |
+   | `let` cannot be used for global variables
+   | help: consider using `static` or `const` instead of `let`
+   |
+   = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/parser/suggest-static-for-global-var-mut.rs b/tests/ui/parser/suggest-static-for-global-var-mut.rs
new file mode 100644
index 00000000000..c63b09bb7a7
--- /dev/null
+++ b/tests/ui/parser/suggest-static-for-global-var-mut.rs
@@ -0,0 +1,5 @@
+let mut _data = vec![1,2,3];
+//~^ ERROR expected item, found keyword `let`
+
+fn main() {
+}
diff --git a/tests/ui/parser/suggest-static-for-global-var-mut.stderr b/tests/ui/parser/suggest-static-for-global-var-mut.stderr
new file mode 100644
index 00000000000..4b00d1a24f3
--- /dev/null
+++ b/tests/ui/parser/suggest-static-for-global-var-mut.stderr
@@ -0,0 +1,11 @@
+error: expected item, found keyword `let`
+  --> $DIR/suggest-static-for-global-var-mut.rs:1:1
+   |
+LL | let mut _data = vec![1,2,3];
+   | ^^^ `let` cannot be used for global variables
+   |
+   = help: consider using `static` and a `Mutex` instead of `let mut`
+   = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/symbol-names/basic.rs b/tests/ui/symbol-names/basic.rs
index dfcac21ccd6..839dda2b3a3 100644
--- a/tests/ui/symbol-names/basic.rs
+++ b/tests/ui/symbol-names/basic.rs
@@ -1,7 +1,7 @@
 //@ build-fail
 //@ revisions: legacy v0
 //@[legacy]compile-flags: -Z unstable-options -C symbol-mangling-version=legacy
-    //@[v0]compile-flags: -C symbol-mangling-version=v0
+//@[v0]compile-flags: -C symbol-mangling-version=v0
 
 #![feature(rustc_attrs)]
 
diff --git a/tests/ui/symbol-names/impl1.rs b/tests/ui/symbol-names/impl1.rs
index fa4be88f68f..9aefca47447 100644
--- a/tests/ui/symbol-names/impl1.rs
+++ b/tests/ui/symbol-names/impl1.rs
@@ -1,7 +1,7 @@
 //@ build-fail
 //@ revisions: legacy v0
 //@[legacy]compile-flags: -Z unstable-options -C symbol-mangling-version=legacy
-    //@[v0]compile-flags: -C symbol-mangling-version=v0
+//@[v0]compile-flags: -C symbol-mangling-version=v0
 //@[legacy]normalize-stderr-test: "h[\w]{16}E?\)" -> "<SYMBOL_HASH>)"
 
 #![feature(auto_traits, rustc_attrs)]
diff --git a/tests/ui/symbol-names/issue-60925.rs b/tests/ui/symbol-names/issue-60925.rs
index 9f1f007a0fa..ca0f21b7a78 100644
--- a/tests/ui/symbol-names/issue-60925.rs
+++ b/tests/ui/symbol-names/issue-60925.rs
@@ -1,7 +1,7 @@
 //@ build-fail
 //@ revisions: legacy v0
 //@[legacy]compile-flags: -Z unstable-options -C symbol-mangling-version=legacy
-    //@[v0]compile-flags: -C symbol-mangling-version=v0
+//@[v0]compile-flags: -C symbol-mangling-version=v0
 
 #![feature(rustc_attrs)]