Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5ce4d0d
Refresh of #94678
Mallets Mar 20, 2025
03aef02
Use IPv6 addresses in hop_limit_v6 docs
Mallets Mar 20, 2025
8962536
Add ui test cast-array-issue-138836
xizheyin Mar 26, 2025
a34c42f
Expect an array when expected and acutal types are both arrays during…
xizheyin Mar 26, 2025
5ace46a
Update tracking issue to 139166
Mallets Mar 31, 2025
8866af3
Add `naked_functions_rustic_abi` feature gate
folkertdev Mar 26, 2025
0a6e378
Report span of test when should_panic test failed
xizheyin Mar 17, 2025
ee3b557
Adjust test directives
xizheyin Apr 8, 2025
f20efc4
Handle `UnsafePointer` coercions in one place
oli-obk Apr 9, 2025
697768a
Simplify some `unify_and` calls
oli-obk Apr 9, 2025
804b6c9
Rename `unify` to `unify_raw`
oli-obk Apr 9, 2025
34258d6
Add a dedicated function for the common `unify_and(identity)` case
oli-obk Apr 9, 2025
3528a65
Deduplicate `target` type setting in `unify_and` callbacks
oli-obk Apr 9, 2025
673012f
Some performance shenanigans
oli-obk Apr 10, 2025
f80b121
Avoid some more duplication
oli-obk Apr 10, 2025
95ad6df
add `span_extend_to_prev_char_before()` to `SourceMap`
makai410 Apr 10, 2025
0069cad
Micro-optimize `InstSimplify`'s `simplify_primitive_clone`
yotamofek Apr 10, 2025
f97da85
suggest: remove redundant `$()?`around `vis` fragments
makai410 Apr 11, 2025
923f44c
consistent name for `UniversalRegions`
lcnr Apr 11, 2025
8cb7274
use input `def_id` to compute `movable_coroutine`
lcnr Apr 11, 2025
848187c
`local_names` creation to `mbcx` creation
lcnr Apr 11, 2025
0186459
do not buffer `#[rustc_regions]` dump
lcnr Apr 11, 2025
0e294f2
`MirBorrowckCtxt::polonius_output` to ref
lcnr Apr 11, 2025
2c65469
move `dump_polonius_mir`
lcnr Apr 11, 2025
c5fdddc
don't rely on `locals_are_invalidated_at_exit`
lcnr Apr 11, 2025
8303383
remove redundant fields
lcnr Apr 11, 2025
5d00483
`NonGenericOpaqueTypeParam::ty` to `arg`
lcnr Apr 11, 2025
420390c
eagerly initialize `definitions` in sub-fn
lcnr Apr 11, 2025
ac45a67
Use delayed bug for normalization errors in drop elaboration
matthewjasper Apr 4, 2025
c36e8fc
In `rustc_mir_tranform`, iterate over index newtypes instead of ints
yotamofek Apr 11, 2025
accae53
Move FlagComputation, PatternKind, and TypeWalker to rustc_type_ir
jackh726 Apr 8, 2025
16334cd
tests: convert `tests/ui/lint/dead-code/self-assign.rs` to known-bug
jieyouxu Apr 13, 2025
b203d40
compiletest: add `camino` for UTF-8 path handling
jieyouxu Apr 11, 2025
e24b0c8
compiletest: consistently use `{Utf8Path,Utf8PathBuf}`
jieyouxu Apr 11, 2025
957324b
rustdoc-gui-test: pass a `camino::Utf8PathBuf` to `compiletest`
jieyouxu Apr 12, 2025
25fb525
Update docs according to PR review
Mallets Mar 31, 2025
d96c85c
Rollup merge of #138603 - xizheyin:issue-137405, r=chenyukang
ChrisDenton Apr 13, 2025
ac13f79
Rollup merge of #138744 - Mallets:set_ipv6_sock_hop_limit, r=dtolnay
ChrisDenton Apr 13, 2025
eb51b5e
Rollup merge of #138962 - xizheyin:issue-138836, r=compiler-errors
ChrisDenton Apr 13, 2025
7b2411c
Rollup merge of #139001 - folkertdev:naked-function-rustic-abi, r=tra…
ChrisDenton Apr 13, 2025
90656e1
Rollup merge of #139379 - matthewjasper:drop-elab-normalization, r=co…
ChrisDenton Apr 13, 2025
67b84d7
Rollup merge of #139582 - oli-obk:coercion-cleanups, r=compiler-errors
ChrisDenton Apr 13, 2025
8c4e09d
Rollup merge of #139628 - makai410:suggest-vis, r=compiler-errors
ChrisDenton Apr 13, 2025
974dd7f
Rollup merge of #139644 - yotamofek:pr/mir_transform/instsimplify/sim…
ChrisDenton Apr 13, 2025
6874b2a
Rollup merge of #139666 - lcnr:pre-revealing-use-cleanup, r=compiler-…
ChrisDenton Apr 13, 2025
491edd2
Rollup merge of #139674 - yotamofek:pr/mir_transform/index-iterators,…
ChrisDenton Apr 13, 2025
eae35a9
Rollup merge of #139695 - jieyouxu:compiletest-utf8path, r=Kobzol
ChrisDenton Apr 13, 2025
3975cce
Rollup merge of #139722 - jackh726:patternkind-walk-toir, r=compiler-…
ChrisDenton Apr 13, 2025
451c508
Rollup merge of #139740 - jieyouxu:known-bug, r=nnethercote
ChrisDenton Apr 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle UnsafePointer coercions in one place
  • Loading branch information
