about summary refs log tree commit diff
path: root/src/librustdoc/passes
AgeCommit message (Collapse)AuthorLines
2020-10-08Allow generic parameters in intra-doc linksCamelid-1/+202
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-08Use the new module information for intra-doc linksJoshua Nelson-44/+66
- Make the parent module conditional on whether the docs are on a re-export - Make `resolve_link` take `&Item` instead of `&mut Item` Previously the borrow checker gave an error about multiple mutable borrows, because `dox` borrowed from `item`. - Fix `crate::` for re-exports `crate` means something different depending on where the attribute came from. - Make it work for `#[doc]` attributes too This required combining several attributes as one so they would keep the links.
2020-10-08Preserve the parent module of `DocFragment`sJoshua Nelson-4/+12
- Add `parent_module` to `DocFragment` - Require the `parent_module` of the item being inlined - Preserve the hir_id for ExternCrates so rustdoc can find the parent module later - Take an optional `parent_module` for `build_impl` and `merge_attrs`. Preserve the difference between parent modules for each doc-comment. - Support arbitrarily many re-exports in from_ast. In retrospect this is probably not used and could be simplified to a single `Option<(Attrs, DefId)>`. - Don't require the parent_module for all `impl`s, just inlined items In particular, this will be `None` whenever the attribute is not on a re-export. - Only store the parent_module, not the HirId When re-exporting a re-export, the HirId is not available. Fortunately, `collect_intra_doc_links` doesn't actually need all the info from a HirId, just the parent module.
2020-10-07Auto merge of #77119 - GuillaumeGomez:unclosed-html-tag-lint, r=jyn514bors-0/+195
Unclosed html tag lint Part of #67799. I think `@ollie27` will be interested (`@Manishearth` too since they opened the issue ;) ). r? `@jyn514`
2020-10-04Rollup merge of #77513 - jyn514:refactor-doc-fragments, r=GuillaumeGomezJonas Schievink-52/+24
Change DocFragments from enum variant fields to structs with a nested enum This makes the code a lot easier to work with. It also makes it easier to add new fields without updating each variant and `match` individually. - Name the `Kind` variant after `DocFragmentKind` from `collapse_docs` - Remove unneeded impls Progress towards https://github.com/rust-lang/rust/issues/77254. r? @GuillaumeGomez
2020-10-03Change DocFragments from enum variant fields to structs with a nested enumJoshua Nelson-52/+24
This makes the code a lot easier to work with. It also makes it easier to add new fields without updating each variant and `match` individually. - Name the `Kind` variant after `DocFragmentKind` from `collapse_docs` - Remove unneeded impls
2020-10-03Enforce closing HTML tags to have a ">" characterGuillaume Gomez-0/+20
2020-10-03Use char_indices() instead of chars() to prevent more than one-byte ↵Guillaume Gomez-16/+5
characters issue
2020-10-03Correctly handle unicode characters and tags being open just before the end ↵Guillaume Gomez-16/+42
of the doc comment
2020-10-03Don't warn if the tag is nested inside a <script> or inside a <style>Guillaume Gomez-1/+4
2020-10-03Improve codeGuillaume Gomez-7/+15
2020-10-03Fix visitor for invalid_html_tag lintGuillaume Gomez-2/+2
2020-10-03Make invalid_html_tags lint only run on nightly and being allowed by defaultGuillaume Gomez-4/+7
2020-10-03Improve invalid_html_tags lint spanGuillaume Gomez-41/+47
2020-10-03Add `unclosed_html_tags` lintGuillaume Gomez-0/+140
2020-10-02Improve error messagesCamelid-5/+4
2020-10-02Use old error when there's partial resolutionCamelid-5/+10
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-1/+2
2020-10-02Improve rustdoc error for failed intra-doc link resolutionCamelid-4/+4
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-09-29Auto merge of #77253 - jyn514:crate-link, r=Manishearthbors-1/+12
Resolve `crate` in intra-doc links properly across crates Closes https://github.com/rust-lang/rust/issues/77193; see https://github.com/rust-lang/rust/issues/77193#issuecomment-699065946 for an explanation of what's going on here. ~~This also fixes the BTreeMap docs that have been broken for a while; see the description on the second commit for why and how.~~ Nope, see the second commit for why the link had to be changed. r? `@Manishearth` cc `@dylni` `@dylni` note that this doesn't solve your original problem - now _both_ `with_code` and `crate::with_code` will be broken links. However this will fix a lot of other broken links (in particular I think https://docs.rs/sqlx/0.4.0-beta.1/sqlx/query/struct.Query.html is because of this bug). I'll open another issue for resolving additional docs in the new scope.
2020-09-27Resolve `crate` properly across cratesJoshua Nelson-1/+12
2020-09-27Separate `private_intra_doc_links` and `broken_intra_doc_links` into ↵Joshua Nelson-8/+13
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-231/+204
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-24Auto merge of #74430 - Manishearth:stabilize-intra-doc, r=Manishearthbors-8/+2
Stabilize intra-doc links Fixes https://github.com/rust-lang/rust/issues/43466 Thanks to the great work of `@jyn514` in getting the [cross-crate reexport issue](https://github.com/rust-lang/rust/issues/65983) in intra-rustdoc links fixed, I think we're now in a position to stabilize this feature. The tracking issue currently has two unresolved issues: - <s>behavior around doc(hidden): This is fixed in https://github.com/rust-lang/rust/pull/73365, which is just waiting for CI and should land tomorrow. It's also a pretty niche bug so while I expect it to land soon I don't think we need to block stabilization on it anyway.</s> - Non-identifier primitive types like slices: This was not a part of the original RFC anyway, and is a pretty niche use case The feature itself, sans https://github.com/rust-lang/rust/issues/65983, has been shipped on nightly for three years now, with people using it on docs.rs. https://github.com/rust-lang/rust/issues/65983 itself is not an overwhelmingly central bit of functionality; the reason we elected to block stabilization on it was that back in 2017 it was not possible to fix the issue without some major refactorings of resolve, and we did not want to stabilize something that had such a potentially unfixable bug. Given that we've fixed it, I see no reason to delay stabilization on this long awaited feature. It's possible that the latest patches have problems, however we _have_ done crater runs of some of the crucial parts. Furthermore, that's what the release trains are for, we will have a solid three months to let it ride the trains before it actually hits the stable compiler. r? `@rust-lang/rustdoc`
2020-09-23Unify primitive errors with other intra-link errorsJoshua Nelson-34/+14
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-6/+14
- 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-206/+191
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-10/+6
Do not lint ignored private doc tests Fixes #76457. r? @ehuss
2020-09-13Stabilize intra-doc linksManish Goregaokar-8/+2
2020-09-13Require `module_id` param to `resolve` to be non-emptyJoshua Nelson-295/+279
Previously, `resolve` would immediately check that `module_id` was non-empty and give an error if not. This had two downsides: - It introduced `Option`s everywhere, even if the calling function knew it had a valid module, and - It checked the module on each namespace, which is unnecessary: it only needed to be checked once. This makes the caller responsible for checking the module exists, making the code a lot simpler.
2020-09-13Refactor `resolve_with_disambiguator` into a separate functionJoshua Nelson-163/+190
2020-09-13Refactor `resolve_link` into a separate functionJoshua Nelson-325/+342
2020-09-12Don't emit an error on private doc tests when they're ignoredGuillaume Gomez-10/+6
2020-09-11Name the current moduleJoshua Nelson-2/+3
'not in scope' -> 'not in `module`'
2020-09-11Remove unnecessary cloneJoshua Nelson-7/+2
2020-09-11Use `span_label` instead of `note`Joshua Nelson-37/+47
This puts the error message closer to the link, making it easier to see what went wrong.
2020-09-11box ResolutionFailures on the heapJoshua Nelson-37/+32
This decreases the size of the `Result`s being returned, improving performance in the common case.
2020-09-05Find the first segment that failed to resolve for _any_ namespaceJoshua Nelson-45/+64
Moves this detection into `resolution_failure` to avoid doing unnecessary work and make the control flow a little easier to work with.
2020-09-05Give a much better error message when an item has a macro disambiguatorJoshua Nelson-30/+57
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-18/+39
This is both more specific and easier to read.
2020-09-05Don't suggest \[ \] if there's a :: in the pathJoshua Nelson-2/+7
2020-09-05Show the first path segment which failed to resolve.Joshua Nelson-5/+25
Before, it would arbitrarily pick the third-to-last if the last three or more did not resolve.
2020-09-05Address my own review commentsJoshua Nelson-3/+10
- Remove unneeded lifetime parameter - Comment why some code doesn't use `check_full_res`
2020-09-05Fix rebase conflictsJoshua Nelson-2/+2
2020-09-05Give a better error message when linking to a macro with the wrong disambiguatorJoshua Nelson-40/+79
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-51/+35
2020-09-05Turn NoParentItem from a panic into an ICEJoshua Nelson-3/+2
2020-09-05Fix failures to resolve primitivesJoshua Nelson-5/+15
Previously, when looking for the associated items for primitives, rustdoc would look for primitives in the current namespace. But all primitives are in the type namespace. To fix this, rustdoc now always looks for primitives in the namespace when considering them as a stepping stone to the associated item. However, fixing that bug caused several duplicate errors because rustdoc now reports the same error in each namespace. To avoid this, rustdoc now ignores all duplicate errors when issuing them.
2020-09-05Make errors more concise and helpfulJoshua Nelson-35/+60
Before: ``` = note: this link partially resolves to the struct `S` = note: no `fmt` in `S` ``` After: ``` = note: the struct `S` has no field or associated item named `fmt` ```
2020-09-05Remove some TODOsJoshua Nelson-2/+0