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

Only emit one error per unsized binding, instead of one per usage #56607

Closed
estebank opened this issue Dec 7, 2018 · 0 comments · Fixed by #113183
Closed

Only emit one error per unsized binding, instead of one per usage #56607

estebank opened this issue Dec 7, 2018 · 0 comments · Fixed by #113183
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-type-system Area: Type system C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Dec 7, 2018

The following code

fn main() {
    let x = *"";
    println!("{}", x);
    println!("{}", x);
}

Produces the following output:

error[E0277]: the size for values of type `str` cannot be known at compilation time
 --> src/main.rs:2:9
  |
2 |     let x = *"";
  |         ^ doesn't have a size known at compile-time
  |
  = help: the trait `std::marker::Sized` is not implemented for `str`
  = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
  = note: all local variables must have a statically known size
  = help: unsized locals are gated as an unstable feature

error[E0277]: the size for values of type `str` cannot be known at compilation time
 --> src/main.rs:3:5
  |
3 |     println!("{}", x);
  |     ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `std::marker::Sized` is not implemented for `str`
  = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
  = note: required by `std::fmt::ArgumentV1::new`
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0277]: the size for values of type `str` cannot be known at compilation time
 --> src/main.rs:4:5
  |
4 |     println!("{}", x);
  |     ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `std::marker::Sized` is not implemented for `str`
  = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
  = note: required by `std::fmt::ArgumentV1::new`
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to 3 previous errors

The later two messages are not strictly necessary, since the unsized element being complained about is the same as the first one. Because of this, it should be unnecessary to complain about these as fixing the first problem fixes all three of them.

@estebank estebank added A-type-system Area: Type system C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints labels Dec 7, 2018
@estebank estebank added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 22, 2019
@estebank estebank added the D-papercut Diagnostics: An error or lint that needs small tweaks. label Oct 10, 2019
estebank added a commit to estebank/rust that referenced this issue Jun 30, 2023
estebank added a commit to estebank/rust that referenced this issue Oct 9, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 27, 2023
…avidtwco

Only emit one error per unsized binding, instead of one per usage

Fix rust-lang#56607.
@bors bors closed this as completed in 2f79681 Oct 27, 2023
@fmease fmease added A-type-system Area: Type system and removed A-type-system Area: Type system labels Dec 21, 2024
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 A-type-system Area: Type system C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants