about summary refs log tree commit diff
path: root/src/test/rustdoc-ui
AgeCommit message (Collapse)AuthorLines
2020-10-10Apply suggestions from code reviewDániel Buga-1/+20
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-10-10Auto merge of #76934 - camelid:rustdoc-allow-generic-params, r=jyn514bors-1/+122
Allow generic parameters in intra-doc links Fixes #62834. --- The contents of the generics will be mostly ignored (except for warning if fully-qualified syntax is used, which is currently unsupported in intra-doc links - see issue #74563). * Allow links like `Vec<T>`, `Result<T, E>`, and `Option<Box<T>>` * Allow links like `Vec::<T>::new()` * Warn on * Unbalanced angle brackets (e.g. `Vec<T` or `Vec<T>>`) * Missing type to apply generics to (`<T>` or `<Box<T>>`) * Use of fully-qualified syntax (`<Vec as IntoIterator>::into_iter`) * Invalid path separator (`Vec:<T>:new`) * Too many angle brackets (`Vec<<T>>`) * Empty angle brackets (`Vec<>`) Note that this implementation *does* allow some constructs that aren't valid in the actual Rust syntax, for example `Box::<T>new()`. That may not be supported in rustdoc in the future; it is an implementation detail.
2020-10-09Remove unneeded ImportItem on glob onesGuillaume Gomez-13/+2
2020-10-09Add test to ensure that external items aren't lint-checkedGuillaume Gomez-2/+14
2020-10-09Add test for reexported items lintsGuillaume Gomez-0/+31
2020-10-08Allow generic parameters in intra-doc linksCamelid-1/+122
The contents of the generics will be mostly ignored (except for warning if fully-qualified syntax is used, which is currently unsupported in intra-doc links - see issue #74563). * Allow links like `Vec<T>`, `Result<T, E>`, and `Option<Box<T>>` * Allow links like `Vec::<T>::new()` * Warn on * Unbalanced angle brackets (e.g. `Vec<T` or `Vec<T>>`) * Missing type to apply generics to (`<T>` or `<Box<T>>`) * Use of fully-qualified syntax (`<Vec as IntoIterator>::into_iter`) * Invalid path separator (`Vec:<T>:new`) * Too many angle brackets (`Vec<<T>>`) * Empty angle brackets (`Vec<>`) Note that this implementation *does* allow some constructs that aren't valid in the actual Rust syntax, for example `Box::<T>new()`. That may not be supported in rustdoc in the future; it is an implementation detail.
2020-10-07Auto merge of #77119 - GuillaumeGomez:unclosed-html-tag-lint, r=jyn514bors-1/+180
Unclosed html tag lint Part of #67799. I think `@ollie27` will be interested (`@Manishearth` too since they opened the issue ;) ). r? `@jyn514`
2020-10-06Enforce whitespace ascii character check for doc aliasGuillaume Gomez-1/+15
2020-10-05Allow ascii whitespace char for doc aliasesGuillaume Gomez-9/+2
2020-10-05Rollup merge of #76329 - GuillaumeGomez:doc-alias-crate-level, r=matthewjasperDylan DPC-0/+20
Add check for doc alias attribute at crate level Fixes #76298, #64734, #69365. r? @ollie27
2020-10-04Enforce crate level attributes checksGuillaume Gomez-4/+13
2020-10-04Rollup merge of #77469 - camelid:rustdoc-better-failed-res-error, r=jyn514Yuki Okushi-35/+35
Improve rustdoc error for failed intra-doc link resolution The previous error was confusing since it made it sound like you can't link to items that are defined outside the current module. Also suggested importing the item. r? @jyn514
2020-10-03Add test for #[doc(alias = "...")] at crate levelGuillaume Gomez-0/+11
2020-10-03Enforce closing HTML tags to have a ">" characterGuillaume Gomez-2/+14
2020-10-03Use char_indices() instead of chars() to prevent more than one-byte ↵Guillaume Gomez-32/+38
characters issue
2020-10-03Correctly handle unicode characters and tags being open just before the end ↵Guillaume Gomez-13/+30
of the doc comment
2020-10-03Don't warn if the tag is nested inside a <script> or inside a <style>Guillaume Gomez-0/+22
2020-10-03Add test for invalid_html_tag lint in deny(rustdoc)Guillaume Gomez-1/+25
2020-10-03Improve codeGuillaume Gomez-6/+43
2020-10-03Improve invalid_html_tags lint spanGuillaume Gomez-41/+28
2020-10-03Add test for unclosed_html_tag lintGuillaume Gomez-65/+89
2020-10-03Add `unclosed_html_tags` lintGuillaume Gomez-5/+55
2020-10-02Improve error messagesCamelid-35/+35
2020-10-02Use old error when there's partial resolutionCamelid-4/+4
The new error was confusing when there was partial resolution (something like `std::io::nonexistent`); the old one is better for those cases.
2020-10-02Remove unhelpful help messageCamelid-63/+19
2020-10-02Improve rustdoc error for failed intra-doc link resolutionCamelid-54/+98
The previous error was confusing since it made it sound like you can't link to items that are defined outside the current module. Also suggested importing the item.
2020-10-02Rollup merge of #76811 - GuillaumeGomez:doc-alias-name-restriction, ↵Jonas Schievink-1/+39
r=oli-obk,ollie27 Doc alias name restriction Fixes #76705.
2020-10-02Update testsGuillaume Gomez-1/+39
2020-09-27Separate `private_intra_doc_links` and `broken_intra_doc_links` into ↵Joshua Nelson-4/+4
separate lints This is not ideal because it means `deny(broken_intra_doc_links)` will no longer `deny(private_intra_doc_links)`. However, it can't be fixed with a new lint group, because `broken` is already in the `rustdoc` lint group; there would need to be a way to nest groups somehow. This also removes the early `return` so that the link will be generated even though it gives a warning.
2020-09-27Auto merge of #76955 - jyn514:refactor-diagnostics, r=eucliobors-48/+92
Refactor and fix intra-doc link diagnostics, and fix links to primitives Closes https://github.com/rust-lang/rust/issues/76925, closes https://github.com/rust-lang/rust/issues/76693, closes https://github.com/rust-lang/rust/issues/76692. Originally I only meant to fix #76925. But the hack with `has_primitive` was so bad it was easier to fix the primitive issues than to try and work around it. Note that this still has one bug: `std::primitive::i32::MAX` does not resolve. However, this fixes the ICE so I'm fine with fixing the link in a later PR. This is part of a series of refactors to make #76467 possible. This is best reviewed commit-by-commit; it has detailed commit messages. r? `@euclio`
2020-09-25Move from {{closure}}#0 syntax to {closure#0} for (def) path componentsmarmeladema-1/+1
2020-09-23Unify primitive errors with other intra-link errorsJoshua Nelson-8/+32
Now that `PrimTy::name()` exists, there's no need to carry around the name of the primitive that failed to resolve. This removes the variants special-casing primitives in favor of `NotResolved`. - Remove `NoPrimitiveImpl` and `NoPrimitiveAssocItem` - Remove hacky `has_primitive` check in `resolution_failure()` - Fixup a couple tests that I forgot to `--bless` before
2020-09-23Fix intra-doc links for primitivesJoshua Nelson-4/+1
- Add `PrimTy::name` and `PrimTy::name_str` - Use those new functions to distinguish between the name in scope and the canonical name - Fix diagnostics for primitive types - Add tests for primitives
2020-09-23Perform most diagnostic lookups in `resolution_failure`Joshua Nelson-47/+70
Previously, these were spread throughout the codebase. This had two drawbacks: 1. It caused the fast path to be slower: even if a link resolved, rustdoc would still perform various lookups for the error diagnostic. 2. It was inconsistent and didn't always give all diagnostics (https://github.com/rust-lang/rust/issues/76925) Now, diagnostics only perform expensive lookups in the error case. Additionally, the error handling is much more consistent, both in wording and behavior. - Remove `CannotHaveAssociatedItems`, `NotInScope`, `NoAssocItem`, and `NotAVariant` in favor of the more general `NotResolved` `resolution_failure` will now look up which of the four above categories is relevant, instead of requiring the rest of the code to be consistent and accurate in which it picked. - Remove unnecessary lookups throughout the intra-doc link pass. These are now done by `resolution_failure`. + Remove unnecessary `extra_fragment` argument to `variant_field()`; it was only used to do lookups on failure. + Remove various lookups related to associated items + Remove distinction between 'not in scope' and 'no associated item' - Don't perform unnecessary copies - Remove unused variables and code - Update tests - Note why looking at other namespaces is still necessary - 'has no inner item' -> 'contains no item' bless tests
2020-09-16Rollup merge of #76642 - GuillaumeGomez:ignored-private-doc-test, r=jyn514Tyler Mandry-2/+14
Do not lint ignored private doc tests Fixes #76457. r? @ehuss
2020-09-13Don't use `link.span` yetJoshua Nelson-2/+2
This shows the span of the _whole_ link, including the brackets. But rustdoc only wants to warn about the link text.
2020-09-13Upgrade to pulldown-cmark 0.8.0Joshua Nelson-0/+17
Thanks to marcusklaas' hard work in https://github.com/raphlinus/pulldown-cmark/pull/469, this fixes a lot of rustdoc bugs! - Get rid of unnecessary `RefCell` - Fix duplicate warnings for broken implicit reference link - Remove unnecessary copy of links
2020-09-12Add test for ignored private doc testGuillaume Gomez-2/+14
2020-09-12Auto merge of #75756 - jyn514:diagnostic-suggestions, r=estebankbors-115/+267
Improve suggestions for broken intra-doc links ~~Depends on #74489 and should not be merged before that PR.~~ Merged 🎉 ~~Depends on #75916 and should not be merged before.~~ Merged Fixes https://github.com/rust-lang/rust/issues/75305. This does a lot of different things 😆. - Add `PerNS::into_iter()` so I didn't have to keep rewriting hacks around it. Also add `PerNS::iter()` for consistency. Let me know if this should be `impl IntoIterator` instead. - Make `ResolutionFailure` an enum instead of a unit variant. This was most of the changes: everywhere that said `ErrorKind::ResolutionFailure` now has to say _why_ the link failed to resolve. - Store the resolution in case of an anchor failure. Previously this was implemented as variants on `AnchorFailure` which was prone to typos and had inconsistent output compared to the rest of the diagnostics. - Turn some `Err`ors into unwrap() or panic()s, because they're rustdoc bugs and not user error. These have comments as to why they're bugs (in particular this would have caught #76073 as a bug a while ago). - If an item is not in scope at all, say the first segment in the path that failed to resolve - If an item exists but not in the current namespaces, say that and suggests linking to that namespace. - If there is a partial resolution for an item (part of the segments resolved, but not all of them), say the partial resolution and why the following segment didn't resolve. - Add the `DefId` of associated items to `kind_side_channel` so it can be used for diagnostics (tl;dr of the hack: the rest of rustdoc expects the id of the item, but for diagnostics we need the associated item). - No longer suggests escaping the brackets for every link that failed to resolve; this was pretty obnoxious. Now it only suggests `\[ \]` if no segment resolved and there is no `::` in the link. - Add `Suggestion`, which says _what_ to prefix the link with, not just 'prefix with the item kind'. Places where this is currently buggy: <details><summary>All outdated</summary> ~~1. When the link has the wrong namespace:~~ Now fixed. <details> ```rust /// [type@S::h] impl S { pub fn h() {} } /// [type@T::g] pub trait T { fn g() {} } ``` ``` error: unresolved link to `T::g` --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:53:6 | 53 | /// [type@T::g] | ^^^^^^^^^ | = note: this link partially resolves to the trait `T`, = note: `T` has no field, variant, or associated item named `g` error: unresolved link to `S::h` --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:48:6 | 48 | /// [type@S::h] | ^^^^^^^^^ | = note: this link partially resolves to the struct `S`, = note: `S` has no field, variant, or associated item named `h` ``` Instead it should suggest changing the disambiguator, the way it currently does for macros: ``` error: unresolved link to `S` --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:38:6 | 38 | /// [S!] | ^^ help: to link to the unit struct, use its disambiguator: `value@S` | = note: this link resolves to the unit struct `S`, which is not in the macro namespace ``` </details> 2. ~~Associated items for values. It says that the value isn't in scope; instead it should say that values can't have associated items.~~ Fixed. <details> ``` error: unresolved link to `f::A` --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:14:6 | 14 | /// [f::A] | ^^^^ | = note: no item named `f` is in scope = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` ``` This is _mostly_ fixed, it now says ```rust warning: unresolved link to `f::A` --> /home/joshua/test-rustdoc/f.rs:1:6 | 1 | /// [f::A] | ^^^^ | = note: this link partially resolves to the function `f` = note: `f` is a function, not a module ``` 'function, not a module' seems awfully terse when what I actually mean is '`::` isn't allowed here', though. </details> It looks a lot nicer now, it says ``` error: unresolved link to `f::A` --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:13:6 | 13 | /// [f::A] | ^^^^ | = note: `f` is a function, not a module or type, and cannot have associated items ``` 3. ~~I'm also not very happy with the second note for this error:~~ <details> ``` error: unresolved link to `S::A` --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:19:6 | 19 | /// [S::A] | ^^^^ | = note: this link partially resolves to the struct `S`, = note: `S` has no field, variant, or associated item named `A` ``` but I'm not sure how better to word it. I ended up going with 'no `A` in `S`' to match `rustc_resolve` but that seems terse as well. </details> This now says ``` error: unresolved link to `S::A` --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:17:6 | 17 | /// [S::A] | ^^^^ | = note: the struct `S` has no field or associated item named `A` ``` which I think looks pretty good :) 4. This is minor, but it would be nice to say that `path` wasn't found instead of the full thing: ``` error: unresolved link to `path::to::nonexistent::module` --> /home/joshua/rustc/src/test/rustdoc-ui/intra-link-errors.rs:8:6 | 8 | /// [path::to::nonexistent::module] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` It will now look at most 3 paths up (so it reports `path::to` as not in scope), but it doesn't work with arbitrarily many paths. </details> ~~I recommend only reviewing the last few commits - the first 7 are all from #74489.~~ Rebased so that only the relevant commits are shown. Let me know if I should squash the history some more. r? `@estebank`
2020-09-11Name the current moduleJoshua Nelson-82/+58
'not in scope' -> 'not in `module`'
2020-09-11Use `span_label` instead of `note`Joshua Nelson-41/+18
This puts the error message closer to the link, making it easier to see what went wrong.
2020-09-07Make rustdoc output deterministic for UI testsJoshua Nelson-1/+1
2020-09-05Find the first segment that failed to resolve for _any_ namespaceJoshua Nelson-14/+38
Moves this detection into `resolution_failure` to avoid doing unnecessary work and make the control flow a little easier to work with.
2020-09-05x.py blessJoshua Nelson-14/+14
2020-09-05Give a much better error message when an item has a macro disambiguatorJoshua Nelson-2/+2
Previously, this called `check_full_res` for values and types, but not macros. This would result in not showing when there was a partial resolution for a parent of the item. This now calls `check_full_res`. Additionally, it checks if there was a disambiguator, and if so, says that specific kind wasn't found instead of saying generically 'associated item'.
2020-09-05 Say 'prefix with `kind@`' instead of 'prefix with the item kind'Joshua Nelson-82/+34
This is both more specific and easier to read.
2020-09-05Don't suggest \[ \] if there's a :: in the pathJoshua Nelson-22/+13
2020-09-05Show the first path segment which failed to resolve.Joshua Nelson-8/+11
Before, it would arbitrarily pick the third-to-last if the last three or more did not resolve.
2020-09-05Give a better error message when linking to a macro with the wrong disambiguatorJoshua Nelson-10/+63
Before: ``` warning: unresolved link to `m` --> m.rs:1:6 | 1 | /// [value@m] | ^^^^^^^ | = note: `#[warn(broken_intra_doc_links)]` on by default = note: no item named `m` is in scope = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` ``` After: ``` warning: unresolved link to `m` --> m.rs:1:6 | 1 | /// [value@m] | ^^^^^^^ help: to link to the macro, use its disambiguator: `m!` | = note: `#[warn(broken_intra_doc_links)]` on by default = note: this link resolves to the macro `m`, which is not in the value namespace ```
2020-09-05Use rustc_resolve's descr() instead of rewriting itJoshua Nelson-3/+3