Skip to content

Commit

Permalink
Rollup merge of rust-lang#57436 - Xanewok:save-analysis-access-ice-fi…
Browse files Browse the repository at this point in the history
…x, 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
  • Loading branch information
pietroalbini authored Jan 12, 2019
2 parents 1fa2932 + eed163e commit f014b94
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! recording the output.
use rustc::hir::def::Def as HirDef;
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::hir::def_id::DefId;
use rustc::session::config::Input;
use rustc::ty::{self, TyCtxt};
use rustc_data_structures::fx::FxHashSet;
Expand Down Expand Up @@ -56,14 +56,14 @@ macro_rules! access_from {
($save_ctxt:expr, $vis:expr, $id:expr) => {
Access {
public: $vis.node.is_pub(),
reachable: $save_ctxt.tcx.privacy_access_levels(LOCAL_CRATE).is_reachable($id),
reachable: $save_ctxt.access_levels.is_reachable($id),
}
};

($save_ctxt:expr, $item:expr) => {
Access {
public: $item.vis.node.is_pub(),
reachable: $save_ctxt.tcx.privacy_access_levels(LOCAL_CRATE).is_reachable($item.id),
reachable: $save_ctxt.access_levels.is_reachable($item.id),
}
};
}
Expand Down
11 changes: 11 additions & 0 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ use rustc::hir;
use rustc::hir::def::Def as HirDef;
use rustc::hir::Node;
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::middle::privacy::AccessLevels;
use rustc::middle::cstore::ExternCrate;
use rustc::session::config::{CrateType, Input, OutputType};
use rustc::ty::{self, TyCtxt};
use rustc_typeck::hir_ty_to_ty;
use rustc_codegen_utils::link::{filename_for_metadata, out_filename};
use rustc_data_structures::sync::Lrc;

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

// Privacy checking requires and is done after type checking; use a
// fallback in case the access levels couldn't have been correctly computed.
let access_levels = match tcx.sess.compile_status() {
Ok(..) => tcx.privacy_access_levels(LOCAL_CRATE),
Err(..) => Lrc::new(AccessLevels::default()),
};

let save_ctxt = SaveContext {
tcx,
tables: &ty::TypeckTables::empty(None),
analysis,
access_levels: &access_levels,
span_utils: SpanUtils::new(&tcx.sess),
config: find_config(config),
impl_counter: Cell::new(0),
Expand Down

0 comments on commit f014b94

Please sign in to comment.