1
Fork 0

Rollup merge of #64416 - mark-i-m:region-naming-ctx, r=estebank

Various refactorings to clean up nll diagnostics

- Create ErrorReportingCtx and ErrorConstraintInfo, vasting reducing the
  number of arguments passed around everywhere in the error reporting code
- Create RegionErrorNamingCtx, making a given lifetime have consistent
  numbering thoughout all error messages for that MIR def.
- Make the error reporting code return the DiagnosticBuilder rather than
  directly buffer the Diagnostic. This makes it easier to modify the
  diagnostic later, e.g. to add suggestions.

r? @estebank

Split out from https://github.com/rust-lang/rust/pull/58281
This commit is contained in:
Mazdak Farrokhzad 2019-09-17 03:08:36 +02:00 committed by GitHub
commit 69e93e8179
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 316 additions and 214 deletions

View file

@ -13,7 +13,7 @@ use rustc::infer::NLLRegionVariableOrigin;
use rustc::mir::{ConstraintCategory, Location, Body}; use rustc::mir::{ConstraintCategory, Location, Body};
use rustc::ty::{self, RegionVid}; use rustc::ty::{self, RegionVid};
use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::indexed_vec::IndexVec;
use rustc_errors::{Diagnostic, DiagnosticBuilder}; use rustc_errors::DiagnosticBuilder;
use std::collections::VecDeque; use std::collections::VecDeque;
use syntax::errors::Applicability; use syntax::errors::Applicability;
use syntax::symbol::kw; use syntax::symbol::kw;
@ -22,7 +22,7 @@ use syntax_pos::Span;
mod region_name; mod region_name;
mod var_name; mod var_name;
crate use self::region_name::{RegionName, RegionNameSource}; crate use self::region_name::{RegionName, RegionNameSource, RegionErrorNamingCtx};
impl ConstraintDescription for ConstraintCategory { impl ConstraintDescription for ConstraintCategory {
fn description(&self) -> &'static str { fn description(&self) -> &'static str {
@ -54,6 +54,39 @@ enum Trace {
NotVisited, NotVisited,
} }
/// Various pieces of state used when reporting borrow checker errors.
pub struct ErrorReportingCtx<'a, 'b, 'tcx> {
/// The region inference context used for borrow chekcing this MIR body.
#[allow(dead_code)] // FIXME(mark-i-m): used by outlives suggestions
region_infcx: &'b RegionInferenceContext<'tcx>,
/// The inference context used for type checking.
infcx: &'b InferCtxt<'a, 'tcx>,
/// The MIR def we are reporting errors on.
mir_def_id: DefId,
/// The MIR body we are reporting errors on (for convenience).
body: &'b Body<'tcx>,
/// Any upvars for the MIR body we have kept track of during borrow checking.
upvars: &'b [Upvar],
}
/// Information about the various region constraints involved in a borrow checker error.
#[derive(Clone, Debug)]
pub struct ErrorConstraintInfo {
// fr: outlived_fr
fr: RegionVid,
fr_is_local: bool,
outlived_fr: RegionVid,
outlived_fr_is_local: bool,
// Category and span for best blame constraint
category: ConstraintCategory,
span: Span,
}
impl<'tcx> RegionInferenceContext<'tcx> { impl<'tcx> RegionInferenceContext<'tcx> {
/// Tries to find the best constraint to blame for the fact that /// Tries to find the best constraint to blame for the fact that
/// `R: from_region`, where `R` is some region that meets /// `R: from_region`, where `R` is some region that meets
@ -257,16 +290,16 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// ``` /// ```
/// ///
/// Here we would be invoked with `fr = 'a` and `outlived_fr = `'b`. /// Here we would be invoked with `fr = 'a` and `outlived_fr = `'b`.
pub(super) fn report_error( pub(super) fn report_error<'a>(
&self, &'a self,
body: &Body<'tcx>, body: &Body<'tcx>,
upvars: &[Upvar], upvars: &[Upvar],
infcx: &InferCtxt<'_, 'tcx>, infcx: &'a InferCtxt<'a, 'tcx>,
mir_def_id: DefId, mir_def_id: DefId,
fr: RegionVid, fr: RegionVid,
outlived_fr: RegionVid, outlived_fr: RegionVid,
errors_buffer: &mut Vec<Diagnostic>, renctx: &mut RegionErrorNamingCtx,
) { ) -> DiagnosticBuilder<'a> {
debug!("report_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr); debug!("report_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
let (category, _, span) = self.best_blame_constraint(body, fr, |r| { let (category, _, span) = self.best_blame_constraint(body, fr, |r| {
@ -279,8 +312,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let tables = infcx.tcx.typeck_tables_of(mir_def_id); let tables = infcx.tcx.typeck_tables_of(mir_def_id);
let nice = NiceRegionError::new_from_span(infcx, span, o, f, Some(tables)); let nice = NiceRegionError::new_from_span(infcx, span, o, f, Some(tables));
if let Some(diag) = nice.try_report_from_nll() { if let Some(diag) = nice.try_report_from_nll() {
diag.buffer(errors_buffer); return diag;
return;
} }
} }
@ -293,45 +325,28 @@ impl<'tcx> RegionInferenceContext<'tcx> {
"report_error: fr_is_local={:?} outlived_fr_is_local={:?} category={:?}", "report_error: fr_is_local={:?} outlived_fr_is_local={:?} category={:?}",
fr_is_local, outlived_fr_is_local, category fr_is_local, outlived_fr_is_local, category
); );
let errctx = ErrorReportingCtx {
region_infcx: self,
infcx,
mir_def_id,
body,
upvars,
};
let errci = ErrorConstraintInfo {
fr, outlived_fr, fr_is_local, outlived_fr_is_local, category, span
};
match (category, fr_is_local, outlived_fr_is_local) { match (category, fr_is_local, outlived_fr_is_local) {
(ConstraintCategory::Return, true, false) if self.is_closure_fn_mut(infcx, fr) => { (ConstraintCategory::Return, true, false) if self.is_closure_fn_mut(infcx, fr) => {
self.report_fnmut_error( self.report_fnmut_error(&errctx, &errci, renctx)
body,
upvars,
infcx,
mir_def_id,
fr,
outlived_fr,
span,
errors_buffer,
)
} }
(ConstraintCategory::Assignment, true, false) (ConstraintCategory::Assignment, true, false)
| (ConstraintCategory::CallArgument, true, false) => self.report_escaping_data_error( | (ConstraintCategory::CallArgument, true, false) =>
body, self.report_escaping_data_error(&errctx, &errci, renctx),
upvars, _ => self.report_general_error(&errctx, &errci, renctx),
infcx, }
mir_def_id,
fr,
outlived_fr,
category,
span,
errors_buffer,
),
_ => self.report_general_error(
body,
upvars,
infcx,
mir_def_id,
fr,
fr_is_local,
outlived_fr,
outlived_fr_is_local,
category,
span,
errors_buffer,
),
};
} }
/// We have a constraint `fr1: fr2` that is not satisfied, where /// We have a constraint `fr1: fr2` that is not satisfied, where
@ -379,19 +394,19 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// ``` /// ```
fn report_fnmut_error( fn report_fnmut_error(
&self, &self,
body: &Body<'tcx>, errctx: &ErrorReportingCtx<'_, '_, 'tcx>,
upvars: &[Upvar], errci: &ErrorConstraintInfo,
infcx: &InferCtxt<'_, 'tcx>, renctx: &mut RegionErrorNamingCtx,
mir_def_id: DefId, ) -> DiagnosticBuilder<'_> {
_fr: RegionVid, let ErrorConstraintInfo {
outlived_fr: RegionVid, outlived_fr, span, ..
span: Span, } = errci;
errors_buffer: &mut Vec<Diagnostic>,
) { let mut diag = errctx
let mut diag = infcx .infcx
.tcx .tcx
.sess .sess
.struct_span_err(span, "captured variable cannot escape `FnMut` closure body"); .struct_span_err(*span, "captured variable cannot escape `FnMut` closure body");
// We should check if the return type of this closure is in fact a closure - in that // We should check if the return type of this closure is in fact a closure - in that
// case, we can special case the error further. // case, we can special case the error further.
@ -403,11 +418,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
"returns a reference to a captured variable which escapes the closure body" "returns a reference to a captured variable which escapes the closure body"
}; };
diag.span_label(span, message); diag.span_label(*span, message);
match self.give_region_a_name(infcx, body, upvars, mir_def_id, outlived_fr, &mut 1) match self.give_region_a_name(errctx, renctx, *outlived_fr).unwrap().source {
.unwrap().source
{
RegionNameSource::NamedEarlyBoundRegion(fr_span) RegionNameSource::NamedEarlyBoundRegion(fr_span)
| RegionNameSource::NamedFreeRegion(fr_span) | RegionNameSource::NamedFreeRegion(fr_span)
| RegionNameSource::SynthesizedFreeEnvRegion(fr_span, _) | RegionNameSource::SynthesizedFreeEnvRegion(fr_span, _)
@ -427,7 +440,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
); );
diag.note("...therefore, they cannot allow references to captured variables to escape"); diag.note("...therefore, they cannot allow references to captured variables to escape");
diag.buffer(errors_buffer); diag
} }
/// Reports a error specifically for when data is escaping a closure. /// Reports a error specifically for when data is escaping a closure.
@ -444,20 +457,22 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// ``` /// ```
fn report_escaping_data_error( fn report_escaping_data_error(
&self, &self,
body: &Body<'tcx>, errctx: &ErrorReportingCtx<'_, '_, 'tcx>,
upvars: &[Upvar], errci: &ErrorConstraintInfo,
infcx: &InferCtxt<'_, 'tcx>, renctx: &mut RegionErrorNamingCtx,
mir_def_id: DefId, ) -> DiagnosticBuilder<'_> {
fr: RegionVid, let ErrorReportingCtx {
outlived_fr: RegionVid, infcx, body, upvars, ..
category: ConstraintCategory, } = errctx;
span: Span,
errors_buffer: &mut Vec<Diagnostic>, let ErrorConstraintInfo {
) { span, category, ..
} = errci;
let fr_name_and_span = let fr_name_and_span =
self.get_var_name_and_span_for_region(infcx.tcx, body, upvars, fr); self.get_var_name_and_span_for_region(infcx.tcx, body, upvars, errci.fr);
let outlived_fr_name_and_span = let outlived_fr_name_and_span =
self.get_var_name_and_span_for_region(infcx.tcx, body, upvars, outlived_fr); self.get_var_name_and_span_for_region(infcx.tcx, body, upvars, errci.outlived_fr);
let escapes_from = match self.universal_regions.defining_ty { let escapes_from = match self.universal_regions.defining_ty {
DefiningTy::Closure(..) => "closure", DefiningTy::Closure(..) => "closure",
@ -469,27 +484,23 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// Revert to the normal error in these cases. // Revert to the normal error in these cases.
// Assignments aren't "escapes" in function items. // Assignments aren't "escapes" in function items.
if (fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none()) if (fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none())
|| (category == ConstraintCategory::Assignment && escapes_from == "function") || (*category == ConstraintCategory::Assignment && escapes_from == "function")
|| escapes_from == "const" || escapes_from == "const"
{ {
return self.report_general_error( return self.report_general_error(
body, errctx,
upvars, &ErrorConstraintInfo {
infcx, fr_is_local: true,
mir_def_id, outlived_fr_is_local: false,
fr, .. *errci
true, },
outlived_fr, renctx,
false,
category,
span,
errors_buffer,
); );
} }
let mut diag = borrowck_errors::borrowed_data_escapes_closure( let mut diag = borrowck_errors::borrowed_data_escapes_closure(
infcx.tcx, infcx.tcx,
span, *span,
escapes_from, escapes_from,
); );
@ -513,12 +524,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
); );
diag.span_label( diag.span_label(
span, *span,
format!("`{}` escapes the {} body here", fr_name, escapes_from), format!("`{}` escapes the {} body here", fr_name, escapes_from),
); );
} }
diag.buffer(errors_buffer); diag
} }
/// Reports a region inference error for the general case with named/synthesized lifetimes to /// Reports a region inference error for the general case with named/synthesized lifetimes to
@ -538,41 +549,37 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// ``` /// ```
fn report_general_error( fn report_general_error(
&self, &self,
body: &Body<'tcx>, errctx: &ErrorReportingCtx<'_, '_, 'tcx>,
upvars: &[Upvar], errci: &ErrorConstraintInfo,
infcx: &InferCtxt<'_, 'tcx>, renctx: &mut RegionErrorNamingCtx,
mir_def_id: DefId, ) -> DiagnosticBuilder<'_> {
fr: RegionVid, let ErrorReportingCtx {
fr_is_local: bool, infcx, mir_def_id, ..
outlived_fr: RegionVid, } = errctx;
outlived_fr_is_local: bool, let ErrorConstraintInfo {
category: ConstraintCategory, fr, fr_is_local, outlived_fr, outlived_fr_is_local, span, category, ..
span: Span, } = errci;
errors_buffer: &mut Vec<Diagnostic>,
) {
let mut diag = infcx.tcx.sess.struct_span_err( let mut diag = infcx.tcx.sess.struct_span_err(
span, *span,
"lifetime may not live long enough" "lifetime may not live long enough"
); );
let counter = &mut 1; let mir_def_name = if infcx.tcx.is_closure(*mir_def_id) {
let fr_name = self.give_region_a_name(
infcx, body, upvars, mir_def_id, fr, counter).unwrap();
fr_name.highlight_region_name(&mut diag);
let outlived_fr_name =
self.give_region_a_name(infcx, body, upvars, mir_def_id, outlived_fr, counter).unwrap();
outlived_fr_name.highlight_region_name(&mut diag);
let mir_def_name = if infcx.tcx.is_closure(mir_def_id) {
"closure" "closure"
} else { } else {
"function" "function"
}; };
let fr_name = self.give_region_a_name(errctx, renctx, *fr).unwrap();
fr_name.highlight_region_name(&mut diag);
let outlived_fr_name = self.give_region_a_name(errctx, renctx, *outlived_fr).unwrap();
outlived_fr_name.highlight_region_name(&mut diag);
match (category, outlived_fr_is_local, fr_is_local) { match (category, outlived_fr_is_local, fr_is_local) {
(ConstraintCategory::Return, true, _) => { (ConstraintCategory::Return, true, _) => {
diag.span_label( diag.span_label(
span, *span,
format!( format!(
"{} was supposed to return data with lifetime `{}` but it is returning \ "{} was supposed to return data with lifetime `{}` but it is returning \
data with lifetime `{}`", data with lifetime `{}`",
@ -582,7 +589,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
} }
_ => { _ => {
diag.span_label( diag.span_label(
span, *span,
format!( format!(
"{}requires that `{}` must outlive `{}`", "{}requires that `{}` must outlive `{}`",
category.description(), category.description(),
@ -593,9 +600,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
} }
} }
self.add_static_impl_trait_suggestion(infcx, &mut diag, fr, fr_name, outlived_fr); self.add_static_impl_trait_suggestion(infcx, &mut diag, *fr, fr_name, *outlived_fr);
diag.buffer(errors_buffer); diag
} }
/// Adds a suggestion to errors where a `impl Trait` is returned. /// Adds a suggestion to errors where a `impl Trait` is returned.
@ -704,8 +711,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
borrow_region, borrow_region,
|r| self.provides_universal_region(r, borrow_region, outlived_region) |r| self.provides_universal_region(r, borrow_region, outlived_region)
); );
let outlived_fr_name =
self.give_region_a_name(infcx, body, upvars, mir_def_id, outlived_region, &mut 1); let mut renctx = RegionErrorNamingCtx::new();
let errctx = ErrorReportingCtx {
infcx, body, upvars, mir_def_id,
region_infcx: self,
};
let outlived_fr_name = self.give_region_a_name(&errctx, &mut renctx, outlived_region);
(category, from_closure, span, outlived_fr_name) (category, from_closure, span, outlived_fr_name)
} }

View file

@ -1,5 +1,9 @@
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use crate::borrow_check::nll::region_infer::RegionInferenceContext;
use crate::borrow_check::nll::region_infer::{
RegionInferenceContext,
error_reporting::ErrorReportingCtx,
};
use crate::borrow_check::nll::universal_regions::DefiningTy; use crate::borrow_check::nll::universal_regions::DefiningTy;
use crate::borrow_check::nll::ToRegionVid; use crate::borrow_check::nll::ToRegionVid;
use crate::borrow_check::Upvar; use crate::borrow_check::Upvar;
@ -13,29 +17,75 @@ use rustc::ty::{self, RegionKind, RegionVid, Ty, TyCtxt};
use rustc::ty::print::RegionHighlightMode; use rustc::ty::print::RegionHighlightMode;
use rustc_errors::DiagnosticBuilder; use rustc_errors::DiagnosticBuilder;
use syntax::symbol::kw; use syntax::symbol::kw;
use syntax_pos::Span; use rustc_data_structures::fx::FxHashMap;
use syntax_pos::symbol::InternedString; use syntax_pos::{Span, symbol::InternedString};
#[derive(Debug)] /// A name for a particular region used in emitting diagnostics. This name could be a generated
/// name like `'1`, a name used by the user like `'a`, or a name like `'static`.
#[derive(Debug, Clone)]
crate struct RegionName { crate struct RegionName {
/// The name of the region (interned).
crate name: InternedString, crate name: InternedString,
/// Where the region comes from.
crate source: RegionNameSource, crate source: RegionNameSource,
} }
#[derive(Debug)] /// Denotes the source of a region that is named by a `RegionName`. For example, a free region that
/// was named by the user would get `NamedFreeRegion` and `'static` lifetime would get `Static`.
/// This helps to print the right kinds of diagnostics.
#[derive(Debug, Clone)]
crate enum RegionNameSource { crate enum RegionNameSource {
/// A bound (not free) region that was substituted at the def site (not an HRTB).
NamedEarlyBoundRegion(Span), NamedEarlyBoundRegion(Span),
/// A free region that the user has a name (`'a`) for.
NamedFreeRegion(Span), NamedFreeRegion(Span),
/// The `'static` region.
Static, Static,
/// The free region corresponding to the environment of a closure.
SynthesizedFreeEnvRegion(Span, String), SynthesizedFreeEnvRegion(Span, String),
/// The region name corresponds to a region where the type annotation is completely missing
/// from the code, e.g. in a closure arguments `|x| { ... }`, where `x` is a reference.
CannotMatchHirTy(Span, String), CannotMatchHirTy(Span, String),
/// The region name corresponds a reference that was found by traversing the type in the HIR.
MatchedHirTy(Span), MatchedHirTy(Span),
/// A region name from the generics list of a struct/enum/union.
MatchedAdtAndSegment(Span), MatchedAdtAndSegment(Span),
/// The region corresponding to a closure upvar.
AnonRegionFromUpvar(Span, String), AnonRegionFromUpvar(Span, String),
/// The region corresponding to the return type of a closure.
AnonRegionFromOutput(Span, String, String), AnonRegionFromOutput(Span, String, String),
AnonRegionFromYieldTy(Span, String), AnonRegionFromYieldTy(Span, String),
} }
/// Records region names that have been assigned before so that we can use the same ones in later
/// diagnostics.
#[derive(Debug, Clone)]
crate struct RegionErrorNamingCtx {
/// Record the region names generated for each region in the given
/// MIR def so that we can reuse them later in help/error messages.
renctx: FxHashMap<RegionVid, RegionName>,
/// The counter for generating new region names.
counter: usize,
}
impl RegionErrorNamingCtx {
crate fn new() -> Self {
Self {
counter: 1,
renctx: FxHashMap::default(),
}
}
crate fn get(&self, region: &RegionVid) -> Option<&RegionName> {
self.renctx.get(region)
}
crate fn insert(&mut self, region: RegionVid, name: RegionName) {
self.renctx.insert(region, name);
}
}
impl RegionName { impl RegionName {
#[allow(dead_code)] #[allow(dead_code)]
crate fn was_named(&self) -> bool { crate fn was_named(&self) -> bool {
@ -63,43 +113,40 @@ impl RegionName {
self.name self.name
} }
crate fn highlight_region_name( crate fn highlight_region_name(&self, diag: &mut DiagnosticBuilder<'_>) {
&self,
diag: &mut DiagnosticBuilder<'_>
) {
match &self.source { match &self.source {
RegionNameSource::NamedFreeRegion(span) | RegionNameSource::NamedFreeRegion(span)
RegionNameSource::NamedEarlyBoundRegion(span) => { | RegionNameSource::NamedEarlyBoundRegion(span) => {
diag.span_label( diag.span_label(*span, format!("lifetime `{}` defined here", self));
*span, }
format!("lifetime `{}` defined here", self),
);
},
RegionNameSource::SynthesizedFreeEnvRegion(span, note) => { RegionNameSource::SynthesizedFreeEnvRegion(span, note) => {
diag.span_label( diag.span_label(
*span, *span,
format!("lifetime `{}` represents this closure's body", self), format!("lifetime `{}` represents this closure's body", self),
); );
diag.note(&note); diag.note(&note);
}, }
RegionNameSource::CannotMatchHirTy(span, type_name) => { RegionNameSource::CannotMatchHirTy(span, type_name) => {
diag.span_label(*span, format!("has type `{}`", type_name)); diag.span_label(*span, format!("has type `{}`", type_name));
}, }
RegionNameSource::MatchedHirTy(span) => { RegionNameSource::MatchedHirTy(span) => {
diag.span_label( diag.span_label(
*span, *span,
format!("let's call the lifetime of this reference `{}`", self), format!("let's call the lifetime of this reference `{}`", self),
); );
}, }
RegionNameSource::MatchedAdtAndSegment(span) => { RegionNameSource::MatchedAdtAndSegment(span) => {
diag.span_label(*span, format!("let's call this `{}`", self)); diag.span_label(*span, format!("let's call this `{}`", self));
}, }
RegionNameSource::AnonRegionFromUpvar(span, upvar_name) => { RegionNameSource::AnonRegionFromUpvar(span, upvar_name) => {
diag.span_label( diag.span_label(
*span, *span,
format!("lifetime `{}` appears in the type of `{}`", self, upvar_name), format!(
"lifetime `{}` appears in the type of `{}`",
self, upvar_name
),
); );
}, }
RegionNameSource::AnonRegionFromOutput(span, mir_description, type_name) => { RegionNameSource::AnonRegionFromOutput(span, mir_description, type_name) => {
diag.span_label( diag.span_label(
*span, *span,
@ -151,39 +198,49 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// and then return the name `'1` for us to use. /// and then return the name `'1` for us to use.
crate fn give_region_a_name( crate fn give_region_a_name(
&self, &self,
infcx: &InferCtxt<'_, 'tcx>, errctx: &ErrorReportingCtx<'_, '_, 'tcx>,
body: &Body<'tcx>, renctx: &mut RegionErrorNamingCtx,
upvars: &[Upvar],
mir_def_id: DefId,
fr: RegionVid, fr: RegionVid,
counter: &mut usize,
) -> Option<RegionName> { ) -> Option<RegionName> {
debug!("give_region_a_name(fr={:?}, counter={})", fr, counter); let ErrorReportingCtx {
infcx, body, mir_def_id, upvars, ..
} = errctx;
debug!("give_region_a_name(fr={:?}, counter={:?})", fr, renctx.counter);
assert!(self.universal_regions.is_universal_region(fr)); assert!(self.universal_regions.is_universal_region(fr));
let value = self.give_name_from_error_region(infcx.tcx, mir_def_id, fr, counter) if let Some(value) = renctx.get(&fr) {
return Some(value.clone());
}
let value = self
.give_name_from_error_region(infcx.tcx, *mir_def_id, fr, renctx)
.or_else(|| { .or_else(|| {
self.give_name_if_anonymous_region_appears_in_arguments( self.give_name_if_anonymous_region_appears_in_arguments(
infcx, body, mir_def_id, fr, counter, infcx, body, *mir_def_id, fr, renctx,
) )
}) })
.or_else(|| { .or_else(|| {
self.give_name_if_anonymous_region_appears_in_upvars( self.give_name_if_anonymous_region_appears_in_upvars(
infcx.tcx, upvars, fr, counter, infcx.tcx, upvars, fr, renctx
) )
}) })
.or_else(|| { .or_else(|| {
self.give_name_if_anonymous_region_appears_in_output( self.give_name_if_anonymous_region_appears_in_output(
infcx, body, mir_def_id, fr, counter, infcx, body, *mir_def_id, fr, renctx,
) )
}) })
.or_else(|| { .or_else(|| {
self.give_name_if_anonymous_region_appears_in_yield_ty( self.give_name_if_anonymous_region_appears_in_yield_ty(
infcx, body, mir_def_id, fr, counter, infcx, body, *mir_def_id, fr, renctx,
) )
}); });
if let Some(ref value) = value {
renctx.insert(fr, value.clone());
}
debug!("give_region_a_name: gave name {:?}", value); debug!("give_region_a_name: gave name {:?}", value);
value value
} }
@ -197,7 +254,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
mir_def_id: DefId, mir_def_id: DefId,
fr: RegionVid, fr: RegionVid,
counter: &mut usize, renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> { ) -> Option<RegionName> {
let error_region = self.to_error_region(fr)?; let error_region = self.to_error_region(fr)?;
@ -208,7 +265,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let span = self.get_named_span(tcx, error_region, ebr.name); let span = self.get_named_span(tcx, error_region, ebr.name);
Some(RegionName { Some(RegionName {
name: ebr.name, name: ebr.name,
source: RegionNameSource::NamedEarlyBoundRegion(span) source: RegionNameSource::NamedEarlyBoundRegion(span),
}) })
} else { } else {
None None
@ -227,12 +284,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
name, name,
source: RegionNameSource::NamedFreeRegion(span), source: RegionNameSource::NamedFreeRegion(span),
}) })
}, }
ty::BoundRegion::BrEnv => { ty::BoundRegion::BrEnv => {
let mir_hir_id = tcx.hir() let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).expect("non-local mir");
.as_local_hir_id(mir_def_id)
.expect("non-local mir");
let def_ty = self.universal_regions.defining_ty; let def_ty = self.universal_regions.defining_ty;
if let DefiningTy::Closure(def_id, substs) = def_ty { if let DefiningTy::Closure(def_id, substs) = def_ty {
@ -243,7 +298,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
} else { } else {
bug!("Closure is not defined by a closure expr"); bug!("Closure is not defined by a closure expr");
}; };
let region_name = self.synthesize_region_name(counter); let region_name = self.synthesize_region_name(renctx);
let closure_kind_ty = substs.closure_kind_ty(def_id, tcx); let closure_kind_ty = substs.closure_kind_ty(def_id, tcx);
let note = match closure_kind_ty.to_opt_closure_kind() { let note = match closure_kind_ty.to_opt_closure_kind() {
@ -265,7 +320,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
name: region_name, name: region_name,
source: RegionNameSource::SynthesizedFreeEnvRegion( source: RegionNameSource::SynthesizedFreeEnvRegion(
args_span, args_span,
note.to_string() note.to_string(),
), ),
}) })
} else { } else {
@ -335,7 +390,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
body: &Body<'tcx>, body: &Body<'tcx>,
mir_def_id: DefId, mir_def_id: DefId,
fr: RegionVid, fr: RegionVid,
counter: &mut usize, renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> { ) -> Option<RegionName> {
let implicit_inputs = self.universal_regions.defining_ty.implicit_inputs(); let implicit_inputs = self.universal_regions.defining_ty.implicit_inputs();
let argument_index = self.get_argument_index_for_region(infcx.tcx, fr)?; let argument_index = self.get_argument_index_for_region(infcx.tcx, fr)?;
@ -349,12 +404,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
fr, fr,
arg_ty, arg_ty,
argument_index, argument_index,
counter, renctx,
) { ) {
return Some(region_name); return Some(region_name);
} }
self.give_name_if_we_cannot_match_hir_ty(infcx, body, fr, arg_ty, counter) self.give_name_if_we_cannot_match_hir_ty(infcx, body, fr, arg_ty, renctx)
} }
fn give_name_if_we_can_match_hir_ty_from_argument( fn give_name_if_we_can_match_hir_ty_from_argument(
@ -365,7 +420,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
needle_fr: RegionVid, needle_fr: RegionVid,
argument_ty: Ty<'tcx>, argument_ty: Ty<'tcx>,
argument_index: usize, argument_index: usize,
counter: &mut usize, renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> { ) -> Option<RegionName> {
let mir_hir_id = infcx.tcx.hir().as_local_hir_id(mir_def_id)?; let mir_hir_id = infcx.tcx.hir().as_local_hir_id(mir_def_id)?;
let fn_decl = infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?; let fn_decl = infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?;
@ -379,7 +434,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
body, body,
needle_fr, needle_fr,
argument_ty, argument_ty,
counter, renctx,
), ),
_ => self.give_name_if_we_can_match_hir_ty( _ => self.give_name_if_we_can_match_hir_ty(
@ -387,7 +442,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
needle_fr, needle_fr,
argument_ty, argument_ty,
argument_hir_ty, argument_hir_ty,
counter, renctx,
), ),
} }
} }
@ -409,10 +464,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
body: &Body<'tcx>, body: &Body<'tcx>,
needle_fr: RegionVid, needle_fr: RegionVid,
argument_ty: Ty<'tcx>, argument_ty: Ty<'tcx>,
counter: &mut usize, renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> { ) -> Option<RegionName> {
let counter = renctx.counter;
let mut highlight = RegionHighlightMode::default(); let mut highlight = RegionHighlightMode::default();
highlight.highlighting_region_vid(needle_fr, *counter); highlight.highlighting_region_vid(needle_fr, counter);
let type_name = infcx.extract_type_name(&argument_ty, Some(highlight)).0; let type_name = infcx.extract_type_name(&argument_ty, Some(highlight)).0;
debug!( debug!(
@ -428,7 +484,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// This counter value will already have been used, so this function will increment // This counter value will already have been used, so this function will increment
// it so the next value will be used next and return the region name that would // it so the next value will be used next and return the region name that would
// have been used. // have been used.
name: self.synthesize_region_name(counter), name: self.synthesize_region_name(renctx),
source: RegionNameSource::CannotMatchHirTy(span, type_name), source: RegionNameSource::CannotMatchHirTy(span, type_name),
}) })
} else { } else {
@ -455,7 +511,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// type. Once we find that, we can use the span of the `hir::Ty` /// type. Once we find that, we can use the span of the `hir::Ty`
/// to add the highlight. /// to add the highlight.
/// ///
/// This is a somewhat imperfect process, so long the way we also /// This is a somewhat imperfect process, so along the way we also
/// keep track of the **closest** type we've found. If we fail to /// keep track of the **closest** type we've found. If we fail to
/// find the exact `&` or `'_` to highlight, then we may fall back /// find the exact `&` or `'_` to highlight, then we may fall back
/// to highlighting that closest type instead. /// to highlighting that closest type instead.
@ -465,7 +521,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
needle_fr: RegionVid, needle_fr: RegionVid,
argument_ty: Ty<'tcx>, argument_ty: Ty<'tcx>,
argument_hir_ty: &hir::Ty, argument_hir_ty: &hir::Ty,
counter: &mut usize, renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> { ) -> Option<RegionName> {
let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty)> = let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty)> =
&mut vec![(argument_ty, argument_hir_ty)]; &mut vec![(argument_ty, argument_hir_ty)];
@ -483,7 +539,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
hir::TyKind::Rptr(_lifetime, referent_hir_ty), hir::TyKind::Rptr(_lifetime, referent_hir_ty),
) => { ) => {
if region.to_region_vid() == needle_fr { if region.to_region_vid() == needle_fr {
let region_name = self.synthesize_region_name(counter); let region_name = self.synthesize_region_name(renctx);
// Just grab the first character, the `&`. // Just grab the first character, the `&`.
let source_map = tcx.sess.source_map(); let source_map = tcx.sess.source_map();
@ -515,7 +571,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
substs, substs,
needle_fr, needle_fr,
last_segment, last_segment,
counter, renctx,
search_stack, search_stack,
) { ) {
return Some(name); return Some(name);
@ -559,18 +615,19 @@ impl<'tcx> RegionInferenceContext<'tcx> {
substs: SubstsRef<'tcx>, substs: SubstsRef<'tcx>,
needle_fr: RegionVid, needle_fr: RegionVid,
last_segment: &'hir hir::PathSegment, last_segment: &'hir hir::PathSegment,
counter: &mut usize, renctx: &mut RegionErrorNamingCtx,
search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty)>, search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty)>,
) -> Option<RegionName> { ) -> Option<RegionName> {
// Did the user give explicit arguments? (e.g., `Foo<..>`) // Did the user give explicit arguments? (e.g., `Foo<..>`)
let args = last_segment.args.as_ref()?; let args = last_segment.args.as_ref()?;
let lifetime = self.try_match_adt_and_generic_args(substs, needle_fr, args, search_stack)?; let lifetime =
self.try_match_adt_and_generic_args(substs, needle_fr, args, search_stack)?;
match lifetime.name { match lifetime.name {
hir::LifetimeName::Param(_) hir::LifetimeName::Param(_)
| hir::LifetimeName::Error | hir::LifetimeName::Error
| hir::LifetimeName::Static | hir::LifetimeName::Static
| hir::LifetimeName::Underscore => { | hir::LifetimeName::Underscore => {
let region_name = self.synthesize_region_name(counter); let region_name = self.synthesize_region_name(renctx);
let ampersand_span = lifetime.span; let ampersand_span = lifetime.span;
Some(RegionName { Some(RegionName {
name: region_name, name: region_name,
@ -657,12 +714,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
upvars: &[Upvar], upvars: &[Upvar],
fr: RegionVid, fr: RegionVid,
counter: &mut usize, renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> { ) -> Option<RegionName> {
let upvar_index = self.get_upvar_index_for_region(tcx, fr)?; let upvar_index = self.get_upvar_index_for_region(tcx, fr)?;
let (upvar_name, upvar_span) = let (upvar_name, upvar_span) =
self.get_upvar_name_and_span_for_region(tcx, upvars, upvar_index); self.get_upvar_name_and_span_for_region(tcx, upvars, upvar_index);
let region_name = self.synthesize_region_name(counter); let region_name = self.synthesize_region_name(renctx);
Some(RegionName { Some(RegionName {
name: region_name, name: region_name,
@ -680,7 +737,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
body: &Body<'tcx>, body: &Body<'tcx>,
mir_def_id: DefId, mir_def_id: DefId,
fr: RegionVid, fr: RegionVid,
counter: &mut usize, renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> { ) -> Option<RegionName> {
let tcx = infcx.tcx; let tcx = infcx.tcx;
@ -694,7 +751,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
} }
let mut highlight = RegionHighlightMode::default(); let mut highlight = RegionHighlightMode::default();
highlight.highlighting_region_vid(fr, *counter); highlight.highlighting_region_vid(fr, renctx.counter);
let type_name = infcx.extract_type_name(&return_ty, Some(highlight)).0; let type_name = infcx.extract_type_name(&return_ty, Some(highlight)).0;
let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).expect("non-local mir"); let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).expect("non-local mir");
@ -725,11 +782,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// This counter value will already have been used, so this function will increment it // This counter value will already have been used, so this function will increment it
// so the next value will be used next and return the region name that would have been // so the next value will be used next and return the region name that would have been
// used. // used.
name: self.synthesize_region_name(counter), name: self.synthesize_region_name(renctx),
source: RegionNameSource::AnonRegionFromOutput( source: RegionNameSource::AnonRegionFromOutput(
return_span, return_span,
mir_description.to_string(), mir_description.to_string(),
type_name type_name,
), ),
}) })
} }
@ -740,7 +797,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
body: &Body<'tcx>, body: &Body<'tcx>,
mir_def_id: DefId, mir_def_id: DefId,
fr: RegionVid, fr: RegionVid,
counter: &mut usize, renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> { ) -> Option<RegionName> {
// Note: generators from `async fn` yield `()`, so we don't have to // Note: generators from `async fn` yield `()`, so we don't have to
// worry about them here. // worry about them here.
@ -757,7 +814,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
} }
let mut highlight = RegionHighlightMode::default(); let mut highlight = RegionHighlightMode::default();
highlight.highlighting_region_vid(fr, *counter); highlight.highlighting_region_vid(fr, renctx.counter);
let type_name = infcx.extract_type_name(&yield_ty, Some(highlight)).0; let type_name = infcx.extract_type_name(&yield_ty, Some(highlight)).0;
let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).expect("non-local mir"); let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).expect("non-local mir");
@ -780,16 +837,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
); );
Some(RegionName { Some(RegionName {
name: self.synthesize_region_name(counter), name: self.synthesize_region_name(renctx),
source: RegionNameSource::AnonRegionFromYieldTy(yield_span, type_name), source: RegionNameSource::AnonRegionFromYieldTy(yield_span, type_name),
}) })
} }
/// Creates a synthetic region named `'1`, incrementing the /// Creates a synthetic region named `'1`, incrementing the counter.
/// counter. fn synthesize_region_name(&self, renctx: &mut RegionErrorNamingCtx) -> InternedString {
fn synthesize_region_name(&self, counter: &mut usize) -> InternedString { let c = renctx.counter;
let c = *counter; renctx.counter += 1;
*counter += 1;
InternedString::intern(&format!("'{:?}", c)) InternedString::intern(&format!("'{:?}", c))
} }

