Perform most diagnostic lookups in resolution_failure

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
This commit is contained in:
Joshua Nelson 2020-09-20 00:32:00 -04:00
parent cbc5e4d4d5
commit dd7b8c85a6
9 changed files with 263 additions and 253 deletions

View file

@ -6,19 +6,23 @@
/// [path::to::nonexistent::module]
//~^ ERROR unresolved link
//~| NOTE no item named `path` in `intra_link_errors`
//~| NOTE `intra_link_errors` contains no item named `path`
/// [path::to::nonexistent::macro!]
//~^ ERROR unresolved link
//~| NOTE no item named `path` in `intra_link_errors`
//~| NOTE `intra_link_errors` contains no item named `path`
/// [type@path::to::nonexistent::type]
//~^ ERROR unresolved link
//~| NOTE no item named `path` in `intra_link_errors`
//~| NOTE `intra_link_errors` contains no item named `path`
/// [std::io::not::here]
//~^ ERROR unresolved link
//~| NOTE the module `io` has no inner item
//~| NOTE `io` contains no item named `not`
/// [type@std::io::not::here]
//~^ ERROR unresolved link
//~| NOTE `io` contains no item named `not`
/// [std::io::Error::x]
//~^ ERROR unresolved link
@ -32,6 +36,10 @@
//~^ ERROR unresolved link
//~| NOTE `f` is a function, not a module
/// [f::A!]
//~^ ERROR unresolved link
//~| NOTE `f` is a function, not a module
/// [S::A]
//~^ ERROR unresolved link
//~| NOTE struct `S` has no field or associated item