Rollup merge of #75188 - Aaron1011:fix/fieldless-tuple-error, r=varkor

Handle fieldless tuple structs in diagnostic code

Fixes #75062
This commit is contained in:
Yuki Okushi 2020-08-07 09:35:21 +09:00 committed by GitHub
commit 665138c977
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 4 deletions

View file

@ -1075,11 +1075,10 @@ 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");
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
}

View file

@ -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
}

View file

@ -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`.