-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fix panic when reexporting primitive type in rustdoc #67972
Conversation
The job Click to expand the log.
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 |
ed564b2
to
18d211e
Compare
No, I think that's not quite expected behavior, if I'm following you correctly. I would be fine with either |
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. |
It is definitely useful, see the PR that brought this up - #67637. |
Damn it, that's a good point! Ok, adding it... |
It now appears in the documentation as well. |
There was a problem hiding this 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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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!()).
The job Click to expand the log.
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 |
I don't think that the primitive type docs should be inlined into the |
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). |
I can link to std directly if you prefer? |
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. |
So what should I do? Link to core or to std? :) |
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 Does that sound reasonable? |
What about the primitive types that can't be reexported in |
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 |
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; | ||
} |
There was a problem hiding this comment.
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;
}
}
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, | ||
}); |
There was a problem hiding this comment.
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.
I had a go at fixing this such that the re-exports show up as |
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