use borrow_check::nll::region_infer::error_reporting::region_name::RegionNameSource;
use borrow_check::nll::type_check::Locations;
use borrow_check::nll::universal_regions::DefiningTy;
+use util::borrowck_errors::{BorrowckErrors, Origin};
use rustc::hir::def_id::DefId;
use rustc::infer::error_reporting::nice_region_error::NiceRegionError;
use rustc::infer::InferCtxt;
match self {
ConstraintCategory::Assignment => "assignment ",
ConstraintCategory::Return => "returning this value ",
+ ConstraintCategory::UseAsConst => "using this value as a constant ",
+ ConstraintCategory::UseAsStatic => "using this value as a static ",
ConstraintCategory::Cast => "cast ",
ConstraintCategory::CallArgument => "argument ",
ConstraintCategory::TypeAnnotation => "type annotation ",
| ConstraintCategory::Boring
| ConstraintCategory::BoringNoLocation
| ConstraintCategory::Internal => false,
+ ConstraintCategory::TypeAnnotation
+ | ConstraintCategory::Return => true,
_ => constraint_sup_scc != target_scc,
}
});
let outlived_fr_name_and_span =
self.get_var_name_and_span_for_region(infcx.tcx, mir, outlived_fr);
- let escapes_from = if infcx.tcx.is_closure(mir_def_id) { "closure" } else { "function" };
+ let escapes_from = match self.universal_regions.defining_ty {
+ DefiningTy::Closure(..) => "closure",
+ DefiningTy::Generator(..) => "generator",
+ DefiningTy::FnDef(..) => "function",
+ DefiningTy::Const(..) => "const"
+ };
// Revert to the normal error in these cases.
// Assignments aren't "escapes" in function items.
if (fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none())
|| (category == ConstraintCategory::Assignment && escapes_from == "function")
+ || escapes_from == "const"
{
return self.report_general_error(mir, infcx, mir_def_id,
fr, true, outlived_fr, false,
category, span, errors_buffer);
}
- let mut diag = infcx.tcx.sess.struct_span_err(
- span, &format!("borrowed data escapes outside of {}", escapes_from),
- );
+ let mut diag = infcx.tcx.borrowed_data_escapes_closure(span, escapes_from, Origin::Mir);
if let Some((Some(outlived_fr_name), outlived_fr_span)) = outlived_fr_name_and_span {
diag.span_label(
let span = infcx.tcx.def_span(*did);
if let Ok(snippet) = infcx.tcx.sess.source_map().span_to_snippet(span) {
let suggestable_fr_name = if fr_name.was_named() {
- format!("{}", fr_name)
+ fr_name.to_string()
} else {
"'_".to_string()
};