Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f1ff74f
Fix gdb-cmd for rust-gdbgui
simlay Jul 12, 2022
8abcd4d
EscapeAscii is not an ExactSizeIterator
compiler-errors Jul 29, 2022
67220d6
Make the `config.src` handling for downloadable bootstrap a little mo…
jyn514 Oct 2, 2022
e4549d5
Improve readability of bootstrap's README by adding commas and minor …
anirudh24seven Oct 2, 2022
cddc643
Remove trailing whitespaces
anirudh24seven Oct 2, 2022
0567fec
test: run-make: skip when cross-compiling
pcc Oct 6, 2022
d59c7ff
Remove `mir::CastKind::Misc`
ouz-a Oct 4, 2022
2423483
Fix MIR inlining of asm_unwind
nbdd0121 Oct 7, 2022
6f64334
add a few more assert_unsafe_precondition
RalfJung Sep 26, 2022
d71a851
fix Miri
RalfJung Oct 7, 2022
e8a2aee
Remove `DefId` from some `SelectionCandidate` variants
fee1-dead Oct 7, 2022
d90d055
Allow transmutes between the same types after erasing lifetimes
oli-obk Sep 7, 2022
10bd656
Update rustc-dev-guide
joshtriplett Oct 7, 2022
fc83427
Fix test
nbdd0121 Oct 7, 2022
6d4013d
Update browser-ui-test version
GuillaumeGomez Oct 7, 2022
8d19d53
Update rustdoc-gui test to new browser-ui-test version
GuillaumeGomez Oct 7, 2022
38743ec
rustdoc: remove no-op CSS `.rightside { position: initial }`
notriddle Oct 7, 2022
b2369cb
rustdoc: add main-heading and example-wrap link CSS to big selector
notriddle Oct 8, 2022
6bcdf8a
Rollup merge of #101520 - oli-obk:transmute_lifetimes, r=compiler-errors
matthiaskrgr Oct 8, 2022
c731646
Rollup merge of #102675 - ouz-a:mir-technical-debt, r=oli-obk
matthiaskrgr Oct 8, 2022
2f26649
Rollup merge of #102778 - nbdd0121:mir, r=tmiasko
matthiaskrgr Oct 8, 2022
f1a03b6
Rollup merge of #102785 - fee1-dead-contrib:rm_autoimpl_defid, r=comp…
matthiaskrgr Oct 8, 2022
140fe04
Rollup merge of #102788 - joshtriplett:bump-rustc-dev-guide, r=ehuss
matthiaskrgr Oct 8, 2022
91b9a92
Rollup merge of #102789 - GuillaumeGomez:update-browser-ui-test-versi…
matthiaskrgr Oct 8, 2022
d81aa7c
Rollup merge of #102797 - notriddle:notriddle/rightside-position, r=G…
matthiaskrgr Oct 8, 2022
b8ac02b
Rollup merge of #102798 - notriddle:notriddle/text-decoration-underli…
matthiaskrgr Oct 8, 2022
c27948d
Auto merge of #102809 - matthiaskrgr:rollup-qq62vuv, r=matthiaskrgr
bors Oct 8, 2022
d2e14e2
rustdoc: remove mobile topbar from source pages instead of hiding it
notriddle Oct 8, 2022
569384b
rustdoc: remove weird `<a href="#">` wrapper around unsafe triangle
notriddle Sep 30, 2022
bf510b4
rustdoc: add test case for dimensions and color of unsafe `<sup>`
notriddle Oct 8, 2022
8796e7a
Auto merge of #102315 - RalfJung:assert_unsafe_precondition, r=thomcc
bors Oct 8, 2022
3c23567
Rollup merge of #99194 - simlay:simlay/update-rust-gdbgui-gdb-args-to…
matthiaskrgr Oct 8, 2022
e6f6ad0
Rollup merge of #99880 - compiler-errors:escape-ascii-is-not-exact-si…
matthiaskrgr Oct 8, 2022
6776cac
Rollup merge of #102524 - notriddle:notriddle/unsafe-function, r=Guil…
matthiaskrgr Oct 8, 2022
5d2c29d
Rollup merge of #102581 - jyn514:src-detection, r=Mark-Simulacrum
matthiaskrgr Oct 8, 2022
a5985dc
Rollup merge of #102604 - anirudh24seven:anirudh_improve_bootrap_read…
matthiaskrgr Oct 8, 2022
7983e7a
Rollup merge of #102723 - pcc:run-make-cc, r=Mark-Simulacrum
matthiaskrgr Oct 8, 2022
9262863
Rollup merge of #102815 - notriddle:notriddle/mobile-topbar, r=Guilla…
matthiaskrgr Oct 8, 2022
f382c27
Auto merge of #102819 - matthiaskrgr:rollup-xwnvofc, r=matthiaskrgr
bors Oct 8, 2022
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
99 changes: 89 additions & 10 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2209,25 +2209,104 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
}
}

