From d7ab3c77b3259e25e15d77b6939af4ba8d3be4c0 Mon Sep 17 00:00:00 2001 From: hyd-dev Date: Mon, 15 Mar 2021 17:57:53 +0800 Subject: Add `rustc_interface::interface::Config::parse_sess_created` --- compiler/rustc_interface/src/interface.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_interface/src/interface.rs') 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, + /// This is a callback from the driver that is called when [`ParseSess`] is created. + pub parse_sess_created: Option>, + /// 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(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(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, -- cgit 1.4.1-3-g733a5 From 4709dcd476540621f7fb023ae68b4f916d857278 Mon Sep 17 00:00:00 2001 From: hyd-dev Date: Mon, 15 Mar 2021 20:44:48 +0800 Subject: Change the `.unwrap` to `.expect` with a helpful message --- compiler/rustc_interface/src/interface.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_interface/src/interface.rs') diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 14bffb54e7a..a1090ee316d 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -181,7 +181,11 @@ pub fn create_compiler_and_run(config: Config, f: impl FnOnce(&Compiler) -> R ); if let Some(parse_sess_created) = config.parse_sess_created { - parse_sess_created(&mut Lrc::get_mut(&mut sess).unwrap().parse_sess); + parse_sess_created( + &mut Lrc::get_mut(&mut sess) + .expect("create_session() should never share the returned session") + .parse_sess, + ); } let compiler = Compiler { -- cgit 1.4.1-3-g733a5