filter visiblities when resolving in extern crate
This commit is contained in:
parent
e6a237e75c
commit
837eec8dab
@ -747,7 +747,9 @@ fn resolve_import(&self, module_id: LocalModuleId, import: &Import) -> PartialRe
|
||||
|
||||
if let Some(krate) = res.krate {
|
||||
if krate != self.def_map.krate {
|
||||
return PartialResolvedImport::Resolved(def);
|
||||
return PartialResolvedImport::Resolved(
|
||||
def.filter_visibility(|v| matches!(v, Visibility::Public)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,7 +296,7 @@ fn edition_2015_imports() {
|
||||
use other_crate::FromLib;
|
||||
|
||||
//- /lib.rs crate:other_crate edition:2018
|
||||
struct FromLib;
|
||||
pub struct FromLib;
|
||||
"#,
|
||||
expect![[r#"
|
||||
crate
|
||||
@ -371,7 +371,7 @@ fn extern_crate_rename() {
|
||||
use alloc_crate::Arc;
|
||||
|
||||
//- /lib.rs crate:alloc
|
||||
struct Arc;
|
||||
pub struct Arc;
|
||||
"#,
|
||||
expect![[r#"
|
||||
crate
|
||||
@ -397,7 +397,7 @@ fn extern_crate_rename_2015_edition() {
|
||||
use alloc_crate::Arc;
|
||||
|
||||
//- /lib.rs crate:alloc
|
||||
struct Arc;
|
||||
pub struct Arc;
|
||||
"#,
|
||||
expect![[r#"
|
||||
crate
|
||||
@ -476,13 +476,13 @@ fn no_std_prelude() {
|
||||
|
||||
//- /core.rs crate:core
|
||||
pub mod prelude {
|
||||
pud mod rust_2018 {
|
||||
pub mod rust_2018 {
|
||||
pub struct Rust;
|
||||
}
|
||||
}
|
||||
//- /std.rs crate:std deps:core
|
||||
pub mod prelude {
|
||||
pud mod rust_2018 {
|
||||
pub mod rust_2018 {
|
||||
}
|
||||
}
|
||||
"#,
|
||||
@ -505,7 +505,7 @@ fn edition_specific_preludes() {
|
||||
|
||||
//- /std.rs crate:std
|
||||
pub mod prelude {
|
||||
pud mod rust_2018 {
|
||||
pub mod rust_2018 {
|
||||
pub struct Rust2018;
|
||||
}
|
||||
}
|
||||
@ -522,7 +522,7 @@ pub mod prelude {
|
||||
|
||||
//- /std.rs crate:std
|
||||
pub mod prelude {
|
||||
pud mod rust_2021 {
|
||||
pub mod rust_2021 {
|
||||
pub struct Rust2021;
|
||||
}
|
||||
}
|
||||
@ -839,3 +839,24 @@ mod m {
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn import_from_extern_crate_only_imports_public_items() {
|
||||
check(
|
||||
r#"
|
||||
//- /lib.rs crate:lib deps:settings,macros
|
||||
use macros::settings;
|
||||
use settings::Settings;
|
||||
//- /settings.rs crate:settings
|
||||
pub struct Settings;
|
||||
//- /macros.rs crate:macros
|
||||
mod settings {}
|
||||
pub const settings: () = ();
|
||||
"#,
|
||||
expect![[r#"
|
||||
crate
|
||||
Settings: t v
|
||||
settings: v
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
|
@ -607,8 +607,8 @@ macro_rules! not_current2 {
|
||||
}
|
||||
}
|
||||
|
||||
struct Bar;
|
||||
struct Baz;
|
||||
pub struct Bar;
|
||||
pub struct Baz;
|
||||
"#,
|
||||
expect![[r#"
|
||||
crate
|
||||
|
@ -27,7 +27,7 @@ fn test() {
|
||||
} //^ (i32, {unknown}, i32, {unknown})
|
||||
|
||||
//- /foo.rs crate:foo
|
||||
struct S;
|
||||
pub struct S;
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl S {
|
||||
|
@ -256,8 +256,8 @@ fn test() {
|
||||
} //^ i128
|
||||
|
||||
//- /lib.rs crate:other_crate
|
||||
mod foo {
|
||||
struct S;
|
||||
pub mod foo {
|
||||
pub struct S;
|
||||
impl S {
|
||||
fn thing() -> i128 { 0 }
|
||||
}
|
||||
|
@ -209,8 +209,8 @@ pub mod rust_2018 {
|
||||
|
||||
//- /alloc.rs crate:alloc deps:core
|
||||
#![no_std]
|
||||
mod collections {
|
||||
struct Vec<T> {}
|
||||
pub mod collections {
|
||||
pub struct Vec<T> {}
|
||||
impl<T> Vec<T> {
|
||||
pub fn new() -> Self { Vec {} }
|
||||
pub fn push(&mut self, t: T) { }
|
||||
|
Loading…
Reference in New Issue
Block a user