Skip to content

Commit 7425663

Browse files
committed
Auto merge of #57901 - lqd:issue_57362, r=nikomatsakis
Add information to higher-ranked lifetimes conflicts error messages Make these errors go through the new "placeholder error" code path, to have self tys displayed and make them hopefully less confusing. Should fix #57362. r? @nikomatsakis — so we can iterate on the specific wording you wanted.
2 parents ae1ba15 + c97d135 commit 7425663

27 files changed

+427
-216
lines changed

src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
4646
let (span, sub, sup) = self.get_regions();
4747

4848
// Determine whether the sub and sup consist of both anonymous (elided) regions.
49-
let anon_reg_sup = self.tcx.is_suitable_region(sup)?;
49+
let anon_reg_sup = self.tcx().is_suitable_region(sup)?;
5050

51-
let anon_reg_sub = self.tcx.is_suitable_region(sub)?;
51+
let anon_reg_sub = self.tcx().is_suitable_region(sub)?;
5252
let scope_def_id_sup = anon_reg_sup.def_id;
5353
let bregion_sup = anon_reg_sup.boundregion;
5454
let scope_def_id_sub = anon_reg_sub.def_id;
@@ -138,7 +138,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
138138
};
139139

140140

141-
struct_span_err!(self.tcx.sess, span, E0623, "lifetime mismatch")
141+
struct_span_err!(self.tcx().sess, span, E0623, "lifetime mismatch")
142142
.span_label(span_1, main_label)
143143
.span_label(span_2, String::new())
144144
.span_label(span, span_label)

src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
2626
region: Region<'tcx>,
2727
br: &ty::BoundRegion,
2828
) -> Option<(&hir::Ty, &hir::FnDecl)> {
29-
if let Some(anon_reg) = self.tcx.is_suitable_region(region) {
29+
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
3030
let def_id = anon_reg.def_id;
31-
if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) {
32-
let fndecl = match self.tcx.hir().get(node_id) {
31+
if let Some(node_id) = self.tcx().hir().as_local_node_id(def_id) {
32+
let fndecl = match self.tcx().hir().get(node_id) {
3333
Node::Item(&hir::Item {
3434
node: hir::ItemKind::Fn(ref fndecl, ..),
3535
..
@@ -64,7 +64,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
6464
br: &ty::BoundRegion,
6565
) -> Option<(&'gcx hir::Ty)> {
6666
let mut nested_visitor = FindNestedTypeVisitor {
67-
tcx: self.tcx,
67+
tcx: self.tcx(),
6868
bound_region: *br,
6969
found_type: None,
7070
current_index: ty::INNERMOST,

src/librustc/infer/error_reporting/nice_region_error/mod.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,41 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
2222

2323
if let Some(tables) = self.in_progress_tables {
2424
let tables = tables.borrow();
25-
NiceRegionError::new(self.tcx, error.clone(), Some(&tables)).try_report().is_some()
25+
NiceRegionError::new(self, error.clone(), Some(&tables)).try_report().is_some()
2626
} else {
27-
NiceRegionError::new(self.tcx, error.clone(), None).try_report().is_some()
27+
NiceRegionError::new(self, error.clone(), None).try_report().is_some()
2828
}
2929
}
3030
}
3131

3232
pub struct NiceRegionError<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
33-
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
33+
infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
3434
error: Option<RegionResolutionError<'tcx>>,
3535
regions: Option<(Span, ty::Region<'tcx>, ty::Region<'tcx>)>,
3636
tables: Option<&'cx ty::TypeckTables<'tcx>>,
3737
}
3838

3939
impl<'cx, 'gcx, 'tcx> NiceRegionError<'cx, 'gcx, 'tcx> {
4040
pub fn new(
41-
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
41+
infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
4242
error: RegionResolutionError<'tcx>,
4343
tables: Option<&'cx ty::TypeckTables<'tcx>>,
4444
) -> Self {
45-
Self { tcx, error: Some(error), regions: None, tables }
45+
Self { infcx, error: Some(error), regions: None, tables }
4646
}
4747

4848
pub fn new_from_span(
49-
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
49+
infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
5050
span: Span,
5151
sub: ty::Region<'tcx>,
5252
sup: ty::Region<'tcx>,
5353
tables: Option<&'cx ty::TypeckTables<'tcx>>,
5454
) -> Self {
55-
Self { tcx, error: None, regions: Some((span, sub, sup)), tables }
55+
Self { infcx, error: None, regions: Some((span, sub, sup)), tables }
56+
}
57+
58+
fn tcx(&self) -> TyCtxt<'cx, 'gcx, 'tcx> {
59+
self.infcx.tcx
5660
}
5761

5862
pub fn try_report_from_nll(&self) -> Option<ErrorReported> {

src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
2424
// version new_ty of its type where the anonymous region is replaced
2525
// with the named one.//scope_def_id
2626
let (named, anon, anon_arg_info, region_info) = if self.is_named_region(sub)
27-
&& self.tcx.is_suitable_region(sup).is_some()
27+
&& self.tcx().is_suitable_region(sup).is_some()
2828
&& self.find_arg_with_region(sup, sub).is_some()
2929
{
3030
(
3131
sub,
3232
sup,
3333
self.find_arg_with_region(sup, sub).unwrap(),
34-
self.tcx.is_suitable_region(sup).unwrap(),
34+
self.tcx().is_suitable_region(sup).unwrap(),
3535
)
36-
} else if self.is_named_region(sup) && self.tcx.is_suitable_region(sub).is_some()
36+
} else if self.is_named_region(sup) && self.tcx().is_suitable_region(sub).is_some()
3737
&& self.find_arg_with_region(sub, sup).is_some()
3838
{
3939
(
4040
sup,
4141
sub,
4242
self.find_arg_with_region(sub, sup).unwrap(),
43-
self.tcx.is_suitable_region(sub).unwrap(),
43+
self.tcx().is_suitable_region(sub).unwrap(),
4444
)
4545
} else {
4646
return None; // inapplicable
@@ -97,7 +97,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
9797
};
9898

9999
struct_span_err!(
100-
self.tcx.sess,
100+
self.tcx().sess,
101101
span,
102102
E0621,
103103
"explicit lifetime required in {}",

src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
4747
// closure, provide a specific message pointing this out.
4848
if let (&SubregionOrigin::BindingTypeIsNotValidAtDecl(ref external_span),
4949
&RegionKind::ReFree(ref free_region)) = (&sub_origin, sup_region) {
50-
let hir = &self.tcx.hir();
50+
let hir = &self.tcx().hir();
5151
if let Some(node_id) = hir.as_local_node_id(free_region.scope) {
5252
if let Node::Expr(Expr {
5353
node: Closure(_, _, _, closure_span, None),
5454
..
5555
}) = hir.get(node_id) {
5656
let sup_sp = sup_origin.span();
5757
let origin_sp = origin.span();
58-
let mut err = self.tcx.sess.struct_span_err(
58+
let mut err = self.tcx().sess.struct_span_err(
5959
sup_sp,
6060
"borrowed data cannot be stored outside of its closure");
6161
err.span_label(sup_sp, "cannot be stored outside of its closure");

0 commit comments

Comments
 (0)