@@ -438,7 +438,9 @@ Early::finalize_rebind_import (const Early::ImportPair &mapping)
438438 // We don't want to insert `self` with `use module::self`
439439 if (path.get_final_segment ().is_lower_self_seg ())
440440 {
441- rust_assert (segments.size () > 1 );
441+ // Erroneous `self` or `{self}` use declaration
442+ if (segments.size () == 1 )
443+ break ;
442444 declared_name = segments[segments.size () - 2 ].as_string ();
443445 }
444446 else
@@ -469,7 +471,6 @@ Early::visit (AST::UseDeclaration &decl)
469471 collect_error (
470472 Error (decl.get_locus (), ErrorCode::E0429 ,
471473 " %<self%> imports are only allowed within a { } list" ));
472- return ;
473474 }
474475 }
475476
@@ -498,5 +499,31 @@ Early::visit (AST::UseDeclaration &decl)
498499 DefaultResolver::visit (decl);
499500}
500501
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+
501528} // namespace Resolver2_0
502529} // namespace Rust
0 commit comments