Replace object_safety_violations().is_empty() calls with is_object_safe

This commit is contained in:
Gary Guo 2022-12-29 09:52:46 +00:00
parent d8da513668
commit e144a13254
3 changed files with 3 additions and 5 deletions

View File

@ -834,7 +834,7 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem
_ => {}
}
if !trait_should_be_self.is_empty() {
if tcx.object_safety_violations(trait_def_id).is_empty() {
if tcx.is_object_safe(trait_def_id) {
return;
}
let sugg = trait_should_be_self.iter().map(|span| (*span, "Self".to_string())).collect();

View File

@ -1823,7 +1823,7 @@ fn add_impl_trait_explanation<'a>(
.trait_ref()
.and_then(|t| t.trait_def_id())
.map_or(false, |def_id| {
fcx.tcx.object_safety_violations(def_id).is_empty()
fcx.tcx.is_object_safe(def_id)
})
})
}

View File

@ -1749,9 +1749,7 @@ fn suggest_impl_trait(
let is_object_safe = match ty.kind() {
ty::Dynamic(predicates, _, ty::Dyn) => {
// If the `dyn Trait` is not object safe, do not suggest `Box<dyn Trait>`.
predicates
.principal_def_id()
.map_or(true, |def_id| self.tcx.object_safety_violations(def_id).is_empty())
predicates.principal_def_id().map_or(true, |def_id| self.tcx.is_object_safe(def_id))
}
// We only want to suggest `impl Trait` to `dyn Trait`s.
// For example, `fn foo() -> str` needs to be filtered out.