From 548c44760f14c4547971e0359715f871ce9867bd Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 4 Jun 2024 13:55:15 +0000 Subject: [PATCH] Add regression tests --- .../auto-trait-selection-freeze.next.stderr | 22 +++++++++++++++++ .../impl-trait/auto-trait-selection-freeze.rs | 24 +++++++++++++++++++ .../auto-trait-selection.next.stderr | 22 +++++++++++++++++ tests/ui/impl-trait/auto-trait-selection.rs | 20 ++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr create mode 100644 tests/ui/impl-trait/auto-trait-selection-freeze.rs create mode 100644 tests/ui/impl-trait/auto-trait-selection.next.stderr create mode 100644 tests/ui/impl-trait/auto-trait-selection.rs diff --git a/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr b/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr new file mode 100644 index 00000000000..d9192e85497 --- /dev/null +++ b/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr @@ -0,0 +1,22 @@ +error[E0283]: type annotations needed + --> $DIR/auto-trait-selection-freeze.rs:20:16 + | +LL | if false { is_trait(foo()) } else { Default::default() } + | ^^^^^^^^ ----- type must be known at this point + | | + | cannot infer type of the type parameter `T` declared on the function `is_trait` + | + = note: cannot satisfy `_: Trait<_>` +note: required by a bound in `is_trait` + --> $DIR/auto-trait-selection-freeze.rs:12:16 + | +LL | fn is_trait, U: Default>(_: T) -> U { + | ^^^^^^^^ required by this bound in `is_trait` +help: consider specifying the generic arguments + | +LL | if false { is_trait::(foo()) } else { Default::default() } + | ++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/impl-trait/auto-trait-selection-freeze.rs b/tests/ui/impl-trait/auto-trait-selection-freeze.rs new file mode 100644 index 00000000000..72c24c51962 --- /dev/null +++ b/tests/ui/impl-trait/auto-trait-selection-freeze.rs @@ -0,0 +1,24 @@ +//! This test shows how we fail selection in a way that can influence +//! selection in a code path that succeeds. + +//@ revisions: next old +//@[next] compile-flags: -Znext-solver +//@[old]check-pass + +#![feature(freeze)] + +use std::marker::Freeze; + +fn is_trait, U: Default>(_: T) -> U { + Default::default() +} + +trait Trait {} +impl Trait for T {} +impl Trait for T {} +fn foo() -> impl Sized { + if false { is_trait(foo()) } else { Default::default() } + //[next]~^ ERROR: type annotations needed +} + +fn main() {} diff --git a/tests/ui/impl-trait/auto-trait-selection.next.stderr b/tests/ui/impl-trait/auto-trait-selection.next.stderr new file mode 100644 index 00000000000..2e8d7ad99b2 --- /dev/null +++ b/tests/ui/impl-trait/auto-trait-selection.next.stderr @@ -0,0 +1,22 @@ +error[E0283]: type annotations needed + --> $DIR/auto-trait-selection.rs:16:16 + | +LL | if false { is_trait(foo()) } else { Default::default() } + | ^^^^^^^^ ----- type must be known at this point + | | + | cannot infer type of the type parameter `T` declared on the function `is_trait` + | + = note: cannot satisfy `_: Trait<_>` +note: required by a bound in `is_trait` + --> $DIR/auto-trait-selection.rs:8:16 + | +LL | fn is_trait, U: Default>(_: T) -> U { + | ^^^^^^^^ required by this bound in `is_trait` +help: consider specifying the generic arguments + | +LL | if false { is_trait::(foo()) } else { Default::default() } + | ++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/impl-trait/auto-trait-selection.rs b/tests/ui/impl-trait/auto-trait-selection.rs new file mode 100644 index 00000000000..beb0b189fd7 --- /dev/null +++ b/tests/ui/impl-trait/auto-trait-selection.rs @@ -0,0 +1,20 @@ +//! This test shows how we fail selection in a way that can influence +//! selection in a code path that succeeds. + +//@ revisions: next old +//@[next] compile-flags: -Znext-solver +//@[old]check-pass + +fn is_trait, U: Default>(_: T) -> U { + Default::default() +} + +trait Trait {} +impl Trait for T {} +impl Trait for T {} +fn foo() -> impl Sized { + if false { is_trait(foo()) } else { Default::default() } + //[next]~^ ERROR: type annotations needed +} + +fn main() {}