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: cannot resolve links to associated trait items for primitives #90703

Closed
classabbyamp opened this issue Nov 8, 2021 · 10 comments · Fixed by #92443
Closed

rustdoc: cannot resolve links to associated trait items for primitives #90703

classabbyamp opened this issue Nov 8, 2021 · 10 comments · Fixed by #92443
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

@classabbyamp
Copy link

classabbyamp commented Nov 8, 2021

I tried this code:

use std::{num::ParseFloatError, str::FromStr};

/// Uses the rules from [`f64::from_str()`].
pub struct Number {
    pub value: f64,
}

impl FromStr for Number {
    type Err = ParseFloatError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let value = s.parse::<f64>()?;
        Ok(Self{value})
    }
}

I expected to see this happen: the [f64::from_str()] in the docstring links to https://doc.rust-lang.org/1.56.0/std/primitive.f64.html#method.from_str

Instead, this happened:

cargo doc
 Documenting cayenne v0.1.0 (/home/abi/projects/classabbyamp/rspice)
warning: unresolved link to `f64::from_str`
 --> src/v.rs:3:27
  |
3 | /// Uses the rules from [`f64::from_str()`].
  |                           ^^^^^^^^^^^^^^^ the builtin type `f64` has no function named `from_str`
  |
  = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default

warning: `cayenne` (lib doc) generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.34s

This does not happen for [f64::floor()] nor for linking to a non-primitive FromStr implmentation, like [Number::from_str()] (in the example above).

@jyn514 suggested that resolve_primitive_associated_item() may be only looking at inherent impls and not trait impls, and that it may need a call to resolve_associated_trait_item().

Meta

rustc --version --verbose:

rustc 1.56.0 (09c42c458 2021-10-18)
binary: rustc
commit-hash: 09c42c45858d5f3aedfa670698275303a3d19afa
commit-date: 2021-10-18
host: x86_64-unknown-linux-gnu
release: 1.56.0
LLVM version: 13.0.0

Reproduced on beta:

rustc 1.57.0-beta.3 (708d57e28 2021-11-01)
binary: rustc
commit-hash: 708d57e288d051a6238ed56039ffeac158e10e84
commit-date: 2021-11-01
host: x86_64-unknown-linux-gnu
release: 1.57.0-beta.3
LLVM version: 13.0.0

and nightly:

rustc 1.58.0-nightly (46b8e7488 2021-11-07)
binary: rustc
commit-hash: 46b8e7488eae116722196e8390c1bd2ea2e396cf
commit-date: 2021-11-07
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0
Backtrace

RUSTC_BOOTSTRAP=1 RUSTDOC_LOG=rustdoc::passes::collect_intra_doc_links=debug cargo rustdoc -- -Dwarnings -Ztreat-err-as-bug:

 Documenting cayenne v0.1.0 (/home/classabbyamp/projects/cayenne)
warning: some trace filter directives would enable traces that are disabled statically
 | `rustdoc::passes::collect_intra_doc_links=debug` would enable the DEBUG level for the `rustdoc::passes::collect_intra_doc_links` target
 = note: the static max level is `info`
 = help: to enable DEBUG logging, remove the `max_level_info` feature
