-
Notifications
You must be signed in to change notification settings - Fork 13.3k
pattern_analysis: rework how we hide empty private fields #121000
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
01a38e5
to
196b6a3
Compare
This comment was marked as resolved.
This comment was marked as resolved.
196b6a3
to
02b5f49
Compare
/// Fake extra constructor that indicates that we should skip the column entirely. This is used | ||
/// when a private field is empty, so that we don't observe its emptiness. Only used for | ||
/// specialization. | ||
Skip, |
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 wonder if we should give this a more descriptive name (PrivateUninhabited
) or something
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.
yeah I like that, will rename
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.
done
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
02b5f49
to
c918893
Compare
@bors r+ |
Ty! |
…llaumeGomez Rollup of 7 pull requests Successful merges: - rust-lang#119748 (Increase visibility of `join_path` and `split_paths`) - rust-lang#120820 (Enable CMPXCHG16B, SSE3, SAHF/LAHF and 128-bit Atomics (in nightly) in Windows x64) - rust-lang#121000 (pattern_analysis: rework how we hide empty private fields) - rust-lang#121376 (Skip unnecessary comparison with half-open range patterns) - rust-lang#121596 (Use volatile access instead of `#[used]` for `on_tls_callback`) - rust-lang#121669 (Count stashed errors again) - rust-lang#121783 (Emitter cleanups) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#121000 - Nadrieril:keep_all_fields, r=compiler-errors pattern_analysis: rework how we hide empty private fields Consider this: ```rust mod foo { pub struct Bar { pub a: bool, b: !, } } fn match_a_bar(bar: foo::Bar) -> bool { match bar { Bar { a, .. } => a, } } ``` Because the field `b` is private, matches outside the module are not allowed to observe the fact that `Bar` is empty. In particular `match bar {}` is valid within the module `foo` but an error outside (assuming `exhaustive_patterns`). We currently handle this by hiding the field `b` when it's both private and empty. This means that the pattern `Bar { a, .. }` is lowered to `Bar(a, _)` if we're inside of `foo` and to `Bar(a)` outside. This involves a bit of a dance to keep field indices straight. But most importantly this makes pattern lowering depend on the module. In this PR, I instead do nothing special when lowering. Only during analysis do we track whether a place must be skipped. r? `@compiler-errors`
Consider this:
Because the field
b
is private, matches outside the module are not allowed to observe the fact thatBar
is empty. In particularmatch bar {}
is valid within the modulefoo
but an error outside (assumingexhaustive_patterns
).We currently handle this by hiding the field
b
when it's both private and empty. This means that the patternBar { a, .. }
is lowered toBar(a, _)
if we're inside offoo
and toBar(a)
outside. This involves a bit of a dance to keep field indices straight. But most importantly this makes pattern lowering depend on the module.In this PR, I instead do nothing special when lowering. Only during analysis do we track whether a place must be skipped.
r? @compiler-errors