Skip to content

Commit 06b0cbf

Browse files
Merge #9662
9662: fix: filter visiblities when resolving in extern crate r=jonas-schievink a=jonas-schievink Fixes #9650 Also fixes a bunch of incorrect tests that were importing private items. bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents e6a237e + 837eec8 commit 06b0cbf

File tree

6 files changed

+38
-15
lines changed

6 files changed

+38
-15
lines changed

crates/hir_def/src/nameres/collector.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,9 @@ impl DefCollector<'_> {
747747

748748
if let Some(krate) = res.krate {
749749
if krate != self.def_map.krate {
750-
return PartialResolvedImport::Resolved(def);
750+
return PartialResolvedImport::Resolved(
751+
def.filter_visibility(|v| matches!(v, Visibility::Public)),
752+
);
751753
}
752754
}
753755

crates/hir_def/src/nameres/tests.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ use bar::Bar;
296296
use other_crate::FromLib;
297297
298298
//- /lib.rs crate:other_crate edition:2018
299-
struct FromLib;
299+
pub struct FromLib;
300300
"#,
301301
expect![[r#"
302302
crate
@@ -371,7 +371,7 @@ mod sync;
371371
use alloc_crate::Arc;
372372
373373
//- /lib.rs crate:alloc
374-
struct Arc;
374+
pub struct Arc;
375375
"#,
376376
expect![[r#"
377377
crate
@@ -397,7 +397,7 @@ mod sync;
397397
use alloc_crate::Arc;
398398
399399
//- /lib.rs crate:alloc
400-
struct Arc;
400+
pub struct Arc;
401401
"#,
402402
expect![[r#"
403403
crate
@@ -476,13 +476,13 @@ fn no_std_prelude() {
476476
477477
//- /core.rs crate:core
478478
pub mod prelude {
479-
pud mod rust_2018 {
479+
pub mod rust_2018 {
480480
pub struct Rust;
481481
}
482482
}
483483
//- /std.rs crate:std deps:core
484484
pub mod prelude {
485-
pud mod rust_2018 {
485+
pub mod rust_2018 {
486486
}
487487
}
488488
"#,
@@ -505,7 +505,7 @@ fn edition_specific_preludes() {
505505
506506
//- /std.rs crate:std
507507
pub mod prelude {
508-
pud mod rust_2018 {
508+
pub mod rust_2018 {
509509
pub struct Rust2018;
510510
}
511511
}
@@ -522,7 +522,7 @@ fn edition_specific_preludes() {
522522
523523
//- /std.rs crate:std
524524
pub mod prelude {
525-
pud mod rust_2021 {
525+
pub mod rust_2021 {
526526
pub struct Rust2021;
527527
}
528528
}
@@ -839,3 +839,24 @@ use self::m::S::{self};
839839
"#]],
840840
);
841841
}
842+
843+
#[test]
844+
fn import_from_extern_crate_only_imports_public_items() {
845+
check(
846+
r#"
847+
//- /lib.rs crate:lib deps:settings,macros
848+
use macros::settings;
849+
use settings::Settings;
850+
//- /settings.rs crate:settings
851+
pub struct Settings;
852+
//- /macros.rs crate:macros
853+
mod settings {}
854+
pub const settings: () = ();
855+
"#,
856+
expect![[r#"
857+
crate
858+
Settings: t v
859+
settings: v
860+
"#]],
861+
)
862+
}

crates/hir_def/src/nameres/tests/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ macro_rules! not_current2 {
607607
}
608608
}
609609
610-
struct Bar;
611-
struct Baz;
610+
pub struct Bar;
611+
pub struct Baz;
612612
"#,
613613
expect![[r#"
614614
crate

crates/hir_ty/src/tests/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn test() {
2727
} //^ (i32, {unknown}, i32, {unknown})
2828
2929
//- /foo.rs crate:foo
30-
struct S;
30+
pub struct S;
3131
3232
#[cfg(not(test))]
3333
impl S {

crates/hir_ty/src/tests/method_resolution.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ fn test() {
256256
} //^ i128
257257
258258
//- /lib.rs crate:other_crate
259-
mod foo {
260-
struct S;
259+
pub mod foo {
260+
pub struct S;
261261
impl S {
262262
fn thing() -> i128 { 0 }
263263
}

crates/hir_ty/src/tests/traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ pub mod prelude {
209209
210210
//- /alloc.rs crate:alloc deps:core
211211
#![no_std]
212-
mod collections {
213-
struct Vec<T> {}
212+
pub mod collections {
213+
pub struct Vec<T> {}
214214
impl<T> Vec<T> {
215215
pub fn new() -> Self { Vec {} }
216216
pub fn push(&mut self, t: T) { }

0 commit comments

Comments
 (0)