Uh oh!
There was an error while loading. Please reload this page.
Create Item::full_name method to include name of reexports - #96864
Create Item::full_name method to include name of reexports#96864GuillaumeGomez wants to merge 1 commit into
Conversation
rust-highfive
commented
May 9, 2022
Some changes occurred in cc @camelid |
notriddle
commented
May 9, 2022
This sounds like a good idea to me. |
GuillaumeGomez
commented
May 9, 2022
Except that in some cases, we filter on |
notriddle
commented
May 9, 2022
Where and why is that done? If it's for the search index, maybe a method returning bool could be added just for that. |
GuillaumeGomez
commented
May 9, 2022
If an |
notriddle
commented
May 9, 2022
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 |
GuillaumeGomez
commented
May 9, 2022
With this, reexports should get their own page since they are direct descendant of a module (the reexport itself). |
notriddle
commented
May 9, 2022
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: fnhas_page(self:&Item) -> bool{ifself.full_name().is_none(){returnfalse}ifself.parent_item().is_mod(){returnfalse}ifself.is_use(){returnfalse}true} |
GuillaumeGomez
commented
May 9, 2022
Hum... I could write a function which handles that I guess. That'd be interesting. :) |
notriddle
commented
May 9, 2022
Of course, we should get @camelid's input on all this, too. |
GuillaumeGomez
commented
May 9, 2022
Absolutely! Let's wait for them then. |
camelid
commented
May 20, 2022
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? |
GuillaumeGomez
commented
May 20, 2022
We wanted your opinion on "should we add a method which returns |
bors
commented
May 21, 2022
☔ The latest upstream changes (presumably #97239) made this pull request unmergeable. Please resolve the merge conflicts. |
b6cdfba to
41db4ecCompareGuillaumeGomez
commented
May 21, 2022
Fixed merge conflict. |
camelid
commented
May 26, 2022
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: ifself.parent_item().is_mod(){returnfalse}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.
Does s refer to the y or the x in pub use x as y;?
There was a problem hiding this comment.
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")).
notriddle
commented
May 26, 2022
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)fnis_parent_a_mod(&self) -> bool{let def_id = matchself.item_id{DefId(def_id) => def_id,Auto{ .. } | Blanket{ .. } => returntrue,ItemId::Primitive(_, _) => returnfalse,};ifletSome(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)fnhas_page(&self,tcx:TyCtxt<'_>) -> bool{
!self.is_stripped() && !self.is_import() && parent.is_mod() && self.full_name().is_some()} |
bors
commented
Jan 15, 2023
☔ The latest upstream changes (presumably #106866) made this pull request unmergeable. Please resolve the merge conflicts. |
jyn514
commented
Apr 27, 2023
It's been a while - @GuillaumeGomez are you planning to follow up on this? |
GuillaumeGomez
commented
Apr 27, 2023
No I don't, or at least not before long. Closing then. |
I originally wanted to make
Item::namefield private and implementfull_nameasnamereplacement directly. Not sure if it's a good idea though. What do you think?cc @camelid
r? @notriddle