Skip to content

Fnty args rustdoc #44892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ impl<'a> LoweringContext<'a> {
unsafety: self.lower_unsafety(f.unsafety),
abi: f.abi,
decl: self.lower_fn_decl(&f.decl),
arg_names: self.lower_fn_args_to_names(&f.decl),
}))
}
TyKind::Never => hir::TyNever,
Expand Down
1 change: 1 addition & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 5 additions & 3 deletions src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down Expand Up @@ -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() {
Expand All @@ -2163,7 +2165,7 @@ impl<'a> State<'a> {
name,
&generics,
&hir::Inherited,
&[],
arg_names,
None)?;
self.end()
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_ {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2491,7 +2491,7 @@ impl Clean<BareFunctionDecl> for hir::BareFnTy {
type_params: Vec::new(),
where_predicates: Vec::new()
},
decl: (&*self.decl, &[][..]).clean(cx),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing impls are already powerful enough for this (unless I wasn't careful), all you need is to replace &[][..] with &self.arg_names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly:

no method named `clean` found for type `(&rustc::hir::FnDecl, &syntax::ptr::P<[syntax::codemap::Spanned<syntax::ast::Symbol>]>)` in the current scope
    --> src/librustdoc/clean/mod.rs:2507:50
     |
2507 |             decl: (&*self.decl, &self.arg_names).clean(cx),
     |                                                  ^^^^^
     |
     = note: the method `clean` exists but the following trait bounds were not satisfied:
             `(&[syntax::ptr::P<rustc::hir::Ty>], &syntax::ptr::P<[syntax::codemap::Spanned<syntax::ast::Symbol>]>) : clean::Clean<clean::Arguments>`
     = help: items from traits can only be used if the trait is implemented and in scope
     = note: the following trait defines an item `clean`, perhaps you need to implement it:
             candidate #1: `clean::Clean`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like you need &self.arg_names[..] instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like, look for ForeignItemFn, it starts off with the same information but it doesn't implement the cleaning itself.

decl: (&*self.decl, &self.arg_names[..]).clean(cx),
abi: self.abi,
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/test/rustdoc/fn-pointer-arg-name.rs
Original file line number Diff line number Diff line change
@@ -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)) {}