@@ -392,17 +392,19 @@ pub struct ImportResolution {
392
392
/// The type that this `use` directive names, if there is one.
393
393
mut type_target: Option<Target>,
394
394
395
- mut used: bool,
395
+ /// There exists one state per import statement
396
+ state: @mut ImportState,
396
397
}
397
398
398
- pub fn ImportResolution(privacy: Privacy, span: span) -> ImportResolution {
399
+ pub fn ImportResolution(privacy: Privacy, span: span,
400
+ state: @mut ImportState) -> ImportResolution {
399
401
ImportResolution {
400
402
privacy: privacy,
401
403
span: span,
402
404
outstanding_references: 0,
403
405
value_target: None,
404
406
type_target: None,
405
- used: false
407
+ state: state,
406
408
}
407
409
}
408
410
@@ -415,6 +417,15 @@ pub impl ImportResolution {
415
417
}
416
418
}
417
419
420
+ pub struct ImportState {
421
+ used: bool,
422
+ warned: bool
423
+ }
424
+
425
+ pub fn ImportState() -> ImportState {
426
+ ImportState{ used: false, warned: false }
427
+ }
428
+
418
429
/// The link from a module up to its nearest parent node.
419
430
pub enum ParentLink {
420
431
NoParentLink,
@@ -1415,6 +1426,7 @@ pub impl Resolver {
1415
1426
1416
1427
// Build up the import directives.
1417
1428
let module_ = self.get_module_from_parent(parent);
1429
+ let state = @mut ImportState();
1418
1430
match view_path.node {
1419
1431
view_path_simple(binding, full_path, ns, _) => {
1420
1432
let ns = match ns {
@@ -1430,7 +1442,8 @@ pub impl Resolver {
1430
1442
module_,
1431
1443
module_path,
1432
1444
subclass,
1433
- view_path.span);
1445
+ view_path.span,
1446
+ state);
1434
1447
}
1435
1448
view_path_list(_, ref source_idents, _) => {
1436
1449
for (*source_idents).each |source_ident| {
@@ -1442,15 +1455,17 @@ pub impl Resolver {
1442
1455
module_,
1443
1456
module_path,
1444
1457
subclass,
1445
- view_path.span);
1458
+ view_path.span,
1459
+ state);
1446
1460
}
1447
1461
}
1448
1462
view_path_glob(_, _) => {
1449
1463
self.build_import_directive(privacy,
1450
1464
module_,
1451
1465
module_path,
1452
1466
@GlobImport,
1453
- view_path.span);
1467
+ view_path.span,
1468
+ state);
1454
1469
}
1455
1470
}
1456
1471
}
@@ -1573,7 +1588,8 @@ pub impl Resolver {
1573
1588
// avoid creating cycles in the
1574
1589
// module graph.
1575
1590
1576
- let resolution = @ImportResolution(Public, dummy_sp());
1591
+ let resolution = @ImportResolution(Public, dummy_sp(),
1592
+ @mut ImportState());
1577
1593
resolution.outstanding_references = 0;
1578
1594
1579
1595
match existing_module.parent_link {
@@ -1826,7 +1842,8 @@ pub impl Resolver {
1826
1842
module_ : @Module ,
1827
1843
module_path : @DVec < ident > ,
1828
1844
subclass : @ImportDirectiveSubclass ,
1829
- span : span ) {
1845
+ span : span ,
1846
+ state : @mut ImportState ) {
1830
1847
let directive = @ImportDirective ( privacy, module_path,
1831
1848
subclass, span) ;
1832
1849
module_. imports . push ( directive) ;
@@ -1850,7 +1867,14 @@ pub impl Resolver {
1850
1867
}
1851
1868
None => {
1852
1869
debug ! ( "(building import directive) creating new" ) ;
1853
- let resolution = @ImportResolution ( privacy, span) ;
1870
+ let resolution = @ImportResolution ( privacy, span,
1871
+ state) ;
1872
+ let name = self . idents_to_str ( module_path. get ( ) ) ;
1873
+ // Don't warn about unused intrinsics because they're
1874
+ // automatically appended to all files
1875
+ if name == ~"intrinsic:: rusti" {
1876
+ resolution. state . warned = true ;
1877
+ }
1854
1878
resolution. outstanding_references = 1 ;
1855
1879
module_. import_resolutions . insert ( target, resolution) ;
1856
1880
}
@@ -2183,7 +2207,7 @@ pub impl Resolver {
2183
2207
return UnboundResult ;
2184
2208
}
2185
2209
Some ( target) => {
2186
- import_resolution. used = true ;
2210
+ import_resolution. state . used = true ;
2187
2211
return BoundResult ( target. target_module ,
2188
2212
target. bindings ) ;
2189
2213
}
@@ -2352,7 +2376,7 @@ pub impl Resolver {
2352
2376
module_result = UnboundResult ;
2353
2377
}
2354
2378
Some ( target) => {
2355
- import_resolution. used = true ;
2379
+ import_resolution. state . used = true ;
2356
2380
module_result = BoundResult
2357
2381
( target. target_module ,
2358
2382
target. bindings ) ;
@@ -2419,6 +2443,7 @@ pub impl Resolver {
2419
2443
// everything it can to the list of import resolutions of the module
2420
2444
// node.
2421
2445
debug!(" ( resolving glob import) resolving %? glob import", privacy);
2446
+ let state = @mut ImportState();
2422
2447
2423
2448
// We must bail out if the node has unresolved imports of any kind
2424
2449
// (including globs).
@@ -2445,7 +2470,8 @@ pub impl Resolver {
2445
2470
// Simple: just copy the old import resolution.
2446
2471
let new_import_resolution =
2447
2472
@ImportResolution ( privacy,
2448
- target_import_resolution. span ) ;
2473
+ target_import_resolution. span ,
2474
+ state) ;
2449
2475
new_import_resolution. value_target =
2450
2476
copy target_import_resolution. value_target ;
2451
2477
new_import_resolution. type_target =
@@ -2486,7 +2512,8 @@ pub impl Resolver {
2486
2512
match module_. import_resolutions. find( & ident) {
2487
2513
None => {
2488
2514
// Create a new import resolution from this child.
2489
- dest_import_resolution = @ImportResolution ( privacy, span) ;
2515
+ dest_import_resolution = @ImportResolution ( privacy, span,
2516
+ state) ;
2490
2517
module_. import_resolutions . insert
2491
2518
( ident, dest_import_resolution) ;
2492
2519
}
@@ -2713,7 +2740,7 @@ pub impl Resolver {
2713
2740
namespace) ;
2714
2741
}
2715
2742
Some ( target) => {
2716
- import_resolution. used = true ;
2743
+ import_resolution. state . used = true ;
2717
2744
return Success ( copy target) ;
2718
2745
}
2719
2746
}
@@ -2962,7 +2989,7 @@ pub impl Resolver {
2962
2989
Some ( target) => {
2963
2990
debug ! ( "(resolving name in module) resolved to \
2964
2991
import") ;
2965
- import_resolution. used = true ;
2992
+ import_resolution. state . used = true ;
2966
2993
return Success ( copy target) ;
2967
2994
}
2968
2995
}
@@ -4560,7 +4587,7 @@ pub impl Resolver {
4560
4587
namespace)) {
4561
4588
(Some(def), Some(Public)) => {
4562
4589
// Found it.
4563
- import_resolution.used = true;
4590
+ import_resolution.state. used = true;
4564
4591
return ImportNameDefinition(def);
4565
4592
}
4566
4593
(Some(_), _) | (None, _) => {
@@ -5034,9 +5061,13 @@ pub impl Resolver {
5034
5061
Some ( def) => {
5035
5062
match def {
5036
5063
def_ty( trait_def_id) => {
5037
- self .
5064
+ let added = self .
5038
5065
add_trait_info_if_containing_method(
5039
5066
found_traits, trait_def_id, name) ;
5067
+ if added {
5068
+ import_resolution. state. used =
5069
+ true;
5070
+ }
5040
5071
}
5041
5072
_ => {
5042
5073
// Continue.
@@ -5069,7 +5100,7 @@ pub impl Resolver {
5069
5100
5070
5101
fn add_trait_info_if_containing_method( found_traits: @DVec <def_id>,
5071
5102
trait_def_id: def_id,
5072
- name: ident) {
5103
+ name: ident) -> bool {
5073
5104
5074
5105
debug!( "( adding trait info if containing method) trying trait %d: %d \
5075
5106
for method ' %s' ",
@@ -5085,9 +5116,10 @@ pub impl Resolver {
5085
5116
trait_def_id. node,
5086
5117
self . session. str_of( name) ) ;
5087
5118
( * found_traits) . push( trait_def_id) ;
5119
+ true
5088
5120
}
5089
5121
Some ( _) | None => {
5090
- // Continue.
5122
+ false
5091
5123
}
5092
5124
}
5093
5125
}
@@ -5204,7 +5236,13 @@ pub impl Resolver {
5204
5236
5205
5237
fn check_for_unused_imports_in_module( module_: @Module ) {
5206
5238
for module_. import_resolutions. each_value_ref |& import_resolution| {
5207
- if !import_resolution. used {
5239
+ // Ignore dummy spans for things like automatically injected
5240
+ // imports for the prelude, and also don't warn about the same
5241
+ // import statement being unused more than once.
5242
+ if !import_resolution. state. used &&
5243
+ !import_resolution. state. warned &&
5244
+ import_resolution. span != dummy_sp( ) {
5245
+ import_resolution. state. warned = true ;
5208
5246
match self . unused_import_lint_level {
5209
5247
warn => {
5210
5248
self. session. span_warn( import_resolution. span,
0 commit comments