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: Allow implicit fn main() -> Result<_, _> #56260

Closed
llogiq opened this issue Nov 26, 2018 · 6 comments · Fixed by #56470
Closed

Rustdoc: Allow implicit fn main() -> Result<_, _> #56260

llogiq opened this issue Nov 26, 2018 · 6 comments · Fixed by #56470
Assignees
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@llogiq
Copy link
Contributor

llogiq commented Nov 26, 2018

Rustdoc now allows us to use ? in our tests. Unfortunately, this requires writing the fn main() -> .. manually, which really shouldn't be needed IMHO.

So we now have to write:

/// ```rust
///# fn main() -> Result<(), ()> {
/// let foo = Ok(1usize);
/// assert!(foo? > 0);
///# }
/// ```

where it should suffice to write:

/// ```rust
/// let foo = Ok(1usize);
/// assert!(foo? > 0);
/// ```

Doing so will make the tests shorter and hopefully lead to more ? and less unwrap in tests.

@Centril Centril added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Nov 27, 2018
@Centril
Copy link
Contributor

Centril commented Nov 27, 2018

Feels like a no-brainer to me; would be great. :)

@scottmcm
Copy link
Member

scottmcm commented Dec 3, 2018

I think there are two things we want before doing this:

  • try fn, so that it can always be try fn main() -> TBD {, and existing code will just work.
  • The Try re-do, so we can make a type that accepts any error type (since it'll just error anyway).

@sinkuu
Copy link
Contributor

sinkuu commented Dec 3, 2018

fn main() -> impl std::process::Termination?

@llogiq
Copy link
Contributor Author

llogiq commented Dec 3, 2018

Yes, that's what I'm thinking, and I'm setting up a PR for that. However, it's still unstable.

@QuietMisdreavus
Copy link
Member

I talked about this back in March on the "? in main" tracking issue: #43301 (comment)

That sample you gave isn't even valid as-is, unless () coercing to Ok(()) is also in the pipeline?

@llogiq
Copy link
Contributor Author

llogiq commented Dec 4, 2018

That'll be next, hopefully. I wonder if it suffices to impl From<T> for <Result<T, !>> or if we need to keep a generic error type (which might mess with type inference). In any event, having both the aforementioned and impl From<Result<T, !>> for T should be a no-brainer, right?

bors added a commit that referenced this issue Jan 24, 2019
Modify doctest's auto-`fn main()` to allow `Result`s

This lets the default `fn main()` ~~return `impl Termination`~~ unwrap Results, which allows the use of `?` in most tests without adding it manually. This fixes #56260

~~Blocked on `std::process::Termination` stabilization.~~

Using `Termination` would have been cleaner, but this should work OK.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 17, 2019
… r=GuillaumeGomez

Modify doctest's auto-`fn main()` to allow `Result`s

This lets the default `fn main()` ~~return `impl Termination`~~ unwrap Results, which allows the use of `?` in most tests without adding it manually. This fixes rust-lang#56260

~~Blocked on `std::process::Termination` stabilization.~~

Using `Termination` would have been cleaner, but this should work OK.
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Feb 18, 2019
… r=GuillaumeGomez

Modify doctest's auto-`fn main()` to allow `Result`s

This lets the default `fn main()` ~~return `impl Termination`~~ unwrap Results, which allows the use of `?` in most tests without adding it manually. This fixes rust-lang#56260

~~Blocked on `std::process::Termination` stabilization.~~

Using `Termination` would have been cleaner, but this should work OK.
kennytm added a commit to kennytm/rust that referenced this issue Feb 19, 2019
… r=GuillaumeGomez

Modify doctest's auto-`fn main()` to allow `Result`s

This lets the default `fn main()` ~~return `impl Termination`~~ unwrap Results, which allows the use of `?` in most tests without adding it manually. This fixes rust-lang#56260

~~Blocked on `std::process::Termination` stabilization.~~

Using `Termination` would have been cleaner, but this should work OK.
huxi added a commit to huxi/rusty_ulid that referenced this issue Apr 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants