Skip to content

Commit 2bb0796

Browse files
committed
Convert tests to cross-crate, fix a RefCell bug I found in the process.
1 parent 6340c1a commit 2bb0796

File tree

4 files changed

+95
-41
lines changed

4 files changed

+95
-41
lines changed

src/librustc/middle/typeck/coherence/overlap.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,16 @@ struct OverlapChecker<'cx, 'tcx:'cx> {
3535
impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
3636
fn check_for_overlapping_impls(&self) {
3737
debug!("check_for_overlapping_impls");
38-
let trait_impls = self.tcx.trait_impls.borrow();
39-
for trait_def_id in trait_impls.keys() {
38+
39+
// Collect this into a vector to avoid holding the
40+
// refcell-lock during the
41+
// check_for_overlapping_impls_of_trait() check, since that
42+
// check can populate this table further with impls from other
43+
// crates.
44+
let trait_def_ids: Vec<ast::DefId> =
45+
self.tcx.trait_impls.borrow().keys().map(|&d| d).collect();
46+
47+
for trait_def_id in trait_def_ids.iter() {
4048
self.check_for_overlapping_impls_of_trait(*trait_def_id);
4149
}
4250
}

src/test/auxiliary/go_trait.rs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
// Common code used for tests that model the Fn/FnMut/FnOnce hierarchy.
12+
13+
pub trait Go {
14+
fn go(&self, arg: int);
15+
}
16+
17+
pub fn go<G:Go>(this: &G, arg: int) {
18+
this.go(arg)
19+
}
20+
21+
pub trait GoMut {
22+
fn go_mut(&mut self, arg: int);
23+
}
24+
25+
pub fn go_mut<G:GoMut>(this: &mut G, arg: int) {
26+
this.go_mut(arg)
27+
}
28+
29+
pub trait GoOnce {
30+
fn go_once(self, arg: int);
31+
}
32+
33+
pub fn go_once<G:GoOnce>(this: G, arg: int) {
34+
this.go_once(arg)
35+
}
36+
37+
impl<G> GoMut for G
38+
where G : Go
39+
{
40+
fn go_mut(&mut self, arg: int) {
41+
go(&*self, arg)
42+
}
43+
}
44+
45+
impl<G> GoOnce for G
46+
where G : GoMut
47+
{
48+
fn go_once(mut self, arg: int) {
49+
go_mut(&mut self, arg)
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
// aux-build:go_trait.rs
12+
13+
extern crate go_trait;
14+
15+
use go_trait::{Go,GoMut};
16+
use std::fmt::Show;
17+
use std::default::Default;
18+
19+
struct MyThingy;
20+
21+
impl Go for MyThingy {
22+
fn go(&self, arg: int) { }
23+
}
24+
25+
impl GoMut for MyThingy { //~ ERROR conflicting implementations
26+
fn go_mut(&mut self, arg: int) { }
27+
}
28+
29+
fn main() { }

src/test/run-pass/traits-conditional-model-fn.rs

+5-39
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,14 @@
1212
// most one of `Go`, `GoMut`, or `GoOnce`, and then the others follow
1313
// automatically.
1414

15-
use std::rc::Rc;
16-
use std::cell::Cell;
17-
18-
trait Go {
19-
fn go(&self, arg: int);
20-
}
21-
22-
fn go<G:Go>(this: &G, arg: int) {
23-
this.go(arg)
24-
}
15+
// aux-build:go_trait.rs
2516

26-
trait GoMut {
27-
fn go_mut(&mut self, arg: int);
28-
}
17+
extern crate go_trait;
2918

30-
fn go_mut<G:GoMut>(this: &mut G, arg: int) {
31-
this.go_mut(arg)
32-
}
33-
34-
trait GoOnce {
35-
fn go_once(self, arg: int);
36-
}
19+
use go_trait::{Go, GoMut, GoOnce, go, go_mut, go_once};
3720

38-
fn go_once<G:GoOnce>(this: G, arg: int) {
39-
this.go_once(arg)
40-
}
41-
42-
impl<G> GoMut for G
43-
where G : Go
44-
{
45-
fn go_mut(&mut self, arg: int) {
46-
go(&*self, arg)
47-
}
48-
}
49-
50-
impl<G> GoOnce for G
51-
where G : GoMut
52-
{
53-
fn go_once(mut self, arg: int) {
54-
go_mut(&mut self, arg)
55-
}
56-
}
21+
use std::rc::Rc;
22+
use std::cell::Cell;
5723

5824
///////////////////////////////////////////////////////////////////////////
5925

0 commit comments

Comments
 (0)