@@ -108,7 +108,7 @@ enum ResolutionError<'a> {
108
108
/// error E0403: the name is already used for a type parameter in this type parameter list
109
109
NameAlreadyUsedInTypeParameterList ( Name , & ' a Span ) ,
110
110
/// error E0404: is not a trait
111
- IsNotATrait ( & ' a str ) ,
111
+ IsNotATrait ( & ' a str , & ' a str ) ,
112
112
/// error E0405: use of undeclared trait name
113
113
UndeclaredTraitName ( & ' a str , SuggestedCandidates ) ,
114
114
/// error E0407: method is not a member of trait
@@ -225,13 +225,13 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
225
225
err
226
226
227
227
}
228
- ResolutionError :: IsNotATrait ( name) => {
228
+ ResolutionError :: IsNotATrait ( name, kind_name ) => {
229
229
let mut err = struct_span_err ! ( resolver. session,
230
230
span,
231
231
E0404 ,
232
232
"`{}` is not a trait" ,
233
233
name) ;
234
- err. span_label ( span, & format ! ( "not a trait" ) ) ;
234
+ err. span_label ( span, & format ! ( "expected trait, found {}" , kind_name ) ) ;
235
235
err
236
236
}
237
237
ResolutionError :: UndeclaredTraitName ( name, candidates) => {
@@ -566,7 +566,7 @@ impl<'a> Visitor for Resolver<'a> {
566
566
self . resolve_type ( ty) ;
567
567
}
568
568
fn visit_poly_trait_ref ( & mut self , tref : & ast:: PolyTraitRef , m : & ast:: TraitBoundModifier ) {
569
- match self . resolve_trait_reference ( tref. trait_ref . ref_id , & tref. trait_ref . path , 0 ) {
569
+ match self . resolve_trait_reference ( tref. trait_ref . ref_id , & tref. trait_ref . path , 0 , None ) {
570
570
Ok ( def) => self . record_def ( tref. trait_ref . ref_id , def) ,
571
571
Err ( _) => {
572
572
// error already reported
@@ -1703,7 +1703,7 @@ impl<'a> Resolver<'a> {
1703
1703
}
1704
1704
1705
1705
ItemKind :: DefaultImpl ( _, ref trait_ref) => {
1706
- self . with_optional_trait_ref ( Some ( trait_ref) , |_, _| { } ) ;
1706
+ self . with_optional_trait_ref ( Some ( trait_ref) , |_, _| { } , None ) ;
1707
1707
}
1708
1708
ItemKind :: Impl ( .., ref generics, ref opt_trait_ref, ref self_type, ref impl_items) =>
1709
1709
self . resolve_implementation ( generics,
@@ -1893,7 +1893,8 @@ impl<'a> Resolver<'a> {
1893
1893
fn resolve_trait_reference ( & mut self ,
1894
1894
id : NodeId ,
1895
1895
trait_path : & Path ,
1896
- path_depth : usize )
1896
+ path_depth : usize ,
1897
+ generics : Option < & Generics > )
1897
1898
-> Result < PathResolution , ( ) > {
1898
1899
self . resolve_path ( id, trait_path, path_depth, TypeNS ) . and_then ( |path_res| {
1899
1900
match path_res. base_def {
@@ -1906,8 +1907,16 @@ impl<'a> Resolver<'a> {
1906
1907
}
1907
1908
1908
1909
let mut err = resolve_struct_error ( self , trait_path. span , {
1909
- ResolutionError :: IsNotATrait ( & path_names_to_string ( trait_path, path_depth) )
1910
+ ResolutionError :: IsNotATrait ( & path_names_to_string ( trait_path, path_depth) ,
1911
+ path_res. base_def . kind_name ( ) )
1910
1912
} ) ;
1913
+ if let Some ( generics) = generics {
1914
+ if let Some ( span) = generics. span_for_name (
1915
+ & path_names_to_string ( trait_path, path_depth) ) {
1916
+
1917
+ err. span_label ( span, & "type parameter defined here" ) ;
1918
+ }
1919
+ }
1911
1920
1912
1921
// If it's a typedef, give a note
1913
1922
if let Def :: TyAlias ( ..) = path_res. base_def {
@@ -1952,15 +1961,20 @@ impl<'a> Resolver<'a> {
1952
1961
result
1953
1962
}
1954
1963
1955
- fn with_optional_trait_ref < T , F > ( & mut self , opt_trait_ref : Option < & TraitRef > , f : F ) -> T
1964
+ fn with_optional_trait_ref < T , F > ( & mut self ,
1965
+ opt_trait_ref : Option < & TraitRef > ,
1966
+ f : F ,
1967
+ generics : Option < & Generics > )
1968
+ -> T
1956
1969
where F : FnOnce ( & mut Resolver , Option < DefId > ) -> T
1957
1970
{
1958
1971
let mut new_val = None ;
1959
1972
let mut new_id = None ;
1960
1973
if let Some ( trait_ref) = opt_trait_ref {
1961
1974
if let Ok ( path_res) = self . resolve_trait_reference ( trait_ref. ref_id ,
1962
1975
& trait_ref. path ,
1963
- 0 ) {
1976
+ 0 ,
1977
+ generics) {
1964
1978
assert ! ( path_res. depth == 0 ) ;
1965
1979
self . record_def ( trait_ref. ref_id , path_res) ;
1966
1980
new_val = Some ( ( path_res. base_def . def_id ( ) , trait_ref. clone ( ) ) ) ;
@@ -2048,7 +2062,7 @@ impl<'a> Resolver<'a> {
2048
2062
}
2049
2063
} ) ;
2050
2064
} ) ;
2051
- } ) ;
2065
+ } , Some ( & generics ) ) ;
2052
2066
} ) ;
2053
2067
}
2054
2068
@@ -2492,7 +2506,7 @@ impl<'a> Resolver<'a> {
2492
2506
}
2493
2507
max_assoc_types = path. segments . len ( ) - qself. position ;
2494
2508
// Make sure the trait is valid.
2495
- let _ = self . resolve_trait_reference ( id, path, max_assoc_types) ;
2509
+ let _ = self . resolve_trait_reference ( id, path, max_assoc_types, None ) ;
2496
2510
}
2497
2511
None => {
2498
2512
max_assoc_types = path. segments . len ( ) ;
0 commit comments