Compiler: Rename "object safe" to "dyn compatible"
This commit is contained in:
@@ -37,7 +37,7 @@ use super::{
|
||||
};
|
||||
use crate::error_reporting::TypeErrCtxt;
|
||||
use crate::error_reporting::infer::TyCategory;
|
||||
use crate::error_reporting::traits::report_object_safety_error;
|
||||
use crate::error_reporting::traits::report_dyn_incompatibility;
|
||||
use crate::errors::{
|
||||
AsyncClosureNotFn, ClosureFnMutLabel, ClosureFnOnceLabel, ClosureKindMismatch,
|
||||
};
|
||||
@@ -46,7 +46,7 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
|
||||
use crate::traits::{
|
||||
MismatchedProjectionTypes, NormalizeExt, Obligation, ObligationCause, ObligationCauseCode,
|
||||
ObligationCtxt, Overflow, PredicateObligation, SelectionError, SignatureMismatch,
|
||||
TraitNotObjectSafe, elaborate,
|
||||
TraitDynIncompatible, elaborate,
|
||||
};
|
||||
|
||||
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
@@ -547,9 +547,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
)
|
||||
}
|
||||
|
||||
ty::PredicateKind::ObjectSafe(trait_def_id) => {
|
||||
let violations = self.tcx.object_safety_violations(trait_def_id);
|
||||
report_object_safety_error(self.tcx, span, None, trait_def_id, violations)
|
||||
ty::PredicateKind::DynCompatible(trait_def_id) => {
|
||||
let violations = self.tcx.dyn_compatibility_violations(trait_def_id);
|
||||
report_dyn_incompatibility(self.tcx, span, None, trait_def_id, violations)
|
||||
}
|
||||
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(ty)) => {
|
||||
@@ -624,9 +624,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
def_id,
|
||||
),
|
||||
|
||||
TraitNotObjectSafe(did) => {
|
||||
let violations = self.tcx.object_safety_violations(did);
|
||||
report_object_safety_error(self.tcx, span, None, did, violations)
|
||||
TraitDynIncompatible(did) => {
|
||||
let violations = self.tcx.dyn_compatibility_violations(did);
|
||||
report_dyn_incompatibility(self.tcx, span, None, did, violations)
|
||||
}
|
||||
|
||||
SelectionError::NotConstEvaluatable(NotConstEvaluatable::MentionsInfer) => {
|
||||
|
||||
@@ -12,8 +12,8 @@ use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_hir::{self as hir, LangItem};
|
||||
use rustc_infer::traits::{
|
||||
ObjectSafetyViolation, Obligation, ObligationCause, ObligationCauseCode, PredicateObligation,
|
||||
SelectionError,
|
||||
DynCompatibilityViolation, Obligation, ObligationCause, ObligationCauseCode,
|
||||
PredicateObligation, SelectionError,
|
||||
};
|
||||
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
@@ -406,12 +406,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn report_object_safety_error<'tcx>(
|
||||
pub fn report_dyn_incompatibility<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
span: Span,
|
||||
hir_id: Option<hir::HirId>,
|
||||
trait_def_id: DefId,
|
||||
violations: &[ObjectSafetyViolation],
|
||||
violations: &[DynCompatibilityViolation],
|
||||
) -> Diag<'tcx> {
|
||||
let trait_str = tcx.def_path_str(trait_def_id);
|
||||
let trait_span = tcx.hir().get_if_local(trait_def_id).and_then(|node| match node {
|
||||
@@ -449,12 +449,12 @@ pub fn report_object_safety_error<'tcx>(
|
||||
let mut multi_span = vec![];
|
||||
let mut messages = vec![];
|
||||
for violation in violations {
|
||||
if let ObjectSafetyViolation::SizedSelf(sp) = &violation
|
||||
if let DynCompatibilityViolation::SizedSelf(sp) = &violation
|
||||
&& !sp.is_empty()
|
||||
{
|
||||
// Do not report `SizedSelf` without spans pointing at `SizedSelf` obligations
|
||||
// with a `Span`.
|
||||
reported_violations.insert(ObjectSafetyViolation::SizedSelf(vec![].into()));
|
||||
reported_violations.insert(DynCompatibilityViolation::SizedSelf(vec![].into()));
|
||||
}
|
||||
if reported_violations.insert(violation.clone()) {
|
||||
let spans = violation.spans();
|
||||
@@ -481,9 +481,10 @@ pub fn report_object_safety_error<'tcx>(
|
||||
for (span, msg) in iter::zip(multi_span, messages) {
|
||||
note_span.push_span_label(span, msg);
|
||||
}
|
||||
// FIXME(dyn_compat_renaming): Update the URL.
|
||||
err.span_note(
|
||||
note_span,
|
||||
"for a trait to be \"object safe\" it needs to allow building a vtable to allow the call \
|
||||
"for a trait to be \"dyn-compatible\" it needs to allow building a vtable to allow the call \
|
||||
to be resolvable dynamically; for more information visit \
|
||||
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user