Rollup merge of #112018 - GuillaumeGomez:cleanup-tcx, r=notriddle
Clean up usage of `cx.tcx` when `tcx` is already set into a variable I discovered a few cases where `cx.tcx` (and equivalents) was used whereas `tcx` was already stored into a variable. In those cases, better to just use `tcx` directly. r? `@notriddle`
This commit is contained in:
commit
9f5dce7d75
@ -355,9 +355,9 @@ pub(crate) fn build_impl(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _prof_timer = cx.tcx.sess.prof.generic_activity("build_impl");
|
|
||||||
|
|
||||||
let tcx = cx.tcx;
|
let tcx = cx.tcx;
|
||||||
|
let _prof_timer = tcx.sess.prof.generic_activity("build_impl");
|
||||||
|
|
||||||
let associated_trait = tcx.impl_trait_ref(did).map(ty::EarlyBinder::skip_binder);
|
let associated_trait = tcx.impl_trait_ref(did).map(ty::EarlyBinder::skip_binder);
|
||||||
|
|
||||||
// Only inline impl if the implemented trait is
|
// Only inline impl if the implemented trait is
|
||||||
|
@ -193,7 +193,7 @@ pub(crate) fn build_deref_target_impls(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(prim) = target.primitive_type() {
|
if let Some(prim) = target.primitive_type() {
|
||||||
let _prof_timer = cx.tcx.sess.prof.generic_activity("build_primitive_inherent_impls");
|
let _prof_timer = tcx.sess.prof.generic_activity("build_primitive_inherent_impls");
|
||||||
for did in prim.impls(tcx).filter(|did| !did.is_local()) {
|
for did in prim.impls(tcx).filter(|did| !did.is_local()) {
|
||||||
inline::build_impl(cx, did, None, ret);
|
inline::build_impl(cx, did, None, ret);
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ pub(crate) fn populate(cx: &mut DocContext<'_>, mut krate: clean::Crate) -> clea
|
|||||||
|
|
||||||
// Cache where all our extern crates are located
|
// Cache where all our extern crates are located
|
||||||
// FIXME: this part is specific to HTML so it'd be nice to remove it from the common code
|
// FIXME: this part is specific to HTML so it'd be nice to remove it from the common code
|
||||||
for &crate_num in cx.tcx.crates(()) {
|
for &crate_num in tcx.crates(()) {
|
||||||
let e = ExternalCrate { crate_num };
|
let e = ExternalCrate { crate_num };
|
||||||
|
|
||||||
let name = e.name(tcx);
|
let name = e.name(tcx);
|
||||||
|
@ -405,18 +405,18 @@ fn cmp(
|
|||||||
|
|
||||||
clean::ImportItem(ref import) => {
|
clean::ImportItem(ref import) => {
|
||||||
let stab_tags = if let Some(import_def_id) = import.source.did {
|
let stab_tags = if let Some(import_def_id) = import.source.did {
|
||||||
let ast_attrs = cx.tcx().get_attrs_unchecked(import_def_id);
|
let ast_attrs = tcx.get_attrs_unchecked(import_def_id);
|
||||||
let import_attrs = Box::new(clean::Attributes::from_ast(ast_attrs));
|
let import_attrs = Box::new(clean::Attributes::from_ast(ast_attrs));
|
||||||
|
|
||||||
// Just need an item with the correct def_id and attrs
|
// Just need an item with the correct def_id and attrs
|
||||||
let import_item = clean::Item {
|
let import_item = clean::Item {
|
||||||
item_id: import_def_id.into(),
|
item_id: import_def_id.into(),
|
||||||
attrs: import_attrs,
|
attrs: import_attrs,
|
||||||
cfg: ast_attrs.cfg(cx.tcx(), &cx.cache().hidden_cfg),
|
cfg: ast_attrs.cfg(tcx, &cx.cache().hidden_cfg),
|
||||||
..myitem.clone()
|
..myitem.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let stab_tags = Some(extra_info_tags(&import_item, item, cx.tcx()).to_string());
|
let stab_tags = Some(extra_info_tags(&import_item, item, tcx).to_string());
|
||||||
stab_tags
|
stab_tags
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -454,8 +454,7 @@ fn cmp(
|
|||||||
|
|
||||||
let unsafety_flag = match *myitem.kind {
|
let unsafety_flag = match *myitem.kind {
|
||||||
clean::FunctionItem(_) | clean::ForeignFunctionItem(_)
|
clean::FunctionItem(_) | clean::ForeignFunctionItem(_)
|
||||||
if myitem.fn_header(cx.tcx()).unwrap().unsafety
|
if myitem.fn_header(tcx).unwrap().unsafety == hir::Unsafety::Unsafe =>
|
||||||
== hir::Unsafety::Unsafe =>
|
|
||||||
{
|
{
|
||||||
"<sup title=\"unsafe function\">⚠</sup>"
|
"<sup title=\"unsafe function\">⚠</sup>"
|
||||||
}
|
}
|
||||||
@ -488,7 +487,7 @@ fn cmp(
|
|||||||
{docs_before}{docs}{docs_after}",
|
{docs_before}{docs}{docs_after}",
|
||||||
name = myitem.name.unwrap(),
|
name = myitem.name.unwrap(),
|
||||||
visibility_emoji = visibility_emoji,
|
visibility_emoji = visibility_emoji,
|
||||||
stab_tags = extra_info_tags(myitem, item, cx.tcx()),
|
stab_tags = extra_info_tags(myitem, item, tcx),
|
||||||
class = myitem.type_(),
|
class = myitem.type_(),
|
||||||
unsafety_flag = unsafety_flag,
|
unsafety_flag = unsafety_flag,
|
||||||
href = item_path(myitem.type_(), myitem.name.unwrap().as_str()),
|
href = item_path(myitem.type_(), myitem.name.unwrap().as_str()),
|
||||||
@ -935,7 +934,7 @@ fn trait_item(w: &mut Buffer, cx: &mut Context<'_>, m: &clean::Item, t: &clean::
|
|||||||
write_small_section_header(w, "foreign-impls", "Implementations on Foreign Types", "");
|
write_small_section_header(w, "foreign-impls", "Implementations on Foreign Types", "");
|
||||||
|
|
||||||
for implementor in foreign {
|
for implementor in foreign {
|
||||||
let provided_methods = implementor.inner_impl().provided_trait_methods(cx.tcx());
|
let provided_methods = implementor.inner_impl().provided_trait_methods(tcx);
|
||||||
let assoc_link =
|
let assoc_link =
|
||||||
AssocItemLink::GotoSource(implementor.impl_item.item_id, &provided_methods);
|
AssocItemLink::GotoSource(implementor.impl_item.item_id, &provided_methods);
|
||||||
render_impl(
|
render_impl(
|
||||||
@ -968,7 +967,7 @@ fn trait_item(w: &mut Buffer, cx: &mut Context<'_>, m: &clean::Item, t: &clean::
|
|||||||
}
|
}
|
||||||
w.write_str("</div>");
|
w.write_str("</div>");
|
||||||
|
|
||||||
if t.is_auto(cx.tcx()) {
|
if t.is_auto(tcx) {
|
||||||
write_small_section_header(
|
write_small_section_header(
|
||||||
w,
|
w,
|
||||||
"synthetic-implementors",
|
"synthetic-implementors",
|
||||||
@ -997,7 +996,7 @@ fn trait_item(w: &mut Buffer, cx: &mut Context<'_>, m: &clean::Item, t: &clean::
|
|||||||
"<div id=\"implementors-list\"></div>",
|
"<div id=\"implementors-list\"></div>",
|
||||||
);
|
);
|
||||||
|
|
||||||
if t.is_auto(cx.tcx()) {
|
if t.is_auto(tcx) {
|
||||||
write_small_section_header(
|
write_small_section_header(
|
||||||
w,
|
w,
|
||||||
"synthetic-implementors",
|
"synthetic-implementors",
|
||||||
|
@ -54,13 +54,13 @@ pub(crate) fn document_type_layout<'a, 'cx: 'a>(
|
|||||||
} else if let Primitive::Int(i, _) = tag.primitive() {
|
} else if let Primitive::Int(i, _) = tag.primitive() {
|
||||||
i.size().bytes()
|
i.size().bytes()
|
||||||
} else {
|
} else {
|
||||||
span_bug!(cx.tcx().def_span(ty_def_id), "tag is neither niche nor int")
|
span_bug!(tcx.def_span(ty_def_id), "tag is neither niche nor int")
|
||||||
};
|
};
|
||||||
variants
|
variants
|
||||||
.iter_enumerated()
|
.iter_enumerated()
|
||||||
.map(|(variant_idx, variant_layout)| {
|
.map(|(variant_idx, variant_layout)| {
|
||||||
let Adt(adt, _) = type_layout.ty.kind() else {
|
let Adt(adt, _) = type_layout.ty.kind() else {
|
||||||
span_bug!(cx.tcx().def_span(ty_def_id), "not an adt")
|
span_bug!(tcx.def_span(ty_def_id), "not an adt")
|
||||||
};
|
};
|
||||||
let name = adt.variant(variant_idx).name;
|
let name = adt.variant(variant_idx).name;
|
||||||
let is_unsized = variant_layout.abi.is_unsized();
|
let is_unsized = variant_layout.abi.is_unsized();
|
||||||
|
@ -723,7 +723,7 @@ fn resolve_associated_trait_item<'a>(
|
|||||||
.iter()
|
.iter()
|
||||||
.flat_map(|&(impl_, trait_)| {
|
.flat_map(|&(impl_, trait_)| {
|
||||||
filter_assoc_items_by_name_and_namespace(
|
filter_assoc_items_by_name_and_namespace(
|
||||||
cx.tcx,
|
tcx,
|
||||||
trait_,
|
trait_,
|
||||||
Ident::with_dummy_span(item_name),
|
Ident::with_dummy_span(item_name),
|
||||||
ns,
|
ns,
|
||||||
@ -1743,7 +1743,7 @@ fn split(path: &str) -> Option<(&str, &str)> {
|
|||||||
if let Ok(v_res) = collector.resolve(start, ns, item_id, module_id) {
|
if let Ok(v_res) = collector.resolve(start, ns, item_id, module_id) {
|
||||||
debug!("found partial_res={:?}", v_res);
|
debug!("found partial_res={:?}", v_res);
|
||||||
if !v_res.is_empty() {
|
if !v_res.is_empty() {
|
||||||
*partial_res = Some(full_res(collector.cx.tcx, v_res[0]));
|
*partial_res = Some(full_res(tcx, v_res[0]));
|
||||||
*unresolved = end.into();
|
*unresolved = end.into();
|
||||||
break 'outer;
|
break 'outer;
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,10 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate {
|
pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate {
|
||||||
|
let tcx = cx.tcx;
|
||||||
// We need to check if there are errors before running this pass because it would crash when
|
// We need to check if there are errors before running this pass because it would crash when
|
||||||
// we try to get auto and blanket implementations.
|
// we try to get auto and blanket implementations.
|
||||||
if cx.tcx.sess.diagnostic().has_errors_or_lint_errors().is_some() {
|
if tcx.sess.diagnostic().has_errors_or_lint_errors().is_some() {
|
||||||
return krate;
|
return krate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,8 +33,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
|
|||||||
});
|
});
|
||||||
|
|
||||||
let local_crate = ExternalCrate { crate_num: LOCAL_CRATE };
|
let local_crate = ExternalCrate { crate_num: LOCAL_CRATE };
|
||||||
let prims: FxHashSet<PrimitiveType> =
|
let prims: FxHashSet<PrimitiveType> = local_crate.primitives(tcx).iter().map(|p| p.1).collect();
|
||||||
local_crate.primitives(cx.tcx).iter().map(|p| p.1).collect();
|
|
||||||
|
|
||||||
let crate_items = {
|
let crate_items = {
|
||||||
let mut coll = ItemCollector::new();
|
let mut coll = ItemCollector::new();
|
||||||
@ -46,9 +46,9 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
|
|||||||
|
|
||||||
// External trait impls.
|
// External trait impls.
|
||||||
{
|
{
|
||||||
let _prof_timer = cx.tcx.sess.prof.generic_activity("build_extern_trait_impls");
|
let _prof_timer = tcx.sess.prof.generic_activity("build_extern_trait_impls");
|
||||||
for &cnum in cx.tcx.crates(()) {
|
for &cnum in tcx.crates(()) {
|
||||||
for &impl_def_id in cx.tcx.trait_impls_in_crate(cnum) {
|
for &impl_def_id in tcx.trait_impls_in_crate(cnum) {
|
||||||
inline::build_impl(cx, impl_def_id, None, &mut new_items_external);
|
inline::build_impl(cx, impl_def_id, None, &mut new_items_external);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,14 +56,13 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
|
|||||||
|
|
||||||
// Local trait impls.
|
// Local trait impls.
|
||||||
{
|
{
|
||||||
let _prof_timer = cx.tcx.sess.prof.generic_activity("build_local_trait_impls");
|
let _prof_timer = tcx.sess.prof.generic_activity("build_local_trait_impls");
|
||||||
let mut attr_buf = Vec::new();
|
let mut attr_buf = Vec::new();
|
||||||
for &impl_def_id in cx.tcx.trait_impls_in_crate(LOCAL_CRATE) {
|
for &impl_def_id in tcx.trait_impls_in_crate(LOCAL_CRATE) {
|
||||||
let mut parent = Some(cx.tcx.parent(impl_def_id));
|
let mut parent = Some(tcx.parent(impl_def_id));
|
||||||
while let Some(did) = parent {
|
while let Some(did) = parent {
|
||||||
attr_buf.extend(
|
attr_buf.extend(
|
||||||
cx.tcx
|
tcx.get_attrs(did, sym::doc)
|
||||||
.get_attrs(did, sym::doc)
|
|
||||||
.filter(|attr| {
|
.filter(|attr| {
|
||||||
if let Some([attr]) = attr.meta_item_list().as_deref() {
|
if let Some([attr]) = attr.meta_item_list().as_deref() {
|
||||||
attr.has_name(sym::cfg)
|
attr.has_name(sym::cfg)
|
||||||
@ -73,25 +72,24 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
|
|||||||
})
|
})
|
||||||
.cloned(),
|
.cloned(),
|
||||||
);
|
);
|
||||||
parent = cx.tcx.opt_parent(did);
|
parent = tcx.opt_parent(did);
|
||||||
}
|
}
|
||||||
inline::build_impl(cx, impl_def_id, Some((&attr_buf, None)), &mut new_items_local);
|
inline::build_impl(cx, impl_def_id, Some((&attr_buf, None)), &mut new_items_local);
|
||||||
attr_buf.clear();
|
attr_buf.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cx.tcx.sess.prof.generic_activity("build_primitive_trait_impls").run(|| {
|
tcx.sess.prof.generic_activity("build_primitive_trait_impls").run(|| {
|
||||||
for def_id in PrimitiveType::all_impls(cx.tcx) {
|
for def_id in PrimitiveType::all_impls(tcx) {
|
||||||
// Try to inline primitive impls from other crates.
|
// Try to inline primitive impls from other crates.
|
||||||
if !def_id.is_local() {
|
if !def_id.is_local() {
|
||||||
inline::build_impl(cx, def_id, None, &mut new_items_external);
|
inline::build_impl(cx, def_id, None, &mut new_items_external);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (prim, did) in PrimitiveType::primitive_locations(cx.tcx) {
|
for (prim, did) in PrimitiveType::primitive_locations(tcx) {
|
||||||
// Do not calculate blanket impl list for docs that are not going to be rendered.
|
// Do not calculate blanket impl list for docs that are not going to be rendered.
|
||||||
// While the `impl` blocks themselves are only in `libcore`, the module with `doc`
|
// While the `impl` blocks themselves are only in `libcore`, the module with `doc`
|
||||||
// attached is directly included in `libstd` as well.
|
// attached is directly included in `libstd` as well.
|
||||||
let tcx = cx.tcx;
|
|
||||||
if did.is_local() {
|
if did.is_local() {
|
||||||
for def_id in prim.impls(tcx).filter(|def_id| {
|
for def_id in prim.impls(tcx).filter(|def_id| {
|
||||||
// Avoid including impl blocks with filled-in generics.
|
// Avoid including impl blocks with filled-in generics.
|
||||||
@ -157,7 +155,7 @@ fn add_deref_target(
|
|||||||
// scan through included items ahead of time to splice in Deref targets to the "valid" sets
|
// scan through included items ahead of time to splice in Deref targets to the "valid" sets
|
||||||
for it in new_items_external.iter().chain(new_items_local.iter()) {
|
for it in new_items_external.iter().chain(new_items_local.iter()) {
|
||||||
if let ImplItem(box Impl { ref for_, ref trait_, ref items, .. }) = *it.kind &&
|
if let ImplItem(box Impl { ref for_, ref trait_, ref items, .. }) = *it.kind &&
|
||||||
trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait() &&
|
trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait() &&
|
||||||
cleaner.keep_impl(for_, true)
|
cleaner.keep_impl(for_, true)
|
||||||
{
|
{
|
||||||
let target = items
|
let target = items
|
||||||
@ -199,7 +197,7 @@ fn add_deref_target(
|
|||||||
if let ImplItem(box Impl { ref for_, ref trait_, ref kind, .. }) = *it.kind {
|
if let ImplItem(box Impl { ref for_, ref trait_, ref kind, .. }) = *it.kind {
|
||||||
cleaner.keep_impl(
|
cleaner.keep_impl(
|
||||||
for_,
|
for_,
|
||||||
trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait(),
|
trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait(),
|
||||||
) || trait_.as_ref().map_or(false, |t| cleaner.keep_impl_with_def_id(t.def_id().into()))
|
) || trait_.as_ref().map_or(false, |t| cleaner.keep_impl_with_def_id(t.def_id().into()))
|
||||||
|| kind.is_blanket()
|
|| kind.is_blanket()
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,7 +56,7 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
|
|||||||
)
|
)
|
||||||
.unwrap_or_else(|| item.attr_span(tcx));
|
.unwrap_or_else(|| item.attr_span(tcx));
|
||||||
|
|
||||||
cx.tcx.struct_span_lint_hir(crate::lint::UNESCAPED_BACKTICKS, hir_id, span, "unescaped backtick", |lint| {
|
tcx.struct_span_lint_hir(crate::lint::UNESCAPED_BACKTICKS, hir_id, span, "unescaped backtick", |lint| {
|
||||||
let mut help_emitted = false;
|
let mut help_emitted = false;
|
||||||
|
|
||||||
match element.prev_code_guess {
|
match element.prev_code_guess {
|
||||||
|
@ -280,9 +280,8 @@ fn maybe_inline_local(
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
let is_private =
|
let is_private = !self.cx.cache.effective_visibilities.is_directly_public(tcx, ori_res_did);
|
||||||
!self.cx.cache.effective_visibilities.is_directly_public(self.cx.tcx, ori_res_did);
|
let is_hidden = inherits_doc_hidden(tcx, res_did, None);
|
||||||
let is_hidden = inherits_doc_hidden(self.cx.tcx, res_did, None);
|
|
||||||
|
|
||||||
// Only inline if requested or if the item would otherwise be stripped.
|
// Only inline if requested or if the item would otherwise be stripped.
|
||||||
if (!please_inline && !is_private && !is_hidden) || is_no_inline {
|
if (!please_inline && !is_private && !is_hidden) || is_no_inline {
|
||||||
@ -290,7 +289,7 @@ fn maybe_inline_local(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !please_inline &&
|
if !please_inline &&
|
||||||
let Some(item_def_id) = reexport_chain(self.cx.tcx, def_id, res_did).iter()
|
let Some(item_def_id) = reexport_chain(tcx, def_id, res_did).iter()
|
||||||
.flat_map(|reexport| reexport.id()).map(|id| id.expect_local())
|
.flat_map(|reexport| reexport.id()).map(|id| id.expect_local())
|
||||||
.chain(iter::once(res_did)).nth(1) &&
|
.chain(iter::once(res_did)).nth(1) &&
|
||||||
item_def_id != def_id &&
|
item_def_id != def_id &&
|
||||||
@ -298,8 +297,8 @@ fn maybe_inline_local(
|
|||||||
.cx
|
.cx
|
||||||
.cache
|
.cache
|
||||||
.effective_visibilities
|
.effective_visibilities
|
||||||
.is_directly_public(self.cx.tcx, item_def_id.to_def_id()) &&
|
.is_directly_public(tcx, item_def_id.to_def_id()) &&
|
||||||
!inherits_doc_hidden(self.cx.tcx, item_def_id, None)
|
!inherits_doc_hidden(tcx, item_def_id, None)
|
||||||
{
|
{
|
||||||
// The imported item is public and not `doc(hidden)` so no need to inline it.
|
// The imported item is public and not `doc(hidden)` so no need to inline it.
|
||||||
return false;
|
return false;
|
||||||
@ -329,7 +328,7 @@ fn maybe_inline_local(
|
|||||||
Node::Item(&hir::Item { kind: hir::ItemKind::Mod(ref m), .. }) if glob => {
|
Node::Item(&hir::Item { kind: hir::ItemKind::Mod(ref m), .. }) if glob => {
|
||||||
let prev = mem::replace(&mut self.inlining, true);
|
let prev = mem::replace(&mut self.inlining, true);
|
||||||
for &i in m.item_ids {
|
for &i in m.item_ids {
|
||||||
let i = self.cx.tcx.hir().item(i);
|
let i = tcx.hir().item(i);
|
||||||
self.visit_item_inner(i, None, Some(def_id));
|
self.visit_item_inner(i, None, Some(def_id));
|
||||||
}
|
}
|
||||||
self.inlining = prev;
|
self.inlining = prev;
|
||||||
|
Loading…
Reference in New Issue
Block a user