You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
crates are considered for fn() -> type name resolution if they have generic parameters #139095
externcrate libc as usize;externcrate libc asOption;#[usize::inner]//~ ERROR could not find `inner` in `usize`fnfoo(){}fnbar() -> usize{0}// OKfnbaz() -> Option<T>{0}//~ ERROR type arguments not allowed on crate
I expected to see this happen: usize and Option 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 and Option resolves to the crate.
In attribute position, usize resolves to the crate (which seems reasonable, because associated macros aren't a thing.)
changed the title [-]crates are not considered for `fn() -> type` name resolution, except if they have generic parameters[/-][+]crates are considered for `fn() -> type` name resolution if they have generic parameters[/+]on Mar 29, 2025
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 Option<T> when Option is defined as a crate name:
error[E0573]: expected type, found crate `Option`
--> src/lib.rs:6:13
|
6 | fn baz() -> Option<T> { 0 }
| ^^^^^^^^^ not a type
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 Option when filing this bug, but previously were experimenting with something like the following code?
externcrate libc as usize;externcrate libc as isize;fnbar() -> usize{0}// OKfnbaz() -> isize<i32> {0}// type arguments are not allowed on crate `libc`
According to that error, it may look like baz's return type is resolving to libc as isize, but I think that's just a diagnostic bug, since we later go on to note:
help: primitive type `isize` doesn't have generic parameters
|
4 - fn baz() -> isize<i32> { 0 } //~ ERROR type arguments not allowed on crate
4 + fn baz() -> isize { 0 } //~ ERROR type arguments not allowed on crate
And indeed, the "path res" (the resolution) for the full path isize<i32> is indeed PrimTy, even if the "segment res" (resolution of just the path segment) is the crate. That's probably just a bug.
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.
I'm reading between the lines, but did you happen to modify this example to use Option when filing this bug, but previously were experimenting with something like the following code?
you're absolutely right, that comment is left over from an old version of the code. nice catch, thanks.
Activity
[-]crates are not considered for `fn() -> type` name resolution, except if they have generic parameters[/-][+]crates are considered for `fn() -> type` name resolution if they have generic parameters[/+]jyn514 commentedon Mar 29, 2025
cc @petrochenkov
compiler-errors commentedon Mar 30, 2025
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
Option<T>whenOptionis defined as a crate name: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
Optionwhen filing this bug, but previously were experimenting with something like the following code?According to that error, it may look like
baz's return type is resolving tolibc as isize, but I think that's just a diagnostic bug, since we later go on to note:And indeed, the "path res" (the resolution) for the full path
isize<i32>is indeedPrimTy, even if the "segment res" (resolution of just the path segment) is the crate. That's probably just a bug.compiler-errors commentedon Mar 30, 2025
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
jyn514 commentedon Mar 30, 2025
you're absolutely right, that comment is left over from an old version of the code. nice catch, thanks.
Rollup merge of rust-lang#139127 - compiler-errors:prim-ty-hack, r=ol…
Unrolled build for rust-lang#139127
bb1yd commentedon Jul 17, 2026
Should we close this issue?