@@ -438,7 +438,9 @@ Early::finalize_rebind_import (const Early::ImportPair &mapping)
438
438
// We don't want to insert `self` with `use module::self`
439
439
if (path.get_final_segment ().is_lower_self_seg ())
440
440
{
441
- rust_assert (segments.size () > 1 );
441
+ // Erroneous `self` or `{self}` use declaration
442
+ if (segments.size () == 1 )
443
+ break ;
442
444
declared_name = segments[segments.size () - 2 ].as_string ();
443
445
}
444
446
else
@@ -469,7 +471,6 @@ Early::visit (AST::UseDeclaration &decl)
469
471
collect_error (
470
472
Error (decl.get_locus (), ErrorCode::E0429 ,
471
473
" %<self%> imports are only allowed within a { } list" ));
472
- return ;
473
474
}
474
475
}
475
476
@@ -498,5 +499,31 @@ Early::visit (AST::UseDeclaration &decl)
498
499
DefaultResolver::visit (decl);
499
500
}
500
501
502
+ void
503
+ Early::visit (AST::UseTreeList &use_list)
504
+ {
505
+ if (!use_list.has_path ())
506
+ {
507
+ for (auto &&tree : use_list.get_trees ())
508
+ {
509
+ if (tree->get_kind () == AST::UseTree::Kind::Rebind)
510
+ {
511
+ auto &rebind = static_cast <AST::UseTreeRebind &> (*tree);
512
+ auto path_size = rebind.get_path ().get_segments ().size ();
513
+ if (path_size == 1
514
+ && rebind.get_path ()
515
+ .get_final_segment ()
516
+ .is_lower_self_seg ())
517
+ {
518
+ collect_error (Error (rebind.get_locus (), ErrorCode::E0431 ,
519
+ " %<self%> import can only appear in an "
520
+ " import list with a non-empty prefix" ));
521
+ }
522
+ }
523
+ }
524
+ }
525
+ DefaultResolver::visit (use_list);
526
+ }
527
+
501
528
} // namespace Resolver2_0
502
529
} // namespace Rust
0 commit comments