Skip to content

Commit 7edd17c

Browse files
authored
Rollup merge of rust-lang#135711 - estebank:issue-135649, r=davidtwco
Do not ICE on default_field_value const with lifetimes `#![feature(default_field_values)]` uses a `const` body that should be treated as inline `const`s, but is actually being detected otherwise. This is similar to the situation in rust-lang#78174, so we take the same solution: we check if the const actually comes from a field, and if it does, we use that logic to get the appropriate lifetimes and not ICE during borrowck. Fix rust-lang#135649.
2 parents 3b022d8 + 08ee5f5 commit 7edd17c

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

compiler/rustc_borrowck/src/universal_regions.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::iter;
2121
use rustc_data_structures::fx::FxIndexMap;
2222
use rustc_errors::Diag;
2323
use rustc_hir::BodyOwnerKind;
24+
use rustc_hir::def::DefKind;
2425
use rustc_hir::def_id::{DefId, LocalDefId};
2526
use rustc_hir::lang_items::LangItem;
2627
use rustc_index::IndexVec;
@@ -603,7 +604,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
603604

604605
BodyOwnerKind::Const { .. } | BodyOwnerKind::Static(..) => {
605606
let identity_args = GenericArgs::identity_for_item(tcx, typeck_root_def_id);
606-
if self.mir_def.to_def_id() == typeck_root_def_id {
607+
if self.mir_def.to_def_id() == typeck_root_def_id
608+
// Do not ICE when checking default_field_values consts with lifetimes (#135649)
609+
&& DefKind::Field != tcx.def_kind(tcx.parent(typeck_root_def_id))
610+
{
607611
let args =
608612
self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_args);
609613
DefiningTy::Const(self.mir_def.to_def_id(), args)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![feature(default_field_values)]
2+
struct A<'a> { //~ ERROR lifetime parameter `'a` is never used
3+
x: Vec<A> = Vec::new(), //~ ERROR missing lifetime specifier
4+
}
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0106]: missing lifetime specifier
2+
--> $DIR/do-not-ice-on-invalid-lifetime.rs:3:12
3+
|
4+
LL | x: Vec<A> = Vec::new(),
5+
| ^ expected named lifetime parameter
6+
|
7+
help: consider using the `'a` lifetime
8+
|
9+
LL | x: Vec<A<'a>> = Vec::new(),
10+
| ++++
11+
12+
error[E0392]: lifetime parameter `'a` is never used
13+
--> $DIR/do-not-ice-on-invalid-lifetime.rs:2:10
14+
|
15+
LL | struct A<'a> {
16+
| ^^ unused lifetime parameter
17+
|
18+
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`
19+
20+
error: aborting due to 2 previous errors
21+
22+
Some errors have detailed explanations: E0106, E0392.
23+
For more information about an error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)