Skip to content

create LifetimeRes::Fresh firstly when lower lifetime binder #119021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,15 +874,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
binder: NodeId,
generic_params: &[GenericParam],
) -> &'hir [hir::GenericParam<'hir>] {
let mut generic_params: Vec<_> = self
.lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder)
.collect();
let mut params = vec![];

let extra_lifetimes = self.resolver.take_extra_lifetime_params(binder);
debug!(?extra_lifetimes);
generic_params.extend(extra_lifetimes.into_iter().filter_map(|(ident, node_id, res)| {
params.extend(extra_lifetimes.into_iter().filter_map(|(ident, node_id, res)| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this fix the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An invocation of a def_id in extra_lifetimes occurs during lower_generic_params_mut. This rearrangement ensures that the def_id is not None.

self.lifetime_res_to_generic_param(ident, node_id, res, hir::GenericParamSource::Binder)
}));
let generic_params = self.arena.alloc_from_iter(generic_params);

params
.extend(self.lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder));

let generic_params = self.arena.alloc_from_iter(params);
debug!(?generic_params);

generic_params
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/anonymous-higher-ranked-lifetime.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ LL | f2(|_: (), _: ()| {});
| |
| expected due to this
|
= note: expected closure signature `for<'a, 'b> fn(&'a (), &'b ()) -> _`
= note: expected closure signature `for<'b, 'a> fn(&'a (), &'b ()) -> _`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems acceptable. Alternatively, we could sort this before displaying the diagnostics?

found closure signature `fn((), ()) -> _`
note: required by a bound in `f2`
--> $DIR/anonymous-higher-ranked-lifetime.rs:17:25
Expand Down Expand Up @@ -66,7 +66,7 @@ LL | f4(|_: (), _: ()| {});
| |
| expected due to this
|
= note: expected closure signature `for<'r, 'a> fn(&'a (), &'r ()) -> _`
= note: expected closure signature `for<'a, 'r> fn(&'a (), &'r ()) -> _`
found closure signature `fn((), ()) -> _`
note: required by a bound in `f4`
--> $DIR/anonymous-higher-ranked-lifetime.rs:19:25
Expand Down Expand Up @@ -206,7 +206,7 @@ LL | h2(|_: (), _: (), _: (), _: ()| {});
| |
| expected due to this
|
= note: expected closure signature `for<'t0, 'a> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>, &'t0 (), for<'a, 'b> fn(&'a (), &'b ())) -> _`
= note: expected closure signature `for<'a, 't0> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>, &'t0 (), for<'a, 'b> fn(&'a (), &'b ())) -> _`
found closure signature `fn((), (), (), ()) -> _`
note: required by a bound in `h2`
--> $DIR/anonymous-higher-ranked-lifetime.rs:30:25
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/traits/non_lifetime_binders/issue-118697.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![allow(incomplete_features)]
#![feature(non_lifetime_binders)]

type T = dyn for<V = A(&())> Fn(());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably just ban parameter defaults in non-lifetime binders before we get to AST->HIR lowering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree this is a promising approach. I'll give it a try.

//~^ ERROR cannot find type `A` in this scope
//~| ERROR late-bound type parameter not allowed on trait object types

fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/traits/non_lifetime_binders/issue-118697.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0412]: cannot find type `A` in this scope
--> $DIR/issue-118697.rs:4:22
|
LL | type T = dyn for<V = A(&())> Fn(());
| ^ not found in this scope

error: late-bound type parameter not allowed on trait object types
--> $DIR/issue-118697.rs:4:18
|
LL | type T = dyn for<V = A(&())> Fn(());
| ^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0412`.