From ac31d52324f3a0c41b5daabd842e36448fd95aae Mon Sep 17 00:00:00 2001 From: b-naber Date: Wed, 2 Nov 2022 13:37:37 +0100 Subject: [PATCH] implement PlaceBuilder::try_ty --- Cargo.lock | 52 ++++++----------- .../src/build/expr/as_place.rs | 58 +++++++++++++++++++ 2 files changed, 75 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c987bf44ec0..12e075a08c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -285,7 +285,7 @@ dependencies = [ [[package]] name = "cargo" -version = "0.68.0" +version = "0.67.0" dependencies = [ "anyhow", "atty", @@ -307,7 +307,6 @@ dependencies = [ "glob", "hex 0.4.2", "home", - "http-auth", "humantime 2.0.1", "ignore", "im-rc", @@ -350,11 +349,11 @@ dependencies = [ [[package]] name = "cargo-credential" -version = "0.2.0" +version = "0.1.0" [[package]] name = "cargo-credential-1password" -version = "0.2.0" +version = "0.1.0" dependencies = [ "cargo-credential", "serde", @@ -363,7 +362,7 @@ dependencies = [ [[package]] name = "cargo-credential-macos-keychain" -version = "0.2.0" +version = "0.1.0" dependencies = [ "cargo-credential", "security-framework", @@ -371,7 +370,7 @@ dependencies = [ [[package]] name = "cargo-credential-wincred" -version = "0.2.0" +version = "0.1.0" dependencies = [ "cargo-credential", "winapi", @@ -425,6 +424,7 @@ dependencies = [ "glob", "itertools", "lazy_static", + "remove_dir_all", "serde_json", "snapbox", "tar", @@ -436,7 +436,7 @@ dependencies = [ [[package]] name = "cargo-util" -version = "0.2.3" +version = "0.2.2" dependencies = [ "anyhow", "core-foundation", @@ -446,7 +446,7 @@ dependencies = [ "jobserver", "libc", "log", - "miow 0.5.0", + "miow", "same-file", "shell-escape", "tempfile", @@ -808,7 +808,7 @@ dependencies = [ "lazy_static", "lazycell", "libc", - "miow 0.3.7", + "miow", "miropt-test-tools", "regex", "rustfix", @@ -833,7 +833,7 @@ dependencies = [ "lazy_static", "libc", "log", - "miow 0.3.7", + "miow", "regex", "rustfix", "serde", @@ -846,9 +846,9 @@ dependencies = [ [[package]] name = "concolor" -version = "0.0.9" +version = "0.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b90f9dcd9490a97db91a85ccd79e38a87e14323f0bb824659ee3274e9143ba37" +checksum = "015267563b1df20adccdd00cb05257b1dfbea70a04928e9cf88ffb850c1a40af" dependencies = [ "atty", "bitflags", @@ -857,9 +857,9 @@ dependencies = [ [[package]] name = "concolor-query" -version = "0.1.0" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a90734b3d5dcf656e7624cca6bce9c3a90ee11f900e80141a7427ccfb3d317" +checksum = "d6417fe6fc03a8b533fd2177742eeb39a90c7233eedec7bac96d4d6b69a09449" [[package]] name = "content_inspector" @@ -909,7 +909,7 @@ dependencies = [ [[package]] name = "crates-io" -version = "0.35.0" +version = "0.34.0" dependencies = [ "anyhow", "curl", @@ -1698,15 +1698,6 @@ dependencies = [ "syn", ] -[[package]] -name = "http-auth" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0b40b39d66c28829a0cf4d09f7e139ff8201f7500a5083732848ed3b4b4d850" -dependencies = [ - "memchr", -] - [[package]] name = "humantime" version = "1.3.0" @@ -2309,15 +2300,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "miow" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ffbca2f655e33c08be35d87278e5b18b89550a37dbd598c20db92f6a471123" -dependencies = [ - "windows-sys", -] - [[package]] name = "miri" version = "0.1.0" @@ -4711,9 +4693,9 @@ checksum = "da73c8f77aebc0e40c300b93f0a5f1bece7a248a36eee287d4e095f35c7b7d6e" [[package]] name = "snapbox" -version = "0.4.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "827c00e91b15e2674d8a5270bae91f898693cbf9561cbb58d8eaa31974597293" +checksum = "44d199ccf8f606592df2d145db26f2aa45344e23c64b074cc5a4047f1d99b0f7" dependencies = [ "concolor", "content_inspector", diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index edd52728626..b6f2e3de668 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -323,6 +323,64 @@ impl<'tcx> PlaceBuilder<'tcx> { projection: Vec::from_iter(self.projection.iter().copied().chain([elem])), } } + + pub fn try_ty(&self, local_decls: &D, cx: &Builder<'_, 'tcx>) -> Option> + where + D: HasLocalDecls<'tcx>, + { + let tcx = cx.tcx; + + let project_ty = |ty: Ty<'tcx>, elem: &PlaceElem<'tcx>| -> Ty<'tcx> { + match elem { + ProjectionElem::Deref => { + ty.builtin_deref(true) + .unwrap_or_else(|| { + bug!("deref projection of non-dereferenceable ty {:?}", ty) + }) + .ty + } + ProjectionElem::Index(_) | ProjectionElem::ConstantIndex { .. } => { + ty.builtin_index().unwrap() + } + ProjectionElem::Subslice { from, to, from_end } => match ty.kind() { + ty::Slice(..) => ty, + ty::Array(inner, _) if !from_end => tcx.mk_array(*inner, (to - from) as u64), + ty::Array(inner, size) if *from_end => { + let size = size.eval_usize(tcx, ty::ParamEnv::empty()); + let len = size - (*from as u64) - (*to as u64); + tcx.mk_array(*inner, len) + } + _ => bug!("cannot subslice non-array type: `{:?}`", ty), + }, + ProjectionElem::Downcast(..) => ty, + ProjectionElem::Field(_, ty) | ProjectionElem::OpaqueCast(ty) => *ty, + } + }; + + match self.base { + PlaceBase::Local(local) => { + let base_ty = local_decls.local_decls()[local].ty; + Some(self.projection.iter().fold(base_ty, |ty, &elem| project_ty(ty, &elem))) + } + PlaceBase::Upvar { .. } => { + match to_upvars_resolved_place_builder(self.clone(), cx) { + Ok(resolved_place_builder) => { + // `base` is guaranteed to be `PlaceBase::Local` now, so recursive call is ok + resolved_place_builder.try_ty(local_decls, cx) + } + Err(place_builder) => { + match &place_builder.projection[..] { + &[ProjectionElem::OpaqueCast(base_ty), ref projections @ ..] => Some( + projections.iter().fold(base_ty, |ty, &elem| project_ty(ty, &elem)), + ), + + _ => None, // would need a base `Ty` for these + } + } + } + } + } + } } impl<'tcx> From for PlaceBuilder<'tcx> {