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

Add support for "true"/"false" intra doc link #75101

Conversation

GuillaumeGomez
Copy link
Member

Part of #74515.

Explanations of what I did here: instead of checking more globally in primitive types, I think that only true and false values should be transformed into a link to bool. Others are either numbers or strings and I don't think we want to link all of them "generally". So in here, in case true and false didn't match anything (maybe a module was here, we don't know?), we then link them to the bool type.

r? @jyn514

cc @rust-lang/rustdoc

@rust-highfive
Copy link
Collaborator

Some changes occurred in intra-doc-links.

cc @jyn514

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 3, 2020
@jyn514
Copy link
Member

jyn514 commented Aug 3, 2020

How do we know these are the only primitive values that have keywords? I'm ok with this workaround but I want to be sure we didn't miss anything.

@jyn514 jyn514 added 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. labels Aug 3, 2020
@jyn514
Copy link
Member

jyn514 commented Aug 3, 2020

Ok, there is a list of keywords at https://doc.rust-lang.org/std/index.html#keywords.

Do we want to support all of those, like as and dyn? Or just the keywords that are types?

@jyn514
Copy link
Member

jyn514 commented Aug 3, 2020

I think we should at least support enum, union, and trait.

@GuillaumeGomez
Copy link
Member Author

keyword != primitive. In here we use values which are in fact of primitive type. enum, union and trait aren't. Or maybe I missed your point?

@GuillaumeGomez
Copy link
Member Author

CI failure:

warning: spurious network error (1 tries remaining): failed to get 200 response from `https://crates.io/api/v1/crates/autocfg/1.0.0/download`, got 504
error: failed to download from `https://crates.io/api/v1/crates/libc/0.2.74/download`

@Mark-Simulacrum
Copy link
Member

It seems a bit odd to link to the bool type for these rather than https://doc.rust-lang.org/nightly/std/keyword.true.html and https://doc.rust-lang.org/nightly/std/keyword.false.html -- if we're going to autolink keywords, we should link to the keyword documentation, I think.

@GuillaumeGomez
Copy link
Member Author

Oh I see, we had two different things in mind. Then we could try to do this based on the doc aliases directly, don't you think? Or should we keep a list based on the official keywords and only link using those? The second solution would allow a much simpler fix.

@jyn514
Copy link
Member

jyn514 commented Aug 3, 2020

I think linking by doc-aliases would be the best approach - that would link to all keywords, right?

The issue with special-casing keywords is that now we have to hard-code either stable or nightly; if we use resolve for it then it will always be the appropriate version.

@GuillaumeGomez
Copy link
Member Author

Ok, I'll update the PR with this change.

Comment on lines 751 to 756
match PRIMITIVES.iter().find(|(ty, _)| *ty == "bool") {
Some((_, res)) => (*res, Some("bool".to_owned())),
None => {
resolution_failure(cx, &item, path_str, &dox, link_range);
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be always checking in a loop? Shouldn't we get bool only once or make this static?

@Manishearth
Copy link
Member

I think we should link to the keywords here.

But I'm kinda skeptical of doing this at all, these are keywords and not paths. Seems ok for true and false but maybe not so much for other keywords. I also see a very low utility for it, and because they're not paths, I don't expect people to reach for them aside from the bool literals (which behave kinda like paths, at least)

@jyn514
Copy link
Member

jyn514 commented Aug 3, 2020

FWIW I'm ok with just not implementing this, this is definitely out of the scope of the original RFC. Up to @GuillaumeGomez if he wants to go through with the PR since he already wrote a lot of it.

If we do implement it though, I think it would be nice to make it work for all keywords.

@GuillaumeGomez
Copy link
Member Author

Honestly I'm not sure it's worth it so let's just keep it simple. I'll update to link to the keyword pages though.

@Manishearth
Copy link
Member

I'm very against linking to all keywords, the only reason I'm somewhat okay with this one is because true and false behave kind of like paths; they operate in path positions (unlike most other keywords).

@GuillaumeGomez
Copy link
Member Author

Yes we agree, only keywords for true and false. ;)

@GuillaumeGomez GuillaumeGomez force-pushed the true-false-intra-doc-link branch from 14a9aca to 4d2a53f Compare August 3, 2020 16:35
@GuillaumeGomez
Copy link
Member Author

Updated!

@Manishearth
Copy link
Member

No that was a response to @jyn514 who wanted us to do all keywords if we do true/false.

@GuillaumeGomez GuillaumeGomez force-pushed the true-false-intra-doc-link branch from 4d2a53f to 66d998f Compare August 3, 2020 16:36
@GuillaumeGomez
Copy link
Member Author

Oh I see, well, we can talk about it at a later time if enough people are interested. But currently, not very convinced.

@jyn514
Copy link
Member

jyn514 commented Aug 3, 2020

@bors r+

@Manishearth
Copy link
Member

@bors r-

two team members are against it at this point. Maybe we should hold off unless there's strong motivation?

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 3, 2020
@GuillaumeGomez
Copy link
Member Author

I don't have strong feelings here so we can close it if everyone agrees?

@jyn514
Copy link
Member

jyn514 commented Aug 4, 2020

Sounds good to me.

@jyn514 jyn514 closed this Aug 4, 2020
@GuillaumeGomez GuillaumeGomez deleted the true-false-intra-doc-link branch August 4, 2020 13:11
@jyn514
Copy link
Member

jyn514 commented Aug 15, 2020

This came up again in #75567, which has 38 different links to true and false ... what do you think about only linking true and false and no other keywords? I took a bit of a strong position last time 😆

cc @poliorcetics

@GuillaumeGomez
Copy link
Member Author

Well, if enough people are interested, please reopen then. 😆

@jyn514

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez restored the true-false-intra-doc-link branch August 15, 2020 21:48
@GuillaumeGomez

This comment has been minimized.

@jyn514 jyn514 reopened this Aug 15, 2020
@ollie27
Copy link
Member

ollie27 commented Aug 15, 2020

what do you think about only linking true and false and no other keywords?

What would they link to? I think linking to the bool page makes sense and would be more useful than the keyword pages which don't contain much.

@Manishearth
Copy link
Member

I agree with Ollie here

@jyn514
Copy link
Member

jyn514 commented Aug 16, 2020

Linking to bool sounds fine to me, that's actually where they go currently: https://github.com/rust-lang/rust/pull/75567/files#diff-3935db3bd98ce45bbc780286b8d11c78R212

@poliorcetics
Copy link
Contributor

poliorcetics commented Aug 16, 2020

true and false would be very nice to have for documenting rust itself (I expected them to behave like Ok or Some) but if it needs a lot of special-casing code, don't bother. They shouldn't be used too much outside std, core or alloc (though that claim is completely unverified) so we should ensure the benefits outweigh the costs.

@jyn514
Copy link
Member

jyn514 commented Aug 16, 2020

if it needs a lot of special-casing code, don't bother

If we're just linking to bool, the code can be simplified quite a bit, @GuillaumeGomez just needs to add an alias next to bool:

("bool", Res::PrimTy(hir::PrimTy::Bool)),

I expected them to behave like Ok or Some

Well, they can't really because Ok and Some are documented on the same page as Result, but all the keywords are on separate pages. Does linking to bool sound like the right behavior?

@poliorcetics
Copy link
Contributor

Oh that's nice if it doesn't ask for a lot of code.

Yeah, linking to bool is better I think.

@jyn514
Copy link
Member

jyn514 commented Aug 18, 2020

Opened #75652 which links true and false to bool. It's a little simpler than this one because it doesn't have to deal with keywords.

@GuillaumeGomez do you mind if I close this PR (again :P)?

@GuillaumeGomez
Copy link
Member Author

Too late, I already did! :p

tmandry added a commit to tmandry/rust that referenced this pull request Aug 19, 2020
Resolve true and false as booleans

Successor to rust-lang#75101.

r? @Manishearth
cc @rust-lang/rustdoc
tmandry added a commit to tmandry/rust that referenced this pull request Aug 19, 2020
Resolve true and false as booleans

Successor to rust-lang#75101.

r? @Manishearth
cc @rust-lang/rustdoc
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 19, 2020
Resolve true and false as booleans

Successor to rust-lang#75101.

r? @Manishearth
cc @rust-lang/rustdoc
@GuillaumeGomez GuillaumeGomez deleted the true-false-intra-doc-link branch August 19, 2024 12:24
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. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants