-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Recursive traits should be allowed when boxing #17893
Comments
Currently gets the error "error: illegal recursive type; insert an enum or struct in the cycle, if this is desired" |
Triage: current error:
|
New error:
|
I would also like to see this. use core::marker::PhantomData;
// API:
pub struct Rc<Dyn: ?Sized + Trace<Dyn>>{
ptr_and_stuff: PhantomData<Dyn>,
}
pub trait Trace<Dyn: Trace<Dyn> + ?Sized> {
/// Give the tracer access to other Rc<Dyn> that we own.
/// Their `Dyn` must be the same as ours.
fn trace(&self, tracer: fn(&Rc<Dyn>));
}
// user code:
trait MyTrait: Trace<dyn MyTrait>{}
struct MyStruct{
field: Rc<dyn MyTrait>,
}
impl Trace<dyn MyTrait> for MyStruct {
fn trace(&self, tracer: fn(&Rc<dyn MyTrait>)){
tracer(&self.field);
}
} The hacky workarounds found on stackoverflow sadly don't work. |
Could someone comment if this has a chance to get accepted in the future? MRE: trait Foo<T: ?Sized> {}
trait Bar: Foo<dyn Bar> {} |
fix: Panic while hovering associated function with type annotation on generic param that not inherited from its container type Fixes rust-lang#17871 We call `generic_args_sans_defaults` here; https://github.com/rust-lang/rust-analyzer/blob/64a140527b383e3a2fe95908881624fc5374c60c/crates/hir-ty/src/display.rs#L1021-L1034 but the following substitution inside that function panic in rust-lang#17871; https://github.com/rust-lang/rust-analyzer/blob/64a140527b383e3a2fe95908881624fc5374c60c/crates/hir-ty/src/display.rs#L1468 it's because the `Binders.binder` inside `default_parameters` has a same length with the generics of the function we are hovering on, but the generics of it is split into two, `fn_params` and `parent_params`. Because of this, it may panic if the function has one or more default parameters and both `fn_params` and `parent_params` are non-empty, like the case in the title of this PR. So, we must call `generic_args_sans_default` first and then split it into `fn_params` and `parent_params`
The following should work:
The text was updated successfully, but these errors were encountered: