Skip to content

Commit dec3dbd

Browse files
authored
Rollup merge of #80799 - jyn514:pretty-print, r=CraftSpider
Get rid of custom pretty-printing in rustdoc and use rustc_hir_pretty directly instead. Closes #79497. r? `@CraftSpider`
2 parents faf5412 + 31375d2 commit dec3dbd

File tree

4 files changed

+9
-71
lines changed

4 files changed

+9
-71
lines changed

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], hir::BodyId) {
963963
.iter()
964964
.enumerate()
965965
.map(|(i, ty)| Argument {
966-
name: name_from_pat(&body.params[i].pat),
966+
name: Symbol::intern(&rustc_hir_pretty::param_to_string(&body.params[i])),
967967
type_: ty.clean(cx),
968968
})
969969
.collect(),

src/librustdoc/clean/utils.rs

-70
Original file line numberDiff line numberDiff line change
@@ -314,25 +314,6 @@ crate fn strip_path(path: &Path) -> Path {
314314
Path { global: path.global, res: path.res, segments }
315315
}
316316

317-
crate fn qpath_to_string(p: &hir::QPath<'_>) -> String {
318-
let segments = match *p {
319-
hir::QPath::Resolved(_, ref path) => &path.segments,
320-
hir::QPath::TypeRelative(_, ref segment) => return segment.ident.to_string(),
321-
hir::QPath::LangItem(lang_item, ..) => return lang_item.name().to_string(),
322-
};
323-
324-
let mut s = String::new();
325-
for (i, seg) in segments.iter().enumerate() {
326-
if i > 0 {
327-
s.push_str("::");
328-
}
329-
if seg.ident.name != kw::PathRoot {
330-
s.push_str(&seg.ident.as_str());
331-
}
332-
}
333-
s
334-
}
335-
336317
crate fn build_deref_target_impls(cx: &DocContext<'_>, items: &[Item], ret: &mut Vec<Item>) {
337318
let tcx = cx.tcx;
338319

@@ -376,57 +357,6 @@ impl ToSource for rustc_span::Span {
376357
}
377358
}
378359

379-
crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
380-
use rustc_hir::*;
381-
debug!("trying to get a name from pattern: {:?}", p);
382-
383-
Symbol::intern(&match p.kind {
384-
PatKind::Wild => return kw::Underscore,
385-
PatKind::Binding(_, _, ident, _) => return ident.name,
386-
PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p),
387-
PatKind::Struct(ref name, ref fields, etc) => format!(
388-
"{} {{ {}{} }}",
389-
qpath_to_string(name),
390-
fields
391-
.iter()
392-
.map(|fp| format!("{}: {}", fp.ident, name_from_pat(&fp.pat)))
393-
.collect::<Vec<String>>()
394-
.join(", "),
395-
if etc { ", .." } else { "" }
396-
),
397-
PatKind::Or(ref pats) => pats
398-
.iter()
399-
.map(|p| name_from_pat(&**p).to_string())
400-
.collect::<Vec<String>>()
401-
.join(" | "),
402-
PatKind::Tuple(ref elts, _) => format!(
403-
"({})",
404-
elts.iter()
405-
.map(|p| name_from_pat(&**p).to_string())
406-
.collect::<Vec<String>>()
407-
.join(", ")
408-
),
409-
PatKind::Box(ref p) => return name_from_pat(&**p),
410-
PatKind::Ref(ref p, _) => return name_from_pat(&**p),
411-
PatKind::Lit(..) => {
412-
warn!(
413-
"tried to get argument name from PatKind::Lit, which is silly in function arguments"
414-
);
415-
return Symbol::intern("()");
416-
}
417-
PatKind::Range(..) => panic!(
418-
"tried to get argument name from PatKind::Range, \
419-
which is not allowed in function arguments"
420-
),
421-
PatKind::Slice(ref begin, ref mid, ref end) => {
422-
let begin = begin.iter().map(|p| name_from_pat(&**p).to_string());
423-
let mid = mid.as_ref().map(|p| format!("..{}", name_from_pat(&**p))).into_iter();
424-
let end = end.iter().map(|p| name_from_pat(&**p).to_string());
425-
format!("[{}]", begin.chain(mid).chain(end).collect::<Vec<_>>().join(", "))
426-
}
427-
})
428-
}
429-
430360
crate fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String {
431361
match n.val {
432362
ty::ConstKind::Unevaluated(def, _, promoted) => {

src/test/rustdoc-ui/range-pattern.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// check-pass
2+
3+
fn func(0u8..=255: u8) {}

src/test/rustdoc/range-arg-pattern.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![crate_name = "foo"]
2+
3+
// @has foo/fn.f.html
4+
// @has - '//*[@class="rust fn"]' 'pub fn f(0u8 ...255: u8)'
5+
pub fn f(0u8...255: u8) {}

0 commit comments

Comments
 (0)