Skip to content

Commit d7ab3c7

Browse files
author
hyd-dev
committed
Add rustc_interface::interface::Config::parse_sess_created
1 parent 3963c3d commit d7ab3c7

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

compiler/rustc_driver/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ fn run_compiler(
215215
diagnostic_output,
216216
stderr: None,
217217
lint_caps: Default::default(),
218+
parse_sess_created: None,
218219
register_lints: None,
219220
override_queries: None,
220221
make_codegen_backend: make_codegen_backend.take().unwrap(),
@@ -298,6 +299,7 @@ fn run_compiler(
298299
diagnostic_output,
299300
stderr: None,
300301
lint_caps: Default::default(),
302+
parse_sess_created: None,
301303
register_lints: None,
302304
override_queries: None,
303305
make_codegen_backend: make_codegen_backend.unwrap(),

compiler/rustc_interface/src/interface.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ pub struct Config {
142142

143143
pub lint_caps: FxHashMap<lint::LintId, lint::Level>,
144144

145+
/// This is a callback from the driver that is called when [`ParseSess`] is created.
146+
pub parse_sess_created: Option<Box<dyn FnOnce(&mut ParseSess) + Send>>,
147+
145148
/// This is a callback from the driver that is called when we're registering lints;
146149
/// it is called during plugin registration when we have the LintStore in a non-shared state.
147150
///
@@ -166,7 +169,7 @@ pub struct Config {
166169

167170
pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R) -> R {
168171
let registry = &config.registry;
169-
let (sess, codegen_backend) = util::create_session(
172+
let (mut sess, codegen_backend) = util::create_session(
170173
config.opts,
171174
config.crate_cfg,
172175
config.diagnostic_output,
@@ -177,6 +180,10 @@ pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R
177180
registry.clone(),
178181
);
179182

183+
if let Some(parse_sess_created) = config.parse_sess_created {
184+
parse_sess_created(&mut Lrc::get_mut(&mut sess).unwrap().parse_sess);
185+
}
186+
180187
let compiler = Compiler {
181188
sess,
182189
codegen_backend,

src/librustdoc/core.rs

+1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ crate fn create_config(
311311
diagnostic_output: DiagnosticOutput::Default,
312312
stderr: None,
313313
lint_caps,
314+
parse_sess_created: None,
314315
register_lints: Some(box crate::lint::register_lints),
315316
override_queries: Some(|_sess, providers, _external_providers| {
316317
// Most lints will require typechecking, so just don't run them.

src/librustdoc/doctest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
9595
diagnostic_output: DiagnosticOutput::Default,
9696
stderr: None,
9797
lint_caps,
98+
parse_sess_created: None,
9899
register_lints: Some(box crate::lint::register_lints),
99100
override_queries: None,
100101
make_codegen_backend: None,

0 commit comments

Comments
 (0)