mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-05 03:23:25 +00:00
rustc: take TyCtxt and RegionMaps in CodeMap::span.
This commit is contained in:
parent
28ddd7a4ef
commit
ea6aca7726
@ -64,7 +64,7 @@ use std::fmt;
|
||||
use hir;
|
||||
use hir::map as hir_map;
|
||||
use hir::def_id::DefId;
|
||||
use middle::region;
|
||||
use middle::region::{self, RegionMaps};
|
||||
use traits::{ObligationCause, ObligationCauseCode};
|
||||
use ty::{self, Region, TyCtxt, TypeFoldable};
|
||||
use ty::error::TypeError;
|
||||
@ -83,6 +83,7 @@ mod anon_anon_conflict;
|
||||
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn note_and_explain_region(self,
|
||||
region_maps: &RegionMaps,
|
||||
err: &mut DiagnosticBuilder,
|
||||
prefix: &str,
|
||||
region: ty::Region<'tcx>,
|
||||
@ -130,13 +131,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
format!("{}unknown scope: {:?}{}. Please report a bug.",
|
||||
prefix, scope, suffix)
|
||||
};
|
||||
let span = match scope.span(&self.hir) {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
err.note(&unknown_scope());
|
||||
return;
|
||||
}
|
||||
};
|
||||
let span = scope.span(self, region_maps);
|
||||
let tag = match self.hir.find(scope.node_id()) {
|
||||
Some(hir_map::NodeBlock(_)) => "block",
|
||||
Some(hir_map::NodeExpr(expr)) => match expr.node {
|
||||
@ -260,8 +255,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
pub fn report_region_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>) {
|
||||
pub fn report_region_errors(&self,
|
||||
region_maps: &RegionMaps,
|
||||
errors: &Vec<RegionResolutionError<'tcx>>) {
|
||||
debug!("report_region_errors(): {} errors to start", errors.len());
|
||||
|
||||
// try to pre-process the errors, which will group some of them
|
||||
@ -285,16 +281,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
// the error. If all of these fails, we fall back to a rather
|
||||
// general bit of code that displays the error information
|
||||
ConcreteFailure(origin, sub, sup) => {
|
||||
|
||||
self.report_concrete_failure(origin, sub, sup).emit();
|
||||
self.report_concrete_failure(region_maps, origin, sub, sup).emit();
|
||||
}
|
||||
|
||||
GenericBoundFailure(kind, param_ty, sub) => {
|
||||
self.report_generic_bound_failure(kind, param_ty, sub);
|
||||
self.report_generic_bound_failure(region_maps, kind, param_ty, sub);
|
||||
}
|
||||
|
||||
SubSupConflict(var_origin, sub_origin, sub_r, sup_origin, sup_r) => {
|
||||
self.report_sub_sup_conflict(var_origin,
|
||||
self.report_sub_sup_conflict(region_maps,
|
||||
var_origin,
|
||||
sub_origin,
|
||||
sub_r,
|
||||
sup_origin,
|
||||
@ -773,6 +769,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
|
||||
fn report_generic_bound_failure(&self,
|
||||
region_maps: &RegionMaps,
|
||||
origin: SubregionOrigin<'tcx>,
|
||||
bound_kind: GenericKind<'tcx>,
|
||||
sub: Region<'tcx>)
|
||||
@ -840,6 +837,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
err.help(&format!("consider adding an explicit lifetime bound for `{}`",
|
||||
bound_kind));
|
||||
self.tcx.note_and_explain_region(
|
||||
region_maps,
|
||||
&mut err,
|
||||
&format!("{} must be valid for ", labeled_user_string),
|
||||
sub,
|
||||
@ -853,6 +851,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
|
||||
fn report_sub_sup_conflict(&self,
|
||||
region_maps: &RegionMaps,
|
||||
var_origin: RegionVariableOrigin,
|
||||
sub_origin: SubregionOrigin<'tcx>,
|
||||
sub_region: Region<'tcx>,
|
||||
@ -860,14 +859,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
sup_region: Region<'tcx>) {
|
||||
let mut err = self.report_inference_failure(var_origin);
|
||||
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"first, the lifetime cannot outlive ",
|
||||
sup_region,
|
||||
"...");
|
||||
|
||||
self.note_region_origin(&mut err, &sup_origin);
|
||||
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"but, the lifetime must be valid for ",
|
||||
sub_region,
|
||||
"...");
|
||||
|
@ -9,6 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
use infer::{self, InferCtxt, SubregionOrigin};
|
||||
use middle::region::RegionMaps;
|
||||
use ty::{self, Region};
|
||||
use ty::error::TypeError;
|
||||
use errors::DiagnosticBuilder;
|
||||
@ -144,6 +145,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
|
||||
pub(super) fn report_concrete_failure(&self,
|
||||
region_maps: &RegionMaps,
|
||||
origin: SubregionOrigin<'tcx>,
|
||||
sub: Region<'tcx>,
|
||||
sup: Region<'tcx>)
|
||||
@ -151,7 +153,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
match origin {
|
||||
infer::Subtype(trace) => {
|
||||
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
|
||||
self.report_and_explain_type_error(trace, &terr)
|
||||
let mut err = self.report_and_explain_type_error(trace, &terr);
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err, "", sup, "...");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"...does not necessarily outlive ", sub, "");
|
||||
err
|
||||
}
|
||||
infer::Reborrow(span) => {
|
||||
let mut err = struct_span_err!(self.tcx.sess,
|
||||
@ -159,11 +165,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
E0312,
|
||||
"lifetime of reference outlives lifetime of \
|
||||
borrowed content...");
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"...the reference is valid for ",
|
||||
sub,
|
||||
"...");
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"...but the borrowed content is only valid for ",
|
||||
sup,
|
||||
"");
|
||||
@ -177,27 +183,27 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
of captured variable `{}`...",
|
||||
self.tcx
|
||||
.local_var_name_str_def_index(upvar_id.var_id));
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"...the borrowed pointer is valid for ",
|
||||
sub,
|
||||
"...");
|
||||
self.tcx
|
||||
.note_and_explain_region(
|
||||
&mut err,
|
||||
&format!("...but `{}` is only valid for ",
|
||||
self.tcx.local_var_name_str_def_index(upvar_id.var_id)),
|
||||
sup,
|
||||
"");
|
||||
self.tcx.note_and_explain_region(
|
||||
region_maps,
|
||||
&mut err,
|
||||
&format!("...but `{}` is only valid for ",
|
||||
self.tcx.local_var_name_str_def_index(upvar_id.var_id)),
|
||||
sup,
|
||||
"");
|
||||
err
|
||||
}
|
||||
infer::InfStackClosure(span) => {
|
||||
let mut err =
|
||||
struct_span_err!(self.tcx.sess, span, E0314, "closure outlives stack frame");
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"...the closure must be valid for ",
|
||||
sub,
|
||||
"...");
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"...but the closure's stack frame is only valid \
|
||||
for ",
|
||||
sup,
|
||||
@ -209,8 +215,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
span,
|
||||
E0315,
|
||||
"cannot invoke closure outside of its lifetime");
|
||||
self.tcx
|
||||
.note_and_explain_region(&mut err, "the closure is only valid for ", sup, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"the closure is only valid for ", sup, "");
|
||||
err
|
||||
}
|
||||
infer::DerefPointer(span) => {
|
||||
@ -218,8 +224,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
span,
|
||||
E0473,
|
||||
"dereference of reference outside its lifetime");
|
||||
self.tcx
|
||||
.note_and_explain_region(&mut err, "the reference is only valid for ", sup, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"the reference is only valid for ", sup, "");
|
||||
err
|
||||
}
|
||||
infer::FreeVariable(span, id) => {
|
||||
@ -229,9 +235,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
"captured variable `{}` does not outlive the \
|
||||
enclosing closure",
|
||||
self.tcx.local_var_name_str(id));
|
||||
self.tcx
|
||||
.note_and_explain_region(&mut err, "captured variable is valid for ", sup, "");
|
||||
self.tcx.note_and_explain_region(&mut err, "closure is valid for ", sub, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"captured variable is valid for ", sup, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"closure is valid for ", sub, "");
|
||||
err
|
||||
}
|
||||
infer::IndexSlice(span) => {
|
||||
@ -239,7 +246,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
span,
|
||||
E0475,
|
||||
"index of slice outside its lifetime");
|
||||
self.tcx.note_and_explain_region(&mut err, "the slice is only valid for ", sup, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"the slice is only valid for ", sup, "");
|
||||
err
|
||||
}
|
||||
infer::RelateObjectBound(span) => {
|
||||
@ -248,8 +256,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
E0476,
|
||||
"lifetime of the source pointer does not outlive \
|
||||
lifetime bound of the object type");
|
||||
self.tcx.note_and_explain_region(&mut err, "object type is valid for ", sub, "");
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"object type is valid for ", sub, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"source pointer is only valid for ",
|
||||
sup,
|
||||
"");
|
||||
@ -264,10 +273,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
self.ty_to_string(ty));
|
||||
match *sub {
|
||||
ty::ReStatic => {
|
||||
self.tcx.note_and_explain_region(&mut err, "type must satisfy ", sub, "")
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"type must satisfy ", sub, "")
|
||||
}
|
||||
_ => {
|
||||
self.tcx.note_and_explain_region(&mut err, "type must outlive ", sub, "")
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"type must outlive ", sub, "")
|
||||
}
|
||||
}
|
||||
err
|
||||
@ -275,11 +286,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
infer::RelateRegionParamBound(span) => {
|
||||
let mut err =
|
||||
struct_span_err!(self.tcx.sess, span, E0478, "lifetime bound not satisfied");
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"lifetime parameter instantiated with ",
|
||||
sup,
|
||||
"");
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"but lifetime parameter must outlive ",
|
||||
sub,
|
||||
"");
|
||||
@ -292,7 +303,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
"the type `{}` (provided as the value of a type \
|
||||
parameter) is not valid at this point",
|
||||
self.ty_to_string(ty));
|
||||
self.tcx.note_and_explain_region(&mut err, "type must outlive ", sub, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"type must outlive ", sub, "");
|
||||
err
|
||||
}
|
||||
infer::CallRcvr(span) => {
|
||||
@ -301,8 +313,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
E0480,
|
||||
"lifetime of method receiver does not outlive the \
|
||||
method call");
|
||||
self.tcx
|
||||
.note_and_explain_region(&mut err, "the receiver is only valid for ", sup, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"the receiver is only valid for ", sup, "");
|
||||
err
|
||||
}
|
||||
infer::CallArg(span) => {
|
||||
@ -311,7 +323,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
E0481,
|
||||
"lifetime of function argument does not outlive \
|
||||
the function call");
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"the function argument is only valid for ",
|
||||
sup,
|
||||
"");
|
||||
@ -323,7 +335,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
E0482,
|
||||
"lifetime of return value does not outlive the \
|
||||
function call");
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"the return value is only valid for ",
|
||||
sup,
|
||||
"");
|
||||
@ -335,8 +347,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
E0483,
|
||||
"lifetime of operand does not outlive the \
|
||||
operation");
|
||||
self.tcx
|
||||
.note_and_explain_region(&mut err, "the operand is only valid for ", sup, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"the operand is only valid for ", sup, "");
|
||||
err
|
||||
}
|
||||
infer::AddrOf(span) => {
|
||||
@ -344,8 +356,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
span,
|
||||
E0484,
|
||||
"reference is not valid at the time of borrow");
|
||||
self.tcx
|
||||
.note_and_explain_region(&mut err, "the borrow is only valid for ", sup, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"the borrow is only valid for ", sup, "");
|
||||
err
|
||||
}
|
||||
infer::AutoBorrow(span) => {
|
||||
@ -354,7 +366,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
E0485,
|
||||
"automatically reference is not valid at the time \
|
||||
of borrow");
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"the automatic borrow is only valid for ",
|
||||
sup,
|
||||
"");
|
||||
@ -367,7 +379,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
"type of expression contains references that are \
|
||||
not valid during the expression: `{}`",
|
||||
self.ty_to_string(t));
|
||||
self.tcx.note_and_explain_region(&mut err, "type is only valid for ", sup, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"type is only valid for ", sup, "");
|
||||
err
|
||||
}
|
||||
infer::SafeDestructor(span) => {
|
||||
@ -377,8 +390,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
"unsafe use of destructor: destructor might be \
|
||||
called while references are dead");
|
||||
// FIXME (22171): terms "super/subregion" are suboptimal
|
||||
self.tcx.note_and_explain_region(&mut err, "superregion: ", sup, "");
|
||||
self.tcx.note_and_explain_region(&mut err, "subregion: ", sub, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err, "superregion: ", sup, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err, "subregion: ", sub, "");
|
||||
err
|
||||
}
|
||||
infer::BindingTypeIsNotValidAtDecl(span) => {
|
||||
@ -387,8 +400,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
E0488,
|
||||
"lifetime of variable does not enclose its \
|
||||
declaration");
|
||||
self.tcx
|
||||
.note_and_explain_region(&mut err, "the variable is only valid for ", sup, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"the variable is only valid for ", sup, "");
|
||||
err
|
||||
}
|
||||
infer::ParameterInScope(_, span) => {
|
||||
@ -396,8 +409,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
span,
|
||||
E0489,
|
||||
"type/lifetime parameter not in scope here");
|
||||
self.tcx
|
||||
.note_and_explain_region(&mut err, "the parameter is only valid for ", sub, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"the parameter is only valid for ", sub, "");
|
||||
err
|
||||
}
|
||||
infer::DataBorrowed(ty, span) => {
|
||||
@ -406,8 +419,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
E0490,
|
||||
"a value of type `{}` is borrowed for too long",
|
||||
self.ty_to_string(ty));
|
||||
self.tcx.note_and_explain_region(&mut err, "the type is valid for ", sub, "");
|
||||
self.tcx.note_and_explain_region(&mut err, "but the borrow lasts for ", sup, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"the type is valid for ", sub, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"but the borrow lasts for ", sup, "");
|
||||
err
|
||||
}
|
||||
infer::ReferenceOutlivesReferent(ty, span) => {
|
||||
@ -417,8 +432,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
"in type `{}`, reference has a longer lifetime \
|
||||
than the data it references",
|
||||
self.ty_to_string(ty));
|
||||
self.tcx.note_and_explain_region(&mut err, "the pointer is valid for ", sub, "");
|
||||
self.tcx.note_and_explain_region(&mut err,
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"the pointer is valid for ", sub, "");
|
||||
self.tcx.note_and_explain_region(region_maps, &mut err,
|
||||
"but the referenced data is only valid for ",
|
||||
sup,
|
||||
"");
|
||||
|
@ -1084,7 +1084,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
// this infcx was in use. This is totally hokey but
|
||||
// otherwise we have a hard time separating legit region
|
||||
// errors from silly ones.
|
||||
self.report_region_errors(&errors); // see error_reporting module
|
||||
self.report_region_errors(region_map, &errors); // see error_reporting module
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
//! Most of the documentation on regions can be found in
|
||||
//! `middle/infer/region_inference/README.md`
|
||||
|
||||
use hir::map as hir_map;
|
||||
use util::nodemap::{FxHashMap, NodeMap, NodeSet};
|
||||
use ty;
|
||||
|
||||
@ -161,34 +160,31 @@ impl CodeExtent {
|
||||
/// Returns the span of this CodeExtent. Note that in general the
|
||||
/// returned span may not correspond to the span of any node id in
|
||||
/// the AST.
|
||||
pub fn span(&self, hir_map: &hir_map::Map) -> Option<Span> {
|
||||
match hir_map.find(self.node_id()) {
|
||||
Some(hir_map::NodeBlock(ref blk)) => {
|
||||
match *self {
|
||||
CodeExtent::CallSiteScope(_) |
|
||||
CodeExtent::ParameterScope(_) |
|
||||
CodeExtent::Misc(_) |
|
||||
CodeExtent::DestructionScope(_) => Some(blk.span),
|
||||
pub fn span(&self, tcx: TyCtxt, region_maps: &RegionMaps) -> Span {
|
||||
let root_node = region_maps.root_body.unwrap().node_id;
|
||||
assert_eq!(DefId::local(tcx.hir.node_to_hir_id(self.node_id()).owner),
|
||||
DefId::local(tcx.hir.node_to_hir_id(root_node).owner));
|
||||
let span = tcx.hir.span(self.node_id());
|
||||
if let CodeExtent::Remainder(r) = *self {
|
||||
if let hir::map::NodeBlock(ref blk) = tcx.hir.get(r.block) {
|
||||
// Want span for extent starting after the
|
||||
// indexed statement and ending at end of
|
||||
// `blk`; reuse span of `blk` and shift `lo`
|
||||
// forward to end of indexed statement.
|
||||
//
|
||||
// (This is the special case aluded to in the
|
||||
// doc-comment for this method)
|
||||
|
||||
CodeExtent::Remainder(r) => {
|
||||
assert_eq!(r.block, blk.id);
|
||||
// Want span for extent starting after the
|
||||
// indexed statement and ending at end of
|
||||
// `blk`; reuse span of `blk` and shift `lo`
|
||||
// forward to end of indexed statement.
|
||||
//
|
||||
// (This is the special case aluded to in the
|
||||
// doc-comment for this method)
|
||||
let stmt_span = blk.stmts[r.first_statement_index as usize].span;
|
||||
Some(Span::new(stmt_span.hi(), blk.span.hi(), stmt_span.ctxt()))
|
||||
}
|
||||
let stmt_span = blk.stmts[r.first_statement_index as usize].span;
|
||||
|
||||
// To avoid issues with macro-generated spans, the span
|
||||
// of the statement must be nested in that of the block.
|
||||
if span.lo() <= stmt_span.lo() && stmt_span.lo() <= span.hi() {
|
||||
return Span::new(stmt_span.lo(), span.hi(), span.ctxt());
|
||||
}
|
||||
}
|
||||
Some(hir_map::NodeExpr(ref expr)) => Some(expr.span),
|
||||
Some(hir_map::NodeStmt(ref stmt)) => Some(stmt.span),
|
||||
Some(hir_map::NodeItem(ref item)) => Some(item.span),
|
||||
Some(_) | None => None,
|
||||
}
|
||||
span
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,11 +36,11 @@ pub enum TypeError<'tcx> {
|
||||
TupleSize(ExpectedFound<usize>),
|
||||
FixedArraySize(ExpectedFound<usize>),
|
||||
ArgCount,
|
||||
|
||||
RegionsDoesNotOutlive(Region<'tcx>, Region<'tcx>),
|
||||
RegionsNotSame(Region<'tcx>, Region<'tcx>),
|
||||
RegionsNoOverlap(Region<'tcx>, Region<'tcx>),
|
||||
RegionsInsufficientlyPolymorphic(BoundRegion, Region<'tcx>),
|
||||
RegionsOverlyPolymorphic(BoundRegion, Region<'tcx>),
|
||||
|
||||
Sorts(ExpectedFound<Ty<'tcx>>),
|
||||
IntMismatch(ExpectedFound<ty::IntVarValue>),
|
||||
FloatMismatch(ExpectedFound<ast::FloatTy>),
|
||||
@ -110,12 +110,6 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
|
||||
RegionsDoesNotOutlive(..) => {
|
||||
write!(f, "lifetime mismatch")
|
||||
}
|
||||
RegionsNotSame(..) => {
|
||||
write!(f, "lifetimes are not the same")
|
||||
}
|
||||
RegionsNoOverlap(..) => {
|
||||
write!(f, "lifetimes do not intersect")
|
||||
}
|
||||
RegionsInsufficientlyPolymorphic(br, _) => {
|
||||
write!(f,
|
||||
"expected bound lifetime parameter{}{}, found concrete lifetime",
|
||||
@ -243,33 +237,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
use self::TypeError::*;
|
||||
|
||||
match err.clone() {
|
||||
RegionsDoesNotOutlive(subregion, superregion) => {
|
||||
self.note_and_explain_region(db, "", subregion, "...");
|
||||
self.note_and_explain_region(db, "...does not necessarily outlive ",
|
||||
superregion, "");
|
||||
}
|
||||
RegionsNotSame(region1, region2) => {
|
||||
self.note_and_explain_region(db, "", region1, "...");
|
||||
self.note_and_explain_region(db, "...is not the same lifetime as ",
|
||||
region2, "");
|
||||
}
|
||||
RegionsNoOverlap(region1, region2) => {
|
||||
self.note_and_explain_region(db, "", region1, "...");
|
||||
self.note_and_explain_region(db, "...does not overlap ",
|
||||
region2, "");
|
||||
}
|
||||
RegionsInsufficientlyPolymorphic(_, conc_region) => {
|
||||
self.note_and_explain_region(db, "concrete lifetime that was found is ",
|
||||
conc_region, "");
|
||||
}
|
||||
RegionsOverlyPolymorphic(_, &ty::ReVar(_)) => {
|
||||
// don't bother to print out the message below for
|
||||
// inference variables, it's not very illuminating.
|
||||
}
|
||||
RegionsOverlyPolymorphic(_, conc_region) => {
|
||||
self.note_and_explain_region(db, "expected concrete lifetime is ",
|
||||
conc_region, "");
|
||||
}
|
||||
Sorts(values) => {
|
||||
let expected_str = values.expected.sort_string(self);
|
||||
let found_str = values.found.sort_string(self);
|
||||
|
@ -371,12 +371,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
|
||||
RegionsDoesNotOutlive(a, b) => {
|
||||
return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b))
|
||||
}
|
||||
RegionsNotSame(a, b) => {
|
||||
return tcx.lift(&(a, b)).map(|(a, b)| RegionsNotSame(a, b))
|
||||
}
|
||||
RegionsNoOverlap(a, b) => {
|
||||
return tcx.lift(&(a, b)).map(|(a, b)| RegionsNoOverlap(a, b))
|
||||
}
|
||||
RegionsInsufficientlyPolymorphic(a, b) => {
|
||||
return tcx.lift(&b).map(|b| RegionsInsufficientlyPolymorphic(a, b))
|
||||
}
|
||||
@ -1057,12 +1051,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::error::TypeError<'tcx> {
|
||||
RegionsDoesNotOutlive(a, b) => {
|
||||
RegionsDoesNotOutlive(a.fold_with(folder), b.fold_with(folder))
|
||||
},
|
||||
RegionsNotSame(a, b) => {
|
||||
RegionsNotSame(a.fold_with(folder), b.fold_with(folder))
|
||||
},
|
||||
RegionsNoOverlap(a, b) => {
|
||||
RegionsNoOverlap(a.fold_with(folder), b.fold_with(folder))
|
||||
},
|
||||
RegionsInsufficientlyPolymorphic(a, b) => {
|
||||
RegionsInsufficientlyPolymorphic(a, b.fold_with(folder))
|
||||
},
|
||||
@ -1088,9 +1076,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::error::TypeError<'tcx> {
|
||||
match *self {
|
||||
UnsafetyMismatch(x) => x.visit_with(visitor),
|
||||
AbiMismatch(x) => x.visit_with(visitor),
|
||||
RegionsDoesNotOutlive(a, b) |
|
||||
RegionsNotSame(a, b) |
|
||||
RegionsNoOverlap(a, b) => {
|
||||
RegionsDoesNotOutlive(a, b) => {
|
||||
a.visit_with(visitor) || b.visit_with(visitor)
|
||||
},
|
||||
RegionsInsufficientlyPolymorphic(_, b) |
|
||||
|
@ -943,6 +943,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||
}
|
||||
None => {
|
||||
self.tcx.note_and_explain_region(
|
||||
&self.region_maps,
|
||||
&mut db,
|
||||
"borrowed value must be valid for ",
|
||||
sub_scope,
|
||||
@ -955,6 +956,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||
}
|
||||
None => {
|
||||
self.tcx.note_and_explain_region(
|
||||
&self.region_maps,
|
||||
&mut db,
|
||||
"...but borrowed value is only valid for ",
|
||||
super_scope,
|
||||
@ -984,12 +986,14 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||
None => self.cmt_to_string(&err.cmt),
|
||||
};
|
||||
self.tcx.note_and_explain_region(
|
||||
&self.region_maps,
|
||||
&mut db,
|
||||
&format!("{} would have to be valid for ",
|
||||
descr),
|
||||
loan_scope,
|
||||
"...");
|
||||
self.tcx.note_and_explain_region(
|
||||
&self.region_maps,
|
||||
&mut db,
|
||||
&format!("...but {} is only valid for ", descr),
|
||||
ptr_scope,
|
||||
@ -1245,14 +1249,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||
fn region_end_span(&self, region: ty::Region<'tcx>) -> Option<Span> {
|
||||
match *region {
|
||||
ty::ReScope(scope) => {
|
||||
match scope.span(&self.tcx.hir) {
|
||||
Some(s) => {
|
||||
Some(s.end_point())
|
||||
}
|
||||
None => {
|
||||
None
|
||||
}
|
||||
}
|
||||
Some(scope.span(self.tcx, &self.region_maps).end_point())
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||
let outer_visibility_scope = this.visibility_scope;
|
||||
let source_info = this.source_info(span);
|
||||
for stmt in stmts {
|
||||
let Stmt { span, kind, opt_destruction_extent } = this.hir.mirror(stmt);
|
||||
let Stmt { kind, opt_destruction_extent } = this.hir.mirror(stmt);
|
||||
match kind {
|
||||
StmtKind::Expr { scope, expr } => {
|
||||
unpack!(block = this.in_opt_scope(
|
||||
@ -83,15 +83,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||
}));
|
||||
}
|
||||
StmtKind::Let { remainder_scope, init_scope, pattern, initializer } => {
|
||||
let tcx = this.hir.tcx();
|
||||
|
||||
// Enter the remainder scope, i.e. the bindings' destruction scope.
|
||||
this.push_scope((remainder_scope, source_info));
|
||||
let_extent_stack.push(remainder_scope);
|
||||
|
||||
// Declare the bindings, which may create a visibility scope.
|
||||
let remainder_span = remainder_scope.span(&tcx.hir);
|
||||
let remainder_span = remainder_span.unwrap_or(span);
|
||||
let remainder_span = remainder_scope.span(this.hir.tcx(),
|
||||
&this.hir.region_maps);
|
||||
let scope = this.declare_bindings(None, remainder_span, &pattern);
|
||||
|
||||
// Evaluate the initializer, if present.
|
||||
|
@ -633,8 +633,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||
if let DropKind::Value { .. } = drop_kind {
|
||||
scope.needs_cleanup = true;
|
||||
}
|
||||
let tcx = self.hir.tcx();
|
||||
let extent_span = extent.span(&tcx.hir).unwrap();
|
||||
let extent_span = extent.span(self.hir.tcx(), &self.hir.region_maps);
|
||||
// Attribute scope exit drops to scope's closing brace
|
||||
let scope_end = extent_span.with_lo(extent_span.hi());
|
||||
scope.drops.push(DropData {
|
||||
|
@ -45,7 +45,6 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
||||
hir::StmtExpr(ref expr, id) |
|
||||
hir::StmtSemi(ref expr, id) => {
|
||||
result.push(StmtRef::Mirror(Box::new(Stmt {
|
||||
span: stmt.span,
|
||||
kind: StmtKind::Expr {
|
||||
scope: CodeExtent::Misc(id),
|
||||
expr: expr.to_ref(),
|
||||
@ -69,7 +68,6 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
||||
cx.tables(),
|
||||
&local.pat);
|
||||
result.push(StmtRef::Mirror(Box::new(Stmt {
|
||||
span: stmt.span,
|
||||
kind: StmtKind::Let {
|
||||
remainder_scope: remainder_extent,
|
||||
init_scope: CodeExtent::Misc(id),
|
||||
|
@ -46,7 +46,6 @@ pub enum StmtRef<'tcx> {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Stmt<'tcx> {
|
||||
pub span: Span,
|
||||
pub kind: StmtKind<'tcx>,
|
||||
pub opt_destruction_extent: Option<CodeExtent>,
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
//! is calculated in `rustc_mir::transform::generator` and may be a subset of the
|
||||
//! types computed here.
|
||||
|
||||
use log;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
use rustc::hir::{self, Body, Pat, PatKind, Expr};
|
||||
@ -36,18 +35,15 @@ impl<'a, 'gcx, 'tcx> InteriorVisitor<'a, 'gcx, 'tcx> {
|
||||
fn record(&mut self, ty: Ty<'tcx>, scope: Option<CodeExtent>, expr: Option<&'tcx Expr>) {
|
||||
use syntax_pos::DUMMY_SP;
|
||||
|
||||
let live_across_yield = scope.map(|s| {
|
||||
self.fcx.tcx.yield_in_extent(s, &mut self.cache).is_some()
|
||||
}).unwrap_or(true);
|
||||
let live_across_yield = scope.map_or(Some(DUMMY_SP), |s| {
|
||||
self.fcx.tcx.yield_in_extent(s, &mut self.cache)
|
||||
});
|
||||
|
||||
if live_across_yield {
|
||||
if let Some(span) = live_across_yield {
|
||||
let ty = self.fcx.resolve_type_vars_if_possible(&ty);
|
||||
|
||||
if log_enabled!(log::LogLevel::Debug) {
|
||||
let span = scope.map(|s| s.span(&self.fcx.tcx.hir).unwrap_or(DUMMY_SP));
|
||||
debug!("type in expr = {:?}, scope = {:?}, type = {:?}, span = {:?}",
|
||||
expr, scope, ty, span);
|
||||
}
|
||||
debug!("type in expr = {:?}, scope = {:?}, type = {:?}, span = {:?}",
|
||||
expr, scope, ty, span);
|
||||
|
||||
// Map the type to the number of types added before it
|
||||
let entries = self.types.len();
|
||||
|
@ -4,7 +4,6 @@ error[E0271]: type mismatch resolving `for<'r> <[closure@$DIR/closure-mismatch.r
|
||||
18 | baz(|_| ());
|
||||
| ^^^ expected bound lifetime parameter, found concrete lifetime
|
||||
|
|
||||
= note: concrete lifetime that was found is lifetime '_#0r
|
||||
= note: required because of the requirements on the impl of `Foo` for `[closure@$DIR/closure-mismatch.rs:18:9: 18:15]`
|
||||
= note: required by `baz`
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user