DEBUG rustdoc::passes::collect_intra_doc_links::early doc=" Uses the rules from [`f64::from_str()`]."
DEBUG rustdoc::passes::collect_intra_doc_links::early link.link="`f64::from_str()`"
DEBUG rustdoc::passes::collect_intra_doc_links looking for the `Self` type
DEBUG rustdoc::passes::collect_intra_doc_links using item_name(): Some("cayenne")
DEBUG rustdoc::passes::collect_intra_doc_links looking for the `Self` type
DEBUG rustdoc::passes::collect_intra_doc_links using item_name(): Some("v")
DEBUG rustdoc::passes::collect_intra_doc_links looking for the `Self` type
DEBUG rustdoc::passes::collect_intra_doc_links using item_name(): Some("Number")
DEBUG rustdoc::passes::collect_intra_doc_links combined_docs=Uses the rules from [`f64::from_str()`].
DEBUG rustdoc::passes::collect_intra_doc_links f64::from_str resolved to Err(()) in namespace ValueNS
DEBUG rustdoc::passes::collect_intra_doc_links resolved primitives F64
DEBUG rustdoc::passes::collect_intra_doc_links looking for enum variant f64::from_str
DEBUG rustdoc::passes::collect_intra_doc_links f64::from_str resolved to Err(()) in namespace TypeNS
DEBUG rustdoc::passes::collect_intra_doc_links resolved primitives F64
DEBUG rustdoc::passes::collect_intra_doc_links resolving f64::from_str as a macro in the module DefId(0:3 ~ cayenne[f5be]::v)
DEBUG rustdoc::passes::collect_intra_doc_links f64 resolved to Ok(Primitive(F64)) in namespace TypeNS
DEBUG rustdoc::passes::collect_intra_doc_links found partial_res=Primitive(F64)
error: unresolved link to `f64::from_str`
 --> src/v.rs:3:27
  |
3 | /// Uses the rules from [`f64::from_str()`].
  |                           ^^^^^^^^^^^^^^^ the builtin type `f64` has no function named `from_str`
  |
  = note: `-D rustdoc::broken-intra-doc-links` implied by `-D warnings`

thread 'rustc' panicked at 'aborting due to `-Z treat-err-as-bug=1`', compiler/rustc_errors/src/lib.rs:1182:27
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

error: Unrecognized option: 'crate-version'

error: could not document `cayenne`

Caused by:
  process didn't exit successfully: `rustdoc --edition=2021 --crate-type lib --crate-name cayenne src/lib.rs -o /home/classabbyamp/projects/cayenne/target/doc --error-format=json --json=diagnostic-rendered-ansi -Dwarnings -Ztreat-err-as-bug -L dependency=/home/classabbyamp/projects/cayenne/target/debug/deps --crate-version 0.1.0` (exit status: 1)

@classabbyamp classabbyamp added the C-bug Category: This is a bug. label Nov 8, 2021
@jyn514 jyn514 added A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name 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. labels Nov 8, 2021
@classabbyamp classabbyamp changed the title cannot resolve a link to associated trait items for primitives in rustdoc cannot resolve links to associated trait items for primitives in rustdoc Nov 8, 2021
@classabbyamp classabbyamp changed the title cannot resolve links to associated trait items for primitives in rustdoc rustdoc: cannot resolve links to associated trait items for primitives in rustdoc Nov 8, 2021
@classabbyamp classabbyamp changed the title rustdoc: cannot resolve links to associated trait items for primitives in rustdoc rustdoc: cannot resolve links to associated trait items for primitives Nov 8, 2021
@Mustafif
Copy link

Mustafif commented Nov 8, 2021

Hello I tested your problem, and found that when I used [f64::from_str().unwrap()] I got no error.

use std::{num::ParseFloatError, str::FromStr};

/// Uses the rules from [`f64::from_str().unwrap()`].
#[derive(Debug)]
pub struct Number {
    pub value: f64,
}

impl FromStr for Number {
    type Err = ParseFloatError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let value = s.parse::<f64>()?;
        Ok(Self{value})
    }
}

When I run cargo doc:

cargo doc
 Documenting num_doc v0.1.0 (C:\Users\Musta\rust_tests\num_doc)
    Finished dev [unoptimized + debuginfo] target(s) in 0.75s

I also tested with a main.rs file, and I mean it does work:

mod num;
use num::Number;
use std::str::FromStr;
fn main(){
    let s = Number::from_str("6.7").unwrap();
    println!("{:?}", s);
}

I hope this helps, but I do find it weird cargo needed the unwrap to not give errors

@jyn514
Copy link
Member

