-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
API documentation suggestion - reduce usage of the ? operator #42725
Comments
Hey @mistydemeo ! Thanks for this. You're totally right that it's a pain point. I want to back up briefly and lay out why this is, bear with me for a moment 😄 So, an important part of doc examples is showing idiomatic Rust. Using We're taking a couple of steps to address things:
So, I think this issue is mostly a duplicate of that second one there. What do you think? What error message would you have liked to see, in an ideal world? |
Sorry for not getting back sooner.
I think an ideal error message would be clearer about why a conversion is happening, and what the problem is. Say, something like:
With the existing message, it's not clear where the The other issue I found was that I couldn't find the docs for the So, I appreciate that |
💯
A good spot to look for "What syntax is this" is https://doc.rust-lang.org/book/first-edition/syntax-index.html, which says
This is a problem I've been thinking about too, but am not sure what to do with: language features don't have pages in the API docs. That's because, well, they're not part of the API, but since that's the only part of our docs that has search... I guess docs-wide search would fix it, but yeah :/ |
Oh yeah, the fact that "question mark operator" is used will help a lot. The Unfortunately the pagerank of the second edition of the book doesn't seem to be great yet - a search for "rust question mark operator" doesn't include the book in the first five pages.
This would be really useful regardless! |
I was looking up the |
shamelessly pitching #25967 |
Fixes rust-lang#42725 or at least, this is the best we can really do. rust-lang#35946 is tracking better errors already, so that should cover the other part of it.
…avus Mention the name of ? in Result's docs Fixes rust-lang#42725 or at least, this is the best we can really do. rust-lang#35946 is tracking better errors already, so that should cover the other part of it.
A small update on this issue: we now have also fixed this in a different way: https://doc.rust-lang.org/nightly/std/fs/fn.create_dir.html |
The Rust std API documentation currently uses the
?
operator in a lot of examples. I think this is likely to be confusing to new Rust developers, who probably haven't encountered it before; it's a powerful shorthand, but it's also confusing and hard to look up.I think it's a particular problem because error messages surrounding
?
are unclear and hard to debug for someone who's new to Rust, and it's easy to make mistakes when borrowing from the examples in the API docs.For example, say a new dev wants to write a function that opens a file and writes to it. That developer has probably already clicked through to the documentation for std::result, which most prominently shows using strings as the
Err
type forResult
. Searching for writing a file, the user then finds the documentation for std::fs::File, and borrows the code in the example at the top of the page since it does what they wanted it to do. Their resulting code looks something like this:When trying to build, they get the following errors:
It's not clear at all from this what the problem was, or how copying and pasting these examples caused an issue. As you can probably tell, this example's basically my own experience. 😅 I eventually found out what I was doing wrong, but it does feel a bit like I fell into a trap door that didn't need to be there.
cc @steveklabnik
The text was updated successfully, but these errors were encountered: