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
8 changes: 8 additions & 0 deletions .ripr/traceability.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12392,6 +12392,12 @@ id = "RIPR-SPEC-0197"
name = "Owner-return pins through calls that name the owner"
spec = "docs/specs/RIPR-SPEC-0197-owner-return-pins.md"
tests = [
"crates/ripr/src/analysis/classify/owner_pin/tests/json_construction.rs::literal_json_binding_in_a_withheld_file_remains_a_refusal",
"crates/ripr/src/analysis/classify/owner_pin/tests/json_construction.rs::literal_json_admission_preserves_binding_and_operand_refusals",
"crates/ripr/src/analysis/classify/owner_pin/tests/json_construction.rs::literal_json_namespace_in_another_source_file_stays_uncredited",
"crates/ripr/src/analysis/classify/owner_pin/tests/json_construction.rs::literal_json_configuration_and_lock_changes_revoke_cached_identity",
"crates/ripr/tests/owner_pin_execution.rs::literal_json_constructor_matches_real_callback_and_runtime_controls",

"crates/ripr/src/analysis/classify/owner_pin/tests.rs::a_tokio_test_runtime_runs_an_async_test_body_and_other_async_tests_refuse",
"crates/ripr/src/analysis/classify/owner_pin/tests.rs::an_async_owner_is_read_through_one_await_and_a_sync_owner_is_not",
"crates/ripr/src/analysis/classify/owner_pin/tests.rs::an_rstest_case_table_with_literal_rows_runs_the_body_once_per_row",
Expand Down Expand Up @@ -12424,6 +12430,8 @@ tests = [
"crates/ripr/tests/fallible_owner_return.rs::frozen_fallible_literal_helper_exposes_exact_owner_return",
"crates/ripr/tests/fallible_owner_return.rs::fallible_literal_helper_refuses_unbound_or_ineffective_oracles",
"crates/ripr/tests/fallible_owner_return.rs::warm_analysis_revalidates_config_lock_and_source_role",
"crates/ripr/src/analysis/workspace/assertion_dependency.rs::tests::json_member_snapshots_revoke_changed_or_missing_manifests",
"crates/ripr/src/analysis/workspace/assertion_dependency.rs::tests::windows_environment_names_preserve_registry_and_home_authority",
"crates/ripr/src/analysis/workspace/assertion_dependency.rs::tests::exact_regular_manifest_and_refusals",
"crates/ripr/src/analysis/workspace/assertion_dependency.rs::tests::injected_config_and_environment_refusals",
"crates/ripr/src/analysis/workspace/assertion_dependency.rs::tests::flag_identity_changes_are_bound_without_flag_interpretation",
Expand Down
4 changes: 4 additions & 0 deletions changelog.d/7776-literal-json-admission.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- section: Fixed -->
- Rust assertion admission recognizes literal JSON construction under a verified
serde_json registry dependency, preserving refusals for shadowed macros,
source replacements and unresolved interpolation (#7776).
60 changes: 49 additions & 11 deletions crates/ripr/src/analysis/classify/owner_pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,20 @@ impl WithheldMacroBindings {
if self.any_name {
return true;
}
let drop_in_verified = |krate: &str| drop_ins.verified(path, krate);
let drop_in_verified = |krate: &str| {
if krate == "serde_json" {
drop_ins.verified_literal_json(path)
} else {
drop_ins.verified(path, krate)
}
};
let root = withheld_crate_root(path);
for (name, site) in
macro_binding_scan(source, packages, NON_RETURNING_MACROS, &drop_in_verified)
{
for (name, site) in macro_binding_scan(
source,
packages,
&assertion_context_macros(),
&drop_in_verified,
) {
if let Some(root) = root.as_ref().filter(|_| site.crate_local) {
self.root_any_name |= site.kind.binds_any_name();
self.by_root
Expand Down Expand Up @@ -644,6 +653,12 @@ impl OwnerPinSyntax {
.collect()
});
let mut ambiguous: BTreeSet<_> = ambiguous.union(empty_ambiguities).cloned().collect();
// Recheck provenance for every admission even when syntax is memoized.
if facts.source.contains("json")
&& !index.drop_in_manifests.verified_literal_json(&test.file)
{
ambiguous.insert("json".to_string());
}
ambiguous.extend(self.scoped_names_for(test, line));
ambiguous.extend(self.crate_names_for(test, index));
let mut by_file = self.by_file.borrow_mut();
Expand Down Expand Up @@ -731,7 +746,7 @@ impl OwnerPinSyntax {
.map(|(condition, _)| err_return_guard_key(condition));
let file_refusal = by_file
.entry(test.file.clone())
.or_insert_with(|| owner_pin_assertions(&facts.source, NON_RETURNING_MACROS))
.or_insert_with(|| owner_pin_assertions(&facts.source, &assertion_context_macros()))
Comment thread
EffortlessSteven marked this conversation as resolved.
Resolved
.refusal(
(test.start_line, test.end_line, &test.name),
&test.body,
Expand Down Expand Up @@ -1166,7 +1181,7 @@ fn workspace_macro_binding_site(
roots: &TargetRoots,
module_resolved: &(dyn Fn(&Path, usize, &str) -> bool + Sync),
) -> Option<(PathBuf, MacroBindingSite)> {
if !NON_RETURNING_MACROS.contains(&name) {
if !assertion_context_macros().contains(&name) {
return None;
}
// Every file may be parsed for this one name, which was a quarter of a
Expand Down Expand Up @@ -1247,7 +1262,7 @@ fn test_macro_binding_site(
memo: &RefCell<TestFileMacroSites>,
module_resolved: &dyn Fn(&Path, usize, &str) -> bool,
) -> Option<(PathBuf, MacroBindingSite)> {
if !NON_RETURNING_MACROS.contains(&name) {
if !assertion_context_macros().contains(&name) {
return None;
}
let facts = index.files().get(&test.file)?;
Expand Down Expand Up @@ -1286,7 +1301,13 @@ fn macro_binding_sites(
index.macro_scope_crates(),
&[name],
&|line, declaration| module_resolved(path, line, declaration),
&|krate| index.drop_in_manifests.verified(path, krate),
&|krate| {
if krate == "serde_json" {
index.drop_in_manifests.verified_literal_json(path)
} else {
index.drop_in_manifests.verified(path, krate)
}
},
)
}

Expand All @@ -1302,6 +1323,7 @@ fn trusted_macro_sites_in(
roots: &TargetRoots,
module_resolved: &(dyn Fn(&Path, usize, &str) -> bool + Sync),
) -> (BTreeSet<String>, ScopedMacroBindings, CrateMacroBindings) {
let context_macros = assertion_context_macros();
type ScanFile<'a> = (&'a PathBuf, &'a str, Option<&'a MacroBindingCandidates>);
let scan = |files: &[ScanFile<'_>]| -> Vec<(PathBuf, String, MacroBindingSite)> {
files
Expand All @@ -1315,9 +1337,15 @@ fn trusted_macro_sites_in(
trusted_macro_binding_sites(
source,
index.macro_scope_crates(),
NON_RETURNING_MACROS,
&context_macros,
&|line, declaration| module_resolved(path, line, declaration),
&|krate| index.drop_in_manifests.verified(path, krate),
&|krate| {
if krate == "serde_json" {
index.drop_in_manifests.verified_literal_json(path)
} else {
index.drop_in_manifests.verified(path, krate)
}
},
)
.into_iter()
.map(|(name, site)| ((*path).clone(), name, site))
Expand Down Expand Up @@ -1356,7 +1384,7 @@ fn trusted_macro_sites_in(
})
.partition(|(_, source, _)| may_saturate_macro_ambiguity(source));
absorb(scan(&likely), &mut global);
if global.len() < NON_RETURNING_MACROS.len() {
if global.len() < context_macros.len() {
absorb(scan(&rest), &mut global);
}
(global, scoped, by_root)
Expand Down Expand Up @@ -3648,6 +3676,16 @@ fn final_statement(masked: &str, end: usize) -> Option<(usize, usize)> {
/// [`crate::analysis::syntax::MacroBindingCandidates`] can report.
const NON_RETURNING_MACROS: &[&str] = TRUSTED_MACRO_NAMES;

// `json` is a construction candidate only in assertion context. It must never
// enter the owner-side generic non-returning list: an opaque owner macro can exit.
fn assertion_context_macros() -> Vec<&'static str> {
NON_RETURNING_MACROS
.iter()
.copied()
.chain(["json"])
.collect()
}

/// Trusted names whose trust is the test-side binding scan's alone (#6578).
/// `expect!` is no `std` macro: outside a test that verifies
/// `use expect_test::expect;`, a bare `expect!` is a crate's own (a try-style
Expand Down
9 changes: 7 additions & 2 deletions crates/ripr/src/analysis/classify/owner_pin/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod json_construction;

use super::*;
use crate::analysis::facts::{FunctionItemFact, SourceRoleProvenance, SourceRoleProvenanceEdge};
use crate::analysis::rust_index::summarize_file;
Expand Down Expand Up @@ -3984,7 +3986,7 @@ fn trusted_macro_scan_skips_files_only_once_every_name_is_ambiguous() {
trusted_macro_binding_sites(
&facts.data().source,
index.macro_scope_crates(),
NON_RETURNING_MACROS,
&assertion_context_macros(),
&|_, _| false,
&|_| false,
)
Expand Down Expand Up @@ -4024,7 +4026,7 @@ fn trusted_macro_scan_skips_files_only_once_every_name_is_ambiguous() {
trusted_macro_sites_in(&index, &TargetRoots::new(&index), &unresolved);
assert_eq!(ambiguous, full_scan(&index), "{files:?}");
assert_eq!(
ambiguous.len() == NON_RETURNING_MACROS.len(),
ambiguous.len() == assertion_context_macros().len(),
saturated,
"{files:?}"
);
Expand All @@ -4038,6 +4040,9 @@ fn trusted_macro_scan_skips_files_only_once_every_name_is_ambiguous() {

#[test]
fn trusted_macro_names_are_distinct_so_a_full_set_means_saturated() {
assert!(!NON_RETURNING_MACROS.contains(&"json"));
let context = assertion_context_macros();
assert_eq!(context.iter().collect::<BTreeSet<_>>().len(), context.len());
let distinct = NON_RETURNING_MACROS.iter().collect::<BTreeSet<_>>();
assert_eq!(distinct.len(), NON_RETURNING_MACROS.len());
}
Expand Down
Loading
Loading