Skip to content

Commit 7832643

Browse files
petrochenkovpietroalbini
authored andcommitted
resolve: Reject some inaccessible candidates sooner during import resolution
This allows import resolution to progress in cases like #53140
1 parent d0026ee commit 7832643

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Diff for: src/librustc_resolve/resolve_imports.rs

+5
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ impl<'a> Resolver<'a> {
203203
};
204204
match self.resolve_ident_in_module(module, ident, ns, false, path_span) {
205205
Err(Determined) => continue,
206+
Ok(binding)
207+
if !self.is_accessible_from(binding.vis, single_import.parent) => continue,
206208
Ok(_) | Err(Undetermined) => return Err(Undetermined),
207209
}
208210
}
@@ -255,8 +257,11 @@ impl<'a> Resolver<'a> {
255257
module, ident, ns, false, false, path_span,
256258
);
257259
self.current_module = orig_current_module;
260+
258261
match result {
259262
Err(Determined) => continue,
263+
Ok(binding)
264+
if !self.is_accessible_from(binding.vis, glob_import.parent) => continue,
260265
Ok(_) | Err(Undetermined) => return Err(Undetermined),
261266
}
262267
}

Diff for: src/test/ui/imports/issue-53140.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 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+
// compile-pass
12+
13+
mod m {
14+
pub struct S(u8);
15+
16+
use S as Z;
17+
}
18+
19+
use m::*;
20+
21+
fn main() {}

0 commit comments

Comments
 (0)