File tree Expand file tree Collapse file tree 6 files changed +56
-9
lines changed
compiler/rustc_hir_analysis Expand file tree Collapse file tree 6 files changed +56
-9
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,9 @@ hir_analysis_cannot_capture_late_bound_lifetime =
65
65
cannot capture late-bound lifetime in { $what }
66
66
.label = lifetime defined here
67
67
68
+ hir_analysis_monomorphization_inherent_impl_for_closure =
69
+ cannot define inherent `impl` for closure types
70
+
68
71
hir_analysis_cannot_capture_late_bound_ty =
69
72
cannot capture late-bound type parameter in { $what }
70
73
.label = parameter defined here
Original file line number Diff line number Diff line change @@ -195,11 +195,10 @@ impl<'tcx> InherentCollect<'tcx> {
195
195
| ty:: Closure ( ..)
196
196
| ty:: CoroutineClosure ( ..)
197
197
| ty:: Coroutine ( ..)
198
- | ty:: CoroutineWitness ( ..)
199
- | ty:: Alias ( ty:: Free , _)
200
- | ty:: Bound ( ..)
201
- | ty:: Placeholder ( _)
202
- | ty:: Infer ( _) => {
198
+ | ty:: CoroutineWitness ( ..) => {
199
+ Err ( self . tcx . dcx ( ) . emit_err ( errors:: InherentImplForClosure { span : item_span } ) )
200
+ }
201
+ ty:: Alias ( ty:: Free , _) | ty:: Bound ( ..) | ty:: Placeholder ( _) | ty:: Infer ( _) => {
203
202
bug ! ( "unexpected impl self type of impl: {:?} {:?}" , id, self_ty) ;
204
203
}
205
204
// We could bail out here, but that will silence other useful errors.
Original file line number Diff line number Diff line change @@ -230,10 +230,12 @@ pub(crate) fn orphan_check_impl(
230
230
ty:: Closure ( ..)
231
231
| ty:: CoroutineClosure ( ..)
232
232
| ty:: Coroutine ( ..)
233
- | ty:: CoroutineWitness ( ..)
234
- | ty:: Bound ( ..)
235
- | ty:: Placeholder ( ..)
236
- | ty:: Infer ( ..) => {
233
+ | ty:: CoroutineWitness ( ..) => {
234
+ return Err ( tcx
235
+ . dcx ( )
236
+ . emit_err ( errors:: InherentImplForClosure { span : tcx. def_span ( impl_def_id) } ) ) ;
237
+ }
238
+ ty:: Bound ( ..) | ty:: Placeholder ( ..) | ty:: Infer ( ..) => {
237
239
let sp = tcx. def_span ( impl_def_id) ;
238
240
span_bug ! ( sp, "weird self type for autotrait impl" )
239
241
}
Original file line number Diff line number Diff line change @@ -59,6 +59,13 @@ pub(crate) struct AssocKindMismatchWrapInBracesSugg {
59
59
pub hi : Span ,
60
60
}
61
61
62
+ #[ derive( Diagnostic ) ]
63
+ #[ diag( hir_analysis_monomorphization_inherent_impl_for_closure) ]
64
+ pub struct InherentImplForClosure {
65
+ #[ primary_span]
66
+ pub span : Span ,
67
+ }
68
+
62
69
#[ derive( Diagnostic ) ]
63
70
#[ diag( hir_analysis_assoc_item_is_private, code = E0624 ) ]
64
71
pub ( crate ) struct AssocItemIsPrivate {
Original file line number Diff line number Diff line change
1
+ impl typeof ( || { } ) { }
2
+ //~^ ERROR `typeof` is a reserved keyword but unimplemented
3
+ //~| ERROR cannot define inherent `impl` for closure types
4
+
5
+ unsafe impl Send for typeof ( || { } ) { }
6
+ //~^ ERROR `typeof` is a reserved keyword but unimplemented
7
+ //~| ERROR cannot define inherent `impl` for closure types
8
+
9
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0516]: `typeof` is a reserved keyword but unimplemented
2
+ --> $DIR/impl-closure-147146.rs:1:6
3
+ |
4
+ LL | impl typeof(|| {}) {}
5
+ | ^^^^^^^^^^^^^ reserved keyword
6
+
7
+ error[E0516]: `typeof` is a reserved keyword but unimplemented
8
+ --> $DIR/impl-closure-147146.rs:5:22
9
+ |
10
+ LL | unsafe impl Send for typeof(|| {}) {}
11
+ | ^^^^^^^^^^^^^ reserved keyword
12
+
13
+ error: cannot define inherent `impl` for closure types
14
+ --> $DIR/impl-closure-147146.rs:5:1
15
+ |
16
+ LL | unsafe impl Send for typeof(|| {}) {}
17
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18
+
19
+ error: cannot define inherent `impl` for closure types
20
+ --> $DIR/impl-closure-147146.rs:1:1
21
+ |
22
+ LL | impl typeof(|| {}) {}
23
+ | ^^^^^^^^^^^^^^^^^^
24
+
25
+ error: aborting due to 4 previous errors
26
+
27
+ For more information about this error, try `rustc --explain E0516`.
You can’t perform that action at this time.
0 commit comments