@@ -2076,25 +2076,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2076
2076
let mut err = self . need_type_info_err ( body_id, span, self_ty, ErrorCode :: E0283 ) ;
2077
2077
err. note ( & format ! ( "cannot resolve `{}`" , predicate) ) ;
2078
2078
if let ObligationCauseCode :: ItemObligation ( def_id) = obligation. cause . code {
2079
- if let Some ( assoc_item) = self . tcx . opt_associated_item ( def_id) {
2080
- if let ty:: AssocKind :: Const | ty:: AssocKind :: Type = assoc_item. kind {
2081
- err. note ( & format ! (
2082
- "{}s cannot be accessed directly on a `trait`, they can only be \
2083
- accessed through a specific `impl`",
2084
- assoc_item. kind. suggestion_descr( ) ,
2085
- ) ) ;
2086
- err. span_suggestion (
2087
- span,
2088
- "use the fully qualified path to an implementation" ,
2089
- format ! (
2090
- "<Type as {}>::{}" ,
2091
- self . tcx. def_path_str( trait_ref. def_id( ) ) ,
2092
- assoc_item. ident
2093
- ) ,
2094
- Applicability :: HasPlaceholders ,
2095
- ) ;
2096
- }
2097
- }
2079
+ self . suggest_fully_qualified_path ( & mut err, def_id, span, trait_ref. def_id ( ) ) ;
2098
2080
} else if let (
2099
2081
Ok ( ref snippet) ,
2100
2082
ObligationCauseCode :: BindingObligation ( ref def_id, _) ,
@@ -2196,6 +2178,30 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2196
2178
err. emit ( ) ;
2197
2179
}
2198
2180
2181
+ fn suggest_fully_qualified_path (
2182
+ & self ,
2183
+ err : & mut DiagnosticBuilder < ' _ > ,
2184
+ def_id : DefId ,
2185
+ span : Span ,
2186
+ trait_ref : DefId ,
2187
+ ) {
2188
+ if let Some ( assoc_item) = self . tcx . opt_associated_item ( def_id) {
2189
+ if let ty:: AssocKind :: Const | ty:: AssocKind :: Type = assoc_item. kind {
2190
+ err. note ( & format ! (
2191
+ "{}s cannot be accessed directly on a `trait`, they can only be \
2192
+ accessed through a specific `impl`",
2193
+ assoc_item. kind. suggestion_descr( ) ,
2194
+ ) ) ;
2195
+ err. span_suggestion (
2196
+ span,
2197
+ "use the fully qualified path to an implementation" ,
2198
+ format ! ( "<Type as {}>::{}" , self . tcx. def_path_str( trait_ref) , assoc_item. ident) ,
2199
+ Applicability :: HasPlaceholders ,
2200
+ ) ;
2201
+ }
2202
+ }
2203
+ }
2204
+
2199
2205
/// Returns `true` if the trait predicate may apply for *some* assignment
2200
2206
/// to the type parameters.
2201
2207
fn predicate_can_apply (
0 commit comments