CastKind::Misc => {
CastKind::IntToInt => {
let ty_from = op.ty(body, tcx);
let cast_ty_from = CastTy::from_ty(ty_from);
let cast_ty_to = CastTy::from_ty(*ty);
// Misc casts are either between floats and ints, or one ptr type to another.
match (cast_ty_from, cast_ty_to) {
(
Some(CastTy::Int(_) | CastTy::Float),
Some(CastTy::Int(_) | CastTy::Float),
)
| (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Ptr(_))) => (),
(Some(CastTy::Int(_)), Some(CastTy::Int(_))) => (),
_ => {
span_mirbug!(
self,
rvalue,
"Invalid Misc cast {:?} -> {:?}",
"Invalid IntToInt cast {:?} -> {:?}",
ty_from,
ty,
ty
)
}
}
}
CastKind::IntToFloat => {
let ty_from = op.ty(body, tcx);
let cast_ty_from = CastTy::from_ty(ty_from);
let cast_ty_to = CastTy::from_ty(*ty);
match (cast_ty_from, cast_ty_to) {
(Some(CastTy::Int(_)), Some(CastTy::Float)) => (),
_ => {
span_mirbug!(
self,
rvalue,
"Invalid IntToFloat cast {:?} -> {:?}",
ty_from,
ty
)
}
}
}
CastKind::FloatToInt => {
let ty_from = op.ty(body, tcx);
let cast_ty_from = CastTy::from_ty(ty_from);
let cast_ty_to = CastTy::from_ty(*ty);
match (cast_ty_from, cast_ty_to) {
(Some(CastTy::Float), Some(CastTy::Int(_))) => (),
_ => {
span_mirbug!(
self,
rvalue,
"Invalid FloatToInt cast {:?} -> {:?}",
ty_from,
ty
)
}
}
}
CastKind::FloatToFloat => {
let ty_from = op.ty(body, tcx);
let cast_ty_from = CastTy::from_ty(ty_from);
let cast_ty_to = CastTy::from_ty(*ty);
match (cast_ty_from, cast_ty_to) {
(Some(CastTy::Float), Some(CastTy::Float)) => (),
_ => {
span_mirbug!(
self,
rvalue,
"Invalid FloatToFloat cast {:?} -> {:?}",
ty_from,
ty
)
}
}
}
CastKind::FnPtrToPtr => {
let ty_from = op.ty(body, tcx);
let cast_ty_from = CastTy::from_ty(ty_from);
let cast_ty_to = CastTy::from_ty(*ty);
match (cast_ty_from, cast_ty_to) {
(Some(CastTy::FnPtr), Some(CastTy::Ptr(_))) => (),
_ => {
span_mirbug!(
self,
rvalue,
"Invalid FnPtrToPtr cast {:?} -> {:?}",
ty_from,
ty
)
}
}
}
CastKind::PtrToPtr => {
let ty_from = op.ty(body, tcx);
let cast_ty_from = CastTy::from_ty(ty_from);
let cast_ty_to = CastTy::from_ty(*ty);
match (cast_ty_from, cast_ty_to) {
(Some(CastTy::Ptr(_)), Some(CastTy::Ptr(_))) => (),
_ => {
span_mirbug!(
self,
rvalue,
"Invalid PtrToPtr cast {:?} -> {:?}",
ty_from,
ty
)
}
}
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,12 @@ fn codegen_stmt<'tcx>(
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
}
Rvalue::Cast(
CastKind::Misc
CastKind::IntToInt
| CastKind::FloatToFloat
| CastKind::FloatToInt
| CastKind::IntToFloat
| CastKind::FnPtrToPtr
| CastKind::PtrToPtr
| CastKind::PointerExposeAddress
| CastKind::PointerFromExposedAddress,
ref operand,
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_codegen_cranelift/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,16 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
match &stmt.kind {
StatementKind::Assign(local_and_rvalue) if &local_and_rvalue.0 == place => {
match &local_and_rvalue.1 {
Rvalue::Cast(CastKind::Misc, operand, ty) => {
Rvalue::Cast(
CastKind::IntToInt
| CastKind::FloatToFloat
| CastKind::FloatToInt
| CastKind::IntToFloat
| CastKind::FnPtrToPtr
| CastKind::PtrToPtr,
operand,
ty,
) => {
if computed_const_val.is_some() {
return None; // local assigned twice
}
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
OperandValue::Pair(lldata, llextra)
}
mir::CastKind::Pointer(PointerCast::MutToConstPointer)
| mir::CastKind::Misc
| mir::CastKind::PtrToPtr
if bx.cx().is_backend_scalar_pair(operand.layout) =>
{
if let OperandValue::Pair(data_ptr, meta) = operand.val {
Expand Down Expand Up @@ -290,7 +290,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
mir::CastKind::Pointer(
PointerCast::MutToConstPointer | PointerCast::ArrayToPointer,
)
| mir::CastKind::Misc
| mir::CastKind::IntToInt
| mir::CastKind::FloatToInt
| mir::CastKind::FloatToFloat
| mir::CastKind::IntToFloat
| mir::CastKind::PtrToPtr
| mir::CastKind::FnPtrToPtr

// Since int2ptr can have arbitrary integer types as input (so we have to do
// sign extension and all that), it is currently best handled in the same code
// path as the other integer-to-X casts.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let res = self.pointer_from_exposed_address_cast(&src, cast_ty)?;
self.write_immediate(res, dest)?;
}

Misc => {
// FIXME: We shouldn't use `misc_cast` for these but handle them separately.
IntToInt | FloatToInt | FloatToFloat | IntToFloat | FnPtrToPtr | PtrToPtr => {
let src = self.read_immediate(src)?;
let res = self.misc_cast(&src, cast_ty)?;
self.write_immediate(res, dest)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
unimplemented!()
}

Rvalue::Cast(CastKind::Misc, _, _) => {}
Rvalue::Cast(_, _, _) => {}

Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => {}
Rvalue::ShallowInitBox(_, _) => {}
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,14 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
}
Rvalue::Cast(kind, operand, target_type) => {
match kind {
CastKind::Misc => {
CastKind::DynStar => {
// FIXME(dyn-star): make sure nothing needs to be done here.
}
// Nothing to check here
CastKind::PointerFromExposedAddress
| CastKind::PointerExposeAddress
| CastKind::Pointer(_) => {}
_ => {
let op_ty = operand.ty(self.body, self.tcx);
if op_ty.is_enum() {
self.fail(
Expand All @@ -568,13 +575,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
);
}
}
CastKind::DynStar => {
// FIXME(dyn-star): make sure nothing needs to be done here.
}
// Nothing to check here
CastKind::PointerFromExposedAddress
| CastKind::PointerExposeAddress
| CastKind::Pointer(_) => {}
}
}
Rvalue::Repeat(_, _)
Expand Down
20 changes: 15 additions & 5 deletions compiler/rustc_hir_analysis/src/check/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn check_transmute(&self, from: Ty<'tcx>, to: Ty<'tcx>, hir_id: HirId) {
let tcx = self.tcx;
let span = tcx.hir().span(hir_id);
let convert = |ty: Ty<'tcx>| {
let normalize = |ty| {
let ty = self.resolve_vars_if_possible(ty);
let ty = tcx.normalize_erasing_regions(self.param_env, ty);
(SizeSkeleton::compute(ty, tcx, self.param_env), ty)
self.tcx.normalize_erasing_regions(self.param_env, ty)
};
let (sk_from, from) = convert(from);
let (sk_to, to) = convert(to);
let from = normalize(from);
let to = normalize(to);
trace!(?from, ?to);

// Transmutes that are only changing lifetimes are always ok.
if from == to {
return;
}

let skel = |ty| SizeSkeleton::compute(ty, tcx, self.param_env);
let sk_from = skel(from);
let sk_to = skel(to);
trace!(?sk_from, ?sk_to);

// Check for same size using the skeletons.
if let (Ok(sk_from), Ok(sk_to)) = (sk_from, sk_to) {
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,14 @@ impl<'tcx> Rvalue<'tcx> {
| Rvalue::AddressOf(_, _)
| Rvalue::Len(_)
| Rvalue::Cast(
CastKind::Misc | CastKind::Pointer(_) | CastKind::PointerFromExposedAddress,
CastKind::IntToInt
| CastKind::FloatToInt
| CastKind::FloatToFloat
| CastKind::IntToFloat
| CastKind::FnPtrToPtr
| CastKind::PtrToPtr
| CastKind::Pointer(_)
| CastKind::PointerFromExposedAddress,
_,
_,
)
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,12 @@ pub enum CastKind {
Pointer(PointerCast),
/// Cast into a dyn* object.
DynStar,
/// Remaining unclassified casts.
Misc,
IntToInt,
FloatToInt,
FloatToFloat,
IntToFloat,
PtrToPtr,
FnPtrToPtr,
}

#[derive(Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub enum SelectionCandidate<'tcx> {

ParamCandidate(ty::PolyTraitPredicate<'tcx>),
ImplCandidate(DefId),
AutoImplCandidate(DefId),
AutoImplCandidate,

/// This is a trait matching with a projected type as `Self`, and we found
/// an applicable bound in the trait definition. The `usize` is an index
Expand Down Expand Up @@ -143,7 +143,7 @@ pub enum SelectionCandidate<'tcx> {
/// Builtin implementation of `Pointee`.
PointeeCandidate,

TraitAliasCandidate(DefId),
TraitAliasCandidate,

/// Matching `dyn Trait` with a supertrait of `Trait`. The index is the
/// position in the iterator returned by
Expand Down
26 changes: 26 additions & 0 deletions compiler/rustc_middle/src/ty/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// typeck and codegen.

use crate::ty::{self, Ty};
use rustc_middle::mir;

use rustc_macros::HashStable;

Expand Down Expand Up @@ -75,3 +76,28 @@ impl<'tcx> CastTy<'tcx> {
}
}
}

/// Returns `mir::CastKind` from the given parameters.
pub fn mir_cast_kind<'tcx>(from_ty: Ty<'tcx>, cast_ty: Ty<'tcx>) -> mir::CastKind {
let from = CastTy::from_ty(from_ty);
let cast = CastTy::from_ty(cast_ty);
let cast_kind = match (from, cast) {
(Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Int(_))) => {
mir::CastKind::PointerExposeAddress
}
(Some(CastTy::Int(_)), Some(CastTy::Ptr(_))) => mir::CastKind::PointerFromExposedAddress,
(_, Some(CastTy::DynStar)) => mir::CastKind::DynStar,
(Some(CastTy::Int(_)), Some(CastTy::Int(_))) => mir::CastKind::IntToInt,
(Some(CastTy::FnPtr), Some(CastTy::Ptr(_))) => mir::CastKind::FnPtrToPtr,

(Some(CastTy::Float), Some(CastTy::Int(_))) => mir::CastKind::FloatToInt,
(Some(CastTy::Int(_)), Some(CastTy::Float)) => mir::CastKind::IntToFloat,
(Some(CastTy::Float), Some(CastTy::Float)) => mir::CastKind::FloatToFloat,
(Some(CastTy::Ptr(_)), Some(CastTy::Ptr(_))) => mir::CastKind::PtrToPtr,

(_, _) => {
bug!("Attempting to cast non-castable types {:?} and {:?}", from_ty, cast_ty)
}
};
cast_kind
}
13 changes: 2 additions & 11 deletions compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_middle::mir::AssertKind;
use rustc_middle::mir::Place;
use rustc_middle::mir::*;
use rustc_middle::thir::*;
use rustc_middle::ty::cast::CastTy;
use rustc_middle::ty::cast::{mir_cast_kind, CastTy};
use rustc_middle::ty::{self, Ty, UpvarSubsts};
use rustc_span::Span;

Expand Down Expand Up @@ -217,16 +217,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let from_ty = CastTy::from_ty(ty);
let cast_ty = CastTy::from_ty(expr.ty);
debug!("ExprKind::Cast from_ty={from_ty:?}, cast_ty={:?}/{cast_ty:?}", expr.ty,);
let cast_kind = match (from_ty, cast_ty) {
(Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Int(_))) => {
CastKind::PointerExposeAddress
}
(Some(CastTy::Int(_)), Some(CastTy::Ptr(_))) => {
CastKind::PointerFromExposedAddress
}
(_, Some(CastTy::DynStar)) => CastKind::DynStar,
(_, _) => CastKind::Misc,
};
let cast_kind = mir_cast_kind(ty, expr.ty);
block.and(Rvalue::Cast(cast_kind, source, expr.ty))
}
ExprKind::Pointer { cast, source } => {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_mir_dataflow/src/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,10 @@ where
// tmp = &raw mut P;
// cur = tmp as *mut T;
// end = Offset(cur, len);
let mir_cast_kind = ty::cast::mir_cast_kind(iter_ty, tmp_ty);
vec![
self.assign(tmp, Rvalue::AddressOf(Mutability::Mut, self.place)),
self.assign(cur, Rvalue::Cast(CastKind::Misc, Operand::Move(tmp), iter_ty)),
self.assign(cur, Rvalue::Cast(mir_cast_kind, Operand::Move(tmp), iter_ty)),
self.assign(
length_or_end,
Rvalue::BinaryOp(
Expand Down
Loading