]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/ast_util.rs
auto merge of #13711 : alexcrichton/rust/snapshots, r=brson
[rust.git] / src / libsyntax / ast_util.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use ast::*;
12 use ast;
13 use ast_util;
14 use codemap;
15 use codemap::Span;
16 use owned_slice::OwnedSlice;
17 use parse::token;
18 use print::pprust;
19 use visit::Visitor;
20 use visit;
21
22 use std::cell::Cell;
23 use std::cmp;
24 use std::strbuf::StrBuf;
25 use std::u32;
26
27 pub fn path_name_i(idents: &[Ident]) -> ~str {
28     // FIXME: Bad copies (#2543 -- same for everything else that says "bad")
29     idents.iter().map(|i| {
30         token::get_ident(*i).get().to_str()
31     }).collect::<Vec<~str>>().connect("::")
32 }
33
34 // totally scary function: ignores all but the last element, should have
35 // a different name
36 pub fn path_to_ident(path: &Path) -> Ident {
37     path.segments.last().unwrap().identifier
38 }
39
40 pub fn local_def(id: NodeId) -> DefId {
41     ast::DefId { krate: LOCAL_CRATE, node: id }
42 }
43
44 pub fn is_local(did: ast::DefId) -> bool { did.krate == LOCAL_CRATE }
45
46 pub fn stmt_id(s: &Stmt) -> NodeId {
47     match s.node {
48       StmtDecl(_, id) => id,
49       StmtExpr(_, id) => id,
50       StmtSemi(_, id) => id,
51       StmtMac(..) => fail!("attempted to analyze unexpanded stmt")
52     }
53 }
54
55 pub fn variant_def_ids(d: Def) -> Option<(DefId, DefId)> {
56     match d {
57       DefVariant(enum_id, var_id, _) => {
58           Some((enum_id, var_id))
59       }
60       _ => None
61     }
62 }
63
64 pub fn def_id_of_def(d: Def) -> DefId {
65     match d {
66         DefFn(id, _) | DefStaticMethod(id, _, _) | DefMod(id) |
67         DefForeignMod(id) | DefStatic(id, _) |
68         DefVariant(_, id, _) | DefTy(id) | DefTyParam(id, _) |
69         DefUse(id) | DefStruct(id) | DefTrait(id) | DefMethod(id, _) => {
70             id
71         }
72         DefArg(id, _) | DefLocal(id, _) | DefSelfTy(id)
73         | DefUpvar(id, _, _, _) | DefBinding(id, _) | DefRegion(id)
74         | DefTyParamBinder(id) | DefLabel(id) => {
75             local_def(id)
76         }
77
78         DefPrimTy(_) => fail!()
79     }
80 }
81
82 pub fn binop_to_str(op: BinOp) -> &'static str {
83     match op {
84         BiAdd => "+",
85         BiSub => "-",
86         BiMul => "*",
87         BiDiv => "/",
88         BiRem => "%",
89         BiAnd => "&&",
90         BiOr => "||",
91         BiBitXor => "^",
92         BiBitAnd => "&",
93         BiBitOr => "|",
94         BiShl => "<<",
95         BiShr => ">>",
96         BiEq => "==",
97         BiLt => "<",
98         BiLe => "<=",
99         BiNe => "!=",
100         BiGe => ">=",
101         BiGt => ">"
102     }
103 }
104
105 pub fn lazy_binop(b: BinOp) -> bool {
106     match b {
107       BiAnd => true,
108       BiOr => true,
109       _ => false
110     }
111 }
112
113 pub fn is_shift_binop(b: BinOp) -> bool {
114     match b {
115       BiShl => true,
116       BiShr => true,
117       _ => false
118     }
119 }
120
121 pub fn unop_to_str(op: UnOp) -> &'static str {
122     match op {
123       UnBox => "@",
124       UnUniq => "~",
125       UnDeref => "*",
126       UnNot => "!",
127       UnNeg => "-",
128     }
129 }
130
131 pub fn is_path(e: @Expr) -> bool {
132     return match e.node { ExprPath(_) => true, _ => false };
133 }
134
135 // Get a string representation of a signed int type, with its value.
136 // We want to avoid "45int" and "-3int" in favor of "45" and "-3"
137 pub fn int_ty_to_str(t: IntTy, val: Option<i64>) -> ~str {
138     let s = match t {
139         TyI if val.is_some() => "",
140         TyI => "int",
141         TyI8 => "i8",
142         TyI16 => "i16",
143         TyI32 => "i32",
144         TyI64 => "i64"
145     };
146
147     match val {
148         Some(n) => format!("{}{}", n, s),
149         None => s.to_owned()
150     }
151 }
152
153 pub fn int_ty_max(t: IntTy) -> u64 {
154     match t {
155         TyI8 => 0x80u64,
156         TyI16 => 0x8000u64,
157         TyI | TyI32 => 0x80000000u64, // actually ni about TyI
158         TyI64 => 0x8000000000000000u64
159     }
160 }
161
162 // Get a string representation of an unsigned int type, with its value.
163 // We want to avoid "42uint" in favor of "42u"
164 pub fn uint_ty_to_str(t: UintTy, val: Option<u64>) -> ~str {
165     let s = match t {
166         TyU if val.is_some() => "u",
167         TyU => "uint",
168         TyU8 => "u8",
169         TyU16 => "u16",
170         TyU32 => "u32",
171         TyU64 => "u64"
172     };
173
174     match val {
175         Some(n) => format!("{}{}", n, s),
176         None => s.to_owned()
177     }
178 }
179
180 pub fn uint_ty_max(t: UintTy) -> u64 {
181     match t {
182         TyU8 => 0xffu64,
183         TyU16 => 0xffffu64,
184         TyU | TyU32 => 0xffffffffu64, // actually ni about TyU
185         TyU64 => 0xffffffffffffffffu64
186     }
187 }
188
189 pub fn float_ty_to_str(t: FloatTy) -> ~str {
190     match t { TyF32 => "f32".to_owned(), TyF64 => "f64".to_owned(), TyF128 => "f128".to_owned() }
191 }
192
193 pub fn is_call_expr(e: @Expr) -> bool {
194     match e.node { ExprCall(..) => true, _ => false }
195 }
196
197 pub fn block_from_expr(e: @Expr) -> P<Block> {
198     P(Block {
199         view_items: Vec::new(),
200         stmts: Vec::new(),
201         expr: Some(e),
202         id: e.id,
203         rules: DefaultBlock,
204         span: e.span
205     })
206 }
207
208 pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
209     ast::Path {
210         span: s,
211         global: false,
212         segments: vec!(
213             ast::PathSegment {
214                 identifier: identifier,
215                 lifetimes: Vec::new(),
216                 types: OwnedSlice::empty(),
217             }
218         ),
219     }
220 }
221
222 pub fn ident_to_pat(id: NodeId, s: Span, i: Ident) -> @Pat {
223     @ast::Pat { id: id,
224                 node: PatIdent(BindByValue(MutImmutable), ident_to_path(s, i), None),
225                 span: s }
226 }
227
228 pub fn name_to_dummy_lifetime(name: Name) -> Lifetime {
229     Lifetime { id: DUMMY_NODE_ID,
230                span: codemap::DUMMY_SP,
231                name: name }
232 }
233
234 pub fn is_unguarded(a: &Arm) -> bool {
235     match a.guard {
236       None => true,
237       _    => false
238     }
239 }
240
241 pub fn unguarded_pat(a: &Arm) -> Option<Vec<@Pat> > {
242     if is_unguarded(a) {
243         Some(/* FIXME (#2543) */ a.pats.clone())
244     } else {
245         None
246     }
247 }
248
249 /// Generate a "pretty" name for an `impl` from its type and trait.
250 /// This is designed so that symbols of `impl`'d methods give some
251 /// hint of where they came from, (previously they would all just be
252 /// listed as `__extensions__::method_name::hash`, with no indication
253 /// of the type).
254 pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: &Ty) -> Ident {
255     let mut pretty = StrBuf::from_owned_str(pprust::ty_to_str(ty));
256     match *trait_ref {
257         Some(ref trait_ref) => {
258             pretty.push_char('.');
259             pretty.push_str(pprust::path_to_str(&trait_ref.path));
260         }
261         None => {}
262     }
263     token::gensym_ident(pretty.as_slice())
264 }
265
266 pub fn public_methods(ms: Vec<@Method> ) -> Vec<@Method> {
267     ms.move_iter().filter(|m| {
268         match m.vis {
269             Public => true,
270             _   => false
271         }
272     }).collect()
273 }
274
275 // extract a TypeMethod from a TraitMethod. if the TraitMethod is
276 // a default, pull out the useful fields to make a TypeMethod
277 pub fn trait_method_to_ty_method(method: &TraitMethod) -> TypeMethod {
278     match *method {
279         Required(ref m) => (*m).clone(),
280         Provided(ref m) => {
281             TypeMethod {
282                 ident: m.ident,
283                 attrs: m.attrs.clone(),
284                 fn_style: m.fn_style,
285                 decl: m.decl,
286                 generics: m.generics.clone(),
287                 explicit_self: m.explicit_self,
288                 id: m.id,
289                 span: m.span,
290             }
291         }
292     }
293 }
294
295 pub fn split_trait_methods(trait_methods: &[TraitMethod])
296     -> (Vec<TypeMethod> , Vec<@Method> ) {
297     let mut reqd = Vec::new();
298     let mut provd = Vec::new();
299     for trt_method in trait_methods.iter() {
300         match *trt_method {
301             Required(ref tm) => reqd.push((*tm).clone()),
302             Provided(m) => provd.push(m)
303         }
304     };
305     (reqd, provd)
306 }
307
308 pub fn struct_field_visibility(field: ast::StructField) -> Visibility {
309     match field.node.kind {
310         ast::NamedField(_, v) | ast::UnnamedField(v) => v
311     }
312 }
313
314 /// Maps a binary operator to its precedence
315 pub fn operator_prec(op: ast::BinOp) -> uint {
316   match op {
317       // 'as' sits here with 12
318       BiMul | BiDiv | BiRem     => 11u,
319       BiAdd | BiSub             => 10u,
320       BiShl | BiShr             =>  9u,
321       BiBitAnd                  =>  8u,
322       BiBitXor                  =>  7u,
323       BiBitOr                   =>  6u,
324       BiLt | BiLe | BiGe | BiGt =>  4u,
325       BiEq | BiNe               =>  3u,
326       BiAnd                     =>  2u,
327       BiOr                      =>  1u
328   }
329 }
330
331 /// Precedence of the `as` operator, which is a binary operator
332 /// not appearing in the prior table.
333 pub static as_prec: uint = 12u;
334
335 pub fn empty_generics() -> Generics {
336     Generics {lifetimes: Vec::new(),
337               ty_params: OwnedSlice::empty()}
338 }
339
340 // ______________________________________________________________________
341 // Enumerating the IDs which appear in an AST
342
343 #[deriving(Encodable, Decodable)]
344 pub struct IdRange {
345     pub min: NodeId,
346     pub max: NodeId,
347 }
348
349 impl IdRange {
350     pub fn max() -> IdRange {
351         IdRange {
352             min: u32::MAX,
353             max: u32::MIN,
354         }
355     }
356
357     pub fn empty(&self) -> bool {
358         self.min >= self.max
359     }
360
361     pub fn add(&mut self, id: NodeId) {
362         self.min = cmp::min(self.min, id);
363         self.max = cmp::max(self.max, id + 1);
364     }
365 }
366
367 pub trait IdVisitingOperation {
368     fn visit_id(&self, node_id: NodeId);
369 }
370
371 pub struct IdVisitor<'a, O> {
372     pub operation: &'a O,
373     pub pass_through_items: bool,
374     pub visited_outermost: bool,
375 }
376
377 impl<'a, O: IdVisitingOperation> IdVisitor<'a, O> {
378     fn visit_generics_helper(&self, generics: &Generics) {
379         for type_parameter in generics.ty_params.iter() {
380             self.operation.visit_id(type_parameter.id)
381         }
382         for lifetime in generics.lifetimes.iter() {
383             self.operation.visit_id(lifetime.id)
384         }
385     }
386 }
387
388 impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
389     fn visit_mod(&mut self,
390                  module: &Mod,
391                  _: Span,
392                  node_id: NodeId,
393                  env: ()) {
394         self.operation.visit_id(node_id);
395         visit::walk_mod(self, module, env)
396     }
397
398     fn visit_view_item(&mut self, view_item: &ViewItem, env: ()) {
399         if !self.pass_through_items {
400             if self.visited_outermost {
401                 return;
402             } else {
403                 self.visited_outermost = true;
404             }
405         }
406         match view_item.node {
407             ViewItemExternCrate(_, _, node_id) => {
408                 self.operation.visit_id(node_id)
409             }
410             ViewItemUse(ref view_paths) => {
411                 for view_path in view_paths.iter() {
412                     match view_path.node {
413                         ViewPathSimple(_, _, node_id) |
414                         ViewPathGlob(_, node_id) => {
415                             self.operation.visit_id(node_id)
416                         }
417                         ViewPathList(_, ref paths, node_id) => {
418                             self.operation.visit_id(node_id);
419                             for path in paths.iter() {
420                                 self.operation.visit_id(path.node.id)
421                             }
422                         }
423                     }
424                 }
425             }
426         }
427         visit::walk_view_item(self, view_item, env);
428         self.visited_outermost = false;
429     }
430
431     fn visit_foreign_item(&mut self, foreign_item: &ForeignItem, env: ()) {
432         self.operation.visit_id(foreign_item.id);
433         visit::walk_foreign_item(self, foreign_item, env)
434     }
435
436     fn visit_item(&mut self, item: &Item, env: ()) {
437         if !self.pass_through_items {
438             if self.visited_outermost {
439                 return
440             } else {
441                 self.visited_outermost = true
442             }
443         }
444
445         self.operation.visit_id(item.id);
446         match item.node {
447             ItemEnum(ref enum_definition, _) => {
448                 for variant in enum_definition.variants.iter() {
449                     self.operation.visit_id(variant.node.id)
450                 }
451             }
452             _ => {}
453         }
454
455         visit::walk_item(self, item, env);
456
457         self.visited_outermost = false
458     }
459
460     fn visit_local(&mut self, local: &Local, env: ()) {
461         self.operation.visit_id(local.id);
462         visit::walk_local(self, local, env)
463     }
464
465     fn visit_block(&mut self, block: &Block, env: ()) {
466         self.operation.visit_id(block.id);
467         visit::walk_block(self, block, env)
468     }
469
470     fn visit_stmt(&mut self, statement: &Stmt, env: ()) {
471         self.operation.visit_id(ast_util::stmt_id(statement));
472         visit::walk_stmt(self, statement, env)
473     }
474
475     fn visit_pat(&mut self, pattern: &Pat, env: ()) {
476         self.operation.visit_id(pattern.id);
477         visit::walk_pat(self, pattern, env)
478     }
479
480
481     fn visit_expr(&mut self, expression: &Expr, env: ()) {
482         self.operation.visit_id(expression.id);
483         visit::walk_expr(self, expression, env)
484     }
485
486     fn visit_ty(&mut self, typ: &Ty, env: ()) {
487         self.operation.visit_id(typ.id);
488         match typ.node {
489             TyPath(_, _, id) => self.operation.visit_id(id),
490             _ => {}
491         }
492         visit::walk_ty(self, typ, env)
493     }
494
495     fn visit_generics(&mut self, generics: &Generics, env: ()) {
496         self.visit_generics_helper(generics);
497         visit::walk_generics(self, generics, env)
498     }
499
500     fn visit_fn(&mut self,
501                 function_kind: &visit::FnKind,
502                 function_declaration: &FnDecl,
503                 block: &Block,
504                 span: Span,
505                 node_id: NodeId,
506                 env: ()) {
507         if !self.pass_through_items {
508             match *function_kind {
509                 visit::FkMethod(..) if self.visited_outermost => return,
510                 visit::FkMethod(..) => self.visited_outermost = true,
511                 _ => {}
512             }
513         }
514
515         self.operation.visit_id(node_id);
516
517         match *function_kind {
518             visit::FkItemFn(_, generics, _, _) |
519             visit::FkMethod(_, generics, _) => {
520                 self.visit_generics_helper(generics)
521             }
522             visit::FkFnBlock => {}
523         }
524
525         for argument in function_declaration.inputs.iter() {
526             self.operation.visit_id(argument.id)
527         }
528
529         visit::walk_fn(self,
530                         function_kind,
531                         function_declaration,
532                         block,
533                         span,
534                         node_id,
535                         env);
536
537         if !self.pass_through_items {
538             match *function_kind {
539                 visit::FkMethod(..) => self.visited_outermost = false,
540                 _ => {}
541             }
542         }
543     }
544
545     fn visit_struct_field(&mut self, struct_field: &StructField, env: ()) {
546         self.operation.visit_id(struct_field.node.id);
547         visit::walk_struct_field(self, struct_field, env)
548     }
549
550     fn visit_struct_def(&mut self,
551                         struct_def: &StructDef,
552                         ident: ast::Ident,
553                         generics: &ast::Generics,
554                         id: NodeId,
555                         _: ()) {
556         self.operation.visit_id(id);
557         struct_def.ctor_id.map(|ctor_id| self.operation.visit_id(ctor_id));
558         visit::walk_struct_def(self, struct_def, ident, generics, id, ());
559     }
560
561     fn visit_trait_method(&mut self, tm: &ast::TraitMethod, _: ()) {
562         match *tm {
563             ast::Required(ref m) => self.operation.visit_id(m.id),
564             ast::Provided(ref m) => self.operation.visit_id(m.id),
565         }
566         visit::walk_trait_method(self, tm, ());
567     }
568 }
569
570 pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &InlinedItem,
571                                                           operation: &O) {
572     let mut id_visitor = IdVisitor {
573         operation: operation,
574         pass_through_items: true,
575         visited_outermost: false,
576     };
577
578     visit::walk_inlined_item(&mut id_visitor, item, ());
579 }
580
581 struct IdRangeComputingVisitor {
582     result: Cell<IdRange>,
583 }
584
585 impl IdVisitingOperation for IdRangeComputingVisitor {
586     fn visit_id(&self, id: NodeId) {
587         let mut id_range = self.result.get();
588         id_range.add(id);
589         self.result.set(id_range)
590     }
591 }
592
593 pub fn compute_id_range_for_inlined_item(item: &InlinedItem) -> IdRange {
594     let visitor = IdRangeComputingVisitor {
595         result: Cell::new(IdRange::max())
596     };
597     visit_ids_for_inlined_item(item, &visitor);
598     visitor.result.get()
599 }
600
601 pub fn is_item_impl(item: @ast::Item) -> bool {
602     match item.node {
603         ItemImpl(..) => true,
604         _            => false
605     }
606 }
607
608 pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool {
609     if !it(pat) {
610         return false;
611     }
612
613     match pat.node {
614         PatIdent(_, _, Some(p)) => walk_pat(p, it),
615         PatStruct(_, ref fields, _) => {
616             fields.iter().advance(|f| walk_pat(f.pat, |p| it(p)))
617         }
618         PatEnum(_, Some(ref s)) | PatTup(ref s) => {
619             s.iter().advance(|&p| walk_pat(p, |p| it(p)))
620         }
621         PatUniq(s) | PatRegion(s) => {
622             walk_pat(s, it)
623         }
624         PatVec(ref before, ref slice, ref after) => {
625             before.iter().advance(|&p| walk_pat(p, |p| it(p))) &&
626                 slice.iter().advance(|&p| walk_pat(p, |p| it(p))) &&
627                 after.iter().advance(|&p| walk_pat(p, |p| it(p)))
628         }
629         PatWild | PatWildMulti | PatLit(_) | PatRange(_, _) | PatIdent(_, _, _) |
630         PatEnum(_, _) => {
631             true
632         }
633     }
634 }
635
636 pub trait EachViewItem {
637     fn each_view_item(&self, f: |&ast::ViewItem| -> bool) -> bool;
638 }
639
640 struct EachViewItemData<'a> {
641     callback: |&ast::ViewItem|: 'a -> bool,
642 }
643
644 impl<'a> Visitor<()> for EachViewItemData<'a> {
645     fn visit_view_item(&mut self, view_item: &ast::ViewItem, _: ()) {
646         let _ = (self.callback)(view_item);
647     }
648 }
649
650 impl EachViewItem for ast::Crate {
651     fn each_view_item(&self, f: |&ast::ViewItem| -> bool) -> bool {
652         let mut visit = EachViewItemData {
653             callback: f,
654         };
655         visit::walk_crate(&mut visit, self, ());
656         true
657     }
658 }
659
660 pub fn view_path_id(p: &ViewPath) -> NodeId {
661     match p.node {
662         ViewPathSimple(_, _, id) | ViewPathGlob(_, id)
663         | ViewPathList(_, _, id) => id
664     }
665 }
666
667 /// Returns true if the given struct def is tuple-like; i.e. that its fields
668 /// are unnamed.
669 pub fn struct_def_is_tuple_like(struct_def: &ast::StructDef) -> bool {
670     struct_def.ctor_id.is_some()
671 }
672
673 /// Returns true if the given pattern consists solely of an identifier
674 /// and false otherwise.
675 pub fn pat_is_ident(pat: @ast::Pat) -> bool {
676     match pat.node {
677         ast::PatIdent(..) => true,
678         _ => false,
679     }
680 }
681
682 // are two paths equal when compared unhygienically?
683 // since I'm using this to replace ==, it seems appropriate
684 // to compare the span, global, etc. fields as well.
685 pub fn path_name_eq(a : &ast::Path, b : &ast::Path) -> bool {
686     (a.span == b.span)
687     && (a.global == b.global)
688     && (segments_name_eq(a.segments.as_slice(), b.segments.as_slice()))
689 }
690
691 // are two arrays of segments equal when compared unhygienically?
692 pub fn segments_name_eq(a : &[ast::PathSegment], b : &[ast::PathSegment]) -> bool {
693     if a.len() != b.len() {
694         false
695     } else {
696         for (idx,seg) in a.iter().enumerate() {
697             if (seg.identifier.name != b[idx].identifier.name)
698                 // FIXME #7743: ident -> name problems in lifetime comparison?
699                 || (seg.lifetimes != b[idx].lifetimes)
700                 // can types contain idents?
701                 || (seg.types != b[idx].types) {
702                 return false;
703             }
704         }
705         true
706     }
707 }
708
709 // Returns true if this literal is a string and false otherwise.
710 pub fn lit_is_str(lit: @Lit) -> bool {
711     match lit.node {
712         LitStr(..) => true,
713         _ => false,
714     }
715 }
716
717 pub fn get_inner_tys(ty: P<Ty>) -> Vec<P<Ty>> {
718     match ty.node {
719         ast::TyRptr(_, mut_ty) | ast::TyPtr(mut_ty) => {
720             vec!(mut_ty.ty)
721         }
722         ast::TyBox(ty)
723         | ast::TyVec(ty)
724         | ast::TyUniq(ty)
725         | ast::TyFixedLengthVec(ty, _) => vec!(ty),
726         ast::TyTup(ref tys) => tys.clone(),
727         _ => Vec::new()
728     }
729 }
730
731
732 #[cfg(test)]
733 mod test {
734     use ast::*;
735     use super::*;
736     use owned_slice::OwnedSlice;
737
738     fn ident_to_segment(id : &Ident) -> PathSegment {
739         PathSegment {identifier:id.clone(),
740                      lifetimes: Vec::new(),
741                      types: OwnedSlice::empty()}
742     }
743
744     #[test] fn idents_name_eq_test() {
745         assert!(segments_name_eq(
746             [Ident{name:3,ctxt:4}, Ident{name:78,ctxt:82}]
747                 .iter().map(ident_to_segment).collect::<Vec<PathSegment>>().as_slice(),
748             [Ident{name:3,ctxt:104}, Ident{name:78,ctxt:182}]
749                 .iter().map(ident_to_segment).collect::<Vec<PathSegment>>().as_slice()));
750         assert!(!segments_name_eq(
751             [Ident{name:3,ctxt:4}, Ident{name:78,ctxt:82}]
752                 .iter().map(ident_to_segment).collect::<Vec<PathSegment>>().as_slice(),
753             [Ident{name:3,ctxt:104}, Ident{name:77,ctxt:182}]
754                 .iter().map(ident_to_segment).collect::<Vec<PathSegment>>().as_slice()));
755     }
756 }