From a33532b1b720eb87d358911e1f79cf635297dac6 Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Thu, 10 Sep 2015 11:26:19 -0400 Subject: [PATCH] Add tests for #22638, #22872, #23024, #23046 Closes #22638. Closes #22872. Closes #23024. Closes #23046. --- src/test/compile-fail/issue-22638.rs | 67 ++++++++++++++++++++++++++++ src/test/compile-fail/issue-22872.rs | 36 +++++++++++++++ src/test/compile-fail/issue-23024.rs | 23 ++++++++++ src/test/compile-fail/issue-23046.rs | 30 +++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 src/test/compile-fail/issue-22638.rs create mode 100644 src/test/compile-fail/issue-22872.rs create mode 100644 src/test/compile-fail/issue-23024.rs create mode 100644 src/test/compile-fail/issue-23046.rs diff --git a/src/test/compile-fail/issue-22638.rs b/src/test/compile-fail/issue-22638.rs new file mode 100644 index 00000000000..3f4f2ced283 --- /dev/null +++ b/src/test/compile-fail/issue-22638.rs @@ -0,0 +1,67 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(unused)] + +#[derive(Clone)] +struct A (B); + +impl A { + pub fn matches(&self, f: &F) { + //~^ ERROR reached the recursion limit during monomorphization + let &A(ref term) = self; + term.matches(f); + } +} + +#[derive(Clone)] +enum B { + Variant1, + Variant2(C), +} + +impl B { + pub fn matches(&self, f: &F) { + match self { + &B::Variant2(ref factor) => { + factor.matches(&|| ()) + } + _ => unreachable!("") + } + } +} + +#[derive(Clone)] +struct C (D); + +impl C { + pub fn matches(&self, f: &F) { + let &C(ref base) = self; + base.matches(&|| { + C(base.clone()).matches(f) + }) + } +} + +#[derive(Clone)] +struct D (Box); + +impl D { + pub fn matches(&self, f: &F) { + let &D(ref a) = self; + a.matches(f) + } +} + +pub fn matches() { + A(B::Variant1).matches(&(|| ())) +} + +fn main() {} diff --git a/src/test/compile-fail/issue-22872.rs b/src/test/compile-fail/issue-22872.rs new file mode 100644 index 00000000000..86982284ac2 --- /dev/null +++ b/src/test/compile-fail/issue-22872.rs @@ -0,0 +1,36 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Wrap<'b> { + fn foo(&'b mut self); +} + +struct Wrapper

(P); + +impl<'b, P> Wrap<'b> for Wrapper

+where P: Process<'b>, +

>::Item: Iterator { + fn foo(&mut self) {} +} + + +pub trait Process<'a> { + type Item; + fn bar(&'a self); +} + +fn push_process

(process: P) where P: Process<'static> { + let _: Box Wrap<'b>> = Box::new(Wrapper(process)); + //~^ ERROR the trait `for<'b> Process<'b>` is not implemented for the type `P` [E0277] + //~| ERROR the trait `for<'b> core::iter::Iterator` is not implemented for the type + //~| ERROR cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting +} + +fn main() {} diff --git a/src/test/compile-fail/issue-23024.rs b/src/test/compile-fail/issue-23024.rs new file mode 100644 index 00000000000..92610c1c6d3 --- /dev/null +++ b/src/test/compile-fail/issue-23024.rs @@ -0,0 +1,23 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(box_syntax)] +use std::any::Any; + +fn main() +{ + fn h(x:i32) -> i32 {3*x} + let mut vfnfer:Vec> = vec![]; + vfnfer.push(box h); + println!("{:?}",(vfnfer[0] as Fn)(3)); + //~^ ERROR the precise format of `Fn`-family traits' + //~| ERROR wrong number of type arguments: expected 1, found 0 + //~| ERROR the value of the associated type `Output` (from the trait `core::ops::FnOnce`) +} diff --git a/src/test/compile-fail/issue-23046.rs b/src/test/compile-fail/issue-23046.rs new file mode 100644 index 00000000000..8c83c4cefd1 --- /dev/null +++ b/src/test/compile-fail/issue-23046.rs @@ -0,0 +1,30 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub enum Expr<'var, VAR> { + Let(Box>, + Box Fn(Expr<'v, VAR>) -> Expr<'v, VAR> + 'var>) +} + +pub fn add<'var, VAR> + (a: Expr<'var, VAR>, b: Expr<'var, VAR>) -> Expr<'var, VAR> { + loop {} +} + +pub fn let_<'var, VAR, F: for<'v: 'var> Fn(Expr<'v, VAR>) -> Expr<'v, VAR>> + (a: Expr<'var, VAR>, b: F) -> Expr<'var, VAR> { + loop {} +} + +fn main() { + let ex = (|x| { + let_(add(x,x), |y| { //~ ERROR unable to infer enough type information about `_` + let_(add(x, x), |x|x)})}); +}