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 panic when reexporting primitive type in rustdoc #67972

Closed

Conversation

GuillaumeGomez
Copy link
Member

Fixes #67646.

For info: the reexported primitive type won't appear in the documentation. It seems to me to be the expected behavior.

r? @Mark-Simulacrum

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-01-07T13:41:46.0823479Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-01-07T13:41:46.0836736Z ##[command]git config gc.auto 0
2020-01-07T13:41:46.0841561Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-01-07T13:41:46.0845533Z ##[command]git config --get-all http.proxy
2020-01-07T13:41:46.0850576Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/67972/merge:refs/remotes/pull/67972/merge

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@Mark-Simulacrum
Copy link
Member

No, I think that's not quite expected behavior, if I'm following you correctly. I would be fine with either pub use $ty where the type links to primitive docs (if available, currently I believe only in std, though ideally we would change that), or merely a full inlining that treats the new location as the "source of truth", i.e. having the primitive types table there.

@GuillaumeGomez
Copy link
Member Author

I don't see any case where reexporting a primitive type as is would be useful. If we're talking about an alias, it'd make sense but a primitive type, definitely not.

@Mark-Simulacrum
Copy link
Member

It is definitely useful, see the PR that brought this up - #67637.

@GuillaumeGomez
Copy link
Member Author

Damn it, that's a good point! Ok, adding it...

@GuillaumeGomez
Copy link
Member Author

It now appears in the documentation as well.

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

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

r=me with nits addressed

Thanks for getting to this so quickly!

hir::PrimTy::Int(syntax::ast::IntTy::I128) => PrimitiveType::I128,
hir::PrimTy::Int(syntax::ast::IntTy::Isize) => PrimitiveType::Isize,
hir::PrimTy::Float(syntax::ast::FloatTy::F32) => PrimitiveType::F32,
hir::PrimTy::Float(syntax::ast::FloatTy::F64) => PrimitiveType::F64,
Copy link
Member

Choose a reason for hiding this comment

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

I think we already ave impls for the IntTy/FloatTy types so maybe we can just call into() on that?

"str" => tcx.lang_items().str_impl(),
"bool" => tcx.lang_items().bool_impl(),
"char" => tcx.lang_items().char_impl(),
_ => None,
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this should not be a _ but rather an error (e.g., panic!()).

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-01-07T23:34:01.4255501Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-01-07T23:34:01.4266131Z ##[command]git config gc.auto 0
2020-01-07T23:34:01.4268459Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-01-07T23:34:01.4270728Z ##[command]git config --get-all http.proxy
2020-01-07T23:34:01.4272986Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/67972/merge:refs/remotes/pull/67972/merge

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@ollie27
Copy link
Member

ollie27 commented Jan 8, 2020

I don't think that the primitive type docs should be inlined into the std::primitive module because it will unnecessarily duplicate the docs. It should just display pub use bool; etc.

@Mark-Simulacrum
Copy link
Member

Yes, I would prefer that as well -- though it would be great to get the linking working too (even better if we can link from core to std, but I think that's not possible -- i.e., https://doc.rust-lang.org/nightly/core/primitive.char.html not existing is not great).

@GuillaumeGomez
Copy link
Member Author

I can link to std directly if you prefer?

@Mark-Simulacrum
Copy link
Member

I don't know what would work best. It's probably a bit odd to have links in core docs to std docs. Maybe we can move the primitive doc definitions to core and link to those across the board?

OTOH, for ~all other types we re-export from core, we duplicate their documentation, right? So maybe it's a bit weird to only have one location for the primitive types.

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Jan 8, 2020

So what should I do? Link to core or to std? :)

@Mark-Simulacrum
Copy link
Member

How about this:

In core, we will make the primitive module the canonical location for the primitive docs (i.e., no top-level primitives in rustdoc).

In std, the module would render as pub use [i32](core/primitive/primitive.i32.html).

Does that sound reasonable?

@ollie27
Copy link
Member

ollie27 commented Jan 8, 2020

In core, we will make the primitive module the canonical location for the primitive docs (i.e., no top-level primitives in rustdoc).

What about the primitive types that can't be reexported in core::primitive i.e. array, fn, pointer, reference, slice, tuple, unit and never? Where would they be documented?

@Mark-Simulacrum
Copy link
Member

Presumably we could document them in the same module, but that might also be a reason to not do it.

I'm fine with the somewhat more minimal option of just linking to existing docs from std and showing all primitive re-exports as pub use, indeed I might prefer this (but to be honest I am not sure). I think @dtolnay thought that pub use would be the right approach for now at least though.

@hdhoang hdhoang added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 9, 2020
Comment on lines +431 to +437
let def_id = match clean::utils::res_to_def_id(cx, &item.res) {
Some(did) => did,
None => continue,
};
if did == def_id || !visited.insert(def_id) {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

As the def_id is only used to avoid infinite recursion, we only really care about the def_id of modules so using mod_def_id() should be all that's needed to fix the ICE:

if let Some(def_id) = item.res.mod_def_id() {
    if did == def_id || !visited.insert(def_id) {
        continue;
    }
}

Comment on lines +439 to +450
record_extern_fqn(cx, def_id, TypeKind::Primitive);
cx.renderinfo.borrow_mut().inlined.insert(def_id);
items.push(clean::Item {
source: cx.tcx.def_span(def_id).clean(cx),
name: Some(item.ident.clean(cx)),
attrs: cx.tcx.get_attrs(def_id).clean(cx),
inner: clean::ItemEnum::PrimitiveItem(clean::PrimitiveType::from(primitive)),
visibility: clean::Public,
stability: cx.tcx.lookup_stability(def_id).clean(cx),
deprecation: cx.tcx.lookup_deprecation(def_id).clean(cx),
def_id,
});
Copy link
Member

Choose a reason for hiding this comment

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

It might be better to synthesize a clean::Import here rather than trying to directly inline primitive types.

@ollie27
Copy link
Member

ollie27 commented Jan 26, 2020

I had a go at fixing this such that the re-exports show up as pub use bool; with working links: #68556

@bors bors closed this in edfa0f4 Jan 29, 2020
@GuillaumeGomez GuillaumeGomez deleted the reexport-primitive-panic branch February 10, 2020 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustdoc primitive re-export
5 participants