Skip to content

Commit bce743c

Browse files
committed
Auto merge of #29939 - mitaa:doc_const_fn, r=alexcrichton
fixes #27362
2 parents b289892 + 82d37f3 commit bce743c

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

src/librustdoc/clean/inline.rs

+15-2
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/librustdoc/html/render.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1829,12 +1829,12 @@ fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
18291829

18301830
fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
18311831
f: &clean::Function) -> fmt::Result {
1832-
try!(write!(w, "<pre class='rust fn'>{vis}{unsafety}{abi}{constness}fn \
1832+
try!(write!(w, "<pre class='rust fn'>{vis}{constness}{unsafety}{abi}fn \
18331833
{name}{generics}{decl}{where_clause}</pre>",
18341834
vis = VisSpace(it.visibility),
1835+
constness = ConstnessSpace(f.constness),
18351836
unsafety = UnsafetySpace(f.unsafety),
18361837
abi = AbiSpace(f.abi),
1837-
constness = ConstnessSpace(f.constness),
18381838
name = it.name.as_ref().unwrap(),
18391839
generics = f.generics,
18401840
where_clause = WhereClause(&f.generics),
@@ -2055,8 +2055,8 @@ fn render_assoc_item(w: &mut fmt::Formatter, meth: &clean::Item,
20552055
};
20562056
write!(w, "{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
20572057
{generics}{decl}{where_clause}",
2058-
UnsafetySpace(unsafety),
20592058
ConstnessSpace(constness),
2059+
UnsafetySpace(unsafety),
20602060
match abi {
20612061
Abi::Rust => String::new(),
20622062
a => format!("extern {} ", a.to_string())

src/test/auxiliary/issue-27362.rs

+20
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

+19
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)