-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Create Item::full_name method to include name of reexports #96864
Conversation
Some changes occurred in cc @camelid |
This sounds like a good idea to me. |
Except that in some cases, we filter on |
Where and why is that done? If it's for the search index, maybe a method returning bool could be added just for that. |
If an |
It seems like there should be a function whose job is just to determine whether something gets its own page or not, separately from the considering whether something has a name or not. After all, there are multiple considerations that go into this:
The question of whether something gets a page is a "responsibility," in the SRP sense. I really don't want to be tweaking the logic behind the |
With this, reexports should get their own page since they are direct descendant of a module (the reexport itself). |
The point I’m trying to make is to distill the logic behind whether something gets its own page. Right now, this logic is spread out all over the codebase. We barely even have a name for this! In pseudo-rust, here’s that bulleted list: fn has_page(self: &Item) -> bool {
if self.full_name().is_none() { return false }
if self.parent_item().is_mod() { return false }
if self.is_use() { return false }
true
} |
Hum... I could write a function which handles that I guess. That'd be interesting. :) |
Of course, we should get @camelid's input on all this, too. |
Absolutely! Let's wait for them then. |
Sorry, I didn't realize you were waiting on me! I've been busier with other stuff recently. What is it that you wanted my feedback on? |
We wanted your opinion on "should we add a method which returns |
☔ The latest upstream changes (presumably #97239) made this pull request unmergeable. Please resolve the merge conflicts. |
b6cdfba
to
41db4ec
Compare
Fixed merge conflict. |
My opinion is that sounds like a great idea. @notriddle's pseudo-Rust at #96864 (comment) looks like a good approach. My only question is with this part, which seems incorrect: if self.parent_item().is_mod() { return false } Is that supposed to be |
pub(crate) fn full_name(&self) -> Option<Symbol> { | ||
self.name.or_else(|| { | ||
if let ImportItem(ref i) = *self.kind && | ||
let ImportKind::Simple(s) = i.kind { Some(s) } else { 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.
Does s
refer to the y
or the x
in pub use x as y;
?
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.
Yes. Simple
is created with new_simple
which returns an Import
. The Import
struct contains the source
(so x
in this case) and the kind (our Simple("y")
).
Sorry. That should have been Only the children of modules get their own page, because only modules get their own directory to put stuff in. |
So currently, the filtering of which item should get its own page is here. Another place is in print_sidebar. The last place being here. In all cases, we need to check the item to call the correct function. I can eventually centralize it with a function taking a callback, but I'm not sure we can do much better. At least the logic would be in one place only. What do you think? EDIT: as for the pub(crate) fn is_parent_a_mod(&self) -> bool {
let def_id = match self.item_id {
DefId(def_id) => def_id,
Auto { .. } | Blanket { .. } => return true,
ItemId::Primitive(_, _) => return false,
};
if let Some(def_id) = def_id.as_local() {
let hir = tcx.hir();
let parent_def_id = hir.get_parent_item(hir.local_def_id_to_hir_id(def_id));
matches!(hir.opt_def_kind(parent_def_id), Some(DefKind::Mod))
} else {
false
}
}
pub(crate) fn has_page(&self, tcx: TyCtxt<'_>) -> bool {
!self.is_stripped() && !self.is_import() && parent.is_mod() && self.full_name().is_some()
} |
☔ The latest upstream changes (presumably #106866) made this pull request unmergeable. Please resolve the merge conflicts. |
It's been a while - @GuillaumeGomez are you planning to follow up on this? |
No I don't, or at least not before long. Closing then. |
I originally wanted to make
Item::name
field private and implementfull_name
asname
replacement directly. Not sure if it's a good idea though. What do you think?cc @camelid
r? @notriddle