From 354cd752de1083d63b8ba2baf293167dac3ccf66 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 19 Nov 2026 13:38:21 -0800 Subject: [PATCH 1/3] ffi: resolve an exclude's crate path when checking what a cfg left out configured_out resolved a path only from the facade's root, so an exclude naming a type by its defining crate's path, the form the walk counts a type no facade module re-exports under, refused on a build whose cfg drops it, as moq_tokio::server::Streams::unix does on Windows. Co-Authored-By: Claude Opus 5.5 --- ffi/src/driver.rs | 19 ++++++++++++++----- ffi/tests/fixtures.rs | 11 ++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ffi/src/driver.rs b/ffi/src/driver.rs index 04eb7ccd9..c07e0ca7a 100644 --- a/ffi/src/driver.rs +++ b/ffi/src/driver.rs @@ -701,14 +701,23 @@ fn parse_item(tcx: TyCtxt<'_>, source: &str) -> Option> { } } -/// Whether `path`, from the facade's root, names an item a `cfg` leaves out of this build, -/// or a field or variant of one: the config names it for the builds that have it. Its first -/// segment no module has is stripped from that module or from one the module -/// glob-re-exports. +/// Whether `path` names an item a `cfg` leaves out of this build, or a field or variant of +/// one: the config names it for the builds that have it. The path runs from the facade's +/// root, or from a crate's by its name, as the walk names a type no facade module +/// re-exports. fn configured_out(tcx: TyCtxt<'_>, path: &str) -> bool { let path = path.strip_prefix("field@").unwrap_or(path); let segments: Vec<&str> = path.split("::").collect(); - let mut module = LOCAL_CRATE.as_def_id(); + // Any crate of the name, since a build may link several of its versions. + let mut krates = tcx.crates(()).iter().filter(|&&k| tcx.crate_name(k).as_str() == segments[0]); + stripped_under(tcx, LOCAL_CRATE.as_def_id(), &segments) + || krates.any(|&k| stripped_under(tcx, k.as_def_id(), &segments[1..])) +} + +/// Whether `segments`, from `module`, name an item a `cfg` strips, or a field or variant of +/// one. Its first segment no module has is stripped from that module or from one the module +/// glob-re-exports. +fn stripped_under(tcx: TyCtxt<'_>, mut module: DefId, segments: &[&str]) -> bool { for (i, segment) in segments.iter().enumerate() { let name = segment.split('<').next().unwrap_or(segment); let children = match module.as_local() { diff --git a/ffi/tests/fixtures.rs b/ffi/tests/fixtures.rs index 1efc53339..c581fbb95 100644 --- a/ffi/tests/fixtures.rs +++ b/ffi/tests/fixtures.rs @@ -3636,9 +3636,9 @@ fn foreign_role_names() { /// An exclude may name what a `cfg` leaves out of this build, whether the facade's own /// module or another crate's that the facade re-exports through a glob, or a chain of them, /// or a field or variant of the facade's or another crate's type, under a `cfg` or one a -/// `cfg_attr` adds, an inline module's type and a const-generic one's included, but not -/// what no build has, nor what a module only some of whose items the facade re-exports -/// leaves out. +/// `cfg_attr` adds, an inline module's type and a const-generic one's included, and by the +/// defining crate's path as well as the facade's, but not what no build has, nor what a +/// module only some of whose items the facade re-exports leaves out. #[test] fn configured_out() { let package = package("configured_out", &[]); @@ -3654,7 +3654,7 @@ fn configured_out() { ("Cargo.toml", &manifest), ( "src/lib.rs", - "pub use ::dep::Size;\n\npub mod dep {\n\tpub use ::dep::*;\n}\n\n#[cfg(any())]\npub mod local {}\n\n\ + "pub use ::dep::Size;\n\npub mod glob {\n\tpub use ::dep::*;\n}\n\n#[cfg(any())]\npub mod local {}\n\n\ mod inner {\n\tpub fn kept() -> u32 {\n\t\t1\n\t}\n\n\t#[cfg(any())]\n\tpub mod gone {}\n}\n\n\ mod middle {\n\tpub use crate::inner::*;\n}\n\npub mod outer {\n\tpub use crate::middle::*;\n}\n\n\ pub struct Shape {\n\tpub n: u32,\n\t#[cfg(any())]\n\tpub gone: u32,\n\t#[cfg_attr(all(), cfg_attr(all(), cfg(any())))]\n\tpub gated: u32,\n}\n\n\ @@ -3663,7 +3663,7 @@ fn configured_out() { ), ( "ffi.toml", - "exclude = [\"Gone\", \"Kind::Gone\", \"dep::Area::scaled\", \"Shape::gated\", \"Shape::gone\", \"Shape::missing\", \"Size::depth\", \"nested::Inner::gone\", \"dep::gone::Gone\", \"gone::Gone\", \"local::Gone\", \"outer::gone::Gone\"]\n", + "exclude = [\"Gone\", \"Kind::Gone\", \"dep::Size::depth\", \"dep::Size::missing\", \"glob::Area::scaled\", \"Shape::gated\", \"Shape::gone\", \"Shape::missing\", \"Size::depth\", \"nested::Inner::gone\", \"glob::gone::Gone\", \"gone::Gone\", \"local::Gone\", \"outer::gone::Gone\"]\n", ), ], ); @@ -3681,6 +3681,7 @@ fn configured_out() { errors, [ "error: rust2-ffi: exclude `Gone` in the config names nothing exported", + "error: rust2-ffi: exclude `dep::Size::missing` in the config names nothing exported", "error: rust2-ffi: exclude `Shape::missing` in the config names nothing exported", "error: rust2-ffi: exclude `gone::Gone` in the config names nothing exported", ], From 5734169aaf42ab2759a9c68cac3f5054f41e3c81 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 19 Nov 2026 13:38:36 -0800 Subject: [PATCH 2/3] ffi: format configured_out --- ffi/src/driver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffi/src/driver.rs b/ffi/src/driver.rs index c07e0ca7a..24b645022 100644 --- a/ffi/src/driver.rs +++ b/ffi/src/driver.rs @@ -709,7 +709,7 @@ fn configured_out(tcx: TyCtxt<'_>, path: &str) -> bool { let path = path.strip_prefix("field@").unwrap_or(path); let segments: Vec<&str> = path.split("::").collect(); // Any crate of the name, since a build may link several of its versions. - let mut krates = tcx.crates(()).iter().filter(|&&k| tcx.crate_name(k).as_str() == segments[0]); + let mut krates = (tcx.crates(()).iter()).filter(|&&k| tcx.crate_name(k).as_str() == segments[0]); stripped_under(tcx, LOCAL_CRATE.as_def_id(), &segments) || krates.any(|&k| stripped_under(tcx, k.as_def_id(), &segments[1..])) } From 2655968906dedd91997a3c55aaaaac6883e1ba58 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 19 Nov 2026 13:43:04 -0800 Subject: [PATCH 3/3] ffi: document an exclude's crate path --- ffi/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ffi/README.md b/ffi/README.md index b27d0bea3..849ca3f76 100644 --- a/ffi/README.md +++ b/ffi/README.md @@ -58,7 +58,8 @@ manifest, so exports that differ build apart in a target directory they share. ```toml # ffi.toml, beside the package's Cargo.toml unless --manifest-path says otherwise. -# Paths from the facade's root left out: a module, an item, or one method or field. Each +# Paths from the facade's root left out: a module, an item, or one method or field. A type +# no facade module re-exports goes by its crate's name and its public path there. Each # must name something exported, or what a `cfg` leaves out of this build, as moq-tokio's # `unix` is on Windows. Nothing else leaves an item out. As in rustdoc, a path a # method or constant shares with a field names the method, and `field@` the field.