filter visiblities when resolving in extern crate

This commit is contained in:
Jonas Schievink 2021-07-21 17:51:56 +02:00
parent e6a237e75c
commit 837eec8dab
6 changed files with 38 additions and 15 deletions

View File

@ -747,7 +747,9 @@ fn resolve_import(&self, module_id: LocalModuleId, import: &Import) -> PartialRe
if let Some(krate) = res.krate { if let Some(krate) = res.krate {
if krate != self.def_map.krate { if krate != self.def_map.krate {
return PartialResolvedImport::Resolved(def); return PartialResolvedImport::Resolved(
def.filter_visibility(|v| matches!(v, Visibility::Public)),
);
} }
} }

View File

@ -296,7 +296,7 @@ fn edition_2015_imports() {
use other_crate::FromLib; use other_crate::FromLib;
//- /lib.rs crate:other_crate edition:2018 //- /lib.rs crate:other_crate edition:2018
struct FromLib; pub struct FromLib;
"#, "#,
expect![[r#" expect![[r#"
crate crate
@ -371,7 +371,7 @@ fn extern_crate_rename() {
use alloc_crate::Arc; use alloc_crate::Arc;
//- /lib.rs crate:alloc //- /lib.rs crate:alloc
struct Arc; pub struct Arc;
"#, "#,
expect![[r#" expect![[r#"
crate crate
@ -397,7 +397,7 @@ fn extern_crate_rename_2015_edition() {
use alloc_crate::Arc; use alloc_crate::Arc;
//- /lib.rs crate:alloc //- /lib.rs crate:alloc
struct Arc; pub struct Arc;
"#, "#,
expect![[r#" expect![[r#"
crate crate
@ -476,13 +476,13 @@ fn no_std_prelude() {
//- /core.rs crate:core //- /core.rs crate:core
pub mod prelude { pub mod prelude {
pud mod rust_2018 { pub mod rust_2018 {
pub struct Rust; pub struct Rust;
} }
} }
//- /std.rs crate:std deps:core //- /std.rs crate:std deps:core
pub mod prelude { pub mod prelude {
pud mod rust_2018 { pub mod rust_2018 {
} }
} }
"#, "#,
@ -505,7 +505,7 @@ fn edition_specific_preludes() {
//- /std.rs crate:std //- /std.rs crate:std
pub mod prelude { pub mod prelude {
pud mod rust_2018 { pub mod rust_2018 {
pub struct Rust2018; pub struct Rust2018;
} }
} }
@ -522,7 +522,7 @@ pub mod prelude {
//- /std.rs crate:std //- /std.rs crate:std
pub mod prelude { pub mod prelude {
pud mod rust_2021 { pub mod rust_2021 {
pub struct Rust2021; 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
"#]],
)
}

View File

@ -607,8 +607,8 @@ macro_rules! not_current2 {
} }
} }
struct Bar; pub struct Bar;
struct Baz; pub struct Baz;
"#, "#,
expect![[r#" expect![[r#"
crate crate

View File

@ -27,7 +27,7 @@ fn test() {
} //^ (i32, {unknown}, i32, {unknown}) } //^ (i32, {unknown}, i32, {unknown})
//- /foo.rs crate:foo //- /foo.rs crate:foo
struct S; pub struct S;
#[cfg(not(test))] #[cfg(not(test))]
impl S { impl S {

View File

@ -256,8 +256,8 @@ fn test() {
} //^ i128 } //^ i128
//- /lib.rs crate:other_crate //- /lib.rs crate:other_crate
mod foo { pub mod foo {
struct S; pub struct S;
impl S { impl S {
fn thing() -> i128 { 0 } fn thing() -> i128 { 0 }
} }

View File

@ -209,8 +209,8 @@ pub mod rust_2018 {
//- /alloc.rs crate:alloc deps:core //- /alloc.rs crate:alloc deps:core
#![no_std] #![no_std]
mod collections { pub mod collections {
struct Vec<T> {} pub struct Vec<T> {}
impl<T> Vec<T> { impl<T> Vec<T> {
pub fn new() -> Self { Vec {} } pub fn new() -> Self { Vec {} }
pub fn push(&mut self, t: T) { } pub fn push(&mut self, t: T) { }