From 7cece8eca3fa42f93c53acfc1d376077025126f2 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 3 Dec 2020 15:49:20 -0500 Subject: [PATCH 01/11] Add trait Fns to rust-call resolution --- compiler/rustc_typeck/src/check/check.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index 489d836298f87..a4b21e96f05f0 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -103,6 +103,9 @@ pub(super) fn check_fn<'a, 'tcx>( Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(header, ..), .. }) => Some(header), + Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Fn(header, .. ), .. + }) => Some(header), // Closures are RustCall, but they tuple their arguments, so shouldn't be checked Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => None, node => bug!("Item being checked wasn't a function/closure: {:?}", node), From 35e86c2ab52603bbb5e5561bbab1e7e62c668d9d Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 3 Dec 2020 15:53:52 -0500 Subject: [PATCH 02/11] Add more complete tests of possible rust-call cases --- compiler/rustc_typeck/src/check/check.rs | 3 ++- .../ui/abi/issues/issue-22565-rust-call.rs | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index a4b21e96f05f0..676386ccf2e52 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -104,7 +104,8 @@ pub(super) fn check_fn<'a, 'tcx>( kind: hir::ImplItemKind::Fn(header, ..), .. }) => Some(header), Node::TraitItem(hir::TraitItem { - kind: hir::TraitItemKind::Fn(header, .. ), .. + kind: hir::TraitItemKind::Fn(header, ..), + .. }) => Some(header), // Closures are RustCall, but they tuple their arguments, so shouldn't be checked Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => None, diff --git a/src/test/ui/abi/issues/issue-22565-rust-call.rs b/src/test/ui/abi/issues/issue-22565-rust-call.rs index 055d959b46e10..f0740185da09f 100644 --- a/src/test/ui/abi/issues/issue-22565-rust-call.rs +++ b/src/test/ui/abi/issues/issue-22565-rust-call.rs @@ -3,6 +3,31 @@ extern "rust-call" fn b(_i: i32) {} //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument that is a tuple +trait Tr { + extern "rust-call" fn a(); + //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument + + extern "rust-call" fn b() {} + //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument +} + +struct Foo; + +impl Foo { + extern "rust-call" fn bar() {} + //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument +} + +impl Tr for Foo { + fn a() {} + //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument +} + fn main () { b(10); + + Foo::bar(); + + ::a(); + ::b(); } From 9908f593195f8241a97fe7f453ade9a54510371b Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 3 Dec 2020 19:16:57 -0500 Subject: [PATCH 03/11] Fix ui test --- src/test/ui/abi/issues/issue-22565-rust-call.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/ui/abi/issues/issue-22565-rust-call.rs b/src/test/ui/abi/issues/issue-22565-rust-call.rs index f0740185da09f..383eaab454ec4 100644 --- a/src/test/ui/abi/issues/issue-22565-rust-call.rs +++ b/src/test/ui/abi/issues/issue-22565-rust-call.rs @@ -5,7 +5,6 @@ extern "rust-call" fn b(_i: i32) {} trait Tr { extern "rust-call" fn a(); - //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument extern "rust-call" fn b() {} //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument @@ -19,7 +18,7 @@ impl Foo { } impl Tr for Foo { - fn a() {} + extern "rust-call" fn a() {} //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument } From d41122a9182bc2ab7e3e427f865a123d633301a0 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 3 Dec 2020 19:59:39 -0500 Subject: [PATCH 04/11] Update stderr --- .../abi/issues/issue-22565-rust-call.stderr | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/test/ui/abi/issues/issue-22565-rust-call.stderr b/src/test/ui/abi/issues/issue-22565-rust-call.stderr index 31fb035eb99af..f7c3d1de793dc 100644 --- a/src/test/ui/abi/issues/issue-22565-rust-call.stderr +++ b/src/test/ui/abi/issues/issue-22565-rust-call.stderr @@ -4,5 +4,23 @@ error: A function with the "rust-call" ABI must take a single non-self argument LL | extern "rust-call" fn b(_i: i32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to previous error +error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple + --> $DIR/issue-22565-rust-call.rs:9:5 + | +LL | extern "rust-call" fn b() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple + --> $DIR/issue-22565-rust-call.rs:16:5 + | +LL | extern "rust-call" fn bar() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple + --> $DIR/issue-22565-rust-call.rs:21:5 + | +LL | extern "rust-call" fn a() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors From 7edd1810b41e239ea59b22a73a87f8c377d2293f Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 25 Dec 2020 19:04:50 -0500 Subject: [PATCH 05/11] Don't panic when an external crate can't be resolved This isn't actually a bug, it can occur when rustdoc tries to resolve a crate that isn't used in the main code. --- src/librustdoc/core.rs | 9 ++++----- .../rustdoc-ui/intra-doc/unused-extern-crate.rs | 5 +++++ .../intra-doc/unused-extern-crate.stderr | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs create mode 100644 src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 7e85342ac7d5d..819dc06845f8b 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -428,16 +428,15 @@ crate fn create_resolver<'a>( sess.time("load_extern_crates", || { for extern_name in &extern_names { debug!("loading extern crate {}", extern_name); - resolver + if let Err(()) = resolver .resolve_str_path_error( DUMMY_SP, extern_name, TypeNS, LocalDefId { local_def_index: CRATE_DEF_INDEX }.to_def_id(), - ) - .unwrap_or_else(|()| { - panic!("Unable to resolve external crate {}", extern_name) - }); + ) { + warn!("unable to resolve external crate {} (do you have an unused `--extern` crate?)", extern_name) + } } }); }); diff --git a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs new file mode 100644 index 0000000000000..186503cf69d3f --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs @@ -0,0 +1,5 @@ +// compile-flags: --extern zip=whatever.rlib +#![deny(broken_intra_doc_links)] +/// See [zip] crate. +//~^ ERROR unresolved +pub struct ArrayZip; diff --git a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr new file mode 100644 index 0000000000000..b3b57fd131838 --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr @@ -0,0 +1,15 @@ +error: unresolved link to `zip` + --> $DIR/unused-extern-crate.rs:3:10 + | +LL | /// See [zip] crate. + | ^^^ no item named `zip` in scope + | +note: the lint level is defined here + --> $DIR/unused-extern-crate.rs:2:9 + | +LL | #![deny(broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^ + = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` + +error: aborting due to previous error + From 10180b4c53d22c5182135506238b0a3fc9fc3df5 Mon Sep 17 00:00:00 2001 From: Marcus Svensson Date: Thu, 7 Jan 2021 18:22:37 +0100 Subject: [PATCH 06/11] Fix type name in doc example for Iter and IterMut --- library/core/src/slice/iter.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index a367b4737dbac..6b819628113ad 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -51,7 +51,7 @@ fn size_from_ptr(_: *const T) -> usize { /// Basic usage: /// /// ``` -/// // First, we declare a type which has `iter` method to get the `Iter` struct (&[usize here]): +/// // First, we declare a type which has `iter` method to get the `Iter` struct (&[usize] here): /// let slice = &[1, 2, 3]; /// /// // Then, we iterate over it: @@ -112,7 +112,7 @@ impl<'a, T> Iter<'a, T> { /// /// ``` /// // First, we declare a type which has the `iter` method to get the `Iter` - /// // struct (&[usize here]): + /// // struct (&[usize] here): /// let slice = &[1, 2, 3]; /// /// // Then, we get the iterator: @@ -167,7 +167,7 @@ impl AsRef<[T]> for Iter<'_, T> { /// /// ``` /// // First, we declare a type which has `iter_mut` method to get the `IterMut` -/// // struct (&[usize here]): +/// // struct (&[usize] here): /// let mut slice = &mut [1, 2, 3]; /// /// // Then, we iterate over it and increment each element value: @@ -246,7 +246,7 @@ impl<'a, T> IterMut<'a, T> { /// /// ``` /// // First, we declare a type which has `iter_mut` method to get the `IterMut` - /// // struct (&[usize here]): + /// // struct (&[usize] here): /// let mut slice = &mut [1, 2, 3]; /// /// { From 358ef56216c298b36dfa95e879e9605bc0bae492 Mon Sep 17 00:00:00 2001 From: Marcus Svensson Date: Thu, 7 Jan 2021 18:36:25 +0100 Subject: [PATCH 07/11] Enclose types in comments in backticks --- library/core/src/slice/iter.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index 6b819628113ad..769b673d80ab5 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -51,7 +51,7 @@ fn size_from_ptr(_: *const T) -> usize { /// Basic usage: /// /// ``` -/// // First, we declare a type which has `iter` method to get the `Iter` struct (&[usize] here): +/// // First, we declare a type which has `iter` method to get the `Iter` struct (`&[usize]` here): /// let slice = &[1, 2, 3]; /// /// // Then, we iterate over it: @@ -112,7 +112,7 @@ impl<'a, T> Iter<'a, T> { /// /// ``` /// // First, we declare a type which has the `iter` method to get the `Iter` - /// // struct (&[usize] here): + /// // struct (`&[usize]` here): /// let slice = &[1, 2, 3]; /// /// // Then, we get the iterator: @@ -167,7 +167,7 @@ impl AsRef<[T]> for Iter<'_, T> { /// /// ``` /// // First, we declare a type which has `iter_mut` method to get the `IterMut` -/// // struct (&[usize] here): +/// // struct (`&[usize]` here): /// let mut slice = &mut [1, 2, 3]; /// /// // Then, we iterate over it and increment each element value: @@ -246,7 +246,7 @@ impl<'a, T> IterMut<'a, T> { /// /// ``` /// // First, we declare a type which has `iter_mut` method to get the `IterMut` - /// // struct (&[usize] here): + /// // struct (`&[usize]` here): /// let mut slice = &mut [1, 2, 3]; /// /// { From 4f6305bc3705c96d428526b07b23391dac686115 Mon Sep 17 00:00:00 2001 From: Andreas Jonson Date: Thu, 7 Jan 2021 19:40:19 +0100 Subject: [PATCH 08/11] handle generic trait methods in coverage tests make the generic function pattern more specific --- src/test/run-make-fulldeps/coverage-reports/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make-fulldeps/coverage-reports/Makefile b/src/test/run-make-fulldeps/coverage-reports/Makefile index c4700b317efa0..f98245b4a9944 100644 --- a/src/test/run-make-fulldeps/coverage-reports/Makefile +++ b/src/test/run-make-fulldeps/coverage-reports/Makefile @@ -172,7 +172,7 @@ else # files are redundant, so there is no need to generate `expected_*.json` files or # compare actual JSON results.) - $(DIFF) --ignore-matching-lines='::<.*>.*:$$' \ + $(DIFF) --ignore-matching-lines='^ | .*::<.*>.*:$$' --ignore-matching-lines='^ | <.*>::.*:$$' \ expected_show_coverage.$@.txt "$(TMPDIR)"/actual_show_coverage.$@.txt || \ ( grep -q '^\/\/ ignore-llvm-cov-show-diffs' $(SOURCEDIR)/$@.rs && \ >&2 echo 'diff failed, but suppressed with `// ignore-llvm-cov-show-diffs` in $(SOURCEDIR)/$@.rs' \ From 961f9ee6dfd21bfcbe75b68eb38ea86bce1dc1d1 Mon Sep 17 00:00:00 2001 From: LingMan Date: Thu, 7 Jan 2021 20:03:59 +0100 Subject: [PATCH 09/11] Use Option::map_or instead of `.map(..).unwrap_or(..)` --- src/librustdoc/clean/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 0b979120ff91f..9399187033879 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -942,7 +942,7 @@ impl<'a> Clean for (&'a [hir::Ty<'a>], &'a [Ident]) { .iter() .enumerate() .map(|(i, ty)| { - let mut name = self.1.get(i).map(|ident| ident.name).unwrap_or(kw::Empty); + let mut name = self.1.get(i).map_or(kw::Empty, |ident| ident.name); if name.is_empty() { name = kw::Underscore; } @@ -1001,7 +1001,7 @@ impl<'tcx> Clean for (DefId, ty::PolyFnSig<'tcx>) { .iter() .map(|t| Argument { type_: t.clean(cx), - name: names.next().map(|i| i.name).unwrap_or(kw::Empty), + name: names.next().map_or(kw::Empty, |i| i.name), }) .collect(), }, From f915e3e5cff7505178bb19286db8abd7b8eb25dc Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 7 Jan 2021 17:58:05 +0300 Subject: [PATCH 10/11] rustc_ast_pretty: Remove `PrintState::insert_extra_parens` It's no longer necessary after #79472 --- compiler/rustc_ast_pretty/src/pprust/mod.rs | 5 ---- compiler/rustc_ast_pretty/src/pprust/state.rs | 28 ++----------------- compiler/rustc_hir_pretty/src/lib.rs | 3 -- compiler/rustc_parse/src/lib.rs | 3 +- 4 files changed, 3 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_ast_pretty/src/pprust/mod.rs b/compiler/rustc_ast_pretty/src/pprust/mod.rs index b34ea41ab558a..b88699f6ee176 100644 --- a/compiler/rustc_ast_pretty/src/pprust/mod.rs +++ b/compiler/rustc_ast_pretty/src/pprust/mod.rs @@ -8,11 +8,6 @@ use rustc_ast as ast; use rustc_ast::token::{Nonterminal, Token, TokenKind}; use rustc_ast::tokenstream::{TokenStream, TokenTree}; -pub fn nonterminal_to_string_no_extra_parens(nt: &Nonterminal) -> String { - let state = State::without_insert_extra_parens(); - state.nonterminal_to_string(nt) -} - pub fn nonterminal_to_string(nt: &Nonterminal) -> String { State::new().nonterminal_to_string(nt) } diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 0e4f2798bd313..ca816ef676959 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -88,13 +88,6 @@ pub struct State<'a> { comments: Option>, ann: &'a (dyn PpAnn + 'a), is_expanded: bool, - // If `true`, additional parenthesis (separate from `ExprKind::Paren`) - // are inserted to ensure that proper precedence is preserved - // in the pretty-printed output. - // - // This is usually `true`, except when performing the pretty-print/reparse - // check in `nt_to_tokenstream` - insert_extra_parens: bool, } crate const INDENT_UNIT: usize = 4; @@ -115,7 +108,6 @@ pub fn print_crate<'a>( comments: Some(Comments::new(sm, filename, input)), ann, is_expanded, - insert_extra_parens: true, }; if is_expanded && !krate.attrs.iter().any(|attr| attr.has_name(sym::no_core)) { @@ -235,7 +227,6 @@ impl std::ops::DerefMut for State<'_> { } pub trait PrintState<'a>: std::ops::Deref + std::ops::DerefMut { - fn insert_extra_parens(&self) -> bool; fn comments(&mut self) -> &mut Option>; fn print_ident(&mut self, ident: Ident); fn print_generic_args(&mut self, args: &ast::GenericArgs, colons_before_params: bool); @@ -819,16 +810,12 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::Dere fn to_string(&self, f: impl FnOnce(&mut State<'_>)) -> String { let mut printer = State::new(); - printer.insert_extra_parens = self.insert_extra_parens(); f(&mut printer); printer.s.eof() } } impl<'a> PrintState<'a> for State<'a> { - fn insert_extra_parens(&self) -> bool { - self.insert_extra_parens - } fn comments(&mut self) -> &mut Option> { &mut self.comments } @@ -865,17 +852,7 @@ impl<'a> PrintState<'a> for State<'a> { impl<'a> State<'a> { pub fn new() -> State<'a> { - State { - s: pp::mk_printer(), - comments: None, - ann: &NoAnn, - is_expanded: false, - insert_extra_parens: true, - } - } - - pub(super) fn without_insert_extra_parens() -> State<'a> { - State { insert_extra_parens: false, ..State::new() } + State { s: pp::mk_printer(), comments: None, ann: &NoAnn, is_expanded: false } } // Synthesizes a comment that was not textually present in the original source @@ -1680,8 +1657,7 @@ impl<'a> State<'a> { } /// Prints `expr` or `(expr)` when `needs_par` holds. - fn print_expr_cond_paren(&mut self, expr: &ast::Expr, mut needs_par: bool) { - needs_par &= self.insert_extra_parens; + fn print_expr_cond_paren(&mut self, expr: &ast::Expr, needs_par: bool) { if needs_par { self.popen(); } diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index ddd3827c81df6..a9aa192bbcc3b 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -138,9 +138,6 @@ impl std::ops::DerefMut for State<'_> { } impl<'a> PrintState<'a> for State<'a> { - fn insert_extra_parens(&self) -> bool { - true - } fn comments(&mut self) -> &mut Option> { &mut self.comments } diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 4fa9768febb36..0da9cd3fe5ee9 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -283,8 +283,7 @@ pub fn nt_to_tokenstream( } else if matches!(synthesize_tokens, CanSynthesizeMissingTokens::Yes) { return fake_token_stream(sess, nt); } else { - let pretty = rustc_ast_pretty::pprust::nonterminal_to_string_no_extra_parens(&nt); - panic!("Missing tokens for nt {:?}", pretty); + panic!("Missing tokens for nt {:?}", pprust::nonterminal_to_string(nt)); } } From 31375d2074aeed0c6f173aa200f0bd3bf6d36756 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 7 Jan 2021 17:40:07 -0500 Subject: [PATCH 11/11] Get rid of custom pretty-printing in rustdoc and use rustc_hir_pretty directly instead --- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/clean/utils.rs | 70 --------------------------- src/test/rustdoc-ui/range-pattern.rs | 3 ++ src/test/rustdoc/range-arg-pattern.rs | 5 ++ 4 files changed, 9 insertions(+), 71 deletions(-) create mode 100644 src/test/rustdoc-ui/range-pattern.rs create mode 100644 src/test/rustdoc/range-arg-pattern.rs diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f4eb1924e6f7e..992b6220f0ca7 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -962,7 +962,7 @@ impl<'a> Clean for (&'a [hir::Ty<'a>], hir::BodyId) { .iter() .enumerate() .map(|(i, ty)| Argument { - name: name_from_pat(&body.params[i].pat), + name: Symbol::intern(&rustc_hir_pretty::param_to_string(&body.params[i])), type_: ty.clean(cx), }) .collect(), diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index d4482d6fa9015..ca8cc0a83bd3f 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -314,25 +314,6 @@ crate fn strip_path(path: &Path) -> Path { Path { global: path.global, res: path.res, segments } } -crate fn qpath_to_string(p: &hir::QPath<'_>) -> String { - let segments = match *p { - hir::QPath::Resolved(_, ref path) => &path.segments, - hir::QPath::TypeRelative(_, ref segment) => return segment.ident.to_string(), - hir::QPath::LangItem(lang_item, ..) => return lang_item.name().to_string(), - }; - - let mut s = String::new(); - for (i, seg) in segments.iter().enumerate() { - if i > 0 { - s.push_str("::"); - } - if seg.ident.name != kw::PathRoot { - s.push_str(&seg.ident.as_str()); - } - } - s -} - crate fn build_deref_target_impls(cx: &DocContext<'_>, items: &[Item], ret: &mut Vec) { let tcx = cx.tcx; @@ -376,57 +357,6 @@ impl ToSource for rustc_span::Span { } } -crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { - use rustc_hir::*; - debug!("trying to get a name from pattern: {:?}", p); - - Symbol::intern(&match p.kind { - PatKind::Wild => return kw::Underscore, - PatKind::Binding(_, _, ident, _) => return ident.name, - PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p), - PatKind::Struct(ref name, ref fields, etc) => format!( - "{} {{ {}{} }}", - qpath_to_string(name), - fields - .iter() - .map(|fp| format!("{}: {}", fp.ident, name_from_pat(&fp.pat))) - .collect::>() - .join(", "), - if etc { ", .." } else { "" } - ), - PatKind::Or(ref pats) => pats - .iter() - .map(|p| name_from_pat(&**p).to_string()) - .collect::>() - .join(" | "), - PatKind::Tuple(ref elts, _) => format!( - "({})", - elts.iter() - .map(|p| name_from_pat(&**p).to_string()) - .collect::>() - .join(", ") - ), - PatKind::Box(ref p) => return name_from_pat(&**p), - PatKind::Ref(ref p, _) => return name_from_pat(&**p), - PatKind::Lit(..) => { - warn!( - "tried to get argument name from PatKind::Lit, which is silly in function arguments" - ); - return Symbol::intern("()"); - } - PatKind::Range(..) => panic!( - "tried to get argument name from PatKind::Range, \ - which is not allowed in function arguments" - ), - PatKind::Slice(ref begin, ref mid, ref end) => { - let begin = begin.iter().map(|p| name_from_pat(&**p).to_string()); - let mid = mid.as_ref().map(|p| format!("..{}", name_from_pat(&**p))).into_iter(); - let end = end.iter().map(|p| name_from_pat(&**p).to_string()); - format!("[{}]", begin.chain(mid).chain(end).collect::>().join(", ")) - } - }) -} - crate fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String { match n.val { ty::ConstKind::Unevaluated(def, _, promoted) => { diff --git a/src/test/rustdoc-ui/range-pattern.rs b/src/test/rustdoc-ui/range-pattern.rs new file mode 100644 index 0000000000000..fd255d02fcb6a --- /dev/null +++ b/src/test/rustdoc-ui/range-pattern.rs @@ -0,0 +1,3 @@ +// check-pass + +fn func(0u8..=255: u8) {} diff --git a/src/test/rustdoc/range-arg-pattern.rs b/src/test/rustdoc/range-arg-pattern.rs new file mode 100644 index 0000000000000..f4cc36b1055ad --- /dev/null +++ b/src/test/rustdoc/range-arg-pattern.rs @@ -0,0 +1,5 @@ +#![crate_name = "foo"] + +// @has foo/fn.f.html +// @has - '//*[@class="rust fn"]' 'pub fn f(0u8 ...255: u8)' +pub fn f(0u8...255: u8) {}