Skip to content

Commit 7ad7232

Browse files
committed
Auto merge of #38375 - petrochenkov:prim, r=eddyb
Fix regression in resolution of primitive types Fix often encountered ICE. Extracted from #38154 Fixes #38155, fixes #38188, fixes #38277, fixes #38280, fixes #38292, fixes #38311, fixes #38344, fixes #38363, fixes #38372 (duplicates) r? @jseyfried or @eddyb or @nrc
2 parents 52e024f + 0157e6c commit 7ad7232

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/librustc_resolve/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ impl<'a> LexicalScopeBinding<'a> {
754754
}
755755
}
756756

757-
#[derive(Copy, Clone)]
757+
#[derive(Copy, Clone, PartialEq)]
758758
enum PathScope {
759759
Global,
760760
Lexical,
@@ -2292,7 +2292,9 @@ impl<'a> Resolver<'a> {
22922292
//
22932293
// Such behavior is required for backward compatibility.
22942294
// The same fallback is used when `a` resolves to nothing.
2295-
_ if self.primitive_type_table.primitive_types.contains_key(&path[0].name) => {
2295+
PathResult::Module(..) | PathResult::Failed(..)
2296+
if scope == PathScope::Lexical && (ns == TypeNS || path.len() > 1) &&
2297+
self.primitive_type_table.primitive_types.contains_key(&path[0].name) => {
22962298
PathResolution {
22972299
base_def: Def::PrimTy(self.primitive_type_table.primitive_types[&path[0].name]),
22982300
depth: segments.len() - 1,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
// Make sure primitive type fallback doesn't work in value namespace
13+
std::mem::size_of(u16);
14+
//~^ ERROR unresolved name `u16`
15+
//~| ERROR this function takes 0 parameters but 1 parameter was supplied
16+
17+
// Make sure primitive type fallback doesn't work with global paths
18+
let _: ::u8;
19+
//~^ ERROR type name `u8` is undefined or not in scope
20+
}

0 commit comments

Comments
 (0)