Skip to content

Commit

Permalink
[experiments]
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Feb 28, 2024
1 parent 438ca19 commit a981f2c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ pub(crate) fn build_function<'tcx>(
generics.params.sort_by_key(|param| cx.tcx.def_ident_span(param.def_id).unwrap());
}

// FIXME(fmease): @Temporary
crate::clean::simplify::move_bounds_to_generic_parameters(&mut generics);

let decl = clean_poly_fn_sig(cx, Some(def_id), sig);

Box::new(clean::Function { decl, generics })
Expand Down
42 changes: 40 additions & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ pub(crate) fn clean_generics<'tcx>(

fn clean_ty_generics<'tcx>(
cx: &mut DocContext<'tcx>,
generics: &ty::Generics,
generics: &'tcx ty::Generics,
predicates: ty::GenericPredicates<'tcx>,
_item_def_id: DefId,
) -> Generics {
Expand Down Expand Up @@ -787,10 +787,48 @@ fn clean_ty_generics<'tcx>(
let mut impl_trait_proj =
FxHashMap::<u32, Vec<(DefId, PathSegment, ty::Binder<'_, ty::Term<'_>>)>>::default();

let item_span = {
if !predicates.predicates.is_empty() {
let span = cx.tcx.def_span(_item_def_id);
// FIXME: this is not correct if spans come from different expansions!
let params_sp = {
let mut params = generics.params.iter();
if let Some(param) = params.next() {
let mut sp = cx.tcx.def_ident_span(param.def_id).unwrap();
while let Some(param) = params.next() {
sp = sp.to(cx.tcx.def_ident_span(param.def_id).unwrap());
}
sp
} else {
None
}
};

Some(span)
} else {
None
}
};

let where_predicates = predicates
.predicates
.iter()
.flat_map(|(pred, _)| {
.flat_map(|(pred, span)| {
if !(span.is_dummy()
|| span.is_empty()
|| span.from_expansion()
|| !cx.tcx.sess.source_map().is_span_accessible(*span))
{
let mut diag = cx.tcx.dcx().struct_span_warn(*span, format!("pred={pred:?}"));

if let Some(item_span) = item_span {
diag.span_note(item_span, "span");
diag.note(if item_span.contains(*span) { "<...>" } else { "where ... " });
}

diag.emit();
}

let mut projection = None;
let param_idx = (|| {
let bound_p = pred.kind();
Expand Down

0 comments on commit a981f2c

Please sign in to comment.