Skip to content

Commit 7449912

Browse files
authored
Rollup merge of rust-lang#108950 - cjgillot:inherit-less, r=compiler-errors
Directly construct Inherited in typeck. Using `InheritedBuilder` + a closure does not seem necessary any more. + a few opportunistic simplifications to typeck entry point.
2 parents 7333b36 + 5c85cd9 commit 7449912

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

clippy_lints/src/methods/unnecessary_to_owned.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,10 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
369369
Node::Item(item) => {
370370
if let ItemKind::Fn(_, _, body_id) = &item.kind
371371
&& let output_ty = return_ty(cx, item.owner_id)
372-
&& Inherited::build(cx.tcx, item.owner_id.def_id).enter(|inherited| {
373-
let fn_ctxt = FnCtxt::new(inherited, cx.param_env, item.owner_id.def_id);
374-
fn_ctxt.can_coerce(ty, output_ty)
375-
}) {
372+
&& let inherited = Inherited::new(cx.tcx, item.owner_id.def_id)
373+
&& let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, item.owner_id.def_id)
374+
&& fn_ctxt.can_coerce(ty, output_ty)
375+
{
376376
if has_lifetime(output_ty) && has_lifetime(ty) {
377377
return false;
378378
}

clippy_lints/src/transmute/utils.rs

+28-29
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,37 @@ pub(super) fn check_cast<'tcx>(
3333
let hir_id = e.hir_id;
3434
let local_def_id = hir_id.owner.def_id;
3535

36-
Inherited::build(cx.tcx, local_def_id).enter(|inherited| {
37-
let fn_ctxt = FnCtxt::new(inherited, cx.param_env, local_def_id);
36+
let inherited = Inherited::new(cx.tcx, local_def_id);
37+
let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, local_def_id);
3838

39-
// If we already have errors, we can't be sure we can pointer cast.
39+
// If we already have errors, we can't be sure we can pointer cast.
40+
assert!(
41+
!fn_ctxt.errors_reported_since_creation(),
42+
"Newly created FnCtxt contained errors"
43+
);
44+
45+
if let Ok(check) = cast::CastCheck::new(
46+
&fn_ctxt,
47+
e,
48+
from_ty,
49+
to_ty,
50+
// We won't show any error to the user, so we don't care what the span is here.
51+
DUMMY_SP,
52+
DUMMY_SP,
53+
hir::Constness::NotConst,
54+
) {
55+
let res = check.do_check(&fn_ctxt);
56+
57+
// do_check's documentation says that it might return Ok and create
58+
// errors in the fcx instead of returning Err in some cases. Those cases
59+
// should be filtered out before getting here.
4060
assert!(
4161
!fn_ctxt.errors_reported_since_creation(),
42-
"Newly created FnCtxt contained errors"
62+
"`fn_ctxt` contained errors after cast check!"
4363
);
4464

45-
if let Ok(check) = cast::CastCheck::new(
46-
&fn_ctxt,
47-
e,
48-
from_ty,
49-
to_ty,
50-
// We won't show any error to the user, so we don't care what the span is here.
51-
DUMMY_SP,
52-
DUMMY_SP,
53-
hir::Constness::NotConst,
54-
) {
55-
let res = check.do_check(&fn_ctxt);
56-
57-
// do_check's documentation says that it might return Ok and create
58-
// errors in the fcx instead of returning Err in some cases. Those cases
59-
// should be filtered out before getting here.
60-
assert!(
61-
!fn_ctxt.errors_reported_since_creation(),
62-
"`fn_ctxt` contained errors after cast check!"
63-
);
64-
65-
res.ok()
66-
} else {
67-
None
68-
}
69-
})
65+
res.ok()
66+
} else {
67+
None
68+
}
7069
}

0 commit comments

Comments
 (0)