@@ -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
@@ -223,13 +223,13 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
223
223
err
224
224
225
225
}
226
- ResolutionError :: IsNotATrait ( name) => {
226
+ ResolutionError :: IsNotATrait ( name, kind_name ) => {
227
227
let mut err = struct_span_err ! ( resolver. session,
228
228
span,
229
229
E0404 ,
230
230
"`{}` is not a trait" ,
231
231
name) ;
232
- err. span_label ( span, & format ! ( "not a trait" ) ) ;
232
+ err. span_label ( span, & format ! ( "expected trait, found {}" , kind_name ) ) ;
233
233
err
234
234
}
235
235
ResolutionError :: UndeclaredTraitName ( name, candidates) => {
@@ -555,7 +555,7 @@ impl<'a> Visitor for Resolver<'a> {
555
555
self . resolve_type ( ty) ;
556
556
}
557
557
fn visit_poly_trait_ref ( & mut self , tref : & ast:: PolyTraitRef , m : & ast:: TraitBoundModifier ) {
558
- match self . resolve_trait_reference ( tref. trait_ref . ref_id , & tref. trait_ref . path , 0 ) {
558
+ match self . resolve_trait_reference ( tref. trait_ref . ref_id , & tref. trait_ref . path , 0 , None ) {
559
559
Ok ( def) => self . record_def ( tref. trait_ref . ref_id , def) ,
560
560
Err ( _) => {
561
561
// error already reported
@@ -1699,7 +1699,7 @@ impl<'a> Resolver<'a> {
1699
1699
}
1700
1700
1701
1701
ItemKind :: DefaultImpl ( _, ref trait_ref) => {
1702
- self . with_optional_trait_ref ( Some ( trait_ref) , |_, _| { } ) ;
1702
+ self . with_optional_trait_ref ( Some ( trait_ref) , |_, _| { } , None ) ;
1703
1703
}
1704
1704
ItemKind :: Impl ( .., ref generics, ref opt_trait_ref, ref self_type, ref impl_items) =>
1705
1705
self . resolve_implementation ( generics,
@@ -1889,7 +1889,8 @@ impl<'a> Resolver<'a> {
1889
1889
fn resolve_trait_reference ( & mut self ,
1890
1890
id : NodeId ,
1891
1891
trait_path : & Path ,
1892
- path_depth : usize )
1892
+ path_depth : usize ,
1893
+ generics : Option < & Generics > )
1893
1894
-> Result < PathResolution , ( ) > {
1894
1895
self . resolve_path ( id, trait_path, path_depth, TypeNS ) . and_then ( |path_res| {
1895
1896
match path_res. base_def {
@@ -1902,8 +1903,16 @@ impl<'a> Resolver<'a> {
1902
1903
}
1903
1904
1904
1905
let mut err = resolve_struct_error ( self , trait_path. span , {
1905
- ResolutionError :: IsNotATrait ( & path_names_to_string ( trait_path, path_depth) )
1906
+ ResolutionError :: IsNotATrait ( & path_names_to_string ( trait_path, path_depth) ,
1907
+ path_res. base_def . kind_name ( ) )
1906
1908
} ) ;
1909
+ if let Some ( generics) = generics {
1910
+ if let Some ( span) = generics. span_for_name (
1911
+ & path_names_to_string ( trait_path, path_depth) ) {
1912
+
1913
+ err. span_label ( span, & "type parameter defined here" ) ;
1914
+ }
1915
+ }
1907
1916
1908
1917
// If it's a typedef, give a note
1909
1918
if let Def :: TyAlias ( ..) = path_res. base_def {
@@ -1948,15 +1957,20 @@ impl<'a> Resolver<'a> {
1948
1957
result
1949
1958
}
1950
1959
1951
- fn with_optional_trait_ref < T , F > ( & mut self , opt_trait_ref : Option < & TraitRef > , f : F ) -> T
1960
+ fn with_optional_trait_ref < T , F > ( & mut self ,
1961
+ opt_trait_ref : Option < & TraitRef > ,
1962
+ f : F ,
1963
+ generics : Option < & Generics > )
1964
+ -> T
1952
1965
where F : FnOnce ( & mut Resolver , Option < DefId > ) -> T
1953
1966
{
1954
1967
let mut new_val = None ;
1955
1968
let mut new_id = None ;
1956
1969
if let Some ( trait_ref) = opt_trait_ref {
1957
1970
if let Ok ( path_res) = self . resolve_trait_reference ( trait_ref. ref_id ,
1958
1971
& trait_ref. path ,
1959
- 0 ) {
1972
+ 0 ,
1973
+ generics) {
1960
1974
assert ! ( path_res. depth == 0 ) ;
1961
1975
self . record_def ( trait_ref. ref_id , path_res) ;
1962
1976
new_val = Some ( ( path_res. base_def . def_id ( ) , trait_ref. clone ( ) ) ) ;
@@ -2044,7 +2058,7 @@ impl<'a> Resolver<'a> {
2044
2058
}
2045
2059
} ) ;
2046
2060
} ) ;
2047
- } ) ;
2061
+ } , Some ( & generics ) ) ;
2048
2062
} ) ;
2049
2063
}
2050
2064
@@ -2494,7 +2508,7 @@ impl<'a> Resolver<'a> {
2494
2508
}
2495
2509
max_assoc_types = path. segments . len ( ) - qself. position ;
2496
2510
// Make sure the trait is valid.
2497
- let _ = self . resolve_trait_reference ( id, path, max_assoc_types) ;
2511
+ let _ = self . resolve_trait_reference ( id, path, max_assoc_types, None ) ;
2498
2512
}
2499
2513
None => {
2500
2514
max_assoc_types = path. segments . len ( ) ;
0 commit comments