-
Notifications
You must be signed in to change notification settings - Fork 13.4k
rustc: fix ICE regarding struct variants in enums #15786
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
Conversation
and someone wrote this: enum {
Foo {}
} really maybe a usual case :( |
assert!(fields.len() > 0); | ||
|
||
if fields.len() == 0 { | ||
cx.sess.fatal("you don't specify any field, use simple defination") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean "definition" instead of "defination"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way... I think it would be more informative for the reader if you followed the style of the error a couple of lines below (enum_variants: all fields in struct must have a name
). What about enum_variants: struct variant must have at least one field
?
EDIT: ignore this comment and read what huonw wrote below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionaly, I think you will need to use cx.sess.span_err(ast_variant.span, "error message")
instead of cx.sess.fatal
.
EDIT: ignore this comment and read what huonw wrote below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend cx.sess.span_fatal(ast_variant.span, "struct variants must have at least one field");
.
I think it would be invalid to continue compilation at this point, so one must use fatal
rather than err
(which just prints an error message, and causes compilation to stop at some future point, but not immediately). Also, the enum_variants: ...
warning in the error message below is only appropriate there, since that one is a bug
(the parser shouldn't let through any UnnamedField
s in a struct variant), while this is a user-facing message, and users don't care about the compiler-internals function which emits the error message.
Also, this should have a test, add a file to // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum Foo {
Bar { } //~ ERROR struct variant must have at least one field
}
fn main() {} See https://github.com/rust-lang/rust/wiki/Note-testsuite#language-and-compiler-tests for more details. |
@@ -3665,8 +3665,10 @@ impl VariantInfo { | |||
ast::StructVariantKind(ref struct_def) => { | |||
|
|||
let fields: &[StructField] = struct_def.fields.as_slice(); | |||
|
|||
assert!(fields.len() > 0); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The travis build failed in make tidy
because this line has trailing whitespace, can you remove the whitespace?
@huonw don't forget the |
thanks guys so much, @aochagavia and @huonw. |
and plus, i have changed the title of my pr/commit to: rustc: fix ICE regarding struct variants in enums |
There's a tidy issue: https://travis-ci.org/rust-lang/rust/jobs/30350054 /home/travis/build/rust-lang/rust/src/librustc/middle/ty.rs:3728: line longer than 100 chars |
done :p |
#![feature(struct_variant)] | ||
|
||
enum Foo { | ||
Bar { } //~ ERROR struct variant must have at least one field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error above has "struct variants must have" whereas this error says "struct variant must have"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @alexcrichton, i have changed this in ty.rs, now LGTY?
hi, the travis is green :) |
@yorkie I don't think this should be done in librustc but rather libsyntax. What's the point of accepting it in the parser if we're just gonna error out later. The relevant bit in libsyntax would be |
i dont 100% agreed on this, because this error breaks here, do we really need to move this patch to the parsing phase? i need more from u |
Closing due to inactivity, but feel free to reopen with comments addressed! |
fix: Fix VS Code detection for Insiders version Addresses rust-lang/rust-analyzer#15784.
Hi, this is inspired by the output of previous rustc output:
This unexpected failure will scare off someone IMO, right, then such that a better error print would be better :p