Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not ICE on default_field_value const with lifetimes #135711

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::iter;
use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::Diag;
use rustc_hir::BodyOwnerKind;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem;
use rustc_index::IndexVec;
Expand Down Expand Up @@ -603,7 +604,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {

BodyOwnerKind::Const { .. } | BodyOwnerKind::Static(..) => {
let identity_args = GenericArgs::identity_for_item(tcx, typeck_root_def_id);
if self.mir_def.to_def_id() == typeck_root_def_id {
if self.mir_def.to_def_id() == typeck_root_def_id
// Do not ICE when checking default_field_values consts with lifetimes (#135649)
&& DefKind::Field != tcx.def_kind(tcx.parent(typeck_root_def_id))
{
let args =
self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_args);
DefiningTy::Const(self.mir_def.to_def_id(), args)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![feature(default_field_values)]
struct A<'a> { //~ ERROR lifetime parameter `'a` is never used
x: Vec<A> = Vec::new(), //~ ERROR missing lifetime specifier
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0106]: missing lifetime specifier
--> $DIR/do-not-ice-on-invalid-lifetime.rs:3:12
|
LL | x: Vec<A> = Vec::new(),
| ^ expected named lifetime parameter
|
help: consider using the `'a` lifetime
|
LL | x: Vec<A<'a>> = Vec::new(),
| ++++

error[E0392]: lifetime parameter `'a` is never used
--> $DIR/do-not-ice-on-invalid-lifetime.rs:2:10
|
LL | struct A<'a> {
| ^^ unused lifetime parameter
|
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0106, E0392.
For more information about an error, try `rustc --explain E0106`.
Loading