Skip to content

Commit 4083bdf

Browse files
Fix impl assoc constant link not working
1 parent a0b0f5f commit 4083bdf

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/librustdoc/clean/mod.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1022,11 +1022,12 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
10221022
.flat_map(|imp| cx.tcx.associated_items(*imp))
10231023
.find(|item| item.name == item_name);
10241024
if let Some(item) = item {
1025-
if item.kind == ty::AssociatedKind::Method && is_val {
1026-
Ok((ty.def, Some(format!("method.{}", item_name))))
1027-
} else {
1028-
Err(())
1029-
}
1025+
let out = match item.kind {
1026+
ty::AssociatedKind::Method if is_val => "method",
1027+
ty::AssociatedKind::Const if is_val => "associatedconstant",
1028+
_ => return Err(())
1029+
};
1030+
Ok((ty.def, Some(format!("{}.{}", out, item_name))))
10301031
} else {
10311032
Err(())
10321033
}
@@ -1139,9 +1140,6 @@ impl Clean<Attributes> for [ast::Attribute] {
11391140
&link[..]
11401141
}.trim();
11411142

1142-
// avoid resolving things (i.e. regular links) which aren't like paths
1143-
// FIXME(Manishearth) given that most links have slashes in them might be worth
1144-
// doing a check for slashes first
11451143
if path_str.contains(|ch: char| !(ch.is_alphanumeric() ||
11461144
ch == ':' || ch == '_')) {
11471145
continue;

src/test/rustdoc/link-assoc-const.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2018 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+
#![crate_name = "foo"]
12+
13+
// @has foo/index.html '//a[@href="../foo/foo/constant.FIRSTCONST.html"]' 'foo::FIRSTCONST'
14+
// @has foo/index.html '//a[@href="../foo/struct.Bar.html#associatedconstant.CONST"]' 'Bar::CONST'
15+
16+
//! We have here [`foo::FIRSTCONST`] and [`Bar::CONST`].
17+
18+
pub mod foo {
19+
pub const FIRSTCONST: u32 = 42;
20+
}
21+
22+
pub struct Bar;
23+
24+
impl Bar {
25+
pub const CONST: u32 = 42;
26+
}

0 commit comments

Comments
 (0)