about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStuart Cook <Zalathar@users.noreply.github.com>2025-05-06 16:28:41 +1000
committerGitHub <noreply@github.com>2025-05-06 16:28:41 +1000
commit7ea335090202b4ccf634923f25b2a90072a08cbf (patch)
tree2e6bf1e35118bd21464e220c3123269b23a97b6c
parent7cd76052777a1f213b2c5630605d1911e8ae8f56 (diff)
parent0f81fca8ec623e849225a254ef6f639963ff54c0 (diff)
downloadrust-7ea335090202b4ccf634923f25b2a90072a08cbf.tar.gz
rust-7ea335090202b4ccf634923f25b2a90072a08cbf.zip
Rollup merge of #140532 - celinval:chores-smir-ra, r=oli-obk
Fix RustAnalyzer discovery of rustc's `stable_mir` crate

This fixes issues with RustAnalyzer not finding `stable_mir` crate since RA discovery traverses the dependency graph of `rustc_driver` crate.

This change also aligns with the long term architecture plan for these crates, since we are moving towards having stable_mir depend on rustc_smir and not the other way around. See [this doc](https://hackmd.io/jBRkZLqAQL2EVgwIIeNMHg) for more details.

I believe a similar function will come handy eventually for `stable_mir` users, but I'm keeping it as part of `rustc_internal` since its current format initializes the StableMir context and requires `TyCtxt`.

Finally, I added the `rustc_internal` module re-export under a feature since the APIs from this module shall not be stabilized.
-rw-r--r--Cargo.lock2
-rw-r--r--compiler/rustc_driver_impl/Cargo.toml2
-rw-r--r--compiler/rustc_driver_impl/src/pretty.rs2
-rw-r--r--compiler/stable_mir/Cargo.toml6
-rw-r--r--compiler/stable_mir/src/lib.rs4
5 files changed, 13 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b5fc86f50fe..98b90a47e39 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3605,13 +3605,13 @@ dependencies = [
  "rustc_query_system",
  "rustc_resolve",
  "rustc_session",
- "rustc_smir",
  "rustc_span",
  "rustc_target",
  "rustc_trait_selection",
  "rustc_ty_utils",
  "serde_json",
  "shlex",
+ "stable_mir",
  "tracing",
  "windows 0.59.0",
 ]
diff --git a/compiler/rustc_driver_impl/Cargo.toml b/compiler/rustc_driver_impl/Cargo.toml
index c823d11126e..9da4f2dbc27 100644
--- a/compiler/rustc_driver_impl/Cargo.toml
+++ b/compiler/rustc_driver_impl/Cargo.toml
@@ -44,13 +44,13 @@ rustc_privacy = { path = "../rustc_privacy" }
 rustc_query_system = { path = "../rustc_query_system" }
 rustc_resolve = { path = "../rustc_resolve" }
 rustc_session = { path = "../rustc_session" }
-rustc_smir = { path = "../rustc_smir" }
 rustc_span = { path = "../rustc_span" }
 rustc_target = { path = "../rustc_target" }
 rustc_trait_selection = { path = "../rustc_trait_selection" }
 rustc_ty_utils = { path = "../rustc_ty_utils" }
 serde_json = "1.0.59"
 shlex = "1.0"
+stable_mir = { path = "../stable_mir", features = ["rustc_internal"] }
 tracing = { version = "0.1.35" }
 # tidy-alphabetical-end
 
diff --git a/compiler/rustc_driver_impl/src/pretty.rs b/compiler/rustc_driver_impl/src/pretty.rs
index 16d70af7e05..ec77043cd12 100644
--- a/compiler/rustc_driver_impl/src/pretty.rs
+++ b/compiler/rustc_driver_impl/src/pretty.rs
@@ -10,8 +10,8 @@ use rustc_middle::ty::{self, TyCtxt};
 use rustc_mir_build::thir::print::{thir_flat, thir_tree};
 use rustc_session::Session;
 use rustc_session::config::{OutFileName, PpHirMode, PpMode, PpSourceMode};
-use rustc_smir::rustc_internal::pretty::write_smir_pretty;
 use rustc_span::{FileName, Ident};
+use stable_mir::rustc_internal::pretty::write_smir_pretty;
 use tracing::debug;
 use {rustc_ast as ast, rustc_hir_pretty as pprust_hir};
 
diff --git a/compiler/stable_mir/Cargo.toml b/compiler/stable_mir/Cargo.toml
index 3a01ee5783e..516c8e9c718 100644
--- a/compiler/stable_mir/Cargo.toml
+++ b/compiler/stable_mir/Cargo.toml
@@ -5,3 +5,9 @@ edition = "2024"
 
 [dependencies]
 rustc_smir = { path = "../rustc_smir" }
+
+[features]
+# Provides access to APIs that expose internals of the rust compiler.
+# APIs enabled by this feature are unstable. They can be removed or modified
+# at any point and they are not included in the crate's semantic versioning.
+rustc_internal = []
diff --git a/compiler/stable_mir/src/lib.rs b/compiler/stable_mir/src/lib.rs
index cc0fb52433d..688f3936b26 100644
--- a/compiler/stable_mir/src/lib.rs
+++ b/compiler/stable_mir/src/lib.rs
@@ -4,4 +4,8 @@
 //! This is a transitional measure as described in [PR #139319](https://github.com/rust-lang/rust/pull/139319).
 //! Once the refactoring is complete, the `stable_mir` implementation will be moved back here.
 
+/// Export the rustc_internal APIs. Note that this module has no stability
+/// guarantees and it is not taken into account for semver.
+#[cfg(feature = "rustc_internal")]
+pub use rustc_smir::rustc_internal;
 pub use rustc_smir::stable_mir::*;