diff options
| author | bors <bors@rust-lang.org> | 2023-01-12 13:59:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-01-12 13:59:30 +0000 |
| commit | 222d1ff68d5bfe1dc2d7f3f0c42811fe12964af9 (patch) | |
| tree | 1a75241d0b3c0600dcb76bd03d07d9fad8f31062 /src | |
| parent | 606c3907251397a42e23d3e60de31be9d32525d5 (diff) | |
| parent | 58782a8842bdd74e3304092251a1d06e5b6b550b (diff) | |
Auto merge of #105603 - oli-obk:non_repeatable_queries, r=petrochenkov
Harden the pre-tyctxt query system against accidental recomputation While the current compiler has no issues where we `take` and then compute the query again, in https://github.com/rust-lang/rust/pull/105462 I accidentally introduced such a case. I also took the opportunity to remove `peek_mut`, which is only ever used for `global_tcx` to then invoke `enter`. I added an `enter` method directly on the query.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/doctest.rs | 8 | ||||
| -rw-r--r-- | src/librustdoc/lib.rs | 5 | ||||
| -rw-r--r-- | src/tools/miri/src/bin/miri.rs | 2 |
3 files changed, 6 insertions, 9 deletions
diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 81d9c46447a..5f8c777f32a 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -115,9 +115,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> { let (tests, unused_extern_reports, compiling_test_count) = interface::run_compiler(config, |compiler| { compiler.enter(|queries| { - let mut global_ctxt = queries.global_ctxt()?.take(); - - let collector = global_ctxt.enter(|tcx| { + let collector = queries.global_ctxt()?.enter(|tcx| { let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID); let opts = scrape_test_config(crate_attrs); @@ -156,9 +154,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> { let unused_extern_reports = collector.unused_extern_reports.clone(); let compiling_test_count = collector.compiling_test_count.load(Ordering::SeqCst); - let ret: Result<_, ErrorGuaranteed> = - Ok((collector.tests, unused_extern_reports, compiling_test_count)); - ret + Ok((collector.tests, unused_extern_reports, compiling_test_count)) }) })?; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index ef1d7da5a34..ed77de200a9 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -800,7 +800,8 @@ fn main_args(at_args: &[String]) -> MainResult { // FIXME(#83761): Resolver cloning can lead to inconsistencies between data in the // two copies because one of the copies can be modified after `TyCtxt` construction. let (resolver, resolver_caches) = { - let (krate, resolver, _) = &*abort_on_err(queries.expansion(), sess).peek(); + let expansion = abort_on_err(queries.expansion(), sess); + let (krate, resolver, _) = &*expansion.borrow(); let resolver_caches = resolver.borrow_mut().access(|resolver| { collect_intra_doc_links::early_resolve_intra_doc_links( resolver, @@ -817,7 +818,7 @@ fn main_args(at_args: &[String]) -> MainResult { sess.fatal("Compilation failed, aborting rustdoc"); } - let mut global_ctxt = abort_on_err(queries.global_ctxt(), sess).peek_mut(); + let global_ctxt = abort_on_err(queries.global_ctxt(), sess); global_ctxt.enter(|tcx| { let (krate, render_opts, mut cache) = sess.time("run_global_ctxt", || { diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index 8c01748613c..6a147de3be2 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -61,7 +61,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls { ) -> Compilation { compiler.session().abort_if_errors(); - queries.global_ctxt().unwrap().peek_mut().enter(|tcx| { + queries.global_ctxt().unwrap().enter(|tcx| { init_late_loggers(tcx); if !tcx.sess.crate_types().contains(&CrateType::Executable) { tcx.sess.fatal("miri only makes sense on bin crates"); |
