Skip to content

Commit 79cba78

Browse files
authored
Rollup merge of #154680 - GuillaumeGomez:doccontext-cleanup, r=Urgau
[rustdoc] Replace `DocContext` with `TyCtxt` wherever possible In a lot of places, we pass down `DocContext` but actually only use its `tcx` field (`TyCtxt`). To make it more obvious what's actually being done, I replaced `DocContext` with `TyCtxt` (which implements `Copy`) in the function arguments. It created quite the cascade effect so I ended up with a lot more changes I expected. Because it's a lot of changes, I made small commits which are easy to go through, so I strongly recommend reviewing this PR one commit at a time. r? @Urgau
2 parents 1ecf840 + 0b941ed commit 79cba78

7 files changed

Lines changed: 113 additions & 118 deletions

File tree

src/librustdoc/clean/auto_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn clean_param_env<'tcx>(
203203

204204
let mut generics = clean::Generics { params, where_predicates };
205205
simplify::sized_bounds(cx, &mut generics);
206-
generics.where_predicates = simplify::where_clauses(cx, generics.where_predicates);
206+
generics.where_predicates = simplify::where_clauses(cx.tcx, generics.where_predicates);
207207
generics
208208
}
209209

src/librustdoc/clean/inline.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub(crate) fn try_inline(
137137
})
138138
}
139139
Res::Def(DefKind::Macro(kinds), did) => {
140-
let mac = build_macro(cx, did, name, kinds);
140+
let mac = build_macro(cx.tcx, did, name, kinds);
141141

142142
// FIXME: handle attributes and derives that aren't proc macros, and macros with
143143
// multiple kinds
@@ -218,10 +218,10 @@ pub(crate) fn try_inline_glob(
218218
}
219219
}
220220

221-
pub(crate) fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> &'hir [hir::Attribute] {
221+
pub(crate) fn load_attrs<'hir>(tcx: TyCtxt<'hir>, did: DefId) -> &'hir [hir::Attribute] {
222222
// FIXME: all uses should use `find_attr`!
223223
#[allow(deprecated)]
224-
cx.tcx.get_all_attrs(did)
224+
tcx.get_all_attrs(did)
225225
}
226226

227227
pub(crate) fn item_relative_path(tcx: TyCtxt<'_>, def_id: DefId) -> Vec<Symbol> {
@@ -289,7 +289,7 @@ pub(crate) fn build_trait(cx: &mut DocContext<'_>, did: DefId) -> clean::Trait {
289289
supertrait_bounds.retain(|b| {
290290
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
291291
// is shown and none of the new sizedness traits leak into documentation.
292-
!b.is_meta_sized_bound(cx)
292+
!b.is_meta_sized_bound(cx.tcx)
293293
});
294294

295295
clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds }
@@ -302,7 +302,7 @@ fn build_trait_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::TraitAlias {
302302
bounds.retain(|b| {
303303
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
304304
// is shown and none of the new sizedness traits leak into documentation.
305-
!b.is_meta_sized_bound(cx)
305+
!b.is_meta_sized_bound(cx.tcx)
306306
});
307307

308308
clean::TraitAlias { generics, bounds }
@@ -312,7 +312,7 @@ pub(super) fn build_function(cx: &mut DocContext<'_>, def_id: DefId) -> Box<clea
312312
let sig = cx.tcx.fn_sig(def_id).instantiate_identity();
313313
// The generics need to be cleaned before the signature.
314314
let mut generics = clean_ty_generics(cx, def_id);
315-
let bound_vars = clean_bound_vars(sig.bound_vars(), cx);
315+
let bound_vars = clean_bound_vars(sig.bound_vars(), cx.tcx);
316316

317317
// At the time of writing early & late-bound params are stored separately in rustc,
318318
// namely in `generics.params` and `bound_vars` respectively.
@@ -388,8 +388,8 @@ pub(crate) fn build_impls(
388388
attrs: Option<(&[hir::Attribute], Option<LocalDefId>)>,
389389
ret: &mut Vec<clean::Item>,
390390
) {
391-
let _prof_timer = cx.tcx.sess.prof.generic_activity("build_inherent_impls");
392391
let tcx = cx.tcx;
392+
let _prof_timer = tcx.sess.prof.generic_activity("build_inherent_impls");
393393

394394
// for each implementation of an item represented by `did`, build the clean::Item for that impl
395395
for &did in tcx.inherent_impls(did).iter() {
@@ -416,7 +416,7 @@ pub(crate) fn build_impls(
416416
}
417417

418418
pub(crate) fn merge_attrs(
419-
cx: &mut DocContext<'_>,
419+
tcx: TyCtxt<'_>,
420420
old_attrs: &[hir::Attribute],
421421
new_attrs: Option<(&[hir::Attribute], Option<LocalDefId>)>,
422422
cfg_info: &mut CfgInfo,
@@ -434,13 +434,10 @@ pub(crate) fn merge_attrs(
434434
} else {
435435
Attributes::from_hir(&both)
436436
},
437-
extract_cfg_from_attrs(both.iter(), cx.tcx, cfg_info),
437+
extract_cfg_from_attrs(both.iter(), tcx, cfg_info),
438438
)
439439
} else {
440-
(
441-
Attributes::from_hir(old_attrs),
442-
extract_cfg_from_attrs(old_attrs.iter(), cx.tcx, cfg_info),
443-
)
440+
(Attributes::from_hir(old_attrs), extract_cfg_from_attrs(old_attrs.iter(), tcx, cfg_info))
444441
}
445442
}
446443

@@ -623,7 +620,8 @@ pub(crate) fn build_impl(
623620
// doesn't matter at this point.
624621
//
625622
// We need to pass this empty `CfgInfo` because `merge_attrs` is used when computing the `cfg`.
626-
let (merged_attrs, cfg) = merge_attrs(cx, load_attrs(cx, did), attrs, &mut CfgInfo::default());
623+
let (merged_attrs, cfg) =
624+
merge_attrs(cx.tcx, load_attrs(cx.tcx, did), attrs, &mut CfgInfo::default());
627625
trace!("merged_attrs={merged_attrs:?}");
628626

629627
trace!(
@@ -771,17 +769,17 @@ fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::St
771769
}
772770

773771
fn build_macro(
774-
cx: &mut DocContext<'_>,
772+
tcx: TyCtxt<'_>,
775773
def_id: DefId,
776774
name: Symbol,
777775
macro_kinds: MacroKinds,
778776
) -> clean::ItemKind {
779-
match CStore::from_tcx(cx.tcx).load_macro_untracked(cx.tcx, def_id) {
777+
match CStore::from_tcx(tcx).load_macro_untracked(tcx, def_id) {
780778
// FIXME: handle attributes and derives that aren't proc macros, and macros with multiple
781779
// kinds
782780
LoadedMacro::MacroDef { def, .. } => match macro_kinds {
783781
MacroKinds::BANG => clean::MacroItem(clean::Macro {
784-
source: utils::display_macro_source(cx, name, &def),
782+
source: utils::display_macro_source(tcx, name, &def),
785783
macro_rules: def.macro_rules,
786784
}),
787785
MacroKinds::DERIVE => clean::ProcMacroItem(clean::ProcMacro {

0 commit comments

Comments
 (0)