diff options
Diffstat (limited to 'tests')
13 files changed, 201 insertions, 8 deletions
diff --git a/tests/crashes/140642.rs b/tests/crashes/140642.rs deleted file mode 100644 index ff75a6ec2f2..00000000000 --- a/tests/crashes/140642.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ known-bug: #140642 -#![feature(min_generic_const_args)] - -pub trait Tr<A> { - const SIZE: usize; -} - -fn mk_array(_x: T) -> [(); <T as Tr<bool>>::SIZE] {} diff --git a/tests/rustdoc-ui/doctest/failed-doctest-extra-semicolon-on-item.stderr b/tests/rustdoc-ui/doctest/failed-doctest-extra-semicolon-on-item.stderr new file mode 100644 index 00000000000..113fb7ccb60 --- /dev/null +++ b/tests/rustdoc-ui/doctest/failed-doctest-extra-semicolon-on-item.stderr @@ -0,0 +1,8 @@ +warning: the `main` function of this doctest won't be run as it contains expressions at the top level, meaning that the whole doctest code will be wrapped in a function + --> $DIR/failed-doctest-extra-semicolon-on-item.rs:11:1 + | +11 | /// ```rust + | ^^^^^^^^^^^ + +warning: 1 warning emitted + diff --git a/tests/rustdoc-ui/doctest/main-alongside-stmts.stderr b/tests/rustdoc-ui/doctest/main-alongside-stmts.stderr new file mode 100644 index 00000000000..d90a289ca69 --- /dev/null +++ b/tests/rustdoc-ui/doctest/main-alongside-stmts.stderr @@ -0,0 +1,14 @@ +warning: the `main` function of this doctest won't be run as it contains expressions at the top level, meaning that the whole doctest code will be wrapped in a function + --> $DIR/main-alongside-stmts.rs:17:1 + | +17 | //! ``` + | ^^^^^^^ + +warning: the `main` function of this doctest won't be run as it contains expressions at the top level, meaning that the whole doctest code will be wrapped in a function + --> $DIR/main-alongside-stmts.rs:26:1 + | +26 | //! ``` + | ^^^^^^^ + +warning: 2 warnings emitted + diff --git a/tests/rustdoc-ui/doctest/test-main-alongside-exprs.stderr b/tests/rustdoc-ui/doctest/test-main-alongside-exprs.stderr new file mode 100644 index 00000000000..0dc7c2a2eea --- /dev/null +++ b/tests/rustdoc-ui/doctest/test-main-alongside-exprs.stderr @@ -0,0 +1,8 @@ +warning: the `main` function of this doctest won't be run as it contains expressions at the top level, meaning that the whole doctest code will be wrapped in a function + --> $DIR/test-main-alongside-exprs.rs:15:1 + | +15 | //! ``` + | ^^^^^^^ + +warning: 1 warning emitted + diff --git a/tests/rustdoc-ui/doctest/warn-main-not-called.rs b/tests/rustdoc-ui/doctest/warn-main-not-called.rs new file mode 100644 index 00000000000..25d92e9cee9 --- /dev/null +++ b/tests/rustdoc-ui/doctest/warn-main-not-called.rs @@ -0,0 +1,22 @@ +//@ check-pass +//@ compile-flags:--test --test-args --test-threads=1 +//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR" +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" + +// In case there is a `main` function in the doctest alongside expressions, +// the whole doctest will be wrapped into a function and the `main` function +// won't be called. + +//! ``` +//! macro_rules! bla { +//! ($($x:tt)*) => {} +//! } +//! +//! let x = 12; +//! bla!(fn main ()); +//! ``` +//! +//! ``` +//! let x = 12; +//! fn main() {} +//! ``` diff --git a/tests/rustdoc-ui/doctest/warn-main-not-called.stderr b/tests/rustdoc-ui/doctest/warn-main-not-called.stderr new file mode 100644 index 00000000000..3a079f47555 --- /dev/null +++ b/tests/rustdoc-ui/doctest/warn-main-not-called.stderr @@ -0,0 +1,14 @@ +warning: the `main` function of this doctest won't be run as it contains expressions at the top level, meaning that the whole doctest code will be wrapped in a function + --> $DIR/warn-main-not-called.rs:10:1 + | +10 | //! ``` + | ^^^^^^^ + +warning: the `main` function of this doctest won't be run as it contains expressions at the top level, meaning that the whole doctest code will be wrapped in a function + --> $DIR/warn-main-not-called.rs:19:1 + | +19 | //! ``` + | ^^^^^^^ + +warning: 2 warnings emitted + diff --git a/tests/rustdoc-ui/doctest/warn-main-not-called.stdout b/tests/rustdoc-ui/doctest/warn-main-not-called.stdout new file mode 100644 index 00000000000..07cdddc7b94 --- /dev/null +++ b/tests/rustdoc-ui/doctest/warn-main-not-called.stdout @@ -0,0 +1,7 @@ + +running 2 tests +test $DIR/warn-main-not-called.rs - (line 10) ... ok +test $DIR/warn-main-not-called.rs - (line 19) ... ok + +test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/ui/async-await/async-closures/async-fn-mut-impl-fn-once.rs b/tests/ui/async-await/async-closures/async-fn-mut-impl-fn-once.rs new file mode 100644 index 00000000000..59d034953d7 --- /dev/null +++ b/tests/ui/async-await/async-closures/async-fn-mut-impl-fn-once.rs @@ -0,0 +1,15 @@ +//@ edition:2021 +//@ check-pass +//@ revisions: current next +//@ ignore-compare-mode-next-solver (explicit revisions) +//@[next] compile-flags: -Znext-solver + +fn call_once<F>(_: impl FnOnce() -> F) {} + +fn main() { + let mut i = 0; + let c = async || { + i += 1; + }; + call_once(c); +} diff --git a/tests/ui/const-generics/mgca/projection-error.rs b/tests/ui/const-generics/mgca/projection-error.rs new file mode 100644 index 00000000000..d1c4fa8a492 --- /dev/null +++ b/tests/ui/const-generics/mgca/projection-error.rs @@ -0,0 +1,17 @@ +#![feature(min_generic_const_args)] +#![expect(incomplete_features)] + +// Regression test for #140642. Test that normalizing const aliases +// containing erroneous types normalizes to a const error instead of +// a type error. + + +pub trait Tr<A> { + const SIZE: usize; +} + +fn mk_array(_x: T) -> [(); <T as Tr<bool>>::SIZE] {} +//~^ ERROR: cannot find type `T` in this scope +//~| ERROR: cannot find type `T` in this scope + +fn main() {} diff --git a/tests/ui/const-generics/mgca/projection-error.stderr b/tests/ui/const-generics/mgca/projection-error.stderr new file mode 100644 index 00000000000..e6888351da1 --- /dev/null +++ b/tests/ui/const-generics/mgca/projection-error.stderr @@ -0,0 +1,39 @@ +error[E0412]: cannot find type `T` in this scope + --> $DIR/projection-error.rs:13:17 + | +LL | pub trait Tr<A> { + | --------------- similarly named trait `Tr` defined here +... +LL | fn mk_array(_x: T) -> [(); <T as Tr<bool>>::SIZE] {} + | ^ + | +help: a trait with a similar name exists + | +LL | fn mk_array(_x: Tr) -> [(); <T as Tr<bool>>::SIZE] {} + | + +help: you might be missing a type parameter + | +LL | fn mk_array<T>(_x: T) -> [(); <T as Tr<bool>>::SIZE] {} + | +++ + +error[E0412]: cannot find type `T` in this scope + --> $DIR/projection-error.rs:13:29 + | +LL | pub trait Tr<A> { + | --------------- similarly named trait `Tr` defined here +... +LL | fn mk_array(_x: T) -> [(); <T as Tr<bool>>::SIZE] {} + | ^ + | +help: a trait with a similar name exists + | +LL | fn mk_array(_x: T) -> [(); <Tr as Tr<bool>>::SIZE] {} + | + +help: you might be missing a type parameter + | +LL | fn mk_array<T>(_x: T) -> [(); <T as Tr<bool>>::SIZE] {} + | +++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/mismatched_types/hr-projection-mismatch.current.stderr b/tests/ui/mismatched_types/hr-projection-mismatch.current.stderr new file mode 100644 index 00000000000..a2cec972e4a --- /dev/null +++ b/tests/ui/mismatched_types/hr-projection-mismatch.current.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/hr-projection-mismatch.rs:20:5 + | +LL | wrap::<_, Thing>(); + | ^^^^^^^^^^^^^^^^ one type is more general than the other + | + = note: expected reference `&'a _` + found reference `&_` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/mismatched_types/hr-projection-mismatch.next.stderr b/tests/ui/mismatched_types/hr-projection-mismatch.next.stderr new file mode 100644 index 00000000000..6ea0d43e153 --- /dev/null +++ b/tests/ui/mismatched_types/hr-projection-mismatch.next.stderr @@ -0,0 +1,20 @@ +error[E0271]: type mismatch resolving `<Thing as Trait<'a>>::Assoc == &i32` + --> $DIR/hr-projection-mismatch.rs:20:15 + | +LL | wrap::<_, Thing>(); + | ^^^^^ type mismatch resolving `<Thing as Trait<'a>>::Assoc == &i32` + | +note: types differ + --> $DIR/hr-projection-mismatch.rs:14:18 + | +LL | type Assoc = &'a i32; + | ^^^^^^^ +note: required by a bound in `wrap` + --> $DIR/hr-projection-mismatch.rs:17:33 + | +LL | fn wrap<T, U: for<'a> Trait<'a, Assoc = T>>() {} + | ^^^^^^^^^ required by this bound in `wrap` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0271`. diff --git a/tests/ui/mismatched_types/hr-projection-mismatch.rs b/tests/ui/mismatched_types/hr-projection-mismatch.rs new file mode 100644 index 00000000000..f96314a3fca --- /dev/null +++ b/tests/ui/mismatched_types/hr-projection-mismatch.rs @@ -0,0 +1,25 @@ +//@ revisions: current next +//@ ignore-compare-mode-next-solver (explicit revisions) +//@[next] compile-flags: -Znext-solver + +// Regression test for <https://github.com/rust-lang/rust/issues/141322>. + +trait Trait<'a> { + type Assoc; +} + +struct Thing; + +impl<'a> Trait<'a> for Thing { + type Assoc = &'a i32; +} + +fn wrap<T, U: for<'a> Trait<'a, Assoc = T>>() {} + +fn foo() { + wrap::<_, Thing>(); + //[next]~^ ERROR type mismatch resolving `<Thing as Trait<'a>>::Assoc == &i32 + //[current]~^^ ERROR mismatched types +} + +fn main() {} |
