Skip to content

Commit a33532b

Browse files
committed
Add tests for #22638, #22872, #23024, #23046
Closes #22638. Closes #22872. Closes #23024. Closes #23046.
1 parent 5f9f0b7 commit a33532b

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed

src/test/compile-fail/issue-22638.rs

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![allow(unused)]
12+
13+
#[derive(Clone)]
14+
struct A (B);
15+
16+
impl A {
17+
pub fn matches<F: Fn()>(&self, f: &F) {
18+
//~^ ERROR reached the recursion limit during monomorphization
19+
let &A(ref term) = self;
20+
term.matches(f);
21+
}
22+
}
23+
24+
#[derive(Clone)]
25+
enum B {
26+
Variant1,
27+
Variant2(C),
28+
}
29+
30+
impl B {
31+
pub fn matches<F: Fn()>(&self, f: &F) {
32+
match self {
33+
&B::Variant2(ref factor) => {
34+
factor.matches(&|| ())
35+
}
36+
_ => unreachable!("")
37+
}
38+
}
39+
}
40+
41+
#[derive(Clone)]
42+
struct C (D);
43+
44+
impl C {
45+
pub fn matches<F: Fn()>(&self, f: &F) {
46+
let &C(ref base) = self;
47+
base.matches(&|| {
48+
C(base.clone()).matches(f)
49+
})
50+
}
51+
}
52+
53+
#[derive(Clone)]
54+
struct D (Box<A>);
55+
56+
impl D {
57+
pub fn matches<F: Fn()>(&self, f: &F) {
58+
let &D(ref a) = self;
59+
a.matches(f)
60+
}
61+
}
62+
63+
pub fn matches() {
64+
A(B::Variant1).matches(&(|| ()))
65+
}
66+
67+
fn main() {}

src/test/compile-fail/issue-22872.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Wrap<'b> {
12+
fn foo(&'b mut self);
13+
}
14+
15+
struct Wrapper<P>(P);
16+
17+
impl<'b, P> Wrap<'b> for Wrapper<P>
18+
where P: Process<'b>,
19+
<P as Process<'b>>::Item: Iterator {
20+
fn foo(&mut self) {}
21+
}
22+
23+
24+
pub trait Process<'a> {
25+
type Item;
26+
fn bar(&'a self);
27+
}
28+
29+
fn push_process<P>(process: P) where P: Process<'static> {
30+
let _: Box<for<'b> Wrap<'b>> = Box::new(Wrapper(process));
31+
//~^ ERROR the trait `for<'b> Process<'b>` is not implemented for the type `P` [E0277]
32+
//~| ERROR the trait `for<'b> core::iter::Iterator` is not implemented for the type
33+
//~| ERROR cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting
34+
}
35+
36+
fn main() {}

src/test/compile-fail/issue-23024.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(box_syntax)]
12+
use std::any::Any;
13+
14+
fn main()
15+
{
16+
fn h(x:i32) -> i32 {3*x}
17+
let mut vfnfer:Vec<Box<Any>> = vec![];
18+
vfnfer.push(box h);
19+
println!("{:?}",(vfnfer[0] as Fn)(3));
20+
//~^ ERROR the precise format of `Fn`-family traits'
21+
//~| ERROR wrong number of type arguments: expected 1, found 0
22+
//~| ERROR the value of the associated type `Output` (from the trait `core::ops::FnOnce`)
23+
}

src/test/compile-fail/issue-23046.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub enum Expr<'var, VAR> {
12+
Let(Box<Expr<'var, VAR>>,
13+
Box<for<'v: 'var> Fn(Expr<'v, VAR>) -> Expr<'v, VAR> + 'var>)
14+
}
15+
16+
pub fn add<'var, VAR>
17+
(a: Expr<'var, VAR>, b: Expr<'var, VAR>) -> Expr<'var, VAR> {
18+
loop {}
19+
}
20+
21+
pub fn let_<'var, VAR, F: for<'v: 'var> Fn(Expr<'v, VAR>) -> Expr<'v, VAR>>
22+
(a: Expr<'var, VAR>, b: F) -> Expr<'var, VAR> {
23+
loop {}
24+
}
25+
26+
fn main() {
27+
let ex = (|x| {
28+
let_(add(x,x), |y| { //~ ERROR unable to infer enough type information about `_`
29+
let_(add(x, x), |x|x)})});
30+
}

0 commit comments

Comments
 (0)