View file

@ -1,15 +1,20 @@
use super::universal_regions::UniversalRegions; use std::rc::Rc;
use crate::borrow_check::nll::constraints::graph::NormalConstraintGraph;
use crate::borrow_check::nll::constraints::{ use crate::borrow_check::nll::{
ConstraintSccIndex, OutlivesConstraint, OutlivesConstraintSet, constraints::{
graph::NormalConstraintGraph,
ConstraintSccIndex,
OutlivesConstraint,
OutlivesConstraintSet,
},
member_constraints::{MemberConstraintSet, NllMemberConstraintIndex},
region_infer::values::{
PlaceholderIndices, RegionElement, ToElementIndex
},
type_check::{free_region_relations::UniversalRegionRelations, Locations},
}; };
use crate::borrow_check::nll::member_constraints::{MemberConstraintSet, NllMemberConstraintIndex};
use crate::borrow_check::nll::region_infer::values::{
PlaceholderIndices, RegionElement, ToElementIndex,
};
use crate::borrow_check::nll::type_check::free_region_relations::UniversalRegionRelations;
use crate::borrow_check::nll::type_check::Locations;
use crate::borrow_check::Upvar; use crate::borrow_check::Upvar;
use rustc::hir::def_id::DefId; use rustc::hir::def_id::DefId;
use rustc::infer::canonical::QueryOutlivesConstraint; use rustc::infer::canonical::QueryOutlivesConstraint;
use rustc::infer::opaque_types; use rustc::infer::opaque_types;
@ -31,16 +36,16 @@ use rustc_data_structures::indexed_vec::IndexVec;
use rustc_errors::{Diagnostic, DiagnosticBuilder}; use rustc_errors::{Diagnostic, DiagnosticBuilder};
use syntax_pos::Span; use syntax_pos::Span;
use std::rc::Rc; crate use self::error_reporting::{RegionName, RegionNameSource, RegionErrorNamingCtx};
use self::values::{LivenessValues, RegionValueElements, RegionValues};
use super::universal_regions::UniversalRegions;
use super::ToRegionVid;
mod dump_mir; mod dump_mir;
mod error_reporting; mod error_reporting;
crate use self::error_reporting::{RegionName, RegionNameSource};
mod graphviz; mod graphviz;
pub mod values;
use self::values::{LivenessValues, RegionValueElements, RegionValues};
use super::ToRegionVid; pub mod values;
pub struct RegionInferenceContext<'tcx> { pub struct RegionInferenceContext<'tcx> {
/// Contains the definition for every region variable. Region /// Contains the definition for every region variable. Region
@ -487,6 +492,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
errors_buffer, errors_buffer,
); );
// If we produce any errors, we keep track of the names of all regions, so that we can use
// the same error names in any suggestions we produce. Note that we need names to be unique
// across different errors for the same MIR def so that we can make suggestions that fix
// multiple problems.
let mut region_naming = RegionErrorNamingCtx::new();
self.check_universal_regions( self.check_universal_regions(
infcx, infcx,
body, body,
@ -494,6 +505,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
mir_def_id, mir_def_id,
outlives_requirements.as_mut(), outlives_requirements.as_mut(),
errors_buffer, errors_buffer,
&mut region_naming,
); );
self.check_member_constraints(infcx, mir_def_id, errors_buffer); self.check_member_constraints(infcx, mir_def_id, errors_buffer);
@ -1312,6 +1324,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
mir_def_id: DefId, mir_def_id: DefId,
mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>, mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
errors_buffer: &mut Vec<Diagnostic>, errors_buffer: &mut Vec<Diagnostic>,
region_naming: &mut RegionErrorNamingCtx,
) { ) {
for (fr, fr_definition) in self.definitions.iter_enumerated() { for (fr, fr_definition) in self.definitions.iter_enumerated() {
match fr_definition.origin { match fr_definition.origin {
@ -1327,6 +1340,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
fr, fr,
&mut propagated_outlives_requirements, &mut propagated_outlives_requirements,
errors_buffer, errors_buffer,
region_naming,
); );
} }
@ -1358,6 +1372,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
longer_fr: RegionVid, longer_fr: RegionVid,
propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>, propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
errors_buffer: &mut Vec<Diagnostic>, errors_buffer: &mut Vec<Diagnostic>,
region_naming: &mut RegionErrorNamingCtx,
) { ) {
debug!("check_universal_region(fr={:?})", longer_fr); debug!("check_universal_region(fr={:?})", longer_fr);
@ -1385,6 +1400,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
mir_def_id, mir_def_id,
propagated_outlives_requirements, propagated_outlives_requirements,
errors_buffer, errors_buffer,
region_naming,
); );
return; return;
} }
@ -1401,8 +1417,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
mir_def_id, mir_def_id,
propagated_outlives_requirements, propagated_outlives_requirements,
errors_buffer, errors_buffer,
region_naming,
) { ) {
// continuing to iterate just reports more errors than necessary // continuing to iterate just reports more errors than necessary
//
// FIXME It would also allow us to report more Outlives Suggestions, though, so
// it's not clear that that's a bad thing. Somebody should try commenting out this
// line and see it is actually a regression.
return; return;
} }
} }
@ -1418,6 +1439,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
mir_def_id: DefId, mir_def_id: DefId,
propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>, propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
errors_buffer: &mut Vec<Diagnostic>, errors_buffer: &mut Vec<Diagnostic>,
region_naming: &mut RegionErrorNamingCtx,
) -> Option<ErrorReported> { ) -> Option<ErrorReported> {
// If it is known that `fr: o`, carry on. // If it is known that `fr: o`, carry on.
if self.universal_region_relations.outlives(longer_fr, shorter_fr) { if self.universal_region_relations.outlives(longer_fr, shorter_fr) {
@ -1466,7 +1488,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// //
// Note: in this case, we use the unapproximated regions to report the // Note: in this case, we use the unapproximated regions to report the
// error. This gives better error messages in some cases. // error. This gives better error messages in some cases.
self.report_error(body, upvars, infcx, mir_def_id, longer_fr, shorter_fr, errors_buffer); let db = self.report_error(
body,
upvars,
infcx,
mir_def_id,
longer_fr,
shorter_fr,
region_naming,
);
db.buffer(errors_buffer);
Some(ErrorReported) Some(ErrorReported)
} }

View file

@ -37,11 +37,11 @@ error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:20:5 --> $DIR/variadic-ffi-4.rs:20:5
| |
LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| ------- ------- has type `core::ffi::VaListImpl<'1>` | ------- ------- has type `core::ffi::VaListImpl<'2>`
| | | |
| has type `&mut core::ffi::VaListImpl<'2>` | has type `&mut core::ffi::VaListImpl<'1>`
LL | *ap0 = ap1; LL | *ap0 = ap1;
| ^^^^ assignment requires that `'1` must outlive `'2` | ^^^^ assignment requires that `'2` must outlive `'1`
error: lifetime may not live long enough error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:25:5 --> $DIR/variadic-ffi-4.rs:25:5
@ -57,11 +57,11 @@ error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:25:5 --> $DIR/variadic-ffi-4.rs:25:5
| |
LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
| --- ------- has type `core::ffi::VaListImpl<'1>` | --- ------- has type `core::ffi::VaListImpl<'2>`
| | | |
| has type `&mut core::ffi::VaListImpl<'2>` | has type `&mut core::ffi::VaListImpl<'1>`
LL | ap0 = &mut ap1; LL | ap0 = &mut ap1;
| ^^^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2` | ^^^^^^^^^^^^^^ assignment requires that `'2` must outlive `'1`
error[E0384]: cannot assign to immutable argument `ap0` error[E0384]: cannot assign to immutable argument `ap0`
--> $DIR/variadic-ffi-4.rs:25:5 --> $DIR/variadic-ffi-4.rs:25:5
@ -99,11 +99,11 @@ error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:33:12 --> $DIR/variadic-ffi-4.rs:33:12
| |
LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| ------- ------- has type `core::ffi::VaListImpl<'1>` | ------- ------- has type `core::ffi::VaListImpl<'2>`
| | | |
| has type `&mut core::ffi::VaListImpl<'2>` | has type `&mut core::ffi::VaListImpl<'1>`
LL | *ap0 = ap1.clone(); LL | *ap0 = ap1.clone();
| ^^^^^^^^^^^ argument requires that `'1` must outlive `'2` | ^^^^^^^^^^^ argument requires that `'2` must outlive `'1`
error: aborting due to 11 previous errors error: aborting due to 11 previous errors

View file

@ -12,11 +12,11 @@ error: lifetime may not live long enough
--> $DIR/ex3-both-anon-regions-3.rs:2:5 --> $DIR/ex3-both-anon-regions-3.rs:2:5
| |
LL | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) { LL | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
| - - let's call the lifetime of this reference `'1` | - - let's call the lifetime of this reference `'3`
| | | |
| let's call the lifetime of this reference `'2` | let's call the lifetime of this reference `'4`
LL | z.push((x,y)); LL | z.push((x,y));
| ^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2` | ^^^^^^^^^^^^^ argument requires that `'3` must outlive `'4`
error: aborting due to 2 previous errors error: aborting due to 2 previous errors