Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "submodule_visibility"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "submodule_visibility"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
library;

// other is a submodule that declares a private submodule lib
// lib contains a declaration of the public struct S, but since lib is private it is not visible here.
// It is visible inside other, though.
pub mod other;

// lib is private, and not a direct submodule of the current module, so this should fail
use other::lib::S;

pub fn foo() {
let my_struct = S { val: 0 };

// lib is private, and not a direct submodule of the current module, so this should fail
let my_other_struct = lib::T { val: 1 };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
library;

mod lib; // private submodule

// lib is private, but since it is a direct submodule we can access its public items.
use lib::S;

// Public function
pub fn foo() {
let my_struct = S { val: 0 };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
library;

pub struct S {
pub val: u64,
}

pub struct T {
pub val: u64,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
category = "fail"

# check: $()error
# check: $()Module "lib" is private.

# check: $()error
# check: $()Module "lib" could not be found.

# check: $()Aborting due to 2 errors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "submodule_visibility"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "submodule_visibility"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
library;

// other is a submodule that declares a private submodule lib
// lib contains a declaration of the public struct S, but since lib is private it is not visible here.
// It is visible inside other, though.
pub mod other;

// other reexports other::lib::U, so we can access it as other::U
use other::U;

// Public function
pub fn foo() {
let my_struct = U { val: 0 };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
library;

mod lib; // private submodule

// lib is private, but since it is a direct submodule we can access its public items.
use lib::S;

// lib is private, but since it is a direct submodule we can access its public items.
// Reexporting it makes it visible from here, but not from lib
pub use lib::U;

// Public function
pub fn foo() {
let my_struct = S { val: 0 };

// lib is private, but since it is a direct submodule we can access its public items.
let my_other_struct = lib::T { val: 1 };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
library;

pub struct S {
pub val: u64,
}

pub struct T {
pub val: u64,
}

pub struct U {
pub val: u64,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
category = "compile"
expected_warnings = 3
Loading