-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
Using a returned impl Trait
for a trait with an associated type and not specifying the associated type leads to the following error:
error[E0700]: hidden type for `impl Trait + 'static` captures lifetime that does not appear in bounds
..even when + 'static
is specified, meaning no lifetimes should be captured. Adding #![feature(associated_type_bounds)]
and instead using impl Trait<AssocType: 'static>
as a return type solves the issue. I'm not sure if this is intended behavior - it seems pretty strange since AssocType
is defined with a 'static
bound. See the code below for a reproducible example.
#![feature(associated_type_bounds)]
trait Anything {}
impl<T: ?Sized> Anything for T {}
trait Thing {
type Output: 'static;
fn calc(&mut self) -> Self::Output;
}
impl<'a> Thing for &'a u8 {
type Output = u8;
fn calc(&mut self) -> u8 { **self }
}
// uncomment the bound to make it work
fn get_thing(x: &u8) -> impl Thing /* <Output: 'static> */ + '_ {
x
}
fn f(n: &u8) -> impl Anything + 'static {
let mut t = get_thing(n);
t.calc()
}
Meta
rustc --version --verbose
:
rustc 1.67.0-nightly (c090c6880 2022-12-01)
kmicklas
Metadata
Metadata
Assignees
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.