Stream: t-compiler/rust-analyzer

Topic: ra_syntax ast traits

vipentti (Feb 25 2019 at 11:51, on Zulip):


Question regarding the ast traits defined in ra_syntax/src/, such as NameOwner. At what point do you consider adding a new trait ?

This came up with rust-analyzer#897 when working with ast::ConstDef & ast::StaticDef, both have a type_ref option, which also appear in multiple other nodes as well. Is there a reason there is no TypeRefOwner trait or could I add one and replace the options TypeRef in grammar.ron with trait TypeRefOwner and then use TypeRefOwner in the trait bounds?

Similar method of working with nodes with NameOwner and a type_ref occurs in

matklad (Feb 25 2019 at 12:03, on Zulip):

@vipentti in general it's always a good idea to add traits to share AST fuctionlity

matklad (Feb 25 2019 at 12:04, on Zulip):

In this case all things with : Type should probably share a trait

matklad (Feb 25 2019 at 12:05, on Zulip):

I'd say something like

trait TypeAscriptionOwner {
    fn ascribed_type(&self) -> Option<TypeRef>;

impl TypeAscriptionOwner for const, static, let, param
vipentti (Mar 21 2019 at 14:42, on Zulip):

Is there a reason there is no ast::WherePred and a collection for WhereClause of predicates ?

matklad (Mar 21 2019 at 14:44, on Zulip):

no, there's no reason

matklad (Mar 21 2019 at 14:44, on Zulip):

they should be added to grammar.ron

matklad (Mar 21 2019 at 14:45, on Zulip):

I am also passively thinking about rewriting AST bits of grammar.ron using a BNF-ish concrete sytnax

matklad (Mar 21 2019 at 14:46, on Zulip):
fn_def ::=
   modifiers 'fn' name param_list return_type? body?
vipentti (Mar 21 2019 at 14:47, on Zulip):

That sounds pretty cool actually

vipentti (Mar 21 2019 at 14:48, on Zulip):

I'll add a WherePred , I'm not sure though what methods or traits to implement for it, currently don't need anything but I wonder what would be the best way to get access to the paths

vipentti (Mar 21 2019 at 14:53, on Zulip):

hmm, is there an actual name for the "type" part of the where clause, e.g. T in where T: Debug + Clone

matklad (Mar 21 2019 at 14:53, on Zulip):

I'd call it just type_ref

vipentti (Mar 21 2019 at 14:54, on Zulip):

I guess the Debug + Clone is called bounds ?

vipentti (Mar 21 2019 at 14:54, on Zulip):

Yeah, that's what I was thinking

matklad (Mar 21 2019 at 14:54, on Zulip):

yep, thouse are bounds

vipentti (Mar 21 2019 at 15:07, on Zulip):

hmm, can bounds actually be anything other than PathType ? or should they return Option<&TypeRef> as well ?

Last update: Jul 29 2021 at 22:45UTC