diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2016-05-21 08:34:18 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2016-05-31 19:59:34 -0400 |
| commit | d3d2fc51f7fc20ec7adbf147ed4fd9f89034bd3d (patch) | |
| tree | e704653fbfba160fa21283a537bec833685b2dbd /src/test | |
| parent | 72b97070ff1281c4dc4cc69ce3c2b186b9eb81d7 (diff) | |
| download | rust-d3d2fc51f7fc20ec7adbf147ed4fd9f89034bd3d.tar.gz rust-d3d2fc51f7fc20ec7adbf147ed4fd9f89034bd3d.zip | |
some new tests
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/associated-types/cache/chrono-scan.rs | 39 | ||||
| -rw-r--r-- | src/test/compile-fail/associated-types/cache/elision.rs | 34 | ||||
| -rw-r--r-- | src/test/run-pass/project-cache-issue-31849.rs | 75 |
3 files changed, 148 insertions, 0 deletions
diff --git a/src/test/compile-fail/associated-types/cache/chrono-scan.rs b/src/test/compile-fail/associated-types/cache/chrono-scan.rs new file mode 100644 index 00000000000..a753527ea53 --- /dev/null +++ b/src/test/compile-fail/associated-types/cache/chrono-scan.rs @@ -0,0 +1,39 @@ +// Copyright 2012-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(rustc_attrs)] +#![allow(warnings)] + +pub type ParseResult<T> = Result<T, ()>; + +pub enum Item<'a> { Literal(&'a str), + } + +pub fn colon_or_space(s: &str) -> ParseResult<&str> { + unimplemented!() +} + +pub fn timezone_offset_zulu<F>(s: &str, colon: F) -> ParseResult<(&str, i32)> + where F: FnMut(&str) -> ParseResult<&str> { + unimplemented!() +} + +pub fn parse<'a, I>(mut s: &str, items: I) -> ParseResult<()> + where I: Iterator<Item=Item<'a>> { + macro_rules! try_consume { + ($e:expr) => ({ let (s_, v) = try!($e); s = s_; v }) + } + let offset = try_consume!(timezone_offset_zulu(s.trim_left(), colon_or_space)); + let offset = try_consume!(timezone_offset_zulu(s.trim_left(), colon_or_space)); + Ok(()) +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/compile-fail/associated-types/cache/elision.rs b/src/test/compile-fail/associated-types/cache/elision.rs new file mode 100644 index 00000000000..d1117328c86 --- /dev/null +++ b/src/test/compile-fail/associated-types/cache/elision.rs @@ -0,0 +1,34 @@ +// Copyright 2014 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(rustc_attrs)] +#![allow(warnings)] + +// Check that you are allowed to implement using elision but write +// trait without elision (a bug in this cropped up during +// bootstrapping, so this is a regression test). + +pub struct SplitWhitespace<'a> { + x: &'a u8 +} + +pub trait UnicodeStr { + fn split_whitespace<'a>(&'a self) -> SplitWhitespace<'a>; +} + +impl UnicodeStr for str { + #[inline] + fn split_whitespace(&self) -> SplitWhitespace { + unimplemented!() + } +} + +#[rustc_error] +fn main() { } //~ ERROR compilation successful diff --git a/src/test/run-pass/project-cache-issue-31849.rs b/src/test/run-pass/project-cache-issue-31849.rs new file mode 100644 index 00000000000..d03424b2b2b --- /dev/null +++ b/src/test/run-pass/project-cache-issue-31849.rs @@ -0,0 +1,75 @@ +// 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. + +// Regression test for #31849: the problem here was actually a performance +// cliff, but I'm adding the test for reference. + +pub trait Upcast<T> { + fn upcast(self) -> T; +} + +impl<S1, S2, T1, T2> Upcast<(T1, T2)> for (S1,S2) + where S1: Upcast<T1>, + S2: Upcast<T2>, +{ + fn upcast(self) -> (T1, T2) { (self.0.upcast(), self.1.upcast()) } +} + +impl Upcast<()> for () +{ + fn upcast(self) -> () { () } +} + +pub trait ToStatic { + type Static: 'static; + fn to_static(self) -> Self::Static where Self: Sized; +} + +impl<T, U> ToStatic for (T, U) + where T: ToStatic, + U: ToStatic +{ + type Static = (T::Static, U::Static); + fn to_static(self) -> Self::Static { (self.0.to_static(), self.1.to_static()) } +} + +impl ToStatic for () +{ + type Static = (); + fn to_static(self) -> () { () } +} + + +trait Factory { + type Output; + fn build(&self) -> Self::Output; +} + +impl<S,T> Factory for (S, T) + where S: Factory, + T: Factory, + S::Output: ToStatic, + <S::Output as ToStatic>::Static: Upcast<S::Output>, +{ + type Output = (S::Output, T::Output); + fn build(&self) -> Self::Output { (self.0.build().to_static().upcast(), self.1.build()) } +} + +impl Factory for () { + type Output = (); + fn build(&self) -> Self::Output { () } +} + +fn main() { + // More parens, more time. + let it = ((((((((((),()),()),()),()),()),()),()),()),()); + it.build(); +} + |
