@@ -17,7 +17,7 @@ use metadata::csearch::get_type_name_if_impl;
17
17
use metadata:: cstore:: find_extern_mod_stmt_cnum;
18
18
use metadata:: decoder:: { def_like, dl_def, dl_field, dl_impl} ;
19
19
use middle:: lang_items:: LanguageItems ;
20
- use middle:: lint:: unused_imports;
20
+ use middle:: lint:: { unnecessary_qualification , unused_imports} ;
21
21
use middle:: pat_util:: pat_bindings;
22
22
23
23
use syntax:: ast:: * ;
@@ -3561,7 +3561,7 @@ impl Resolver {
3561
3561
3562
3562
// Resolve derived traits.
3563
3563
for traits. iter( ) . advance |trt| {
3564
- self . resolve_trait_reference( trt, visitor, TraitDerivation ) ;
3564
+ self . resolve_trait_reference( item . id , trt, visitor, TraitDerivation ) ;
3565
3565
}
3566
3566
3567
3567
for ( * methods) . iter( ) . advance |method| {
@@ -3802,27 +3802,29 @@ impl Resolver {
3802
3802
visitor: ResolveVisitor ) {
3803
3803
for type_parameters. iter( ) . advance |type_parameter| {
3804
3804
for type_parameter. bounds. iter( ) . advance |bound| {
3805
- self . resolve_type_parameter_bound( bound, visitor) ;
3805
+ self . resolve_type_parameter_bound( type_parameter . id , bound, visitor) ;
3806
3806
}
3807
3807
}
3808
3808
}
3809
3809
3810
3810
pub fn resolve_type_parameter_bound( @mut self ,
3811
+ id: node_id,
3811
3812
type_parameter_bound: & TyParamBound ,
3812
3813
visitor: ResolveVisitor ) {
3813
3814
match * type_parameter_bound {
3814
3815
TraitTyParamBound ( ref tref) => {
3815
- self . resolve_trait_reference( tref, visitor, TraitBoundingTypeParameter )
3816
+ self . resolve_trait_reference( id , tref, visitor, TraitBoundingTypeParameter )
3816
3817
}
3817
3818
RegionTyParamBound => { }
3818
3819
}
3819
3820
}
3820
3821
3821
3822
pub fn resolve_trait_reference( @mut self ,
3823
+ id: node_id,
3822
3824
trait_reference: & trait_ref,
3823
3825
visitor: ResolveVisitor ,
3824
3826
reference_type: TraitReferenceType ) {
3825
- match self . resolve_path( & trait_reference. path, TypeNS , true , visitor) {
3827
+ match self . resolve_path( id , & trait_reference. path, TypeNS , true , visitor) {
3826
3828
None => {
3827
3829
let path_str = self . idents_to_str( trait_reference. path. idents) ;
3828
3830
@@ -3930,7 +3932,8 @@ impl Resolver {
3930
3932
let original_trait_refs;
3931
3933
match opt_trait_reference {
3932
3934
& Some ( ref trait_reference) => {
3933
- self . resolve_trait_reference( trait_reference, visitor, TraitImplementation ) ;
3935
+ self . resolve_trait_reference( id, trait_reference, visitor,
3936
+ TraitImplementation ) ;
3934
3937
3935
3938
// Record the current set of trait references.
3936
3939
let mut new_trait_refs = ~[ ] ;
@@ -4142,7 +4145,7 @@ impl Resolver {
4142
4145
4143
4146
match result_def {
4144
4147
None => {
4145
- match self . resolve_path( path, TypeNS , true , visitor) {
4148
+ match self . resolve_path( ty . id , path, TypeNS , true , visitor) {
4146
4149
Some ( def) => {
4147
4150
debug ! ( "(resolving type) resolved `%s` to \
4148
4151
type %?",
@@ -4179,15 +4182,15 @@ impl Resolver {
4179
4182
4180
4183
do bounds. map |bound_vec| {
4181
4184
for bound_vec. iter( ) . advance |bound| {
4182
- self . resolve_type_parameter_bound( bound, visitor) ;
4185
+ self . resolve_type_parameter_bound( ty . id , bound, visitor) ;
4183
4186
}
4184
4187
} ;
4185
4188
}
4186
4189
4187
4190
ty_closure( c) => {
4188
4191
do c. bounds. map |bounds| {
4189
4192
for bounds. iter( ) . advance |bound| {
4190
- self . resolve_type_parameter_bound( bound, visitor) ;
4193
+ self . resolve_type_parameter_bound( ty . id , bound, visitor) ;
4191
4194
}
4192
4195
} ;
4193
4196
visit_ty( ty, ( ( ) , visitor) ) ;
@@ -4340,7 +4343,7 @@ impl Resolver {
4340
4343
4341
4344
pat_ident( binding_mode, ref path, _) => {
4342
4345
// This must be an enum variant, struct, or constant.
4343
- match self . resolve_path( path, ValueNS , false , visitor) {
4346
+ match self . resolve_path( pat_id , path, ValueNS , false , visitor) {
4344
4347
Some ( def @ def_variant( * ) ) |
4345
4348
Some ( def @ def_struct( * ) ) => {
4346
4349
self . record_def( pattern. id, def) ;
@@ -4373,7 +4376,7 @@ impl Resolver {
4373
4376
4374
4377
pat_enum( ref path, _) => {
4375
4378
// This must be an enum variant, struct or const.
4376
- match self . resolve_path( path, ValueNS , false , visitor) {
4379
+ match self . resolve_path( pat_id , path, ValueNS , false , visitor) {
4377
4380
Some ( def @ def_fn( * ) ) |
4378
4381
Some ( def @ def_variant( * ) ) |
4379
4382
Some ( def @ def_struct( * ) ) |
@@ -4410,7 +4413,7 @@ impl Resolver {
4410
4413
}
4411
4414
4412
4415
pat_struct( ref path, _, _) => {
4413
- match self . resolve_path( path, TypeNS , false , visitor) {
4416
+ match self . resolve_path( pat_id , path, TypeNS , false , visitor) {
4414
4417
Some ( def_ty( class_id) )
4415
4418
if self . structs. contains( & class_id) => {
4416
4419
let class_def = def_struct( class_id) ;
@@ -4484,6 +4487,7 @@ impl Resolver {
4484
4487
/// If `check_ribs` is true, checks the local definitions first; i.e.
4485
4488
/// doesn't skip straight to the containing module.
4486
4489
pub fn resolve_path( @mut self ,
4490
+ id: node_id,
4487
4491
path: & Path ,
4488
4492
namespace: Namespace ,
4489
4493
check_ribs: bool ,
@@ -4500,16 +4504,24 @@ impl Resolver {
4500
4504
namespace) ;
4501
4505
}
4502
4506
4507
+ let unqualified_def = self . resolve_identifier(
4508
+ * path. idents. last( ) , namespace, check_ribs, path. span) ;
4509
+
4503
4510
if path. idents. len( ) > 1 {
4504
- return self . resolve_module_relative_path( path,
4505
- self . xray_context,
4506
- namespace) ;
4511
+ let def = self . resolve_module_relative_path(
4512
+ path, self . xray_context, namespace) ;
4513
+ match ( def, unqualified_def) {
4514
+ ( Some ( d) , Some ( ud) ) if d == ud => {
4515
+ self . session. add_lint( unnecessary_qualification,
4516
+ id, path. span,
4517
+ ~"unnecessary qualification") ;
4518
+ }
4519
+ _ => ( )
4520
+ }
4521
+ return def;
4507
4522
}
4508
4523
4509
- return self . resolve_identifier( * path. idents. last( ) ,
4510
- namespace,
4511
- check_ribs,
4512
- path. span) ;
4524
+ return unqualified_def;
4513
4525
}
4514
4526
4515
4527
pub fn resolve_identifier( @mut self ,
@@ -4920,7 +4932,7 @@ impl Resolver {
4920
4932
// This is a local path in the value namespace. Walk through
4921
4933
// scopes looking for it.
4922
4934
4923
- match self . resolve_path( path, ValueNS , true , visitor) {
4935
+ match self . resolve_path( expr . id , path, ValueNS , true , visitor) {
4924
4936
Some ( def) => {
4925
4937
// Write the result into the def map.
4926
4938
debug ! ( "(resolving expr) resolved `%s`" ,
@@ -4987,7 +4999,7 @@ impl Resolver {
4987
4999
4988
5000
expr_struct( ref path, _, _) => {
4989
5001
// Resolve the path to the structure it goes to.
4990
- match self . resolve_path( path, TypeNS , false , visitor) {
5002
+ match self . resolve_path( expr . id , path, TypeNS , false , visitor) {
4991
5003
Some ( def_ty( class_id) ) | Some ( def_struct( class_id) )
4992
5004
if self . structs. contains( & class_id) => {
4993
5005
let class_def = def_struct( class_id) ;
0 commit comments