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

Intra-doc links don't accept all macro delimiters #86310

Closed
LeSeulArtichaut opened this issue Jun 14, 2021 · 6 comments · Fixed by #86523
Closed

Intra-doc links don't accept all macro delimiters #86310

LeSeulArtichaut opened this issue Jun 14, 2021 · 6 comments · Fixed by #86523
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@LeSeulArtichaut
Copy link
Contributor

LeSeulArtichaut commented Jun 14, 2021

Consider this code:

// This can be invoked with `foo!()`, `foo[]` or `foo{}`
#[macro_export] macro_rules! foo {
    () => {}
}

/// This is parsed as an intra-doc link: [foo!()]...
/// ...but those aren't: [foo![]] [foo!{}]
pub struct Foo;

I'm not sure if this is a deliberate decision or not. If it is, what's the rationale for not accepting [] and {}? cc @jyn514

@LeSeulArtichaut LeSeulArtichaut added C-bug Category: This is a bug. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name T-rustdoc labels Jun 14, 2021
@jyn514
Copy link
Member

jyn514 commented Jun 14, 2021

It isn't valid markdown syntax.

@jyn514
Copy link
Member

jyn514 commented Jun 14, 2021

Well, {} might be. But [] definitely is not.

@LeSeulArtichaut
Copy link
Contributor Author

It isn't valid markdown syntax.

[foo![]](foo!) seems to work fine (it renders as foo![] and the link is correct). But maybe you're saying that we shouldn't accept [foo![]] because it wouldn't be valid markdown?

Well, {} might be.

Is it worth implementing?

@jyn514
Copy link
Member

jyn514 commented Jun 14, 2021

@LeSeulArtichaut hmm, it might be valid in that position, but it's not valid as a link reference:

See [foo![]].

[foo![]]: foo![]

But I guess there's no reason for rustdoc to explicitly reject it.

Is it worth implementing?

I would be ok with it, @Manishearth may have opinions.

@Manishearth
Copy link
Member

I'm okay with it. I'm mostly wary about characters that are common in URLs, curly braces are not.

@LeSeulArtichaut LeSeulArtichaut added C-enhancement Category: An issue proposing an enhancement or a PR with one. and removed C-bug Category: This is a bug. labels Jun 16, 2021
@LeSeulArtichaut
Copy link
Contributor Author

LeSeulArtichaut commented Jun 21, 2021

Oh, the reason why [macro![]](macro!) works is because the rules for inline links are more relaxed:

Brackets are allowed in the link text only if (a) they are backslash-escaped or (b) they appear as a matched pair of brackets, with an open bracket [, a sequence of zero or more inlines, and a close bracket ].

vs

A link label begins with a left bracket ([) and ends with the first right bracket (]) that is not backslash-escaped. Unescaped square bracket characters are not allowed inside the opening and closing square brackets of link labels.

So instead do you think rustdoc should parse [macro!\[\]]?

@jyn514 jyn514 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed T-rustdoc-temp labels Jun 22, 2021
@bors bors closed this as completed in f9ebf1e Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants