Skip to content

Commit 6d8a173

Browse files
committed
Reword E0044 and message for !Send types
- Reword E0044 help. - Change error message for types that don't implement `Send`
1 parent 883e746 commit 6d8a173

26 files changed

+66
-55
lines changed

src/libcore/marker.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,10 @@ pub trait Copy : Clone {
343343
/// [transmute]: ../../std/mem/fn.transmute.html
344344
#[stable(feature = "rust1", since = "1.0.0")]
345345
#[lang = "sync"]
346-
#[rustc_on_unimplemented = "`{Self}` cannot be shared between threads safely"]
346+
#[rustc_on_unimplemented(
347+
message="`{Self}` cannot be shared between threads safely",
348+
label="`{Self}` cannot be shared between threads safely"
349+
)]
347350
pub unsafe auto trait Sync {
348351
// Empty
349352
}

src/librustc_typeck/check/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,9 +1222,10 @@ pub fn check_item_type<'a,'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Item
12221222
if !generics.types.is_empty() {
12231223
let mut err = struct_span_err!(tcx.sess, item.span, E0044,
12241224
"foreign items may not have type parameters");
1225-
span_help!(&mut err, item.span,
1226-
"consider using specialization instead of \
1227-
type parameters");
1225+
// FIXME: once we start storing spans for type arguments, turn this into a
1226+
// suggestion.
1227+
err.help("use specialization instead of type parameters by replacing them \
1228+
with concrete types like `u32`");
12281229
err.emit();
12291230
}
12301231

src/test/compile-fail/builtin-superkinds-double-superkind.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313

1414
trait Foo : Send+Sync { }
1515

16-
impl <T: Sync+'static> Foo for (T,) { } //~ ERROR `T: std::marker::Send` is not satisfied
16+
impl <T: Sync+'static> Foo for (T,) { }
17+
//~^ ERROR the trait bound `T: std::marker::Send` is not satisfied in `(T,)` [E0277]
1718

18-
impl <T: Send> Foo for (T,T) { } //~ ERROR `T: std::marker::Sync` is not satisfied
19+
impl <T: Send> Foo for (T,T) { }
20+
//~^ ERROR `T` cannot be shared between threads safely [E0277]
1921

2022
impl <T: Send+Sync> Foo for (T,T,T) { } // (ok)
2123

src/test/compile-fail/closure-bounds-subtype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn give_any<F>(f: F) where F: FnOnce() {
2121

2222
fn give_owned<F>(f: F) where F: FnOnce() + Send {
2323
take_any(f);
24-
take_const_owned(f); //~ ERROR `F: std::marker::Sync` is not satisfied
24+
take_const_owned(f); //~ ERROR `F` cannot be shared between threads safely [E0277]
2525
}
2626

2727
fn main() {}

src/test/compile-fail/extern-types-not-sync-send.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn assert_send<T: ?Sized + Send>() { }
2121

2222
fn main() {
2323
assert_sync::<A>();
24-
//~^ ERROR the trait bound `A: std::marker::Sync` is not satisfied
24+
//~^ ERROR `A` cannot be shared between threads safely [E0277]
2525

2626
assert_send::<A>();
2727
//~^ ERROR the trait bound `A: std::marker::Send` is not satisfied

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod Y {
2121
}
2222

2323
static foo: *const Y::X = Y::foo(Y::x as *const Y::X);
24-
//~^ ERROR `*const usize: std::marker::Sync` is not satisfied
24+
//~^ ERROR `*const usize` cannot be shared between threads safely [E0277]
2525
//~| ERROR cannot refer to other statics by value, use the address-of operator or a constant instead
2626
//~| ERROR E0015
2727

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ impl !Sync for Foo {}
1717

1818
static FOO: usize = 3;
1919
static BAR: Foo = Foo;
20-
//~^ ERROR: `Foo: std::marker::Sync` is not satisfied
20+
//~^ ERROR: `Foo` cannot be shared between threads safely [E0277]
2121

2222
fn main() {}

src/test/compile-fail/issue-43733-2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<T> Key<T> {
3333
use std::thread::__FastLocalKeyInner as Key;
3434

3535
static __KEY: Key<()> = Key::new();
36-
//~^ ERROR `std::cell::UnsafeCell<std::option::Option<()>>: std::marker::Sync` is not satisfied
37-
//~| ERROR `std::cell::Cell<bool>: std::marker::Sync` is not satisfied
36+
//~^ ERROR `std::cell::UnsafeCell<std::option::Option<()>>` cannot be shared between threads
37+
//~| ERROR `std::cell::Cell<bool>` cannot be shared between threads safely [E0277]
3838

3939
fn main() {}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ use std::cell::RefCell;
1515
// Regression test for issue 7364
1616
static boxed: Box<RefCell<isize>> = box RefCell::new(0);
1717
//~^ ERROR allocations are not allowed in statics
18-
//~| ERROR `std::cell::RefCell<isize>: std::marker::Sync` is not satisfied
18+
//~| ERROR `std::cell::RefCell<isize>` cannot be shared between threads safely [E0277]
1919

2020
fn main() { }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait Message : Send { }
2020

2121
fn object_ref_with_static_bound_not_ok() {
2222
assert_send::<&'static (Dummy+'static)>();
23-
//~^ ERROR : std::marker::Sync` is not satisfied
23+
//~^ ERROR `Dummy + 'static` cannot be shared between threads safely [E0277]
2424
}
2525

2626
fn box_object_with_no_bound_not_ok<'a>() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait Dummy { }
1818
// careful with object types, who knows what they close over...
1919
fn test51<'a>() {
2020
assert_send::<&'a Dummy>();
21-
//~^ ERROR : std::marker::Sync` is not satisfied
21+
//~^ ERROR `Dummy + 'a` cannot be shared between threads safely [E0277]
2222
}
2323
fn test52<'a>() {
2424
assert_send::<&'a (Dummy+Sync)>();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ fn assert_send<T:Send>() { }
1414
trait Dummy { }
1515

1616
fn test50() {
17-
assert_send::<&'static Dummy>(); //~ ERROR : std::marker::Sync` is not satisfied
17+
assert_send::<&'static Dummy>();
18+
//~^ ERROR `Dummy + 'static` cannot be shared between threads safely [E0277]
1819
}
1920

2021
fn test53() {

src/test/compile-fail/mutable-enum-indirect.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ fn bar<T: Sync>(_: T) {}
2424

2525
fn main() {
2626
let x = Foo::A(NoSync);
27-
bar(&x); //~ ERROR `NoSync: std::marker::Sync` is not satisfied
27+
bar(&x);
28+
//~^ ERROR `NoSync` cannot be shared between threads safely [E0277]
2829
}

src/test/compile-fail/mutexguard-sync.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ fn main()
1818
{
1919
let m = Mutex::new(Cell::new(0i32));
2020
let guard = m.lock().unwrap();
21-
test_sync(guard); //~ ERROR the trait bound
21+
test_sync(guard);
22+
//~^ ERROR `std::cell::Cell<i32>` cannot be shared between threads safely [E0277]
2223
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ fn bar<T: Sync>(_: T) {}
2222
fn main() {
2323
let x = Foo::A(NoSync);
2424
bar(x);
25-
//~^ ERROR `NoSync: std::marker::Sync` is not satisfied
25+
//~^ ERROR `NoSync` cannot be shared between threads safely [E0277]
2626
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ fn bar<T: Sync>(_: T) {}
2020
fn main() {
2121
let x = Foo { a: 5 };
2222
bar(x);
23-
//~^ ERROR `Foo: std::marker::Sync` is not satisfied
23+
//~^ ERROR `Foo` cannot be shared between threads safely [E0277]
2424
}

src/test/compile-fail/not-sync.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ fn test<T: Sync>() {}
1616

1717
fn main() {
1818
test::<Cell<i32>>();
19-
//~^ ERROR `std::cell::Cell<i32>: std::marker::Sync` is not satisfied
19+
//~^ ERROR `std::cell::Cell<i32>` cannot be shared between threads safely [E0277]
2020
test::<RefCell<i32>>();
21-
//~^ ERROR `std::cell::RefCell<i32>: std::marker::Sync` is not satisfied
21+
//~^ ERROR `std::cell::RefCell<i32>` cannot be shared between threads safely [E0277]
2222

2323
test::<Rc<i32>>();
24-
//~^ ERROR `std::rc::Rc<i32>: std::marker::Sync` is not satisfied
24+
//~^ ERROR `std::rc::Rc<i32>` cannot be shared between threads safely [E0277]
2525
test::<Weak<i32>>();
26-
//~^ ERROR `std::rc::Weak<i32>: std::marker::Sync` is not satisfied
26+
//~^ ERROR `std::rc::Weak<i32>` cannot be shared between threads safely [E0277]
2727

2828
test::<Receiver<i32>>();
29-
//~^ ERROR `std::sync::mpsc::Receiver<i32>: std::marker::Sync` is not satisfied
29+
//~^ ERROR `std::sync::mpsc::Receiver<i32>` cannot be shared between threads safely [E0277]
3030
test::<Sender<i32>>();
31-
//~^ ERROR `std::sync::mpsc::Sender<i32>: std::marker::Sync` is not satisfied
31+
//~^ ERROR `std::sync::mpsc::Sender<i32>` cannot be shared between threads safely [E0277]
3232
}

src/test/compile-fail/phantom-oibit.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ struct Nested<T>(T);
2828
fn is_zen<T: Zen>(_: T) {}
2929

3030
fn not_sync<T>(x: Guard<T>) {
31-
is_zen(x) //~ error: `T: std::marker::Sync` is not satisfied
31+
is_zen(x)
32+
//~^ ERROR `T` cannot be shared between threads safely [E0277]
3233
}
3334

3435
fn nested_not_sync<T>(x: Nested<Guard<T>>) {
35-
is_zen(x) //~ error: `T: std::marker::Sync` is not satisfied
36+
is_zen(x)
37+
//~^ ERROR `T` cannot be shared between threads safely [E0277]
3638
}
3739

3840
fn main() {}

src/test/compile-fail/typeck-default-trait-impl-negation-sync.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ fn is_sync<T: Sync>() {}
4343
fn main() {
4444
is_sync::<MySync>();
4545
is_sync::<MyNotSync>();
46-
//~^ ERROR `MyNotSync: std::marker::Sync` is not satisfied
46+
//~^ ERROR `MyNotSync` cannot be shared between threads safely [E0277]
4747

4848
is_sync::<MyTypeWUnsafe>();
49-
//~^ ERROR `std::cell::UnsafeCell<u8>: std::marker::Sync` is not satisfied
49+
//~^ ERROR `std::cell::UnsafeCell<u8>` cannot be shared between threads safely [E0277]
5050

5151
is_sync::<MyTypeManaged>();
52-
//~^ ERROR `Managed: std::marker::Sync` is not satisfied
52+
//~^ ERROR `Managed` cannot be shared between threads safely [E0277]
5353
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ fn test<T: Sync>(s: T) {}
2727
fn main() {
2828
let us = UnsafeCell::new(MySync{u: UnsafeCell::new(0)});
2929
test(us);
30-
//~^ ERROR `std::cell::UnsafeCell<MySync<{integer}>>: std::marker::Sync` is not satisfied
30+
//~^ ERROR `std::cell::UnsafeCell<MySync<{integer}>>` cannot be shared between threads safely
3131

3232
let uns = UnsafeCell::new(NoSync);
3333
test(uns);
34-
//~^ ERROR `std::cell::UnsafeCell<NoSync>: std::marker::Sync` is not satisfied
34+
//~^ ERROR `std::cell::UnsafeCell<NoSync>` cannot be shared between threads safely [E0277]
3535

3636
let ms = MySync{u: uns};
3737
test(ms);
38-
//~^ ERROR `std::cell::UnsafeCell<NoSync>: std::marker::Sync` is not satisfied
38+
//~^ ERROR `std::cell::UnsafeCell<NoSync>` cannot be shared between threads safely [E0277]
3939

4040
test(NoSync);
41-
//~^ ERROR `NoSync: std::marker::Sync` is not satisfied
41+
//~^ ERROR `NoSync` cannot be shared between threads safely [E0277]
4242
}

src/test/ui/error-codes/E0044.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,7 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
extern { fn some_func<T>(x: T); } //~ ERROR E0044
11+
extern {
12+
fn sqrt<T>(f: T) -> T;
13+
//~^ ERROR foreign items may not have type parameters [E0044]
14+
//~| HELP use specialization instead of type parameters by replacing them with concrete types
15+
}
1216

1317
fn main() {
1418
}

src/test/ui/error-codes/E0044.stderr

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
error[E0044]: foreign items may not have type parameters
2-
--> $DIR/E0044.rs:11:10
2+
--> $DIR/E0044.rs:12:5
33
|
4-
LL | extern { fn some_func<T>(x: T); } //~ ERROR E0044
5-
| ^^^^^^^^^^^^^^^^^^^^^^
4+
LL | fn sqrt<T>(f: T) -> T;
5+
| ^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
help: consider using specialization instead of type parameters
8-
--> $DIR/E0044.rs:11:10
9-
|
10-
LL | extern { fn some_func<T>(x: T); } //~ ERROR E0044
11-
| ^^^^^^^^^^^^^^^^^^^^^^
7+
= help: use specialization instead of type parameters by replacing them with concrete types like `u32`
128

139
error: aborting due to previous error
1410

src/test/ui/fmt/send-sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ fn main() {
1515
// `Cell` is not `Sync`, so `&Cell` is neither `Sync` nor `Send`,
1616
// `std::fmt::Arguments` used to forget this...
1717
let c = std::cell::Cell::new(42);
18-
send(format_args!("{:?}", c)); //~ ERROR Sync` is not satisfied
19-
sync(format_args!("{:?}", c)); //~ ERROR Sync` is not satisfied
18+
send(format_args!("{:?}", c)); //~ ERROR E0277
19+
sync(format_args!("{:?}", c)); //~ ERROR E0277
2020
}

src/test/ui/fmt/send-sync.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error[E0277]: the trait bound `*mut std::ops::Fn() + 'static: std::marker::Sync` is not satisfied in `[std::fmt::ArgumentV1<'_>]`
1+
error[E0277]: `*mut std::ops::Fn() + 'static` cannot be shared between threads safely
22
--> $DIR/send-sync.rs:18:5
33
|
4-
LL | send(format_args!("{:?}", c)); //~ ERROR Sync` is not satisfied
4+
LL | send(format_args!("{:?}", c)); //~ ERROR E0277
55
| ^^^^ `*mut std::ops::Fn() + 'static` cannot be shared between threads safely
66
|
77
= help: within `[std::fmt::ArgumentV1<'_>]`, the trait `std::marker::Sync` is not implemented for `*mut std::ops::Fn() + 'static`
@@ -18,10 +18,10 @@ note: required by `send`
1818
LL | fn send<T: Send>(_: T) {}
1919
| ^^^^^^^^^^^^^^^^^^^^^^
2020

21-
error[E0277]: the trait bound `*mut std::ops::Fn() + 'static: std::marker::Sync` is not satisfied in `std::fmt::Arguments<'_>`
21+
error[E0277]: `*mut std::ops::Fn() + 'static` cannot be shared between threads safely
2222
--> $DIR/send-sync.rs:19:5
2323
|
24-
LL | sync(format_args!("{:?}", c)); //~ ERROR Sync` is not satisfied
24+
LL | sync(format_args!("{:?}", c)); //~ ERROR E0277
2525
| ^^^^ `*mut std::ops::Fn() + 'static` cannot be shared between threads safely
2626
|
2727
= help: within `std::fmt::Arguments<'_>`, the trait `std::marker::Sync` is not implemented for `*mut std::ops::Fn() + 'static`

src/test/ui/generator/not-send-sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ fn main() {
1717
fn assert_send<T: Send>(_: T) {}
1818

1919
assert_sync(|| {
20-
//~^ ERROR: Sync` is not satisfied
20+
//~^ ERROR: E0277
2121
let a = Cell::new(2);
2222
yield;
2323
});
2424

2525
let a = Cell::new(2);
2626
assert_send(|| {
27-
//~^ ERROR: Sync` is not satisfied
27+
//~^ ERROR: E0277
2828
drop(&a);
2929
yield;
3030
});

src/test/ui/generator/not-send-sync.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0277]: the trait bound `std::cell::Cell<i32>: std::marker::Sync` is not satisfied
1+
error[E0277]: `std::cell::Cell<i32>` cannot be shared between threads safely
22
--> $DIR/not-send-sync.rs:26:5
33
|
44
LL | assert_send(|| {
@@ -13,7 +13,7 @@ note: required by `main::assert_send`
1313
LL | fn assert_send<T: Send>(_: T) {}
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515

16-
error[E0277]: the trait bound `std::cell::Cell<i32>: std::marker::Sync` is not satisfied in `[generator@$DIR/not-send-sync.rs:19:17: 23:6 {std::cell::Cell<i32>, ()}]`
16+
error[E0277]: `std::cell::Cell<i32>` cannot be shared between threads safely
1717
--> $DIR/not-send-sync.rs:19:5
1818
|
1919
LL | assert_sync(|| {

0 commit comments

Comments
 (0)