Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e985218

Browse files
authoredJan 18, 2024
Rollup merge of rust-lang#119833 - celinval:smir-accept-closures, r=oli-obk
Make tcx optional from StableMIR run macro and extend it to accept closures Change `run` macro to avoid sometimes unnecessary dependency on `TyCtxt`, and introduce `run_with_tcx` to capture use cases where `tcx` is required. Additionally, extend both macros to accept closures that may capture variables. I've also modified the `internal()` method to make it safer, by accepting the type context to force the `'tcx` lifetime to match the context lifetime. These are non-backward compatible changes, but they only affect internal APIs which are provided today as helper functions until we have a stable API to start the compiler.
2 parents 53d99e5 + 6a573cb commit e985218

13 files changed

+140
-64
lines changed
 

‎compiler/rustc_smir/src/rustc_internal/mod.rs

+106-16
Original file line numberDiff line numberDiff line change
@@ -190,35 +190,120 @@ where
190190
stable_mir::compiler_interface::run(&tables, || init(&tables, f))
191191
}
192192

193+
/// Instantiate and run the compiler with the provided arguments and callback.
194+
///
195+
/// The callback will be invoked after the compiler ran all its analyses, but before code generation.
196+
/// Note that this macro accepts two different formats for the callback:
197+
/// 1. An ident that resolves to a function that accepts no argument and returns `ControlFlow<B, C>`
198+
/// ```ignore(needs-extern-crate)
199+
/// # extern crate rustc_driver;
200+
/// # extern crate rustc_interface;
201+
/// # #[macro_use]
202+
/// # extern crate rustc_smir;
203+
/// # extern crate stable_mir;
204+
/// #
205+
/// # fn main() {
206+
/// # use std::ops::ControlFlow;
207+
/// # use stable_mir::CompilerError;
208+
/// fn analyze_code() -> ControlFlow<(), ()> {
209+
/// // Your code goes in here.
210+
/// # ControlFlow::Continue(())
211+
/// }
212+
/// # let args = vec!["--verbose".to_string()];
213+
/// let result = run!(args, analyze_code);
214+
/// # assert_eq!(result, Err(CompilerError::Skipped))
215+
/// # }
216+
/// ```
217+
/// 2. A closure expression:
218+
/// ```ignore(needs-extern-crate)
219+
/// # extern crate rustc_driver;
220+
/// # extern crate rustc_interface;
221+
/// # #[macro_use]
222+
/// # extern crate rustc_smir;
223+
/// # extern crate stable_mir;
224+
/// #
225+
/// # fn main() {
226+
/// # use std::ops::ControlFlow;
227+
/// # use stable_mir::CompilerError;
228+
/// fn analyze_code(extra_args: Vec<String>) -> ControlFlow<(), ()> {
229+
/// # let _ = extra_args;
230+
/// // Your code goes in here.
231+
/// # ControlFlow::Continue(())
232+
/// }
233+
/// # let args = vec!["--verbose".to_string()];
234+
/// # let extra_args = vec![];
235+
/// let result = run!(args, || analyze_code(extra_args));
236+
/// # assert_eq!(result, Err(CompilerError::Skipped))
237+
/// # }
238+
/// ```
193239
#[macro_export]
194240
macro_rules! run {
241+
($args:expr, $callback_fn:ident) => {
242+
run_driver!($args, || $callback_fn())
243+
};
244+
($args:expr, $callback:expr) => {
245+
run_driver!($args, $callback)
246+
};
247+
}
248+
249+
/// Instantiate and run the compiler with the provided arguments and callback.
250+
///
251+
/// This is similar to `run` but it invokes the callback with the compiler's `TyCtxt`,
252+
/// which can be used to invoke internal APIs.
253+
#[macro_export]
254+
macro_rules! run_with_tcx {
255+
($args:expr, $callback_fn:ident) => {
256+
run_driver!($args, |tcx| $callback_fn(tcx), with_tcx)
257+
};
195258
($args:expr, $callback:expr) => {
196-
run!($args, tcx, $callback)
259+
run_driver!($args, $callback, with_tcx)
260+
};
261+
}
262+
263+
/// Optionally include an ident. This is needed due to macro hygiene.
264+
#[macro_export]
265+
#[doc(hidden)]
266+
macro_rules! optional {
267+
(with_tcx $ident:ident) => {
268+
$ident
197269
};
198-
($args:expr, $tcx:ident, $callback:expr) => {{
270+
}
271+
272+
/// Prefer using [run!] and [run_with_tcx] instead.
273+
///
274+
/// This macro implements the instantiation of a StableMIR driver, and it will invoke
275+
/// the given callback after the compiler analyses.
276+
///
277+
/// The third argument determines whether the callback requires `tcx` as an argument.
278+
#[macro_export]
279+
#[doc(hidden)]
280+
macro_rules! run_driver {
281+
($args:expr, $callback:expr $(, $with_tcx:ident)?) => {{
199282
use rustc_driver::{Callbacks, Compilation, RunCompiler};
200283
use rustc_interface::{interface, Queries};
201284
use stable_mir::CompilerError;
202285
use std::ops::ControlFlow;
203286

204-
pub struct StableMir<B = (), C = ()>
287+
pub struct StableMir<B = (), C = (), F = fn($(optional!($with_tcx TyCtxt))?) -> ControlFlow<B, C>>
205288
where
206289
B: Send,
207290
C: Send,
291+
F: FnOnce($(optional!($with_tcx TyCtxt))?) -> ControlFlow<B, C> + Send,
208292
{
209293
args: Vec<String>,
210-
callback: fn(TyCtxt<'_>) -> ControlFlow<B, C>,
294+
callback: Option<F>,
211295
result: Option<ControlFlow<B, C>>,
212296
}
213297

214-
impl<B, C> StableMir<B, C>
298+
impl<B, C, F> StableMir<B, C, F>
215299
where
216300
B: Send,
217301
C: Send,
302+
F: FnOnce($(optional!($with_tcx TyCtxt))?) -> ControlFlow<B, C> + Send,
218303
{
219304
/// Creates a new `StableMir` instance, with given test_function and arguments.
220-
pub fn new(args: Vec<String>, callback: fn(TyCtxt<'_>) -> ControlFlow<B, C>) -> Self {
221-
StableMir { args, callback, result: None }
305+
pub fn new(args: Vec<String>, callback: F) -> Self {
306+
StableMir { args, callback: Some(callback), result: None }
222307
}
223308

224309
/// Runs the compiler against given target and tests it with `test_function`
@@ -238,10 +323,11 @@ macro_rules! run {
238323
}
239324
}
240325

241-
impl<B, C> Callbacks for StableMir<B, C>
326+
impl<B, C, F> Callbacks for StableMir<B, C, F>
242327
where
243328
B: Send,
244329
C: Send,
330+
F: FnOnce($(optional!($with_tcx TyCtxt))?) -> ControlFlow<B, C> + Send,
245331
{
246332
/// Called after analysis. Return value instructs the compiler whether to
247333
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
@@ -251,20 +337,24 @@ macro_rules! run {
251337
queries: &'tcx Queries<'tcx>,
252338
) -> Compilation {
253339
queries.global_ctxt().unwrap().enter(|tcx| {
254-
rustc_internal::run(tcx, || {
255-
self.result = Some((self.callback)(tcx));
256-
})
257-
.unwrap();
258-
if self.result.as_ref().is_some_and(|val| val.is_continue()) {
259-
Compilation::Continue
340+
if let Some(callback) = self.callback.take() {
341+
rustc_internal::run(tcx, || {
342+
self.result = Some(callback($(optional!($with_tcx tcx))?));
343+
})
344+
.unwrap();
345+
if self.result.as_ref().is_some_and(|val| val.is_continue()) {
346+
Compilation::Continue
347+
} else {
348+
Compilation::Stop
349+
}
260350
} else {
261-
Compilation::Stop
351+
Compilation::Continue
262352
}
263353
})
264354
}
265355
}
266356

267-
StableMir::new($args, |$tcx| $callback).run()
357+
StableMir::new($args, $callback).run()
268358
}};
269359
}
270360

‎tests/ui-fulldeps/stable-mir/check_abi.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
#![feature(ascii_char, ascii_char_variants)]
1313

1414
extern crate rustc_hir;
15-
extern crate rustc_middle;
1615
#[macro_use]
1716
extern crate rustc_smir;
1817
extern crate rustc_driver;
1918
extern crate rustc_interface;
2019
extern crate stable_mir;
2120

22-
use rustc_middle::ty::TyCtxt;
2321
use rustc_smir::rustc_internal;
2422
use stable_mir::abi::{ArgAbi, CallConvention, FieldsShape, PassMode, VariantsShape};
2523
use stable_mir::mir::mono::Instance;
@@ -32,7 +30,7 @@ use std::ops::ControlFlow;
3230
const CRATE_NAME: &str = "input";
3331

3432
/// This function uses the Stable MIR APIs to get information about the test crate.
35-
fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
33+
fn test_stable_mir() -> ControlFlow<()> {
3634
// Find items in the local crate.
3735
let items = stable_mir::all_local_items();
3836

@@ -117,7 +115,7 @@ fn main() {
117115
CRATE_NAME.to_string(),
118116
path.to_string(),
119117
];
120-
run!(args, tcx, test_stable_mir(tcx)).unwrap();
118+
run!(args, test_stable_mir).unwrap();
121119
}
122120

123121
fn generate_input(path: &str) -> std::io::Result<()> {

‎tests/ui-fulldeps/stable-mir/check_allocation.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
#![feature(ascii_char, ascii_char_variants)]
1515

1616
extern crate rustc_hir;
17-
extern crate rustc_middle;
1817
#[macro_use]
1918
extern crate rustc_smir;
2019
extern crate rustc_driver;
2120
extern crate rustc_interface;
2221
extern crate stable_mir;
2322

24-
use rustc_middle::ty::TyCtxt;
2523
use rustc_smir::rustc_internal;
2624
use stable_mir::crate_def::CrateDef;
2725
use stable_mir::mir::alloc::GlobalAlloc;
@@ -40,7 +38,7 @@ use std::ops::ControlFlow;
4038
const CRATE_NAME: &str = "input";
4139

4240
/// This function uses the Stable MIR APIs to get information about the test crate.
43-
fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
41+
fn test_stable_mir() -> ControlFlow<()> {
4442
// Find items in the local crate.
4543
let items = stable_mir::all_local_items();
4644
check_foo(*get_item(&items, (ItemKind::Static, "FOO")).unwrap());
@@ -230,7 +228,7 @@ fn main() {
230228
CRATE_NAME.to_string(),
231229
path.to_string(),
232230
];
233-
run!(args, tcx, test_stable_mir(tcx)).unwrap();
231+
run!(args, test_stable_mir).unwrap();
234232
}
235233

236234
fn generate_input(path: &str) -> std::io::Result<()> {

‎tests/ui-fulldeps/stable-mir/check_defs.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![feature(assert_matches)]
1212
#![feature(control_flow_enum)]
1313

14-
extern crate rustc_middle;
1514
#[macro_use]
1615
extern crate rustc_smir;
1716
extern crate rustc_driver;
@@ -20,7 +19,6 @@ extern crate stable_mir;
2019

2120
use std::assert_matches::assert_matches;
2221
use mir::{mono::Instance, TerminatorKind::*};
23-
use rustc_middle::ty::TyCtxt;
2422
use rustc_smir::rustc_internal;
2523
use stable_mir::ty::{RigidTy, TyKind, Ty, UintTy};
2624
use stable_mir::*;
@@ -30,7 +28,7 @@ use std::ops::ControlFlow;
3028
const CRATE_NAME: &str = "input";
3129

3230
/// This function uses the Stable MIR APIs to get information about the test crate.
33-
fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
31+
fn test_stable_mir() -> ControlFlow<()> {
3432
let entry = stable_mir::entry_fn().unwrap();
3533
let main_fn = Instance::try_from(entry).unwrap();
3634
assert_eq!(main_fn.name(), "main");
@@ -113,7 +111,7 @@ fn main() {
113111
CRATE_NAME.to_string(),
114112
path.to_string(),
115113
];
116-
run!(args, tcx, test_stable_mir(tcx)).unwrap();
114+
run!(args, test_stable_mir).unwrap();
117115
}
118116

119117
fn generate_input(path: &str) -> std::io::Result<()> {

‎tests/ui-fulldeps/stable-mir/check_instance.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
#![feature(assert_matches)]
1212
#![feature(control_flow_enum)]
1313

14-
extern crate rustc_middle;
1514
#[macro_use]
1615
extern crate rustc_smir;
1716
extern crate rustc_driver;
1817
extern crate rustc_interface;
1918
extern crate stable_mir;
2019

2120
use mir::{mono::Instance, TerminatorKind::*};
22-
use rustc_middle::ty::TyCtxt;
2321
use rustc_smir::rustc_internal;
2422
use stable_mir::ty::{RigidTy, TyKind};
2523
use stable_mir::*;
@@ -29,7 +27,7 @@ use std::ops::ControlFlow;
2927
const CRATE_NAME: &str = "input";
3028

3129
/// This function uses the Stable MIR APIs to get information about the test crate.
32-
fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
30+
fn test_stable_mir() -> ControlFlow<()> {
3331
let items = stable_mir::all_local_items();
3432

3533
// Get all items and split generic vs monomorphic items.
@@ -96,7 +94,7 @@ fn main() {
9694
CRATE_NAME.to_string(),
9795
path.to_string(),
9896
];
99-
run!(args, tcx, test_stable_mir(tcx)).unwrap();
97+
run!(args, test_stable_mir).unwrap();
10098
}
10199

102100
fn generate_input(path: &str) -> std::io::Result<()> {

‎tests/ui-fulldeps/stable-mir/check_item_kind.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
#![feature(assert_matches)]
1212
#![feature(control_flow_enum)]
1313

14-
extern crate rustc_middle;
1514
#[macro_use]
1615
extern crate rustc_smir;
1716
extern crate rustc_driver;
1817
extern crate rustc_interface;
1918
extern crate stable_mir;
2019

21-
use rustc_middle::ty::TyCtxt;
2220
use rustc_smir::rustc_internal;
2321
use stable_mir::*;
2422
use std::io::Write;
@@ -27,7 +25,7 @@ use std::ops::ControlFlow;
2725
const CRATE_NAME: &str = "input";
2826

2927
/// This function uses the Stable MIR APIs to get information about the test crate.
30-
fn test_item_kind(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
28+
fn test_item_kind() -> ControlFlow<()> {
3129
let items = stable_mir::all_local_items();
3230
assert_eq!(items.len(), 4);
3331
// Constructor item.
@@ -59,7 +57,7 @@ fn main() {
5957
CRATE_NAME.to_string(),
6058
path.to_string(),
6159
];
62-
run!(args, tcx, test_item_kind(tcx)).unwrap();
60+
run!(args, test_item_kind).unwrap();
6361
}
6462

6563
fn generate_input(path: &str) -> std::io::Result<()> {

‎tests/ui-fulldeps/stable-mir/check_trait_queries.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
#![feature(assert_matches)]
1212
#![feature(control_flow_enum)]
1313

14-
extern crate rustc_middle;
1514
#[macro_use]
1615
extern crate rustc_smir;
1716
extern crate rustc_driver;
1817
extern crate rustc_interface;
1918
extern crate stable_mir;
2019

21-
use rustc_middle::ty::TyCtxt;
2220
use rustc_smir::rustc_internal;
2321
use stable_mir::CrateDef;
2422
use std::collections::HashSet;
@@ -83,7 +81,7 @@ fn main() {
8381
CRATE_NAME.to_string(),
8482
path.to_string(),
8583
];
86-
run!(args, test_traits()).unwrap();
84+
run!(args, test_traits).unwrap();
8785
}
8886

8987
fn generate_input(path: &str) -> std::io::Result<()> {

‎tests/ui-fulldeps/stable-mir/check_ty_fold.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
#![feature(assert_matches)]
1313
#![feature(control_flow_enum)]
1414

15-
extern crate rustc_middle;
1615
#[macro_use]
1716
extern crate rustc_smir;
1817
extern crate rustc_driver;
1918
extern crate rustc_interface;
2019
extern crate stable_mir;
2120

22-
use rustc_middle::ty::TyCtxt;
2321
use rustc_smir::rustc_internal;
2422
use stable_mir::ty::{RigidTy, TyKind, Ty, };
2523
use stable_mir::mir::{Body, MirVisitor, FieldIdx, Place, ProjectionElem, visit::{Location,
@@ -30,7 +28,7 @@ use std::ops::ControlFlow;
3028
const CRATE_NAME: &str = "input";
3129

3230
/// This function uses the Stable MIR APIs to get information about the test crate.
33-
fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
31+
fn test_stable_mir() -> ControlFlow<()> {
3432
let main_fn = stable_mir::entry_fn();
3533
let body = main_fn.unwrap().body();
3634
let mut visitor = PlaceVisitor{ body: &body, tested: false};
@@ -87,7 +85,7 @@ fn main() {
8785
CRATE_NAME.to_string(),
8886
path.to_string(),
8987
];
90-
run!(args, tcx, test_stable_mir(tcx)).unwrap();
88+
run!(args, test_stable_mir).unwrap();
9189
}
9290

9391
fn generate_input(path: &str) -> std::io::Result<()> {

‎tests/ui-fulldeps/stable-mir/compilation-result.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010
#![feature(rustc_private)]
1111
#![feature(assert_matches)]
1212

13-
extern crate rustc_middle;
1413
#[macro_use]
1514
extern crate rustc_smir;
1615
extern crate rustc_driver;
1716
extern crate rustc_interface;
1817
extern crate stable_mir;
1918

20-
use rustc_middle::ty::TyCtxt;
2119
use rustc_smir::rustc_internal;
2220
use std::io::Write;
2321

@@ -32,33 +30,41 @@ fn main() {
3230
test_continue(args.clone());
3331
test_break(args.clone());
3432
test_failed(args.clone());
35-
test_skipped(args);
33+
test_skipped(args.clone());
34+
test_captured(args)
3635
}
3736

3837
fn test_continue(args: Vec<String>) {
39-
let result = run!(args, ControlFlow::Continue::<(), bool>(true));
38+
let result = run!(args, || ControlFlow::Continue::<(), bool>(true));
4039
assert_eq!(result, Ok(true));
4140
}
4241

4342
fn test_break(args: Vec<String>) {
44-
let result = run!(args, ControlFlow::Break::<bool, i32>(false));
43+
let result = run!(args, || ControlFlow::Break::<bool, i32>(false));
4544
assert_eq!(result, Err(stable_mir::CompilerError::Interrupted(false)));
4645
}
4746

4847
#[allow(unreachable_code)]
4948
fn test_skipped(mut args: Vec<String>) {
5049
args.push("--version".to_string());
51-
let result = run!(args, unreachable!() as ControlFlow<()>);
50+
let result = run!(args, || unreachable!() as ControlFlow<()>);
5251
assert_eq!(result, Err(stable_mir::CompilerError::Skipped));
5352
}
5453

5554
#[allow(unreachable_code)]
5655
fn test_failed(mut args: Vec<String>) {
5756
args.push("--cfg=broken".to_string());
58-
let result = run!(args, unreachable!() as ControlFlow<()>);
57+
let result = run!(args, || unreachable!() as ControlFlow<()>);
5958
assert_eq!(result, Err(stable_mir::CompilerError::CompilationFailed));
6059
}
6160

61+
/// Test that we are able to pass a closure and set the return according to the captured value.
62+
fn test_captured(args: Vec<String>) {
63+
let captured = "10".to_string();
64+
let result = run!(args, || ControlFlow::Continue::<(), usize>(captured.len()));
65+
assert_eq!(result, Ok(captured.len()));
66+
}
67+
6268
fn generate_input(path: &str) -> std::io::Result<()> {
6369
let mut file = std::fs::File::create(path)?;
6470
write!(

‎tests/ui-fulldeps/stable-mir/crate-info.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
#![feature(control_flow_enum)]
1313

1414
extern crate rustc_hir;
15-
extern crate rustc_middle;
1615
#[macro_use]
1716
extern crate rustc_smir;
1817
extern crate rustc_driver;
1918
extern crate rustc_interface;
2019
extern crate stable_mir;
2120

2221
use rustc_hir::def::DefKind;
23-
use rustc_middle::ty::TyCtxt;
2422
use rustc_smir::rustc_internal;
2523
use stable_mir::ItemKind;
2624
use stable_mir::crate_def::CrateDef;
@@ -33,7 +31,7 @@ use std::ops::ControlFlow;
3331
const CRATE_NAME: &str = "input";
3432

3533
/// This function uses the Stable MIR APIs to get information about the test crate.
36-
fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
34+
fn test_stable_mir() -> ControlFlow<()> {
3735
// Get the local crate using stable_mir API.
3836
let local = stable_mir::local_crate();
3937
assert_eq!(&local.name, CRATE_NAME);
@@ -194,7 +192,7 @@ fn main() {
194192
CRATE_NAME.to_string(),
195193
path.to_string(),
196194
];
197-
run!(args, tcx, test_stable_mir(tcx)).unwrap();
195+
run!(args, test_stable_mir).unwrap();
198196
}
199197

200198
fn generate_input(path: &str) -> std::io::Result<()> {

‎tests/ui-fulldeps/stable-mir/projections.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
#![feature(control_flow_enum)]
1313

1414
extern crate rustc_hir;
15-
extern crate rustc_middle;
1615
#[macro_use]
1716
extern crate rustc_smir;
1817
extern crate rustc_driver;
1918
extern crate rustc_interface;
2019
extern crate stable_mir;
2120

22-
use rustc_middle::ty::TyCtxt;
2321
use rustc_smir::rustc_internal;
2422
use stable_mir::crate_def::CrateDef;
2523
use stable_mir::mir::{ProjectionElem, Rvalue, StatementKind};
@@ -32,7 +30,7 @@ use std::ops::ControlFlow;
3230
const CRATE_NAME: &str = "input";
3331

3432
/// Tests projections within Place objects
35-
fn test_place_projections(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
33+
fn test_place_projections() -> ControlFlow<()> {
3634
let items = stable_mir::all_local_items();
3735
let body = get_item(&items, (ItemKind::Fn, "projections")).unwrap().body();
3836
assert_eq!(body.blocks.len(), 4);
@@ -159,7 +157,7 @@ fn main() {
159157
CRATE_NAME.to_string(),
160158
path.to_string(),
161159
];
162-
run!(args, tcx, test_place_projections(tcx)).unwrap();
160+
run!(args, test_place_projections).unwrap();
163161
}
164162

165163
fn generate_input(path: &str) -> std::io::Result<()> {

‎tests/ui-fulldeps/stable-mir/smir_internal.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::ops::ControlFlow;
2626

2727
const CRATE_NAME: &str = "input";
2828

29-
fn test_translation(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
29+
fn test_translation(_tcx: TyCtxt) -> ControlFlow<()> {
3030
let main_fn = stable_mir::entry_fn().unwrap();
3131
let body = main_fn.body();
3232
let orig_ty = body.locals()[0].ty;
@@ -48,7 +48,7 @@ fn main() {
4848
CRATE_NAME.to_string(),
4949
path.to_string(),
5050
];
51-
run!(args, tcx, test_translation(tcx)).unwrap();
51+
run_with_tcx!(args, test_translation).unwrap();
5252
}
5353

5454
fn generate_input(path: &str) -> std::io::Result<()> {

‎tests/ui-fulldeps/stable-mir/smir_visitor.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
#![feature(assert_matches)]
1212
#![feature(control_flow_enum)]
1313

14-
extern crate rustc_middle;
1514
#[macro_use]
1615
extern crate rustc_smir;
1716
extern crate rustc_driver;
1817
extern crate rustc_interface;
1918
extern crate stable_mir;
2019

2120
use std::collections::HashSet;
22-
use rustc_middle::ty::TyCtxt;
2321
use rustc_smir::rustc_internal;
2422
use stable_mir::*;
2523
use stable_mir::mir::MirVisitor;
@@ -28,7 +26,7 @@ use std::ops::ControlFlow;
2826

2927
const CRATE_NAME: &str = "input";
3028

31-
fn test_visitor(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
29+
fn test_visitor() -> ControlFlow<()> {
3230
let main_fn = stable_mir::entry_fn();
3331
let main_body = main_fn.unwrap().body();
3432
let main_visitor = TestVisitor::collect(&main_body);
@@ -116,7 +114,7 @@ fn main() {
116114
CRATE_NAME.to_string(),
117115
path.to_string(),
118116
];
119-
run!(args, tcx, test_visitor(tcx)).unwrap();
117+
run!(args, test_visitor).unwrap();
120118
}
121119

122120
fn generate_input(path: &str) -> std::io::Result<()> {

0 commit comments

Comments
 (0)
Please sign in to comment.