Move methods from Map to TyCtxt, part 2.
Continuing the work started in #136466. Every method gains a `hir_` prefix, though for the ones that already have a `par_` or `try_par_` prefix I added the `hir_` after that.
This commit is contained in:
parent
ce36a966c7
commit
fd7b4bf4e1
108 changed files with 314 additions and 346 deletions
|
|
@ -2121,7 +2121,7 @@ impl Discriminant {
|
|||
/// simplified
|
||||
pub(crate) fn expr(&self, tcx: TyCtxt<'_>) -> Option<String> {
|
||||
self.expr
|
||||
.map(|body| rendered_const(tcx, tcx.hir_body(body), tcx.hir().body_owner_def_id(body)))
|
||||
.map(|body| rendered_const(tcx, tcx.hir_body(body), tcx.hir_body_owner_def_id(body)))
|
||||
}
|
||||
pub(crate) fn value(&self, tcx: TyCtxt<'_>, with_underscores: bool) -> String {
|
||||
print_evaluated_const(tcx, self.value, with_underscores, false).unwrap()
|
||||
|
|
@ -2417,7 +2417,7 @@ impl ConstantKind {
|
|||
ConstantKind::Path { ref path } => path.to_string(),
|
||||
ConstantKind::Extern { def_id } => print_inlined_const(tcx, def_id),
|
||||
ConstantKind::Local { body, .. } | ConstantKind::Anonymous { body } => {
|
||||
rendered_const(tcx, tcx.hir_body(body), tcx.hir().body_owner_def_id(body))
|
||||
rendered_const(tcx, tcx.hir_body(body), tcx.hir_body_owner_def_id(body))
|
||||
}
|
||||
ConstantKind::Infer { .. } => "_".to_string(),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -336,7 +336,7 @@ pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
|
|||
match n.kind() {
|
||||
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, args: _ }) => {
|
||||
let s = if let Some(def) = def.as_local() {
|
||||
rendered_const(cx.tcx, cx.tcx.hir().body_owned_by(def), def)
|
||||
rendered_const(cx.tcx, cx.tcx.hir_body_owned_by(def), def)
|
||||
} else {
|
||||
inline::print_inlined_const(cx.tcx, def)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -304,8 +304,7 @@ pub(crate) fn create_config(
|
|||
return tcx.typeck(typeck_root_def_id);
|
||||
}
|
||||
|
||||
let hir = tcx.hir();
|
||||
let body = hir.body_owned_by(def_id);
|
||||
let body = tcx.hir_body_owned_by(def_id);
|
||||
debug!("visiting body for {def_id:?}");
|
||||
EmitIgnoredResolutionErrors::new(tcx).visit_body(body);
|
||||
(rustc_interface::DEFAULT_QUERY_PROVIDERS.typeck)(tcx, def_id)
|
||||
|
|
@ -335,14 +334,14 @@ pub(crate) fn run_global_ctxt(
|
|||
|
||||
// NOTE: These are copy/pasted from typeck/lib.rs and should be kept in sync with those changes.
|
||||
let _ = tcx.sess.time("wf_checking", || {
|
||||
tcx.hir().try_par_for_each_module(|module| tcx.ensure_ok().check_mod_type_wf(module))
|
||||
tcx.try_par_hir_for_each_module(|module| tcx.ensure_ok().check_mod_type_wf(module))
|
||||
});
|
||||
|
||||
tcx.dcx().abort_if_errors();
|
||||
|
||||
tcx.sess.time("missing_docs", || rustc_lint::check_crate(tcx));
|
||||
tcx.sess.time("check_mod_attrs", || {
|
||||
tcx.hir().for_each_module(|module| tcx.ensure_ok().check_mod_attrs(module))
|
||||
tcx.hir_for_each_module(|module| tcx.ensure_ok().check_mod_attrs(module))
|
||||
});
|
||||
rustc_passes::stability::check_unused_or_stable_features(tcx);
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ impl<'tcx> HirCollector<'tcx> {
|
|||
pub fn collect_crate(mut self) -> Vec<ScrapedDocTest> {
|
||||
let tcx = self.tcx;
|
||||
self.visit_testable("".to_string(), CRATE_DEF_ID, tcx.hir().span(CRATE_HIR_ID), |this| {
|
||||
tcx.hir().walk_toplevel_module(this)
|
||||
tcx.hir_walk_toplevel_module(this)
|
||||
});
|
||||
self.collector.tests
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ pub(crate) fn collect_spans_and_sources(
|
|||
let mut visitor = SpanMapVisitor { tcx, matches: FxHashMap::default() };
|
||||
|
||||
if generate_link_to_definition {
|
||||
tcx.hir().walk_toplevel_module(&mut visitor);
|
||||
tcx.hir_walk_toplevel_module(&mut visitor);
|
||||
}
|
||||
let sources = sources::collect_local_sources(tcx, src_root, krate);
|
||||
(sources, visitor.matches)
|
||||
|
|
@ -173,18 +173,18 @@ impl SpanMapVisitor<'_> {
|
|||
}
|
||||
|
||||
fn infer_id(&mut self, hir_id: HirId, expr_hir_id: Option<HirId>, span: Span) {
|
||||
let hir = self.tcx.hir();
|
||||
let body_id = hir.enclosing_body_owner(hir_id);
|
||||
let tcx = self.tcx;
|
||||
let body_id = tcx.hir_enclosing_body_owner(hir_id);
|
||||
// FIXME: this is showing error messages for parts of the code that are not
|
||||
// compiled (because of cfg)!
|
||||
//
|
||||
// See discussion in https://github.com/rust-lang/rust/issues/69426#issuecomment-1019412352
|
||||
let typeck_results = self.tcx.typeck_body(hir.body_owned_by(body_id).id());
|
||||
let typeck_results = tcx.typeck_body(tcx.hir_body_owned_by(body_id).id());
|
||||
// Interestingly enough, for method calls, we need the whole expression whereas for static
|
||||
// method/function calls, we need the call expression specifically.
|
||||
if let Some(def_id) = typeck_results.type_dependent_def_id(expr_hir_id.unwrap_or(hir_id)) {
|
||||
let link = if def_id.as_local().is_some() {
|
||||
LinkFromSrc::Local(rustc_span(def_id, self.tcx))
|
||||
LinkFromSrc::Local(rustc_span(def_id, tcx))
|
||||
} else {
|
||||
LinkFromSrc::External(def_id)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -846,7 +846,7 @@ fn convert_static(
|
|||
is_unsafe: safety.is_unsafe(),
|
||||
expr: stat
|
||||
.expr
|
||||
.map(|e| rendered_const(tcx, tcx.hir_body(e), tcx.hir().body_owner_def_id(e)))
|
||||
.map(|e| rendered_const(tcx, tcx.hir_body(e), tcx.hir_body_owner_def_id(e)))
|
||||
.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,8 +135,7 @@ where
|
|||
// If we visit an item that contains an expression outside a function body,
|
||||
// then we need to exit before calling typeck (which will panic). See
|
||||
// test/run-make/rustdoc-scrape-examples-invalid-expr for an example.
|
||||
let hir = tcx.hir();
|
||||
if hir.maybe_body_owned_by(ex.hir_id.owner.def_id).is_none() {
|
||||
if tcx.hir_maybe_body_owned_by(ex.hir_id.owner.def_id).is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -302,7 +301,7 @@ pub(crate) fn run(
|
|||
// Run call-finder on all items
|
||||
let mut calls = FxIndexMap::default();
|
||||
let mut finder = FindCalls { calls: &mut calls, cx, target_crates, bin_crate };
|
||||
tcx.hir().visit_all_item_likes_in_crate(&mut finder);
|
||||
tcx.hir_visit_all_item_likes_in_crate(&mut finder);
|
||||
|
||||
// The visitor might have found a type error, which we need to
|
||||
// promote to a fatal error
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue