-
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.C-bugCategory: This is a bug.Category: This is a bug.F-impl_trait_in_assoc_type`#![feature(impl_trait_in_assoc_type)]``#![feature(impl_trait_in_assoc_type)]`I-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
I tried this code:
#![feature(return_position_impl_trait_in_trait)]
trait Nest: FnOnce() -> () {
fn nest(self) -> impl Nest;
}
impl<P: FnOnce() -> ()> Nest for P {
fn nest(self) -> impl Nest {
|| self()
}
}
fn inner(val: &'static str) -> impl Nest {
move || {
val;
}
}
fn main() {
inner("")
.nest().nest().nest().nest().nest()
.nest().nest().nest().nest().nest()
.nest().nest().nest().nest().nest()
.nest().nest().nest().nest().nest()
.nest().nest().nest().nest().nest();
}
I expected this to compile reasonably quickly.
Instead the above example took about a minute and a half. With 20 .nest()
s in sequence, it takes between two and three seconds. For each subsequent .nest()
, it takes about twice the time.
When I replace || self()
with just self
, it compiles almost instantly. The same happens when I remove the apparently inconsequential val;
statement, or when I use an owned type instead of a &'static str
.
Meta
rustc --version --verbose
:
rustc 1.66.0-nightly (3f83906b3 2022-09-24)
binary: rustc
commit-hash: 3f83906b30798bf61513fa340524cebf6676f9db
commit-date: 2022-09-24
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.0
compiler-errors, chenyukang, Dirbaio and lukesandberg
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.C-bugCategory: This is a bug.Category: This is a bug.F-impl_trait_in_assoc_type`#![feature(impl_trait_in_assoc_type)]``#![feature(impl_trait_in_assoc_type)]`I-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Type
Projects
Status
Non-blocking
Milestone
Relationships
Development
Select code repository
Activity
Artemis21 commentedon Sep 30, 2022
The version of this without using RPITIT also compiles quickly:
compiler-errors commentedon Sep 30, 2022
how interesting, I'll look into this :)
Mark-Simulacrum commentedon Sep 30, 2022
Feels like the desugaring might end up similar to #100886, so maybe worth trying any fix on that too.
compiler-errors commentedon Jun 12, 2023
This doesn't exactly have to do with RPITIT -- can be replicated with regular opaques via
impl_trait_in_assoc_type
compiler-errors commentedon Jun 29, 2023
Triage: still hangs
async fn
and return-positionimpl Trait
in trait #115822Auto merge of rust-lang#115822 - compiler-errors:stabilize-rpitit, r=…