-
Notifications
You must be signed in to change notification settings - Fork 13.3k
crates are considered for fn() -> type
name resolution if they have generic parameters
#139095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
fn() -> type
name resolution, except if they have generic parametersfn() -> type
name resolution if they have generic parameters
I think this is two things entangled into what seems like one bug? Specifically, I don't think the preference for crates over types is because of the presence of generic args. I think we just prefer primitives over crate names in resolution. Specifically, we should be hitting a resolver error before even trying to compute the generics of
Am I missing something, b/c I can't seem to reproduce the error "type arguments not allowed on crate" with the code you shared? I'm reading between the lines, but did you happen to modify this example to use extern crate libc as usize;
extern crate libc as isize;
fn bar() -> usize { 0 } // OK
fn baz() -> isize<i32> { 0 } // type arguments are not allowed on crate `libc` According to that error, it may look like
And indeed, the "path res" (the resolution) for the full path |
rust/compiler/rustc_resolve/src/late.rs Lines 4565 to 4602 in 2196aff
This is why we prefer primitives > crate resolutions. So I don't think this has to do with the presence of generic parameters, and that wonky generic parameter error message that mentions "type arguments are not allowed on crate" which I shared above which is just a diagnostics bug which I've fixed in #139127. LMK if I'm missing something critical here |
you're absolutely right, that comment is left over from an old version of the code. nice catch, thanks. |
…i-obk Fix up partial res of segment in primitive resolution hack There is a hack in the resolver: ``` // In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we // don't report an error right away, but try to fallback to a primitive type. ``` This fixes up the resolution for primitives which would otherwise resolve to a module, but we weren't also updating the res of the path segment, leading to weird diagnostics. We explicitly call `self.r.partial_res_map.insert` instead of `record_partial_res` b/c we have recorded a partial res already, and we specifically want to override it. cc rust-lang#139095 (comment)
Rollup merge of rust-lang#139127 - compiler-errors:prim-ty-hack, r=oli-obk Fix up partial res of segment in primitive resolution hack There is a hack in the resolver: ``` // In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we // don't report an error right away, but try to fallback to a primitive type. ``` This fixes up the resolution for primitives which would otherwise resolve to a module, but we weren't also updating the res of the path segment, leading to weird diagnostics. We explicitly call `self.r.partial_res_map.insert` instead of `record_partial_res` b/c we have recorded a partial res already, and we specifically want to override it. cc rust-lang#139095 (comment)
I tried this code:
I expected to see this happen:
usize
andOption
should both consistently resolve to the crate, or they should consistently resolve to the builtin type.Instead, this happened: In return position,
usize
resolves to the builtin type andOption
resolves to the crate.In attribute position,
usize
resolves to the crate (which seems reasonable, because associated macros aren't a thing.)Meta
rustc --version --verbose
:1.87.0-nightly (2025-03-28 920d95eaf23d7eb6b415)
@rustbot label A-resolve
The text was updated successfully, but these errors were encountered: