diff options
Diffstat (limited to 'tests')
42 files changed, 806 insertions, 27 deletions
diff --git a/tests/rustdoc-gui/search-result-display.goml b/tests/rustdoc-gui/search-result-display.goml index afb3a44be30..6593c1a9c45 100644 --- a/tests/rustdoc-gui/search-result-display.goml +++ b/tests/rustdoc-gui/search-result-display.goml @@ -14,7 +14,8 @@ set-window-size: (600, 100) assert-size: (".search-results div.desc", {"width": 566}) // The result set is all on one line. -assert-css: (".search-results .result-name > span", {"display": "inline"}) +assert-css: (".search-results .result-name > span:not(.typename)", {"display": "inline"}) +assert-css: (".search-results .result-name > span.typename", {"display": "inline-block"}) // Check that the crate filter `<select>` is correctly handled when it goes to next line. // To do so we need to update the length of one of its `<option>`. diff --git a/tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html b/tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html new file mode 100644 index 00000000000..29c08c5bd5d --- /dev/null +++ b/tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html @@ -0,0 +1,2 @@ +<pre class="rust item-decl"><code>pub fn create( +) -> <a class="struct" href="struct.Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000.html" title="struct decl_line_wrapping_empty_arg_list::Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000">Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000</a></code></pre> \ No newline at end of file diff --git a/tests/rustdoc/decl-line-wrapping-empty-arg-list.rs b/tests/rustdoc/decl-line-wrapping-empty-arg-list.rs new file mode 100644 index 00000000000..4cfb87496b4 --- /dev/null +++ b/tests/rustdoc/decl-line-wrapping-empty-arg-list.rs @@ -0,0 +1,12 @@ +// Ensure that we don't add an extra line containing nothing but whitespace in between the two +// parentheses of an empty argument list when line-wrapping a function declaration. + +// ignore-tidy-linelength + +pub struct Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000; + +// @has 'decl_line_wrapping_empty_arg_list/fn.create.html' +// @snapshot decl - '//pre[@class="rust item-decl"]' +pub fn create() -> Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000 { + loop {} +} diff --git a/tests/rustdoc/inline_cross/assoc-const-equality.rs b/tests/rustdoc/inline_cross/assoc-const-equality.rs new file mode 100644 index 00000000000..1d3ce9e3172 --- /dev/null +++ b/tests/rustdoc/inline_cross/assoc-const-equality.rs @@ -0,0 +1,8 @@ +// aux-crate:assoc_const_equality=assoc-const-equality.rs +// edition:2021 + +#![crate_name = "user"] + +// @has user/fn.accept.html +// @has - '//pre[@class="rust item-decl"]' 'fn accept(_: impl Trait<K = 0>)' +pub use assoc_const_equality::accept; diff --git a/tests/rustdoc/inline_cross/assoc_item_trait_bounds.rs b/tests/rustdoc/inline_cross/assoc_item_trait_bounds.rs index db2491b87b4..74ceb697af6 100644 --- a/tests/rustdoc/inline_cross/assoc_item_trait_bounds.rs +++ b/tests/rustdoc/inline_cross/assoc_item_trait_bounds.rs @@ -42,3 +42,15 @@ pub use aux::Main; // @has main/trait.Aid.html // @has - '//*[@id="associatedtype.Result"]' "type Result<'inter: 'src>" pub use aux::Aid; + +// Below, ensure that we correctly display generic parameters and where-clauses on +// associated types inside trait *impls*. More particularly, check that we don't render +// any bounds (here `Self::Alias<T>: ...`) as item bounds unlike all the trait test cases above. + +// @has main/struct.Implementor.html +// @has - '//*[@id="associatedtype.Alias"]' \ +// "type Alias<T: Eq> = T \ +// where \ +// String: From<T>, \ +// <Implementor as Implementee>::Alias<T>: From<<Implementor as Implementee>::Alias<T>>" +pub use aux::Implementor; diff --git a/tests/rustdoc/inline_cross/auxiliary/assoc-const-equality.rs b/tests/rustdoc/inline_cross/auxiliary/assoc-const-equality.rs new file mode 100644 index 00000000000..6a25dcea62e --- /dev/null +++ b/tests/rustdoc/inline_cross/auxiliary/assoc-const-equality.rs @@ -0,0 +1,7 @@ +#![feature(associated_const_equality)] + +pub fn accept(_: impl Trait<K = 0>) {} + +pub trait Trait { + const K: i32; +} diff --git a/tests/rustdoc/inline_cross/auxiliary/assoc_item_trait_bounds.rs b/tests/rustdoc/inline_cross/auxiliary/assoc_item_trait_bounds.rs index 6644c8e4147..551e97a2fa9 100644 --- a/tests/rustdoc/inline_cross/auxiliary/assoc_item_trait_bounds.rs +++ b/tests/rustdoc/inline_cross/auxiliary/assoc_item_trait_bounds.rs @@ -44,3 +44,20 @@ pub trait Helper { pub trait Aid<'src> { type Result<'inter: 'src>; } + +pub trait Implementee { + type Alias<T: Eq> + where + String: From<T>; +} + +pub struct Implementor; + +impl Implementee for Implementor { + type Alias<T: Eq> = T + where + String: From<T>, + // We will check that this bound doesn't get turned into an item bound since + // associated types in impls are not allowed to have any. + Self::Alias<T>: From<Self::Alias<T>>; +} diff --git a/tests/ui/associated-consts/issue-110933.rs b/tests/ui/associated-consts/issue-110933.rs new file mode 100644 index 00000000000..aa4882ae535 --- /dev/null +++ b/tests/ui/associated-consts/issue-110933.rs @@ -0,0 +1,20 @@ +// check-pass + +#![feature(associated_const_equality)] + +pub trait Trait { + const ASSOC: usize; +} + +pub fn foo< + T: Trait< + ASSOC = { + let a = 10_usize; + let b: &'_ usize = &a; + *b + }, + >, +>() { +} + +fn main() {} diff --git a/tests/ui/associated-inherent-types/issue-109071.no_gate.stderr b/tests/ui/associated-inherent-types/issue-109071.no_gate.stderr new file mode 100644 index 00000000000..8b6a8206569 --- /dev/null +++ b/tests/ui/associated-inherent-types/issue-109071.no_gate.stderr @@ -0,0 +1,35 @@ +error[E0637]: `&` without an explicit lifetime name cannot be used here + --> $DIR/issue-109071.rs:8:17 + | +LL | type Item = &[T]; + | ^ explicit lifetime name needed here + +error[E0107]: missing generics for struct `Windows` + --> $DIR/issue-109071.rs:7:9 + | +LL | impl<T> Windows { + | ^^^^^^^ expected 1 generic argument + | +note: struct defined here, with 1 generic parameter: `T` + --> $DIR/issue-109071.rs:5:8 + | +LL | struct Windows<T> {} + | ^^^^^^^ - +help: add missing generic argument + | +LL | impl<T> Windows<T> { + | +++ + +error[E0658]: inherent associated types are unstable + --> $DIR/issue-109071.rs:8:5 + | +LL | type Item = &[T]; + | ^^^^^^^^^^^^^^^^^ + | + = note: see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information + = help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0107, E0637, E0658. +For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/associated-inherent-types/issue-109071.rs b/tests/ui/associated-inherent-types/issue-109071.rs new file mode 100644 index 00000000000..73b969d5940 --- /dev/null +++ b/tests/ui/associated-inherent-types/issue-109071.rs @@ -0,0 +1,18 @@ +// revisions: with_gate no_gate +#![cfg_attr(with_gate, feature(inherent_associated_types))] +#![cfg_attr(with_gate, allow(incomplete_features))] + +struct Windows<T> {} + +impl<T> Windows { //~ ERROR: missing generics for struct `Windows` + type Item = &[T]; //~ ERROR: `&` without an explicit lifetime name cannot be used here + //[no_gate]~^ ERROR: inherent associated types are unstable + + fn next() -> Option<Self::Item> {} +} + +impl<T> Windows<T> { + fn T() -> Option<Self::Item> {} +} + +fn main() {} diff --git a/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr b/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr new file mode 100644 index 00000000000..a91bb7a5162 --- /dev/null +++ b/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr @@ -0,0 +1,26 @@ +error[E0637]: `&` without an explicit lifetime name cannot be used here + --> $DIR/issue-109071.rs:8:17 + | +LL | type Item = &[T]; + | ^ explicit lifetime name needed here + +error[E0107]: missing generics for struct `Windows` + --> $DIR/issue-109071.rs:7:9 + | +LL | impl<T> Windows { + | ^^^^^^^ expected 1 generic argument + | +note: struct defined here, with 1 generic parameter: `T` + --> $DIR/issue-109071.rs:5:8 + | +LL | struct Windows<T> {} + | ^^^^^^^ - +help: add missing generic argument + | +LL | impl<T> Windows<T> { + | +++ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0107, E0637. +For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/cfg/diagnostics-reexport.rs b/tests/ui/cfg/diagnostics-reexport.rs index 1d43d6ba02f..b9548e91183 100644 --- a/tests/ui/cfg/diagnostics-reexport.rs +++ b/tests/ui/cfg/diagnostics-reexport.rs @@ -9,6 +9,30 @@ pub mod inner { //~^ NOTE found an item that was configured out } +pub use a::x; +//~^ ERROR unresolved import `a::x` +//~| NOTE no `x` in `a` + +mod a { + #[cfg(no)] + pub fn x() {} + //~^ NOTE found an item that was configured out +} + +pub use b::{x, y}; +//~^ ERROR unresolved imports `b::x`, `b::y` +//~| NOTE no `x` in `b` +//~| NOTE no `y` in `b` + +mod b { + #[cfg(no)] + pub fn x() {} + //~^ NOTE found an item that was configured out + #[cfg(no)] + pub fn y() {} + //~^ NOTE found an item that was configured out +} + fn main() { // There is no uwu at this path - no diagnostic. inner::uwu(); //~ ERROR cannot find function diff --git a/tests/ui/cfg/diagnostics-reexport.stderr b/tests/ui/cfg/diagnostics-reexport.stderr index 6c977cbfa41..e25b7cf86e2 100644 --- a/tests/ui/cfg/diagnostics-reexport.stderr +++ b/tests/ui/cfg/diagnostics-reexport.stderr @@ -1,5 +1,36 @@ +error[E0432]: unresolved import `a::x` + --> $DIR/diagnostics-reexport.rs:12:9 + | +LL | pub use a::x; + | ^^^^ no `x` in `a` + | +note: found an item that was configured out + --> $DIR/diagnostics-reexport.rs:18:12 + | +LL | pub fn x() {} + | ^ + +error[E0432]: unresolved imports `b::x`, `b::y` + --> $DIR/diagnostics-reexport.rs:22:13 + | +LL | pub use b::{x, y}; + | ^ ^ no `y` in `b` + | | + | no `x` in `b` + | +note: found an item that was configured out + --> $DIR/diagnostics-reexport.rs:29:12 + | +LL | pub fn x() {} + | ^ +note: found an item that was configured out + --> $DIR/diagnostics-reexport.rs:32:12 + | +LL | pub fn y() {} + | ^ + error[E0425]: cannot find function `uwu` in module `inner` - --> $DIR/diagnostics-reexport.rs:14:12 + --> $DIR/diagnostics-reexport.rs:38:12 | LL | inner::uwu(); | ^^^ not found in `inner` @@ -10,6 +41,7 @@ note: found an item that was configured out LL | pub use super::uwu; | ^^^ -error: aborting due to previous error +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0425`. +Some errors have detailed explanations: E0425, E0432. +For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/const-generics/generic_const_exprs/issue-109141.rs b/tests/ui/const-generics/generic_const_exprs/issue-109141.rs new file mode 100644 index 00000000000..148c3bda8d2 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/issue-109141.rs @@ -0,0 +1,13 @@ +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +impl EntriesBuffer { + fn a(&self) -> impl Iterator { + self.0.iter_mut() //~ ERROR: cannot borrow `*self.0` as mutable, as it is behind a `&` reference + } +} + +struct EntriesBuffer(Box<[[u8; HashesEntryLEN]; 5]>); +//~^ ERROR: cannot find value `HashesEntryLEN` in this scope + +fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/issue-109141.stderr b/tests/ui/const-generics/generic_const_exprs/issue-109141.stderr new file mode 100644 index 00000000000..f61edd60e3b --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/issue-109141.stderr @@ -0,0 +1,26 @@ +error[E0425]: cannot find value `HashesEntryLEN` in this scope + --> $DIR/issue-109141.rs:10:32 + | +LL | struct EntriesBuffer(Box<[[u8; HashesEntryLEN]; 5]>); + | ^^^^^^^^^^^^^^ not found in this scope + | +help: you might be missing a const parameter + | +LL | struct EntriesBuffer<const HashesEntryLEN: /* Type */>(Box<[[u8; HashesEntryLEN]; 5]>); + | ++++++++++++++++++++++++++++++++++ + +error[E0596]: cannot borrow `*self.0` as mutable, as it is behind a `&` reference + --> $DIR/issue-109141.rs:6:9 + | +LL | self.0.iter_mut() + | ^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn a(&mut self) -> impl Iterator { + | ~~~~~~~~~ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0425, E0596. +For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/const-generics/generic_const_exprs/issue-96699.rs b/tests/ui/const-generics/generic_const_exprs/issue-96699.rs new file mode 100644 index 00000000000..83f329d2a2d --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/issue-96699.rs @@ -0,0 +1,87 @@ +// check-pass + +#![allow(dead_code, incomplete_features)] +#![feature(generic_const_exprs)] + +const fn min(a: usize, b: usize) -> usize { + if a < b { + a + } else { + b + } +} + +trait Trait1<Inner1> +where + Self: Sized, +{ + fn crash_here() + where + Inner1: Default, + { + Inner1::default(); + } +} + +struct Struct1<T>(T); +impl<T> Trait1<T> for Struct1<T> {} + +trait Trait2<Inner2> +where + Self: Sized, +{ + type Assoc: Trait1<Inner2>; + + fn call_crash() + where + Inner2: Default, + { + // if Inner2 implements Default, we can call crash_here. + Self::Assoc::crash_here(); + } +} + +struct Struct2<const SIZE1: usize, const SIZE2: usize> {} +/* +where + [(); min(SIZE1, SIZE2)]:, +{ + elem: [i32; min(SIZE1, SIZE2)], +} +*/ + +impl<const SIZE1: usize, const SIZE2: usize> Trait2<[i32; min(SIZE1, SIZE2)]> + for Struct2<SIZE1, SIZE2> +{ + type Assoc = Struct1<[i32; min(SIZE1, SIZE2)]>; + // dose Struct1<[i32; min(SIZE1, SIZE2)]> implement Default? +} + +fn main() { + pattern2(); + + print_fully_name(<Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::Assoc::crash_here); + // <compiler_bug2::Struct1<[i32; 1]> as compiler_bug2::Trait1<[i32; 1]>>::crash_here +} + +fn pattern1() { + // no crash + <Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::Assoc::crash_here(); + <Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::call_crash(); +} + +fn pattern2() { + // crash + <Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::call_crash(); + + // undefined reference to `compiler_bug2::Trait1::crash_here' +} + +fn pattern3() { + // no crash + <Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::Assoc::crash_here(); +} + +fn print_fully_name<T>(_: T) { + let _ = std::any::type_name::<T>(); +} diff --git a/tests/ui/explicit-tail-calls/become-outside.array.stderr b/tests/ui/explicit-tail-calls/become-outside.array.stderr new file mode 100644 index 00000000000..839c20509fe --- /dev/null +++ b/tests/ui/explicit-tail-calls/become-outside.array.stderr @@ -0,0 +1,9 @@ +error[E0572]: become statement outside of function body + --> $DIR/become-outside.rs:11:17 + | +LL | struct Bad([(); become f()]); + | ^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0572`. diff --git a/tests/ui/explicit-tail-calls/become-outside.constant.stderr b/tests/ui/explicit-tail-calls/become-outside.constant.stderr new file mode 100644 index 00000000000..9b67f08af3a --- /dev/null +++ b/tests/ui/explicit-tail-calls/become-outside.constant.stderr @@ -0,0 +1,9 @@ +error[E0572]: become statement outside of function body + --> $DIR/become-outside.rs:7:5 + | +LL | become f(); + | ^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0572`. diff --git a/tests/ui/explicit-tail-calls/become-outside.rs b/tests/ui/explicit-tail-calls/become-outside.rs new file mode 100644 index 00000000000..51b4389c88f --- /dev/null +++ b/tests/ui/explicit-tail-calls/become-outside.rs @@ -0,0 +1,15 @@ +// revisions: constant array +#![allow(incomplete_features)] +#![feature(explicit_tail_calls)] + +#[cfg(constant)] +const _: () = { + become f(); //[constant]~ error: become statement outside of function body +}; + +#[cfg(array)] +struct Bad([(); become f()]); //[array]~ error: become statement outside of function body + +fn f() {} + +fn main() {} diff --git a/tests/ui/explicit-tail-calls/return-lifetime-sub.rs b/tests/ui/explicit-tail-calls/return-lifetime-sub.rs new file mode 100644 index 00000000000..8a3f43d4b92 --- /dev/null +++ b/tests/ui/explicit-tail-calls/return-lifetime-sub.rs @@ -0,0 +1,13 @@ +// check-pass +#![allow(incomplete_features)] +#![feature(explicit_tail_calls)] + +fn _f<'a>() -> &'a [u8] { + become _g(); +} + +fn _g() -> &'static [u8] { + &[0, 1, 2, 3] +} + +fn main() {} diff --git a/tests/ui/explicit-tail-calls/return-mismatches.rs b/tests/ui/explicit-tail-calls/return-mismatches.rs new file mode 100644 index 00000000000..935a1a1d28b --- /dev/null +++ b/tests/ui/explicit-tail-calls/return-mismatches.rs @@ -0,0 +1,28 @@ +#![allow(incomplete_features)] +#![feature(explicit_tail_calls)] + +fn _f0<'a>() -> &'static [u8] { + become _g0(); //~ error: mismatched types +} + +fn _g0() -> &'static [u8; 1] { + &[0] +} + +fn _f1() { + become _g1(); //~ error: mismatched types +} + +fn _g1() -> ! { + become _g1(); +} + +fn _f2() -> u32 { + become _g2(); //~ error: mismatched types +} + +fn _g2() -> u16 { + 0 +} + +fn main() {} diff --git a/tests/ui/explicit-tail-calls/return-mismatches.stderr b/tests/ui/explicit-tail-calls/return-mismatches.stderr new file mode 100644 index 00000000000..1dcc35797c1 --- /dev/null +++ b/tests/ui/explicit-tail-calls/return-mismatches.stderr @@ -0,0 +1,27 @@ +error[E0308]: mismatched types + --> $DIR/return-mismatches.rs:5:5 + | +LL | become _g0(); + | ^^^^^^^^^^^^ expected `&[u8]`, found `&[u8; 1]` + | + = note: expected reference `&'static [u8]` + found reference `&'static [u8; 1]` + +error[E0308]: mismatched types + --> $DIR/return-mismatches.rs:13:5 + | +LL | become _g1(); + | ^^^^^^^^^^^^ expected `()`, found `!` + | + = note: expected unit type `()` + found type `!` + +error[E0308]: mismatched types + --> $DIR/return-mismatches.rs:21:5 + | +LL | become _g2(); + | ^^^^^^^^^^^^ expected `u32`, found `u16` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/higher-ranked/trait-bounds/future.classic.stderr b/tests/ui/higher-ranked/trait-bounds/future.classic.stderr new file mode 100644 index 00000000000..33c0f7173a1 --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/future.classic.stderr @@ -0,0 +1,6 @@ +error: the compiler unexpectedly panicked. this is a bug. + +query stack during panic: +#0 [evaluate_obligation] evaluating trait selection obligation `for<'a> [async fn body@$DIR/future.rs:32:35: 34:2]: core::future::future::Future` +#1 [codegen_select_candidate] computing candidate for `<strlen as Trait>` +end of query stack diff --git a/tests/ui/higher-ranked/trait-bounds/future.rs b/tests/ui/higher-ranked/trait-bounds/future.rs new file mode 100644 index 00000000000..da7ee034329 --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/future.rs @@ -0,0 +1,38 @@ +// ignore-tidy-linelength +// edition:2021 +// revisions: classic next +//[next] compile-flags: -Ztrait-solver=next +//[next] check-pass +//[classic] known-bug: #112347 +//[classic] build-fail +//[classic] failure-status: 101 +//[classic] normalize-stderr-test "note: .*\n\n" -> "" +//[classic] normalize-stderr-test "thread 'rustc' panicked.*\n" -> "" +//[classic] normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: " +//[classic] rustc-env:RUST_BACKTRACE=0 + +#![feature(unboxed_closures)] + +use std::future::Future; + +trait Trait { + fn func(&self, _: &str); +} + +impl<T> Trait for T +where + for<'a> T: Fn<(&'a str,)> + Send + Sync, + for<'a> <T as FnOnce<(&'a str,)>>::Output: Future<Output = usize> + Send, +{ + fn func(&self, _: &str) { + println!("hello!"); + } +} + +async fn strlen(x: &str) -> usize { + x.len() +} + +fn main() { + strlen.func("hi"); +} diff --git a/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs b/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs new file mode 100644 index 00000000000..98dbaf036be --- /dev/null +++ b/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs @@ -0,0 +1,12 @@ +// check-pass + +#![allow(incomplete_features)] +#![feature(adt_const_params, return_position_impl_trait_in_trait)] + +pub struct Element; + +pub trait Node { + fn elements<const T: &'static str>(&self) -> impl Iterator<Item = Element>; +} + +fn main() {} diff --git a/tests/ui/issues/issue-51714.rs b/tests/ui/issues/issue-51714.rs index 8716524d6f4..03b50b7963e 100644 --- a/tests/ui/issues/issue-51714.rs +++ b/tests/ui/issues/issue-51714.rs @@ -1,9 +1,9 @@ fn main() { -//~^ NOTE: not the enclosing function body -//~| NOTE: not the enclosing function body -//~| NOTE: not the enclosing function body -//~| NOTE: not the enclosing function body - |_: [_; return || {}] | {}; + //~^ NOTE: not the enclosing function body + //~| NOTE: not the enclosing function body + //~| NOTE: not the enclosing function body + //~| NOTE: not the enclosing function body + |_: [_; return || {}]| {}; //~^ ERROR: return statement outside of function body [E0572] //~| NOTE: the return is part of this body... diff --git a/tests/ui/issues/issue-51714.stderr b/tests/ui/issues/issue-51714.stderr index 514d69c1c7d..e53e10afcaf 100644 --- a/tests/ui/issues/issue-51714.stderr +++ b/tests/ui/issues/issue-51714.stderr @@ -1,13 +1,13 @@ error[E0572]: return statement outside of function body - --> $DIR/issue-51714.rs:6:14 + --> $DIR/issue-51714.rs:6:13 | LL | / fn main() { LL | | LL | | LL | | LL | | -LL | | |_: [_; return || {}] | {}; - | | ^^^^^^^^^^^^ the return is part of this body... +LL | | |_: [_; return || {}]| {}; + | | ^^^^^^^^^^^^ the return is part of this body... ... | LL | | LL | | } diff --git a/tests/ui/pattern/byte-string-inference.rs b/tests/ui/pattern/byte-string-inference.rs new file mode 100644 index 00000000000..b1517de6b67 --- /dev/null +++ b/tests/ui/pattern/byte-string-inference.rs @@ -0,0 +1,15 @@ +// check-pass + +fn load<L>() -> Option<L> { + todo!() +} + +fn main() { + while let Some(tag) = load() { + match &tag { + b"NAME" => {} + b"DATA" => {} + _ => {} + } + } +} diff --git a/tests/ui/return/issue-64620.rs b/tests/ui/return/issue-64620.rs index a62e5bf8d3c..ab293165195 100644 --- a/tests/ui/return/issue-64620.rs +++ b/tests/ui/return/issue-64620.rs @@ -1,5 +1,5 @@ enum Bug { - V1 = return [0][0] //~ERROR return statement outside of function body + V1 = return [0][0], //~ERROR return statement outside of function body } fn main() {} diff --git a/tests/ui/return/issue-64620.stderr b/tests/ui/return/issue-64620.stderr index f40ac4de32d..3210a67d418 100644 --- a/tests/ui/return/issue-64620.stderr +++ b/tests/ui/return/issue-64620.stderr @@ -1,7 +1,7 @@ error[E0572]: return statement outside of function body --> $DIR/issue-64620.rs:2:10 | -LL | V1 = return [0][0] +LL | V1 = return [0][0], | ^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/return/issue-86188-return-not-in-fn-body.rs b/tests/ui/return/issue-86188-return-not-in-fn-body.rs index 4f076fa0693..3117cf3fd91 100644 --- a/tests/ui/return/issue-86188-return-not-in-fn-body.rs +++ b/tests/ui/return/issue-86188-return-not-in-fn-body.rs @@ -7,7 +7,7 @@ const C: [(); 42] = { [(); return || { - //~^ ERROR: return statement outside of function body [E0572] + //~^ ERROR: return statement outside of function body [E0572] let tx; }] }; @@ -16,7 +16,7 @@ struct S {} trait Tr { fn foo(); fn bar() { - //~^ NOTE: ...not the enclosing function body + //~^ NOTE: ...not the enclosing function body [(); return]; //~^ ERROR: return statement outside of function body [E0572] //~| NOTE: the return is part of this body... @@ -24,7 +24,7 @@ trait Tr { } impl Tr for S { fn foo() { - //~^ NOTE: ...not the enclosing function body + //~^ NOTE: ...not the enclosing function body [(); return]; //~^ ERROR: return statement outside of function body [E0572] //~| NOTE: the return is part of this body... @@ -32,10 +32,10 @@ impl Tr for S { } fn main() { -//~^ NOTE: ...not the enclosing function body + //~^ NOTE: ...not the enclosing function body [(); return || { - //~^ ERROR: return statement outside of function body [E0572] - //~| NOTE: the return is part of this body... + //~^ ERROR: return statement outside of function body [E0572] + //~| NOTE: the return is part of this body... let tx; }]; } diff --git a/tests/ui/return/tail-expr-as-potential-return.rs b/tests/ui/return/tail-expr-as-potential-return.rs index f46e088b85f..2046d6680dd 100644 --- a/tests/ui/return/tail-expr-as-potential-return.rs +++ b/tests/ui/return/tail-expr-as-potential-return.rs @@ -1,8 +1,8 @@ -// > Suggest `return`ing tail expressions that match return type +// > Suggest returning tail expressions that match return type // > // > Some newcomers are confused by the behavior of tail expressions, // > interpreting that "leaving out the `;` makes it the return value". -// > To help them go in the right direction, suggest using `return` instead +// > To help them go in the right direction, suggest using return instead // > when applicable. // (original commit description for this test) // diff --git a/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs b/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs index a776e508907..a9d678c1e6a 100644 --- a/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs +++ b/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs @@ -1,4 +1,4 @@ -// compile-flags -Wrust-2021-incompatible-closure-captures +#![warn(rust_2021_incompatible_closure_captures)] fn main() {} @@ -9,7 +9,7 @@ impl Numberer { //~^ ERROR `async fn` is not permitted in Rust 2015 interval: Duration, //~^ ERROR cannot find type `Duration` in this scope - ) -> Numberer { + ) -> Numberer { //~WARN: changes to closure capture in Rust 2021 Numberer {} } } diff --git a/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr b/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr index 60433e1c284..71e9e7602e8 100644 --- a/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr +++ b/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr @@ -18,7 +18,32 @@ help: consider importing this struct LL + use std::time::Duration; | -error: aborting due to 2 previous errors +warning: changes to closure capture in Rust 2021 will affect drop order + --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs:12:19 + | +LL | interval: Duration, + | -------- in Rust 2018, this causes the closure to capture `interval`, but in Rust 2021, it has no effect +LL | +LL | ) -> Numberer { + | _________________-_^ + | | | + | | in Rust 2018, `interval` is dropped here along with the closure, but in Rust 2021 `interval` is not part of the closure +LL | | Numberer {} +LL | | } + | |_____^ + | + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html> +note: the lint level is defined here + --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs:1:9 + | +LL | #![warn(rust_2021_incompatible_closure_captures)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: add a dummy let to cause `interval` to be fully captured + | +LL | ) -> Numberer { let _ = &interval; + | ++++++++++++++++++ + +error: aborting due to 2 previous errors; 1 warning emitted Some errors have detailed explanations: E0412, E0670. For more information about an error, try `rustc --explain E0412`. diff --git a/tests/ui/suggestions/issue-109991.rs b/tests/ui/suggestions/issue-109991.rs new file mode 100644 index 00000000000..918451cb8ee --- /dev/null +++ b/tests/ui/suggestions/issue-109991.rs @@ -0,0 +1,27 @@ +struct S { + a: usize, + b: usize, +} + +fn main() { + let a: usize; + let b: usize; + let c: usize; + + (c) = (&123); //~ ERROR mismatched types + (a, b) = (123, &mut 123); //~ ERROR mismatched types + + let x: String; + (x,) = (1,); //~ ERROR mismatched types + + let x: i32; + [x] = [&1]; //~ ERROR mismatched types + + let x: &i32; + [x] = [1]; //~ ERROR mismatched types + + let x = (1, &mut 2); + (a, b) = x; //~ ERROR mismatched types + + S { a, b } = S { a: 1, b: &mut 2 }; //~ ERROR mismatched types +} diff --git a/tests/ui/suggestions/issue-109991.stderr b/tests/ui/suggestions/issue-109991.stderr new file mode 100644 index 00000000000..bd21e4de648 --- /dev/null +++ b/tests/ui/suggestions/issue-109991.stderr @@ -0,0 +1,72 @@ +error[E0308]: mismatched types + --> $DIR/issue-109991.rs:11:11 + | +LL | let c: usize; + | ----- expected due to this type +LL | +LL | (c) = (&123); + | ^^^^^^ expected `usize`, found `&{integer}` + | +help: consider removing the borrow + | +LL - (c) = (&123); +LL + (c) = (123); + | + +error[E0308]: mismatched types + --> $DIR/issue-109991.rs:12:9 + | +LL | let b: usize; + | ----- expected due to this type +... +LL | (a, b) = (123, &mut 123); + | ^ expected `usize`, found `&mut {integer}` + +error[E0308]: mismatched types + --> $DIR/issue-109991.rs:15:6 + | +LL | let x: String; + | ------ expected due to this type +LL | (x,) = (1,); + | ^ expected `String`, found integer + +error[E0308]: mismatched types + --> $DIR/issue-109991.rs:18:6 + | +LL | let x: i32; + | --- expected due to this type +LL | [x] = [&1]; + | ^ expected `i32`, found `&{integer}` + +error[E0308]: mismatched types + --> $DIR/issue-109991.rs:21:6 + | +LL | let x: &i32; + | ---- expected due to this type +LL | [x] = [1]; + | ^ expected `&i32`, found integer + +error[E0308]: mismatched types + --> $DIR/issue-109991.rs:24:9 + | +LL | let b: usize; + | ----- expected due to this type +... +LL | (a, b) = x; + | ^ expected `usize`, found `&mut {integer}` + +error[E0308]: mismatched types + --> $DIR/issue-109991.rs:26:31 + | +LL | S { a, b } = S { a: 1, b: &mut 2 }; + | ^^^^^^ expected `usize`, found `&mut {integer}` + | +help: consider removing the borrow + | +LL - S { a, b } = S { a: 1, b: &mut 2 }; +LL + S { a, b } = S { a: 1, b: 2 }; + | + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/traits/new-solver/member-constraints-in-root-universe.rs b/tests/ui/traits/new-solver/member-constraints-in-root-universe.rs new file mode 100644 index 00000000000..97c44305864 --- /dev/null +++ b/tests/ui/traits/new-solver/member-constraints-in-root-universe.rs @@ -0,0 +1,17 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +trait Trait { + type Ty; +} + +impl Trait for for<'a> fn(&'a u8, &'a u8) { + type Ty = (); +} + +// argument is necessary to create universes before registering the hidden type. +fn test<'a>(_: <fn(&u8, &u8) as Trait>::Ty) -> impl Sized { + "hidden type is `&'?0 str` with '?0 member of ['static,]" +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/slice-match-byte-lit.rs b/tests/ui/traits/new-solver/slice-match-byte-lit.rs index 4f848062595..5f9c0df6450 100644 --- a/tests/ui/traits/new-solver/slice-match-byte-lit.rs +++ b/tests/ui/traits/new-solver/slice-match-byte-lit.rs @@ -1,5 +1,5 @@ // compile-flags: -Ztrait-solver=next -// check-pass +// known-bug: rust-lang/trait-system-refactor-initiative#38 fn test(s: &[u8]) { match &s[0..3] { diff --git a/tests/ui/traits/new-solver/slice-match-byte-lit.stderr b/tests/ui/traits/new-solver/slice-match-byte-lit.stderr new file mode 100644 index 00000000000..294e8bc94be --- /dev/null +++ b/tests/ui/traits/new-solver/slice-match-byte-lit.stderr @@ -0,0 +1,11 @@ +error[E0271]: type mismatch resolving `[u8; 3] <: <Range<usize> as SliceIndex<[u8]>>::Output` + --> $DIR/slice-match-byte-lit.rs:6:9 + | +LL | match &s[0..3] { + | -------- this expression has type `&<std::ops::Range<usize> as SliceIndex<[u8]>>::Output` +LL | b"uwu" => {} + | ^^^^^^ types differ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0271`. diff --git a/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr b/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr new file mode 100644 index 00000000000..dd2737c706d --- /dev/null +++ b/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr @@ -0,0 +1,55 @@ +error: concrete type differs from previous defining opaque type use + --> $DIR/normalize-hidden-types.rs:25:20 + | +LL | fn define() -> Opaque { + | ^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(<u8 as Trait>::Gat<'a>)` + | +note: previous use here + --> $DIR/normalize-hidden-types.rs:27:9 + | +LL | dyn_hoops::<_>(0) + | ^^^^^^^^^^^^^^^^^ + +error: concrete type differs from previous defining opaque type use + --> $DIR/normalize-hidden-types.rs:34:22 + | +LL | fn define_1() -> Opaque { dyn_hoops::<_>(0) } + | ^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(<u8 as Trait>::Gat<'a>)` + | +note: previous use here + --> $DIR/normalize-hidden-types.rs:34:31 + | +LL | fn define_1() -> Opaque { dyn_hoops::<_>(0) } + | ^^^^^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/normalize-hidden-types.rs:44:25 + | +LL | type Opaque = impl Sized; + | ---------- the expected opaque type +... +LL | let _: Opaque = dyn_hoops::<u8>(0); + | ------ ^^^^^^^^^^^^^^^^^^ expected opaque type, found `*const dyn FnOnce(())` + | | + | expected due to this + | + = note: expected opaque type `typeck::Opaque` + found raw pointer `*const (dyn FnOnce(()) + 'static)` + = help: consider constraining the associated type `<u8 as Trait>::Gat<'_>` to `()` or calling a method that returns `<u8 as Trait>::Gat<'_>` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + +error: concrete type differs from previous defining opaque type use + --> $DIR/normalize-hidden-types.rs:54:25 + | +LL | let _: Opaque = dyn_hoops::<_>(0); + | ^^^^^^^^^^^^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(<u8 as Trait>::Gat<'a>)` + | +note: previous use here + --> $DIR/normalize-hidden-types.rs:56:9 + | +LL | None + | ^^^^ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/normalize-hidden-types.rs b/tests/ui/type-alias-impl-trait/normalize-hidden-types.rs new file mode 100644 index 00000000000..8d80546444a --- /dev/null +++ b/tests/ui/type-alias-impl-trait/normalize-hidden-types.rs @@ -0,0 +1,60 @@ +// Regression test for #112691 +// +// revisions: current next +// [next] compile-flags: -Ztrait-solver=next +// [next] check-pass +// [current]: known-bug: #112691 + +#![feature(type_alias_impl_trait)] + +trait Trait { + type Gat<'lt>; +} + +impl Trait for u8 { + type Gat<'lt> = (); +} + +fn dyn_hoops<T: Trait>(_: T) -> *const dyn FnOnce(T::Gat<'_>) { + loop {} +} + +mod typeof_1 { + use super::*; + type Opaque = impl Sized; + fn define() -> Opaque { + //[current]~^ ERROR concrete type differs + dyn_hoops::<_>(0) + } +} + +mod typeof_2 { + use super::*; + type Opaque = impl Sized; + fn define_1() -> Opaque { dyn_hoops::<_>(0) } + //[current]~^ ERROR concrete type differs + fn define_2() -> Opaque { dyn_hoops::<u8>(0) } +} + +mod typeck { + use super::*; + type Opaque = impl Sized; + fn define() -> Option<Opaque> { + let _: Opaque = dyn_hoops::<_>(0); + let _: Opaque = dyn_hoops::<u8>(0); + //[current]~^ ERROR mismatched types + None + } +} + +mod borrowck { + use super::*; + type Opaque = impl Sized; + fn define() -> Option<Opaque> { + let _: Opaque = dyn_hoops::<_>(0); + //[current]~^ ERROR concrete type differs + None + } +} + +fn main() {} diff --git a/tests/ui/typeck/issue-86721-return-expr-ice.rs b/tests/ui/typeck/issue-86721-return-expr-ice.rs index cd7135f18b1..4f882f7a3f1 100644 --- a/tests/ui/typeck/issue-86721-return-expr-ice.rs +++ b/tests/ui/typeck/issue-86721-return-expr-ice.rs @@ -2,7 +2,7 @@ // revisions: rev1 rev2 #![cfg_attr(any(), rev1, rev2)] -#![crate_type="lib"] +#![crate_type = "lib"] #[cfg(any(rev1))] trait T { |
