Skip to content
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

rustdoc type paths contain zero-width spaces #16555

Closed
SiegeLord opened this issue Aug 17, 2014 · 1 comment · Fixed by #16556
Closed

rustdoc type paths contain zero-width spaces #16555

SiegeLord opened this issue Aug 17, 2014 · 1 comment · Fixed by #16556

Comments

@SiegeLord
Copy link
Contributor

E.g. go to http://doc.rust-lang.org/std/option/type.Option.html and copy the path contained in: "Enum std​::option​::Option​". If you paste it into a Rust source file, you'll get an error along these lines:

<anon>:18:16: 18:17 error: unknown start of token: \u200b
<anon>:18         use std​::option​::Option​;

That character is the zero-width space.

This is highly inconvenient.

@bachm
Copy link

bachm commented Aug 17, 2014

As far as I can tell, they're all over the rust docs.

pczarn added a commit to pczarn/rust that referenced this issue Aug 17, 2014
Prevents zero-width spaces from appearing in copy-pasted paths.

Puts line breaks after `::`.

Fixes rust-lang#16555
bors added a commit that referenced this issue Aug 18, 2014
Prevents zero-width spaces from appearing in copy-pasted paths.

Fixes #16555
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 3, 2024
…-by-exploiting-orphan-rules, r=Veykril

performance: Speed up Method Completions By Taking Advantage of Orphan Rules

(Continues rust-lang/rust-analyzer#16498)

This PR speeds up method completions by doing two things without regressing `analysis-stats`[^1]:
- Filter candidate traits prior to calling `iterate_path_candidates` by relying on orphan rules (see below for a slightly more in-depth explanation). When generating completions [on `slog::Logger`](https://github.com/oxidecomputer/omicron/blob/5e9e59c312cd787ba50cf6776f220951917dfa14/common/src/ledger.rs#L78) in `oxidecomputer/omicron` as a test, this PR halved my completion times—it's now 454ms cold and 281ms warm. Before this PR, it was 808ms cold and 579ms warm.
- Inline some of the method candidate checks into `is_valid_method_candidate` and remove some unnecessary visibility checks. This was suggested by `@Veykril` in [this comment](rust-lang/rust-analyzer#16498 (comment)).

We filter candidate traits by taking advantage of orphan rules. For additional details, I'll rely on `@WaffleLapkin's` explanation  [from Zulip](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Trait.20Checking/near/420942417):

> A type `A` can only implements traits which
> 1. Have a blanket implementation (`impl<T> Trait for T {}`)
> 2. Have implementation for `A` (`impl Trait for A {}`)
>
> Blanket implementation can only exist in `Trait`'s crate. Implementation for `A` can only exist in `A`'s or `Trait`'s crate.

Big thanks to Waffle for its keen observation!

---

I think some additional improvements are possible:
- `for_trait_and_self_ty` seemingly does not distinguish between `&T`, `&mut T`, or `T`, resulting in seemingly irrelevant traits like `tokio::io::AsyncWrite` being being included for, e.g., `&slog::Logger`. I don't know they're being considered due to the [autoref/autoderef behavior](https://github.com/rust-lang/rust-analyzer/blob/a02a219773629686bd8ff123ca1aa995fa50d976/crates/hir-ty/src/method_resolution.rs#L945-L962), but I wonder if it'd make sense to filter by mutability earlier and not consider trait implementations that require `&mut T` when we only have a `&T`.
- The method completions [spend a _lot_ of time in unification](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Trait.20Checking/near/421072356), and while there might be low-hanging fruit there, it might make more sense to wait for the new trait solver in `rustc`. I dunno.

[^1]: The filtering occurs outside of typechecking, after all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants