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

todo! and unimplemented! should generate rustc warnings when returning used values #3045

Open
bbarker opened this issue Dec 27, 2020 · 3 comments

Comments

@bbarker
Copy link

bbarker commented Dec 27, 2020

I tried this code:

pub fn some_num() -> i32 {
    todo!();
}

I expected to see this happen:

A warning noting that a panic would occur (either showing the line of the todo! or the line of the function call making use of the todo!, for instance). I suppose even fancier ergonomics could be added, so that if the return type is (), a () could could be supplied - but this is still not good IMO, since that implies an effect should happen, but isn't happening. So even in that case, I think a warning should be given.

Instead, this happened:

Currently (nightly) rustc will not warn if some_num is used, e.g., from main: println!("{}", some_num()); - this will compile without warning, but will panic:

$ ./target/debug/sfwtools
thread 'main' panicked at 'not yet implemented', src/sfwtools.rs:63:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Meta

rustc --version --verbose:

rustc 1.50.0-nightly (0edce6f4b 2020-12-24)
binary: rustc
commit-hash: 0edce6f4bbb4514482537f569f0b8ef48e71e0a0
commit-date: 2020-12-24
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly

@bbarker
Copy link
Author

bbarker commented Dec 27, 2020

I'll just note an easy workaround I found is to use todo!(); ();, like this:

pub fn wc_file(src: &File) -> Result<(), Error> {
    todo!(); ();
}

This seems to work regardless of what the return type of the enclosing function is.

@SOF3
Copy link

SOF3 commented Dec 28, 2020

See also rust-lang/rust#75277, where I suggested something exactly opposite

@kaarelen
Copy link

@SOF3
Probably we can add something like " #[warn(todo)] ", or at least make warnings for release builds?

PS: I'm relatively new at rust, prob such functionality already exists, and I'm failed to google it, sorry if it's a case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants