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: Referencing methods on extern_types does not resolve #78777

Closed
crumblingstatue opened this issue Nov 5, 2020 · 3 comments · Fixed by #79182 or #79273
Closed

rustdoc: Referencing methods on extern_types does not resolve #78777

crumblingstatue opened this issue Nov 5, 2020 · 3 comments · Fixed by #79182 or #79273
Assignees
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@crumblingstatue
Copy link
Contributor

I tried this code:

#![feature(extern_types)]

extern {
    /// The extern type Foo.
    pub type Foo;
}

/// The struct Bar.
pub struct Bar;

impl Foo {
    /// Does stuff
    pub fn do_it(&self) {

    }
}

impl Bar {
    /// This does stuff too
    pub fn do_it(&self) {

    }
}

/// See also [Foo::do_it]
pub fn foo() {

}

/// See also [Bar::do_it]
pub fn bar() {

}

I expected to see this happen: Both Foo::do_it and Bar::do_it resolve.

Instead, this happened: Only Bar::do_it resolves.

warning: unresolved link to `Foo::do_it`
  --> src/lib.rs:25:15
   |
25 | /// See also [Foo::do_it]
   |               ^^^^^^^^^^ the foreign type `Foo` has no associated item named `do_it`

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
binary: rustc
commit-hash: ffa2e7ae8fbf9badc035740db949b9dae271c29f
commit-date: 2020-10-24
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0
@crumblingstatue crumblingstatue added the C-bug Category: This is a bug. label Nov 5, 2020
@jonas-schievink jonas-schievink added A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Nov 5, 2020
@jyn514
Copy link
Member

jyn514 commented Nov 5, 2020

Mentoring instructions: in

Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::TyAlias, did) => {

instead of checking specific DefKinds one at a time, look to see if they're in the TypeNS. You can check with kind.ns() == Some(TypeNS).

@jyn514 jyn514 added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Nov 5, 2020
@lochsh
Copy link
Contributor

lochsh commented Nov 8, 2020

I'll have a crack at this if no one is working on it -- I'm a first-time contributor but the mentoring instructions look like enough to be getting on with 👍

@jyn514
Copy link
Member

jyn514 commented Nov 8, 2020

@lochsh awesome! There's instructions for getting started on https://rustc-dev-guide.rust-lang.org/, and you can ask in the Rustdoc Discord channel if you need help.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 21, 2020
…r=jyn514

Fix links to extern types in rustdoc (fixes rust-lang#78777)

 r? `@jyn514`
 Fixes rust-lang#78777.
The initial fix we tried was:
```diff
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs
index 8be9482acff..c4b7086fdb1 100644
--- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
`@@` -433,8 +433,9 `@@` impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
             Res::PrimTy(prim) => Some(
                 self.resolve_primitive_associated_item(prim, ns, module_id, item_name, item_str),
             ),
-            Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::TyAlias, did) => {
+            Res::Def(kind, did) if kind.ns() == Some(Namespace::TypeNS) => {
                 debug!("looking for associated item named {} for item {:?}", item_name, did);
+
                 // Checks if item_name belongs to `impl SomeItem`
                 let assoc_item = cx
                     .tcx
```

However, this caused traits to be matched, resulting in a panic when `resolve_associated_trait_item` is called further down in this function.

This PR also adds an error message for that panic. Currently it will look something like:
```rust
thread 'rustc' panicked at 'Not a type: DefIndex(8624)', compiler/rustc_metadata/src/rmeta/decoder.rs:951:32
```
I wasn't sure how to get a better debug output than `DefIndex(...)`, and am open to suggestions.
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 21, 2020
Rollup of 8 pull requests

Successful merges:

 - rust-lang#77844 (clarify rules for ZST Boxes)
 - rust-lang#79067 (Refactor the abi handling code a bit)
 - rust-lang#79182 (Fix links to extern types in rustdoc (fixes rust-lang#78777))
 - rust-lang#79231 (Exhaustively match in variant count instrinsic)
 - rust-lang#79238 (Direct RUSTC_LOG (tracing/log) output to stderr instead of stdout.)
 - rust-lang#79256 (Fix typos)
 - rust-lang#79264 (Get rid of some doctree items)
 - rust-lang#79272 (Support building clone shims for arrays with generic size)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 071d8b1 Nov 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
4 participants