Skip to content

Handle fieldless tuple structs in diagnostic code #75188

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

Merged
merged 1 commit into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,10 +1075,9 @@ impl<'a> Resolver<'a> {
) = binding.kind
{
let def_id = (&*self).parent(ctor_def_id).expect("no parent for a constructor");
if let Some(fields) = self.field_names.get(&def_id) {
let first_field = fields.first().expect("empty field list in the map");
return Some(fields.iter().fold(first_field.span, |acc, field| acc.to(field.span)));
}
let fields = self.field_names.get(&def_id)?;
let first_field = fields.first()?; // Handle `struct Foo()`
return Some(fields.iter().fold(first_field.span, |acc, field| acc.to(field.span)));
}
None
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/privacy/issue-75062-fieldless-tuple-struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Regression test for issue #75062
// Tests that we don't ICE on a privacy error for a fieldless tuple struct.

mod foo {
struct Bar();
}

fn main() {
foo::Bar(); //~ ERROR tuple struct
}
15 changes: 15 additions & 0 deletions src/test/ui/privacy/issue-75062-fieldless-tuple-struct.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0603]: tuple struct `Bar` is private
--> $DIR/issue-75062-fieldless-tuple-struct.rs:9:10
|
LL | foo::Bar();
| ^^^ private tuple struct
|
note: the tuple struct `Bar` is defined here
--> $DIR/issue-75062-fieldless-tuple-struct.rs:5:5
|
LL | struct Bar();
| ^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0603`.