Skip to content

Commit ae60ebd

Browse files
authored
Rollup merge of rust-lang#147219 - Kivooeo:typeof-is-imposter, r=jdonszelmann
Add proper error handling for closure in impl Fixes rust-lang#147146 Fixes rust-lang#146620 Not sure if it can cause any regressions or anything, as for test also have no idea where to store this one cc ```@theemathas``` r? compiler
2 parents 4b905f9 + b810a68 commit ae60ebd

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,10 @@ impl<'tcx> InherentCollect<'tcx> {
195195
| ty::Closure(..)
196196
| ty::CoroutineClosure(..)
197197
| 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().delayed_bug("cannot define inherent `impl` for closure types"))
200+
}
201+
ty::Alias(ty::Free, _) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) => {
203202
bug!("unexpected impl self type of impl: {:?} {:?}", id, self_ty);
204203
}
205204
// We could bail out here, but that will silence other useful errors.

compiler/rustc_hir_analysis/src/coherence/orphan.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,12 @@ pub(crate) fn orphan_check_impl(
230230
ty::Closure(..)
231231
| ty::CoroutineClosure(..)
232232
| ty::Coroutine(..)
233-
| ty::CoroutineWitness(..)
234-
| ty::Bound(..)
235-
| ty::Placeholder(..)
236-
| ty::Infer(..) => {
233+
| ty::CoroutineWitness(..) => {
234+
return Err(tcx
235+
.dcx()
236+
.delayed_bug("cannot define inherent `impl` for closure types"));
237+
}
238+
ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) => {
237239
let sp = tcx.def_span(impl_def_id);
238240
span_bug!(sp, "weird self type for autotrait impl")
239241
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
impl typeof(|| {}) {}
2+
//~^ ERROR `typeof` is a reserved keyword but unimplemented
3+
4+
unsafe impl Send for typeof(|| {}) {}
5+
//~^ ERROR `typeof` is a reserved keyword but unimplemented
6+
7+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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:4:22
9+
|
10+
LL | unsafe impl Send for typeof(|| {}) {}
11+
| ^^^^^^^^^^^^^ reserved keyword
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0516`.

0 commit comments

Comments
 (0)