fn parse_trait_def(&mut self, attrs: Vec<Located<Attr>>) -> PResult<Located<Def>> {
        located_ok!(self, {
            consume_without_check!(self, Token::Trait);

            let (mode_given, elements) = self.parse_mixfix_elements()?;
            let opt_guard = self.parse_opt_guard()?;

            let mut has_name = false;

            for element in &elements {
                match element {
                    MixfixParam::Name(_) => { has_name = true; },
                    _ => {},
                }
            }

            let params = Parser::make_params(&elements);

            if ! has_name {
                return self.error_here("Missing struct name.")
            }

            if mode_given {
                return self.error_here("A struct cannot have attribute modes.")
            }

            for p in &params {
                if p.attr.mode == CallingMode::Output {
                    return self.error_here("A struct cannot have output attributes.")
                }
            }

            // We have a valid struct definition.
            let name = Parser::make_mixfix_name(&elements);

            let id = self.alloc_node_id();

            let mut supers = vec![];

            while let Token::With = *self.lookahead()? {
                self.eat();
                let s = self.parse_primary()?;
                match s {
                    Located { loc, value: Exp::Tuple { es } } => {
                        for e in es {
                            supers.push(e);
                        }
                    },
                    Located { loc, value: Exp::Union { box e1, box e2 } } => {
                        supers.push(e1);
                        supers.push(e2);
                    },
                    e => {
                        supers.push(e);
                    }
                }
            }

            let defs = match *self.lookahead()? {
                Token::Eq => {
                    self.eat();

                    let loc = self.lookahead()?.loc;

                    let cmds = self.parse_block()?;

                    for cmd in &cmds {
                        match **cmd {
                            Cmd::Exp(_) => {
                                return self.error_here("A struct block cannot contain expressions.")
                            },
                            _ => {},
                        }
                    }

                    filter_collect_loc!(cmds, Cmd::Def(d), d)
                },
                _ => {
                    vec![]
                }
            };

            Ok(Def::TraitDef {
                id,
                attrs,
                name,
                opt_guard: opt_guard.map(|e| box e),
                params,
                defs: defs,
                supers: supers.clone()
            })
        })
    }
// A trait has a block for a body.
A trait has a block for a body.
A trait has a block for a body .
fn parse_trait_def(&mut self, attrs: Vec<Located<Attr>>) -> PResult<Located<Def>> {
        located_ok!(self, {
            consume_without_check!(self, Token::Trait);
            let (mode_given, elements) = self.parse_mixfix_elements()?;
            let opt_guard = self.parse_opt_guard()?;
            let mut has_name = false;
            for element in &elements {
                match element {
                    MixfixParam::Name(_) => { has_name = true; },
                    _ => {},
                }
            }
            let params = Parser::make_params(&elements);
            if ! has_name {
                return self.error_here("Missing struct name.")
            }
            if mode_given {
                return self.error_here("A struct cannot have attribute modes.")
            }
            for p in &params {
                if p.attr.mode == CallingMode::Output {
                    return self.error_here("A struct cannot have output attributes.")
                }
            }
            // We have a valid struct definition.
            let name = Parser::make_mixfix_name(&elements);
            let id = self.alloc_node_id();
            let mut supers = vec![];
            while let Token::With = *self.lookahead()? {
                self.eat();
                let s = self.parse_primary()?;
                match s {
                    Located { loc, value: Exp::Tuple { es } } => {
                        for e in es {
                            supers.push(e);
                        }
                    },
                    Located { loc, value: Exp::Union { box e1, box e2 } } => {
                        supers.push(e1);
                        supers.push(e2);
                    },
                    e => {
                        supers.push(e);
                    }
                }
            }
            let defs = match *self.lookahead()? {
                Token::Eq => {
                    self.eat();
                    let loc = self.lookahead()?.loc;
                    let cmds = self.parse_block()?;
                    for cmd in &cmds {
                        match **cmd {
                            Cmd::Exp(_) => {
                                return self.error_here("A struct block cannot contain expressions.")
                            },
                            _ => {},
                        }
                    }
                    filter_collect_loc!(cmds, Cmd::Def(d), d)
                },
                _ => {
                    vec![]
                }
            };
            Ok(Def::TraitDef {
                id,
                attrs,
                name,
                opt_guard: opt_guard.map(|e| box e),
                params,
                defs: defs,
                supers: supers.clone()
            })
        })
    }
fn parse_trait_def ( & mut self , attrs : Vec < Located < Attr > > ) -> PResult < Located < Def > > { located_ok ! ( self { consume_without_check ( self Token Trait ) let ( mode_given elements ) self parse_mixfix_elements ( ) let opt_guard self parse_opt_guard ( ) let mut has_name false for element in elements { match element { MixfixParam Name ( ) { has_name true } { } } } let params Parser make_params ( elements ) if has_name { return self error_here ( " " ) } if mode_given { return self error_here ( " " ) } for p in params { if p attr mode CallingMode Output { return self error_here ( " " ) } } // We have a valid struct definition. let name Parser make_mixfix_name ( elements ) let id self alloc_node_id ( ) let mut supers vec [ ] while let Token With self lookahead ( ) { self eat ( ) let s self parse_primary ( ) match s { Located { loc value Exp Tuple { es } } { for e in es { supers push ( e ) } } Located { loc value Exp Union { box e1 box e2 } } { supers push ( e1 ) supers push ( e2 ) } e { supers push ( e ) } } } let defs match self lookahead ( ) { Token Eq { self eat ( ) let loc self lookahead ( ) loc let cmds self parse_block ( ) for cmd in cmds { match cmd { Cmd Exp ( ) { return self error_here ( " " ) } { } } } filter_collect_loc ( cmds Cmd Def ( d ) d ) } { vec [ ] } } Ok ( Def TraitDef { id attrs name opt_guard opt_guard map ( e box e ) params defs defs supers supers clone ( ) } ) } ) }
A trait has a block for a body.
A trait has a block for a body .
&mut self
attrs
Vec<Located<Attr>>
&mut self
attrs
Vec<Located<Attr>>