Skip to content

Commit a4adc00

Browse files
authored
Rollup merge of #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 #139095 (comment)
2 parents c580c49 + 18c787f commit a4adc00

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

compiler/rustc_resolve/src/late.rs

+5
Original file line numberDiff line numberDiff line change
@@ -4606,6 +4606,11 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
46064606
}
46074607
};
46084608

4609+
// Fix up partial res of segment from `resolve_path` call.
4610+
if let Some(id) = path[0].id {
4611+
self.r.partial_res_map.insert(id, PartialRes::new(Res::PrimTy(prim)));
4612+
}
4613+
46094614
PartialRes::with_unresolved_segments(Res::PrimTy(prim), path.len() - 1)
46104615
}
46114616
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {

tests/ui/resolve/auxiliary/empty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Intentionally empty.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ aux-build: empty.rs
2+
3+
extern crate empty as usize;
4+
5+
fn foo() -> usize<()> { 0 }
6+
//~^ ERROR type arguments are not allowed on builtin type `usize`
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0109]: type arguments are not allowed on builtin type `usize`
2+
--> $DIR/prim-crate-partial-res.rs:5:19
3+
|
4+
LL | fn foo() -> usize<()> { 0 }
5+
| ----- ^^ type argument not allowed
6+
| |
7+
| not allowed on builtin type `usize`
8+
|
9+
help: primitive type `usize` doesn't have generic parameters
10+
|
11+
LL - fn foo() -> usize<()> { 0 }
12+
LL + fn foo() -> usize { 0 }
13+
|
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0109`.

0 commit comments

Comments
 (0)