@@ -1455,29 +1455,20 @@ impl<'a> Resolver<'a> {
14551455 // Extract and intern the module part of the path. For
14561456 // globs and lists, the path is found directly in the AST;
14571457 // for simple paths we have to munge the path a little.
1458-
1459- let mut module_path = Vec :: new ( ) ;
1460- match view_path. node {
1458+ let module_path = match view_path. node {
14611459 ViewPathSimple ( _, ref full_path, _) => {
1462- let path_len = full_path. segments . len ( ) ;
1463- assert ! ( path_len != 0 ) ;
1464-
1465- for ( i, segment) in full_path. segments
1466- . iter ( )
1467- . enumerate ( ) {
1468- if i != path_len - 1 {
1469- module_path. push ( segment. identifier )
1470- }
1471- }
1460+ full_path. segments
1461+ . as_slice ( ) . init ( )
1462+ . iter ( ) . map ( |ident| ident. identifier )
1463+ . collect ( )
14721464 }
14731465
14741466 ViewPathGlob ( ref module_ident_path, _) |
14751467 ViewPathList ( ref module_ident_path, _, _) => {
1476- for segment in module_ident_path. segments . iter ( ) {
1477- module_path. push ( segment. identifier )
1478- }
1468+ module_ident_path. segments
1469+ . iter ( ) . map ( |ident| ident. identifier ) . collect ( )
14791470 }
1480- }
1471+ } ;
14811472
14821473 // Build up the import directives.
14831474 let module_ = parent. module ( ) ;
@@ -1486,6 +1477,11 @@ impl<'a> Resolver<'a> {
14861477 ViewPathSimple ( binding, ref full_path, id) => {
14871478 let source_ident =
14881479 full_path. segments . last ( ) . unwrap ( ) . identifier ;
1480+ if token:: get_ident ( source_ident) . get ( ) == "mod" {
1481+ self . resolve_error ( view_path. span ,
1482+ "`mod` imports are only allowed within a { } list" ) ;
1483+ }
1484+
14891485 let subclass = SingleImport ( binding,
14901486 source_ident) ;
14911487 self . build_import_directive ( & * module_,
@@ -1495,16 +1491,50 @@ impl<'a> Resolver<'a> {
14951491 id,
14961492 is_public) ;
14971493 }
1498- ViewPathList ( _, ref source_idents, _) => {
1499- for source_ident in source_idents. iter ( ) {
1500- let name = source_ident. node . name ;
1494+ ViewPathList ( _, ref source_items, _) => {
1495+ // Make sure there's at most one `mod` import in the list.
1496+ let mod_spans = source_items. iter ( ) . filter_map ( |item| match item. node {
1497+ PathListMod { .. } => Some ( item. span ) ,
1498+ _ => None
1499+ } ) . collect :: < Vec < Span > > ( ) ;
1500+ match mod_spans. as_slice ( ) {
1501+ [ first, second, ..other] => {
1502+ self . resolve_error ( first,
1503+ "`mod` import can only appear once in the list" ) ;
1504+ self . session . span_note ( second,
1505+ "another `mod` import appears here" ) ;
1506+ for & other_span in other. iter ( ) {
1507+ self . session . span_note ( other_span,
1508+ "another `mod` import appears here" ) ;
1509+ }
1510+ } ,
1511+ [ _] | [ ] => ( )
1512+ }
1513+
1514+ for source_item in source_items. iter ( ) {
1515+ let ( module_path, name) = match source_item. node {
1516+ PathListIdent { name, .. } =>
1517+ ( module_path. clone ( ) , name) ,
1518+ PathListMod { .. } => {
1519+ let name = match module_path. last ( ) {
1520+ Some ( ident) => ident. clone ( ) ,
1521+ None => {
1522+ self . resolve_error ( source_item. span ,
1523+ "`mod` import can only appear in an import list \
1524+ with a non-empty prefix") ;
1525+ continue ;
1526+ }
1527+ } ;
1528+ let module_path = module_path. as_slice ( ) . init ( ) ;
1529+ ( Vec :: from_slice ( module_path) , name)
1530+ }
1531+ } ;
15011532 self . build_import_directive (
15021533 & * module_,
1503- module_path. clone ( ) ,
1534+ module_path,
15041535 SingleImport ( name, name) ,
1505- source_ident. span ,
1506- source_ident. node . id ,
1507- is_public) ;
1536+ source_item. span ,
1537+ source_item. node . id ( ) , is_public) ;
15081538 }
15091539 }
15101540 ViewPathGlob ( _, id) => {
@@ -5492,7 +5522,7 @@ impl<'a> Resolver<'a> {
54925522 ViewPathSimple ( _, _, id) => self . finalize_import ( id, p. span ) ,
54935523 ViewPathList ( _, ref list, _) => {
54945524 for i in list. iter ( ) {
5495- self . finalize_import ( i. node . id , i. span ) ;
5525+ self . finalize_import ( i. node . id ( ) , i. span ) ;
54965526 }
54975527 } ,
54985528 ViewPathGlob ( _, id) => {
0 commit comments