Skip to content

Commit 908c1f2

Browse files
committed
use DUMMY_NODE_ID as the body_id during NLL type-checking
The choice is arbitrary since there is only one involved.
1 parent 6a5a487 commit 908c1f2

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

src/librustc_mir/borrow_check/nll/type_check/input_output.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc::hir::def_id::DefId;
2323
use rustc::infer::InferOk;
2424
use rustc::mir::visit::TyContext;
2525
use rustc::mir::*;
26-
use rustc::traits::PredicateObligations;
26+
use rustc::traits::{ObligationCause, PredicateObligations};
2727
use rustc::ty::subst::Subst;
2828
use rustc::ty::Ty;
2929

@@ -84,9 +84,10 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
8484
|cx| {
8585
let mut obligations = ObligationAccumulator::default();
8686

87+
let dummy_body_id = ObligationCause::dummy().body_id;
8788
let (output_ty, anon_type_map) = obligations.add(infcx.instantiate_anon_types(
8889
mir_def_id,
89-
cx.body_id,
90+
dummy_body_id,
9091
cx.param_env,
9192
&output_ty,
9293
));
@@ -105,7 +106,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
105106
);
106107
obligations.add(
107108
infcx
108-
.at(&cx.misc(cx.last_span), cx.param_env)
109+
.at(&ObligationCause::dummy(), cx.param_env)
109110
.eq(output_ty, mir_output_ty)?,
110111
);
111112

@@ -124,7 +125,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
124125
debug!("equate_inputs_and_outputs: anon_defn_ty={:?}", anon_defn_ty);
125126
obligations.add(
126127
infcx
127-
.at(&cx.misc(cx.last_span), cx.param_env)
128+
.at(&ObligationCause::dummy(), cx.param_env)
128129
.eq(anon_decl.concrete_ty, anon_defn_ty)?,
129130
);
130131
}

src/librustc_mir/borrow_check/nll/type_check/liveness.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use dataflow::{FlowAtLocation, FlowsAtLocation};
1616
use rustc::infer::region_constraints::RegionConstraintData;
1717
use rustc::mir::Local;
1818
use rustc::mir::{BasicBlock, Location, Mir};
19+
use rustc::traits::ObligationCause;
1920
use rustc::ty::subst::Kind;
2021
use rustc::ty::{Ty, TypeFoldable};
2122
use rustc_data_structures::fx::FxHashMap;
2223
use std::rc::Rc;
23-
use syntax::codemap::DUMMY_SP;
2424
use util::liveness::LivenessResults;
2525

