Skip to content

Commit ea6aca7

Browse files
committed
rustc: take TyCtxt and RegionMaps in CodeMap::span.
1 parent 28ddd7a commit ea6aca7

File tree

13 files changed

+120
-170
lines changed

13 files changed

+120
-170
lines changed

Diff for: src/librustc/infer/error_reporting/mod.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use std::fmt;
6464
use hir;
6565
use hir::map as hir_map;
6666
use hir::def_id::DefId;
67-
use middle::region;
67+
use middle::region::{self, RegionMaps};
6868
use traits::{ObligationCause, ObligationCauseCode};
6969
use ty::{self, Region, TyCtxt, TypeFoldable};
7070
use ty::error::TypeError;
@@ -83,6 +83,7 @@ mod anon_anon_conflict;
8383

8484
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
8585
pub fn note_and_explain_region(self,
86+
region_maps: &RegionMaps,
8687
err: &mut DiagnosticBuilder,
8788
prefix: &str,
8889
region: ty::Region<'tcx>,
@@ -130,13 +131,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
130131
format!("{}unknown scope: {:?}{}. Please report a bug.",
131132
prefix, scope, suffix)
132133
};
133-
let span = match scope.span(&self.hir) {
134-
Some(s) => s,
135-
None => {
136-
err.note(&unknown_scope());
137-
return;
138-
}
139-
};
134+
let span = scope.span(self, region_maps);
140135
let tag = match self.hir.find(scope.node_id()) {
141136
Some(hir_map::NodeBlock(_)) => "block",
142137
Some(hir_map::NodeExpr(expr)) => match expr.node {
@@ -260,8 +255,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
260255
}
261256

262257
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
263-
264-
pub fn report_region_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>) {
258+
pub fn report_region_errors(&self,
259+
region_maps: &RegionMaps,
260+
errors: &Vec<RegionResolutionError<'tcx>>) {
265261
debug!("report_region_errors(): {} errors to start", errors.len());
266262

267263
// try to pre-process the errors, which will group some of them
@@ -285,16 +281,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
285281
// the error. If all of these fails, we fall back to a rather
286282
// general bit of code that displays the error information
287283
ConcreteFailure(origin, sub, sup) => {
288-
289-
self.report_concrete_failure(origin, sub, sup).emit();
284+
self.report_concrete_failure(region_maps, origin, sub, sup).emit();
290285
}
291286

292287
GenericBoundFailure(kind, param_ty, sub) => {
293-
self.report_generic_bound_failure(kind, param_ty, sub);
288+
self.report_generic_bound_failure(region_maps, kind, param_ty, sub);
294289
}
295290

296291
SubSupConflict(var_origin, sub_origin, sub_r, sup_origin, sup_r) => {
297-
self.report_sub_sup_conflict(var_origin,
292+
self.report_sub_sup_conflict(region_maps,
293+
var_origin,
298294
sub_origin,
299295
sub_r,
300296
sup_origin,
@@ -773,6 +769,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
773769
}
774770

775771
fn report_generic_bound_failure(&self,
772+
region_maps: &RegionMaps,
776773
origin: SubregionOrigin<'tcx>,
777774
bound_kind: GenericKind<'tcx>,
778775
sub: Region<'tcx>)
@@ -840,6 +837,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
840837
err.help(&format!("consider adding an explicit lifetime bound for `{}`",
841838
bound_kind));
842839
self.tcx.note_and_explain_region(
840+
region_maps,
843841
&mut err,
844842
&format!("{} must be valid for ", labeled_user_string),
845843
sub,
@@ -853,21 +851,22 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
853851
}
854852

855853
fn report_sub_sup_conflict(&self,
854+
region_maps: &RegionMaps,
856855
var_origin: RegionVariableOrigin,
857856
sub_origin: SubregionOrigin<'tcx>,
858857
sub_region: Region<'tcx>,
859858
sup_origin: SubregionOrigin<'tcx>,
860859
sup_region: Region<'tcx>) {
861860
let mut err = self.report_inference_failure(var_origin);
862861

863-
self.tcx.note_and_explain_region(&mut err,
862+
self.tcx.note_and_explain_region(region_maps, &mut err,
864863
"first, the lifetime cannot outlive ",
865864
sup_region,
866865
"...");
867866

868867
self.note_region_origin(&mut err, &sup_origin);
869868

870-
self.tcx.note_and_explain_region(&mut err,
869+
self.tcx.note_and_explain_region(region_maps, &mut err,
871870
"but, the lifetime must be valid for ",
872871
sub_region,
873872
"...");

0 commit comments

Comments
 (0)