diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-09-27 00:43:37 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-10-07 17:23:06 +0200 |
| commit | fe24e815a2d0aecfd975a15a12a4b4937bb4cc37 (patch) | |
| tree | b14e534477fb66a951439ad35c434aa11025fc3f | |
| parent | 3493c62ff2628ef81f6f3a968c951252e9b57824 (diff) | |
| download | rust-fe24e815a2d0aecfd975a15a12a4b4937bb4cc37.tar.gz rust-fe24e815a2d0aecfd975a15a12a4b4937bb4cc37.zip | |
Fix invalid rustdoc rendering for FnTy args
| -rw-r--r-- | src/librustc/hir/intravisit.rs | 2 | ||||
| -rw-r--r-- | src/librustc/hir/lowering.rs | 11 | ||||
| -rw-r--r-- | src/librustc/hir/mod.rs | 1 | ||||
| -rw-r--r-- | src/librustc/hir/print.rs | 8 | ||||
| -rw-r--r-- | src/librustc/ich/impls_hir.rs | 3 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 2 | ||||
| -rw-r--r-- | src/test/rustdoc/fn-pointer-arg-name.rs | 15 |
7 files changed, 27 insertions, 15 deletions
diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 3130a88306e..1755b3bca05 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -574,7 +574,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { TyTup(ref tuple_element_types) => { walk_list!(visitor, visit_ty, tuple_element_types); } - TyBareFn(ref function_declaration, _) => { + TyBareFn(ref function_declaration) => { visitor.visit_fn_decl(&function_declaration.decl); walk_list!(visitor, visit_lifetime_def, &function_declaration.lifetimes); } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index c03c9499608..64a2ba1fa6f 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -673,15 +673,8 @@ impl<'a> LoweringContext<'a> { unsafety: self.lower_unsafety(f.unsafety), abi: f.abi, decl: self.lower_fn_decl(&f.decl), - }, - decl.inputs.iter().map(|arg| { - match arg.pat.node { - PatKind::Ident(_, ident, None) => { - respan(ident.span, ident.node.name) - } - _ => respan(arg.pat.span, keywords::Invalid.name()), - } - }).collect())) + arg_names: self.lower_fn_args_to_names(&f.decl), + })) } TyKind::Never => hir::TyNever, TyKind::Tup(ref tys) => { diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index dcff66dc23b..5ad0ff04c1b 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1418,6 +1418,7 @@ pub struct BareFnTy { pub abi: Abi, pub lifetimes: HirVec<LifetimeDef>, pub decl: P<FnDecl>, + pub arg_names: HirVec<Spanned<Name>>, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 5daffe667fd..7287e599b29 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -399,7 +399,8 @@ impl<'a> State<'a> { }, span: syntax_pos::DUMMY_SP, }; - self.print_ty_fn(f.abi, f.unsafety, &f.decl, None, &generics)?; + self.print_ty_fn(f.abi, f.unsafety, &f.decl, None, &generics, + &f.arg_names[..])?; } hir::TyPath(ref qpath) => { self.print_qpath(qpath, false)? @@ -2140,7 +2141,8 @@ impl<'a> State<'a> { unsafety: hir::Unsafety, decl: &hir::FnDecl, name: Option<ast::Name>, - generics: &hir::Generics) + generics: &hir::Generics, + arg_names: &[Spanned<ast::Name>]) -> io::Result<()> { self.ibox(indent_unit)?; if !generics.lifetimes.is_empty() || !generics.ty_params.is_empty() { @@ -2163,7 +2165,7 @@ impl<'a> State<'a> { name, &generics, &hir::Inherited, - &[], + arg_names, None)?; self.end() } diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 776f85cf5da..c0fae8bf8bd 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -274,7 +274,8 @@ impl_stable_hash_for!(struct hir::BareFnTy { unsafety, abi, lifetimes, - decl + decl, + arg_names }); impl_stable_hash_for!(enum hir::Ty_ { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c9afa3646b2..424f48a17e9 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2491,7 +2491,7 @@ impl Clean<BareFunctionDecl> for hir::BareFnTy { type_params: Vec::new(), where_predicates: Vec::new() }, - decl: (&*self.decl, &[][..]).clean(cx), + decl: (&*self.decl, &self.arg_names[..]).clean(cx), abi: self.abi, } } diff --git a/src/test/rustdoc/fn-pointer-arg-name.rs b/src/test/rustdoc/fn-pointer-arg-name.rs new file mode 100644 index 00000000000..af87f1b4669 --- /dev/null +++ b/src/test/rustdoc/fn-pointer-arg-name.rs @@ -0,0 +1,15 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_name = "foo"] + +// @has foo/fn.f.html +// @has - '//*[@class="rust fn"]' 'pub fn f(callback: fn(len: usize, foo: u32))' +pub fn f(callback: fn(len: usize, foo: u32)) {} |
