Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
a new regression test discovered during bootstrapping.
more regression tests extracted while bootstrapping.
  • Loading branch information
pnkfelix committed Jan 12, 2015
commit 2316d6c31436bec9ee7671ec2332eb1d4f97e184
36 changes: 36 additions & 0 deletions src/test/run-pass/regions-refcell.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2012-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.

// This is a regression test for something that only came up while
// attempting to bootstrap librustc with new destructor lifetime
// semantics.

use std::collections::HashMap;
use std::cell::RefCell;

fn foo(map: RefCell<HashMap<&'static str, &[uint]>>) {
// assert_eq!(map.borrow().get("one"), Some(&1u));
let map = map.borrow();
for (i, &x) in map.get("one").unwrap().iter().enumerate() {
assert_eq!((i, x), (0u, 1u));
}
}

fn main() {
let zer = [0u];
let one = [1u];
let two = [2u];
let mut map = HashMap::new();
map.insert("zero", zer.as_slice());
map.insert("one", one.as_slice());
map.insert("two", two.as_slice());
let map = RefCell::new(map);
foo(map);
}
43 changes: 43 additions & 0 deletions src/test/run-pass/regions-trait-object-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2012-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.

// This is a regression test for something that only came up while
// attempting to bootstrap libsyntax; it is adapted from
// `syntax::ext::tt::generic_extension`.

pub struct E<'a> {
pub f: &'a u8,
}
impl<'b> E<'b> {
pub fn m(&self) -> &'b u8 { self.f }
}

pub struct P<'c> {
pub g: &'c u8,
}
pub trait M {
fn n(&self) -> u8;
}
impl<'d> M for P<'d> {
fn n(&self) -> u8 { *self.g }
}

fn extension<'e>(x: &'e E<'e>) -> Box<M+'e> {
loop {
let p = P { g: x.m() };
return Box::new(p) as Box<M+'e>;
}
}

fn main() {
let w = E { f: &10u8 };
let o = extension(&w);
assert_eq!(o.n(), 10u8);
}
42 changes: 42 additions & 0 deletions src/test/run-pass/trait-object-with-lifetime-bound.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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.

// Uncovered during work on new scoping rules for safe destructors
// as an important use case to support properly.

pub struct E<'a> {
pub f: &'a u8,
}
impl<'b> E<'b> {
pub fn m(&self) -> &'b u8 { self.f }
}

pub struct P<'c> {
pub g: &'c u8,
}
pub trait M {
fn n(&self) -> u8;
}
impl<'d> M for P<'d> {
fn n(&self) -> u8 { *self.g }
}

fn extension<'e>(x: &'e E<'e>) -> Box<M+'e> {
loop {
let p = P { g: x.m() };
return Box::new(p) as Box<M+'e>;
}
}

fn main() {
let w = E { f: &10u8 };
let o = extension(&w);
assert_eq!(o.n(), 10u8);
}