jyn514 commented Nov 8, 2021

@Mustafif when you put a dot in a link, rustdoc treats it as a url, not an intra doc link

@Mustafif
Copy link

Mustafif commented Nov 8, 2021

Oh my I did not realize that, thank you for informing me about that

@theryangeary
Copy link

I'd like to take a shot at this, if that's alright.

@jyn514
Copy link
Member

jyn514 commented Nov 8, 2021

@theryangeary go for it! :) if you need help, feel free to ask here or on Zulip.

@jyn514
Copy link
Member

jyn514 commented Nov 25, 2021

Just for posterity: the zulip thread for this is https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/help.20with.20.2390703.

@mdibaiee
Copy link
Contributor

Hello, is this still being worked on? The last message on the Zulip thread is 25th November. If it's free to pick up I'd be happy to pick it up.

@theryangeary
Copy link

theryangeary commented Dec 30, 2021 via email

@mdibaiee
Copy link
Contributor

@rustbot claim

@rustbot rustbot assigned mdibaiee and unassigned theryangeary Dec 31, 2021
@mdibaiee
Copy link
Contributor

mdibaiee commented Jan 3, 2022

#92443 will fix this for "simple" primitives such as:
char, str, bool, never, usize, u{8, 16, 32, 64, 128}, isize, i{8, 16, 32, 64, 128} and f32, f64. However, for generic types that wrap around other types, such as Tuple, Array, Slice, RawPtr, etc. I was not able to make it work at first try. See the discussion here: #92443 (comment)

As such, I think this issue is now "partially" fixed, however more work is needed to make it work for these other types.

Should I create a separate issue for these unsupported ones, or should we just keep this same issue?

See the new issue: #92536

mdibaiee added a commit to mdibaiee/rust that referenced this issue Jan 3, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 4, 2022
…imitive-types, r=Manishearth

Rustdoc: resolve associated traits for non-generic primitive types

Fixes rust-lang#90703

This seems to work:
<img width="457" alt="image" src="https://user-images.githubusercontent.com/2807772/147774059-9556ff96-4519-409e-8ed0-c33ecc436171.png">

I'm just afraid I might have missed some cases / broken previous functionality.

I also have not written tests yet, I will have to take a look to see where tests are and how they are structured, but any help there is also appreciated.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 5, 2022
…imitive-types, r=Manishearth

Rustdoc: resolve associated traits for non-generic primitive types

Fixes rust-lang#90703

This seems to work:
<img width="457" alt="image" src="https://user-images.githubusercontent.com/2807772/147774059-9556ff96-4519-409e-8ed0-c33ecc436171.png">

I'm just afraid I might have missed some cases / broken previous functionality.

I also have not written tests yet, I will have to take a look to see where tests are and how they are structured, but any help there is also appreciated.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 5, 2022
…imitive-types, r=Manishearth

Rustdoc: resolve associated traits for non-generic primitive types

Fixes rust-lang#90703

This seems to work:
<img width="457" alt="image" src="https://user-images.githubusercontent.com/2807772/147774059-9556ff96-4519-409e-8ed0-c33ecc436171.png">

I'm just afraid I might have missed some cases / broken previous functionality.

I also have not written tests yet, I will have to take a look to see where tests are and how they are structured, but any help there is also appreciated.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 6, 2022
…imitive-types, r=Manishearth

Rustdoc: resolve associated traits for non-generic primitive types

Fixes rust-lang#90703

This seems to work:
<img width="457" alt="image" src="https://user-images.githubusercontent.com/2807772/147774059-9556ff96-4519-409e-8ed0-c33ecc436171.png">

I'm just afraid I might have missed some cases / broken previous functionality.

I also have not written tests yet, I will have to take a look to see where tests are and how they are structured, but any help there is also appreciated.
@bors bors closed this as completed in 83487b8 Jan 6, 2022
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
Development

Successfully merging a pull request may close this issue.

5 participants