oli-obk committed Apr 9, 2025
commit f20efc4c61a0d5deaf86988565a0214733ff0e6b
60 changes: 23 additions & 37 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
ty::FnPtr(a_sig_tys, a_hdr) => {
// We permit coercion of fn pointers to drop the
// unsafe qualifier.
self.coerce_from_fn_pointer(a, a_sig_tys.with(a_hdr), b)
self.coerce_from_fn_pointer(a_sig_tys.with(a_hdr), b)
}
ty::Closure(closure_def_id_a, args_a) => {
// Non-capturing closures are coercible to
Expand Down Expand Up @@ -813,18 +813,12 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
})
}

fn coerce_from_safe_fn<F, G>(
fn coerce_from_safe_fn(
&self,
a: Ty<'tcx>,
fn_ty_a: ty::PolyFnSig<'tcx>,
b: Ty<'tcx>,
to_unsafe: F,
normal: G,
) -> CoerceResult<'tcx>
where
F: FnOnce(Ty<'tcx>) -> Vec<Adjustment<'tcx>>,
G: FnOnce(Ty<'tcx>) -> Vec<Adjustment<'tcx>>,
{
adjustment: Option<Adjust>,
) -> CoerceResult<'tcx> {
self.commit_if_ok(|snapshot| {
let outer_universe = self.infcx.universe();

Expand All @@ -833,9 +827,22 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
&& hdr_b.safety.is_unsafe()
{
let unsafe_a = self.tcx.safe_to_unsafe_fn_ty(fn_ty_a);
self.unify_and(unsafe_a, b, to_unsafe)
self.unify_and(unsafe_a, b, |target| match adjustment {
Some(kind) => vec![
Adjustment { kind, target: Ty::new_fn_ptr(self.tcx, fn_ty_a) },
Adjustment {
kind: Adjust::Pointer(PointerCoercion::UnsafeFnPointer),
target,
},
],
None => simple(Adjust::Pointer(PointerCoercion::UnsafeFnPointer))(target),
})
} else {
self.unify_and(a, b, normal)
let a = Ty::new_fn_ptr(self.tcx, fn_ty_a);
self.unify_and(a, b, |target| match adjustment {
None => vec![],
Some(kind) => vec![Adjustment { kind, target }],
})
};

// FIXME(#73154): This is a hack. Currently LUB can generate
Expand All @@ -852,7 +859,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {

fn coerce_from_fn_pointer(
&self,
a: Ty<'tcx>,
fn_ty_a: ty::PolyFnSig<'tcx>,
b: Ty<'tcx>,
) -> CoerceResult<'tcx> {
Expand All @@ -861,15 +867,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
//!

let b = self.shallow_resolve(b);
debug!("coerce_from_fn_pointer(a={:?}, b={:?})", a, b);

self.coerce_from_safe_fn(
a,
fn_ty_a,
b,
simple(Adjust::Pointer(PointerCoercion::UnsafeFnPointer)),
identity,
)
debug!(?fn_ty_a, ?b, "coerce_from_fn_pointer");

self.coerce_from_safe_fn(fn_ty_a, b, None)
}

fn coerce_from_fn_item(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
Expand Down Expand Up @@ -916,24 +916,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
self.at(&self.cause, self.param_env).normalize(a_sig);
obligations.extend(o1);

let a_fn_pointer = Ty::new_fn_ptr(self.tcx, a_sig);
let InferOk { value, obligations: o2 } = self.coerce_from_safe_fn(
a_fn_pointer,
a_sig,
b,
|unsafe_ty| {
vec![
Adjustment {
kind: Adjust::Pointer(PointerCoercion::ReifyFnPointer),
target: a_fn_pointer,
},
Adjustment {
kind: Adjust::Pointer(PointerCoercion::UnsafeFnPointer),
target: unsafe_ty,
},
]
},
simple(Adjust::Pointer(PointerCoercion::ReifyFnPointer)),
Some(Adjust::Pointer(PointerCoercion::ReifyFnPointer)),
)?;

obligations.extend(o2);
Expand Down