diff options
| author | 许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com> | 2025-07-22 00:54:27 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-22 00:54:27 +0800 |
| commit | 2e0748b1858079062284e116d0730a8156a1dab7 (patch) | |
| tree | f2b876b2b5cfe346eb7a73f9ded4e8d92edefb4a /tests/ui-fulldeps/rustc_public/smir_internal.rs | |
| parent | 38efe3875aac14e282e64623e241acdf973d0f63 (diff) | |
| parent | 20a7f722d824ebc4e733ec848d797088363624e9 (diff) | |
| download | rust-2e0748b1858079062284e116d0730a8156a1dab7.tar.gz rust-2e0748b1858079062284e116d0730a8156a1dab7.zip | |
Rollup merge of #143985 - makai410:rp-rename, r=oli-obk
rustc_public: de-StableMIR-ize This PR updates relevant docs about StableMIR, basically just rewording StableMIR/SMIR to rustc_public/rustc_public's IR. The README.md in the `rustc_public` crate is out-dated. I plan to rewrite it after we fork rustc_public into its own repository. This PR doesn't change the fact that we still use `-Z unpretty=stable-mir` as a rustc parameter for printing the IR, since I feel it's a bit verbose and weird if we use `-Z unpretty=rustc-public-ir`. I was wondering if we can have a short and easy alias for rustc_public's IR.
Diffstat (limited to 'tests/ui-fulldeps/rustc_public/smir_internal.rs')
| -rw-r--r-- | tests/ui-fulldeps/rustc_public/smir_internal.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/ui-fulldeps/rustc_public/smir_internal.rs b/tests/ui-fulldeps/rustc_public/smir_internal.rs new file mode 100644 index 00000000000..b74bdfe4eb1 --- /dev/null +++ b/tests/ui-fulldeps/rustc_public/smir_internal.rs @@ -0,0 +1,61 @@ +//@ run-pass +//! Test that users are able to use retrieve internal constructs from stable ones to help with +//! the migration. + +//@ ignore-stage1 +//@ ignore-cross-compile +//@ ignore-remote +//@ edition: 2021 + +#![feature(rustc_private)] +#![feature(assert_matches)] + +extern crate rustc_driver; +extern crate rustc_interface; +extern crate rustc_middle; +#[macro_use] +extern crate rustc_public; + +use rustc_middle::ty::TyCtxt; +use rustc_public::rustc_internal; +use std::io::Write; +use std::ops::ControlFlow; + +const CRATE_NAME: &str = "input"; + +fn test_translation(tcx: TyCtxt<'_>) -> ControlFlow<()> { + let main_fn = rustc_public::entry_fn().unwrap(); + let body = main_fn.expect_body(); + let orig_ty = body.locals()[0].ty; + let rustc_ty = rustc_internal::internal(tcx, &orig_ty); + assert!(rustc_ty.is_unit()); + ControlFlow::Continue(()) +} + +/// This test will generate and analyze a dummy crate using the stable mir. +/// For that, it will first write the dummy crate into a file. +/// Then it will create a `RustcPublic` using custom arguments and then +/// it will run the compiler. +fn main() { + let path = "internal_input.rs"; + generate_input(&path).unwrap(); + let args = &[ + "rustc".to_string(), + "--crate-name".to_string(), + CRATE_NAME.to_string(), + path.to_string(), + ]; + run_with_tcx!(args, test_translation).unwrap(); +} + +fn generate_input(path: &str) -> std::io::Result<()> { + let mut file = std::fs::File::create(path)?; + write!( + file, + r#" + pub fn main() {{ + }} + "# + )?; + Ok(()) +} |
