Skip to content

Commit

Permalink
Auto merge of #57901 - lqd:issue_57362, r=nikomatsakis
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jan 29, 2019
2 parents ae1ba15 + c97d135 commit 7425663
Show file tree
Hide file tree
Showing 27 changed files with 427 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
let (span, sub, sup) = self.get_regions();

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

let anon_reg_sub = self.tcx.is_suitable_region(sub)?;
let anon_reg_sub = self.tcx().is_suitable_region(sub)?;
let scope_def_id_sup = anon_reg_sup.def_id;
let bregion_sup = anon_reg_sup.boundregion;
let scope_def_id_sub = anon_reg_sub.def_id;
Expand Down Expand Up @@ -138,7 +138,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
};


struct_span_err!(self.tcx.sess, span, E0623, "lifetime mismatch")
struct_span_err!(self.tcx().sess, span, E0623, "lifetime mismatch")
.span_label(span_1, main_label)
.span_label(span_2, String::new())
.span_label(span, span_label)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
region: Region<'tcx>,
br: &ty::BoundRegion,
) -> Option<(&hir::Ty, &hir::FnDecl)> {
if let Some(anon_reg) = self.tcx.is_suitable_region(region) {
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
let def_id = anon_reg.def_id;
if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) {
let fndecl = match self.tcx.hir().get(node_id) {
if let Some(node_id) = self.tcx().hir().as_local_node_id(def_id) {
let fndecl = match self.tcx().hir().get(node_id) {
Node::Item(&hir::Item {
node: hir::ItemKind::Fn(ref fndecl, ..),
..
Expand Down Expand Up @@ -64,7 +64,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
br: &ty::BoundRegion,
) -> Option<(&'gcx hir::Ty)> {
let mut nested_visitor = FindNestedTypeVisitor {
tcx: self.tcx,
tcx: self.tcx(),
bound_region: *br,
found_type: None,
current_index: ty::INNERMOST,
Expand Down
18 changes: 11 additions & 7 deletions src/librustc/infer/error_reporting/nice_region_error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,41 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {

if let Some(tables) = self.in_progress_tables {
let tables = tables.borrow();
NiceRegionError::new(self.tcx, error.clone(), Some(&tables)).try_report().is_some()
NiceRegionError::new(self, error.clone(), Some(&tables)).try_report().is_some()
} else {
NiceRegionError::new(self.tcx, error.clone(), None).try_report().is_some()
NiceRegionError::new(self, error.clone(), None).try_report().is_some()
}
}
}

pub struct NiceRegionError<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
error: Option<RegionResolutionError<'tcx>>,
regions: Option<(Span, ty::Region<'tcx>, ty::Region<'tcx>)>,
tables: Option<&'cx ty::TypeckTables<'tcx>>,
}

impl<'cx, 'gcx, 'tcx> NiceRegionError<'cx, 'gcx, 'tcx> {
pub fn new(
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
error: RegionResolutionError<'tcx>,
tables: Option<&'cx ty::TypeckTables<'tcx>>,
) -> Self {
Self { tcx, error: Some(error), regions: None, tables }
Self { infcx, error: Some(error), regions: None, tables }
}

pub fn new_from_span(
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
span: Span,
sub: ty::Region<'tcx>,
sup: ty::Region<'tcx>,
tables: Option<&'cx ty::TypeckTables<'tcx>>,
) -> Self {
Self { tcx, error: None, regions: Some((span, sub, sup)), tables }
Self { infcx, error: None, regions: Some((span, sub, sup)), tables }
}

fn tcx(&self) -> TyCtxt<'cx, 'gcx, 'tcx> {
self.infcx.tcx
}

pub fn try_report_from_nll(&self) -> Option<ErrorReported> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
// version new_ty of its type where the anonymous region is replaced
// with the named one.//scope_def_id
let (named, anon, anon_arg_info, region_info) = if self.is_named_region(sub)
&& self.tcx.is_suitable_region(sup).is_some()
&& self.tcx().is_suitable_region(sup).is_some()
&& self.find_arg_with_region(sup, sub).is_some()
{
(
sub,
sup,
self.find_arg_with_region(sup, sub).unwrap(),
self.tcx.is_suitable_region(sup).unwrap(),
self.tcx().is_suitable_region(sup).unwrap(),
)
} else if self.is_named_region(sup) && self.tcx.is_suitable_region(sub).is_some()
} else if self.is_named_region(sup) && self.tcx().is_suitable_region(sub).is_some()
&& self.find_arg_with_region(sub, sup).is_some()
{
(
sup,
sub,
self.find_arg_with_region(sub, sup).unwrap(),
self.tcx.is_suitable_region(sub).unwrap(),
self.tcx().is_suitable_region(sub).unwrap(),
)
} else {
return None; // inapplicable
Expand Down Expand Up @@ -97,7 +97,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
};

struct_span_err!(
self.tcx.sess,
self.tcx().sess,
span,
E0621,
"explicit lifetime required in {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
// closure, provide a specific message pointing this out.
if let (&SubregionOrigin::BindingTypeIsNotValidAtDecl(ref external_span),
&RegionKind::ReFree(ref free_region)) = (&sub_origin, sup_region) {
let hir = &self.tcx.hir();
let hir = &self.tcx().hir();
if let Some(node_id) = hir.as_local_node_id(free_region.scope) {
if let Node::Expr(Expr {
node: Closure(_, _, _, closure_span, None),
..
}) = hir.get(node_id) {
let sup_sp = sup_origin.span();
let origin_sp = origin.span();
let mut err = self.tcx.sess.struct_span_err(
let mut err = self.tcx().sess.struct_span_err(
sup_sp,
"borrowed data cannot be stored outside of its closure");
err.span_label(sup_sp, "cannot be stored outside of its closure");
Expand Down
Loading

0 comments on commit 7425663

Please sign in to comment.