Skip to content

Commit d3d2fc5

Browse files
committed
some new tests
1 parent 72b9707 commit d3d2fc5

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2012-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(rustc_attrs)]
12+
#![allow(warnings)]
13+
14+
pub type ParseResult<T> = Result<T, ()>;
15+
16+
pub enum Item<'a> { Literal(&'a str),
17+
}
18+
19+
pub fn colon_or_space(s: &str) -> ParseResult<&str> {
20+
unimplemented!()
21+
}
22+
23+
pub fn timezone_offset_zulu<F>(s: &str, colon: F) -> ParseResult<(&str, i32)>
24+
where F: FnMut(&str) -> ParseResult<&str> {
25+
unimplemented!()
26+
}
27+
28+
pub fn parse<'a, I>(mut s: &str, items: I) -> ParseResult<()>
29+
where I: Iterator<Item=Item<'a>> {
30+
macro_rules! try_consume {
31+
($e:expr) => ({ let (s_, v) = try!($e); s = s_; v })
32+
}
33+
let offset = try_consume!(timezone_offset_zulu(s.trim_left(), colon_or_space));
34+
let offset = try_consume!(timezone_offset_zulu(s.trim_left(), colon_or_space));
35+
Ok(())
36+
}
37+
38+
#[rustc_error]
39+
fn main() { } //~ ERROR compilation successful
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2014 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(rustc_attrs)]
12+
#![allow(warnings)]
13+
14+
// Check that you are allowed to implement using elision but write
15+
// trait without elision (a bug in this cropped up during
16+
// bootstrapping, so this is a regression test).
17+
18+
pub struct SplitWhitespace<'a> {
19+
x: &'a u8
20+
}
21+
22+
pub trait UnicodeStr {
23+
fn split_whitespace<'a>(&'a self) -> SplitWhitespace<'a>;
24+
}
25+
26+
impl UnicodeStr for str {
27+
#[inline]
28+
fn split_whitespace(&self) -> SplitWhitespace {
29+
unimplemented!()
30+
}
31+
}
32+
33+
#[rustc_error]
34+
fn main() { } //~ ERROR compilation successful
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
// Regression test for #31849: the problem here was actually a performance
12+
// cliff, but I'm adding the test for reference.
13+
14+
pub trait Upcast<T> {
15+
fn upcast(self) -> T;
16+
}
17+
18+
impl<S1, S2, T1, T2> Upcast<(T1, T2)> for (S1,S2)
19+
where S1: Upcast<T1>,
20+
S2: Upcast<T2>,
21+
{
22+
fn upcast(self) -> (T1, T2) { (self.0.upcast(), self.1.upcast()) }
23+
}
24+
25+
impl Upcast<()> for ()
26+
{
27+
fn upcast(self) -> () { () }
28+
}
29+
30+
pub trait ToStatic {
31+
type Static: 'static;
32+
fn to_static(self) -> Self::Static where Self: Sized;
33+
}
34+
35+
impl<T, U> ToStatic for (T, U)
36+
where T: ToStatic,
37+
U: ToStatic
38+
{
39+
type Static = (T::Static, U::Static);
40+
fn to_static(self) -> Self::Static { (self.0.to_static(), self.1.to_static()) }
41+
}
42+
43+
impl ToStatic for ()
44+
{
45+
type Static = ();
46+
fn to_static(self) -> () { () }
47+
}
48+
49+
50+
trait Factory {
51+
type Output;
52+
fn build(&self) -> Self::Output;
53+
}
54+
55+
impl<S,T> Factory for (S, T)
56+
where S: Factory,
57+
T: Factory,
58+
S::Output: ToStatic,
59+
<S::Output as ToStatic>::Static: Upcast<S::Output>,
60+
{
61+
type Output = (S::Output, T::Output);
62+
fn build(&self) -> Self::Output { (self.0.build().to_static().upcast(), self.1.build()) }
63+
}
64+
65+
impl Factory for () {
66+
type Output = ();
67+
fn build(&self) -> Self::Output { () }
68+
}
69+
70+
fn main() {
71+
// More parens, more time.
72+
let it = ((((((((((),()),()),()),()),()),()),()),()),());
73+
it.build();
74+
}
75+

0 commit comments

Comments
 (0)