Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup intra-doc link handling of
Self
- Remove the difference between `parent_item` and `current_item`; these should never have been different. - Remove `current_item` from `resolve` and `variant_field` so that `Self` is only substituted in one place at the very start. - Resolve the current item as a `DefId`, not a `HirId`. This allows using `Self` across crates. Hacks: - `clean` uses `TypedefItem` when it _really_ should be `AssociatedTypeItem`. I tried fixing this without success and hacked around it instead (see comments) - This doesn't replace `Self` if there's no parent for the current item. In theory this should be possible, but it caused panics when I tried to implement it. - This replaces `Self` in the _displayed_ text, not just when resolving. This should probably be fixed, but it was an existing issue so I didn't fix it here. - Use `Res` instead of strings for associated items The main idea is to, if given a `Self` type, skip over all the logic to find the root type and go straight to resolving the associated item. Everything else is just refactors to make implementing that possible. + Switch to using `Res` instead of a string for `resolve_associated_item` + Use a `Res` instead of a string for `variant_field` + Remove `self_name` + If given a `Self` type, skip over all the logic to find the root type and go straight to resolving the associated item + Give a more helpful error if there's no `Self` type in scope + Fix broken `all_fields()` logic - it should have been checking enum variants instead - Handle primitives in `resolve_associated_item` This does _not_ fix `Self` on primitives because it doesn't have a way to go from the `DefId` of a lang_item to the corresponding `PrimTy`. However once that's fixed, this fix will be necessary. - Ignore broken test for primitives - Fix small bug with variant fields Previously, they would be resolved as `DefKind::Variant`, and since they resolved successfully, passed through to `resolve_associated_item`. Then, if resolve_associated_item couldn't handle them, it would pass `path_str` to `variant_field`. But after my change, it no longer had access to `path_str` - all it had was `item_str`, which is only one path segment long. So it would never resolve through `variant_field`. Instead, skip straight to `variant_field` if the path resolved to a variant. - Don't resolve `variant_field` in more than one place Now that `resolve` handles it, `resolve_associated_item` doesn't need to. - Add test for unresolved `Self`
- Loading branch information