Skip to content

Commit 50139d2

Browse files
committed
alternate solution
1 parent 130e5e3 commit 50139d2

File tree

3 files changed

+8
-27
lines changed

3 files changed

+8
-27
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ use rustc_middle::ty::TypeVisitor;
2727
use rustc_middle::ty::{self, RegionVid, Ty};
2828
use rustc_middle::ty::{Region, TyCtxt};
2929
use rustc_span::symbol::{kw, Ident};
30-
use rustc_span::{Span, DUMMY_SP};
30+
use rustc_span::{Span, Symbol, DUMMY_SP};
3131

3232
use crate::borrowck_errors;
3333
use crate::session_diagnostics::{
3434
FnMutError, FnMutReturnTypeErr, GenericDoesNotLiveLongEnough, LifetimeOutliveErr,
3535
LifetimeReturnCategoryErr, RequireStaticErr, VarHereDenote,
3636
};
3737

38-
use super::{OutlivesSuggestionBuilder, RegionName};
38+
use super::{OutlivesSuggestionBuilder, RegionName, RegionNameSource};
3939
use crate::region_infer::{BlameConstraint, ExtraConstraintInfo};
4040
use crate::{
4141
nll::ConstraintDescription,
@@ -763,7 +763,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
763763
let err = LifetimeOutliveErr { span: *span };
764764
let mut diag = self.infcx.tcx.sess.create_err(err);
765765

766-
let fr_name = self.give_region_a_name(*fr).unwrap();
766+
// If we can't find name here we just make it up to avoid ICEs.
767+
let fr_name = self
768+
.give_region_a_name(*fr)
769+
.unwrap_or(RegionName { name: Symbol::intern("'_"), source: RegionNameSource::Static });
767770
fr_name.highlight_region_name(&mut diag);
768771
let outlived_fr_name = self.give_region_a_name(*outlived_fr).unwrap();
769772
outlived_fr_name.highlight_region_name(&mut diag);

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+2-21
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
258258
.or_else(|| self.give_name_if_anonymous_region_appears_in_output(fr))
259259
.or_else(|| self.give_name_if_anonymous_region_appears_in_yield_ty(fr))
260260
.or_else(|| self.give_name_if_anonymous_region_appears_in_impl_signature(fr))
261-
.or_else(|| self.give_name_if_anonymous_region_appears_in_arg_position_impl_trait(fr))
262-
.or_else(|| self.give_name_if_anonymous_region_appears_in_early_param(fr));
261+
.or_else(|| self.give_name_if_anonymous_region_appears_in_arg_position_impl_trait(fr));
262+
263263
if let Some(value) = &value {
264264
self.region_names.try_borrow_mut().unwrap().insert(fr, value.clone());
265265
}
@@ -966,23 +966,4 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
966966
}
967967
})
968968
}
969-
970-
fn give_name_if_anonymous_region_appears_in_early_param(
971-
&self,
972-
fr: RegionVid,
973-
) -> Option<RegionName> {
974-
let error_region = self.to_error_region(fr)?;
975-
let tcx = self.infcx.tcx;
976-
977-
match *error_region {
978-
ty::ReEarlyParam(ebr) => {
979-
let span = tcx.hir().span_if_local(ebr.def_id).unwrap_or(DUMMY_SP);
980-
Some(RegionName {
981-
name: ebr.name,
982-
source: RegionNameSource::NamedEarlyParamRegion(span),
983-
})
984-
}
985-
_ => None,
986-
}
987-
}
988969
}

tests/ui/borrowck/generic_const_early_param.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ LL | #![feature(generic_const_exprs)]
3333
error: lifetime may not live long enough
3434
--> $DIR/generic_const_early_param.rs:6:20
3535
|
36-
LL | struct DataWrapper<'static> {
37-
| ------- lifetime `'_` defined here
38-
LL |
3936
LL | data: &'a [u8; Self::SIZE],
4037
| ^^^^^^^^^^ requires that `'_` must outlive `'static`
4138

0 commit comments

Comments
 (0)