Skip to content

Commit ce82fa4

Browse files
authored
Rollup merge of rust-lang#123625 - oli-obk:private_fnctxt, r=fee1-dead
Stop exporting `TypeckRootCtxt` and `FnCtxt`. While they have many convenient APIs, it is better to expose dedicated functions for them noticed in rust-lang#122213
2 parents 4daaf19 + 02b5e1a commit ce82fa4

File tree

3 files changed

+3
-43
lines changed

3 files changed

+3
-43
lines changed

clippy_lints/src/methods/unnecessary_to_owned.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_errors::Applicability;
1212
use rustc_hir::def::{DefKind, Res};
1313
use rustc_hir::def_id::DefId;
1414
use rustc_hir::{BorrowKind, Expr, ExprKind, ItemKind, LangItem, Node};
15-
use rustc_hir_typeck::{FnCtxt, TypeckRootCtxt};
1615
use rustc_infer::infer::TyCtxtInferExt;
1716
use rustc_lint::LateContext;
1817
use rustc_middle::mir::Mutability;
@@ -437,9 +436,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
437436
Node::Item(item) => {
438437
if let ItemKind::Fn(_, _, body_id) = &item.kind
439438
&& let output_ty = return_ty(cx, item.owner_id)
440-
&& let root_ctxt = TypeckRootCtxt::new(cx.tcx, item.owner_id.def_id)
441-
&& let fn_ctxt = FnCtxt::new(&root_ctxt, cx.param_env, item.owner_id.def_id)
442-
&& fn_ctxt.can_coerce(ty, output_ty)
439+
&& rustc_hir_typeck::can_coerce(cx.tcx, cx.param_env, item.owner_id.def_id, ty, output_ty)
443440
{
444441
if has_lifetime(output_ty) && has_lifetime(ty) {
445442
return false;

clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::utils::check_cast;
1+
use rustc_hir_typeck::cast::check_cast;
22
use super::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS;
33
use clippy_utils::diagnostics::span_lint_and_sugg;
44
use clippy_utils::sugg::Sugg;
@@ -22,7 +22,7 @@ pub(super) fn check<'tcx>(
2222
) -> bool {
2323
use CastKind::{AddrPtrCast, ArrayPtrCast, FnPtrAddrCast, FnPtrPtrCast, PtrAddrCast, PtrPtrCast};
2424
let mut app = Applicability::MachineApplicable;
25-
let mut sugg = match check_cast(cx, e, from_ty, to_ty) {
25+
let mut sugg = match check_cast(cx.tcx, cx.param_env, e, from_ty, to_ty) {
2626
Some(FnPtrAddrCast | PtrAddrCast) if const_context => return false,
2727
Some(PtrPtrCast | AddrPtrCast | ArrayPtrCast | FnPtrPtrCast | FnPtrAddrCast) => {
2828
Sugg::hir_with_context(cx, arg, e.span.ctxt(), "..", &mut app)

clippy_lints/src/transmute/utils.rs

-37
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
use rustc_hir as hir;
2-
use rustc_hir::Expr;
3-
use rustc_hir_typeck::{cast, FnCtxt, TypeckRootCtxt};
41
use rustc_lint::LateContext;
5-
use rustc_middle::ty::cast::CastKind;
62
use rustc_middle::ty::Ty;
7-
use rustc_span::DUMMY_SP;
83

94
// check if the component types of the transmuted collection and the result have different ABI,
105
// size or alignment
@@ -20,35 +15,3 @@ pub(super) fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx
2015
false
2116
}
2217
}
23-
24-
/// If a cast from `from_ty` to `to_ty` is valid, returns an Ok containing the kind of
25-
/// the cast. In certain cases, including some invalid casts from array references
26-
/// to pointers, this may cause additional errors to be emitted and/or ICE error
27-
/// messages. This function will panic if that occurs.
28-
pub(super) fn check_cast<'tcx>(
29-
cx: &LateContext<'tcx>,
30-
e: &'tcx Expr<'_>,
31-
from_ty: Ty<'tcx>,
32-
to_ty: Ty<'tcx>,
33-
) -> Option<CastKind> {
34-
let hir_id = e.hir_id;
35-
let local_def_id = hir_id.owner.def_id;
36-
37-
let root_ctxt = TypeckRootCtxt::new(cx.tcx, local_def_id);
38-
let fn_ctxt = FnCtxt::new(&root_ctxt, cx.param_env, local_def_id);
39-
40-
if let Ok(check) = cast::CastCheck::new(
41-
&fn_ctxt,
42-
e,
43-
from_ty,
44-
to_ty,
45-
// We won't show any error to the user, so we don't care what the span is here.
46-
DUMMY_SP,
47-
DUMMY_SP,
48-
hir::Constness::NotConst,
49-
) {
50-
check.do_check(&fn_ctxt).ok()
51-
} else {
52-
None
53-
}
54-
}

0 commit comments

Comments
 (0)