Auto merge of #45050 - petrochenkov:ambind, r=nikomatsakis
resolve: Use same rules for disambiguating fresh bindings in `match` and `let`
Resolve `Unit` as a unit struct pattern in
```rust
struct Unit;
let Unit = x;
```
consistently with
```rust
match x {
Unit => {}
}
```
It was previously an error.
(The change also applies to unit variants and constants.)
Fixes https://users.rust-lang.org/t/e0530-cannot-shadow-unit-structs-what-in-the-earthly-what/13054
(This particular change doesn't depend on a fix for the issue mentioned in https://users.rust-lang.org/t/e0530-cannot-shadow-unit-structs-what-in-the-earthly-what/13054/4)
cc @rust-lang/lang
r? @nikomatsakis
This commit is contained in:
commit
a35a3abcda
9 changed files with 126 additions and 31 deletions
|
|
@ -260,7 +260,14 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
|
|||
"refutable pattern in {}: `{}` not covered",
|
||||
origin, pattern_string
|
||||
);
|
||||
diag.span_label(pat.span, format!("pattern `{}` not covered", pattern_string));
|
||||
let label_msg = match pat.node {
|
||||
PatKind::Path(hir::QPath::Resolved(None, ref path))
|
||||
if path.segments.len() == 1 && path.segments[0].parameters.is_none() => {
|
||||
format!("interpreted as a {} pattern, not new variable", path.def.kind_name())
|
||||
}
|
||||
_ => format!("pattern `{}` not covered", pattern_string),
|
||||
};
|
||||
diag.span_label(pat.span, label_msg);
|
||||
diag.emit();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue