From 793607059bcd49cbafc3d75f8438b496cd793970 Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Sun, 8 Jun 2025 19:09:38 +0500 Subject: cleaned up some tests --- tests/ui/defaults-well-formedness.rs | 27 --------- tests/ui/deprecation-in-force-unstable.rs | 5 -- tests/ui/deprecation/deprecated_main_function.rs | 5 ++ tests/ui/deref-rc.rs | 8 --- tests/ui/deref.rs | 6 -- tests/ui/derive-uninhabited-enum-38885.rs | 19 ------- tests/ui/derive-uninhabited-enum-38885.stderr | 15 ----- tests/ui/derives/derive-debug-uninhabited-enum.rs | 23 ++++++++ .../derives/derive-debug-uninhabited-enum.stderr | 15 +++++ tests/ui/destructure-trait-ref.rs | 46 --------------- tests/ui/destructure-trait-ref.stderr | 65 ---------------------- tests/ui/diverging-fallback-method-chain.rs | 20 ------- tests/ui/diverging-fallback-option.rs | 14 ----- .../default-type-params-well-formedness.rs | 50 +++++++++++++++++ tests/ui/never_type/never-type-fallback-option.rs | 22 ++++++++ tests/ui/traits/trait-object-destructure.rs | 29 ++++++++++ tests/ui/traits/trait-object-destructure.stderr | 65 ++++++++++++++++++++++ .../inference-method-chain-diverging-fallback.rs | 19 +++++++ 18 files changed, 228 insertions(+), 225 deletions(-) delete mode 100644 tests/ui/defaults-well-formedness.rs delete mode 100644 tests/ui/deprecation-in-force-unstable.rs create mode 100644 tests/ui/deprecation/deprecated_main_function.rs delete mode 100644 tests/ui/deref-rc.rs delete mode 100644 tests/ui/deref.rs delete mode 100644 tests/ui/derive-uninhabited-enum-38885.rs delete mode 100644 tests/ui/derive-uninhabited-enum-38885.stderr create mode 100644 tests/ui/derives/derive-debug-uninhabited-enum.rs create mode 100644 tests/ui/derives/derive-debug-uninhabited-enum.stderr delete mode 100644 tests/ui/destructure-trait-ref.rs delete mode 100644 tests/ui/destructure-trait-ref.stderr delete mode 100644 tests/ui/diverging-fallback-method-chain.rs delete mode 100644 tests/ui/diverging-fallback-option.rs create mode 100644 tests/ui/generics/default-type-params-well-formedness.rs create mode 100644 tests/ui/never_type/never-type-fallback-option.rs create mode 100644 tests/ui/traits/trait-object-destructure.rs create mode 100644 tests/ui/traits/trait-object-destructure.stderr create mode 100644 tests/ui/typeck/inference-method-chain-diverging-fallback.rs diff --git a/tests/ui/defaults-well-formedness.rs b/tests/ui/defaults-well-formedness.rs deleted file mode 100644 index e5e48edad88..00000000000 --- a/tests/ui/defaults-well-formedness.rs +++ /dev/null @@ -1,27 +0,0 @@ -//@ run-pass - -#![allow(dead_code)] -trait Trait {} -struct Foo(U, V) where U: Trait; - -trait Marker {} -struct TwoParams(T, U); -impl Marker for TwoParams {} - -// Clauses with more than 1 param are not checked. -struct IndividuallyBogus(TwoParams) where TwoParams: Marker; -struct BogusTogether(T, U) where TwoParams: Marker; -// Clauses with non-defaulted params are not checked. -struct NonDefaultedInClause(TwoParams) where TwoParams: Marker; -struct DefaultedLhs(U, V) where V: Trait; -// Dependent defaults are not checked. -struct Dependent(T, U) where U: Copy; -trait SelfBound {} -// Not even for well-formedness. -struct WellFormedProjection::Item>(A, T); - -// Issue #49344, predicates with lifetimes should not be checked. -trait Scope<'a> {} -struct Request<'a, S: Scope<'a> = i32>(S, &'a ()); - -fn main() {} diff --git a/tests/ui/deprecation-in-force-unstable.rs b/tests/ui/deprecation-in-force-unstable.rs deleted file mode 100644 index 6aaf29b069a..00000000000 --- a/tests/ui/deprecation-in-force-unstable.rs +++ /dev/null @@ -1,5 +0,0 @@ -//@ run-pass -//@ compile-flags:-Zforce-unstable-if-unmarked - -#[deprecated] // should work even with -Zforce-unstable-if-unmarked -fn main() { } diff --git a/tests/ui/deprecation/deprecated_main_function.rs b/tests/ui/deprecation/deprecated_main_function.rs new file mode 100644 index 00000000000..398046637d8 --- /dev/null +++ b/tests/ui/deprecation/deprecated_main_function.rs @@ -0,0 +1,5 @@ +//@ run-pass +//@ compile-flags:-Zforce-unstable-if-unmarked + +#[deprecated] // should work even with -Zforce-unstable-if-unmarked +fn main() {} diff --git a/tests/ui/deref-rc.rs b/tests/ui/deref-rc.rs deleted file mode 100644 index 92fdd900359..00000000000 --- a/tests/ui/deref-rc.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ run-pass - -use std::rc::Rc; - -fn main() { - let x = Rc::new([1, 2, 3, 4]); - assert_eq!(*x, [1, 2, 3, 4]); -} diff --git a/tests/ui/deref.rs b/tests/ui/deref.rs deleted file mode 100644 index 0a6f3cc81f6..00000000000 --- a/tests/ui/deref.rs +++ /dev/null @@ -1,6 +0,0 @@ -//@ run-pass - -pub fn main() { - let x: Box = Box::new(10); - let _y: isize = *x; -} diff --git a/tests/ui/derive-uninhabited-enum-38885.rs b/tests/ui/derive-uninhabited-enum-38885.rs deleted file mode 100644 index 2259a542706..00000000000 --- a/tests/ui/derive-uninhabited-enum-38885.rs +++ /dev/null @@ -1,19 +0,0 @@ -//@ check-pass -//@ compile-flags: -Wunused - -// ensure there are no special warnings about uninhabited types -// when deriving Debug on an empty enum - -#[derive(Debug)] -enum Void {} - -#[derive(Debug)] -enum Foo { - Bar(#[allow(dead_code)] u8), - Void(Void), //~ WARN variant `Void` is never constructed -} - -fn main() { - let x = Foo::Bar(42); - println!("{:?}", x); -} diff --git a/tests/ui/derive-uninhabited-enum-38885.stderr b/tests/ui/derive-uninhabited-enum-38885.stderr deleted file mode 100644 index bcd8f6b7b53..00000000000 --- a/tests/ui/derive-uninhabited-enum-38885.stderr +++ /dev/null @@ -1,15 +0,0 @@ -warning: variant `Void` is never constructed - --> $DIR/derive-uninhabited-enum-38885.rs:13:5 - | -LL | enum Foo { - | --- variant in this enum -LL | Bar(#[allow(dead_code)] u8), -LL | Void(Void), - | ^^^^ - | - = note: `Foo` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis - = note: `-W dead-code` implied by `-W unused` - = help: to override `-W unused` add `#[allow(dead_code)]` - -warning: 1 warning emitted - diff --git a/tests/ui/derives/derive-debug-uninhabited-enum.rs b/tests/ui/derives/derive-debug-uninhabited-enum.rs new file mode 100644 index 00000000000..be7b3ab348d --- /dev/null +++ b/tests/ui/derives/derive-debug-uninhabited-enum.rs @@ -0,0 +1,23 @@ +//! Regression test for `#[derive(Debug)]` on enums with uninhabited variants. +//! +//! Ensures there are no special warnings about uninhabited types when deriving +//! Debug on an enum with uninhabited variants, only standard unused warnings. +//! +//! Issue: https://github.com/rust-lang/rust/issues/38885 + +//@ check-pass +//@ compile-flags: -Wunused + +#[derive(Debug)] +enum Void {} + +#[derive(Debug)] +enum Foo { + Bar(#[allow(dead_code)] u8), + Void(Void), //~ WARN variant `Void` is never constructed +} + +fn main() { + let x = Foo::Bar(42); + println!("{:?}", x); +} diff --git a/tests/ui/derives/derive-debug-uninhabited-enum.stderr b/tests/ui/derives/derive-debug-uninhabited-enum.stderr new file mode 100644 index 00000000000..4911b6b6cde --- /dev/null +++ b/tests/ui/derives/derive-debug-uninhabited-enum.stderr @@ -0,0 +1,15 @@ +warning: variant `Void` is never constructed + --> $DIR/derive-debug-uninhabited-enum.rs:17:5 + | +LL | enum Foo { + | --- variant in this enum +LL | Bar(#[allow(dead_code)] u8), +LL | Void(Void), + | ^^^^ + | + = note: `Foo` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis + = note: `-W dead-code` implied by `-W unused` + = help: to override `-W unused` add `#[allow(dead_code)]` + +warning: 1 warning emitted + diff --git a/tests/ui/destructure-trait-ref.rs b/tests/ui/destructure-trait-ref.rs deleted file mode 100644 index daa0ca30d68..00000000000 --- a/tests/ui/destructure-trait-ref.rs +++ /dev/null @@ -1,46 +0,0 @@ -// The regression test for #15031 to make sure destructuring trait -// reference work properly. - -//@ dont-require-annotations: NOTE - -#![feature(box_patterns)] - -trait T { fn foo(&self) {} } -impl T for isize {} - - -fn main() { - // For an expression of the form: - // - // let &...&x = &..&SomeTrait; - // - // Say we have n `&` at the left hand and m `&` right hand, then: - // if n < m, we are golden; - // if n == m, it's a derefing non-derefable type error; - // if n > m, it's a type mismatch error. - - // n < m - let &x = &(&1isize as &dyn T); - let &x = &&(&1isize as &dyn T); - let &&x = &&(&1isize as &dyn T); - - // n == m - let &x = &1isize as &dyn T; //~ ERROR type `&dyn T` cannot be dereferenced - let &&x = &(&1isize as &dyn T); //~ ERROR type `&dyn T` cannot be dereferenced - let box x = Box::new(1isize) as Box; - //~^ ERROR type `Box` cannot be dereferenced - - // n > m - let &&x = &1isize as &dyn T; - //~^ ERROR mismatched types - //~| NOTE expected trait object `dyn T` - //~| NOTE found reference `&_` - let &&&x = &(&1isize as &dyn T); - //~^ ERROR mismatched types - //~| NOTE expected trait object `dyn T` - //~| NOTE found reference `&_` - let box box x = Box::new(1isize) as Box; - //~^ ERROR mismatched types - //~| NOTE expected trait object `dyn T` - //~| NOTE found struct `Box<_>` -} diff --git a/tests/ui/destructure-trait-ref.stderr b/tests/ui/destructure-trait-ref.stderr deleted file mode 100644 index 0b5ea551a57..00000000000 --- a/tests/ui/destructure-trait-ref.stderr +++ /dev/null @@ -1,65 +0,0 @@ -error[E0033]: type `&dyn T` cannot be dereferenced - --> $DIR/destructure-trait-ref.rs:28:9 - | -LL | let &x = &1isize as &dyn T; - | ^^ type `&dyn T` cannot be dereferenced - -error[E0033]: type `&dyn T` cannot be dereferenced - --> $DIR/destructure-trait-ref.rs:29:10 - | -LL | let &&x = &(&1isize as &dyn T); - | ^^ type `&dyn T` cannot be dereferenced - -error[E0033]: type `Box` cannot be dereferenced - --> $DIR/destructure-trait-ref.rs:30:9 - | -LL | let box x = Box::new(1isize) as Box; - | ^^^^^ type `Box` cannot be dereferenced - -error[E0308]: mismatched types - --> $DIR/destructure-trait-ref.rs:34:10 - | -LL | let &&x = &1isize as &dyn T; - | ^^ ----------------- this expression has type `&dyn T` - | | - | expected `dyn T`, found `&_` - | - = note: expected trait object `dyn T` - found reference `&_` -help: consider removing `&` from the pattern - | -LL - let &&x = &1isize as &dyn T; -LL + let &x = &1isize as &dyn T; - | - -error[E0308]: mismatched types - --> $DIR/destructure-trait-ref.rs:38:11 - | -LL | let &&&x = &(&1isize as &dyn T); - | ^^ -------------------- this expression has type `&&dyn T` - | | - | expected `dyn T`, found `&_` - | - = note: expected trait object `dyn T` - found reference `&_` -help: consider removing `&` from the pattern - | -LL - let &&&x = &(&1isize as &dyn T); -LL + let &&x = &(&1isize as &dyn T); - | - -error[E0308]: mismatched types - --> $DIR/destructure-trait-ref.rs:42:13 - | -LL | let box box x = Box::new(1isize) as Box; - | ^^^^^ ------------------------------ this expression has type `Box` - | | - | expected `dyn T`, found `Box<_>` - | - = note: expected trait object `dyn T` - found struct `Box<_>` - -error: aborting due to 6 previous errors - -Some errors have detailed explanations: E0033, E0308. -For more information about an error, try `rustc --explain E0033`. diff --git a/tests/ui/diverging-fallback-method-chain.rs b/tests/ui/diverging-fallback-method-chain.rs deleted file mode 100644 index aa8eba1191b..00000000000 --- a/tests/ui/diverging-fallback-method-chain.rs +++ /dev/null @@ -1,20 +0,0 @@ -//@ run-pass - -#![allow(unused_imports)] -// Test a regression found when building compiler. The `produce()` -// error type `T` winds up getting unified with result of `x.parse()`; -// the type of the closure given to `unwrap_or_else` needs to be -// inferred to `usize`. - -use std::num::ParseIntError; - -fn produce() -> Result<&'static str, T> { - Ok("22") -} - -fn main() { - let x: usize = produce() - .and_then(|x| x.parse()) - .unwrap_or_else(|_| panic!()); - println!("{}", x); -} diff --git a/tests/ui/diverging-fallback-option.rs b/tests/ui/diverging-fallback-option.rs deleted file mode 100644 index aa793ebd017..00000000000 --- a/tests/ui/diverging-fallback-option.rs +++ /dev/null @@ -1,14 +0,0 @@ -//@ run-pass - -#![allow(warnings)] - -// Here the type of `c` is `Option`, where `?T` is unconstrained. -// Because there is data-flow from the `{ return; }` block, which -// diverges and hence has type `!`, into `c`, we will default `?T` to -// `!`, and hence this code compiles rather than failing and requiring -// a type annotation. - -fn main() { - let c = Some({ return; }); - c.unwrap(); -} diff --git a/tests/ui/generics/default-type-params-well-formedness.rs b/tests/ui/generics/default-type-params-well-formedness.rs new file mode 100644 index 00000000000..22b8f5011f7 --- /dev/null +++ b/tests/ui/generics/default-type-params-well-formedness.rs @@ -0,0 +1,50 @@ +//! Test for well-formedness checking of default type parameters. +//! +//! Regression Test for: https://github.com/rust-lang/rust/issues/49344 + +//@ run-pass + +#![allow(dead_code)] + +trait Trait {} +struct Foo(U, V) +where + U: Trait; + +trait Marker {} +struct TwoParams(T, U); +impl Marker for TwoParams {} + +// Clauses with more than 1 param are not checked. +struct IndividuallyBogus(TwoParams) +where + TwoParams: Marker; + +struct BogusTogether(T, U) +where + TwoParams: Marker; + +// Clauses with non-defaulted params are not checked. +struct NonDefaultedInClause(TwoParams) +where + TwoParams: Marker; + +struct DefaultedLhs(U, V) +where + V: Trait; + +// Dependent defaults are not checked. +struct Dependent(T, U) +where + U: Copy; + +trait SelfBound {} + +// Not even for well-formedness. +struct WellFormedProjection::Item>(A, T); + +// Issue #49344, predicates with lifetimes should not be checked. +trait Scope<'a> {} +struct Request<'a, S: Scope<'a> = i32>(S, &'a ()); + +fn main() {} diff --git a/tests/ui/never_type/never-type-fallback-option.rs b/tests/ui/never_type/never-type-fallback-option.rs new file mode 100644 index 00000000000..9c8103aa0a4 --- /dev/null +++ b/tests/ui/never_type/never-type-fallback-option.rs @@ -0,0 +1,22 @@ +//@ run-pass + +#![allow(warnings)] + +//! Tests type inference fallback to `!` (never type) in `Option` context. +//! +//! Regression test for issues: +//! - https://github.com/rust-lang/rust/issues/39808 +//! - https://github.com/rust-lang/rust/issues/39984 +//! +//! Here the type of `c` is `Option`, where `?T` is unconstrained. +//! Because there is data-flow from the `{ return; }` block, which +//! diverges and hence has type `!`, into `c`, we will default `?T` to +//! `!`, and hence this code compiles rather than failing and requiring +//! a type annotation. + +fn main() { + let c = Some({ + return; + }); + c.unwrap(); +} diff --git a/tests/ui/traits/trait-object-destructure.rs b/tests/ui/traits/trait-object-destructure.rs new file mode 100644 index 00000000000..6c091677c8c --- /dev/null +++ b/tests/ui/traits/trait-object-destructure.rs @@ -0,0 +1,29 @@ +//! Regression test for destructuring trait references (`&dyn T`/`Box`). +//! Checks cases where number of `&`/`Box` patterns (n) matches/doesn't match references (m). +//! +//! Issue: https://github.com/rust-lang/rust/issues/15031 + +#![feature(box_patterns)] + +trait T { + fn foo(&self) {} +} + +impl T for isize {} + +fn main() { + // Valid cases: n < m (can dereference) + let &x = &(&1isize as &dyn T); + let &x = &&(&1isize as &dyn T); + let &&x = &&(&1isize as &dyn T); + + // Error cases: n == m (cannot dereference trait object) + let &x = &1isize as &dyn T; //~ ERROR type `&dyn T` cannot be dereferenced + let &&x = &(&1isize as &dyn T); //~ ERROR type `&dyn T` cannot be dereferenced + let box x = Box::new(1isize) as Box; //~ ERROR type `Box` cannot be dereferenced + + // Error cases: n > m (type mismatch) + let &&x = &1isize as &dyn T; //~ ERROR mismatched types + let &&&x = &(&1isize as &dyn T); //~ ERROR mismatched types + let box box x = Box::new(1isize) as Box; //~ ERROR mismatched types +} diff --git a/tests/ui/traits/trait-object-destructure.stderr b/tests/ui/traits/trait-object-destructure.stderr new file mode 100644 index 00000000000..c7c832dc40a --- /dev/null +++ b/tests/ui/traits/trait-object-destructure.stderr @@ -0,0 +1,65 @@ +error[E0033]: type `&dyn T` cannot be dereferenced + --> $DIR/trait-object-destructure.rs:21:9 + | +LL | let &x = &1isize as &dyn T; + | ^^ type `&dyn T` cannot be dereferenced + +error[E0033]: type `&dyn T` cannot be dereferenced + --> $DIR/trait-object-destructure.rs:22:10 + | +LL | let &&x = &(&1isize as &dyn T); + | ^^ type `&dyn T` cannot be dereferenced + +error[E0033]: type `Box` cannot be dereferenced + --> $DIR/trait-object-destructure.rs:23:9 + | +LL | let box x = Box::new(1isize) as Box; + | ^^^^^ type `Box` cannot be dereferenced + +error[E0308]: mismatched types + --> $DIR/trait-object-destructure.rs:26:10 + | +LL | let &&x = &1isize as &dyn T; + | ^^ ----------------- this expression has type `&dyn T` + | | + | expected `dyn T`, found `&_` + | + = note: expected trait object `dyn T` + found reference `&_` +help: consider removing `&` from the pattern + | +LL - let &&x = &1isize as &dyn T; +LL + let &x = &1isize as &dyn T; + | + +error[E0308]: mismatched types + --> $DIR/trait-object-destructure.rs:27:11 + | +LL | let &&&x = &(&1isize as &dyn T); + | ^^ -------------------- this expression has type `&&dyn T` + | | + | expected `dyn T`, found `&_` + | + = note: expected trait object `dyn T` + found reference `&_` +help: consider removing `&` from the pattern + | +LL - let &&&x = &(&1isize as &dyn T); +LL + let &&x = &(&1isize as &dyn T); + | + +error[E0308]: mismatched types + --> $DIR/trait-object-destructure.rs:28:13 + | +LL | let box box x = Box::new(1isize) as Box; + | ^^^^^ ------------------------------ this expression has type `Box` + | | + | expected `dyn T`, found `Box<_>` + | + = note: expected trait object `dyn T` + found struct `Box<_>` + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0033, E0308. +For more information about an error, try `rustc --explain E0033`. diff --git a/tests/ui/typeck/inference-method-chain-diverging-fallback.rs b/tests/ui/typeck/inference-method-chain-diverging-fallback.rs new file mode 100644 index 00000000000..8f549b7d9d6 --- /dev/null +++ b/tests/ui/typeck/inference-method-chain-diverging-fallback.rs @@ -0,0 +1,19 @@ +//! Test type inference in method chains with diverging fallback. +//! Verifies that closure type in `unwrap_or_else` is properly inferred +//! when chained with other combinators and contains a diverging path. + +//@ run-pass + +fn produce() -> Result<&'static str, T> { + Ok("22") +} + +fn main() { + // The closure's error type `T` must unify with `ParseIntError`, + // while the success type must be `usize` (from parse()) + let x: usize = produce() + .and_then(|x| x.parse::()) // Explicit turbofish for clarity + .unwrap_or_else(|_| panic!()); // Diverging fallback + + assert_eq!(x, 22); +} -- cgit 1.4.1-3-g733a5