File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
src/librustc_typeck/check Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -166,11 +166,13 @@ fn check_object_safety_inner<'tcx>(tcx: &ty::ctxt<'tcx>,
166
166
}
167
167
}
168
168
169
- /// Returns a vec of error messages. If hte vec is empty - no errors!
169
+ /// Returns a vec of error messages. If the vec is empty - no errors!
170
170
///
171
171
/// There are some limitations to calling functions through an object, because (a) the self
172
172
/// type is not known (that's the whole point of a trait instance, after all, to obscure the
173
- /// self type) and (b) the call must go through a vtable and hence cannot be monomorphized.
173
+ /// self type), (b) the call must go through a vtable and hence cannot be monomorphized and
174
+ /// (c) the trait contains static methods which can't be called because we don't know the
175
+ /// concrete type.
174
176
fn check_object_safety_of_method < ' tcx > ( tcx : & ty:: ctxt < ' tcx > ,
175
177
method : & ty:: Method < ' tcx > )
176
178
-> Vec < String > {
@@ -185,9 +187,11 @@ fn check_object_safety_inner<'tcx>(tcx: &ty::ctxt<'tcx>,
185
187
}
186
188
187
189
ty:: StaticExplicitSelfCategory => {
188
- // Static methods are always object-safe since they
189
- // can't be called through a trait object
190
- return msgs
190
+ // Static methods are never object safe (reason (c)).
191
+ msgs. push ( format ! ( "cannot call a static method (`{}`) \
192
+ through a trait object",
193
+ method_name) ) ;
194
+ return msgs;
191
195
}
192
196
ty:: ByReferenceExplicitSelfCategory ( ..) |
193
197
ty:: ByBoxExplicitSelfCategory => { }
You can’t perform that action at this time.
0 commit comments