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