Skip to content

Unhelpful error message when putting URL in docstring #105014

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

Closed
DavidVorick opened this issue Nov 28, 2022 · 1 comment
Closed

Unhelpful error message when putting URL in docstring #105014

DavidVorick opened this issue Nov 28, 2022 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.

Comments

@DavidVorick
Copy link

DavidVorick commented Nov 28, 2022

I wrote a docstring that had a url in it. The code looked something like this:

#![forbid(unsafe_code)]
#![deny(missing_docs)]
#![deny(unused_must_use)]
#![deny(unused_mut)]

//! seed implements functions for moving between a seed and a seed phrase. This blog post provides
//! a full specification for the code presented here:
//!
//!     https://blog.sia.tech/a-technical-breakdown-of-mysky-seeds-ba9964505978

use anyhow::{bail, Error, Result};
use sha2::{Digest, Sha256};
// ...

When I ran cargo test, the output looked something like this:

   Doc-tests seed_manager

running 1 test
test src/seed.rs - seed (line 9) ... FAILED

failures:

---- src/seed.rs - seed (line 9) stdout ----
error: expected expression, found `}`
 --> src/seed.rs:11:1
  |
2 | fn main() { #[allow(non_snake_case)] fn _doctest_main_src_seed_rs_9_0() {
  |                                                                         - while parsing this struct
3 | https://blog.sia.tech/a-technical-breakdown-of-mysky-seeds-ba9964505978
4 | } _doctest_main_src_seed_rs_9_0() }
  | ^ expected expression

error: struct literal body without path
 --> src/seed.rs:9:73
  |
2 |   fn main() { #[allow(non_snake_case)] fn _doctest_main_src_seed_rs_9_0() {
  |  _________________________________________________________________________^
3 | | https://blog.sia.tech/a-technical-breakdown-of-mysky-seeds-ba9964505978
4 | | } _doctest_main_src_seed_rs_9_0() }
  | |_^
  |
help: you might have forgotten to add the struct literal inside the block
  |
2 ~ fn main() { #[allow(non_snake_case)] fn _doctest_main_src_seed_rs_9_0() { SomeStruct {
3 | https://blog.sia.tech/a-technical-breakdown-of-mysky-seeds-ba9964505978
4 ~ } } _doctest_main_src_seed_rs_9_0() }
  |

error: aborting due to 2 previous errors

Couldn't compile the test.

failures:
    src/seed.rs - seed (line 9)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s

error: test failed, to rerun pass '--doc'

With some help, I was able to determine that the problem was my URL was being interpreted as code due to having 4 preceding spaces. The compiler error presented here was not remotely helpful to me (I'm relatively new to rust) in determining what the problem was. I think this issue has two potential resolutions:

  1. don't interpret something as code if it's clearly not code
  2. present a more helpful error message to suggest that my docstring is being interpreted as code and that I should remove the 4 spaces

Meta

rustc --version --verbose:

rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-unknown-linux-gnu
release: 1.64.0
LLVM version: 14.0.6
@DavidVorick DavidVorick added the C-bug Category: This is a bug. label Nov 28, 2022
@ChrisDenton ChrisDenton added the A-diagnostics Area: Messages for errors, warnings, and lints label Nov 28, 2022
@ehuss
Copy link
Contributor

ehuss commented Nov 28, 2022

Thanks for the report! I understand it can be confusing.

I'm going to close since this has been reported before. Closing as a duplicate of #64162, #59867, #88590, #100225.

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants