Skip to content

Commit f014b94

Browse files
authored
Rollup merge of rust-lang#57436 - Xanewok:save-analysis-access-ice-fix, r=nikomatsakis
save-analysis: use a fallback when access levels couldn't be computed Fixing an RLS regression I introduced in rust-lang#57343 😢 I missed a case where we get [called back with analysis when type checking fails](https://github.com/rust-lang/rust/blob/9d54812829e9d92dac35a4a0f358cdc5a2475371/src/librustc_driver/driver.rs#L1264). Since privacy checking normally is done afterwards, when we execute the `privacy_access_levels` query inside the save_analysis callback we'll calculate it for the first time and since typeck info isn't complete, we'll crash there. Double-checked locally and it seems to have fixed the problem. r? @nikomatsakis
2 parents 1fa2932 + eed163e commit f014b94

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/librustc_save_analysis/dump_visitor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! recording the output.
1515
1616
use rustc::hir::def::Def as HirDef;
17-
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
17+
use rustc::hir::def_id::DefId;
1818
use rustc::session::config::Input;
1919
use rustc::ty::{self, TyCtxt};
2020
use rustc_data_structures::fx::FxHashSet;
@@ -56,14 +56,14 @@ macro_rules! access_from {
5656
($save_ctxt:expr, $vis:expr, $id:expr) => {
5757
Access {
5858
public: $vis.node.is_pub(),
59-
reachable: $save_ctxt.tcx.privacy_access_levels(LOCAL_CRATE).is_reachable($id),
59+
reachable: $save_ctxt.access_levels.is_reachable($id),
6060
}
6161
};
6262

6363
($save_ctxt:expr, $item:expr) => {
6464
Access {
6565
public: $item.vis.node.is_pub(),
66-
reachable: $save_ctxt.tcx.privacy_access_levels(LOCAL_CRATE).is_reachable($item.id),
66+
reachable: $save_ctxt.access_levels.is_reachable($item.id),
6767
}
6868
};
6969
}

src/librustc_save_analysis/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ use rustc::hir;
3535
use rustc::hir::def::Def as HirDef;
3636
use rustc::hir::Node;
3737
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
38+
use rustc::middle::privacy::AccessLevels;
3839
use rustc::middle::cstore::ExternCrate;
3940
use rustc::session::config::{CrateType, Input, OutputType};
4041
use rustc::ty::{self, TyCtxt};
4142
use rustc_typeck::hir_ty_to_ty;
4243
use rustc_codegen_utils::link::{filename_for_metadata, out_filename};
44+
use rustc_data_structures::sync::Lrc;
4345

4446
use std::cell::Cell;
4547
use std::default::Default;
@@ -68,6 +70,7 @@ use rls_data::config::Config;
6870
pub struct SaveContext<'l, 'tcx: 'l> {
6971
tcx: TyCtxt<'l, 'tcx, 'tcx>,
7072
tables: &'l ty::TypeckTables<'tcx>,
73+
access_levels: &'l AccessLevels,
7174
analysis: &'l ty::CrateAnalysis,
7275
span_utils: SpanUtils<'tcx>,
7376
config: Config,
@@ -1124,10 +1127,18 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
11241127
tcx.dep_graph.with_ignore(|| {
11251128
info!("Dumping crate {}", cratename);
11261129

1130+
// Privacy checking requires and is done after type checking; use a
1131+
// fallback in case the access levels couldn't have been correctly computed.
1132+
let access_levels = match tcx.sess.compile_status() {
1133+
Ok(..) => tcx.privacy_access_levels(LOCAL_CRATE),
1134+
Err(..) => Lrc::new(AccessLevels::default()),
1135+
};
1136+
11271137
let save_ctxt = SaveContext {
11281138
tcx,
11291139
tables: &ty::TypeckTables::empty(None),
11301140
analysis,
1141+
access_levels: &access_levels,
11311142
span_utils: SpanUtils::new(&tcx.sess),
11321143
config: find_config(config),
11331144
impl_counter: Cell::new(0),

0 commit comments

Comments
 (0)