Skip to content

Commit 607f607

Browse files
committed
Keep track of the whole error chain
1 parent 8818693 commit 607f607

20 files changed

+66
-48
lines changed

src/librustc/middle/traits/select.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
19281928
}
19291929
}
19301930

1931+
#[allow(unused_comparisons)]
19311932
fn derived_cause(&self,
19321933
obligation: &TraitObligation<'tcx>,
19331934
variant: fn(Rc<ty::Binder<ty::TraitRef<'tcx>>>,
@@ -1945,7 +1946,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
19451946
* reporting.
19461947
*/
19471948

1948-
if obligation.recursion_depth == 0 {
1949+
// NOTE(flaper87): As of now, it keeps track of the whole error
1950+
// chain. Ideally, we should have a way to configure this either
1951+
// by using -Z verbose or just a CLI argument.
1952+
if obligation.recursion_depth >= 0 {
19491953
ObligationCause::new(obligation.cause.span,
19501954
obligation.trait_ref.def_id().node,
19511955
variant(obligation.trait_ref.clone(),

src/libsyntax/ext/deriving/bounds.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ pub fn expand_deriving_bound<F>(cx: &mut ExtCtxt,
2626
MetaWord(ref tname) => {
2727
match tname.get() {
2828
"Copy" => "Copy",
29-
"Send" => "Send",
30-
"Sync" => "Sync",
29+
"Send" | "Sync" => {
30+
return cx.span_err(span,
31+
format!("{} is an unsafe trait and it \
32+
should be implemented explicitly", *tname)[])
33+
}
3134
ref tname => {
3235
cx.span_bug(span,
3336
format!("expected built-in trait name but \

src/test/compile-fail/deriving-bounds.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[deriving(Sync(Bad),Send,Copy)]
11+
#[deriving(Copy(Bad))]
1212
//~^ ERROR unexpected value in deriving, expected a trait
1313
struct Test;
1414

15+
#[deriving(Sync)]
16+
//~^ ERROR Sync is an unsafe trait and it should be implemented explicitly
17+
struct Test1;
18+
1519
pub fn main() {}

src/test/compile-fail/issue-17718-static-sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ struct Foo { marker: marker::NoSync }
1414

1515
static FOO: uint = 3;
1616
static BAR: Foo = Foo { marker: marker::NoSync };
17-
//~^ ERROR: shared static items must have a type which implements Sync
17+
//~^ ERROR: the trait `core::kinds::Sync` is not implemented
1818

1919
fn main() {}

src/test/compile-fail/issue-7013.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ struct A {
3333
fn main() {
3434
let a = A {v: box B{v: None} as Box<Foo+Send>};
3535
//~^ ERROR the trait `core::kinds::Send` is not implemented
36+
//~^^ ERROR the trait `core::kinds::Send` is not implemented
3637
}

src/test/compile-fail/issue-7364.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use std::cell::RefCell;
1414
// Regresion test for issue 7364
1515
static boxed: Box<RefCell<int>> = box RefCell::new(0);
1616
//~^ ERROR statics are not allowed to have custom pointers
17-
//~^^ ERROR: shared static items must have a type which implements Sync
17+
//~^^ ERROR: the trait `core::kinds::Sync` is not implemented for the type
18+
//~^^^ ERROR: the trait `core::kinds::Sync` is not implemented for the type
19+
//~^^^^ ERROR: the trait `core::kinds::Sync` is not implemented for the type
1820

1921
fn main() { }

src/test/compile-fail/kindck-destructor-owned.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,6 @@
99
// except according to those terms.
1010

1111

12-
use std::rc::Rc;
13-
14-
struct Foo {
15-
f: Rc<int>,
16-
}
17-
18-
impl Drop for Foo {
19-
//~^ ERROR the trait `core::kinds::Send` is not implemented
20-
//~^^ NOTE cannot implement a destructor on a structure or enumeration that does not satisfy Send
21-
fn drop(&mut self) {
22-
}
23-
}
24-
2512
struct Bar<'a> {
2613
f: &'a int,
2714
}

src/test/compile-fail/kindck-nonsendable-1.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ fn bar<F:FnOnce() + Send>(_: F) { }
1717

1818
fn main() {
1919
let x = Rc::new(3u);
20-
bar(move|| foo(x)); //~ ERROR `core::kinds::Send` is not implemented
20+
bar(move|| foo(x));
21+
//~^ ERROR `core::kinds::Send` is not implemented
22+
//~^^ ERROR `core::kinds::Send` is not implemented
2123
}
2224

src/test/compile-fail/kindck-send-unsafe.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
extern crate core;
12+
1113
fn assert_send<T:Send>() { }
1214

13-
// unsafe ptrs are ok unless they point at unsendable things
14-
fn test70() {
15-
assert_send::<*mut int>();
16-
}
1715
fn test71<'a>() {
18-
assert_send::<*mut &'a int>(); //~ ERROR declared lifetime bound not satisfied
16+
assert_send::<*mut &'a int>();
17+
//~^ ERROR the trait `core::kinds::Send` is not implemented for the type
1918
}
2019

2120
fn main() {

src/test/compile-fail/mut-not-freeze.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ fn f<T: Sync>(_: T) {}
1414

1515
fn main() {
1616
let x = RefCell::new(0i);
17-
f(x); //~ ERROR `core::kinds::Sync` is not implemented
17+
f(x);
18+
//~^ ERROR `core::kinds::Sync` is not implemented
19+
//~^^ ERROR `core::kinds::Sync` is not implemented
20+
//~^^^ ERROR `core::kinds::Sync` is not implemented
1821
}

src/test/compile-fail/no-send-res-ports.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn main() {
3737

3838
task::spawn(move|| {
3939
//~^ ERROR `core::kinds::Send` is not implemented
40+
//~^^ ERROR `core::kinds::Send` is not implemented
4041
let y = x;
4142
println!("{}", y);
4243
});

src/test/compile-fail/no_send-rc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ fn main() {
1616
let x = Rc::new(5i);
1717
bar(x);
1818
//~^ ERROR `core::kinds::Send` is not implemented
19+
//~^^ ERROR `core::kinds::Send` is not implemented
1920
}

src/test/compile-fail/no_share-rc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ fn main() {
1717
let x = Rc::new(RefCell::new(5i));
1818
bar(x);
1919
//~^ ERROR the trait `core::kinds::Sync` is not implemented
20+
//~^^ ERROR the trait `core::kinds::Sync` is not implemented
2021
}

src/test/compile-fail/regions-bounded-by-send.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
// in this file all test region bound and lifetime violations that are
1313
// detected during type check.
1414

15+
extern crate core;
16+
use core::ptr::Unique;
17+
1518
fn assert_send<T:Send>() { }
16-
trait Dummy { }
19+
trait Dummy:Send { }
1720

1821
// lifetime pointers with 'static lifetime are ok
1922

@@ -58,7 +61,7 @@ fn box_with_region_not_ok<'a>() {
5861

5962
fn object_with_random_bound_not_ok<'a>() {
6063
assert_send::<&'a (Dummy+'a)>();
61-
//~^ ERROR not implemented
64+
//~^ ERROR reference has a longer lifetime
6265
}
6366

6467
fn object_with_send_bound_not_ok<'a>() {
@@ -73,17 +76,12 @@ fn closure_with_lifetime_not_ok<'a>() {
7376

7477
// unsafe pointers are ok unless they point at unsendable things
7578

76-
fn unsafe_ok1<'a>(_: &'a int) {
77-
assert_send::<*const int>();
78-
assert_send::<*mut int>();
79-
}
79+
struct UniqueUnsafePtr(Unique<*const int>);
8080

81-
fn unsafe_ok2<'a>(_: &'a int) {
82-
assert_send::<*const &'a int>(); //~ ERROR declared lifetime bound not satisfied
83-
}
81+
unsafe impl Send for UniqueUnsafePtr {}
8482

85-
fn unsafe_ok3<'a>(_: &'a int) {
86-
assert_send::<*mut &'a int>(); //~ ERROR declared lifetime bound not satisfied
83+
fn unsafe_ok1<'a>(_: &'a int) {
84+
assert_send::<UniqueUnsafePtr>();
8785
}
8886

8987
fn main() {

src/test/compile-fail/task-rng-isnt-sendable.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ fn test_send<S: Send>() {}
1717
pub fn main() {
1818
test_send::<rand::TaskRng>();
1919
//~^ ERROR `core::kinds::Send` is not implemented
20+
//~^^ ERROR `core::kinds::Send` is not implemented
2021
}

src/test/compile-fail/typeck-unsafe-always-share.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ fn test<T: Sync>(s: T){
3030
fn main() {
3131
let us = UnsafeCell::new(MySync{u: UnsafeCell::new(0i)});
3232
test(us);
33+
//~^ ERROR `core::kinds::Sync` is not implemented
3334

3435
let uns = UnsafeCell::new(NoSync{m: marker::NoSync});
3536
test(uns);
37+
//~^ ERROR `core::kinds::Sync` is not implemented
3638

3739
let ms = MySync{u: uns};
3840
test(ms);
41+
//~^ ERROR `core::kinds::Sync` is not implemented
3942

4043
let ns = NoSync{m: marker::NoSync};
4144
test(ns);

src/test/compile-fail/unique-unique-kind.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ fn f<T:Send>(_i: T) {
1616

1717
fn main() {
1818
let i = box Rc::new(100i);
19-
f(i); //~ ERROR `core::kinds::Send` is not implemented
19+
f(i);
20+
//~^ ERROR `core::kinds::Send` is not implemented
21+
//~^^ ERROR `core::kinds::Send` is not implemented
2022
}

src/test/compile-fail/unsendable-class.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ fn foo(i:int, j: Rc<String>) -> foo {
2828

2929
fn main() {
3030
let cat = "kitty".to_string();
31-
let (tx, _) = channel(); //~ ERROR `core::kinds::Send` is not implemented
31+
let (tx, _) = channel();
32+
//~^ ERROR `core::kinds::Send` is not implemented
33+
//~^^ ERROR `core::kinds::Send` is not implemented
3234
tx.send(foo(42, Rc::new(cat)));
3335
}

src/test/run-pass/deriving-bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[deriving(Sync,Send,Copy)]
11+
#[deriving(Copy)]
1212
struct Test;
1313

1414
pub fn main() {}

src/test/run-pass/issue-17718-static-unsafe-interior.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,43 @@
1111
use std::kinds::marker;
1212
use std::cell::UnsafeCell;
1313

14+
struct MyUnsafePack<T>(UnsafeCell<T>);
15+
16+
unsafe impl<T: Send> Sync for MyUnsafePack<T> {}
17+
1418
struct MyUnsafe<T> {
15-
value: UnsafeCell<T>
19+
value: MyUnsafePack<T>
1620
}
1721

1822
impl<T> MyUnsafe<T> {
1923
fn forbidden(&self) {}
2024
}
2125

22-
impl<T: Send> Sync for MyUnsafe<T> {}
26+
unsafe impl<T: Send> Sync for MyUnsafe<T> {}
2327

2428
enum UnsafeEnum<T> {
2529
VariantSafe,
2630
VariantUnsafe(UnsafeCell<T>)
2731
}
2832

29-
impl<T: Send> Sync for UnsafeEnum<T> {}
33+
unsafe impl<T: Send> Sync for UnsafeEnum<T> {}
3034

3135
static STATIC1: UnsafeEnum<int> = UnsafeEnum::VariantSafe;
3236

33-
static STATIC2: UnsafeCell<int> = UnsafeCell { value: 1 };
34-
const CONST: UnsafeCell<int> = UnsafeCell { value: 1 };
37+
static STATIC2: MyUnsafePack<int> = MyUnsafePack(UnsafeCell { value: 1 });
38+
const CONST: MyUnsafePack<int> = MyUnsafePack(UnsafeCell { value: 1 });
3539
static STATIC3: MyUnsafe<int> = MyUnsafe{value: CONST};
3640

37-
static STATIC4: &'static UnsafeCell<int> = &STATIC2;
41+
static STATIC4: &'static MyUnsafePack<int> = &STATIC2;
3842

3943
struct Wrap<T> {
4044
value: T
4145
}
4246

4347
unsafe impl<T: Send> Sync for Wrap<T> {}
4448

45-
static UNSAFE: UnsafeCell<int> = UnsafeCell{value: 1};
46-
static WRAPPED_UNSAFE: Wrap<&'static UnsafeCell<int>> = Wrap { value: &UNSAFE };
49+
static UNSAFE: MyUnsafePack<int> = MyUnsafePack(UnsafeCell{value: 2});
50+
static WRAPPED_UNSAFE: Wrap<&'static MyUnsafePack<int>> = Wrap { value: &UNSAFE };
4751

4852
fn main() {
4953
let a = &STATIC1;

0 commit comments

Comments
 (0)