diff options
Diffstat (limited to 'src/librustdoc/core.rs')
| -rw-r--r-- | src/librustdoc/core.rs | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 413f5bdf521..b2eeaf584bf 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -1,4 +1,3 @@ -use rustc_attr as attr; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{self, Lrc}; use rustc_driver::abort_on_err; @@ -14,9 +13,8 @@ use rustc_hir::{ }; use rustc_interface::interface; use rustc_middle::hir::map::Map; -use rustc_middle::middle::cstore::CrateStore; use rustc_middle::middle::privacy::AccessLevels; -use rustc_middle::ty::{Ty, TyCtxt}; +use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use rustc_resolve as resolve; use rustc_session::config::{self, CrateType, ErrorOutputType}; use rustc_session::lint; @@ -26,7 +24,7 @@ use rustc_span::source_map; use rustc_span::symbol::sym; use rustc_span::DUMMY_SP; -use std::cell::RefCell; +use std::cell::{Cell, RefCell}; use std::mem; use std::rc::Rc; @@ -43,6 +41,10 @@ crate type ExternalPaths = FxHashMap<DefId, (Vec<String>, clean::TypeKind)>; crate struct DocContext<'tcx> { crate tcx: TyCtxt<'tcx>, crate resolver: Rc<RefCell<interface::BoxedResolver>>, + /// Used for normalization. + /// + /// Most of this logic is copied from rustc_lint::late. + crate param_env: Cell<ParamEnv<'tcx>>, /// Later on moved into `CACHE_KEY` crate renderinfo: RefCell<RenderInfo>, /// Later on moved through `clean::Crate` into `CACHE_KEY` @@ -80,6 +82,13 @@ impl<'tcx> DocContext<'tcx> { &self.tcx.sess } + crate fn with_param_env<T, F: FnOnce() -> T>(&self, def_id: DefId, f: F) -> T { + let old_param_env = self.param_env.replace(self.tcx.param_env(def_id)); + let ret = f(); + self.param_env.set(old_param_env); + ret + } + crate fn enter_resolver<F, R>(&self, f: F) -> R where F: FnOnce(&mut resolve::Resolver<'_>) -> R, @@ -156,21 +165,6 @@ impl<'tcx> DocContext<'tcx> { def_id.as_local().map(|def_id| self.tcx.hir().local_def_id_to_hir_id(def_id)) } } - - crate fn stability(&self, id: HirId) -> Option<attr::Stability> { - self.tcx - .hir() - .opt_local_def_id(id) - .and_then(|def_id| self.tcx.lookup_stability(def_id.to_def_id())) - .cloned() - } - - crate fn deprecation(&self, id: HirId) -> Option<attr::Deprecation> { - self.tcx - .hir() - .opt_local_def_id(id) - .and_then(|def_id| self.tcx.lookup_deprecation(def_id.to_def_id())) - } } /// Creates a new diagnostic `Handler` that can be used to emit warnings and errors. @@ -376,6 +370,7 @@ crate fn run_core( error_format, edition, describe_lints, + crate_name, ..Options::default() }; @@ -389,7 +384,6 @@ crate fn run_core( file_loader: None, diagnostic_output: DiagnosticOutput::Default, stderr: None, - crate_name, lint_caps, register_lints: None, override_queries: Some(|_sess, providers, _external_providers| { @@ -417,9 +411,7 @@ crate fn run_core( let hir = tcx.hir(); let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(def_id))); debug!("visiting body for {:?}", def_id); - tcx.sess.time("emit_ignored_resolution_errors", || { - EmitIgnoredResolutionErrors::new(tcx).visit_body(body); - }); + EmitIgnoredResolutionErrors::new(tcx).visit_body(body); (rustc_interface::DEFAULT_QUERY_PROVIDERS.typeck)(tcx, def_id) }; }), @@ -540,6 +532,7 @@ fn run_global_ctxt( let mut ctxt = DocContext { tcx, resolver, + param_env: Cell::new(ParamEnv::empty()), external_traits: Default::default(), active_extern_traits: Default::default(), renderinfo: RefCell::new(renderinfo), |
