summary refs log tree commit diff
path: root/compiler/rustc_interface/src/interface.rs
diff options
context:
space:
mode:
authorhyd-dev <yd-huang@outlook.com>2021-03-15 17:57:53 +0800
committerhyd-dev <yd-huang@outlook.com>2021-03-15 18:24:58 +0800
commitd7ab3c77b3259e25e15d77b6939af4ba8d3be4c0 (patch)
tree7c18417d7bfbb0d9454cc6510f9155ef03a66b2b /compiler/rustc_interface/src/interface.rs
parent3963c3da02d17b9c52feaf0e05271db2ec51c29f (diff)
downloadrust-d7ab3c77b3259e25e15d77b6939af4ba8d3be4c0.tar.gz
rust-d7ab3c77b3259e25e15d77b6939af4ba8d3be4c0.zip
Add `rustc_interface::interface::Config::parse_sess_created`
Diffstat (limited to 'compiler/rustc_interface/src/interface.rs')
-rw-r--r--compiler/rustc_interface/src/interface.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs
index 502e7155c2e..14bffb54e7a 100644
--- a/compiler/rustc_interface/src/interface.rs
+++ b/compiler/rustc_interface/src/interface.rs
@@ -142,6 +142,9 @@ pub struct Config {
 
     pub lint_caps: FxHashMap<lint::LintId, lint::Level>,
 
+    /// This is a callback from the driver that is called when [`ParseSess`] is created.
+    pub parse_sess_created: Option<Box<dyn FnOnce(&mut ParseSess) + Send>>,
+
     /// This is a callback from the driver that is called when we're registering lints;
     /// it is called during plugin registration when we have the LintStore in a non-shared state.
     ///
@@ -166,7 +169,7 @@ pub struct Config {
 
 pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R) -> R {
     let registry = &config.registry;
-    let (sess, codegen_backend) = util::create_session(
+    let (mut sess, codegen_backend) = util::create_session(
         config.opts,
         config.crate_cfg,
         config.diagnostic_output,
@@ -177,6 +180,10 @@ pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R
         registry.clone(),
     );
 
+    if let Some(parse_sess_created) = config.parse_sess_created {
+        parse_sess_created(&mut Lrc::get_mut(&mut sess).unwrap().parse_sess);
+    }
+
     let compiler = Compiler {
         sess,
         codegen_backend,