Skip to content

Commit c8a3507

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 b199613 + bac6484 commit c8a3507

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
@@ -929,7 +929,7 @@ fn ambiguity_error(cx: &DocContext, attrs: &Attributes,
929929
select the {}",
930930
disambig1, kind1, disambig2,
931931
kind2))
932-
.emit();
932+
.emit();
933933
}
934934

935935
/// Given an enum variant's def, return the def of its enum and the associated fragment
@@ -1074,6 +1074,7 @@ fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
10741074
}
10751075
}
10761076

1077+
#[derive(Debug)]
10771078
enum PathKind {
10781079
/// can be either value or type, not a macro
10791080
Unknown,
@@ -1082,7 +1083,7 @@ enum PathKind {
10821083
/// values, functions, consts, statics, everything in the value namespace
10831084
Value,
10841085
/// types, traits, everything in the type namespace
1085-
Type
1086+
Type,
10861087
}
10871088

10881089
impl Clean<Attributes> for [ast::Attribute] {
@@ -1091,12 +1092,13 @@ impl Clean<Attributes> for [ast::Attribute] {
10911092

10921093
if UnstableFeatures::from_environment().is_nightly_build() {
10931094
let dox = attrs.collapsed_doc_value().unwrap_or_else(String::new);
1094-
for link in markdown_links(&dox) {
1095+
for ori_link in markdown_links(&dox) {
10951096
// bail early for real links
1096-
if link.contains('/') {
1097+
if ori_link.contains('/') {
10971098
continue;
10981099
}
1099-
let (def, fragment) = {
1100+
let link = ori_link.replace("`", "");
1101+
let (def, fragment) = {
11001102
let mut kind = PathKind::Unknown;
11011103
let path_str = if let Some(prefix) =
11021104
["struct@", "enum@", "type@",
@@ -1132,7 +1134,6 @@ impl Clean<Attributes> for [ast::Attribute] {
11321134
continue;
11331135
}
11341136

1135-
11361137
match kind {
11371138
PathKind::Value => {
11381139
if let Ok(def) = resolve(cx, path_str, true) {
@@ -1206,9 +1207,8 @@ impl Clean<Attributes> for [ast::Attribute] {
12061207
}
12071208
};
12081209

1209-
12101210
let id = register_def(cx, def);
1211-
attrs.links.push((link, id, fragment));
1211+
attrs.links.push((ori_link, id, fragment));
12121212
}
12131213

12141214
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)