Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add "-Zpublic-denpendency" for public-dependency feature.
Browse files Browse the repository at this point in the history
linyihai committed Jan 18, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent c061bfb commit 8a2bc71
Showing 30 changed files with 199 additions and 213 deletions.
12 changes: 2 additions & 10 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ use crate::core::compiler::future_incompat::FutureIncompatReport;
pub use crate::core::compiler::unit::{Unit, UnitInterner};
use crate::core::manifest::TargetSourcePath;
use crate::core::profiles::{PanicStrategy, Profile, StripInner};
use crate::core::{Feature, PackageId, Target, Verbosity};
use crate::core::{PackageId, Target, Verbosity};
use crate::util::errors::{CargoResult, VerboseError};
use crate::util::interning::InternedString;
use crate::util::machine_message::{self, Message};
@@ -1437,15 +1437,7 @@ pub fn extern_args(
|dep: &UnitDep, extern_crate_name: InternedString, noprelude: bool| -> CargoResult<()> {
let mut value = OsString::new();
let mut opts = Vec::new();
if unit
.pkg
.manifest()
.unstable_features()
.require(Feature::public_dependency())
.is_ok()
&& !dep.public
&& unit.target.is_lib()
{
if !dep.public && unit.target.is_lib() {
opts.push("priv");
*unstable_opts = true;
}
5 changes: 2 additions & 3 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
@@ -458,9 +458,6 @@ features! {
/// Declarative build scripts.
(unstable, metabuild, "", "reference/unstable.html#metabuild"),

/// Specifying the 'public' attribute on dependencies.
(unstable, public_dependency, "", "reference/unstable.html#public-dependency"),

/// Allow to specify profiles other than 'dev', 'release', 'test', etc.
(stable, named_profiles, "1.57", "reference/profiles.html#custom-profiles"),

@@ -764,6 +761,7 @@ unstable_cli_options!(
panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"),
precise_pre_release: bool = ("Enable pre-release versions to be selected with `update --precise`"),
profile_rustflags: bool = ("Enable the `rustflags` option in profiles in .cargo/config.toml file"),
public_dependency: bool = ("Enable public-dependency to allow marking dependencies as public/private"),
publish_timeout: bool = ("Enable the `publish.timeout` key in .cargo/config.toml file"),
rustdoc_map: bool = ("Allow passing external documentation mappings to rustdoc"),
rustdoc_scrape_examples: bool = ("Allows Rustdoc to scrape code examples from reverse-dependencies"),
@@ -1140,6 +1138,7 @@ impl CliUnstable {
"mtime-on-use" => self.mtime_on_use = parse_empty(k, v)?,
"no-index-update" => self.no_index_update = parse_empty(k, v)?,
"panic-abort-tests" => self.panic_abort_tests = parse_empty(k, v)?,
"public-dependency" => self.public_dependency = parse_empty(k, v)?,
"profile-rustflags" => self.profile_rustflags = parse_empty(k, v)?,
"precise-pre-release" => self.precise_pre_release = parse_empty(k, v)?,
"trim-paths" => self.trim_paths = parse_empty(k, v)?,
1 change: 0 additions & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
@@ -449,7 +449,6 @@ impl<'cfg> Workspace<'cfg> {
// NOTE: Since we use ConfigRelativePath, this root isn't used as
// any relative paths are resolved before they'd be joined with root.
Path::new("unused-relative-path"),
self.unstable_features(),
/* kind */ None,
)
})
17 changes: 2 additions & 15 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@ use crate::core::compiler::{BuildConfig, CompileMode, DefaultExecutor, Executor}
use crate::core::manifest::Target;
use crate::core::resolver::CliFeatures;
use crate::core::{registry::PackageRegistry, resolver::HasDevUnits};
use crate::core::{Feature, Shell, Verbosity, Workspace};
use crate::core::{Package, PackageId, PackageSet, Resolve, SourceId};
use crate::core::{Shell, Verbosity, Workspace};
use crate::sources::PathSource;
use crate::util::cache_lock::CacheLockMode;
use crate::util::config::JobsConfig;
@@ -910,20 +910,7 @@ fn run_verify(
let new_pkg = src.root_package()?;
let pkg_fingerprint = hash_all(&dst)?;
let ws = Workspace::ephemeral(new_pkg, config, None, true)?;

let rustc_args = if pkg
.manifest()
.unstable_features()
.require(Feature::public_dependency())
.is_ok()
{
// FIXME: Turn this on at some point in the future
//Some(vec!["-D exported_private_dependencies".to_string()])
Some(vec![])
} else {
None
};

let rustc_args = Some(vec![]);
let exec: Arc<dyn Executor> = Arc::new(DefaultExecutor);
ops::compile_with_exec(
&ws,
140 changes: 79 additions & 61 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@ use crate::AlreadyPrintedError;
use anyhow::{anyhow, bail, Context as _};
use cargo_platform::Platform;
use cargo_util::paths;
use cargo_util_schemas::manifest;
use cargo_util_schemas::manifest::RustVersion;
use cargo_util_schemas::manifest::{self, InheritableDependency};
use cargo_util_schemas::manifest::{RustVersion, TomlDependency};
use itertools::Itertools;
use lazycell::LazyCell;
use pathdiff::diff_paths;
@@ -105,61 +105,62 @@ fn read_manifest_from_str(

let mut unused = BTreeSet::new();
let deserializer = toml::de::Deserializer::new(contents);
let manifest: manifest::TomlManifest = match serde_ignored::deserialize(deserializer, |path| {
let mut key = String::new();
stringify(&mut key, &path);
unused.insert(key);
}) {
Ok(manifest) => manifest,
Err(e) => {
let Some(span) = e.span() else {
return Err(e.into());
};
let mut manifest: manifest::TomlManifest =
match serde_ignored::deserialize(deserializer, |path| {
let mut key = String::new();
stringify(&mut key, &path);
unused.insert(key);
}) {
Ok(manifest) => manifest,
Err(e) => {
let Some(span) = e.span() else {
return Err(e.into());
};

let (line_num, column) = translate_position(&contents, span.start);
let source_start = contents[0..span.start]
.rfind('\n')
.map(|s| s + 1)
.unwrap_or(0);
let source_end = contents[span.end - 1..]
.find('\n')
.map(|s| s + span.end)
.unwrap_or(contents.len());
let source = &contents[source_start..source_end];
// Make sure we don't try to highlight past the end of the line,
// but also make sure we are highlighting at least one character
let highlight_end = (column + contents[span].chars().count())
.min(source.len())
.max(column + 1);
// Get the path to the manifest, relative to the cwd
let manifest_path = diff_paths(manifest_file, config.cwd())
.unwrap_or_else(|| manifest_file.to_path_buf())
.display()
.to_string();
let snippet = Snippet {
title: Some(Annotation {
id: None,
label: Some(e.message()),
annotation_type: AnnotationType::Error,
}),
footer: vec![],
slices: vec![Slice {
source: &source,
line_start: line_num + 1,
origin: Some(manifest_path.as_str()),
annotations: vec![SourceAnnotation {
range: (column, highlight_end),
label: "",
let (line_num, column) = translate_position(&contents, span.start);
let source_start = contents[0..span.start]
.rfind('\n')
.map(|s| s + 1)
.unwrap_or(0);
let source_end = contents[span.end - 1..]
.find('\n')
.map(|s| s + span.end)
.unwrap_or(contents.len());
let source = &contents[source_start..source_end];
// Make sure we don't try to highlight past the end of the line,
// but also make sure we are highlighting at least one character
let highlight_end = (column + contents[span].chars().count())
.min(source.len())
.max(column + 1);
// Get the path to the manifest, relative to the cwd
let manifest_path = diff_paths(manifest_file, config.cwd())
.unwrap_or_else(|| manifest_file.to_path_buf())
.display()
.to_string();
let snippet = Snippet {
title: Some(Annotation {
id: None,
label: Some(e.message()),
annotation_type: AnnotationType::Error,
}),
footer: vec![],
slices: vec![Slice {
source: &source,
line_start: line_num + 1,
origin: Some(manifest_path.as_str()),
annotations: vec![SourceAnnotation {
range: (column, highlight_end),
label: "",
annotation_type: AnnotationType::Error,
}],
fold: false,
}],
fold: false,
}],
};
let renderer = Renderer::styled();
writeln!(config.shell().err(), "{}", renderer.render(snippet))?;
return Err(AlreadyPrintedError::new(e.into()).into());
}
};
};
let renderer = Renderer::styled();
writeln!(config.shell().err(), "{}", renderer.render(snippet))?;
return Err(AlreadyPrintedError::new(e.into()).into());
}
};
let add_unused = |warnings: &mut Warnings| {
for key in unused {
warnings.add_warning(format!("unused manifest key: {}", key));
@@ -183,10 +184,33 @@ fn read_manifest_from_str(
}
}
}

let mut public_deps_without_z = BTreeSet::new();
if let Some(deps) = &mut manifest.dependencies {
for (name, dep) in deps {
if let InheritableDependency::Value(toml_dep) = dep {
if toml_dep.is_public() && !config.cli_unstable().public_dependency {
if let TomlDependency::Detailed(d) = toml_dep {
d.public = Some(false)
}
public_deps_without_z.insert(name.clone());
}
}
}
}
let public_warn = |warnings: &mut Warnings| {
for name in public_deps_without_z {
warnings.add_warning(format!(
"{name} is public, pass `-Zpublic-dependency` to enable support for it",
))
}
};

return if manifest.project.is_some() || manifest.package.is_some() {
let (mut manifest, paths) =
to_real_manifest(manifest, embedded, source_id, package_root, config)?;
add_unused(manifest.warnings_mut());
public_warn(manifest.warnings_mut());
if manifest.targets().iter().all(|t| t.is_custom_build()) {
bail!(
"no targets specified in the manifest\n\
@@ -198,6 +222,7 @@ fn read_manifest_from_str(
} else {
let (mut m, paths) = to_virtual_manifest(manifest, source_id, package_root, config)?;
add_unused(m.warnings_mut());
public_warn(m.warnings_mut());
Ok((EitherManifest::Virtual(m), paths))
};

@@ -678,7 +703,6 @@ pub fn to_real_manifest(
nested_paths: &mut nested_paths,
config,
warnings: &mut warnings,
features: &features,
platform: None,
root: package_root,
};
@@ -1153,7 +1177,6 @@ fn to_virtual_manifest(
config,
warnings: &mut warnings,
platform: None,
features: &features,
root,
};
(replace(&me, &mut cx)?, patch(&me, &mut cx)?)
@@ -1302,7 +1325,6 @@ struct Context<'a, 'b> {
warnings: &'a mut Vec<String>,
platform: Option<Platform>,
root: &'a Path,
features: &'a Features,
}

fn verify_lints(lints: Option<manifest::TomlLints>) -> CargoResult<Option<manifest::TomlLints>> {
@@ -1709,7 +1731,6 @@ pub(crate) fn to_dependency<P: ResolveToPath + Clone>(
warnings: &mut Vec<String>,
platform: Option<Platform>,
root: &Path,
features: &Features,
kind: Option<DepKind>,
) -> CargoResult<Dependency> {
dep_to_dependency(
@@ -1723,7 +1744,6 @@ pub(crate) fn to_dependency<P: ResolveToPath + Clone>(
warnings,
platform,
root,
features,
},
kind,
)
@@ -1944,8 +1964,6 @@ fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
}

if let Some(p) = orig.public {
cx.features.require(Feature::public_dependency())?;

if dep.kind() != DepKind::Normal {
bail!("'public' specifier can only be used on regular dependencies, not {:?} dependencies", dep.kind());
}
4 changes: 1 addition & 3 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
@@ -296,11 +296,9 @@ The 'public-dependency' feature allows marking dependencies as 'public'
or 'private'. When this feature is enabled, additional information is passed to rustc to allow
the 'exported_private_dependencies' lint to function properly.

This requires the appropriate key to be set in `cargo-features`:
Pass `-Zpublic-dependency` to cargo to enable support for it.

```toml
cargo-features = ["public-dependency"]

[dependencies]
my_dep = { version = "1.2.3", public = true }
private_dep = "2.0.0" # Will be 'private' by default
6 changes: 5 additions & 1 deletion tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
@@ -2573,6 +2573,10 @@ fn with_assumed_host_target_and_optional_build_dep() {
.run();
}

// Since public-dependency had switched to non-blocking feature gate, (See https://github.com/rust-lang/cargo/issues/13308)
// this test case will warn "trait `c::Trait` from private dependency 'c' in public interface".
// The weird sutuation is that the warning "warning: `a` (lib) generated 1 warning (1 duplicate)" will appear randomly.
// Add #[allow(exported_private_dependencies)] to suppress it.
#[cargo_test]
fn decouple_same_target_transitive_dep_from_artifact_dep() {
// See https://github.com/rust-lang/cargo/issues/11463
@@ -2636,7 +2640,7 @@ fn decouple_same_target_transitive_dep_from_artifact_dep() {
"a/src/lib.rs",
r#"
use b::Trait as _;
#[allow(exported_private_dependencies)]
pub fn use_b_trait(x: &impl c::Trait) {
x.b();
}
11 changes: 7 additions & 4 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
@@ -1439,7 +1439,8 @@ fn cargo_default_env_metadata_env_var() {
-C extra-filename=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps \
--extern bar=[CWD]/target/debug/deps/{prefix}bar{suffix}`
--extern 'priv:bar=[CWD]/target/debug/deps/{prefix}bar{suffix}' \
-Z unstable-options`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
prefix = env::consts::DLL_PREFIX,
suffix = env::consts::DLL_SUFFIX,
@@ -1467,7 +1468,8 @@ fn cargo_default_env_metadata_env_var() {
-C extra-filename=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps \
--extern bar=[CWD]/target/debug/deps/{prefix}bar-[..]{suffix}`
--extern 'priv:bar=[CWD]/target/debug/deps/{prefix}bar-[..]{suffix}' \
-Z unstable-options`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
prefix = env::consts::DLL_PREFIX,
@@ -2445,8 +2447,9 @@ fn verbose_release_build_deps() {
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/release/deps \
--extern foo=[CWD]/target/release/deps/{prefix}foo{suffix} \
--extern foo=[CWD]/target/release/deps/libfoo.rlib`
--extern 'priv:foo=[CWD]/target/release/deps/{prefix}foo{suffix}' \
--extern 'priv:foo=[CWD]/target/release/deps/libfoo.rlib' \
-Z unstable-options`
[FINISHED] release [optimized] target(s) in [..]
",
prefix = env::consts::DLL_PREFIX,
2 changes: 1 addition & 1 deletion tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
@@ -3018,7 +3018,7 @@ fn diamond_passes_args_only_once() {
[COMPILING] a v0.5.0 ([..]
[RUNNING] `rustc [..]`
[COMPILING] foo v0.5.0 ([..]
[RUNNING] `[..]rmeta -L native=test`
[RUNNING] `[..] --extern 'priv:a=[..]rmeta' --extern 'priv:b=[..]rmeta' -Z unstable-options -L native=test`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
)
1 change: 1 addition & 0 deletions tests/testsuite/cargo/z_help/stdout.log
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ Available unstable (nightly-only) flags:
-Z panic-abort-tests Enable support to run tests with -Cpanic=abort
-Z precise-pre-release Enable pre-release versions to be selected with `update --precise`
-Z profile-rustflags Enable the `rustflags` option in profiles in .cargo/config.toml file
-Z public-dependency Enable public-dependency to allow marking dependencies as public/private
-Z publish-timeout Enable the `publish.timeout` key in .cargo/config.toml file
-Z rustdoc-map Allow passing external documentation mappings to rustdoc
-Z rustdoc-scrape-examples Allows Rustdoc to scrape code examples from reverse-dependencies
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[package]
name = "bar"
version = "0.0.0"
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[package]
name = "bar"
version = "0.0.0"
1 change: 0 additions & 1 deletion tests/testsuite/cargo_add/no_public/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[workspace]

[package]
1 change: 0 additions & 1 deletion tests/testsuite/cargo_add/no_public/out/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[workspace]

[package]
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[workspace]

[package]
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[workspace]

[package]
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[workspace]

[package]
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[workspace]

[package]
1 change: 0 additions & 1 deletion tests/testsuite/cargo_add/overwrite_public/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[workspace]

[package]
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/overwrite_public/mod.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ fn case() {

snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("my-package --public")
.arg_line("my-package --public -Zpublic-dependency")
.current_dir(cwd)
.masquerade_as_nightly_cargo(&["public-dependency"])
.assert()
1 change: 0 additions & 1 deletion tests/testsuite/cargo_add/overwrite_public/out/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[workspace]

[package]
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[workspace]

[package]
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ fn case() {

snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("my-package --no-public")
.arg_line("my-package --no-public -Zpublic-dependency")
.current_dir(cwd)
.masquerade_as_nightly_cargo(&["public-dependency"])
.assert()
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[workspace]

[package]
1 change: 0 additions & 1 deletion tests/testsuite/cargo_add/public/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[workspace]

[package]
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/public/mod.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ fn case() {

snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("my-package --public")
.arg_line("my-package --public -Zpublic-dependency")
.current_dir(cwd)
.masquerade_as_nightly_cargo(&["public-dependency"])
.assert()
1 change: 0 additions & 1 deletion tests/testsuite/cargo_add/public/out/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cargo-features = ["public-dependency"]
[workspace]

[package]
7 changes: 4 additions & 3 deletions tests/testsuite/profiles.rs
Original file line number Diff line number Diff line change
@@ -223,9 +223,10 @@ fn top_level_overrides_deps() {
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/release/deps \
--extern foo=[CWD]/target/release/deps/\
{prefix}foo[..]{suffix} \
--extern foo=[CWD]/target/release/deps/libfoo.rlib`
--extern 'priv:foo=[CWD]/target/release/deps/\
{prefix}foo[..]{suffix}' \
--extern 'priv:foo=[CWD]/target/release/deps/libfoo.rlib' \
-Z unstable-options`
[FINISHED] release [optimized + debuginfo] target(s) in [..]
",
prefix = env::consts::DLL_PREFIX,
182 changes: 90 additions & 92 deletions tests/testsuite/pub_priv.rs
Original file line number Diff line number Diff line change
@@ -13,8 +13,6 @@ fn exported_priv_warning() {
.file(
"Cargo.toml",
r#"
cargo-features = ["public-dependency"]
[package]
name = "foo"
version = "0.0.1"
@@ -52,8 +50,6 @@ fn exported_pub_dep() {
.file(
"Cargo.toml",
r#"
cargo-features = ["public-dependency"]
[package]
name = "foo"
version = "0.0.1"
@@ -71,7 +67,7 @@ fn exported_pub_dep() {
)
.build();

p.cargo("check --message-format=short")
p.cargo("check -Zpublic-dependency --message-format=short")
.masquerade_as_nightly_cargo(&["public-dependency"])
.with_stderr(
"\
@@ -86,75 +82,6 @@ fn exported_pub_dep() {
.run()
}

#[cargo_test]
pub fn requires_nightly_cargo() {
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["public-dependency"]
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("check --message-format=short")
.with_status(101)
.with_stderr(
"\
error: failed to parse manifest at `[..]`
Caused by:
the cargo feature `public-dependency` requires a nightly version of Cargo, but this is the `stable` channel
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
See https://doc.rust-lang.org/[..]cargo/reference/unstable.html#public-dependency for more information about using this feature.
"
)
.run()
}

#[cargo_test]
fn requires_feature() {
Package::new("pub_dep", "0.1.0")
.file("src/lib.rs", "")
.publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
[dependencies]
pub_dep = { version = "0.1.0", public = true }
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("check --message-format=short")
.masquerade_as_nightly_cargo(&["public-dependency"])
.with_status(101)
.with_stderr(
"\
error: failed to parse manifest at `[..]`
Caused by:
feature `public-dependency` is required
The package requires the Cargo feature called `public-dependency`, \
but that feature is not stabilized in this version of Cargo (1.[..]).
Consider adding `cargo-features = [\"public-dependency\"]` to the top of Cargo.toml \
(above the [package] table) to tell Cargo you are opting in to use this unstable feature.
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency \
for more information about the status of this feature.
",
)
.run()
}

#[cargo_test]
fn pub_dev_dependency() {
Package::new("pub_dep", "0.1.0")
@@ -165,8 +92,6 @@ fn pub_dev_dependency() {
.file(
"Cargo.toml",
r#"
cargo-features = ["public-dependency"]
[package]
name = "foo"
version = "0.0.1"
@@ -184,7 +109,7 @@ fn pub_dev_dependency() {
)
.build();

p.cargo("check --message-format=short")
p.cargo("check -Zpublic-dependency --message-format=short")
.masquerade_as_nightly_cargo(&["public-dependency"])
.with_status(101)
.with_stderr(
@@ -214,8 +139,6 @@ fn workspace_pub_disallowed() {
.file(
"Cargo.toml",
r#"
cargo-features = ["public-dependency"]
[package]
name = "foo"
version = "0.0.1"
@@ -266,8 +189,6 @@ fn allow_priv_in_tests() {
.file(
"Cargo.toml",
r#"
cargo-features = ["public-dependency"]
[package]
name = "foo"
version = "0.0.1"
@@ -310,8 +231,6 @@ fn allow_priv_in_benchs() {
.file(
"Cargo.toml",
r#"
cargo-features = ["public-dependency"]
[package]
name = "foo"
version = "0.0.1"
@@ -354,8 +273,6 @@ fn allow_priv_in_bins() {
.file(
"Cargo.toml",
r#"
cargo-features = ["public-dependency"]
[package]
name = "foo"
version = "0.0.1"
@@ -399,8 +316,6 @@ fn allow_priv_in_examples() {
.file(
"Cargo.toml",
r#"
cargo-features = ["public-dependency"]
[package]
name = "foo"
version = "0.0.1"
@@ -444,8 +359,6 @@ fn allow_priv_in_custom_build() {
.file(
"Cargo.toml",
r#"
cargo-features = ["public-dependency"]
[package]
name = "foo"
version = "0.0.1"
@@ -486,7 +399,6 @@ fn publish_package_with_public_dependency() {
.file("src/lib.rs", "pub struct FromPub;")
.publish();
Package::new("bar", "0.1.0")
.cargo_feature("public-dependency")
.add_dep(Dependency::new("pub_bar", "0.1.0").public(true))
.file(
"src/lib.rs",
@@ -501,7 +413,6 @@ fn publish_package_with_public_dependency() {
.file(
"Cargo.toml",
r#"
cargo-features = ["public-dependency"]
[package]
name = "foo"
version = "0.0.1"
@@ -518,7 +429,7 @@ fn publish_package_with_public_dependency() {
)
.build();

p.cargo("check --message-format=short")
p.cargo("check -Zpublic-dependency --message-format=short")
.masquerade_as_nightly_cargo(&["public-dependency"])
.with_stderr(
"\
@@ -534,3 +445,90 @@ fn publish_package_with_public_dependency() {
)
.run()
}

#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
fn exported_pub_dep_without_z_public_dependency() {
Package::new("pub_dep", "0.1.0")
.file("src/lib.rs", "pub struct FromPub;")
.publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
[dependencies]
pub_dep = {version = "0.1.0", public = true}
"#,
)
.file(
"src/lib.rs",
"
extern crate pub_dep;
pub fn use_pub(_: pub_dep::FromPub) {}
",
)
.build();

p.cargo("check --message-format=short")
.masquerade_as_nightly_cargo(&["public-dependency"])
.with_stderr(
"\
[..]pub_dep is public, pass `-Zpublic-dependency` to enable support for it
[UPDATING] `[..]` index
[DOWNLOADING] crates ...
[DOWNLOADED] pub_dep v0.1.0 ([..])
[CHECKING] pub_dep v0.1.0
[CHECKING] foo v0.0.1 ([CWD])
src/lib.rs:3:13: warning: type `[..]FromPub` from private dependency 'pub_dep' in public interface
[WARNING] `foo` (lib) generated 1 warning
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
)
.run();
}

#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
fn exported_pub_dep_with_z_public_dependency() {
Package::new("pub_dep", "0.1.0")
.file("src/lib.rs", "pub struct FromPub;")
.publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
[dependencies]
pub_dep = {version = "0.1.0", public = true}
"#,
)
.file(
"src/lib.rs",
"
extern crate pub_dep;
pub fn use_pub(_: pub_dep::FromPub) {}
",
)
.build();

p.cargo("check -Zpublic-dependency --message-format=short")
.masquerade_as_nightly_cargo(&["public-dependency"])
.with_stderr(
"\
[UPDATING] `[..]` index
[DOWNLOADING] crates ...
[DOWNLOADED] pub_dep v0.1.0 ([..])
[CHECKING] pub_dep v0.1.0
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
)
.run();
}
4 changes: 2 additions & 2 deletions tests/testsuite/rename_deps.rs
Original file line number Diff line number Diff line change
@@ -268,8 +268,8 @@ fn can_run_doc_tests() {
[DOCTEST] foo
[RUNNING] `rustdoc [..]--test [..]src/lib.rs \
[..] \
--extern bar=[CWD]/target/debug/deps/libbar-[..].rlib \
--extern baz=[CWD]/target/debug/deps/libbar-[..].rlib \
--extern 'priv:bar=[CWD]/target/debug/deps/libbar-[..].rlib' \
--extern 'priv:baz=[CWD]/target/debug/deps/libbar-[..].rlib' \
[..]`
",
)

0 comments on commit 8a2bc71

Please sign in to comment.