From db01b6789db9b4f89209ea6e28781dfd66eebbcb Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 24 Aug 2018 23:11:44 -0400 Subject: [PATCH 1/8] [nll] Refactor the `Edges` iterator to return `OutlivesConstraints` Part of #53178 --- .../borrow_check/nll/constraints/graph.rs | 18 +++++---- .../nll/region_infer/error_reporting/mod.rs | 40 +++++++++---------- .../borrow_check/nll/region_infer/mod.rs | 2 +- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/constraints/graph.rs b/src/librustc_mir/borrow_check/nll/constraints/graph.rs index 1a1094b570bd1..7cf94ec84dc93 100644 --- a/src/librustc_mir/borrow_check/nll/constraints/graph.rs +++ b/src/librustc_mir/borrow_check/nll/constraints/graph.rs @@ -103,10 +103,15 @@ impl ConstraintGraph { } /// Given a region `R`, iterate over all constraints `R: R1`. - crate fn outgoing_edges(&self, region_sup: RegionVid) -> Edges<'_, D> { + crate fn outgoing_edges<'a>( + &'a self, + region_sup: RegionVid, + constraints: &'a ConstraintSet, + ) -> Edges<'a, D> { let first = self.first_constraints[region_sup]; Edges { graph: self, + constraints, pointer: first, } } @@ -114,16 +119,17 @@ impl ConstraintGraph { crate struct Edges<'s, D: ConstraintGraphDirecton> { graph: &'s ConstraintGraph, + constraints: &'s ConstraintSet, pointer: Option, } impl<'s, D: ConstraintGraphDirecton> Iterator for Edges<'s, D> { - type Item = ConstraintIndex; + type Item = OutlivesConstraint; fn next(&mut self) -> Option { if let Some(p) = self.pointer { self.pointer = self.graph.next_constraints[p]; - Some(p) + Some(self.constraints[p]) } else { None } @@ -154,14 +160,12 @@ impl<'s, D: ConstraintGraphDirecton> RegionGraph<'s, D> { /// there exists a constraint `R: R1`. crate fn outgoing_regions(&self, region_sup: RegionVid) -> Successors<'_, D> { Successors { - set: self.set, - edges: self.constraint_graph.outgoing_edges(region_sup), + edges: self.constraint_graph.outgoing_edges(region_sup, self.set), } } } crate struct Successors<'s, D: ConstraintGraphDirecton> { - set: &'s ConstraintSet, edges: Edges<'s, D>, } @@ -169,7 +173,7 @@ impl<'s, D: ConstraintGraphDirecton> Iterator for Successors<'s, D> { type Item = RegionVid; fn next(&mut self) -> Option { - self.edges.next().map(|c| D::end_region(&self.set[c])) + self.edges.next().map(|c| D::end_region(&c)) } } diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs index ca208a434314f..2a541b6474f58 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use borrow_check::nll::region_infer::{ConstraintIndex, RegionInferenceContext}; +use borrow_check::nll::constraints::OutlivesConstraint; +use borrow_check::nll::region_infer::RegionInferenceContext; use borrow_check::nll::type_check::Locations; use rustc::hir::def_id::DefId; use rustc::infer::error_reporting::nice_region_error::NiceRegionError; @@ -53,7 +54,7 @@ impl fmt::Display for ConstraintCategory { #[derive(Copy, Clone, PartialEq, Eq)] enum Trace { StartRegion, - FromConstraint(ConstraintIndex), + FromOutlivesConstraint(OutlivesConstraint), NotVisited, } @@ -80,12 +81,11 @@ impl<'tcx> RegionInferenceContext<'tcx> { debug!( "best_blame_constraint: path={:#?}", path.iter() - .map(|&ci| format!( - "{:?}: {:?} ({:?}: {:?})", - ci, - &self.constraints[ci], - self.constraint_sccs.scc(self.constraints[ci].sup), - self.constraint_sccs.scc(self.constraints[ci].sub), + .map(|&c| format!( + "{:?} ({:?}: {:?})", + c, + self.constraint_sccs.scc(c.sup), + self.constraint_sccs.scc(c.sub), )) .collect::>() ); @@ -121,7 +121,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // highlight (e.g., a call site or something). let target_scc = self.constraint_sccs.scc(target_region); let best_choice = (0..path.len()).rev().find(|&i| { - let constraint = &self.constraints[path[i]]; + let constraint = path[i]; let constraint_sup_scc = self.constraint_sccs.scc(constraint.sup); @@ -164,7 +164,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { &self, from_region: RegionVid, target_test: impl Fn(RegionVid) -> bool, - ) -> Option<(Vec, RegionVid)> { + ) -> Option<(Vec, RegionVid)> { let mut context = IndexVec::from_elem(Trace::NotVisited, &self.definitions); context[from_region] = Trace::StartRegion; @@ -185,9 +185,9 @@ impl<'tcx> RegionInferenceContext<'tcx> { Trace::NotVisited => { bug!("found unvisited region {:?} on path to {:?}", p, r) } - Trace::FromConstraint(c) => { + Trace::FromOutlivesConstraint(c) => { result.push(c); - p = self.constraints[c].sup; + p = c.sup; } Trace::StartRegion => { @@ -201,11 +201,11 @@ impl<'tcx> RegionInferenceContext<'tcx> { // Otherwise, walk over the outgoing constraints and // enqueue any regions we find, keeping track of how we // reached them. - for constraint in self.constraint_graph.outgoing_edges(r) { - assert_eq!(self.constraints[constraint].sup, r); - let sub_region = self.constraints[constraint].sub; + for constraint in self.constraint_graph.outgoing_edges(r, &self.constraints) { + assert_eq!(constraint.sup, r); + let sub_region = constraint.sub; if let Trace::NotVisited = context[sub_region] { - context[sub_region] = Trace::FromConstraint(constraint); + context[sub_region] = Trace::FromOutlivesConstraint(constraint); deque.push_back(sub_region); } } @@ -216,8 +216,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// This function will return true if a constraint is interesting and false if a constraint /// is not. It is useful in filtering constraint paths to only interesting points. - fn constraint_is_interesting(&self, index: ConstraintIndex) -> bool { - let constraint = self.constraints[index]; + fn constraint_is_interesting(&self, constraint: OutlivesConstraint) -> bool { debug!( "constraint_is_interesting: locations={:?} constraint={:?}", constraint.locations, constraint @@ -232,11 +231,10 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// This function classifies a constraint from a location. fn classify_constraint( &self, - index: ConstraintIndex, + constraint: OutlivesConstraint, mir: &Mir<'tcx>, tcx: TyCtxt<'_, '_, 'tcx>, ) -> (ConstraintCategory, Span) { - let constraint = self.constraints[index]; debug!("classify_constraint: constraint={:?}", constraint); let span = constraint.locations.span(mir); let location = constraint @@ -244,7 +242,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { .from_location() .unwrap_or(Location::START); - if !self.constraint_is_interesting(index) { + if !self.constraint_is_interesting(constraint) { return (ConstraintCategory::Boring, span); } diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index ff68b5987e85a..4fe39ba3c9520 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -11,7 +11,7 @@ use super::universal_regions::UniversalRegions; use borrow_check::nll::constraints::graph::NormalConstraintGraph; use borrow_check::nll::constraints::{ - ConstraintIndex, ConstraintSccIndex, ConstraintSet, OutlivesConstraint, + ConstraintSccIndex, ConstraintSet, OutlivesConstraint, }; use borrow_check::nll::region_infer::values::{RegionElement, ToElementIndex}; use borrow_check::nll::type_check::free_region_relations::UniversalRegionRelations; From 4e706f56bd3beb0833d9e05b0dabdc3c3ce750e4 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Sun, 26 Aug 2018 22:50:57 -0400 Subject: [PATCH 2/8] [nll] teach SCC about `'static` Fixes #53178 --- .../borrow_check/nll/constraints/graph.rs | 70 ++++++++++++++++--- .../borrow_check/nll/constraints/mod.rs | 3 +- .../nll/region_infer/error_reporting/mod.rs | 5 +- .../borrow_check/nll/region_infer/mod.rs | 3 +- .../nll/type_check/liveness/mod.rs | 3 +- 5 files changed, 71 insertions(+), 13 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/constraints/graph.rs b/src/librustc_mir/borrow_check/nll/constraints/graph.rs index 7cf94ec84dc93..b1e8b974379d6 100644 --- a/src/librustc_mir/borrow_check/nll/constraints/graph.rs +++ b/src/librustc_mir/borrow_check/nll/constraints/graph.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use borrow_check::nll::type_check::Locations; use borrow_check::nll::constraints::{ConstraintIndex, ConstraintSet, OutlivesConstraint}; use rustc::ty::RegionVid; use rustc_data_structures::graph; @@ -31,6 +32,7 @@ crate type ReverseConstraintGraph = ConstraintGraph; crate trait ConstraintGraphDirecton: Copy + 'static { fn start_region(c: &OutlivesConstraint) -> RegionVid; fn end_region(c: &OutlivesConstraint) -> RegionVid; + fn is_normal() -> bool; } /// In normal mode, a `R1: R2` constraint results in an edge `R1 -> @@ -48,6 +50,10 @@ impl ConstraintGraphDirecton for Normal { fn end_region(c: &OutlivesConstraint) -> RegionVid { c.sub } + + fn is_normal() -> bool { + true + } } /// In reverse mode, a `R1: R2` constraint results in an edge `R2 -> @@ -65,6 +71,10 @@ impl ConstraintGraphDirecton for Reverse { fn end_region(c: &OutlivesConstraint) -> RegionVid { c.sup } + + fn is_normal() -> bool { + false + } } impl ConstraintGraph { @@ -98,8 +108,12 @@ impl ConstraintGraph { /// Given the constraint set from which this graph was built /// creates a region graph so that you can iterate over *regions* /// and not constraints. - crate fn region_graph<'rg>(&'rg self, set: &'rg ConstraintSet) -> RegionGraph<'rg, D> { - RegionGraph::new(set, self) + crate fn region_graph<'rg>( + &'rg self, + set: &'rg ConstraintSet, + static_region: RegionVid, + ) -> RegionGraph<'rg, D> { + RegionGraph::new(set, self, static_region) } /// Given a region `R`, iterate over all constraints `R: R1`. @@ -107,12 +121,28 @@ impl ConstraintGraph { &'a self, region_sup: RegionVid, constraints: &'a ConstraintSet, + static_region: RegionVid, ) -> Edges<'a, D> { - let first = self.first_constraints[region_sup]; - Edges { - graph: self, - constraints, - pointer: first, + //if this is the `'static` region and the graph's direction is normal, + //then setup the Edges iterator to return all regions #53178 + if region_sup == static_region && D::is_normal() { + Edges { + graph: self, + constraints, + pointer: None, + next_static_idx: Some(0), + static_region, + } + } else { + //otherwise, just setup the iterator as normal + let first = self.first_constraints[region_sup]; + Edges { + graph: self, + constraints, + pointer: first, + next_static_idx: None, + static_region, + } } } } @@ -121,6 +151,8 @@ crate struct Edges<'s, D: ConstraintGraphDirecton> { graph: &'s ConstraintGraph, constraints: &'s ConstraintSet, pointer: Option, + next_static_idx: Option, + static_region: RegionVid, } impl<'s, D: ConstraintGraphDirecton> Iterator for Edges<'s, D> { @@ -129,7 +161,21 @@ impl<'s, D: ConstraintGraphDirecton> Iterator for Edges<'s, D> { fn next(&mut self) -> Option { if let Some(p) = self.pointer { self.pointer = self.graph.next_constraints[p]; + Some(self.constraints[p]) + } else if let Some(next_static_idx) = self.next_static_idx { + self.next_static_idx = + if next_static_idx == (self.graph.first_constraints.len() - 1) { + None + } else { + Some(next_static_idx + 1) + }; + + Some(OutlivesConstraint { + sup: self.static_region, + sub: next_static_idx.into(), + locations: Locations::All, + }) } else { None } @@ -142,6 +188,7 @@ impl<'s, D: ConstraintGraphDirecton> Iterator for Edges<'s, D> { crate struct RegionGraph<'s, D: ConstraintGraphDirecton> { set: &'s ConstraintSet, constraint_graph: &'s ConstraintGraph, + static_region: RegionVid, } impl<'s, D: ConstraintGraphDirecton> RegionGraph<'s, D> { @@ -149,10 +196,15 @@ impl<'s, D: ConstraintGraphDirecton> RegionGraph<'s, D> { /// R2` is treated as an edge `R1 -> R2`. We use this graph to /// construct SCCs for region inference but also for error /// reporting. - crate fn new(set: &'s ConstraintSet, constraint_graph: &'s ConstraintGraph) -> Self { + crate fn new( + set: &'s ConstraintSet, + constraint_graph: &'s ConstraintGraph, + static_region: RegionVid, + ) -> Self { Self { set, constraint_graph, + static_region, } } @@ -160,7 +212,7 @@ impl<'s, D: ConstraintGraphDirecton> RegionGraph<'s, D> { /// there exists a constraint `R: R1`. crate fn outgoing_regions(&self, region_sup: RegionVid) -> Successors<'_, D> { Successors { - edges: self.constraint_graph.outgoing_edges(region_sup, self.set), + edges: self.constraint_graph.outgoing_edges(region_sup, self.set, self.static_region), } } } diff --git a/src/librustc_mir/borrow_check/nll/constraints/mod.rs b/src/librustc_mir/borrow_check/nll/constraints/mod.rs index 4cb92262ff085..9a8b0f391de9d 100644 --- a/src/librustc_mir/borrow_check/nll/constraints/mod.rs +++ b/src/librustc_mir/borrow_check/nll/constraints/mod.rs @@ -58,8 +58,9 @@ impl ConstraintSet { crate fn compute_sccs( &self, constraint_graph: &graph::NormalConstraintGraph, + static_region: RegionVid, ) -> Sccs { - let region_graph = &constraint_graph.region_graph(self); + let region_graph = &constraint_graph.region_graph(self, static_region); Sccs::new(region_graph) } } diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs index 2a541b6474f58..0b9b9b33b3f15 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs @@ -201,7 +201,10 @@ impl<'tcx> RegionInferenceContext<'tcx> { // Otherwise, walk over the outgoing constraints and // enqueue any regions we find, keeping track of how we // reached them. - for constraint in self.constraint_graph.outgoing_edges(r, &self.constraints) { + let fr_static = self.universal_regions.fr_static; + for constraint in self.constraint_graph.outgoing_edges(r, + &self.constraints, + fr_static) { assert_eq!(constraint.sup, r); let sub_region = constraint.sub; if let Trace::NotVisited = context[sub_region] { diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index 4fe39ba3c9520..bbdf2a9292210 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -234,7 +234,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { let constraints = Rc::new(outlives_constraints); // freeze constraints let constraint_graph = Rc::new(constraints.graph(definitions.len())); - let constraint_sccs = Rc::new(constraints.compute_sccs(&constraint_graph)); + let fr_static = universal_regions.fr_static; + let constraint_sccs = Rc::new(constraints.compute_sccs(&constraint_graph, fr_static)); let mut scc_values = RegionValues::new(elements, universal_regions.len(), max_universe); diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs index b3fc73e9b7be3..357e9ee72102a 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs @@ -69,7 +69,8 @@ fn regions_that_outlive_free_regions( // reachable from each free region, we will have all the // regions that are forced to outlive some free region. let rev_constraint_graph = constraint_set.reverse_graph(num_region_vars); - let rev_region_graph = rev_constraint_graph.region_graph(constraint_set); + let fr_static = universal_regions.fr_static; + let rev_region_graph = rev_constraint_graph.region_graph(constraint_set, fr_static); // Stack for the depth-first search. Start out with all the free regions. let mut stack: Vec<_> = universal_regions.universal_regions().collect(); From 2eb76fc8a17cbbbbefe12c6a4413b3d803c03941 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 6 Sep 2018 12:38:15 -0400 Subject: [PATCH 3/8] add a useful debug to `give_region_a_name` --- .../region_infer/error_reporting/region_name.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index 6177194ab914d..8ac4bcd67b6bf 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -62,20 +62,26 @@ impl<'tcx> RegionInferenceContext<'tcx> { assert!(self.universal_regions.is_universal_region(fr)); - self.give_name_from_error_region(infcx.tcx, mir_def_id, fr, counter, diag) + let value = self.give_name_from_error_region(infcx.tcx, mir_def_id, fr, counter, diag) .or_else(|| { self.give_name_if_anonymous_region_appears_in_arguments( - infcx, mir, mir_def_id, fr, counter, diag) + infcx, mir, mir_def_id, fr, counter, diag, + ) }) .or_else(|| { self.give_name_if_anonymous_region_appears_in_upvars( - infcx.tcx, mir, fr, counter, diag) + infcx.tcx, mir, fr, counter, diag, + ) }) .or_else(|| { self.give_name_if_anonymous_region_appears_in_output( - infcx, mir, mir_def_id, fr, counter, diag) + infcx, mir, mir_def_id, fr, counter, diag, + ) }) - .unwrap_or_else(|| span_bug!(mir.span, "can't make a name for free region {:?}", fr)) + .unwrap_or_else(|| span_bug!(mir.span, "can't make a name for free region {:?}", fr)); + + debug!("give_region_a_name: gave name {:?}", value); + value } /// Check for the case where `fr` maps to something that the From bf6fe2a51e900cdadd356d49baf4a9e6d5fce7e2 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 6 Sep 2018 12:38:49 -0400 Subject: [PATCH 4/8] region_name: rustfmt --- .../error_reporting/region_name.rs | 82 ++++++++++--------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index 8ac4bcd67b6bf..5ae123bdc18d1 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -9,8 +9,8 @@ // except according to those terms. use borrow_check::nll::region_infer::RegionInferenceContext; -use borrow_check::nll::ToRegionVid; use borrow_check::nll::universal_regions::DefiningTy; +use borrow_check::nll::ToRegionVid; use rustc::hir; use rustc::hir::def_id::DefId; use rustc::infer::InferCtxt; @@ -107,7 +107,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { } else { None } - }, + } ty::ReStatic => Some(keywords::StaticLifetime.name().as_interned_str()), @@ -115,15 +115,15 @@ impl<'tcx> RegionInferenceContext<'tcx> { ty::BoundRegion::BrNamed(_, name) => { self.highlight_named_span(tcx, error_region, &name, diag); Some(name) - }, + } ty::BoundRegion::BrEnv => { let mir_node_id = tcx.hir.as_local_node_id(mir_def_id).expect("non-local mir"); let def_ty = self.universal_regions.defining_ty; if let DefiningTy::Closure(def_id, substs) = def_ty { - let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) - = tcx.hir.expect_expr(mir_node_id).node + let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) = + tcx.hir.expect_expr(mir_node_id).node { span } else { @@ -201,16 +201,14 @@ impl<'tcx> RegionInferenceContext<'tcx> { let node = tcx.hir.as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID); let mut sp = cm.def_span(tcx.hir.span(node)); - if let Some(param) = tcx.hir.get_generics(scope).and_then(|generics| { - generics.get_named(name) - }) { + if let Some(param) = tcx.hir + .get_generics(scope) + .and_then(|generics| generics.get_named(name)) + { sp = param.span; } - diag.span_label( - sp, - format!("lifetime `{}` defined here", name), - ); + diag.span_label(sp, format!("lifetime `{}` defined here", name)); } /// Find an argument that contains `fr` and label it with a fully @@ -248,14 +246,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { return Some(region_name); } - self.give_name_if_we_cannot_match_hir_ty( - infcx, - mir, - fr, - arg_ty, - counter, - diag, - ) + self.give_name_if_we_cannot_match_hir_ty(infcx, mir, fr, arg_ty, counter, diag) } fn give_name_if_we_can_match_hir_ty_from_argument( @@ -320,8 +311,10 @@ impl<'tcx> RegionInferenceContext<'tcx> { infcx.extract_type_name(&argument_ty) }); - debug!("give_name_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}", - type_name, needle_fr); + debug!( + "give_name_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}", + type_name, needle_fr + ); let assigned_region_name = if type_name.find(&format!("'{}", counter)).is_some() { // Only add a label if we can confirm that a region was labelled. let argument_index = self.get_argument_index_for_region(infcx.tcx, needle_fr)?; @@ -553,13 +546,16 @@ impl<'tcx> RegionInferenceContext<'tcx> { diag: &mut DiagnosticBuilder<'_>, ) -> Option { let upvar_index = self.get_upvar_index_for_region(tcx, fr)?; - let (upvar_name, upvar_span) = self.get_upvar_name_and_span_for_region(tcx, mir, - upvar_index); + let (upvar_name, upvar_span) = + self.get_upvar_name_and_span_for_region(tcx, mir, upvar_index); let region_name = self.synthesize_region_name(counter); diag.span_label( upvar_span, - format!("lifetime `{}` appears in the type of `{}`", region_name, upvar_name), + format!( + "lifetime `{}` appears in the type of `{}`", + region_name, upvar_name + ), ); Some(region_name) @@ -585,27 +581,33 @@ impl<'tcx> RegionInferenceContext<'tcx> { "give_name_if_anonymous_region_appears_in_output: return_ty = {:?}", return_ty ); - if !infcx.tcx.any_free_region_meets(&return_ty, |r| r.to_region_vid() == fr) { + if !infcx + .tcx + .any_free_region_meets(&return_ty, |r| r.to_region_vid() == fr) + { return None; } - let type_name = with_highlight_region(fr, *counter, || { - infcx.extract_type_name(&return_ty) - }); + let type_name = with_highlight_region(fr, *counter, || infcx.extract_type_name(&return_ty)); let mir_node_id = tcx.hir.as_local_node_id(mir_def_id).expect("non-local mir"); - let (return_span, mir_description) = if let hir::ExprKind::Closure(_, _, _, span, gen_move) - = tcx.hir.expect_expr(mir_node_id).node - { - ( - tcx.sess.source_map().end_point(span), - if gen_move.is_some() { " of generator" } else { " of closure" } - ) - } else { - // unreachable? - (mir.span, "") - }; + let (return_span, mir_description) = + if let hir::ExprKind::Closure(_, _, _, span, gen_move) = + tcx.hir.expect_expr(mir_node_id).node + { + ( + tcx.sess.source_map().end_point(span), + if gen_move.is_some() { + " of generator" + } else { + " of closure" + }, + ) + } else { + // unreachable? + (mir.span, "") + }; diag.span_label( return_span, From da12d02b37dc872a090de96a0517d9966286cc9b Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 6 Sep 2018 12:39:27 -0400 Subject: [PATCH 5/8] useful debug in `universal_regions` --- .../borrow_check/nll/universal_regions.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index 8112b71b12752..ed2b77344065c 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -619,6 +619,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'gcx, 'tcx> { value, all_outlive_scope, ); let (value, _map) = self.tcx.replace_late_bound_regions(value, |br| { + debug!("replace_bound_regions_with_nll_infer_vars: br={:?}", br); let liberated_region = self.tcx.mk_region(ty::ReFree(ty::FreeRegion { scope: all_outlive_scope, bound_region: br, @@ -626,7 +627,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'gcx, 'tcx> { let region_vid = self.next_nll_region_var(origin); indices.insert_late_bound_region(liberated_region, region_vid.to_region_vid()); debug!( - "liberated_region={:?} => {:?}", + "replace_bound_regions_with_nll_infer_vars: liberated_region={:?} => {:?}", liberated_region, region_vid ); region_vid @@ -648,12 +649,18 @@ impl<'cx, 'gcx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'gcx, 'tcx> { mir_def_id: DefId, indices: &mut UniversalRegionIndices<'tcx>, ) { + debug!( + "replace_late_bound_regions_with_nll_infer_vars(mir_def_id={:?})", + mir_def_id + ); let closure_base_def_id = self.tcx.closure_base_def_id(mir_def_id); for_each_late_bound_region_defined_on(self.tcx, closure_base_def_id, |r| { + debug!("replace_late_bound_regions_with_nll_infer_vars: r={:?}", r); if !indices.indices.contains_key(&r) { let region_vid = self.next_nll_region_var(FR); indices.insert_late_bound_region(r, region_vid.to_region_vid()); - }}); + } + }); } } From 81f64b7fa31de97930560fe6d18b6e291f76a626 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 6 Sep 2018 12:39:38 -0400 Subject: [PATCH 6/8] universal_regions.rs: rustfmt --- .../borrow_check/nll/universal_regions.rs | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index ed2b77344065c..5115312825605 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -241,8 +241,9 @@ impl<'tcx> UniversalRegions<'tcx> { region_mapping.push(fr); }); - for_each_late_bound_region_defined_on( - tcx, closure_base_def_id, |r| { region_mapping.push(r); }); + for_each_late_bound_region_defined_on(tcx, closure_base_def_id, |r| { + region_mapping.push(r); + }); assert_eq!( region_mapping.len(), @@ -352,9 +353,8 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> { // let c = || { let x: &'a u32 = ...; } // } if self.mir_def_id != closure_base_def_id { - self.infcx.replace_late_bound_regions_with_nll_infer_vars( - self.mir_def_id, - &mut indices) + self.infcx + .replace_late_bound_regions_with_nll_infer_vars(self.mir_def_id, &mut indices) } let bound_inputs_and_output = self.compute_inputs_and_output(&indices, defining_ty); @@ -371,9 +371,8 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> { // Converse of above, if this is a function then the late-bound regions declared on its // signature are local to the fn. if self.mir_def_id == closure_base_def_id { - self.infcx.replace_late_bound_regions_with_nll_infer_vars( - self.mir_def_id, - &mut indices); + self.infcx + .replace_late_bound_regions_with_nll_infer_vars(self.mir_def_id, &mut indices); } let fr_fn_body = self.infcx.next_nll_region_var(FR).to_region_vid(); @@ -582,11 +581,10 @@ trait InferCtxtExt<'tcx> { where T: TypeFoldable<'tcx>; - fn replace_late_bound_regions_with_nll_infer_vars( &self, mir_def_id: DefId, - indices: &mut UniversalRegionIndices<'tcx> + indices: &mut UniversalRegionIndices<'tcx>, ); } @@ -710,11 +708,14 @@ impl<'tcx> UniversalRegionIndices<'tcx> { fn for_each_late_bound_region_defined_on<'tcx>( tcx: TyCtxt<'_, '_, 'tcx>, fn_def_id: DefId, - mut f: impl FnMut(ty::Region<'tcx>) - ) { + mut f: impl FnMut(ty::Region<'tcx>), +) { if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.index) { for late_bound in late_bounds.iter() { - let hir_id = HirId{ owner: fn_def_id.index, local_id: *late_bound }; + let hir_id = HirId { + owner: fn_def_id.index, + local_id: *late_bound, + }; let region_node_id = tcx.hir.hir_to_node_id(hir_id); let name = tcx.hir.name(region_node_id).as_interned_str(); let region_def_id = tcx.hir.local_def_id(region_node_id); From 5390cf32f7314eba09c504aac3be02e8f546b1f6 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 6 Sep 2018 12:39:48 -0400 Subject: [PATCH 7/8] resolve_lifetime: types are not late-bound regions =) --- src/librustc/middle/resolve_lifetime.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index d0f801e661b43..db931d0a739ff 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -2567,6 +2567,13 @@ fn insert_late_bound_lifetimes( // - do not appear in the where-clauses // - are not implicitly captured by `impl Trait` for param in &generics.params { + match param.kind { + hir::GenericParamKind::Lifetime { .. } => { /* fall through */ } + + // Types are not late-bound. + hir::GenericParamKind::Type { .. } => continue, + } + let lt_name = hir::LifetimeName::Param(param.name.modern()); // appears in the where clauses? early-bound. if appears_in_where_clause.regions.contains(<_name) { From b1211e870370cac1000a64c48ceb8a2ad6dc1f45 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Thu, 6 Sep 2018 22:57:05 -0400 Subject: [PATCH 8/8] Fix tests --- src/test/mir-opt/nll/named-lifetimes-basic.rs | 2 +- ...-fn-ret-contravariant.transmute.nll.stderr | 12 ++++++- ...ject-fn-ret-invariant.transmute.nll.stderr | 13 ++++++- .../static-return-lifetime-infered.nll.stderr | 4 +-- ...approximated-shorter-to-static-no-bound.rs | 3 +- ...oximated-shorter-to-static-no-bound.stderr | 22 +++++++++--- ...roximated-shorter-to-static-wrong-bound.rs | 3 +- ...mated-shorter-to-static-wrong-bound.stderr | 24 +++++++++---- .../propagate-from-trait-match.stderr | 2 +- src/test/ui/nll/mir_check_cast_reify.rs | 2 +- src/test/ui/nll/mir_check_cast_reify.stderr | 6 ++-- src/test/ui/nll/mir_check_cast_unsafe_fn.rs | 2 +- .../ui/nll/mir_check_cast_unsafe_fn.stderr | 6 ++-- src/test/ui/nll/mir_check_cast_unsize.stderr | 2 +- .../projection-no-regions-closure.stderr | 8 ++--- .../projection-one-region-closure.stderr | 8 ++--- ...tion-one-region-trait-bound-closure.stderr | 10 +++--- ...ojection-two-region-trait-bound-closure.rs | 8 ++--- ...tion-two-region-trait-bound-closure.stderr | 36 +++++++++---------- ...ram-closure-approximate-lower-bound.stderr | 4 +-- ...m-closure-outlives-from-return-type.stderr | 2 +- ...-closure-outlives-from-where-clause.stderr | 8 ++--- .../regions/regions-addr-of-self.nll.stderr | 4 +-- .../regions-addr-of-upvar-self.nll.stderr | 18 ++++++++-- ...ions-close-object-into-object-2.nll.stderr | 4 +-- ...ions-close-object-into-object-4.nll.stderr | 16 ++++----- .../regions-static-bound.ll.nll.stderr | 25 +++++++++++-- .../ui/regions/regions-static-bound.ll.stderr | 2 +- .../regions/regions-static-bound.nll.stderr | 25 +++++++++++-- src/test/ui/regions/regions-static-bound.rs | 2 ++ .../dyn-trait-underscore.nll.stderr | 2 +- 31 files changed, 194 insertions(+), 91 deletions(-) diff --git a/src/test/mir-opt/nll/named-lifetimes-basic.rs b/src/test/mir-opt/nll/named-lifetimes-basic.rs index ffc5603bb1670..c7fa7973a2d4d 100644 --- a/src/test/mir-opt/nll/named-lifetimes-basic.rs +++ b/src/test/mir-opt/nll/named-lifetimes-basic.rs @@ -34,7 +34,7 @@ fn main() { // | '_#4r | Local | ['_#4r] // | // | Inferred Region Values -// | '_#0r | U0 | {bb0[0..=1], '_#0r} +// | '_#0r | U0 | {bb0[0..=1], '_#0r, '_#1r, '_#2r, '_#3r, '_#4r} // | '_#1r | U0 | {bb0[0..=1], '_#1r} // | '_#2r | U0 | {bb0[0..=1], '_#2r} // | '_#3r | U0 | {bb0[0..=1], '_#3r} diff --git a/src/test/ui/associated-types/cache/project-fn-ret-contravariant.transmute.nll.stderr b/src/test/ui/associated-types/cache/project-fn-ret-contravariant.transmute.nll.stderr index b5cba945fb11a..2f632fec17e9e 100644 --- a/src/test/ui/associated-types/cache/project-fn-ret-contravariant.transmute.nll.stderr +++ b/src/test/ui/associated-types/cache/project-fn-ret-contravariant.transmute.nll.stderr @@ -6,5 +6,15 @@ LL | fn baz<'a,'b>(x: &'a u32) -> &'static u32 { LL | bar(foo, x) //[transmute]~ ERROR E0495 | ^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` -error: aborting due to previous error +error: unsatisfied lifetime constraints + --> $DIR/project-fn-ret-contravariant.rs:48:4 + | +LL | fn baz<'a,'b>(x: &'a u32) -> &'static u32 { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | bar(foo, x) //[transmute]~ ERROR E0495 + | ^^^^^^^^^^^ requires that `'a` must outlive `'b` + +error: aborting due to 2 previous errors diff --git a/src/test/ui/associated-types/cache/project-fn-ret-invariant.transmute.nll.stderr b/src/test/ui/associated-types/cache/project-fn-ret-invariant.transmute.nll.stderr index bb1be40980dad..63e1f665005cc 100644 --- a/src/test/ui/associated-types/cache/project-fn-ret-invariant.transmute.nll.stderr +++ b/src/test/ui/associated-types/cache/project-fn-ret-invariant.transmute.nll.stderr @@ -7,5 +7,16 @@ LL | fn baz<'a,'b>(x: Type<'a>) -> Type<'static> { LL | bar(foo, x) //[transmute]~ ERROR E0495 | ^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` -error: aborting due to previous error +error: unsatisfied lifetime constraints + --> $DIR/project-fn-ret-invariant.rs:58:13 + | +LL | fn baz<'a,'b>(x: Type<'a>) -> Type<'static> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +... +LL | bar(foo, x) //[transmute]~ ERROR E0495 + | ^ requires that `'a` must outlive `'b` + +error: aborting due to 2 previous errors diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr index 2568eb2ed3fc1..d75de81fc1c7f 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr @@ -4,7 +4,7 @@ error: unsatisfied lifetime constraints LL | fn iter_values_anon(&self) -> impl Iterator { | - let's call the lifetime of this reference `'1` LL | self.x.iter().map(|a| a.0) - | ^^^^^^^^^^^^^ requires that `'1` must outlive `'static` + | ^^^^^^ cast requires that `'1` must outlive `'static` error: unsatisfied lifetime constraints --> $DIR/static-return-lifetime-infered.rs:21:9 @@ -12,7 +12,7 @@ error: unsatisfied lifetime constraints LL | fn iter_values<'a>(&'a self) -> impl Iterator { | -- lifetime `'a` defined here LL | self.x.iter().map(|a| a.0) - | ^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + | ^^^^^^ cast requires that `'a` must outlive `'static` error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs index e32a4395f88e1..9963954c9c2d4 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs @@ -43,7 +43,8 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3 #[rustc_regions] fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { - //~^ ERROR + //~^ ERROR borrowed data escapes outside of function + //~| ERROR unsatisfied lifetime constraints // Only works if 'x: 'y: demand_y(x, y, x.get()) diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr index 0d47935630484..f50864d946be9 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr @@ -3,7 +3,8 @@ note: External requirements | LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { | _______________________________________________^ -LL | | //~^ ERROR +LL | | //~^ ERROR borrowed data escapes outside of function +LL | | //~| ERROR unsatisfied lifetime constraints LL | | LL | | // Only works if 'x: 'y: LL | | demand_y(x, y, x.get()) @@ -22,8 +23,8 @@ note: No external requirements | LL | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { LL | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { -LL | | //~^ ERROR -LL | | +LL | | //~^ ERROR borrowed data escapes outside of function +LL | | //~| ERROR unsatisfied lifetime constraints ... | LL | | }); LL | | } @@ -37,12 +38,23 @@ error: borrowed data escapes outside of function LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { | ------ `cell_a` is a reference that is only valid in the function body LL | / establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { -LL | | //~^ ERROR +LL | | //~^ ERROR borrowed data escapes outside of function +LL | | //~| ERROR unsatisfied lifetime constraints LL | | LL | | // Only works if 'x: 'y: LL | | demand_y(x, y, x.get()) LL | | }); | |______^ `cell_a` escapes the function body here -error: aborting due to previous error +error: unsatisfied lifetime constraints + --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:29 + | +LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { + | ^^^^^^^ requires that `'a` must outlive `'b` + +error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs index 0334f9ffd86fc..d35b5c34a9181 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs @@ -46,7 +46,8 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3 #[rustc_regions] fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { - //~^ ERROR + //~^ ERROR borrowed data escapes outside of function + //~| ERROR unsatisfied lifetime constraints // Only works if 'x: 'y: demand_y(x, y, x.get()) }); diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr index 88743169fcbee..8a89320d10cad 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr @@ -3,7 +3,8 @@ note: External requirements | LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { | _______________________________________________^ -LL | | //~^ ERROR +LL | | //~^ ERROR borrowed data escapes outside of function +LL | | //~| ERROR unsatisfied lifetime constraints LL | | // Only works if 'x: 'y: LL | | demand_y(x, y, x.get()) LL | | }); @@ -21,9 +22,9 @@ note: No external requirements | LL | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { LL | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { -LL | | //~^ ERROR -LL | | // Only works if 'x: 'y: -LL | | demand_y(x, y, x.get()) +LL | | //~^ ERROR borrowed data escapes outside of function +LL | | //~| ERROR unsatisfied lifetime constraints +... | LL | | }); LL | | } | |_^ @@ -36,11 +37,22 @@ error: borrowed data escapes outside of function LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { | ------ `cell_a` is a reference that is only valid in the function body LL | / establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { -LL | | //~^ ERROR +LL | | //~^ ERROR borrowed data escapes outside of function +LL | | //~| ERROR unsatisfied lifetime constraints LL | | // Only works if 'x: 'y: LL | | demand_y(x, y, x.get()) LL | | }); | |______^ `cell_a` escapes the function body here -error: aborting due to previous error +error: unsatisfied lifetime constraints + --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:29 + | +LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { + | ^^^^^^^ requires that `'a` must outlive `'b` + +error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr index fda9743fb6b9b..d1976b40df414 100644 --- a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr @@ -17,7 +17,7 @@ LL | | }); i32, extern "rust-call" fn((T,)) ] - = note: number of external vids: 3 + = note: number of external vids: 2 = note: where T: '_#1r note: No external requirements diff --git a/src/test/ui/nll/mir_check_cast_reify.rs b/src/test/ui/nll/mir_check_cast_reify.rs index 93f10b96c2220..332ec7a7da28c 100644 --- a/src/test/ui/nll/mir_check_cast_reify.rs +++ b/src/test/ui/nll/mir_check_cast_reify.rs @@ -44,8 +44,8 @@ fn bar<'a>(x: &'a u32) -> &'static u32 { // The MIR type checker must therefore relate `'?0` to `'?1` and `'?2` // as part of checking the `ReifyFnPointer`. let f: fn(_) -> _ = foo; + //~^ ERROR unsatisfied lifetime constraints f(x) - //~^ ERROR } fn main() {} diff --git a/src/test/ui/nll/mir_check_cast_reify.stderr b/src/test/ui/nll/mir_check_cast_reify.stderr index fdb71b17287d9..fa5c4100c91e4 100644 --- a/src/test/ui/nll/mir_check_cast_reify.stderr +++ b/src/test/ui/nll/mir_check_cast_reify.stderr @@ -1,11 +1,11 @@ error: unsatisfied lifetime constraints - --> $DIR/mir_check_cast_reify.rs:47:5 + --> $DIR/mir_check_cast_reify.rs:46:25 | LL | fn bar<'a>(x: &'a u32) -> &'static u32 { | -- lifetime `'a` defined here ... -LL | f(x) - | ^^^^ returning this value requires that `'a` must outlive `'static` +LL | let f: fn(_) -> _ = foo; + | ^^^ cast requires that `'a` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/nll/mir_check_cast_unsafe_fn.rs b/src/test/ui/nll/mir_check_cast_unsafe_fn.rs index 71dcfc8886cc5..937ab31c31586 100644 --- a/src/test/ui/nll/mir_check_cast_unsafe_fn.rs +++ b/src/test/ui/nll/mir_check_cast_unsafe_fn.rs @@ -16,8 +16,8 @@ fn bar<'a>(input: &'a u32, f: fn(&'a u32) -> &'a u32) -> &'static u32 { // Here the NLL checker must relate the types in `f` to the types // in `g`. These are related via the `UnsafeFnPointer` cast. let g: unsafe fn(_) -> _ = f; + //~^ ERROR unsatisfied lifetime constraints unsafe { g(input) } - //~^ ERROR } fn main() {} diff --git a/src/test/ui/nll/mir_check_cast_unsafe_fn.stderr b/src/test/ui/nll/mir_check_cast_unsafe_fn.stderr index c14fb93a525e5..82ff71c055157 100644 --- a/src/test/ui/nll/mir_check_cast_unsafe_fn.stderr +++ b/src/test/ui/nll/mir_check_cast_unsafe_fn.stderr @@ -1,11 +1,11 @@ error: unsatisfied lifetime constraints - --> $DIR/mir_check_cast_unsafe_fn.rs:19:14 + --> $DIR/mir_check_cast_unsafe_fn.rs:18:32 | LL | fn bar<'a>(input: &'a u32, f: fn(&'a u32) -> &'a u32) -> &'static u32 { | -- lifetime `'a` defined here ... -LL | unsafe { g(input) } - | ^^^^^^^^ returning this value requires that `'a` must outlive `'static` +LL | let g: unsafe fn(_) -> _ = f; + | ^ cast requires that `'a` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/nll/mir_check_cast_unsize.stderr b/src/test/ui/nll/mir_check_cast_unsize.stderr index 526dfb6013386..77a2e8311f052 100644 --- a/src/test/ui/nll/mir_check_cast_unsize.stderr +++ b/src/test/ui/nll/mir_check_cast_unsize.stderr @@ -4,7 +4,7 @@ error: unsatisfied lifetime constraints LL | fn bar<'a>(x: &'a u32) -> &'static dyn Debug { | -- lifetime `'a` defined here LL | x - | ^ returning this value requires that `'a` must outlive `'static` + | ^ cast requires that `'a` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr b/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr index 61e9794b76e2e..9b7fe466696f8 100644 --- a/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr @@ -10,7 +10,7 @@ LL | with_signature(x, |mut y| Box::new(y.next())) i32, extern "rust-call" fn((std::boxed::Box,)) -> std::boxed::Box<(dyn Anything + '_#2r)> ] - = note: number of external vids: 4 + = note: number of external vids: 3 = note: where ::Item: '_#2r note: No external requirements @@ -50,7 +50,7 @@ LL | with_signature(x, |mut y| Box::new(y.next())) i32, extern "rust-call" fn((std::boxed::Box,)) -> std::boxed::Box<(dyn Anything + '_#2r)> ] - = note: number of external vids: 4 + = note: number of external vids: 3 = note: where ::Item: '_#2r note: No external requirements @@ -82,7 +82,7 @@ LL | with_signature(x, |mut y| Box::new(y.next())) i32, extern "rust-call" fn((std::boxed::Box,)) -> std::boxed::Box<(dyn Anything + '_#3r)> ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where ::Item: '_#3r note: No external requirements @@ -124,7 +124,7 @@ LL | with_signature(x, |mut y| Box::new(y.next())) i32, extern "rust-call" fn((std::boxed::Box,)) -> std::boxed::Box<(dyn Anything + '_#3r)> ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where ::Item: '_#3r note: No external requirements diff --git a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr index 918cf53cf36fa..24f4bea1ba2f8 100644 --- a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr @@ -10,7 +10,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#2r ()>, T)) ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where T: '_#2r = note: where '_#1r: '_#2r @@ -63,7 +63,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T)) ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where T: '_#3r = note: where '_#2r: '_#3r @@ -117,7 +117,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T)) ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where T: '_#3r = note: where '_#2r: '_#3r @@ -171,7 +171,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T)) ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where T: '_#3r = note: where '_#2r: '_#3r diff --git a/src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-closure.stderr b/src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-closure.stderr index ab1ad42f2a97e..df4f619b7763b 100644 --- a/src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-closure.stderr @@ -10,7 +10,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#2r ()>, T)) ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where '_#1r: '_#2r note: No external requirements @@ -54,7 +54,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T)) ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where '_#2r: '_#3r note: No external requirements @@ -99,7 +99,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T)) ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where '_#2r: '_#3r note: No external requirements @@ -144,7 +144,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T)) ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where '_#2r: '_#3r note: No external requirements @@ -177,7 +177,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#2r ()>, T)) ] - = note: number of external vids: 4 + = note: number of external vids: 3 = note: where '_#1r: '_#2r note: No external requirements diff --git a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.rs b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.rs index 72c1a631396be..b492525352442 100644 --- a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.rs +++ b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.rs @@ -46,7 +46,7 @@ where T: Anything<'b, 'c>, { with_signature(cell, t, |cell, t| require(cell, t)); - //~^ ERROR associated type `>::AssocType` may not live long enough + //~^ ERROR associated type `>::AssocType` may not live long enough } #[rustc_regions] @@ -56,7 +56,7 @@ where 'a: 'a, { with_signature(cell, t, |cell, t| require(cell, t)); - //~^ ERROR associated type `>::AssocType` may not live long enough + //~^ ERROR associated type `>::AssocType` may not live long enough } #[rustc_regions] @@ -76,7 +76,7 @@ where // can do better here with a more involved verification step. with_signature(cell, t, |cell, t| require(cell, t)); - //~^ ERROR associated type `>::AssocType` may not live long enough + //~^ ERROR associated type `>::AssocType` may not live long enough } #[rustc_regions] @@ -103,7 +103,7 @@ where T: Anything<'b, 'b>, { with_signature(cell, t, |cell, t| require(cell, t)); - //~^ ERROR + //~^ ERROR unsatisfied lifetime constraints } #[rustc_regions] diff --git a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr index 9cabd29b12dc4..176e45ae09872 100644 --- a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr @@ -11,7 +11,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T)) ] - = note: number of external vids: 6 + = note: number of external vids: 5 = note: where >::AssocType: '_#3r note: No external requirements @@ -22,7 +22,7 @@ LL | | where LL | | T: Anything<'b, 'c>, LL | | { LL | | with_signature(cell, t, |cell, t| require(cell, t)); -LL | | //~^ ERROR associated type `>::AssocType` may not live long enough +LL | | //~^ ERROR associated type `>::AssocType` may not live long enough LL | | } | |_^ | @@ -32,13 +32,13 @@ LL | | } T ] -error[E0309]: the associated type `>::AssocType` may not live long enough +error[E0309]: the associated type `>::AssocType` may not live long enough --> $DIR/projection-two-region-trait-bound-closure.rs:48:29 | LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `>::AssocType: ReFree(DefId(0/0:8 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(1:18), 'a))`... + = help: consider adding an explicit lifetime bound `>::AssocType: ReFree(DefId(0/0:8 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(1:18), 'a))`... note: External requirements --> $DIR/projection-two-region-trait-bound-closure.rs:58:29 @@ -54,7 +54,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#4r ()>, T)) ] - = note: number of external vids: 6 + = note: number of external vids: 5 = note: where >::AssocType: '_#4r note: No external requirements @@ -65,7 +65,7 @@ LL | | where LL | | T: Anything<'b, 'c>, LL | | 'a: 'a, ... | -LL | | //~^ ERROR associated type `>::AssocType` may not live long enough +LL | | //~^ ERROR associated type `>::AssocType` may not live long enough LL | | } | |_^ | @@ -76,13 +76,13 @@ LL | | } T ] -error[E0309]: the associated type `>::AssocType` may not live long enough +error[E0309]: the associated type `>::AssocType` may not live long enough --> $DIR/projection-two-region-trait-bound-closure.rs:58:29 | LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `>::AssocType: ReEarlyBound(0, 'a)`... + = help: consider adding an explicit lifetime bound `>::AssocType: ReEarlyBound(0, 'a)`... note: External requirements --> $DIR/projection-two-region-trait-bound-closure.rs:78:29 @@ -98,7 +98,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#4r ()>, T)) ] - = note: number of external vids: 6 + = note: number of external vids: 5 = note: where >::AssocType: '_#4r note: No external requirements @@ -109,7 +109,7 @@ LL | | where LL | | T: Anything<'b, 'c>, LL | | T::AssocType: 'a, ... | -LL | | //~^ ERROR associated type `>::AssocType` may not live long enough +LL | | //~^ ERROR associated type `>::AssocType` may not live long enough LL | | } | |_^ | @@ -120,13 +120,13 @@ LL | | } T ] -error[E0309]: the associated type `>::AssocType` may not live long enough +error[E0309]: the associated type `>::AssocType` may not live long enough --> $DIR/projection-two-region-trait-bound-closure.rs:78:29 | LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `>::AssocType: ReEarlyBound(0, 'a)`... + = help: consider adding an explicit lifetime bound `>::AssocType: ReEarlyBound(0, 'a)`... note: External requirements --> $DIR/projection-two-region-trait-bound-closure.rs:88:29 @@ -142,7 +142,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#4r ()>, T)) ] - = note: number of external vids: 6 + = note: number of external vids: 5 = note: where >::AssocType: '_#4r note: No external requirements @@ -178,7 +178,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#4r ()>, T)) ] - = note: number of external vids: 6 + = note: number of external vids: 5 = note: where >::AssocType: '_#4r note: No external requirements @@ -212,7 +212,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#2r ()>, T)) ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where >::AssocType: '_#2r note: No external requirements @@ -223,7 +223,7 @@ LL | | where LL | | T: Anything<'b, 'b>, LL | | { LL | | with_signature(cell, t, |cell, t| require(cell, t)); -LL | | //~^ ERROR +LL | | //~^ ERROR unsatisfied lifetime constraints LL | | } | |_^ | @@ -256,7 +256,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T)) ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where >::AssocType: '_#3r note: No external requirements @@ -289,7 +289,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t)); i32, extern "rust-call" fn((std::cell::Cell<&'_#2r ()>, T)) ] - = note: number of external vids: 4 + = note: number of external vids: 3 = note: where >::AssocType: '_#2r note: No external requirements diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr index 6050e627c71fd..1f5edf08957d6 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr @@ -9,7 +9,7 @@ LL | twice(cell, value, |a, b| invoke(a, b)); i16, for<'r, 's> extern "rust-call" fn((std::option::Option>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) T)) ] - = note: number of external vids: 3 + = note: number of external vids: 2 = note: where T: '_#1r note: No external requirements @@ -36,7 +36,7 @@ LL | twice(cell, value, |a, b| invoke(a, b)); i16, for<'r, 's> extern "rust-call" fn((std::option::Option>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) T)) ] - = note: number of external vids: 4 + = note: number of external vids: 3 = note: where T: '_#1r note: No external requirements diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr index 5215f6a527711..9e69ae051732c 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr @@ -10,7 +10,7 @@ LL | with_signature(x, |y| y) i32, extern "rust-call" fn((std::boxed::Box,)) -> std::boxed::Box<(dyn std::fmt::Debug + '_#2r)> ] - = note: number of external vids: 4 + = note: number of external vids: 3 = note: where T: '_#2r note: No external requirements diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr index 7129ec397de75..1b9baf61305d9 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr @@ -16,7 +16,7 @@ LL | | }) i32, extern "rust-call" fn((std::cell::Cell<&'_#1r ()>, T)) ] - = note: number of external vids: 4 + = note: number of external vids: 3 = note: where T: '_#1r note: No external requirements @@ -69,7 +69,7 @@ LL | | }) i32, extern "rust-call" fn((std::cell::Cell<&'_#2r ()>, T)) ] - = note: number of external vids: 4 + = note: number of external vids: 3 = note: where T: '_#2r note: No external requirements @@ -106,7 +106,7 @@ LL | | }) i32, extern "rust-call" fn((std::cell::Cell<&'_#2r ()>, T)) ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where T: '_#2r note: No external requirements @@ -156,7 +156,7 @@ LL | | }) i32, extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T)) ] - = note: number of external vids: 5 + = note: number of external vids: 4 = note: where T: '_#3r note: No external requirements diff --git a/src/test/ui/regions/regions-addr-of-self.nll.stderr b/src/test/ui/regions/regions-addr-of-self.nll.stderr index 18578a1813445..a85822e48fa6a 100644 --- a/src/test/ui/regions/regions-addr-of-self.nll.stderr +++ b/src/test/ui/regions/regions-addr-of-self.nll.stderr @@ -1,10 +1,10 @@ error: unsatisfied lifetime constraints - --> $DIR/regions-addr-of-self.rs:17:37 + --> $DIR/regions-addr-of-self.rs:17:13 | LL | pub fn chase_cat(&mut self) { | - let's call the lifetime of this reference `'1` LL | let p: &'static mut usize = &mut self.cats_chased; //~ ERROR cannot infer - | ^^^^^^^^^^^^^^^^^^^^^ requires that `'1` must outlive `'static` + | ^ requires that `'1` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/regions/regions-addr-of-upvar-self.nll.stderr b/src/test/ui/regions/regions-addr-of-upvar-self.nll.stderr index d20cf12f4161a..9d6301af0fbea 100644 --- a/src/test/ui/regions/regions-addr-of-upvar-self.nll.stderr +++ b/src/test/ui/regions/regions-addr-of-upvar-self.nll.stderr @@ -1,10 +1,22 @@ error: unsatisfied lifetime constraints - --> $DIR/regions-addr-of-upvar-self.rs:20:41 + --> $DIR/regions-addr-of-upvar-self.rs:20:17 | LL | let _f = || { | -- lifetime `'1` represents this closure's body LL | let p: &'static mut usize = &mut self.food; //~ ERROR cannot infer - | ^^^^^^^^^^^^^^ requires that `'1` must outlive `'static` + | ^ requires that `'1` must outlive `'static` + | + = note: closure implements `FnMut`, so references to captured variables can't escape the closure + +error: unsatisfied lifetime constraints + --> $DIR/regions-addr-of-upvar-self.rs:20:17 + | +LL | pub fn chase_cat(&mut self) { + | --------- lifetime `'2` appears in the type of `self` +LL | let _f = || { + | -- lifetime `'1` represents this closure's body +LL | let p: &'static mut usize = &mut self.food; //~ ERROR cannot infer + | ^ requires that `'1` must outlive `'2` | = note: closure implements `FnMut`, so references to captured variables can't escape the closure @@ -29,6 +41,6 @@ LL | } | = note: borrowed value must be valid for the static lifetime... -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/regions/regions-close-object-into-object-2.nll.stderr b/src/test/ui/regions/regions-close-object-into-object-2.nll.stderr index c073e3728e705..e619431ddbbc3 100644 --- a/src/test/ui/regions/regions-close-object-into-object-2.nll.stderr +++ b/src/test/ui/regions/regions-close-object-into-object-2.nll.stderr @@ -1,10 +1,10 @@ error: unsatisfied lifetime constraints - --> $DIR/regions-close-object-into-object-2.rs:20:5 + --> $DIR/regions-close-object-into-object-2.rs:20:11 | LL | fn g<'a, T: 'static>(v: Box+'a>) -> Box { | -- lifetime `'a` defined here LL | box B(&*v) as Box //~ ERROR cannot infer - | ^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` + | ^^^ cast requires that `'a` must outlive `'static` error[E0597]: `*v` does not live long enough --> $DIR/regions-close-object-into-object-2.rs:20:11 diff --git a/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr b/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr index 4b47b951d7717..1de1cdc9807f9 100644 --- a/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr +++ b/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr @@ -6,14 +6,6 @@ LL | box B(&*v) as Box //~ ERROR cannot infer | = help: consider adding an explicit lifetime bound `U: 'static`... -error: unsatisfied lifetime constraints - --> $DIR/regions-close-object-into-object-4.rs:20:5 - | -LL | fn i<'a, T, U>(v: Box+'a>) -> Box { - | -- lifetime `'a` defined here -LL | box B(&*v) as Box //~ ERROR cannot infer - | ^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` - error[E0310]: the parameter type `U` may not live long enough --> $DIR/regions-close-object-into-object-4.rs:20:9 | @@ -22,6 +14,14 @@ LL | box B(&*v) as Box //~ ERROR cannot infer | = help: consider adding an explicit lifetime bound `U: 'static`... +error: unsatisfied lifetime constraints + --> $DIR/regions-close-object-into-object-4.rs:20:11 + | +LL | fn i<'a, T, U>(v: Box+'a>) -> Box { + | -- lifetime `'a` defined here +LL | box B(&*v) as Box //~ ERROR cannot infer + | ^^^ cast requires that `'a` must outlive `'static` + error[E0597]: `*v` does not live long enough --> $DIR/regions-close-object-into-object-4.rs:20:11 | diff --git a/src/test/ui/regions/regions-static-bound.ll.nll.stderr b/src/test/ui/regions/regions-static-bound.ll.nll.stderr index 462fbe8ee19bd..dc3a32cec6ac7 100644 --- a/src/test/ui/regions/regions-static-bound.ll.nll.stderr +++ b/src/test/ui/regions/regions-static-bound.ll.nll.stderr @@ -15,7 +15,7 @@ LL | static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of | ^^^^^^^^^^^^^ lifetime `'static` required error[E0621]: explicit lifetime required in the type of `v` - --> $DIR/regions-static-bound.rs:26:5 + --> $DIR/regions-static-bound.rs:27:5 | LL | fn error(u: &(), v: &()) { | --- help: add explicit lifetime `'static` to the type of `v`: `&'static ()` @@ -23,6 +23,27 @@ LL | fn error(u: &(), v: &()) { LL | static_id_indirect(&v); //[ll]~ ERROR explicit lifetime required in the type of `v` [E0621] | ^^^^^^^^^^^^^^^^^^^^^^ lifetime `'static` required -error: aborting due to 3 previous errors +error: unsatisfied lifetime constraints + --> $DIR/regions-static-bound.rs:24:5 + | +LL | fn error(u: &(), v: &()) { + | - - let's call the lifetime of this reference `'2` + | | + | let's call the lifetime of this reference `'1` +LL | static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of `u` [E0621] + | ^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2` + +error: unsatisfied lifetime constraints + --> $DIR/regions-static-bound.rs:27:5 + | +LL | fn error(u: &(), v: &()) { + | - - let's call the lifetime of this reference `'1` + | | + | let's call the lifetime of this reference `'2` +... +LL | static_id_indirect(&v); //[ll]~ ERROR explicit lifetime required in the type of `v` [E0621] + | ^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2` + +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0621`. diff --git a/src/test/ui/regions/regions-static-bound.ll.stderr b/src/test/ui/regions/regions-static-bound.ll.stderr index cf291279210c9..16add00eb41e1 100644 --- a/src/test/ui/regions/regions-static-bound.ll.stderr +++ b/src/test/ui/regions/regions-static-bound.ll.stderr @@ -20,7 +20,7 @@ LL | static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of | ^^^^^^^^^ lifetime `'static` required error[E0621]: explicit lifetime required in the type of `v` - --> $DIR/regions-static-bound.rs:26:5 + --> $DIR/regions-static-bound.rs:27:5 | LL | fn error(u: &(), v: &()) { | --- help: add explicit lifetime `'static` to the type of `v`: `&'static ()` diff --git a/src/test/ui/regions/regions-static-bound.nll.stderr b/src/test/ui/regions/regions-static-bound.nll.stderr index 462fbe8ee19bd..dc3a32cec6ac7 100644 --- a/src/test/ui/regions/regions-static-bound.nll.stderr +++ b/src/test/ui/regions/regions-static-bound.nll.stderr @@ -15,7 +15,7 @@ LL | static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of | ^^^^^^^^^^^^^ lifetime `'static` required error[E0621]: explicit lifetime required in the type of `v` - --> $DIR/regions-static-bound.rs:26:5 + --> $DIR/regions-static-bound.rs:27:5 | LL | fn error(u: &(), v: &()) { | --- help: add explicit lifetime `'static` to the type of `v`: `&'static ()` @@ -23,6 +23,27 @@ LL | fn error(u: &(), v: &()) { LL | static_id_indirect(&v); //[ll]~ ERROR explicit lifetime required in the type of `v` [E0621] | ^^^^^^^^^^^^^^^^^^^^^^ lifetime `'static` required -error: aborting due to 3 previous errors +error: unsatisfied lifetime constraints + --> $DIR/regions-static-bound.rs:24:5 + | +LL | fn error(u: &(), v: &()) { + | - - let's call the lifetime of this reference `'2` + | | + | let's call the lifetime of this reference `'1` +LL | static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of `u` [E0621] + | ^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2` + +error: unsatisfied lifetime constraints + --> $DIR/regions-static-bound.rs:27:5 + | +LL | fn error(u: &(), v: &()) { + | - - let's call the lifetime of this reference `'1` + | | + | let's call the lifetime of this reference `'2` +... +LL | static_id_indirect(&v); //[ll]~ ERROR explicit lifetime required in the type of `v` [E0621] + | ^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2` + +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0621`. diff --git a/src/test/ui/regions/regions-static-bound.rs b/src/test/ui/regions/regions-static-bound.rs index c5dc6000e839c..34baf5ffff0a7 100644 --- a/src/test/ui/regions/regions-static-bound.rs +++ b/src/test/ui/regions/regions-static-bound.rs @@ -23,8 +23,10 @@ fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a { fn error(u: &(), v: &()) { static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of `u` [E0621] //[nll]~^ ERROR explicit lifetime required in the type of `u` [E0621] + //[nll]~| ERROR unsatisfied lifetime constraints static_id_indirect(&v); //[ll]~ ERROR explicit lifetime required in the type of `v` [E0621] //[nll]~^ ERROR explicit lifetime required in the type of `v` [E0621] + //[nll]~| ERROR unsatisfied lifetime constraints } fn main() {} diff --git a/src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr b/src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr index 7adb195b7d022..745c65c54df4a 100644 --- a/src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr +++ b/src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr @@ -5,7 +5,7 @@ LL | fn a(items: &[T]) -> Box> { | - let's call the lifetime of this reference `'1` LL | // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static` LL | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime - | ^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static` + | ^^^^^^^^^^^^^^^^^^^^^^ cast requires that `'1` must outlive `'static` error: aborting due to previous error