about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-11-21 04:32:03 +0000
committerbors <bors@rust-lang.org>2023-11-21 04:32:03 +0000
commit390e3c8b6615afb4f0b9bb2c3db3ad033ac75d78 (patch)
tree39bab4d92eb3af7a2a2288698fa2d4368862e055 /tests
parentbaf4abff314cad946a3b7335024e3e2756e3828b (diff)
parentd94df6239804b2ee198414fb6916892aa060ba2c (diff)
downloadrust-390e3c8b6615afb4f0b9bb2c3db3ad033ac75d78.tar.gz
rust-390e3c8b6615afb4f0b9bb2c3db3ad033ac75d78.zip
Auto merge of #118015 - celinval:smir-place-ty, r=compiler-errors
Add place.ty() and Ty build from a kind to smir

Add a method to retrieve the type of a place and a few utility functions needed to build the projection type. I decided to return a result to avoid panicking if the user passes invalid inputs, such as wrong list of locals.

r? `@spastorino`
Diffstat (limited to 'tests')
-rw-r--r--tests/ui-fulldeps/stable-mir/check_instance.rs3
-rw-r--r--tests/ui-fulldeps/stable-mir/crate-info.rs3
-rw-r--r--tests/ui-fulldeps/stable-mir/projections.rs20
-rw-r--r--tests/ui-fulldeps/stable-mir/smir_visitor.rs3
4 files changed, 19 insertions, 10 deletions
diff --git a/tests/ui-fulldeps/stable-mir/check_instance.rs b/tests/ui-fulldeps/stable-mir/check_instance.rs
index e5a480cd61d..976dfee774b 100644
--- a/tests/ui-fulldeps/stable-mir/check_instance.rs
+++ b/tests/ui-fulldeps/stable-mir/check_instance.rs
@@ -59,7 +59,8 @@ fn test_body(body: mir::Body) {
     for term in body.blocks.iter().map(|bb| &bb.terminator) {
         match &term.kind {
             Call { func, .. } => {
-                let TyKind::RigidTy(ty) = func.ty(body.locals()).kind() else { unreachable!() };
+                let TyKind::RigidTy(ty) = func.ty(body.locals()).unwrap().kind() else { unreachable!
+                () };
                 let RigidTy::FnDef(def, args) = ty else { unreachable!() };
                 let instance = Instance::resolve(def, &args).unwrap();
                 let mangled_name = instance.mangled_name();
diff --git a/tests/ui-fulldeps/stable-mir/crate-info.rs b/tests/ui-fulldeps/stable-mir/crate-info.rs
index 025ed1b6a95..4164f041022 100644
--- a/tests/ui-fulldeps/stable-mir/crate-info.rs
+++ b/tests/ui-fulldeps/stable-mir/crate-info.rs
@@ -124,7 +124,8 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
     for block in instance.body().unwrap().blocks {
         match &block.terminator.kind {
             stable_mir::mir::TerminatorKind::Call { func, .. } => {
-                let TyKind::RigidTy(ty) = func.ty(&body.locals()).kind() else { unreachable!() };
+                let TyKind::RigidTy(ty) = func.ty(&body.locals()).unwrap().kind() else {
+                    unreachable!() };
                 let RigidTy::FnDef(def, args) = ty else { unreachable!() };
                 let next_func = Instance::resolve(def, &args).unwrap();
                 match next_func.body().unwrap().locals()[1].ty.kind() {
diff --git a/tests/ui-fulldeps/stable-mir/projections.rs b/tests/ui-fulldeps/stable-mir/projections.rs
index d00f17d206b..29930763591 100644
--- a/tests/ui-fulldeps/stable-mir/projections.rs
+++ b/tests/ui-fulldeps/stable-mir/projections.rs
@@ -22,7 +22,7 @@ extern crate stable_mir;
 use rustc_middle::ty::TyCtxt;
 use rustc_smir::rustc_internal;
 use stable_mir::mir::{ProjectionElem, Rvalue, StatementKind};
-use stable_mir::ty::{RigidTy, TyKind};
+use stable_mir::ty::{RigidTy, TyKind, UintTy};
 use stable_mir::ItemKind;
 use std::assert_matches::assert_matches;
 use std::io::Write;
@@ -39,7 +39,7 @@ fn test_place_projections(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
     // `s` is passed as a reference argument, and a field access for field `c`.
     match &body.blocks[0].statements[0].kind {
         StatementKind::Assign(
-            stable_mir::mir::Place { local: _, projection: local_proj },
+            place @ stable_mir::mir::Place { local: _, projection: local_proj },
             Rvalue::Ref(_, _, stable_mir::mir::Place { local: _, projection: r_proj }),
         ) => {
             // We can't match on vecs, only on slices. Comparing statements for equality wouldn't be
@@ -48,10 +48,14 @@ fn test_place_projections(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
             assert!(local_proj.is_empty());
             match &r_proj[..] {
                 // Similarly we can't match against a type, only against its kind.
-                [ProjectionElem::Deref, ProjectionElem::Field(2, ty)] => assert_matches!(
-                    ty.kind(),
-                    TyKind::RigidTy(RigidTy::Uint(stable_mir::ty::UintTy::U8))
-                ),
+                [ProjectionElem::Deref, ProjectionElem::Field(2, ty)] => {
+                    assert_matches!(
+                        ty.kind(),
+                        TyKind::RigidTy(RigidTy::Uint(stable_mir::ty::UintTy::U8))
+                    );
+                    let ty = place.ty(body.locals()).unwrap();
+                    assert_matches!(ty.kind().rigid(), Some(RigidTy::Ref(..)));
+                },
                 other => panic!(
                     "Unable to match against expected rvalue projection. Expected the projection \
                      for `s.c`, which is a Deref and u8 Field. Got: {:?}",
@@ -69,7 +73,7 @@ fn test_place_projections(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
     // since `slice` is a reference, and an index.
     match &body.blocks[2].statements[0].kind {
         StatementKind::Assign(
-            stable_mir::mir::Place { local: _, projection: local_proj },
+            place @ stable_mir::mir::Place { local: _, projection: local_proj },
             Rvalue::Use(stable_mir::mir::Operand::Copy(stable_mir::mir::Place {
                 local: _,
                 projection: r_proj,
@@ -80,6 +84,8 @@ fn test_place_projections(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
             // wildcards.
             assert!(local_proj.is_empty());
             assert_matches!(r_proj[..], [ProjectionElem::Deref, ProjectionElem::Index(_)]);
+            let ty = place.ty(body.locals()).unwrap();
+            assert_matches!(ty.kind().rigid(), Some(RigidTy::Uint(UintTy::U8)));
         }
         other => panic!(
             "Unable to match against expected Assign statement with a Use rvalue. Expected the \
diff --git a/tests/ui-fulldeps/stable-mir/smir_visitor.rs b/tests/ui-fulldeps/stable-mir/smir_visitor.rs
index 3ec63efcc06..027b0e7d9e8 100644
--- a/tests/ui-fulldeps/stable-mir/smir_visitor.rs
+++ b/tests/ui-fulldeps/stable-mir/smir_visitor.rs
@@ -92,7 +92,8 @@ impl<'a> mir::MirVisitor for TestVisitor<'a> {
 
     fn visit_terminator(&mut self, term: &mir::Terminator, location: mir::visit::Location) {
         if let mir::TerminatorKind::Call { func, .. } = &term.kind {
-            let ty::TyKind::RigidTy(ty) = func.ty(self.body.locals()).kind() else { unreachable!
+            let ty::TyKind::RigidTy(ty) = func.ty(self.body.locals()).unwrap().kind() else {
+                unreachable!
             () };
             let ty::RigidTy::FnDef(def, args) = ty else { unreachable!() };
             self.calls.push(mir::mono::Instance::resolve(def, &args).unwrap());