Skip to content

Commit d7eda77

Browse files
committed
Rollup merge of rust-lang#49189 - GuillaumeGomez:fix-implied-shortcut-links, r=QuietMisdreavus
Fix automatic urls with backticks Fixes rust-lang#49164. r? @QuietMisdreavus
2 parents 95967c7 + bac6484 commit d7eda77

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

src/librustdoc/clean/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ fn ambiguity_error(cx: &DocContext, attrs: &Attributes,
942942
select the {}",
943943
disambig1, kind1, disambig2,
944944
kind2))
945-
.emit();
945+
.emit();
946946
}
947947

948948
/// Given an enum variant's def, return the def of its enum and the associated fragment
@@ -1087,6 +1087,7 @@ fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
10871087
}
10881088
}
10891089

1090+
#[derive(Debug)]
10901091
enum PathKind {
10911092
/// can be either value or type, not a macro
10921093
Unknown,
@@ -1095,7 +1096,7 @@ enum PathKind {
10951096
/// values, functions, consts, statics, everything in the value namespace
10961097
Value,
10971098
/// types, traits, everything in the type namespace
1098-
Type
1099+
Type,
10991100
}
11001101

11011102
impl Clean<Attributes> for [ast::Attribute] {
@@ -1104,12 +1105,13 @@ impl Clean<Attributes> for [ast::Attribute] {
11041105

11051106
if UnstableFeatures::from_environment().is_nightly_build() {
11061107
let dox = attrs.collapsed_doc_value().unwrap_or_else(String::new);
1107-
for link in markdown_links(&dox) {
1108+
for ori_link in markdown_links(&dox) {
11081109
// bail early for real links
1109-
if link.contains('/') {
1110+
if ori_link.contains('/') {
11101111
continue;
11111112
}
1112-
let (def, fragment) = {
1113+
let link = ori_link.replace("`", "");
1114+
let (def, fragment) = {
11131115
let mut kind = PathKind::Unknown;
11141116
let path_str = if let Some(prefix) =
11151117
["struct@", "enum@", "type@",
@@ -1145,7 +1147,6 @@ impl Clean<Attributes> for [ast::Attribute] {
11451147
continue;
11461148
}
11471149

1148-
11491150
match kind {
11501151
PathKind::Value => {
11511152
if let Ok(def) = resolve(cx, path_str, true) {
@@ -1219,9 +1220,8 @@ impl Clean<Attributes> for [ast::Attribute] {
12191220
}
12201221
};
12211222

1222-
12231223
let id = register_def(cx, def);
1224-
attrs.links.push((link, id, fragment));
1224+
attrs.links.push((ori_link, id, fragment));
12251225
}
12261226

12271227
cx.sess().abort_if_errors();

src/librustdoc/html/markdown.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,14 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
233233
/// Make headings links with anchor ids and build up TOC.
234234
struct LinkReplacer<'a, 'b, I: Iterator<Item = Event<'a>>> {
235235
inner: I,
236-
links: &'b [(String, String)]
236+
links: &'b [(String, String)],
237237
}
238238

239239
impl<'a, 'b, I: Iterator<Item = Event<'a>>> LinkReplacer<'a, 'b, I> {
240240
fn new(iter: I, links: &'b [(String, String)]) -> Self {
241241
LinkReplacer {
242242
inner: iter,
243-
links
243+
links,
244244
}
245245
}
246246
}

src/test/rustdoc/check-styled-link.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
pub struct Foo;
14+
15+
// @has foo/struct.Bar.html '//a[@href="../foo/struct.Foo.html"]' 'Foo'
16+
17+
/// Code-styled reference to [`Foo`].
18+
pub struct Bar;

0 commit comments

Comments
 (0)