From 2a7abed87f5cb50620c3d81ac4fd1c5f9380e08e Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 5 Jul 2022 21:54:38 +0200 Subject: [PATCH 1/3] Return a FxIndexSet in is_late_bound query. This return value is iterated upon by borrowck, hence the need to preserve a deterministic iteration order. --- compiler/rustc_middle/src/arena.rs | 1 + compiler/rustc_middle/src/query/mod.rs | 2 +- compiler/rustc_resolve/src/late/lifetimes.rs | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 984c95b314b..661a9b1944c 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -96,6 +96,7 @@ macro_rules! arena_types { // (during lowering) and the `librustc_middle` arena (for decoding MIR) [decode] asm_template: rustc_ast::InlineAsmTemplatePiece, [decode] used_trait_imports: rustc_data_structures::fx::FxHashSet, + [decode] is_late_bound_map: rustc_data_structures::fx::FxIndexSet, [decode] impl_source: rustc_middle::traits::ImplSource<'tcx, ()>, [] dep_kind: rustc_middle::dep_graph::DepKindStruct, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 294f56d16b1..f66f1865c34 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1573,7 +1573,7 @@ rustc_queries! { Option<&'tcx FxHashMap> { desc { "looking up a named region" } } - query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxHashSet> { + query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxIndexSet> { desc { "testing if a region is late bound" } } /// For a given item (like a struct), gets the default lifetimes to be used diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index ed5d1165c7d..557dbecfabe 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -2539,12 +2539,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { /// "Constrained" basically means that it appears in any type but /// not amongst the inputs to a projection. In other words, `<&'a /// T as Trait<''b>>::Foo` does not constrain `'a` or `'b`. -fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxHashSet> { +fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxIndexSet> { let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let decl = tcx.hir().fn_decl_by_hir_id(hir_id)?; let generics = tcx.hir().get_generics(def_id)?; - let mut late_bound = FxHashSet::default(); + let mut late_bound = FxIndexSet::default(); let mut constrained_by_input = ConstrainedCollector::default(); for arg_ty in decl.inputs { From 9715ea4562ef9eabcf326167a15305eba266b40a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 6 Jul 2022 10:56:35 +0200 Subject: [PATCH 2/3] Add regression test. --- src/test/incremental/async-lifetimes.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/incremental/async-lifetimes.rs diff --git a/src/test/incremental/async-lifetimes.rs b/src/test/incremental/async-lifetimes.rs new file mode 100644 index 00000000000..b97725d3b6a --- /dev/null +++ b/src/test/incremental/async-lifetimes.rs @@ -0,0 +1,17 @@ +// revisions: rpass1 rpass2 +// edition:2021 + +#![allow(unused)] + +struct Foo; + +impl Foo { + async fn f(&self, _: &&()) -> &() { + &() + } +} + +#[cfg(rpass2)] +enum Bar {} + +fn main() {} From 8ff4115b5b24095d6abde141957b0c3659ff1d55 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 6 Jul 2022 11:32:55 +0200 Subject: [PATCH 3/3] Add link to issue for src/test/incremental/async-lifetimes.rs --- src/test/incremental/async-lifetimes.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/incremental/async-lifetimes.rs b/src/test/incremental/async-lifetimes.rs index b97725d3b6a..90a0b93b99a 100644 --- a/src/test/incremental/async-lifetimes.rs +++ b/src/test/incremental/async-lifetimes.rs @@ -1,6 +1,8 @@ // revisions: rpass1 rpass2 // edition:2021 +// See https://github.com/rust-lang/rust/issues/98890 + #![allow(unused)] struct Foo;