@@ -2086,8 +2086,11 @@ impl Resolver {
2086
2086
match self . resolve_import_for_module( module_, import_directive) {
2087
2087
Failed => {
2088
2088
// We presumably emitted an error. Continue.
2089
- self . session. span_err( import_directive. span,
2090
- ~"failed to resolve import") ;
2089
+ let idents = import_directive. module_path. get( ) ;
2090
+ let msg = fmt!( "failed to resolve import: %s",
2091
+ self . import_path_to_str( idents,
2092
+ * import_directive. subclass) ) ;
2093
+ self . session. span_err( import_directive. span, msg) ;
2091
2094
}
2092
2095
Indeterminate => {
2093
2096
// Bail out. We'll come around next time.
@@ -2103,20 +2106,29 @@ impl Resolver {
2103
2106
}
2104
2107
2105
2108
fn idents_to_str( idents: ~[ ident] ) -> ~str {
2106
- // XXX: str::connect should do this.
2107
- let mut result = ~"";
2108
- let mut first = true;
2109
- for idents. each( ) |ident| {
2110
- if first {
2111
- first = false ;
2112
- } else {
2113
- result += ~":: ";
2114
- }
2115
- result += self . session. str_of( * ident) ;
2116
- }
2117
- // XXX: Shouldn't copy here. We need string builder functionality.
2118
- return result;
2109
+ let ident_strs = idents. map( |& ident| self . session. str_of( ident) ) ;
2110
+ return str :: connect( ident_strs, ":: ") ;
2119
2111
}
2112
+
2113
+ fn import_directive_subclass_to_str( subclass: ImportDirectiveSubclass )
2114
+ -> ~str {
2115
+ match subclass {
2116
+ SingleImport ( _target, source, _ns) => self . session. str_of( source) ,
2117
+ GlobImport => ~"* "
2118
+ }
2119
+ }
2120
+
2121
+ fn import_path_to_str(idents: ~[ident], subclass: ImportDirectiveSubclass)
2122
+ -> ~str {
2123
+ if idents.is_empty() {
2124
+ self.import_directive_subclass_to_str(subclass)
2125
+ } else {
2126
+ fmt!(" %s:: %s",
2127
+ self . idents_to_str ( idents) ,
2128
+ self . import_directive_subclass_to_str ( subclass) )
2129
+ }
2130
+ }
2131
+
2120
2132
/**
2121
2133
* Attempts to resolve the given import. The return value indicates
2122
2134
* failure if we're certain the name does not exist, indeterminate if we
@@ -4501,17 +4513,14 @@ impl Resolver {
4501
4513
// Write the result into the def map.
4502
4514
debug ! ( "(resolving type) writing resolution for `%s` \
4503
4515
(id %d)",
4504
- connect( path. idents. map(
4505
- |x| self . session. str_of( * x) ) , ~":: ") ,
4516
+ self . idents_to_str( path. idents) ,
4506
4517
path_id) ;
4507
4518
self . record_def( path_id, def) ;
4508
4519
}
4509
4520
None => {
4510
4521
self . session. span_err
4511
4522
( ty. span, fmt ! ( "use of undeclared type name `%s`" ,
4512
- connect( path. idents. map(
4513
- |x| self . session. str_of( * x) ) ,
4514
- ~":: ") ) ) ;
4523
+ self . idents_to_str( path. idents) ) ) ;
4515
4524
}
4516
4525
}
4517
4526
}
@@ -4705,9 +4714,7 @@ impl Resolver {
4705
4714
self . session. span_err(
4706
4715
path. span,
4707
4716
fmt ! ( "`%s` does not name a structure" ,
4708
- connect( path. idents. map(
4709
- |x| self . session. str_of( * x) ) ,
4710
- ~":: ") ) ) ;
4717
+ self . idents_to_str( path. idents) ) ) ;
4711
4718
}
4712
4719
}
4713
4720
}
@@ -5103,14 +5110,11 @@ impl Resolver {
5103
5110
Some ( def) => {
5104
5111
// Write the result into the def map.
5105
5112
debug ! ( "(resolving expr) resolved `%s`" ,
5106
- connect( path. idents. map(
5107
- |x| self . session. str_of( * x) ) , ~":: ") ) ;
5113
+ self . idents_to_str( path. idents) ) ;
5108
5114
self . record_def( expr. id, def) ;
5109
5115
}
5110
5116
None => {
5111
- let wrong_name =
5112
- connect( path. idents. map(
5113
- |x| self . session. str_of( * x) ) , ~":: ") ;
5117
+ let wrong_name = self . idents_to_str( path. idents) ;
5114
5118
if self . name_exists_in_scope_struct( wrong_name) {
5115
5119
self . session. span_err( expr. span,
5116
5120
fmt ! ( "unresolved name: `%s`. \
@@ -5170,9 +5174,7 @@ impl Resolver {
5170
5174
self . session. span_err(
5171
5175
path. span,
5172
5176
fmt ! ( "`%s` does not name a structure" ,
5173
- connect( path. idents. map(
5174
- |x| self . session. str_of( * x) ) ,
5175
- ~":: ") ) ) ;
5177
+ self . idents_to_str( path. idents) ) ) ;
5176
5178
}
5177
5179
}
5178
5180
@@ -5491,7 +5493,7 @@ impl Resolver {
5491
5493
// hit.
5492
5494
//
5493
5495
5494
- /// A somewhat inefficient routine to print out the name of a module.
5496
+ /// A somewhat inefficient routine to obtain the name of a module.
5495
5497
fn module_to_str( module_: @Module ) -> ~str {
5496
5498
let idents = DVec ( ) ;
5497
5499
let mut current_module = module_;
@@ -5514,22 +5516,7 @@ impl Resolver {
5514
5516
if idents. len( ) == 0 {
5515
5517
return ~"???";
5516
5518
}
5517
-
5518
- let mut string = ~"";
5519
- let mut i = idents. len( ) - 1 ;
5520
- loop {
5521
- if i < idents. len( ) - 1 {
5522
- string += ~":: ";
5523
- }
5524
- string += self . session. str_of( idents. get_elt( i) ) ;
5525
-
5526
- if i == 0 {
5527
- break ;
5528
- }
5529
- i -= 1 ;
5530
- }
5531
-
5532
- return string;
5519
+ return self . idents_to_str( vec:: reversed( idents. get( ) ) ) ;
5533
5520
}
5534
5521
5535
5522
fn dump_module( module_: @Module ) {
0 commit comments