-
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
Remove unnecessary Option
wrapping around Crate.module
#83415
Changes from all commits
72a180e
c9ae359
68244fc
a7f902b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use rustc_middle::ty::TyCtxt; | ||
use rustc_span::edition::Edition; | ||
use rustc_span::{edition::Edition, Symbol}; | ||
|
||
use crate::clean; | ||
use crate::config::RenderOptions; | ||
|
@@ -40,7 +40,7 @@ crate trait FormatRenderer<'tcx>: Sized { | |
/// A handler is available if the renderer wants to report errors. | ||
fn after_krate( | ||
&mut self, | ||
krate: &clean::Crate, | ||
crate_name: Symbol, | ||
diag: &rustc_errors::Handler, | ||
) -> Result<(), Error>; | ||
|
||
|
@@ -58,21 +58,15 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>( | |
) -> Result<(), Error> { | ||
let prof = &tcx.sess.prof; | ||
|
||
let (mut format_renderer, mut krate) = prof | ||
let (mut format_renderer, krate) = prof | ||
.extra_verbose_generic_activity("create_renderer", T::descr()) | ||
.run(|| T::init(krate, options, edition, cache, tcx))?; | ||
|
||
let mut item = match krate.module.take() { | ||
Some(i) => i, | ||
None => return Ok(()), | ||
}; | ||
|
||
item.name = Some(krate.name); | ||
|
||
// Render the crate documentation | ||
let mut work = vec![(format_renderer.make_child_renderer(), item)]; | ||
let crate_name = krate.name; | ||
let mut work = vec![(format_renderer.make_child_renderer(), krate.module)]; | ||
|
||
let unknown = rustc_span::Symbol::intern("<unknown item>"); | ||
let unknown = Symbol::intern("<unknown item>"); | ||
while let Some((mut cx, item)) = work.pop() { | ||
if item.is_mod() { | ||
// modules are special because they add a namespace. We also need to | ||
|
@@ -102,5 +96,5 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>( | |
} | ||
} | ||
prof.extra_verbose_generic_activity("renderer_after_krate", T::descr()) | ||
.run(|| format_renderer.after_krate(&krate, diag)) | ||
.run(|| format_renderer.after_krate(crate_name, diag)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It took me a second to realize: the reason this changed is because you partially moved out of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I mentioned that in the PR description:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right - that explains that it's possible, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I should've included more information :) |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,12 +131,8 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate { | |
} | ||
} | ||
|
||
let items = if let Some(ref mut it) = krate.module { | ||
if let ModuleItem(Module { ref mut items, .. }) = *it.kind { | ||
items | ||
} else { | ||
panic!("collect-trait-impls can't run"); | ||
} | ||
let items = if let ModuleItem(Module { ref mut items, .. }) = *krate.module.kind { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like a future enhancement could be to store a |
||
items | ||
} else { | ||
panic!("collect-trait-impls can't run"); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// check-pass | ||
|
||
//! [my_module] | ||
//~^ WARN public documentation for `private_from_crate_level` links to private item `my_module` | ||
|
||
mod my_module {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
warning: public documentation for `private_from_crate_level` links to private item `my_module` | ||
--> $DIR/private-from-crate-level.rs:3:6 | ||
| | ||
LL | //! [my_module] | ||
| ^^^^^^^^^ this item is private | ||
| | ||
= note: `#[warn(rustdoc::private_intra_doc_links)]` on by default | ||
= note: this link will resolve properly if you pass `--document-private-items` | ||
|
||
warning: 1 warning emitted | ||
|
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.
Is there ever a case where this
unwrap
will fail? Why doesfold_item
return anOption
anyway?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.
fold_item
returnsNone
if the itme was stripped. I don't think the whole crate can be stripped so this should be fine.