Skip to content

Commit

Permalink
alternate solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ouz-a committed Nov 20, 2023
1 parent 130e5e3 commit 50139d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
9 changes: 6 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 27,15 @@ use rustc_middle::ty::TypeVisitor;
use rustc_middle::ty::{self, RegionVid, Ty};
use rustc_middle::ty::{Region, TyCtxt};
use rustc_span::symbol::{kw, Ident};
use rustc_span::{Span, DUMMY_SP};
use rustc_span::{Span, Symbol, DUMMY_SP};

use crate::borrowck_errors;
use crate::session_diagnostics::{
FnMutError, FnMutReturnTypeErr, GenericDoesNotLiveLongEnough, LifetimeOutliveErr,
LifetimeReturnCategoryErr, RequireStaticErr, VarHereDenote,
};

use super::{OutlivesSuggestionBuilder, RegionName};
use super::{OutlivesSuggestionBuilder, RegionName, RegionNameSource};
use crate::region_infer::{BlameConstraint, ExtraConstraintInfo};
use crate::{
nll::ConstraintDescription,
Expand Down Expand Up @@ -763,7 763,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let err = LifetimeOutliveErr { span: *span };
let mut diag = self.infcx.tcx.sess.create_err(err);

let fr_name = self.give_region_a_name(*fr).unwrap();
// If we can't find name here we just make it up to avoid ICEs.
let fr_name = self
.give_region_a_name(*fr)
.unwrap_or(RegionName { name: Symbol::intern("'_"), source: RegionNameSource::Static });
fr_name.highlight_region_name(&mut diag);
let outlived_fr_name = self.give_region_a_name(*outlived_fr).unwrap();
outlived_fr_name.highlight_region_name(&mut diag);
Expand Down
23 changes: 2 additions & 21 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 258,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
.or_else(|| self.give_name_if_anonymous_region_appears_in_output(fr))
.or_else(|| self.give_name_if_anonymous_region_appears_in_yield_ty(fr))
.or_else(|| self.give_name_if_anonymous_region_appears_in_impl_signature(fr))
.or_else(|| self.give_name_if_anonymous_region_appears_in_arg_position_impl_trait(fr))
.or_else(|| self.give_name_if_anonymous_region_appears_in_early_param(fr));
.or_else(|| self.give_name_if_anonymous_region_appears_in_arg_position_impl_trait(fr));

if let Some(value) = &value {
self.region_names.try_borrow_mut().unwrap().insert(fr, value.clone());
}
Expand Down Expand Up @@ -966,23 966,4 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
}
})
}

fn give_name_if_anonymous_region_appears_in_early_param(
&self,
fr: RegionVid,
) -> Option<RegionName> {
let error_region = self.to_error_region(fr)?;
let tcx = self.infcx.tcx;

match *error_region {
ty::ReEarlyParam(ebr) => {
let span = tcx.hir().span_if_local(ebr.def_id).unwrap_or(DUMMY_SP);
Some(RegionName {
name: ebr.name,
source: RegionNameSource::NamedEarlyParamRegion(span),
})
}
_ => None,
}
}
}
3 changes: 0 additions & 3 deletions tests/ui/borrowck/generic_const_early_param.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 33,6 @@ LL | #![feature(generic_const_exprs)]
error: lifetime may not live long enough
--> $DIR/generic_const_early_param.rs:6:20
|
LL | struct DataWrapper<'static> {
| ------- lifetime `'_` defined here
LL |
LL | data: &'a [u8; Self::SIZE],
| ^^^^^^^^^^ requires that `'_` must outlive `'static`

Expand Down

0 comments on commit 50139d2

Please sign in to comment.