2626
use super::TypeChecker;
@@ -223,11 +223,9 @@ impl<'gen, 'typeck, 'flow, 'gcx, 'tcx> TypeLivenessGenerator<'gen, 'typeck, 'flo
223223
cx.fully_perform_op_and_get_region_constraint_data(
224224
|| format!("compute_drop_data(dropped_ty={:?})", dropped_ty),
225225
|cx| {
226-
// crappy span, but I don't think it really matters
227-
let span = DUMMY_SP;
228226
Ok(cx
229227
.infcx
230-
.at(&cx.misc(span), cx.param_env)
228+
.at(&ObligationCause::dummy(), cx.param_env)
231229
.dropck_outlives(dropped_ty))
232230
},
233231
).unwrap();

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+29-24
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ use rustc::mir::tcx::PlaceTy;
2727
use rustc::mir::visit::{PlaceContext, Visitor};
2828
use rustc::mir::*;
2929
use rustc::traits::query::NoSolution;
30-
use rustc::traits::{self, Normalized, TraitEngine};
30+
use rustc::traits::{self, ObligationCause, Normalized, TraitEngine};
3131
use rustc::ty::error::TypeError;
3232
use rustc::ty::fold::TypeFoldable;
3333
use rustc::ty::{self, ToPolyTraitRef, Ty, TyCtxt, TypeVariants};
3434
use std::fmt;
3535
use std::rc::Rc;
36-
use syntax::ast;
3736
use syntax_pos::{Span, DUMMY_SP};
3837
use transform::{MirPass, MirSource};
3938
use util::liveness::LivenessResults;
@@ -48,7 +47,7 @@ macro_rules! span_mirbug {
4847
$context.last_span,
4948
&format!(
5049
"broken MIR in {:?} ({:?}): {}",
51-
$context.body_id,
50+
$context.mir_def_id,
5251
$elem,
5352
format_args!($($message)*),
5453
),
@@ -110,11 +109,10 @@ pub(crate) fn type_check<'gcx, 'tcx>(
110109
flow_inits: &mut FlowAtLocation<MaybeInitializedPlaces<'_, 'gcx, 'tcx>>,
111110
move_data: &MoveData<'tcx>,
112111
) -> MirTypeckRegionConstraints<'tcx> {
113-
let body_id = infcx.tcx.hir.as_local_node_id(mir_def_id).unwrap();
114112
let implicit_region_bound = infcx.tcx.mk_region(ty::ReVar(universal_regions.fr_fn_body));
115113
type_check_internal(
116114
infcx,
117-
body_id,
115+
mir_def_id,
118116
param_env,
119117
mir,
120118
&universal_regions.region_bound_pairs,
@@ -134,7 +132,7 @@ pub(crate) fn type_check<'gcx, 'tcx>(
134132

135133
fn type_check_internal<'gcx, 'tcx>(
136134
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
137-
body_id: ast::NodeId,
135+
mir_def_id: DefId,
138136
param_env: ty::ParamEnv<'gcx>,
139137
mir: &Mir<'tcx>,
140138
region_bound_pairs: &[(ty::Region<'tcx>, GenericKind<'tcx>)],
@@ -144,7 +142,7 @@ fn type_check_internal<'gcx, 'tcx>(
144142
) -> MirTypeckRegionConstraints<'tcx> {
145143
let mut checker = TypeChecker::new(
146144
infcx,
147-
body_id,
145+
mir_def_id,
148146
param_env,
149147
region_bound_pairs,
150148
implicit_region_bound,
@@ -187,7 +185,7 @@ struct TypeVerifier<'a, 'b: 'a, 'gcx: 'b + 'tcx, 'tcx: 'b> {
187185
cx: &'a mut TypeChecker<'b, 'gcx, 'tcx>,
188186
mir: &'a Mir<'tcx>,
189187
last_span: Span,
190-
body_id: ast::NodeId,
188+
mir_def_id: DefId,
191189
errors_reported: bool,
192190
}
193191

@@ -235,7 +233,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
235233
fn new(cx: &'a mut TypeChecker<'b, 'gcx, 'tcx>, mir: &'a Mir<'tcx>) -> Self {
236234
TypeVerifier {
237235
mir,
238-
body_id: cx.body_id,
236+
mir_def_id: cx.mir_def_id,
239237
cx,
240238
last_span: mir.span,
241239
errors_reported: false,
@@ -595,7 +593,7 @@ struct TypeChecker<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
595593
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
596594
param_env: ty::ParamEnv<'gcx>,
597595
last_span: Span,
598-
body_id: ast::NodeId,
596+
mir_def_id: DefId,
599597
region_bound_pairs: &'a [(ty::Region<'tcx>, GenericKind<'tcx>)],
600598
implicit_region_bound: Option<ty::Region<'tcx>>,
601599
reported_errors: FxHashSet<(Ty<'tcx>, Span)>,
@@ -699,7 +697,7 @@ impl Locations {
699697
impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
700698
fn new(
701699
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
702-
body_id: ast::NodeId,
700+
mir_def_id: DefId,
703701
param_env: ty::ParamEnv<'gcx>,
704702
region_bound_pairs: &'a [(ty::Region<'tcx>, GenericKind<'tcx>)],
705703
implicit_region_bound: Option<ty::Region<'tcx>>,
@@ -709,7 +707,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
709707
TypeChecker {
710708
infcx,
711709
last_span: DUMMY_SP,
712-
body_id,
710+
mir_def_id,
713711
param_env,
714712
region_bound_pairs,
715713
implicit_region_bound,
@@ -720,10 +718,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
720718
}
721719
}
722720

723-
fn misc(&self, span: Span) -> traits::ObligationCause<'tcx> {
724-
traits::ObligationCause::misc(span, self.body_id)
725-
}
726-
727721
/// Given some operation `op` that manipulates types, proves
728722
/// predicates, or otherwise uses the inference context, executes
729723
/// `op` and then executes all the further obligations that `op`
@@ -794,7 +788,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
794788
}
795789

796790
let mut fulfill_cx = TraitEngine::new(self.infcx.tcx);
791+
let dummy_body_id = ObligationCause::dummy().body_id;
797792
let InferOk { value, obligations } = self.infcx.commit_if_ok(|_| op(self))?;
793+
debug_assert!(obligations.iter().all(|o| o.cause.body_id == dummy_body_id));
798794
fulfill_cx.register_predicate_obligations(self.infcx, obligations);
799795
if let Err(e) = fulfill_cx.select_all_or_error(self.infcx) {
800796
span_mirbug!(self, "", "errors selecting obligation: {:?}", e);
@@ -804,7 +800,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
804800
self.region_bound_pairs,
805801
self.implicit_region_bound,
806802
self.param_env,
807-
self.body_id,
803+
dummy_body_id,
808804
);
809805

810806
let data = self.infcx.take_and_reset_region_constraints();
@@ -832,7 +828,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
832828
|| format!("sub_types({:?} <: {:?})", sub, sup),
833829
|this| {
834830
this.infcx
835-
.at(&this.misc(this.last_span), this.param_env)
831+
.at(&ObligationCause::dummy(), this.param_env)
836832
.sup(sup, sub)
837833
},
838834
)
@@ -850,7 +846,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
850846
|| format!("eq_types({:?} = {:?})", a, b),
851847
|this| {
852848
this.infcx
853-
.at(&this.misc(this.last_span), this.param_env)
849+
.at(&ObligationCause::dummy(), this.param_env)
854850
.eq(b, a)
855851
},
856852
)
@@ -1575,9 +1571,10 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
15751571
if let Some(closure_region_requirements) =
15761572
tcx.mir_borrowck(*def_id).closure_requirements
15771573
{
1574+
let dummy_body_id = ObligationCause::dummy().body_id;
15781575
closure_region_requirements.apply_requirements(
15791576
self.infcx,
1580-
self.body_id,
1577+
dummy_body_id,
15811578
location,
15821579
*def_id,
15831580
*substs,
@@ -1613,7 +1610,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
16131610
where
16141611
T: IntoIterator<Item = ty::Predicate<'tcx>> + Clone,
16151612
{
1616-
let cause = self.misc(self.last_span);
1613+
let cause = ObligationCause::dummy();
16171614
let obligations: Vec<_> = predicates
16181615
.into_iter()
16191616
.map(|p| traits::Obligation::new(cause.clone(), self.param_env, p))
@@ -1694,7 +1691,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
16941691
|this| {
16951692
let Normalized { value, obligations } = this
16961693
.infcx
1697-
.at(&this.misc(this.last_span), this.param_env)
1694+
.at(&ObligationCause::dummy(), this.param_env)
16981695
.normalize(value)
16991696
.unwrap_or_else(|NoSolution| {
17001697
span_bug!(
@@ -1715,7 +1712,6 @@ pub struct TypeckMir;
17151712
impl MirPass for TypeckMir {
17161713
fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource, mir: &mut Mir<'tcx>) {
17171714
let def_id = src.def_id;
1718-
let id = tcx.hir.as_local_node_id(def_id).unwrap();
17191715
debug!("run_pass: {:?}", def_id);
17201716

17211717
// When NLL is enabled, the borrow checker runs the typeck
@@ -1731,7 +1727,16 @@ impl MirPass for TypeckMir {
17311727
}
17321728
let param_env = tcx.param_env(def_id);
17331729
tcx.infer_ctxt().enter(|infcx| {
1734-
let _ = type_check_internal(&infcx, id, param_env, mir, &[], None, None, &mut |_| ());
1730+
let _ = type_check_internal(
1731+
&infcx,
1732+
def_id,
1733+
param_env,
1734+
mir,
1735+
&[],
1736+
None,
1737+
None,
1738+
&mut |_| (),
1739+
);
17351740

17361741
// For verification purposes, we just ignore the resulting
17371742
// region constraint sets. Not our problem. =)

0 commit comments

Comments
 (0)