Skip to content

compiletest string_enums have no error reporting #135392

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
lolbinarycat opened this issue Jan 12, 2025 · 2 comments · Fixed by #135397
Closed

compiletest string_enums have no error reporting #135392

lolbinarycat opened this issue Jan 12, 2025 · 2 comments · Fixed by #135397
Labels
A-compiletest Area: The compiletest test runner C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@lolbinarycat
Copy link
Contributor

in common.rs:

        impl FromStr for $name {
            type Err = ();

            fn from_str(s: &str) -> Result<Self, ()> {
                match s {
                    $($repr => Ok(Self::$variant),)*
                    _ => Err(()),
                }
            }
        }

the error type being unit means if you pass an unrecognized option to any string enum flag, you get a very unhelpful error (it just prints ()).

if it was changed to the following:

        impl FromStr for $name {
            type Err = String;

            fn from_str(s: &str) -> Result<Self, String> {
                match s {
                    $($repr => Ok(Self::$variant),)*
                    _ => Err(s.to_string()),
                }
            }
        }

you would at least get an error message that says what the unrecognized argument is.

i would file a PR myself but the build system seems to be falling apart at the seams for me.

@lolbinarycat lolbinarycat added A-compiletest Area: The compiletest test runner T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jan 12, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 12, 2025
@jieyouxu jieyouxu added C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 12, 2025
@jieyouxu
Copy link
Member

In the short term something like Err(format!("unknown option: `{}`", s)) is fine.

@jieyouxu jieyouxu added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Jan 12, 2025
@lolbinarycat
Copy link
Contributor Author

it would be leagues better than the status quo, and probably quite easy.

@bors bors closed this as completed in 1b45dad Jan 12, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 12, 2025
Rollup merge of rust-lang#135397 - lqd:compiletest-enums, r=jieyouxu

compiletest: add erroneous variant to `string_enum`s conversions error

As requested in rust-lang#135392, this adds which variant caused the string conversion failure.

r? jieyouxu
fixes rust-lang#135392
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiletest Area: The compiletest test runner C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
Development

Successfully merging a pull request may close this issue.

3 participants