Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix automatic urls with backticks #49189

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ fn ambiguity_error(cx: &DocContext, attrs: &Attributes,
select the {}",
disambig1, kind1, disambig2,
kind2))
.emit();
.emit();
}

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

#[derive(Debug)]
enum PathKind {
/// can be either value or type, not a macro
Unknown,
Expand All @@ -1082,7 +1083,7 @@ enum PathKind {
/// values, functions, consts, statics, everything in the value namespace
Value,
/// types, traits, everything in the type namespace
Type
Type,
}

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

if UnstableFeatures::from_environment().is_nightly_build() {
let dox = attrs.collapsed_doc_value().unwrap_or_else(String::new);
for link in markdown_links(&dox) {
for ori_link in markdown_links(&dox) {
// bail early for real links
if link.contains('/') {
if ori_link.contains('/') {
continue;
}
let (def, fragment) = {
let link = ori_link.replace("`", "");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some part of me wants this to be a trim_matches instead of a replace, but in practice it won't matter.

let (def, fragment) = {
let mut kind = PathKind::Unknown;
let path_str = if let Some(prefix) =
["struct@", "enum@", "type@",
Expand Down Expand Up @@ -1132,7 +1134,6 @@ impl Clean<Attributes> for [ast::Attribute] {
continue;
}


match kind {
PathKind::Value => {
if let Ok(def) = resolve(cx, path_str, true) {
Expand Down Expand Up @@ -1206,9 +1207,8 @@ impl Clean<Attributes> for [ast::Attribute] {
}
};


let id = register_def(cx, def);
attrs.links.push((link, id, fragment));
attrs.links.push((ori_link, id, fragment));
}

cx.sess().abort_if_errors();
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
/// Make headings links with anchor ids and build up TOC.
struct LinkReplacer<'a, 'b, I: Iterator<Item = Event<'a>>> {
inner: I,
links: &'b [(String, String)]
links: &'b [(String, String)],
}

impl<'a, 'b, I: Iterator<Item = Event<'a>>> LinkReplacer<'a, 'b, I> {
fn new(iter: I, links: &'b [(String, String)]) -> Self {
LinkReplacer {
inner: iter,
links
links,
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/rustdoc/check-styled-link.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![crate_name = "foo"]

pub struct Foo;

// @has foo/struct.Bar.html '//a[@href="../foo/struct.Foo.html"]' 'Foo'

/// Code-styled reference to [`Foo`].
pub struct Bar;