resolve: Fresh bindings in match
/let
are preferred to "import ambiguity items"
#46079
Labels
A-resolve
Area: Name resolution
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
In the example below two glob imports bring two conflicting names
V
into scope.According to RFC 1560 an error is not immediately reported when two globs conflict, it is reported "on use" only if the ambiguous name is actually used.
Internally such an ambiguity creates an "erroneous item" (
Def::Err
) with nameV
used exclusively for reporting diagnostics. (However, see #36837, which is an issue closely related to this one.)For other purposes the name
V
doesn't exist in our module.In the example above we can see that in
let v = V;
V
is properly reported as ambiguous on use.In
match
however the meaning ofV
is determined in two-step disambiguation process. First we search for an existing item namedV
, then if no item namedV
exists we create a new variable.Diagnostics-only
Def::Err
items do not exist from this disambiguation process' point of view, so the first step fails forV
and we interpret it as a new variable without any "ambiguous name" warning.In many cases however, a warning about unused imports will be reported for
use E1::*;
anduse E2::*;
, but this happens only if the imports aren't actually used anywhere else and the warnings are not always noticed (see #46078).Two possible solutions are:
V
inmatch
.The text was updated successfully, but these errors were encountered: