File tree Expand file tree Collapse file tree 4 files changed +65
-1
lines changed
compiler/rustc_hir_analysis/src/check
tests/ui/field_projections Expand file tree Collapse file tree 4 files changed +65
-1
lines changed Original file line number Diff line number Diff line change @@ -259,6 +259,17 @@ pub(super) fn check_item<'tcx>(
259259 . with_span_label ( sp, "auto trait" )
260260 . emit ( ) ) ;
261261 }
262+ if is_auto && let rustc_hir:: TyKind :: FieldOf ( ..) = impl_. self_ty . kind {
263+ res = res. and ( Err ( tcx
264+ . dcx ( )
265+ . struct_span_err (
266+ item. span ,
267+ "impls of auto traits for field representing types not supported" ,
268+ )
269+ . with_span_label ( impl_. self_ty . span , "field representing type" )
270+ . with_span_label ( of_trait. trait_ref . path . span , "auto trait" )
271+ . emit ( ) ) ) ;
272+ }
262273 match header. polarity {
263274 ty:: ImplPolarity :: Positive => {
264275 res = res. and ( check_impl ( tcx, item, impl_) ) ;
Original file line number Diff line number Diff line change 1+ error: impls of auto traits for field representing types not supported
2+ --> $DIR/send.rs:13:1
3+ |
4+ LL | unsafe impl Send for field_of!(Bar, bar_field) {}
5+ | ^^^^^^^^^^^^----^^^^^-------------------------^^^
6+ | | |
7+ | | field representing type
8+ | auto trait
9+
10+ error[E0277]: `field_of!(Foo, field)` cannot be sent between threads safely
11+ --> $DIR/send.rs:20:15
12+ |
13+ LL | is_send::<field_of!(Foo, field)>();
14+ | ^^^^^^^^^^^^^^^^^^^^^ `field_of!(Foo, field)` cannot be sent between threads safely
15+ |
16+ = help: the trait `Send` is not implemented for `field_of!(Foo, field)`
17+ = help: the trait `Send` is implemented for `field_of!(Bar, bar_field)`
18+ note: required by a bound in `is_send`
19+ --> $DIR/send.rs:16:15
20+ |
21+ LL | fn is_send<T: Send>() {}
22+ | ^^^^ required by this bound in `is_send`
23+
24+ error: aborting due to 2 previous errors
25+
26+ For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change 1+ error: impls of auto traits for field representing types not supported
2+ --> $DIR/send.rs:13:1
3+ |
4+ LL | unsafe impl Send for field_of!(Bar, bar_field) {}
5+ | ^^^^^^^^^^^^----^^^^^-------------------------^^^
6+ | | |
7+ | | field representing type
8+ | auto trait
9+
10+ error[E0277]: `field_of!(Foo, field)` cannot be sent between threads safely
11+ --> $DIR/send.rs:20:15
12+ |
13+ LL | is_send::<field_of!(Foo, field)>();
14+ | ^^^^^^^^^^^^^^^^^^^^^ `field_of!(Foo, field)` cannot be sent between threads safely
15+ |
16+ = help: the trait `Send` is not implemented for `field_of!(Foo, field)`
17+ = help: the trait `Send` is implemented for `field_of!(Bar, bar_field)`
18+ note: required by a bound in `is_send`
19+ --> $DIR/send.rs:16:15
20+ |
21+ LL | fn is_send<T: Send>() {}
22+ | ^^^^ required by this bound in `is_send`
23+
24+ error: aborting due to 2 previous errors
25+
26+ For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change 11//@ revisions: old next
22//@ [next] compile-flags: -Znext-solver
3- //@ run-pass
43#![ feature( field_projections) ]
54#![ allow( incomplete_features) ]
65use std:: field:: field_of;
@@ -12,10 +11,12 @@ struct Bar {
1211 bar_field : u32 ,
1312}
1413unsafe impl Send for field_of ! ( Bar , bar_field) { }
14+ //~^ ERROR: impls of auto traits for field representing types not supported
1515
1616fn is_send < T : Send > ( ) { }
1717
1818fn main ( ) {
1919 is_send :: < field_of ! ( Bar , bar_field) > ( ) ;
2020 is_send :: < field_of ! ( Foo , field) > ( ) ;
21+ //~^ ERROR: `field_of!(Foo, field)` cannot be sent between threads safely [E0277]
2122}
You can’t perform that action at this time.
0 commit comments