(tokens: &mut TokenIter, attributes: Vec<Attribute>)
| 227 | } |
| 228 | |
| 229 | pub(crate) fn parse_impl(tokens: &mut TokenIter, attributes: Vec<Attribute>) -> Impl { |
| 230 | let tk_unsafe = consume_ident(tokens, "unsafe"); |
| 231 | let tk_impl = parse_ident(tokens, "impl", "impl block"); |
| 232 | |
| 233 | let impl_generic_params = consume_generic_params(tokens); |
| 234 | let trait_or_self_ty = consume_stuff_until( |
| 235 | tokens, |
| 236 | |tk| match tk { |
| 237 | TokenTree::Group(group) if group.delimiter() == Delimiter::Brace => true, |
| 238 | TokenTree::Ident(ident) if ident == "for" || ident == "where" => true, |
| 239 | _ => false, |
| 240 | }, |
| 241 | true, |
| 242 | ); |
| 243 | |
| 244 | let (tk_for, trait_ty, self_ty) = if let Some(tk_for) = consume_ident(tokens, "for") { |
| 245 | let self_ty = consume_stuff_until( |
| 246 | tokens, |
| 247 | |tk| match tk { |
| 248 | TokenTree::Group(group) if group.delimiter() == Delimiter::Brace => true, |
| 249 | TokenTree::Ident(ident) if ident == "where" => true, |
| 250 | _ => false, |
| 251 | }, |
| 252 | true, |
| 253 | ); |
| 254 | |
| 255 | ( |
| 256 | Some(tk_for), |
| 257 | Some(TypeExpr { |
| 258 | tokens: trait_or_self_ty, |
| 259 | }), |
| 260 | TypeExpr { tokens: self_ty }, |
| 261 | ) |
| 262 | } else { |
| 263 | ( |
| 264 | None, |
| 265 | None, |
| 266 | TypeExpr { |
| 267 | tokens: trait_or_self_ty, |
| 268 | }, |
| 269 | ) |
| 270 | }; |
| 271 | |
| 272 | let where_clause = consume_where_clause(tokens); |
| 273 | |
| 274 | let (tk_braces, inner_attributes, body_items) = match tokens.next().unwrap() { |
| 275 | TokenTree::Group(group) if group.delimiter() == Delimiter::Brace => { |
| 276 | parse_impl_body(group, false) |
| 277 | } |
| 278 | token => panic!("cannot parse impl: unexpected token {:?}", token), |
| 279 | }; |
| 280 | |
| 281 | Impl { |
| 282 | attributes, |
| 283 | tk_unsafe, |
| 284 | tk_impl, |
| 285 | impl_generic_params, |
| 286 | trait_ty, |
no test coverage detected