From: Alex Macleod Date: Fri, 23 Oct 2020 17:41:07 +0000 (+0100) Subject: Add some regression tests X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=75bbd80c098c240ffe0f97f50670e4cb66dc59c3;p=rust.git Add some regression tests Closes #56229 Closes #59494 Closes #70746 Closes #73229 --- diff --git a/src/test/ui/issues/issue-56229.rs b/src/test/ui/issues/issue-56229.rs new file mode 100644 index 00000000000..9e5897b9892 --- /dev/null +++ b/src/test/ui/issues/issue-56229.rs @@ -0,0 +1,35 @@ +// check-pass + +trait Mirror { + type Other; +} + +#[derive(Debug)] +struct Even(usize); +struct Odd; + +impl Mirror for Even { + type Other = Odd; +} + +impl Mirror for Odd { + type Other = Even; +} + +trait Dyn: AsRef<::Other> {} + +impl Dyn for Even {} + +impl AsRef for Even { + fn as_ref(&self) -> &Even { + self + } +} + +fn code(d: &dyn Dyn) -> &T::Other { + d.as_ref() +} + +fn main() { + println!("{:?}", code(&Even(22))); +} diff --git a/src/test/ui/issues/issue-59494.rs b/src/test/ui/issues/issue-59494.rs new file mode 100644 index 00000000000..06b8eb777c0 --- /dev/null +++ b/src/test/ui/issues/issue-59494.rs @@ -0,0 +1,23 @@ +fn t7p(f: impl Fn(B) -> C, g: impl Fn(A) -> B) -> impl Fn(A) -> C { + move |a: A| -> C { f(g(a)) } +} + +fn t8n(f: impl Fn(A) -> B, g: impl Fn(A) -> C) -> impl Fn(A) -> (B, C) +where + A: Copy, +{ + move |a: A| -> (B, C) { + let b = a; + let fa = f(a); + let ga = g(b); + (fa, ga) + } +} + +fn main() { + let f = |(_, _)| {}; + let g = |(a, _)| a; + let t7 = |env| |a| |b| t7p(f, g)(((env, a), b)); + let t8 = t8n(t7, t7p(f, g)); + //~^ ERROR: expected a `Fn<(_,)>` closure, found `impl Fn<(((_, _), _),)> +} diff --git a/src/test/ui/issues/issue-59494.stderr b/src/test/ui/issues/issue-59494.stderr new file mode 100644 index 00000000000..e2ac5d94da1 --- /dev/null +++ b/src/test/ui/issues/issue-59494.stderr @@ -0,0 +1,14 @@ +error[E0277]: expected a `Fn<(_,)>` closure, found `impl Fn<(((_, _), _),)>` + --> $DIR/issue-59494.rs:21:22 + | +LL | fn t8n(f: impl Fn(A) -> B, g: impl Fn(A) -> C) -> impl Fn(A) -> (B, C) + | ---------- required by this bound in `t8n` +... +LL | let t8 = t8n(t7, t7p(f, g)); + | ^^^^^^^^^ expected an `Fn<(_,)>` closure, found `impl Fn<(((_, _), _),)>` + | + = help: the trait `Fn<(_,)>` is not implemented for `impl Fn<(((_, _), _),)>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/issues/issue-70746.rs b/src/test/ui/issues/issue-70746.rs new file mode 100644 index 00000000000..8930c15f57e --- /dev/null +++ b/src/test/ui/issues/issue-70746.rs @@ -0,0 +1,29 @@ +// check-pass + +pub trait Trait1 { + type C; +} + +struct T1; +impl Trait1 for T1 { + type C = usize; +} +pub trait Callback: FnMut(::C) {} +impl::C)> Callback for F {} + +pub struct State { + callback: Option>>, +} +impl State { + fn new() -> Self { + Self { callback: None } + } + fn test_cb(&mut self, d: ::C) { + (self.callback.as_mut().unwrap())(d) + } +} + +fn main() { + let mut s = State::::new(); + s.test_cb(1); +} diff --git a/src/test/ui/issues/issue-73229.rs b/src/test/ui/issues/issue-73229.rs new file mode 100644 index 00000000000..35346199add --- /dev/null +++ b/src/test/ui/issues/issue-73229.rs @@ -0,0 +1,33 @@ +// check-pass + +fn any() -> T { + loop {} +} + +trait Foo { + type V; +} + +trait Callback: Fn(&T, &T::V) {} +impl Callback for F {} + +struct Bar { + callback: Box>, +} + +impl Bar { + fn event(&self) { + (self.callback)(any(), any()); + } +} + +struct A; +struct B; +impl Foo for A { + type V = B; +} + +fn main() { + let foo = Bar:: { callback: Box::new(|_: &A, _: &B| ()) }; + foo.event(); +}