Skip to content

Commit 0cb217d

Browse files
Remove CastCheckResult since it's unused
1 parent feb4244 commit 0cb217d

File tree

3 files changed

+22
-38
lines changed

3 files changed

+22
-38
lines changed

Diff for: compiler/rustc_hir_analysis/src/check/cast.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -203,28 +203,8 @@ fn make_invalid_casting_error<'a, 'tcx>(
203203
)
204204
}
205205

206-
pub enum CastCheckResult<'tcx> {
207-
Ok,
208-
Deferred(CastCheck<'tcx>),
209-
Err(ErrorGuaranteed),
210-
}
211-
212-
pub fn check_cast<'tcx>(
213-
fcx: &FnCtxt<'_, 'tcx>,
214-
expr: &'tcx hir::Expr<'tcx>,
215-
expr_ty: Ty<'tcx>,
216-
cast_ty: Ty<'tcx>,
217-
cast_span: Span,
218-
span: Span,
219-
) -> CastCheckResult<'tcx> {
220-
match CastCheck::new(fcx, expr, expr_ty, cast_ty, cast_span, span) {
221-
Ok(check) => CastCheckResult::Deferred(check),
222-
Err(e) => CastCheckResult::Err(e),
223-
}
224-
}
225-
226206
impl<'a, 'tcx> CastCheck<'tcx> {
227-
fn new(
207+
pub fn new(
228208
fcx: &FnCtxt<'a, 'tcx>,
229209
expr: &'tcx hir::Expr<'tcx>,
230210
expr_ty: Ty<'tcx>,

Diff for: compiler/rustc_hir_analysis/src/check/expr.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! See `mod.rs` for more context on type checking in general.
44
55
use crate::astconv::AstConv as _;
6-
use crate::check::cast::{self, CastCheckResult};
6+
use crate::check::cast;
77
use crate::check::coercion::CoerceMany;
88
use crate::check::fatally_break_rust;
99
use crate::check::method::SelfSource;
@@ -1270,17 +1270,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12701270
} else {
12711271
// Defer other checks until we're done type checking.
12721272
let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
1273-
match cast::check_cast(self, e, t_expr, t_cast, t.span, expr.span) {
1274-
CastCheckResult::Ok => t_cast,
1275-
CastCheckResult::Deferred(cast_check) => {
1273+
match cast::CastCheck::new(self, e, t_expr, t_cast, t.span, expr.span) {
1274+
Ok(cast_check) => {
12761275
debug!(
12771276
"check_expr_cast: deferring cast from {:?} to {:?}: {:?}",
12781277
t_cast, t_expr, cast_check,
12791278
);
12801279
deferred_cast_checks.push(cast_check);
12811280
t_cast
12821281
}
1283-
CastCheckResult::Err(ErrorGuaranteed { .. }) => self.tcx.ty_error(),
1282+
Err(_) => self.tcx.ty_error(),
12841283
}
12851284
}
12861285
}

Diff for: src/tools/clippy/clippy_lints/src/transmute/utils.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
use rustc_hir::Expr;
2-
use rustc_hir_analysis::check::{
3-
cast::{self, CastCheckResult},
4-
FnCtxt, Inherited,
5-
};
2+
use rustc_hir_analysis::check::{cast, FnCtxt, Inherited};
63
use rustc_lint::LateContext;
74
use rustc_middle::ty::{cast::CastKind, Ty};
85
use rustc_span::DUMMY_SP;
96

107
// check if the component types of the transmuted collection and the result have different ABI,
118
// size or alignment
12-
pub(super) fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<'tcx>) -> bool {
9+
pub(super) fn is_layout_incompatible<'tcx>(
10+
cx: &LateContext<'tcx>,
11+
from: Ty<'tcx>,
12+
to: Ty<'tcx>,
13+
) -> bool {
1314
if let Ok(from) = cx.tcx.try_normalize_erasing_regions(cx.param_env, from)
1415
&& let Ok(to) = cx.tcx.try_normalize_erasing_regions(cx.param_env, to)
1516
&& let Ok(from_layout) = cx.tcx.layout_of(cx.param_env.and(from))
@@ -32,7 +33,9 @@ pub(super) fn can_be_expressed_as_pointer_cast<'tcx>(
3233
from_ty: Ty<'tcx>,
3334
to_ty: Ty<'tcx>,
3435
) -> bool {
35-
use CastKind::{AddrPtrCast, ArrayPtrCast, FnPtrAddrCast, FnPtrPtrCast, PtrAddrCast, PtrPtrCast};
36+
use CastKind::{
37+
AddrPtrCast, ArrayPtrCast, FnPtrAddrCast, FnPtrPtrCast, PtrAddrCast, PtrPtrCast,
38+
};
3639
matches!(
3740
check_cast(cx, e, from_ty, to_ty),
3841
Some(PtrPtrCast | PtrAddrCast | AddrPtrCast | ArrayPtrCast | FnPtrPtrCast | FnPtrAddrCast)
@@ -43,20 +46,22 @@ pub(super) fn can_be_expressed_as_pointer_cast<'tcx>(
4346
/// the cast. In certain cases, including some invalid casts from array references
4447
/// to pointers, this may cause additional errors to be emitted and/or ICE error
4548
/// messages. This function will panic if that occurs.
46-
fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> Option<CastKind> {
49+
fn check_cast<'tcx>(
50+
cx: &LateContext<'tcx>,
51+
e: &'tcx Expr<'_>,
52+
from_ty: Ty<'tcx>,
53+
to_ty: Ty<'tcx>,
54+
) -> Option<CastKind> {
4755
let hir_id = e.hir_id;
4856
let local_def_id = hir_id.owner.def_id;
4957

5058
Inherited::build(cx.tcx, local_def_id).enter(|inherited| {
5159
let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, hir_id);
5260

5361
// If we already have errors, we can't be sure we can pointer cast.
54-
assert!(
55-
!fn_ctxt.errors_reported_since_creation(),
56-
"Newly created FnCtxt contained errors"
57-
);
62+
assert!(!fn_ctxt.errors_reported_since_creation(), "Newly created FnCtxt contained errors");
5863

59-
if let CastCheckResult::Deferred(check) = cast::check_cast(
64+
if let Ok(check) = cast::CastCheck::new(
6065
&fn_ctxt, e, from_ty, to_ty,
6166
// We won't show any error to the user, so we don't care what the span is here.
6267
DUMMY_SP, DUMMY_SP,

0 commit comments

Comments
 (0)