2019-07-26 16:54:25 -05:00
|
|
|
//@ run-pass
|
2018-12-08 13:30:23 -06:00
|
|
|
// Test that the Callbacks interface to the compiler works.
|
2015-01-30 02:44:27 -06:00
|
|
|
|
2015-04-22 17:20:57 -05:00
|
|
|
//@ ignore-cross-compile
|
2020-05-28 11:32:12 -05:00
|
|
|
//@ ignore-remote
|
2015-02-02 18:40:52 -06:00
|
|
|
|
2018-07-24 12:24:12 -05:00
|
|
|
#![feature(rustc_private)]
|
2015-01-30 02:44:27 -06:00
|
|
|
|
|
|
|
extern crate rustc_driver;
|
2018-12-08 13:30:23 -06:00
|
|
|
extern crate rustc_interface;
|
2015-01-30 02:44:27 -06:00
|
|
|
|
2018-12-08 13:30:23 -06:00
|
|
|
use rustc_interface::interface;
|
2015-01-30 02:44:27 -06:00
|
|
|
|
2018-05-17 13:32:09 -05:00
|
|
|
struct TestCalls<'a> {
|
|
|
|
count: &'a mut u32
|
2015-01-30 02:44:27 -06:00
|
|
|
}
|
|
|
|
|
2018-12-08 13:30:23 -06:00
|
|
|
impl rustc_driver::Callbacks for TestCalls<'_> {
|
|
|
|
fn config(&mut self, _config: &mut interface::Config) {
|
2018-05-17 13:32:09 -05:00
|
|
|
*self.count *= 2;
|
2015-01-30 02:44:27 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2018-05-17 13:32:09 -05:00
|
|
|
let mut count = 1;
|
2018-12-08 13:30:23 -06:00
|
|
|
let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()];
|
2019-05-06 06:47:58 -05:00
|
|
|
rustc_driver::catch_fatal_errors(|| {
|
2020-10-07 07:09:59 -05:00
|
|
|
rustc_driver::RunCompiler::new(&args, &mut TestCalls { count: &mut count }).run().ok();
|
|
|
|
})
|
|
|
|
.ok();
|
2018-12-08 13:30:23 -06:00
|
|
|
assert_eq!(count, 2);
|
2015-01-30 02:44:27 -06:00
|
|
|
}
|