Skip to content

Commit 5b84d5f

Browse files
committed
resolve: Relax fresh binding disambiguation slightly to fix regression
1 parent d626e4d commit 5b84d5f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/librustc_resolve/late.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1522,23 +1522,27 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
15221522
ident: Ident,
15231523
has_sub: bool,
15241524
) -> Option<Res> {
1525+
// An immutable (no `mut`) by-value (no `ref`) binding pattern without
1526+
// a sub pattern (no `@ $pat`) is syntactically ambiguous as it could
1527+
// also be interpreted as a path to e.g. a constant, variant, etc.
1528+
let is_syntactic_ambiguity = !has_sub && bm == BindingMode::ByValue(Mutability::Not);
1529+
15251530
let ls_binding = self.resolve_ident_in_lexical_scope(ident, ValueNS, None, pat.span)?;
15261531
let (res, binding) = match ls_binding {
1527-
LexicalScopeBinding::Item(binding) if binding.is_ambiguity() => {
1532+
LexicalScopeBinding::Item(binding)
1533+
if is_syntactic_ambiguity && binding.is_ambiguity() =>
1534+
{
15281535
// For ambiguous bindings we don't know all their definitions and cannot check
15291536
// whether they can be shadowed by fresh bindings or not, so force an error.
1537+
// issues/33118#issuecomment-233962221 (see below) still applies here,
1538+
// but we have to ignore it for backward compatibility.
15301539
self.r.record_use(ident, ValueNS, binding, false);
15311540
return None;
15321541
}
15331542
LexicalScopeBinding::Item(binding) => (binding.res(), Some(binding)),
15341543
LexicalScopeBinding::Res(res) => (res, None),
15351544
};
15361545

1537-
// An immutable (no `mut`) by-value (no `ref`) binding pattern without
1538-
// a sub pattern (no `@ $pat`) is syntactically ambiguous as it could
1539-
// also be interpreted as a path to e.g. a constant, variant, etc.
1540-
let is_syntactic_ambiguity = !has_sub && bm == BindingMode::ByValue(Mutability::Not);
1541-
15421546
match res {
15431547
Res::SelfCtor(_) // See #70549.
15441548
| Res::Def(

src/test/ui/binding/ambiguity-item.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ fn main() {
1414
let v = f; //~ ERROR `f` is ambiguous
1515
match v {
1616
f => {} //~ ERROR `f` is ambiguous
17+
mut f => {} // OK, unambiguously a fresh binding due to `mut`
1718
}
1819
}

0 commit comments

Comments
 (0)