Skip to content

Add tests for #22638, #22872, #23024, #23046 #28332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/test/compile-fail/issue-22638.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<F: Fn()>(&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<F: Fn()>(&self, f: &F) {
match self {
&B::Variant2(ref factor) => {
factor.matches(&|| ())
}
_ => unreachable!("")
}
}
}

#[derive(Clone)]
struct C (D);

impl C {
pub fn matches<F: Fn()>(&self, f: &F) {
let &C(ref base) = self;
base.matches(&|| {
C(base.clone()).matches(f)
})
}
}

#[derive(Clone)]
struct D (Box<A>);

impl D {
pub fn matches<F: Fn()>(&self, f: &F) {
let &D(ref a) = self;
a.matches(f)
}
}

pub fn matches() {
A(B::Variant1).matches(&(|| ()))
}

fn main() {}
36 changes: 36 additions & 0 deletions src/test/compile-fail/issue-22872.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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>(P);

impl<'b, P> Wrap<'b> for Wrapper<P>
where P: Process<'b>,
<P as Process<'b>>::Item: Iterator {
fn foo(&mut self) {}
}


pub trait Process<'a> {
type Item;
fn bar(&'a self);
}

fn push_process<P>(process: P) where P: Process<'static> {
let _: Box<for<'b> 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() {}
23 changes: 23 additions & 0 deletions src/test/compile-fail/issue-23024.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<Box<Any>> = 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`)
}
30 changes: 30 additions & 0 deletions src/test/compile-fail/issue-23046.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub enum Expr<'var, VAR> {
Let(Box<Expr<'var, VAR>>,
Box<for<'v: 'var> 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)})});
}