implement PlaceBuilder::try_ty
This commit is contained in:
parent
80b3c6dbde
commit
ac31d52324
2 changed files with 75 additions and 35 deletions
52
Cargo.lock
52
Cargo.lock
|
@ -285,7 +285,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cargo"
|
name = "cargo"
|
||||||
version = "0.68.0"
|
version = "0.67.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"atty",
|
"atty",
|
||||||
|
@ -307,7 +307,6 @@ dependencies = [
|
||||||
"glob",
|
"glob",
|
||||||
"hex 0.4.2",
|
"hex 0.4.2",
|
||||||
"home",
|
"home",
|
||||||
"http-auth",
|
|
||||||
"humantime 2.0.1",
|
"humantime 2.0.1",
|
||||||
"ignore",
|
"ignore",
|
||||||
"im-rc",
|
"im-rc",
|
||||||
|
@ -350,11 +349,11 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cargo-credential"
|
name = "cargo-credential"
|
||||||
version = "0.2.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cargo-credential-1password"
|
name = "cargo-credential-1password"
|
||||||
version = "0.2.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo-credential",
|
"cargo-credential",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -363,7 +362,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cargo-credential-macos-keychain"
|
name = "cargo-credential-macos-keychain"
|
||||||
version = "0.2.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo-credential",
|
"cargo-credential",
|
||||||
"security-framework",
|
"security-framework",
|
||||||
|
@ -371,7 +370,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cargo-credential-wincred"
|
name = "cargo-credential-wincred"
|
||||||
version = "0.2.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo-credential",
|
"cargo-credential",
|
||||||
"winapi",
|
"winapi",
|
||||||
|
@ -425,6 +424,7 @@ dependencies = [
|
||||||
"glob",
|
"glob",
|
||||||
"itertools",
|
"itertools",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"remove_dir_all",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"snapbox",
|
"snapbox",
|
||||||
"tar",
|
"tar",
|
||||||
|
@ -436,7 +436,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cargo-util"
|
name = "cargo-util"
|
||||||
version = "0.2.3"
|
version = "0.2.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"core-foundation",
|
"core-foundation",
|
||||||
|
@ -446,7 +446,7 @@ dependencies = [
|
||||||
"jobserver",
|
"jobserver",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"miow 0.5.0",
|
"miow",
|
||||||
"same-file",
|
"same-file",
|
||||||
"shell-escape",
|
"shell-escape",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
@ -808,7 +808,7 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"lazycell",
|
"lazycell",
|
||||||
"libc",
|
"libc",
|
||||||
"miow 0.3.7",
|
"miow",
|
||||||
"miropt-test-tools",
|
"miropt-test-tools",
|
||||||
"regex",
|
"regex",
|
||||||
"rustfix",
|
"rustfix",
|
||||||
|
@ -833,7 +833,7 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"miow 0.3.7",
|
"miow",
|
||||||
"regex",
|
"regex",
|
||||||
"rustfix",
|
"rustfix",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -846,9 +846,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "concolor"
|
name = "concolor"
|
||||||
version = "0.0.9"
|
version = "0.0.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b90f9dcd9490a97db91a85ccd79e38a87e14323f0bb824659ee3274e9143ba37"
|
checksum = "015267563b1df20adccdd00cb05257b1dfbea70a04928e9cf88ffb850c1a40af"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atty",
|
"atty",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
|
@ -857,9 +857,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "concolor-query"
|
name = "concolor-query"
|
||||||
version = "0.1.0"
|
version = "0.0.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "82a90734b3d5dcf656e7624cca6bce9c3a90ee11f900e80141a7427ccfb3d317"
|
checksum = "d6417fe6fc03a8b533fd2177742eeb39a90c7233eedec7bac96d4d6b69a09449"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "content_inspector"
|
name = "content_inspector"
|
||||||
|
@ -909,7 +909,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crates-io"
|
name = "crates-io"
|
||||||
version = "0.35.0"
|
version = "0.34.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"curl",
|
"curl",
|
||||||
|
@ -1698,15 +1698,6 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "http-auth"
|
|
||||||
version = "0.1.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c0b40b39d66c28829a0cf4d09f7e139ff8201f7500a5083732848ed3b4b4d850"
|
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "humantime"
|
name = "humantime"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
|
@ -2309,15 +2300,6 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "miow"
|
|
||||||
version = "0.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "52ffbca2f655e33c08be35d87278e5b18b89550a37dbd598c20db92f6a471123"
|
|
||||||
dependencies = [
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "miri"
|
name = "miri"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -4711,9 +4693,9 @@ checksum = "da73c8f77aebc0e40c300b93f0a5f1bece7a248a36eee287d4e095f35c7b7d6e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "snapbox"
|
name = "snapbox"
|
||||||
version = "0.4.1"
|
version = "0.3.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "827c00e91b15e2674d8a5270bae91f898693cbf9561cbb58d8eaa31974597293"
|
checksum = "44d199ccf8f606592df2d145db26f2aa45344e23c64b074cc5a4047f1d99b0f7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"concolor",
|
"concolor",
|
||||||
"content_inspector",
|
"content_inspector",
|
||||||
|
|
|
@ -323,6 +323,64 @@ impl<'tcx> PlaceBuilder<'tcx> {
|
||||||
projection: Vec::from_iter(self.projection.iter().copied().chain([elem])),
|
projection: Vec::from_iter(self.projection.iter().copied().chain([elem])),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn try_ty<D>(&self, local_decls: &D, cx: &Builder<'_, 'tcx>) -> Option<Ty<'tcx>>
|
||||||
|
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<Local> for PlaceBuilder<'tcx> {
|
impl<'tcx> From<Local> for PlaceBuilder<'tcx> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue