@@ -448,20 +448,22 @@ Late::visit_impl_type (AST::Type &type)
448
448
block_big_self = false ;
449
449
}
450
450
451
- void
452
- Late::visit (AST::TypePath &type)
451
+ template <typename P>
452
+ static void
453
+ resolve_type_path_like (NameResolutionContext &ctx, bool block_big_self,
454
+ P &type)
453
455
{
454
456
// should we add type path resolution in `ForeverStack` directly? Since it's
455
457
// quite more complicated.
456
458
// maybe we can overload `resolve_path<Namespace::Types>` to only do
457
459
// typepath-like path resolution? that sounds good
458
460
459
- DefaultResolver::visit (type);
460
-
461
461
// prevent "impl Self {}" and similar
462
462
if (type.get_segments ().size () == 1
463
- && !type.get_segments ().front ()->is_lang_item ()
464
- && type.get_segments ().front ()->is_big_self_seg () && block_big_self)
463
+ && !unwrap_segment_get_lang_item (type.get_segments ().front ())
464
+ .has_value ()
465
+ && unwrap_type_segment (type.get_segments ().front ()).is_big_self_seg ()
466
+ && block_big_self)
465
467
{
466
468
rust_error_at (type.get_locus (),
467
469
" %<Self%> is not valid in the self type of an impl block" );
@@ -474,17 +476,17 @@ Late::visit (AST::TypePath &type)
474
476
475
477
if (!resolved.has_value ())
476
478
{
477
- if (!ctx.lookup (type.get_segments ().front ()-> get_node_id ( )))
479
+ if (!ctx.lookup (unwrap_segment_node_id ( type.get_segments ().front ())))
478
480
rust_error_at (type.get_locus (), ErrorCode::E0412 ,
479
481
" could not resolve type path %qs" ,
480
- type. make_debug_string ( ).c_str ());
482
+ unwrap_segment_error_string (type ).c_str ());
481
483
return ;
482
484
}
483
485
484
486
if (resolved->is_ambiguous ())
485
487
{
486
488
rust_error_at (type.get_locus (), ErrorCode::E0659 , " %qs is ambiguous" ,
487
- type. make_debug_string ( ).c_str ());
489
+ unwrap_segment_error_string (type ).c_str ());
488
490
return ;
489
491
}
490
492
@@ -500,6 +502,14 @@ Late::visit (AST::TypePath &type)
500
502
Definition (resolved->get_node_id ()));
501
503
}
502
504
505
+ void
506
+ Late::visit (AST::TypePath &type)
507
+ {
508
+ DefaultResolver::visit (type);
509
+
510
+ resolve_type_path_like (ctx, block_big_self, type);
511
+ }
512
+
503
513
void
504
514
Late::visit (AST::Visibility &vis)
505
515
{
@@ -576,10 +586,7 @@ Late::visit (AST::StructExprStruct &s)
576
586
visit_inner_attrs (s);
577
587
DefaultResolver::visit (s.get_struct_name ());
578
588
579
- auto resolved = ctx.resolve_path (s.get_struct_name (), Namespace::Types);
580
-
581
- ctx.map_usage (Usage (s.get_struct_name ().get_node_id ()),
582
- Definition (resolved->get_node_id ()));
589
+ resolve_type_path_like (ctx, block_big_self, s.get_struct_name ());
583
590
}
584
591
585
592
void
@@ -590,10 +597,7 @@ Late::visit (AST::StructExprStructBase &s)
590
597
DefaultResolver::visit (s.get_struct_name ());
591
598
visit (s.get_struct_base ());
592
599
593
- auto resolved = ctx.resolve_path (s.get_struct_name (), Namespace::Types);
594
-
595
- ctx.map_usage (Usage (s.get_struct_name ().get_node_id ()),
596
- Definition (resolved->get_node_id ()));
600
+ resolve_type_path_like (ctx, block_big_self, s.get_struct_name ());
597
601
}
598
602
599
603
void
@@ -607,10 +611,7 @@ Late::visit (AST::StructExprStructFields &s)
607
611
for (auto &field : s.get_fields ())
608
612
visit (field);
609
613
610
- auto resolved = ctx.resolve_path (s.get_struct_name (), Namespace::Types);
611
-
612
- ctx.map_usage (Usage (s.get_struct_name ().get_node_id ()),
613
- Definition (resolved->get_node_id ()));
614
+ resolve_type_path_like (ctx, block_big_self, s.get_struct_name ());
614
615
}
615
616
616
617
// needed because Late::visit (AST::GenericArg &) is non-virtual
0 commit comments