Skip to content

Commit

Permalink
Set constness correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 19, 2018
1 parent 170f068 commit a6943d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -1674,18 +1674,24 @@ impl Clean<Item> for doctree::Function {
(self.generics.clean(cx), (&self.decl, self.body).clean(cx))
});

let did = cx.tcx.hir().local_def_id(self.id);
let constness = if cx.tcx.is_min_const_fn(did) {
hir::Constness::Const
} else {
hir::Constness::NotConst
};
Item {
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
def_id: cx.tcx.hir().local_def_id(self.id),
def_id: did,
inner: FunctionItem(Function {
decl,
generics,
header: self.header,
header: hir::FnHeader { constness, ..self.header },
}),
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/rustdoc/const-display.rs
Expand Up @@ -18,26 +18,26 @@
#![feature(min_const_unsafe_fn)]
#![feature(staged_api)]

// @has 'foo/fn.foo.html' '//pre' 'pub const unsafe fn foo() -> u32'
// @has 'foo/fn.foo.html' '//pre' 'pub unsafe fn foo() -> u32'
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature="foo")]
pub const unsafe fn foo() -> u32 { 42 }

// @has 'foo/fn.foo2.html' '//pre' 'pub const fn foo2() -> u32'
// @has 'foo/fn.foo2.html' '//pre' 'pub fn foo2() -> u32'
#[unstable(feature = "humans", issue="0")]
pub const fn foo2() -> u32 { 42 }

// @has 'foo/fn.bar2.html' '//pre' 'pub const fn bar2() -> u32'
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn bar2() -> u32 { 42 }

// @has 'foo/fn.foo2_gated.html' '//pre' 'pub const unsafe fn foo2_gated() -> u32'
// @has 'foo/fn.foo2_gated.html' '//pre' 'pub unsafe fn foo2_gated() -> u32'
#[unstable(feature = "foo2", issue="0")]
pub const unsafe fn foo2_gated() -> u32 { 42 }

// @has 'foo/fn.bar2_gated.html' '//pre' 'pub const unsafe fn bar2_gated() -> u32'
#[stable(feature = "rust1", since = "1.0.0")]
pub const unsafe fn bar2_gated() -> u32 { 42 }

// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub const unsafe fn bar_not_gated() -> u32'
// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub unsafe fn bar_not_gated() -> u32'
pub const unsafe fn bar_not_gated() -> u32 { 42 }

0 comments on commit a6943d9

Please sign in to comment.