3

[rustdoc] List matching impls on type aliases by GuillaumeGomez · Pull Request #...

 1 year ago
source link: https://github.com/rust-lang/rust/pull/112429
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

This comment has been minimized.

fn render_assoc_items_inner(

mut w: &mut dyn fmt::Write,

cx: &mut Context<'_>,

containing_item: &clean::Item,

it: DefId,

what: AssocItemRender<'_>,

derefs: &mut DefIdSet,

aliased_type: Option<DefId>,

Contributor

I'm sure threading this parameter through all these function calls is probably cheaper than using let is_alias = tcx.def_kind(it) == DefKind::TyAlias and using let aliased_type = tcx.type_of(it) to resolve it, since the calling functions already have this information.

But is pulling the information out of TyCtxt expensive enough to be worth having a function with seven parameters?

Member

Author

We need a variable to tell us that this is an alias. From this, since we already have the DefId, why not using it directly?

EDIT: Just re-read your comment. I'm not sure to like it much simply because we re-compute an information we already have. But that's pretty much my only argument against it. ^^'

Member

Author

I edited my comment, I don't know how but I misread your comment the first time. Sorry about that.

Contributor

There's not a lot of computation going into it, though. It's looking information up in a hash table.

It's not the part worrying me but since I can't put the finger on it, I'll just remove the newly added argument and let's see how it goes. :)

Ah found it! I need it because of Some(aliased_type) => cache.impls.get(&aliased_type).unwrap_or(&empty),. We can't retrieve the DefId easily from a Ty. The only method I found to get it is ty_adt_id but it doesn't cover all the cases we need.

Contributor

That makes sense. Thanks for the info!

Contributor

Having aliased_type separately here feels off to me and may at least deserve a comment, but that's unrelated to the type system itself so I am fine with that.

The doc comment for aliased_type is already on the function. ;)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK