Skip to content

Commit bb4ab24

Browse files
committed
Match coercion
1 parent d982864 commit bb4ab24

File tree

7 files changed

+30
-47
lines changed

7 files changed

+30
-47
lines changed

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
185185

186186
let val = match *kind {
187187
mir::CastKind::Pointer(
188-
PointerCast::ReifyFnPointer | PointerCast::ReifyNotConstFnPointer,
188+
PointerCast::ReifyFnPointer,
189189
) => match *operand.layout.ty.kind() {
190190
ty::FnDef(def_id, substs) => {
191191
if bx.cx().tcx().has_attr(def_id, sym::rustc_args_required_const) {

compiler/rustc_middle/src/ty/adjustment.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ pub enum PointerCast {
1111
/// Go from a fn-item type to a fn-pointer type.
1212
ReifyFnPointer,
1313

14-
/// Go from a fn-item type to a not const fn-pointer type (drop const qualifier)
15-
ReifyNotConstFnPointer,
16-
1714
/// Go from a safe fn pointer to an unsafe fn pointer.
1815
UnsafeFnPointer,
1916

compiler/rustc_mir/src/borrow_check/type_check/mod.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,35 +2072,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20722072
}
20732073
}
20742074

2075-
CastKind::Pointer(PointerCast::ReifyNotConstFnPointer) => {
2076-
let fn_sig = op.ty(body, tcx).fn_sig(tcx);
2077-
2078-
// The type that we see in the fcx is like
2079-
// `foo::<'a, 'b>`, where `foo` is the path to a
2080-
// function definition. When we extract the
2081-
// signature, it comes from the `fn_sig` query,
2082-
// and hence may contain unnormalized results.
2083-
let fn_sig = self.normalize(fn_sig, location);
2084-
2085-
let ty_fn_ptr_from = tcx.mk_not_const_fn_ptr(fn_sig);
2086-
2087-
if let Err(terr) = self.eq_types(
2088-
ty_fn_ptr_from,
2089-
ty,
2090-
location.to_locations(),
2091-
ConstraintCategory::Cast,
2092-
) {
2093-
span_mirbug!(
2094-
self,
2095-
rvalue,
2096-
"equating {:?} with {:?} yields {:?}",
2097-
ty_fn_ptr_from,
2098-
ty,
2099-
terr
2100-
);
2101-
}
2102-
}
2103-
21042075
CastKind::Pointer(PointerCast::ClosureFnPointer(unsafety)) => {
21052076
let sig = match op.ty(body, tcx).kind() {
21062077
ty::Closure(_, substs) => substs.as_closure().sig(),

compiler/rustc_mir/src/interpret/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
4545
self.write_immediate(*v, dest)?;
4646
}
4747

48-
Pointer(PointerCast::ReifyFnPointer | PointerCast::ReifyNotConstFnPointer) => {
48+
Pointer(PointerCast::ReifyFnPointer) => {
4949
// The src operand does not matter, just its type
5050
match *src.layout.ty.kind() {
5151
ty::FnDef(def_id, substs) => {

compiler/rustc_mir/src/transform/check_consts/validation.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,6 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
557557
CastKind::Pointer(
558558
PointerCast::UnsafeFnPointer
559559
| PointerCast::ClosureFnPointer(_)
560-
| PointerCast::ReifyNotConstFnPointer
561560
| PointerCast::NotConstFnPointer
562561
| PointerCast::UnsafeNotConstFnPointer
563562
| PointerCast::ReifyFnPointer,

compiler/rustc_typeck/src/check/coercion.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
975975
(None, None)
976976
} else {
977977
match (&prev_ty.kind(), &new_ty.kind()) {
978-
(&ty::FnDef(..), &ty::FnDef(..)) => {
978+
(&ty::FnDef(..) | &ty::FnPtr(..), &ty::FnDef(..) | &ty::FnPtr(..)) => {
979979
// Don't reify if the function types have a LUB, i.e., they
980980
// are the same function and their parameters have a LUB.
981981
match self
@@ -1040,34 +1040,51 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10401040
// Reify both sides and return the reified fn pointer type.
10411041
let fn_ptr = self.tcx.mk_fn_ptr(sig);
10421042
let prev_adjustment = match prev_ty.kind() {
1043-
ty::Closure(..) => Adjust::Pointer(PointerCast::ClosureFnPointer(a_sig.unsafety())),
1043+
ty::Closure(..) => {
1044+
Some(Adjust::Pointer(PointerCast::ClosureFnPointer(a_sig.unsafety())))
1045+
}
10441046
ty::FnDef(..) => {
1047+
Some(Adjust::Pointer(PointerCast::ReifyFnPointer))
1048+
}
1049+
ty::FnPtr(..) => {
10451050
if prev_drop_const {
1046-
Adjust::Pointer(PointerCast::ReifyNotConstFnPointer)
1051+
Some(Adjust::Pointer(PointerCast::NotConstFnPointer))
10471052
} else {
1048-
Adjust::Pointer(PointerCast::ReifyFnPointer)
1053+
None
10491054
}
10501055
}
10511056
_ => unreachable!(),
10521057
};
10531058
let next_adjustment = match new_ty.kind() {
1054-
ty::Closure(..) => Adjust::Pointer(PointerCast::ClosureFnPointer(b_sig.unsafety())),
1059+
ty::Closure(..) => {
1060+
Some(Adjust::Pointer(PointerCast::ClosureFnPointer(b_sig.unsafety())))
1061+
}
10551062
ty::FnDef(..) => {
1063+
Some(Adjust::Pointer(PointerCast::ReifyFnPointer))
1064+
}
1065+
ty::FnPtr(..) => {
10561066
if new_drop_const {
1057-
Adjust::Pointer(PointerCast::ReifyNotConstFnPointer)
1067+
Some(Adjust::Pointer(PointerCast::NotConstFnPointer))
10581068
} else {
1059-
Adjust::Pointer(PointerCast::ReifyFnPointer)
1069+
None
10601070
}
10611071
}
10621072
_ => unreachable!(),
10631073
};
1064-
for expr in exprs.iter().map(|e| e.as_coercion_site()) {
1074+
if prev_adjustment.is_some() {
1075+
for expr in exprs.iter().map(|e| e.as_coercion_site()) {
1076+
self.apply_adjustments(
1077+
expr,
1078+
vec![Adjustment { kind: prev_adjustment.clone().unwrap().clone(), target: fn_ptr }],
1079+
);
1080+
}
1081+
}
1082+
if next_adjustment.is_some() {
10651083
self.apply_adjustments(
1066-
expr,
1067-
vec![Adjustment { kind: prev_adjustment.clone(), target: fn_ptr }],
1084+
new,
1085+
vec![Adjustment { kind: next_adjustment.unwrap(), target: fn_ptr }],
10681086
);
10691087
}
1070-
self.apply_adjustments(new, vec![Adjustment { kind: next_adjustment, target: fn_ptr }]);
10711088
return Ok(fn_ptr);
10721089
}
10731090

src/tools/clippy/clippy_lints/src/utils/qualify_min_const_fn.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ fn check_rvalue(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, rvalue: &Rv
152152
PointerCast::UnsafeFnPointer
153153
| PointerCast::ClosureFnPointer(_)
154154
| PointerCast::ReifyFnPointer
155-
| PointerCast::ReifyNotConstFnPointer
156155
| PointerCast::NotConstFnPointer
157156
| PointerCast::UnsafeNotConstFnPointer,
158157
),

0 commit comments

Comments
 (0)