Skip to content

Commit 2316d6c

Browse files
committed
a new regression test discovered during bootstrapping.
more regression tests extracted while bootstrapping.
1 parent 42618e7 commit 2316d6c

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

src/test/run-pass/regions-refcell.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2012-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+
// This is a regression test for something that only came up while
12+
// attempting to bootstrap librustc with new destructor lifetime
13+
// semantics.
14+
15+
use std::collections::HashMap;
16+
use std::cell::RefCell;
17+
18+
fn foo(map: RefCell<HashMap<&'static str, &[uint]>>) {
19+
// assert_eq!(map.borrow().get("one"), Some(&1u));
20+
let map = map.borrow();
21+
for (i, &x) in map.get("one").unwrap().iter().enumerate() {
22+
assert_eq!((i, x), (0u, 1u));
23+
}
24+
}
25+
26+
fn main() {
27+
let zer = [0u];
28+
let one = [1u];
29+
let two = [2u];
30+
let mut map = HashMap::new();
31+
map.insert("zero", zer.as_slice());
32+
map.insert("one", one.as_slice());
33+
map.insert("two", two.as_slice());
34+
let map = RefCell::new(map);
35+
foo(map);
36+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2012-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+
// This is a regression test for something that only came up while
12+
// attempting to bootstrap libsyntax; it is adapted from
13+
// `syntax::ext::tt::generic_extension`.
14+
15+
pub struct E<'a> {
16+
pub f: &'a u8,
17+
}
18+
impl<'b> E<'b> {
19+
pub fn m(&self) -> &'b u8 { self.f }
20+
}
21+
22+
pub struct P<'c> {
23+
pub g: &'c u8,
24+
}
25+
pub trait M {
26+
fn n(&self) -> u8;
27+
}
28+
impl<'d> M for P<'d> {
29+
fn n(&self) -> u8 { *self.g }
30+
}
31+
32+
fn extension<'e>(x: &'e E<'e>) -> Box<M+'e> {
33+
loop {
34+
let p = P { g: x.m() };
35+
return Box::new(p) as Box<M+'e>;
36+
}
37+
}
38+
39+
fn main() {
40+
let w = E { f: &10u8 };
41+
let o = extension(&w);
42+
assert_eq!(o.n(), 10u8);
43+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
// Uncovered during work on new scoping rules for safe destructors
12+
// as an important use case to support properly.
13+
14+
pub struct E<'a> {
15+
pub f: &'a u8,
16+
}
17+
impl<'b> E<'b> {
18+
pub fn m(&self) -> &'b u8 { self.f }
19+
}
20+
21+
pub struct P<'c> {
22+
pub g: &'c u8,
23+
}
24+
pub trait M {
25+
fn n(&self) -> u8;
26+
}
27+
impl<'d> M for P<'d> {
28+
fn n(&self) -> u8 { *self.g }
29+
}
30+
31+
fn extension<'e>(x: &'e E<'e>) -> Box<M+'e> {
32+
loop {
33+
let p = P { g: x.m() };
34+
return Box::new(p) as Box<M+'e>;
35+
}
36+
}
37+
38+
fn main() {
39+
let w = E { f: &10u8 };
40+
let o = extension(&w);
41+
assert_eq!(o.n(), 10u8);
42+
}

0 commit comments

Comments
 (0)