Skip to content

Commit b61a28b

Browse files
author
Markus Westerlind
committed
Rebase and use ena 0.14
1 parent fba241f commit b61a28b

File tree

10 files changed

+70
-55
lines changed

10 files changed

+70
-55
lines changed

src/librustc_infer/infer/mod.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
223223
&self.region_obligations
224224
}
225225

226-
pub(crate) fn projection_cache(&mut self) -> traits::ProjectionCache<'tcx, '_> {
226+
pub fn projection_cache(&mut self) -> traits::ProjectionCache<'tcx, '_> {
227227
self.projection_cache.with_log(&mut self.undo_log)
228228
}
229229

@@ -1308,19 +1308,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13081308
outlives_env: &OutlivesEnvironment<'tcx>,
13091309
mode: RegionckMode,
13101310
) {
1311-
assert!(
1312-
self.is_tainted_by_errors() || self.inner.borrow().region_obligations.is_empty(),
1313-
"region_obligations not empty: {:#?}",
1314-
self.inner.borrow().region_obligations
1315-
);
1316-
let (var_infos, data) = self
1317-
.inner
1318-
.borrow_mut()
1319-
.region_constraints
1320-
.take()
1321-
.expect("regions already resolved")
1322-
.with_log(&mut inner.undo_log)
1323-
.into_infos_and_data();
1311+
let (var_infos, data) = {
1312+
let mut inner = self.inner.borrow_mut();
1313+
let inner = &mut *inner;
1314+
assert!(
1315+
self.is_tainted_by_errors() || inner.region_obligations.is_empty(),
1316+
"region_obligations not empty: {:#?}",
1317+
inner.region_obligations
1318+
);
1319+
inner
1320+
.region_constraints
1321+
.take()
1322+
.expect("regions already resolved")
1323+
.with_log(&mut inner.undo_log)
1324+
.into_infos_and_data()
1325+
};
13241326

13251327
let region_rels = &RegionRelations::new(
13261328
self.tcx,
@@ -1686,13 +1688,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16861688
/// having to resort to storing full `GenericArg`s in `stalled_on`.
16871689
#[inline(always)]
16881690
pub fn ty_or_const_infer_var_changed(&self, infer_var: TyOrConstInferVar<'tcx>) -> bool {
1691+
let mut inner = self.inner.borrow_mut();
16891692
match infer_var {
16901693
TyOrConstInferVar::Ty(v) => {
16911694
use self::type_variable::TypeVariableValue;
16921695

16931696
// If `inlined_probe` returns a `Known` value, it never equals
16941697
// `ty::Infer(ty::TyVar(v))`.
1695-
match self.inner.borrow_mut().type_variables().inlined_probe(v) {
1698+
match inner.type_variables().inlined_probe(v) {
16961699
TypeVariableValue::Unknown { .. } => false,
16971700
TypeVariableValue::Known { .. } => true,
16981701
}
@@ -1702,23 +1705,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17021705
// If `inlined_probe_value` returns a value it's always a
17031706
// `ty::Int(_)` or `ty::UInt(_)`, which never matches a
17041707
// `ty::Infer(_)`.
1705-
self.inner.borrow_mut().int_unification_table().inlined_probe_value(v).is_some()
1708+
inner.int_unification_table().inlined_probe_value(v).is_some()
17061709
}
17071710

17081711
TyOrConstInferVar::TyFloat(v) => {
17091712
// If `probe_value` returns a value it's always a
17101713
// `ty::Float(_)`, which never matches a `ty::Infer(_)`.
17111714
//
17121715
// Not `inlined_probe_value(v)` because this call site is colder.
1713-
self.inner.borrow_mut().float_unification_table().probe_value(v).is_some()
1716+
inner.float_unification_table().probe_value(v).is_some()
17141717
}
17151718

17161719
TyOrConstInferVar::Const(v) => {
17171720
// If `probe_value` returns a `Known` value, it never equals
17181721
// `ty::ConstKind::Infer(ty::InferConst::Var(v))`.
17191722
//
17201723
// Not `inlined_probe_value(v)` because this call site is colder.
1721-
match self.inner.borrow_mut().const_unification_table.probe_value(v).val {
1724+
match inner.const_unification_table().probe_value(v).val {
17221725
ConstVariableValue::Unknown { .. } => false,
17231726
ConstVariableValue::Known { .. } => true,
17241727
}

src/librustc_infer/infer/undo_log.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::marker::PhantomData;
22

3-
use rustc::ty;
43
use rustc_data_structures::snapshot_vec as sv;
54
use rustc_data_structures::undo_log::{Rollback, Snapshots, UndoLogs};
65
use rustc_data_structures::unify as ut;
76
use rustc_hir as hir;
7+
use rustc_middle::ty;
88

99
use crate::{
1010
infer::{

src/librustc_infer/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub use self::project::MismatchedProjectionTypes;
2323
pub(crate) use self::project::UndoLog;
2424
pub use self::project::{
2525
Normalized, NormalizedTy, ProjectionCache, ProjectionCacheEntry, ProjectionCacheKey,
26-
ProjectionCacheSnapshot, Reveal,
26+
ProjectionCacheStorage, Reveal,
2727
};
2828
crate use self::util::elaborate_predicates;
2929

src/librustc_infer/traits/project.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
33
use super::PredicateObligation;
44

5-
use rustc_data_structures::snapshot_map::{self, SnapshotMapRef, SnapshotMapStorage};
6-
use rustc_middle::ty::fold::TypeFoldable;
5+
use crate::infer::InferCtxtUndoLogs;
6+
7+
use rustc_data_structures::{
8+
snapshot_map::{self, SnapshotMapRef, SnapshotMapStorage},
9+
undo_log::Rollback,
10+
};
711
use rustc_middle::ty::{self, Ty};
812

913
pub use rustc_middle::traits::Reveal;

src/librustc_middle/hir/map/mod.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -311,16 +311,19 @@ impl<'hir> Map<'hir> {
311311
}
312312

313313
fn find_entry(&self, id: HirId) -> Option<Entry<'hir>> {
314-
if id.local_id == ItemLocalId::from_u32_const(0) {
315-
let owner = self.tcx.hir_owner(id.owner_def_id());
314+
if id.local_id == ItemLocalId::from_u32(0) {
315+
let owner = self.tcx.hir_owner(id.owner);
316316
owner.map(|owner| Entry { parent: owner.parent, node: owner.node })
317317
} else {
318-
let owner = self.tcx.hir_owner_items(id.owner_def_id());
318+
let owner = self.tcx.hir_owner_nodes(id.owner);
319319
owner.and_then(|owner| {
320-
let item = owner.items[id.local_id].as_ref();
321-
item.map(|item| Entry {
322-
parent: HirId { owner: id.owner, local_id: item.parent },
323-
node: item.node,
320+
let node = owner.nodes[id.local_id].as_ref();
321+
// FIXME(eddyb) use a single generic type insted of having both
322+
// `Entry` and `ParentedNode`, which are effectively the same.
323+
// Alternatively, rewrite code using `Entry` to use `ParentedNode`.
324+
node.map(|node| Entry {
325+
parent: HirId { owner: id.owner, local_id: node.parent },
326+
node: node.node,
324327
})
325328
})
326329
}
@@ -352,12 +355,7 @@ impl<'hir> Map<'hir> {
352355
}
353356

354357
pub fn body(&self, id: BodyId) -> &'hir Body<'hir> {
355-
self.tcx
356-
.hir_owner_items(DefId::local(id.hir_id.owner))
357-
.unwrap()
358-
.bodies
359-
.get(&id.hir_id.local_id)
360-
.unwrap()
358+
self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies.get(&id.hir_id.local_id).unwrap()
361359
}
362360

363361
pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {

src/librustc_middle/hir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ pub fn provide(providers: &mut Providers<'_>) {
7777
let module = hir.as_local_hir_id(id);
7878
&tcx.untracked_crate.modules[&module]
7979
};
80-
providers.hir_owner = |tcx, id| tcx.index_hir(id.krate).map[id.index].signature;
81-
providers.hir_owner_items =
82-
|tcx, id| tcx.index_hir(id.krate).map[id.index].with_bodies.as_ref().map(|items| &**items);
80+
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;
81+
providers.hir_owner_nodes =
82+
|tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_ref().map(|nodes| &**nodes);
8383
map::provide(providers);
8484
}

src/librustc_middle/query/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ rustc_queries! {
7575
//
7676
// This can be conveniently accessed by methods on `tcx.hir()`.
7777
// Avoid calling this query directly.
78-
query hir_owner(key: DefId) -> Option<&'tcx HirOwner<'tcx>> {
78+
query hir_owner(key: LocalDefId) -> Option<&'tcx crate::hir::Owner<'tcx>> {
7979
eval_always
8080
desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
8181
}
@@ -84,7 +84,7 @@ rustc_queries! {
8484
//
8585
// This can be conveniently accessed by methods on `tcx.hir()`.
8686
// Avoid calling this query directly.
87-
query hir_owner_items(key: DefId) -> Option<&'tcx HirOwnerItems<'tcx>> {
87+
query hir_owner_nodes(key: LocalDefId) -> Option<&'tcx crate::hir::OwnerNodes<'tcx>> {
8888
eval_always
8989
desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
9090
}

src/librustc_trait_selection/traits/fulfill.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,15 @@ struct FulfillProcessor<'a, 'b, 'tcx> {
240240
register_region_obligations: bool,
241241
}
242242

243-
fn mk_pending(os: Vec<PredicateObligation<'tcx>>) -> Vec<PendingPredicateObligation<'tcx>> {
243+
fn mk_pending(
244+
infcx: &InferCtxt<'_, 'tcx>,
245+
os: Vec<PredicateObligation<'tcx>>,
246+
) -> Vec<PendingPredicateObligation<'tcx>> {
244247
os.into_iter()
245-
.map(|o| PendingPredicateObligation { obligation: o, stalled_on: vec![] })
248+
.map(|mut o| {
249+
o.predicate = infcx.resolve_vars_if_possible(&o.predicate);
250+
PendingPredicateObligation { obligation: o, stalled_on: vec![] }
251+
})
246252
.collect()
247253
}
248254

@@ -312,14 +318,16 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
312318

313319
debug!("process_obligation: obligation = {:?} cause = {:?}", obligation, obligation.cause);
314320

321+
let infcx = self.selcx.infcx();
322+
315323
match obligation.predicate {
316324
ty::Predicate::Trait(ref data, _) => {
317325
let trait_obligation = obligation.with(*data);
318326

319327
if data.is_global() {
320328
// no type variables present, can use evaluation for better caching.
321329
// FIXME: consider caching errors too.
322-
if self.selcx.infcx().predicate_must_hold_considering_regions(&obligation) {
330+
if infcx.predicate_must_hold_considering_regions(&obligation) {
323331
debug!(
324332
"selecting trait `{:?}` at depth {} evaluated to holds",
325333
data, obligation.recursion_depth
@@ -334,7 +342,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
334342
"selecting trait `{:?}` at depth {} yielded Ok(Some)",
335343
data, obligation.recursion_depth
336344
);
337-
ProcessResult::Changed(mk_pending(vtable.nested_obligations()))
345+
ProcessResult::Changed(mk_pending(infcx, vtable.nested_obligations()))
338346
}
339347
Ok(None) => {
340348
debug!(
@@ -351,7 +359,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
351359

352360
debug!(
353361
"process_predicate: pending obligation {:?} now stalled on {:?}",
354-
self.selcx.infcx().resolve_vars_if_possible(obligation),
362+
infcx.resolve_vars_if_possible(obligation),
355363
pending_obligation.stalled_on
356364
);
357365

@@ -369,7 +377,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
369377
}
370378

371379
ty::Predicate::RegionOutlives(ref binder) => {
372-
match self.selcx.infcx().region_outlives_predicate(&obligation.cause, binder) {
380+
match infcx.region_outlives_predicate(&obligation.cause, binder) {
373381
Ok(()) => ProcessResult::Changed(vec![]),
374382
Err(_) => ProcessResult::Error(CodeSelectionError(Unimplemented)),
375383
}
@@ -428,7 +436,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
428436
trait_ref_type_vars(self.selcx, data.to_poly_trait_ref(tcx));
429437
ProcessResult::Unchanged
430438
}
431-
Ok(Some(os)) => ProcessResult::Changed(mk_pending(os)),
439+
Ok(Some(os)) => ProcessResult::Changed(mk_pending(infcx, os)),
432440
Err(e) => ProcessResult::Error(CodeProjectionError(e)),
433441
}
434442
}
@@ -467,7 +475,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
467475
vec![TyOrConstInferVar::maybe_from_ty(ty).unwrap()];
468476
ProcessResult::Unchanged
469477
}
470-
Some(os) => ProcessResult::Changed(mk_pending(os)),
478+
Some(os) => ProcessResult::Changed(mk_pending(infcx, os)),
471479
}
472480
}
473481

@@ -485,7 +493,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
485493
];
486494
ProcessResult::Unchanged
487495
}
488-
Some(Ok(ok)) => ProcessResult::Changed(mk_pending(ok.obligations)),
496+
Some(Ok(ok)) => ProcessResult::Changed(mk_pending(infcx, ok.obligations)),
489497
Some(Err(err)) => {
490498
let expected_found = ExpectedFound::new(
491499
subtype.skip_binder().a_is_expected,

src/librustc_trait_selection/traits/project.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
471471
// bounds. It might be the case that we want two distinct caches,
472472
// or else another kind of cache entry.
473473

474-
let cache_result = infcx.inner.borrow_mut().projection_cache.try_start(cache_key);
474+
let cache_result = infcx.inner.borrow_mut().projection_cache().try_start(cache_key);
475475
match cache_result {
476476
Ok(()) => {}
477477
Err(ProjectionCacheEntry::Ambiguous) => {
@@ -537,7 +537,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
537537
// Once we have inferred everything we need to know, we
538538
// can ignore the `obligations` from that point on.
539539
if infcx.unresolved_type_vars(&ty.value).is_none() {
540-
infcx.inner.borrow_mut().projection_cache.complete_normalized(cache_key, &ty);
540+
infcx.inner.borrow_mut().projection_cache().complete_normalized(cache_key, &ty);
541541
// No need to extend `obligations`.
542542
} else {
543543
obligations.extend(ty.obligations);
@@ -604,7 +604,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
604604
};
605605

606606
let cache_value = prune_cache_value_obligations(infcx, &result);
607-
infcx.inner.borrow_mut().projection_cache.insert_ty(cache_key, cache_value);
607+
infcx.inner.borrow_mut().projection_cache().insert_ty(cache_key, cache_value);
608608
obligations.extend(result.obligations);
609609
Some(result.value)
610610
}
@@ -615,7 +615,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
615615
projected_ty
616616
);
617617
let result = Normalized { value: projected_ty, obligations: vec![] };
618-
infcx.inner.borrow_mut().projection_cache.insert_ty(cache_key, result.clone());
618+
infcx.inner.borrow_mut().projection_cache().insert_ty(cache_key, result.clone());
619619
// No need to extend `obligations`.
620620
Some(result.value)
621621
}
@@ -624,7 +624,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
624624
"opt_normalize_projection_type: \
625625
too many candidates"
626626
);
627-
infcx.inner.borrow_mut().projection_cache.ambiguous(cache_key);
627+
infcx.inner.borrow_mut().projection_cache().ambiguous(cache_key);
628628
None
629629
}
630630
Err(ProjectionTyError::TraitSelectionError(_)) => {
@@ -634,7 +634,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
634634
// Trait`, which when processed will cause the error to be
635635
// reported later
636636

637-
infcx.inner.borrow_mut().projection_cache.error(cache_key);
637+
infcx.inner.borrow_mut().projection_cache().error(cache_key);
638638
let result = normalize_to_error(selcx, param_env, projection_ty, cause, depth);
639639
obligations.extend(result.obligations);
640640
Some(result.value)

src/test/ui/issues/issue-70041.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
// run-pass
33

44
macro_rules! regex {
5+
//~^ WARN unused macro definition
56
() => {};
67
}
78

89
#[allow(dead_code)]
910
use regex;
11+
//~^ WARN unused import
1012

1113
fn main() {}

0 commit comments

Comments
 (0)