You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unify lifetime elision for impl Trait arguments between async and non-async functions #85417
This difference strikes me as very odd. Is this intended? If so, why?
This is formulated as a question, but if I had to guess, I would classify this as oversight or bug -- that's why I created an issue instead of askig in the forum.
// In `async fn`, argument-position elided lifetimes
// must be transformed into fresh generic parameters so that
// they can be applied to the opaque `impl Trait` return type.
AnonymousLifetimeMode::CreateParameter
}else{
self.anonymous_lifetime_mode
};
While we decided that async fn probably exhibits the right behavior, it's possible this could affect other things too which could lead to bugs. Before declaring this fixed we should account for anything that might appear in arguments and be affected by this code.
We also noticed that in sync code, we aren't consistent in the behavior of impl Trait and dyn Trait. For example:
traitSomething{typeItem;}fnfoo(x:&dynSomething<Item = &u32>){}// works finefnfoo(x:&implSomething<Item = &u32>){}// error
We should be more consistent and document the elision rules for all these cases in the reference. Since dyn already accepts this, we decided we should go ahead and accept this for impl Trait too.
Reacted by Lukas Kalbertodt, Esteban Kuber, Petr Kozelka and Peter Szilvasi
#97720 originally suggested to remove the difference between the async and regular fns. In order to avoid and insta-stable change, the choice was made to introduce the feature gate instead in #97720 (comment).
Removing this feature gate is trivial: revert 5a20834.
Re-introducing suggestions there is more complicated: the feature gate happens after the suggestion code. (AST-based resolution accepts the code and does not suggest anything, and HIR-based lifetime resolution issues the feature gate later.)
changed the title [-]Is this difference in lifetime elision for `impl Trait` arguments between async and non-async function intended?[/-][+]Unify lifetime elision for `impl Trait` arguments between async and non-async functions[/+]on Mar 20, 2026
Activity
tmandry commentedon May 21, 2021
We discussed this in our meeting today. The difference in behavior comes from this code:
rust/compiler/rustc_ast_lowering/src/lib.rs
Lines 1800 to 1807 in af2ed1b
While we decided that async fn probably exhibits the right behavior, it's possible this could affect other things too which could lead to bugs. Before declaring this fixed we should account for anything that might appear in arguments and be affected by this code.
We also noticed that in sync code, we aren't consistent in the behavior of impl Trait and dyn Trait. For example:
We should be more consistent and document the elision rules for all these cases in the reference. Since dyn already accepts this, we decided we should go ahead and accept this for impl Trait too.
eholk commentedon Oct 4, 2021
This seems sort of related to #74256 and #74597.
estebank commentedon Aug 16, 2022
The output of this is regressing in 1.64.
1.63:
1.64:
cjgillot commentedon Sep 1, 2022
#97720 originally suggested to remove the difference between the async and regular fns. In order to avoid and insta-stable change, the choice was made to introduce the feature gate instead in #97720 (comment).
Removing this feature gate is trivial: revert 5a20834.
Re-introducing suggestions there is more complicated: the feature gate happens after the suggestion code. (AST-based resolution accepts the code and does not suggest anything, and HIR-based lifetime resolution issues the feature gate later.)
[-]Is this difference in lifetime elision for `impl Trait` arguments between async and non-async function intended?[/-][+]Unify lifetime elision for `impl Trait` arguments between async and non-async functions[/+]