Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 20 pull requests #126653

Closed
wants to merge 53 commits into from
Closed
Changes from 3 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
012a458
Suggest removing unused tuple fields if they are the last fields
May 13, 2024
1e9cd07
Allow constraining opaque types during subtyping in the trait system
oli-obk May 27, 2024
586821e
tip for inaccessible traits
bvanjoi Jun 1, 2024
05b7b46
fix: break inside async closure has incorrect span for enclosing closure
linyihai May 13, 2024
9b05e15
StorageLive: refresh storage (instead of UB) when local is already live
RalfJung Jun 8, 2024
408c8eb
add Miri tests
RalfJung Jun 14, 2024
22d0b1e
delegation: Implement glob delegation
petrochenkov Mar 15, 2024
df1d616
safe transmute: support non-ZST, variantful, uninhabited enums
jswrenn Jun 14, 2024
55fc6bd
Ban `ArrayToPointer` and `MutToConstPointer` from runtime MIR
scottmcm Jun 12, 2024
64bba35
`bug!` more uses of these in runtime stuff
scottmcm Jun 15, 2024
ab0e727
Suggest standalone doctest for non-local impl defs
Urgau Jun 13, 2024
94c2821
Also simplify macro_rules doctest code
Urgau Jun 13, 2024
6b84d75
Add tests
Nadrieril Mar 3, 2024
e74b30e
Tweak simple or-pattern expansion
Nadrieril Mar 20, 2024
5fe2ca6
Always set `otherwise_block`s
Nadrieril Mar 3, 2024
764f086
Use `otherwise_block` for or-pattern shortcutting
Nadrieril Mar 4, 2024
ce374fc
Factor out `finalize_or_candidate`
Nadrieril Mar 20, 2024
7b764be
Expand or-candidates mixed with candidates above
Nadrieril Mar 20, 2024
207c5bc
override user defined channel when using precompiled rustc
onur-ozkan Jun 17, 2024
5ae2446
simplify `Builder::doc_rust_lang_org_channel`
onur-ozkan Jun 17, 2024
6f5b0ef
Add badboy and BlackHoleFox as Mac Catalyst maintainers
madsmtm Jun 17, 2024
b7c2376
Sync fuchsia test runner with clang test runner
erickt May 31, 2024
0f8c3f7
tail expression behind terminating scope
dingxiangfei2009 Apr 12, 2024
475b63f
Add `/rustc-ice*/ to `.gitignore`
tgross35 Jun 18, 2024
af10880
Make async drop code more consistent with regular drop code
zetanumbers Jun 17, 2024
1a8eae1
Apply suggestions from oli-obk's review
zetanumbers Jun 18, 2024
7321e79
Replace `move||` with `move ||` in `compiler/` and `library/`
Vonr Jun 18, 2024
de473a5
Test that opaque types can't have themselves as a hidden type with in…
oli-obk Apr 11, 2024
83cb760
run_make_support nm implementation + bin-emit-no-symbols rmake rewrite
Oneirical May 30, 2024
c1597f9
try implementing suggestions
Oneirical Jun 5, 2024
977d3f6
use llvm_readobj in run-make test instead of nm
Oneirical Jun 18, 2024
bfe6a26
hir_typeck: be more conservative in making "note caller chooses ty pa…
jieyouxu Jun 18, 2024
939026c
tests: update tests for more conservative return ty mismatch note
jieyouxu Jun 16, 2024
e7eb75b
Rollup merge of #123782 - oli-obk:equal_tait_args, r=compiler-errors
jieyouxu Jun 19, 2024
4d2b4ab
Rollup merge of #124135 - petrochenkov:deleglob, r=fmease
jieyouxu Jun 19, 2024
33699c2
Rollup merge of #124580 - gurry:124556-suggest-remove-tuple-field, r=…
jieyouxu Jun 19, 2024
c5009dd
Rollup merge of #125078 - linyihai:issue-124496, r=compiler-errors
jieyouxu Jun 19, 2024
2bae32a
Rollup merge of #125293 - dingxiangfei2009:tail-expr-temp-lifetime, r…
jieyouxu Jun 19, 2024
51ca222
Rollup merge of #125447 - oli-obk:eq_opaque_pred, r=compiler-errors
jieyouxu Jun 19, 2024
03032b8
Rollup merge of #125787 - Oneirical:infinite-test-a-novel, r=jieyouxu
jieyouxu Jun 19, 2024
aad1f30
Rollup merge of #125852 - bvanjoi:improve-tip-for-invisible-trait, r=…
jieyouxu Jun 19, 2024
1381b0c
Rollup merge of #126154 - RalfJung:storage-live, r=compiler-errors
jieyouxu Jun 19, 2024
fe0db03
Rollup merge of #126308 - scottmcm:ban-some-coercions, r=saethlin
jieyouxu Jun 19, 2024
fedd86f
Rollup merge of #126422 - Urgau:doctest-impl-non-local-def, r=fmease
jieyouxu Jun 19, 2024
e0ce50b
Rollup merge of #126493 - jswrenn:fix-126460, r=compiler-errors
jieyouxu Jun 19, 2024
da963d6
Rollup merge of #126504 - erickt:bump-fuchsia, r=tmandry
jieyouxu Jun 19, 2024
b32d9ef
Rollup merge of #126553 - Nadrieril:expand-or-pat-into-above, r=matth…
jieyouxu Jun 19, 2024
5ec5dda
Rollup merge of #126558 - jieyouxu:caller-chooses-ty, r=fmease
jieyouxu Jun 19, 2024
187fe5b
Rollup merge of #126572 - onur-ozkan:channel-problem, r=clubby789
jieyouxu Jun 19, 2024
c4712a0
Rollup merge of #126586 - madsmtm:mac-catalyst-maintainers, r=Nilstrieb
jieyouxu Jun 19, 2024
8c38b6a
Rollup merge of #126594 - zetanumbers:fix-cross-crate-async-drop-glue…
jieyouxu Jun 19, 2024
00df302
Rollup merge of #126615 - tgross35:gitignore-ice, r=compiler-errors
jieyouxu Jun 19, 2024
68e12d3
Rollup merge of #126632 - Vonr:fix/moving-closure-formatting-v2, r=Ni…
jieyouxu Jun 19, 2024
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
21 changes: 11 additions & 10 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
@@ -677,21 +677,22 @@ fn codegen_stmt<'tcx>(
CastKind::PointerCoercion(PointerCoercion::UnsafeFnPointer),
ref operand,
to_ty,
)
| Rvalue::Cast(
CastKind::PointerCoercion(PointerCoercion::MutToConstPointer),
ref operand,
to_ty,
)
| Rvalue::Cast(
CastKind::PointerCoercion(PointerCoercion::ArrayToPointer),
ref operand,
to_ty,
) => {
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
let operand = codegen_operand(fx, operand);
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
}
Rvalue::Cast(
CastKind::PointerCoercion(
PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer,
),
..,
) => {
bug!(
"{:?} is for borrowck, and should never appear in codegen",
to_place_and_rval.1
);
}
Rvalue::Cast(
CastKind::IntToInt
| CastKind::FloatToFloat
11 changes: 6 additions & 5 deletions compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
@@ -456,8 +456,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
base::unsize_ptr(bx, lldata, operand.layout.ty, cast.ty, llextra);
OperandValue::Pair(lldata, llextra)
}
mir::CastKind::PointerCoercion(PointerCoercion::MutToConstPointer)
| mir::CastKind::PtrToPtr
mir::CastKind::PointerCoercion(
PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer,
) => {
bug!("{kind:?} is for borrowck, and should never appear in codegen");
}
mir::CastKind::PtrToPtr
if bx.cx().is_backend_scalar_pair(operand.layout) =>
{
if let OperandValue::Pair(data_ptr, meta) = operand.val {
@@ -477,9 +481,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
base::cast_to_dyn_star(bx, lldata, operand.layout, cast.ty, llextra);
OperandValue::Pair(lldata, llextra)
}
mir::CastKind::PointerCoercion(
PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer,
)
| mir::CastKind::IntToInt
| mir::CastKind::FloatToInt
| mir::CastKind::FloatToFloat
4 changes: 1 addition & 3 deletions compiler/rustc_const_eval/src/interpret/cast.rs
Original file line number Diff line number Diff line change
@@ -70,9 +70,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
CastKind::PointerCoercion(
PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer,
) => {
// These are NOPs, but can be wide pointers.
let v = self.read_immediate(src)?;
self.write_immediate(*v, dest)?;
bug!("{cast_kind:?} casts are for borrowck only, not runtime MIR");
}

CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer) => {
13 changes: 11 additions & 2 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
@@ -127,6 +127,9 @@ pub enum AnalysisPhase {
/// * [`StatementKind::AscribeUserType`]
/// * [`StatementKind::Coverage`] with [`CoverageKind::BlockMarker`] or [`CoverageKind::SpanMarker`]
/// * [`Rvalue::Ref`] with `BorrowKind::Fake`
/// * [`CastKind::PointerCoercion`] with any of the following:
/// * [`PointerCoercion::ArrayToPointer`]
/// * [`PointerCoercion::MutToConstPointer`]
///
/// Furthermore, `Deref` projections must be the first projection within any place (if they
/// appear at all)
@@ -1284,8 +1287,7 @@ pub enum Rvalue<'tcx> {
///
/// This allows for casts from/to a variety of types.
///
/// **FIXME**: Document exactly which `CastKind`s allow which types of casts. Figure out why
/// `ArrayToPointer` and `MutToConstPointer` are special.
/// **FIXME**: Document exactly which `CastKind`s allow which types of casts.
Cast(CastKind, Operand<'tcx>, Ty<'tcx>),

/// * `Offset` has the same semantics as [`offset`](pointer::offset), except that the second
@@ -1365,6 +1367,13 @@ pub enum CastKind {
PointerWithExposedProvenance,
/// Pointer related casts that are done by coercions. Note that reference-to-raw-ptr casts are
/// translated into `&raw mut/const *r`, i.e., they are not actually casts.
///
/// The following are allowed in [`AnalysisPhase::Initial`] as they're needed for borrowck,
/// but after that are forbidden (including in all phases of runtime MIR):
/// * [`PointerCoercion::ArrayToPointer`]
/// * [`PointerCoercion::MutToConstPointer`]
///
/// Both are runtime nops, so should be [`CastKind::PtrToPtr`] instead in runtime MIR.
PointerCoercion(PointerCoercion),
/// Cast into a dyn* object.
DynStar,
19 changes: 18 additions & 1 deletion compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,8 @@

use crate::MirPass;
use rustc_middle::mir::coverage::CoverageKind;
use rustc_middle::mir::{Body, BorrowKind, Rvalue, StatementKind, TerminatorKind};
use rustc_middle::mir::{Body, BorrowKind, CastKind, Rvalue, StatementKind, TerminatorKind};
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::TyCtxt;

pub struct CleanupPostBorrowck;
@@ -36,6 +37,22 @@ impl<'tcx> MirPass<'tcx> for CleanupPostBorrowck {
CoverageKind::BlockMarker { .. } | CoverageKind::SpanMarker { .. },
)
| StatementKind::FakeRead(..) => statement.make_nop(),
StatementKind::Assign(box (
_,
Rvalue::Cast(
ref mut cast_kind @ CastKind::PointerCoercion(
PointerCoercion::ArrayToPointer
| PointerCoercion::MutToConstPointer,
),
..,
),
)) => {
// BorrowCk needed to track whether these cases were coercions or casts,
// to know whether to check lifetimes in their pointees,
// but from now on that distinction doesn't matter,
// so just make them ordinary pointer casts instead.
*cast_kind = CastKind::PtrToPtr;
}
_ => (),
}
}
10 changes: 3 additions & 7 deletions compiler/rustc_mir_transform/src/gvn.rs
Original file line number Diff line number Diff line change
@@ -571,11 +571,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
let ret = self.ecx.ptr_to_ptr(&src, to).ok()?;
ret.into()
}
CastKind::PointerCoercion(
ty::adjustment::PointerCoercion::MutToConstPointer
| ty::adjustment::PointerCoercion::ArrayToPointer
| ty::adjustment::PointerCoercion::UnsafeFnPointer,
) => {
CastKind::PointerCoercion(ty::adjustment::PointerCoercion::UnsafeFnPointer) => {
let src = self.evaluated[value].as_ref()?;
let src = self.ecx.read_immediate(src).ok()?;
let to = self.ecx.layout_of(to).ok()?;
@@ -1164,10 +1160,10 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
}
}

if let PtrToPtr | PointerCoercion(MutToConstPointer) = kind
if let PtrToPtr = kind
&& let Value::Cast { kind: inner_kind, value: inner_value, from: inner_from, to: _ } =
*self.get(value)
&& let PtrToPtr | PointerCoercion(MutToConstPointer) = inner_kind
&& let PtrToPtr = inner_kind
{
from = inner_from;
value = inner_value;
6 changes: 3 additions & 3 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
@@ -51,11 +51,11 @@ mod abort_unwinding_calls;
mod add_call_guards;
mod add_moves_for_packed_drops;
mod add_retag;
mod add_subtyping_projections;
mod check_alignment;
mod check_const_item_mutation;
mod check_packed_ref;
mod remove_place_mention;
// This pass is public to allow external drivers to perform MIR cleanup
mod add_subtyping_projections;
pub mod cleanup_post_borrowck;
mod copy_prop;
mod coroutine;
@@ -94,6 +94,7 @@ mod prettify;
mod promote_consts;
mod ref_prop;
mod remove_noop_landing_pads;
mod remove_place_mention;
mod remove_storage_markers;
mod remove_uninit_drops;
mod remove_unneeded_drops;
@@ -103,7 +104,6 @@ mod reveal_all;
mod shim;
mod ssa;
// This pass is public to allow external drivers to perform MIR cleanup
mod check_alignment;
pub mod simplify;
mod simplify_branches;
mod simplify_comparison_integral;
8 changes: 7 additions & 1 deletion compiler/rustc_mir_transform/src/validate.rs
Original file line number Diff line number Diff line change
@@ -1188,6 +1188,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
"CastKind::{kind:?} output must be a raw const pointer, not {:?}",
ty::RawPtr(_, Mutability::Not)
);
if self.mir_phase >= MirPhase::Analysis(AnalysisPhase::PostCleanup) {
self.fail(location, format!("After borrowck, MIR disallows {kind:?}"));
}
}
CastKind::PointerCoercion(PointerCoercion::ArrayToPointer) => {
// FIXME: Check pointee types
@@ -1201,6 +1204,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
"CastKind::{kind:?} output must be a raw pointer, not {:?}",
ty::RawPtr(..)
);
if self.mir_phase >= MirPhase::Analysis(AnalysisPhase::PostCleanup) {
self.fail(location, format!("After borrowck, MIR disallows {kind:?}"));
}
}
CastKind::PointerCoercion(PointerCoercion::Unsize) => {
// This is used for all `CoerceUnsized` types,
@@ -1212,7 +1218,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
if !input_valid || !target_valid {
self.fail(
location,
format!("Wrong cast kind {kind:?} for the type {op_ty}",),
format!("Wrong cast kind {kind:?} for the type {op_ty}"),
);
}
}
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@

bb4: {
StorageDead(_8);
- _11 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
- _11 = _6 as *const [bool; 0] (PtrToPtr);
- _5 = NonNull::<[bool; 0]> { pointer: _11 };
+ _11 = const {0x1 as *const [bool; 0]};
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@

bb5: {
StorageDead(_8);
- _11 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
- _11 = _6 as *const [bool; 0] (PtrToPtr);
- _5 = NonNull::<[bool; 0]> { pointer: _11 };
+ _11 = const {0x1 as *const [bool; 0]};
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@

bb4: {
StorageDead(_8);
- _11 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
- _11 = _6 as *const [bool; 0] (PtrToPtr);
- _5 = NonNull::<[bool; 0]> { pointer: _11 };
+ _11 = const {0x1 as *const [bool; 0]};
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@

bb5: {
StorageDead(_8);
- _11 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
- _11 = _6 as *const [bool; 0] (PtrToPtr);
- _5 = NonNull::<[bool; 0]> { pointer: _11 };
+ _11 = const {0x1 as *const [bool; 0]};
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
StorageLive(_4);
_4 = _1;
_3 = move _4 as *mut u8 (PtrToPtr);
_2 = move _3 as *const u8 (PointerCoercion(MutToConstPointer));
_2 = move _3 as *const u8 (PtrToPtr);
StorageDead(_4);
StorageDead(_3);
- _0 = move _2 as *const u8 (PtrToPtr);
2 changes: 1 addition & 1 deletion tests/mir-opt/instsimplify/casts.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ pub fn roundtrip(x: *const u8) -> *const u8 {
// CHECK-LABEL: fn roundtrip(
// CHECK: _4 = _1;
// CHECK: _3 = move _4 as *mut u8 (PtrToPtr);
// CHECK: _2 = move _3 as *const u8 (PointerCoercion(MutToConstPointer));
// CHECK: _2 = move _3 as *const u8 (PtrToPtr);
x as *mut u8 as *const u8
}

Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
_7 = _4 as *mut T (PtrToPtr);
_8 = Offset(_7, _3);
StorageDead(_7);
_9 = move _8 as *const T (PointerCoercion(MutToConstPointer));
_9 = move _8 as *const T (PtrToPtr);
StorageDead(_8);
goto -> bb3;
}
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
_7 = _4 as *mut T (PtrToPtr);
_8 = Offset(_7, _3);
StorageDead(_7);
_9 = move _8 as *const T (PointerCoercion(MutToConstPointer));
_9 = move _8 as *const T (PtrToPtr);
StorageDead(_8);
goto -> bb3;
}
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
_7 = _4 as *mut T (PtrToPtr);
_8 = Offset(_7, _3);
StorageDead(_7);
_9 = move _8 as *const T (PointerCoercion(MutToConstPointer));
_9 = move _8 as *const T (PtrToPtr);
StorageDead(_8);
goto -> bb3;
}
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
_7 = _4 as *mut T (PtrToPtr);
_8 = Offset(_7, _3);
StorageDead(_7);
_9 = move _8 as *const T (PointerCoercion(MutToConstPointer));
_9 = move _8 as *const T (PtrToPtr);
StorageDead(_8);
goto -> bb3;
}
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
_7 = _4 as *mut T (PtrToPtr);
_8 = Offset(_7, _3);
StorageDead(_7);
_9 = move _8 as *const T (PointerCoercion(MutToConstPointer));
_9 = move _8 as *const T (PtrToPtr);
StorageDead(_8);
goto -> bb3;
}
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
_7 = _4 as *mut T (PtrToPtr);
_8 = Offset(_7, _3);
StorageDead(_7);
_9 = move _8 as *const T (PointerCoercion(MutToConstPointer));
_9 = move _8 as *const T (PtrToPtr);
StorageDead(_8);
goto -> bb3;
}
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ fn array_casts() -> () {
StorageLive(_4);
_4 = &mut _1;
_3 = &raw mut (*_4);
_2 = move _3 as *mut usize (PointerCoercion(ArrayToPointer));
_2 = move _3 as *mut usize (PtrToPtr);
StorageDead(_3);
StorageDead(_4);
StorageLive(_5);
@@ -87,7 +87,7 @@ fn array_casts() -> () {
StorageLive(_11);
_11 = &_8;
_10 = &raw const (*_11);
_9 = move _10 as *const usize (PointerCoercion(ArrayToPointer));
_9 = move _10 as *const usize (PtrToPtr);
StorageDead(_10);
StorageDead(_11);
StorageLive(_12);
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ fn array_casts() -> () {
StorageLive(_4);
_4 = &mut _1;
_3 = &raw mut (*_4);
_2 = move _3 as *mut usize (PointerCoercion(ArrayToPointer));
_2 = move _3 as *mut usize (PtrToPtr);
StorageDead(_3);
StorageDead(_4);
StorageLive(_5);
@@ -87,7 +87,7 @@ fn array_casts() -> () {
StorageLive(_11);
_11 = &_8;
_10 = &raw const (*_11);
_9 = move _10 as *const usize (PointerCoercion(ArrayToPointer));
_9 = move _10 as *const usize (PtrToPtr);
StorageDead(_10);
StorageDead(_11);
StorageLive(_12);