-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Implement empty structs with braces (RFC 218) #28336
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
|
@@ -8,13 +8,12 @@ | |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// compile-flags: -Z parse-only | ||
// Empty struct defined with braces shouldn't add names into value namespace | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great to have a test for it, but. Isn't this a surprising gotcha? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the RFC is quite explicit about this design, so that was just something new to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a part of the RFC and a result of long discussion. |
||
|
||
struct Foo; | ||
#![feature(braced_empty_structs)] | ||
|
||
fn f2() { | ||
let _end_stmt = Foo { }; | ||
//~^ ERROR: structure literal must either have at least one field | ||
} | ||
struct Empty {} | ||
|
||
fn main() {} | ||
fn main() { | ||
let e = Empty; //~ ERROR `Empty` is the name of a struct or struct variant | ||
} |
This file was deleted.
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.
You might consider explicitly saying here in a comment that this is unconditionally injecting trailing braces
{ }
for source code that may not necessarily have had them. (I do not object to this, especially since the goals for rustc's pretty printer can be considered independently from standalone tools likerustfmt
.)((Again, this nit won't block this PR.))
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 don't think it can inject new braces. This function triggers only for
ExprStruct
s and braceless "struct literals" are justExprPath
s.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.
hmm okay great then