Skip to content

Commit 93ef0cd

Browse files
committed
Auto merge of #99098 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] backport rollup * Return a FxIndexSet in is_late_bound query. #98959 * rustdoc: filter '_ lifetimes from ty::PolyTraitRef #98727 * don't succeed evaluate_obligation query if new opaque types were registered #98614 * Update llvm-project #98567 There's a few more as-yet-unapproved/unmerged PRs that'll land later, but creating a partial rollup for now so that we can include at least some PRs in the first crater run. r? `@Mark-Simulacrum`
2 parents 94811fd + b5c6911 commit 93ef0cd

File tree

29 files changed

+163
-192
lines changed

29 files changed

+163
-192
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
891891
.region_constraints_added_in_snapshot(&snapshot.undo_snapshot)
892892
}
893893

894+
pub fn opaque_types_added_in_snapshot(&self, snapshot: &CombinedSnapshot<'a, 'tcx>) -> bool {
895+
self.inner.borrow().undo_log.opaque_types_in_snapshot(&snapshot.undo_snapshot)
896+
}
897+
894898
pub fn add_given(&self, sub: ty::Region<'tcx>, sup: ty::RegionVid) {
895899
self.inner.borrow_mut().unwrap_region_constraints().add_given(sub, sup);
896900
}

compiler/rustc_infer/src/infer/opaque_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
103103
}
104104
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
105105
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
106-
ty::Opaque(def_id, substs) => {
106+
ty::Opaque(def_id, substs) if def_id.is_local() => {
107107
let origin = if self.defining_use_anchor.is_some() {
108108
// Check that this is `impl Trait` type is
109109
// declared by `parent_def_id` -- i.e., one whose

compiler/rustc_infer/src/infer/undo_log.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ impl<'tcx> InferCtxtUndoLogs<'tcx> {
185185
})
186186
}
187187

188+
pub(crate) fn opaque_types_in_snapshot(&self, s: &Snapshot<'tcx>) -> bool {
189+
self.logs[s.undo_len..].iter().any(|log| matches!(log, UndoLog::OpaqueTypes(..)))
190+
}
191+
188192
pub(crate) fn region_constraints(
189193
&self,
190194
) -> impl Iterator<Item = &'_ region_constraints::UndoLog<'tcx>> + Clone {

compiler/rustc_infer/src/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
203203
Some(&ProjectionCacheEntry::NormalizedTy { ref ty, complete: _ }) => {
204204
info!("ProjectionCacheEntry::complete({:?}) - completing {:?}", key, ty);
205205
let mut ty = ty.clone();
206-
if result == EvaluationResult::EvaluatedToOk {
206+
if result.must_apply_considering_regions() {
207207
ty.obligations = vec![];
208208
}
209209
map.insert(key, ProjectionCacheEntry::NormalizedTy { ty, complete: Some(result) });

compiler/rustc_middle/src/arena.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ macro_rules! arena_types {
9696
// (during lowering) and the `librustc_middle` arena (for decoding MIR)
9797
[decode] asm_template: rustc_ast::InlineAsmTemplatePiece,
9898
[decode] used_trait_imports: rustc_data_structures::fx::FxHashSet<rustc_hir::def_id::LocalDefId>,
99+
[decode] is_late_bound_map: rustc_data_structures::fx::FxIndexSet<rustc_hir::def_id::LocalDefId>,
99100
[decode] impl_source: rustc_middle::traits::ImplSource<'tcx, ()>,
100101

101102
[] dep_kind: rustc_middle::dep_graph::DepKindStruct,

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ rustc_queries! {
15721572
Option<&'tcx FxHashMap<ItemLocalId, Region>> {
15731573
desc { "looking up a named region" }
15741574
}
1575-
query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxHashSet<LocalDefId>> {
1575+
query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxIndexSet<LocalDefId>> {
15761576
desc { "testing if a region is late bound" }
15771577
}
15781578
/// For a given item (like a struct), gets the default lifetimes to be used

compiler/rustc_middle/src/traits/select.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ pub enum EvaluationResult {
176176
EvaluatedToOk,
177177
/// Evaluation successful, but there were unevaluated region obligations.
178178
EvaluatedToOkModuloRegions,
179+
/// Evaluation successful, but need to rerun because opaque types got
180+
/// hidden types assigned without it being known whether the opaque types
181+
/// are within their defining scope
182+
EvaluatedToOkModuloOpaqueTypes,
179183
/// Evaluation is known to be ambiguous -- it *might* hold for some
180184
/// assignment of inference variables, but it might not.
181185
///
@@ -252,9 +256,11 @@ impl EvaluationResult {
252256

253257
pub fn may_apply(self) -> bool {
254258
match self {
255-
EvaluatedToOk | EvaluatedToOkModuloRegions | EvaluatedToAmbig | EvaluatedToUnknown => {
256-
true
257-
}
259+
EvaluatedToOkModuloOpaqueTypes
260+
| EvaluatedToOk
261+
| EvaluatedToOkModuloRegions
262+
| EvaluatedToAmbig
263+
| EvaluatedToUnknown => true,
258264

259265
EvaluatedToErr | EvaluatedToRecur => false,
260266
}
@@ -264,7 +270,11 @@ impl EvaluationResult {
264270
match self {
265271
EvaluatedToUnknown | EvaluatedToRecur => true,
266272

267-
EvaluatedToOk | EvaluatedToOkModuloRegions | EvaluatedToAmbig | EvaluatedToErr => false,
273+
EvaluatedToOkModuloOpaqueTypes
274+
| EvaluatedToOk
275+
| EvaluatedToOkModuloRegions
276+
| EvaluatedToAmbig
277+
| EvaluatedToErr => false,
268278
}
269279
}
270280
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ impl<'tcx> InstantiatedPredicates<'tcx> {
11051105
Lift
11061106
)]
11071107
pub struct OpaqueTypeKey<'tcx> {
1108+
// FIXME(oli-obk): make this a LocalDefId
11081109
pub def_id: DefId,
11091110
pub substs: SubstsRef<'tcx>,
11101111
}

compiler/rustc_resolve/src/late/lifetimes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,12 +2539,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25392539
/// "Constrained" basically means that it appears in any type but
25402540
/// not amongst the inputs to a projection. In other words, `<&'a
25412541
/// T as Trait<''b>>::Foo` does not constrain `'a` or `'b`.
2542-
fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxHashSet<LocalDefId>> {
2542+
fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxIndexSet<LocalDefId>> {
25432543
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
25442544
let decl = tcx.hir().fn_decl_by_hir_id(hir_id)?;
25452545
let generics = tcx.hir().get_generics(def_id)?;
25462546

2547-
let mut late_bound = FxHashSet::default();
2547+
let mut late_bound = FxIndexSet::default();
25482548

25492549
let mut constrained_by_input = ConstrainedCollector::default();
25502550
for arg_ty in decl.inputs {

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
777777
Ok(
778778
EvaluationResult::EvaluatedToOk
779779
| EvaluationResult::EvaluatedToOkModuloRegions
780+
| EvaluationResult::EvaluatedToOkModuloOpaqueTypes
780781
| EvaluationResult::EvaluatedToAmbig,
781782
) => {}
782783
_ => return false,

0 commit comments

Comments
 (0)