Skip to content

Commit 48bc398

Browse files
committed
Handle fieldless tuple structs in diagnostic code
Fixes #75062
1 parent 1d69e3b commit 48bc398

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/librustc_resolve/diagnostics.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1075,10 +1075,9 @@ impl<'a> Resolver<'a> {
10751075
) = binding.kind
10761076
{
10771077
let def_id = (&*self).parent(ctor_def_id).expect("no parent for a constructor");
1078-
if let Some(fields) = self.field_names.get(&def_id) {
1079-
let first_field = fields.first().expect("empty field list in the map");
1080-
return Some(fields.iter().fold(first_field.span, |acc, field| acc.to(field.span)));
1081-
}
1078+
let fields = self.field_names.get(&def_id)?;
1079+
let first_field = fields.first()?; // Handle `struct Foo()`
1080+
return Some(fields.iter().fold(first_field.span, |acc, field| acc.to(field.span)));
10821081
}
10831082
None
10841083
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for issue #75062
2+
// Tests that we don't ICE on a privacy error for a fieldless tuple struct.
3+
4+
mod foo {
5+
struct Bar();
6+
}
7+
8+
fn main() {
9+
foo::Bar(); //~ ERROR tuple struct
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0603]: tuple struct `Bar` is private
2+
--> $DIR/issue-75062-fieldless-tuple-struct.rs:9:10
3+
|
4+
LL | foo::Bar();
5+
| ^^^ private tuple struct
6+
|
7+
note: the tuple struct `Bar` is defined here
8+
--> $DIR/issue-75062-fieldless-tuple-struct.rs:5:5
9+
|
10+
LL | struct Bar();
11+
| ^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0603`.

0 commit comments

Comments
 (0)