rust-lang / rust-lang/rfcs

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

Open
#3,045 3 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the examples with the nightly rustc version described in the issue, including a used return value and the unit-return case. Trace the compiler behavior for todo!() and unimplemented!(); done means the intended cases emit a rustc warning while preserving the existing panic behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.