Skip to content

Commit ac31d52

Browse files
committed
implement PlaceBuilder::try_ty
1 parent 80b3c6d commit ac31d52

File tree

2 files changed

+75
-35
lines changed

2 files changed

+75
-35
lines changed

Cargo.lock

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ dependencies = [
285285

286286
[[package]]
287287
name = "cargo"
288-
version = "0.68.0"
288+
version = "0.67.0"
289289
dependencies = [
290290
"anyhow",
291291
"atty",
@@ -307,7 +307,6 @@ dependencies = [
307307
"glob",
308308
"hex 0.4.2",
309309
"home",
310-
"http-auth",
311310
"humantime 2.0.1",
312311
"ignore",
313312
"im-rc",
@@ -350,11 +349,11 @@ dependencies = [
350349

351350
[[package]]
352351
name = "cargo-credential"
353-
version = "0.2.0"
352+
version = "0.1.0"
354353

355354
[[package]]
356355
name = "cargo-credential-1password"
357-
version = "0.2.0"
356+
version = "0.1.0"
358357
dependencies = [
359358
"cargo-credential",
360359
"serde",
@@ -363,15 +362,15 @@ dependencies = [
363362

364363
[[package]]
365364
name = "cargo-credential-macos-keychain"
366-
version = "0.2.0"
365+
version = "0.1.0"
367366
dependencies = [
368367
"cargo-credential",
369368
"security-framework",
370369
]
371370

372371
[[package]]
373372
name = "cargo-credential-wincred"
374-
version = "0.2.0"
373+
version = "0.1.0"
375374
dependencies = [
376375
"cargo-credential",
377376
"winapi",
@@ -425,6 +424,7 @@ dependencies = [
425424
"glob",
426425
"itertools",
427426
"lazy_static",
427+
"remove_dir_all",
428428
"serde_json",
429429
"snapbox",
430430
"tar",
@@ -436,7 +436,7 @@ dependencies = [
436436

437437
[[package]]
438438
name = "cargo-util"
439-
version = "0.2.3"
439+
version = "0.2.2"
440440
dependencies = [
441441
"anyhow",
442442
"core-foundation",
@@ -446,7 +446,7 @@ dependencies = [
446446
"jobserver",
447447
"libc",
448448
"log",
449-
"miow 0.5.0",
449+
"miow",
450450
"same-file",
451451
"shell-escape",
452452
"tempfile",
@@ -808,7 +808,7 @@ dependencies = [
808808
"lazy_static",
809809
"lazycell",
810810
"libc",
811-
"miow 0.3.7",
811+
"miow",
812812
"miropt-test-tools",
813813
"regex",
814814
"rustfix",
@@ -833,7 +833,7 @@ dependencies = [
833833
"lazy_static",
834834
"libc",
835835
"log",
836-
"miow 0.3.7",
836+
"miow",
837837
"regex",
838838
"rustfix",
839839
"serde",
@@ -846,9 +846,9 @@ dependencies = [
846846

847847
[[package]]
848848
name = "concolor"
849-
version = "0.0.9"
849+
version = "0.0.8"
850850
source = "registry+https://github.com/rust-lang/crates.io-index"
851-
checksum = "b90f9dcd9490a97db91a85ccd79e38a87e14323f0bb824659ee3274e9143ba37"
851+
checksum = "015267563b1df20adccdd00cb05257b1dfbea70a04928e9cf88ffb850c1a40af"
852852
dependencies = [
853853
"atty",
854854
"bitflags",
@@ -857,9 +857,9 @@ dependencies = [
857857

858858
[[package]]
859859
name = "concolor-query"
860-
version = "0.1.0"
860+
version = "0.0.5"
861861
source = "registry+https://github.com/rust-lang/crates.io-index"
862-
checksum = "82a90734b3d5dcf656e7624cca6bce9c3a90ee11f900e80141a7427ccfb3d317"
862+
checksum = "d6417fe6fc03a8b533fd2177742eeb39a90c7233eedec7bac96d4d6b69a09449"
863863

864864
[[package]]
865865
name = "content_inspector"
@@ -909,7 +909,7 @@ dependencies = [
909909

910910
[[package]]
911911
name = "crates-io"
912-
version = "0.35.0"
912+
version = "0.34.0"
913913
dependencies = [
914914
"anyhow",
915915
"curl",
@@ -1698,15 +1698,6 @@ dependencies = [
16981698
"syn",
16991699
]
17001700

1701-
[[package]]
1702-
name = "http-auth"
1703-
version = "0.1.6"
1704-
source = "registry+https://github.com/rust-lang/crates.io-index"
1705-
checksum = "c0b40b39d66c28829a0cf4d09f7e139ff8201f7500a5083732848ed3b4b4d850"
1706-
dependencies = [
1707-
"memchr",
1708-
]
1709-
17101701
[[package]]
17111702
name = "humantime"
17121703
version = "1.3.0"
@@ -2309,15 +2300,6 @@ dependencies = [
23092300
"winapi",
23102301
]
23112302

2312-
[[package]]
2313-
name = "miow"
2314-
version = "0.5.0"
2315-
source = "registry+https://github.com/rust-lang/crates.io-index"
2316-
checksum = "52ffbca2f655e33c08be35d87278e5b18b89550a37dbd598c20db92f6a471123"
2317-
dependencies = [
2318-
"windows-sys",
2319-
]
2320-
23212303
[[package]]
23222304
name = "miri"
23232305
version = "0.1.0"
@@ -4711,9 +4693,9 @@ checksum = "da73c8f77aebc0e40c300b93f0a5f1bece7a248a36eee287d4e095f35c7b7d6e"
47114693

47124694
[[package]]
47134695
name = "snapbox"
4714-
version = "0.4.1"
4696+
version = "0.3.3"
47154697
source = "registry+https://github.com/rust-lang/crates.io-index"
4716-
checksum = "827c00e91b15e2674d8a5270bae91f898693cbf9561cbb58d8eaa31974597293"
4698+
checksum = "44d199ccf8f606592df2d145db26f2aa45344e23c64b074cc5a4047f1d99b0f7"
47174699
dependencies = [
47184700
"concolor",
47194701
"content_inspector",

compiler/rustc_mir_build/src/build/expr/as_place.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,64 @@ impl<'tcx> PlaceBuilder<'tcx> {
323323
projection: Vec::from_iter(self.projection.iter().copied().chain([elem])),
324324
}
325325
}
326+
327+
pub fn try_ty<D>(&self, local_decls: &D, cx: &Builder<'_, 'tcx>) -> Option<Ty<'tcx>>
328+
where
329+
D: HasLocalDecls<'tcx>,
330+
{
331+
let tcx = cx.tcx;
332+
333+
let project_ty = |ty: Ty<'tcx>, elem: &PlaceElem<'tcx>| -> Ty<'tcx> {
334+
match elem {
335+
ProjectionElem::Deref => {
336+
ty.builtin_deref(true)
337+
.unwrap_or_else(|| {
338+
bug!("deref projection of non-dereferenceable ty {:?}", ty)
339+
})
340+
.ty
341+
}
342+
ProjectionElem::Index(_) | ProjectionElem::ConstantIndex { .. } => {
343+
ty.builtin_index().unwrap()
344+
}
345+
ProjectionElem::Subslice { from, to, from_end } => match ty.kind() {
346+
ty::Slice(..) => ty,
347+
ty::Array(inner, _) if !from_end => tcx.mk_array(*inner, (to - from) as u64),
348+
ty::Array(inner, size) if *from_end => {
349+
let size = size.eval_usize(tcx, ty::ParamEnv::empty());
350+
let len = size - (*from as u64) - (*to as u64);
351+
tcx.mk_array(*inner, len)
352+
}
353+
_ => bug!("cannot subslice non-array type: `{:?}`", ty),
354+
},
355+
ProjectionElem::Downcast(..) => ty,
356+
ProjectionElem::Field(_, ty) | ProjectionElem::OpaqueCast(ty) => *ty,
357+
}
358+
};
359+
360+
match self.base {
361+
PlaceBase::Local(local) => {
362+
let base_ty = local_decls.local_decls()[local].ty;
363+
Some(self.projection.iter().fold(base_ty, |ty, &elem| project_ty(ty, &elem)))
364+
}
365+
PlaceBase::Upvar { .. } => {
366+
match to_upvars_resolved_place_builder(self.clone(), cx) {
367+
Ok(resolved_place_builder) => {
368+
// `base` is guaranteed to be `PlaceBase::Local` now, so recursive call is ok
369+
resolved_place_builder.try_ty(local_decls, cx)
370+
}
371+
Err(place_builder) => {
372+
match &place_builder.projection[..] {
373+
&[ProjectionElem::OpaqueCast(base_ty), ref projections @ ..] => Some(
374+
projections.iter().fold(base_ty, |ty, &elem| project_ty(ty, &elem)),
375+
),
376+
377+
_ => None, // would need a base `Ty` for these
378+
}
379+
}
380+
}
381+
}
382+
}
383+
}
326384
}
327385

328386
impl<'tcx> From<Local> for PlaceBuilder<'tcx> {

0 commit comments

Comments
 (0)