Skip to content

Commit 935824e

Browse files
authored
Unrolled build for #143430
Rollup merge of #143430 - cjgillot:extra-lifetime-swap, r=oli-obk Lower extra lifetimes before normal generic params. Fixes #143413
2 parents 3f9f20f + 7da6fd1 commit 935824e

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -874,25 +874,32 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
874874
/// name resolver owing to lifetime elision; this also populates the resolver's node-id->def-id
875875
/// map, so that later calls to `opt_node_id_to_def_id` that refer to these extra lifetime
876876
/// parameters will be successful.
877-
#[instrument(level = "debug", skip(self))]
877+
#[instrument(level = "debug", skip(self), ret)]
878878
#[inline]
879879
fn lower_lifetime_binder(
880880
&mut self,
881881
binder: NodeId,
882882
generic_params: &[GenericParam],
883883
) -> &'hir [hir::GenericParam<'hir>] {
884-
let mut generic_params: Vec<_> = self
885-
.lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder)
886-
.collect();
884+
// Start by creating params for extra lifetimes params, as this creates the definitions
885+
// that may be referred to by the AST inside `generic_params`.
887886
let extra_lifetimes = self.resolver.extra_lifetime_params(binder);
888887
debug!(?extra_lifetimes);
889-
generic_params.extend(extra_lifetimes.into_iter().filter_map(|(ident, node_id, res)| {
890-
self.lifetime_res_to_generic_param(ident, node_id, res, hir::GenericParamSource::Binder)
891-
}));
892-
let generic_params = self.arena.alloc_from_iter(generic_params);
893-
debug!(?generic_params);
894-
895-
generic_params
888+
let extra_lifetimes: Vec<_> = extra_lifetimes
889+
.into_iter()
890+
.filter_map(|(ident, node_id, res)| {
891+
self.lifetime_res_to_generic_param(
892+
ident,
893+
node_id,
894+
res,
895+
hir::GenericParamSource::Binder,
896+
)
897+
})
898+
.collect();
899+
let arena = self.arena;
900+
let explicit_generic_params =
901+
self.lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder);
902+
arena.alloc_from_iter(explicit_generic_params.chain(extra_lifetimes.into_iter()))
896903
}
897904

898905
fn with_dyn_type_scope<T>(&mut self, in_scope: bool, f: impl FnOnce(&mut Self) -> T) -> T {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! Regression test for <https://github.com/rust-lang/rust/issues/143413>
2+
//! The anonymous lifetime in `c(&())` is desugared by the resolver as an extra lifetime parameter
3+
//! at the end of the `for` binder. Verify that lowering creates the definition for that extra
4+
//! lifetime parameter before lowering `c(&())`.
5+
6+
trait D {}
7+
8+
type A = dyn for<const B: c(&())> D;
9+
//~^ ERROR cannot find type `c` in this scope
10+
//~| ERROR only lifetime parameters can be used in this context
11+
12+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0412]: cannot find type `c` in this scope
2+
--> $DIR/elided-lifetime-in-const-param-type.rs:8:27
3+
|
4+
LL | type A = dyn for<const B: c(&())> D;
5+
| ^ not found in this scope
6+
7+
error[E0658]: only lifetime parameters can be used in this context
8+
--> $DIR/elided-lifetime-in-const-param-type.rs:8:24
9+
|
10+
LL | type A = dyn for<const B: c(&())> D;
11+
| ^
12+
|
13+
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
14+
= help: add `#![feature(non_lifetime_binders)]` to the crate attributes to enable
15+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
16+
17+
error: aborting due to 2 previous errors
18+
19+
Some errors have detailed explanations: E0412, E0658.
20+
For more information about an error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)