Skip to content

Commit 82d37f3

Browse files
committed
Show constness for functions of reexported docs
1 parent 81b4c13 commit 82d37f3

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,19 @@ fn build_external_function(cx: &DocContext, tcx: &ty::ctxt, did: DefId) -> clean
170170
ty::TyBareFn(_, ref f) => ((did, &f.sig).clean(cx), f.unsafety, f.abi),
171171
_ => panic!("bad function"),
172172
};
173+
174+
let constness = if csearch::is_const_fn(&tcx.sess.cstore, did) {
175+
hir::Constness::Const
176+
} else {
177+
hir::Constness::NotConst
178+
};
179+
173180
let predicates = tcx.lookup_predicates(did);
174181
clean::Function {
175182
decl: decl,
176183
generics: (&t.generics, &predicates, subst::FnSpace).clean(cx),
177184
unsafety: style,
178-
constness: hir::Constness::NotConst,
185+
constness: constness,
179186
abi: abi,
180187
}
181188
}
@@ -345,9 +352,15 @@ pub fn build_impl(cx: &DocContext,
345352
clean::TyMethodItem(clean::TyMethod {
346353
unsafety, decl, self_, generics, abi
347354
}) => {
355+
let constness = if csearch::is_const_fn(&tcx.sess.cstore, did) {
356+
hir::Constness::Const
357+
} else {
358+
hir::Constness::NotConst
359+
};
360+
348361
clean::MethodItem(clean::Method {
349362
unsafety: unsafety,
350-
constness: hir::Constness::NotConst,
363+
constness: constness,
351364
decl: decl,
352365
self_: self_,
353366
generics: generics,

src/test/auxiliary/issue-27362.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(const_fn)]
12+
13+
pub const fn foo() {}
14+
pub const unsafe fn bar() {}
15+
16+
pub struct Foo;
17+
18+
impl Foo {
19+
pub const unsafe fn baz() {}
20+
}

src/test/rustdoc/issue-27362.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:issue-27362.rs
12+
// ignore-cross-compile
13+
14+
extern crate issue_27362;
15+
pub use issue_27362 as quux;
16+
17+
// @matches issue_27362/quux/fn.foo.html '//pre' "pub const fn foo()"
18+
// @matches issue_27362/quux/fn.bar.html '//pre' "pub const unsafe fn bar()"
19+
// @matches issue_27362/quux/struct.Foo.html '//code' "const unsafe fn baz()"

0 commit comments

Comments
 (0)