Skip to content

Commit 3812b9f

Browse files
committed
Add range support to rustdoc, and ensure it compiles
1 parent 1f5bc17 commit 3812b9f

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

compiler/rustc_hir_pretty/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ pub fn enum_def_to_string(
249249
to_string(NO_ANN, |s| s.print_enum_def(enum_definition, generics, name, span, visibility))
250250
}
251251

252+
pub fn pat_to_string(pat: &hir::Pat<'_>) -> String {
253+
to_string(NO_ANN, |s| s.print_pat(pat))
254+
}
255+
252256
impl<'a> State<'a> {
253257
pub fn cbox(&mut self, u: usize) {
254258
self.s.cbox(u);

src/librustdoc/clean/utils.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,7 @@ crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
413413
);
414414
return Symbol::intern("()");
415415
}
416-
PatKind::Range(..) => panic!(
417-
"tried to get argument name from PatKind::Range, \
418-
which is not allowed in function arguments"
419-
),
416+
PatKind::Range(..) => rustc_hir_pretty::pat_to_string(p),
420417
PatKind::Slice(ref begin, ref mid, ref end) => {
421418
let begin = begin.iter().map(|p| name_from_pat(&**p).to_string());
422419
let mid = mid.as_ref().map(|p| format!("..{}", name_from_pat(&**p))).into_iter();

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) {}

0 commit comments

Comments
 (0)