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
Generate delegate impl #14386
Comments
@rustbot claim |
I am trying to obtain generic parameters from a trait definition. For that I implemented My first question is if it is really necessary to implement a new method? Another huge downside of doing that is that we need to move this line here which is discouraged ! My second question is how I can get from let gens: Vec<hir::TypeOrConstParamData> = its_trait.type_or_const_param_collect(db);
for g in gens {
match g {
hir::TypeOrConstParamData::TypeParamData(tp) => {
/// Into **not** implemented. But I need to make a conversion between
let ast_cpart: ast::TypeParam = tp.into();
}
hir::TypeOrConstParamData::ConstParamData(cp) => todo!(),
}
} The reason why I am trying to do so it to rely on |
|
Simple fix for make::impl_trait This is my first PR in this project. I made this PR because I needed this function to work properly for the main PR I am working on (#14386). This is a small amendment to what it was before. We still need to improve this in order for it to fully comply with its syntactic definition as stated [here](https://doc.rust-lang.org/reference/items/implementations.html).
I wanted to ask what the expectations are in terms of |
Skip them for now, they can be handled afterwards |
I was given the following test case trait Trait<'a, T, const C: usize> {
type AssocType;
const AssocConst: usize;
fn assoc_fn(p: ());
fn assoc_method(&self, p: ());
}
struct Base;
struct S {
field: Base
}
impl<'a, T, const C: usize> Trait<'a, T, C> for Base {
type AssocType = ();
const AssocConst: usize = 0;
fn assoc_fn(p: ()) {}
fn assoc_method(&self, p: ()) {}
}
impl<'a, T, const C: usize> Trait<'a, T, C> for S {
type AssocType = <Base as Trait<'a, T, C>>::AssocType;
const AssocConst: usize = <Base as Trait<'a, T, C>>::AssocConst;
fn assoc_fn(p: ()) {
<Base as Trait<'a, T, C>>::assoc_fn(p)
}
fn assoc_method(&self, p: ()) {
// This is the interesting part, everything so far we could just delegate without trouble
// but here we need to project the field of `self`!
<Base as Trait<'a, T, C>>::assoc_method(&self.field, p)
}
} My question is about the indentation : impl<'a, T, const C: usize> Base for S<'a, T, C> {
type AssocType= <Base as Trait<'a, T, C>>::AssocType;
const AssocConst: usize = <Base as Trait<'a, T, C>>::AssocConst;
fn assoc_fn(p: ()) {
<Base as Trait<'a, T, C>>::assoc_fn(p)
}
fn assoc_method(&self, p: ()) {
<Base as Trait<'a, T, C>>::assoc_method(p)
}
} I can either change the said line to |
the empty space bewteen assoc items is essential (my example was just slimmed down), note that formatting of produces nodes is always a bit off. We are missing the infrastructure for formatting these currently. regarding the R_CURLYs you'll need to adjust their indentation manually. |
We currently have an assist to generate a delegate method for a field and an assist to generate a deref implementation towards a field. I believe we can generalize the latter by generating a "delegated trait impl" to a field, which would include generating a deref impl for a field but also other things like
Intoiterator
etcShould offer delegating traits impls implemented by
Vec<R>
, resulting in output like the following:The text was updated successfully, but these errors were encountered: