Ambiguous item error fails to trigger when use is declared before the source #112713
Labels
A-local-reexports
Area: Documentation that has been locally re-exported (i.e., non-cross-crate)
A-resolve
Area: Name resolution
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
With the following code:
We expected to see this compiler error.
Instead, the compiler accepts it and
foo()
returns1
. We found that if you movefoo
belowsub
, you do get the expected error. @ComputerDruid and I took a while to repro this, because we assumed that the order in which you define functions/modules shouldn't change the semantics. It appears that glob re-exports are also necessary for this behavior to occur. If you change it to:The explicit one will shadow the glob regardless of where
foo
is defined, and if you make both explicit, it'll trigger this error.You can see the difference if you uncomment the bottom function in this playground link. Even changing the import within
foo
touse sub::C
will make it trigger the expected ambiguous item error, so both of the re-exports and the import have to be globs to see the weird behavior.This may be a separate issue, but in the accepted code if you swap the order of the glob re-exports in
sub
,foo()
will return2
, suggesting that whichever one is re-exported first "wins".rustc --version --verbose
:(same behavior on nightly)
The text was updated successfully, but these errors were encountered: