Rename is_object_safe to check_is_object_safe to hint side effects

This commit is contained in:
Gary Guo 2023-01-28 15:07:21 +00:00
parent d6de40b536
commit 94e59cb6e2
12 changed files with 17 additions and 14 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 !trait_should_be_self.is_empty() {
if tcx.is_object_safe(trait_def_id) { if tcx.check_is_object_safe(trait_def_id) {
return; return;
} }
let sugg = trait_should_be_self.iter().map(|span| (*span, "Self".to_string())).collect(); let sugg = trait_should_be_self.iter().map(|span| (*span, "Self".to_string())).collect();

View file

@ -169,7 +169,7 @@ fn check_object_overlap<'tcx>(
}); });
for component_def_id in component_def_ids { for component_def_id in component_def_ids {
if !tcx.is_object_safe(component_def_id) { if !tcx.check_is_object_safe(component_def_id) {
// Without the 'object_safe_for_dispatch' feature this is an error // Without the 'object_safe_for_dispatch' feature this is an error
// which will be reported by wfcheck. Ignore it here. // which will be reported by wfcheck. Ignore it here.
// This is tested by `coherence-impl-trait-for-trait-object-safe.rs`. // This is tested by `coherence-impl-trait-for-trait-object-safe.rs`.

View file

@ -1823,7 +1823,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
.trait_ref() .trait_ref()
.and_then(|t| t.trait_def_id()) .and_then(|t| t.trait_def_id())
.map_or(false, |def_id| { .map_or(false, |def_id| {
fcx.tcx.is_object_safe(def_id) fcx.tcx.check_is_object_safe(def_id)
}) })
}) })
} }

View file

@ -1274,8 +1274,8 @@ rustc_queries! {
query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] { query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
desc { |tcx| "determining object safety of trait `{}`", tcx.def_path_str(trait_id) } desc { |tcx| "determining object safety of trait `{}`", tcx.def_path_str(trait_id) }
} }
query is_object_safe(trait_id: DefId) -> bool { query check_is_object_safe(trait_id: DefId) -> bool {
desc { |tcx| "determining object safety of trait `{}`", tcx.def_path_str(trait_id) } desc { |tcx| "checking if trait `{}` is object safe", tcx.def_path_str(trait_id) }
} }
/// Gets the ParameterEnvironment for a given item; this environment /// Gets the ParameterEnvironment for a given item; this environment

View file

@ -363,7 +363,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
} }
fn compute_object_safe_goal(&mut self, trait_def_id: DefId) -> QueryResult<'tcx> { fn compute_object_safe_goal(&mut self, trait_def_id: DefId) -> QueryResult<'tcx> {
if self.tcx().is_object_safe(trait_def_id) { if self.tcx().check_is_object_safe(trait_def_id) {
self.make_canonical_response(Certainty::Yes) self.make_canonical_response(Certainty::Yes)
} else { } else {
Err(NoSolution) Err(NoSolution)

View file

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

View file

@ -369,7 +369,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
} }
ty::PredicateKind::ObjectSafe(trait_def_id) => { ty::PredicateKind::ObjectSafe(trait_def_id) => {
if !self.selcx.tcx().is_object_safe(trait_def_id) { if !self.selcx.tcx().check_is_object_safe(trait_def_id) {
ProcessResult::Error(CodeSelectionError(Unimplemented)) ProcessResult::Error(CodeSelectionError(Unimplemented))
} else { } else {
ProcessResult::Changed(vec![]) ProcessResult::Changed(vec![])

View file

@ -62,7 +62,7 @@ fn object_safety_violations(tcx: TyCtxt<'_>, trait_def_id: DefId) -> &'_ [Object
) )
} }
fn is_object_safe(tcx: TyCtxt<'_>, trait_def_id: DefId) -> bool { fn check_is_object_safe(tcx: TyCtxt<'_>, trait_def_id: DefId) -> bool {
let violations = tcx.object_safety_violations(trait_def_id); let violations = tcx.object_safety_violations(trait_def_id);
if violations.is_empty() { if violations.is_empty() {
@ -884,5 +884,6 @@ pub fn contains_illegal_impl_trait_in_trait<'tcx>(
} }
pub fn provide(providers: &mut ty::query::Providers) { pub fn provide(providers: &mut ty::query::Providers) {
*providers = ty::query::Providers { object_safety_violations, is_object_safe, ..*providers }; *providers =
ty::query::Providers { object_safety_violations, check_is_object_safe, ..*providers };
} }

View file

@ -466,7 +466,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
if let Some(principal) = data.principal() { if let Some(principal) = data.principal() {
if !self.infcx.tcx.features().object_safe_for_dispatch { if !self.infcx.tcx.features().object_safe_for_dispatch {
principal.with_self_ty(self.tcx(), self_ty) principal.with_self_ty(self.tcx(), self_ty)
} else if self.tcx().is_object_safe(principal.def_id()) { } else if self.tcx().check_is_object_safe(principal.def_id()) {
principal.with_self_ty(self.tcx(), self_ty) principal.with_self_ty(self.tcx(), self_ty)
} else { } else {
return; return;

View file

@ -1009,7 +1009,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// `T` -> `Trait` // `T` -> `Trait`
(_, &ty::Dynamic(ref data, r, ty::Dyn)) => { (_, &ty::Dynamic(ref data, r, ty::Dyn)) => {
let mut object_dids = data.auto_traits().chain(data.principal_def_id()); let mut object_dids = data.auto_traits().chain(data.principal_def_id());
if let Some(did) = object_dids.find(|did| !tcx.is_object_safe(*did)) { if let Some(did) = object_dids.find(|did| !tcx.check_is_object_safe(*did)) {
return Err(TraitNotObjectSafe(did)); return Err(TraitNotObjectSafe(did));
} }

View file

@ -797,7 +797,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
} }
ty::PredicateKind::ObjectSafe(trait_def_id) => { ty::PredicateKind::ObjectSafe(trait_def_id) => {
if self.tcx().is_object_safe(trait_def_id) { if self.tcx().check_is_object_safe(trait_def_id) {
Ok(EvaluatedToOk) Ok(EvaluatedToOk)
} else { } else {
Ok(EvaluatedToErr) Ok(EvaluatedToErr)

View file

@ -580,7 +580,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
} }
fn is_object_safe(&self, trait_id: chalk_ir::TraitId<RustInterner<'tcx>>) -> bool { fn is_object_safe(&self, trait_id: chalk_ir::TraitId<RustInterner<'tcx>>) -> bool {
self.interner.tcx.is_object_safe(trait_id.0) self.interner.tcx.check_is_object_safe(trait_id.0)
} }
fn hidden_opaque_type( fn hidden_opaque_type(