Skip to content

Commit a215b7b

Browse files
committed
remove TypeError::ObjectUnsafeCoercion
1 parent 40a0533 commit a215b7b

File tree

4 files changed

+27
-56
lines changed

4 files changed

+27
-56
lines changed

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use rustc_span::def_id::{DefId, LOCAL_CRATE};
4646
use rustc_span::symbol::sym;
4747
use rustc_span::Span;
4848
use rustc_trait_selection::infer::InferCtxtExt;
49-
use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
5049

5150
/// Reifies a cast check to be checked once we have full type information for
5251
/// a function context.
@@ -727,9 +726,6 @@ impl<'a, 'tcx> CastCheck<'tcx> {
727726
debug!(" -> CoercionCast");
728727
fcx.typeck_results.borrow_mut().set_coercion_cast(self.expr.hir_id.local_id);
729728
}
730-
Err(ty::error::TypeError::ObjectUnsafeCoercion(did)) => {
731-
self.report_object_unsafe_cast(&fcx, did);
732-
}
733729
Err(_) => {
734730
match self.do_check(fcx) {
735731
Ok(k) => {
@@ -741,14 +737,6 @@ impl<'a, 'tcx> CastCheck<'tcx> {
741737
};
742738
}
743739
}
744-
745-
fn report_object_unsafe_cast(&self, fcx: &FnCtxt<'a, 'tcx>, did: DefId) {
746-
let violations = fcx.tcx.object_safety_violations(did);
747-
let mut err = report_object_safety_error(fcx.tcx, self.cast_span, did, violations);
748-
err.note(&format!("required by cast to type '{}'", fcx.ty_to_string(self.cast_ty)));
749-
err.emit();
750-
}
751-
752740
/// Checks a cast, and report an error if one exists. In some cases, this
753741
/// can return Ok and create type errors in the fcx rather than returning
754742
/// directly. coercion-cast is handled in check instead of here.

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
199199
debug!("coerce: unsize successful");
200200
return unsize;
201201
}
202-
Err(TypeError::ObjectUnsafeCoercion(did)) => {
203-
debug!("coerce: unsize not object safe");
204-
return Err(TypeError::ObjectUnsafeCoercion(did));
205-
}
206202
Err(error) => {
207203
debug!(?error, "coerce: unsize failed");
208204
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,40 +1677,34 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
16771677
}
16781678
};
16791679

1680-
match terr {
1681-
// Ignore msg for object safe coercion
1682-
// since E0038 message will be printed
1683-
TypeError::ObjectUnsafeCoercion(_) => {}
1684-
_ => {
1685-
let mut label_or_note = |span: Span, msg: &str| {
1686-
if (prefer_label && is_simple_error) || &[span] == diag.span.primary_spans() {
1687-
diag.span_label(span, msg);
1688-
} else {
1689-
diag.span_note(span, msg);
1690-
}
1691-
};
1692-
if let Some((sp, msg)) = secondary_span {
1693-
if swap_secondary_and_primary {
1694-
let terr = if let Some(infer::ValuePairs::Terms(infer::ExpectedFound {
1695-
expected,
1696-
..
1697-
})) = values
1698-
{
1699-
format!("expected this to be `{}`", expected)
1700-
} else {
1701-
terr.to_string()
1702-
};
1703-
label_or_note(sp, &terr);
1704-
label_or_note(span, &msg);
1705-
} else {
1706-
label_or_note(span, &terr.to_string());
1707-
label_or_note(sp, &msg);
1708-
}
1709-
} else {
1710-
label_or_note(span, &terr.to_string());
1711-
}
1680+
let mut label_or_note = |span: Span, msg: &str| {
1681+
if (prefer_label && is_simple_error) || &[span] == diag.span.primary_spans() {
1682+
diag.span_label(span, msg);
1683+
} else {
1684+
diag.span_note(span, msg);
17121685
}
17131686
};
1687+
if let Some((sp, msg)) = secondary_span {
1688+
if swap_secondary_and_primary {
1689+
let terr = if let Some(infer::ValuePairs::Terms(infer::ExpectedFound {
1690+
expected,
1691+
..
1692+
})) = values
1693+
{
1694+
format!("expected this to be `{}`", expected)
1695+
} else {
1696+
terr.to_string()
1697+
};
1698+
label_or_note(sp, &terr);
1699+
label_or_note(span, &msg);
1700+
} else {
1701+
label_or_note(span, &terr.to_string());
1702+
label_or_note(sp, &msg);
1703+
}
1704+
} else {
1705+
label_or_note(span, &terr.to_string());
1706+
}
1707+
17141708
if let Some((expected, found)) = expected_found {
17151709
let (expected_label, found_label, exp_found) = match exp_found {
17161710
Mismatch::Variable(ef) => (
@@ -1880,9 +1874,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
18801874
);
18811875
}
18821876
}
1883-
TypeError::ObjectUnsafeCoercion(_) => {
1884-
diag.note_unsuccessful_coercion(found, expected);
1885-
}
18861877
_ => {
18871878
debug!(
18881879
"note_type_err: exp_found={:?}, expected={:?} found={:?}",
@@ -3127,7 +3118,6 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
31273118
TypeError::IntrinsicCast => {
31283119
Error0308("cannot coerce intrinsics to function pointers")
31293120
}
3130-
TypeError::ObjectUnsafeCoercion(did) => Error0038(did),
31313121
_ => Error0308("mismatched types"),
31323122
},
31333123
}

compiler/rustc_middle/src/ty/error.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ pub enum TypeError<'tcx> {
7070
CyclicConst(ty::Const<'tcx>),
7171
ProjectionMismatched(ExpectedFound<DefId>),
7272
ExistentialMismatch(ExpectedFound<&'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>>),
73-
ObjectUnsafeCoercion(DefId),
7473
ConstMismatch(ExpectedFound<ty::Const<'tcx>>),
7574

7675
IntrinsicCast,
@@ -222,7 +221,6 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
222221
f,
223222
"cannot coerce functions with `#[target_feature]` to safe function pointers"
224223
),
225-
ObjectUnsafeCoercion(_) => write!(f, "coercion to object-unsafe trait object"),
226224
}
227225
}
228226
}
@@ -249,8 +247,7 @@ impl<'tcx> TypeError<'tcx> {
249247
| ProjectionMismatched(_)
250248
| ExistentialMismatch(_)
251249
| ConstMismatch(_)
252-
| IntrinsicCast
253-
| ObjectUnsafeCoercion(_) => true,
250+
| IntrinsicCast => true,
254251
}
255252
}
256253
}

0 commit comments

Comments
 (0)