only compute codegen_fn_attrs where needed

This commit is contained in:
lcnr 2022-05-04 11:18:37 +02:00
parent 66ff6c32e5
commit d371ebe117
11 changed files with 153 additions and 50 deletions

View file

@ -375,7 +375,12 @@ impl<'tcx> UnsafetyChecker<'_, 'tcx> {
}
let callee_features = &self.tcx.codegen_fn_attrs(func_did).target_features;
let self_features = &self.tcx.codegen_fn_attrs(self.body_did).target_features;
// Constants don't have codegen attributes, so the body might not have codegen attributes.
let self_features: &[_] = if self.tcx.has_codegen_attrs(self.tcx.def_kind(self.body_did)) {
&self.tcx.codegen_fn_attrs(self.body_did).target_features
} else {
&[]
};
// Is `callee_features` a subset of `calling_features`?
if !callee_features.iter().all(|feature| self_features.contains(feature)) {