Skip to content

Commit 95b31cf

Browse files
authored
Rollup merge of rust-lang#82494 - estebank:issue-82455, r=petrochenkov
Substitute erased lifetimes on bad placeholder type Fix rust-lang#82455.
2 parents a1f7540 + 5ad6088 commit 95b31cf

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

compiler/rustc_typeck/src/collect.rs

+12
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
371371
span: Span,
372372
) -> &'tcx Const<'tcx> {
373373
bad_placeholder_type(self.tcx(), vec![span]).emit();
374+
// Typeck doesn't expect erased regions to be returned from `type_of`.
375+
let ty = self.tcx.fold_regions(ty, &mut false, |r, _| match r {
376+
ty::ReErased => self.tcx.lifetimes.re_static,
377+
_ => r,
378+
});
374379
self.tcx().const_error(ty)
375380
}
376381

@@ -1647,6 +1652,12 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
16471652
match get_infer_ret_ty(&sig.decl.output) {
16481653
Some(ty) => {
16491654
let fn_sig = tcx.typeck(def_id).liberated_fn_sigs()[hir_id];
1655+
// Typeck doesn't expect erased regions to be returned from `type_of`.
1656+
let fn_sig = tcx.fold_regions(fn_sig, &mut false, |r, _| match r {
1657+
ty::ReErased => tcx.lifetimes.re_static,
1658+
_ => r,
1659+
});
1660+
16501661
let mut visitor = PlaceholderHirTyCollector::default();
16511662
visitor.visit_ty(ty);
16521663
let mut diag = bad_placeholder_type(tcx, visitor.0);
@@ -1675,6 +1686,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
16751686
}
16761687
}
16771688
diag.emit();
1689+
16781690
ty::Binder::bind(fn_sig)
16791691
}
16801692
None => AstConv::ty_of_fn(

src/test/ui/typeck/typeck_type_placeholder_item.rs

+12
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,15 @@ impl Qux for Struct {
208208
const D: _ = 42;
209209
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
210210
}
211+
212+
fn map<T>(_: fn() -> Option<&'static T>) -> Option<T> {
213+
None
214+
}
215+
216+
fn value() -> Option<&'static _> {
217+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
218+
Option::<&'static u8>::None
219+
}
220+
221+
const _: Option<_> = map(value);
222+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures

src/test/ui/typeck/typeck_type_placeholder_item.stderr

+20-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ LL | fn test11(x: &usize) -> &_ {
158158
| -^
159159
| ||
160160
| |not allowed in type signatures
161-
| help: replace with the correct return type: `&&usize`
161+
| help: replace with the correct return type: `&'static &'static usize`
162162

163163
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
164164
--> $DIR/typeck_type_placeholder_item.rs:52:52
@@ -410,6 +410,24 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa
410410
LL | type Y = impl Trait<_>;
411411
| ^ not allowed in type signatures
412412

413+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
414+
--> $DIR/typeck_type_placeholder_item.rs:216:31
415+
|
416+
LL | fn value() -> Option<&'static _> {
417+
| ----------------^-
418+
| | |
419+
| | not allowed in type signatures
420+
| help: replace with the correct return type: `Option<&'static u8>`
421+
422+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
423+
--> $DIR/typeck_type_placeholder_item.rs:221:10
424+
|
425+
LL | const _: Option<_> = map(value);
426+
| ^^^^^^^^^
427+
| |
428+
| not allowed in type signatures
429+
| help: replace `_` with the correct type: `Option<u8>`
430+
413431
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
414432
--> $DIR/typeck_type_placeholder_item.rs:140:31
415433
|
@@ -614,7 +632,7 @@ LL | const D: _ = 42;
614632
| not allowed in type signatures
615633
| help: replace `_` with the correct type: `i32`
616634

617-
error: aborting due to 67 previous errors
635+
error: aborting due to 69 previous errors
618636

619637
Some errors have detailed explanations: E0121, E0282, E0403.
620638
For more information about an error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)