diff --git a/tooling/ast_fuzzer/src/lib.rs b/tooling/ast_fuzzer/src/lib.rs index 4de189661f1..516c58d444c 100644 --- a/tooling/ast_fuzzer/src/lib.rs +++ b/tooling/ast_fuzzer/src/lib.rs @@ -1,4 +1,5 @@ #![forbid(unsafe_code)] +#![warn(unreachable_pub)] #![warn(clippy::semicolon_if_nothing_returned)] #![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))] diff --git a/tooling/ast_fuzzer/src/program/freq.rs b/tooling/ast_fuzzer/src/program/freq.rs index c098a97c369..6f3a20340eb 100644 --- a/tooling/ast_fuzzer/src/program/freq.rs +++ b/tooling/ast_fuzzer/src/program/freq.rs @@ -36,7 +36,7 @@ pub(crate) struct Freq { } impl Freq { - pub fn new(u: &mut Unstructured, freqs: &Freqs) -> arbitrary::Result { + pub(crate) fn new(u: &mut Unstructured, freqs: &Freqs) -> arbitrary::Result { let x = u.choose_index(freqs.total())?; Ok(Self { freqs: freqs.clone(), x, accumulated: 0, disabled: 0 }) } @@ -44,7 +44,7 @@ impl Freq { /// Check if a key is enabled, based on the already checked cumulative values. /// /// To work correctly, `enabled` calls should come after `enabled_when`s. - pub fn enabled(&mut self, key: &str) -> bool { + pub(crate) fn enabled(&mut self, key: &str) -> bool { self.accumulated += self.freqs[key]; self.passed() } @@ -64,7 +64,7 @@ impl Freq { /// As a workaround, we should /// * check keys which are more likely to be disabled up front /// * have a default case at the end which is always enabled - pub fn enabled_when(&mut self, key: &str, cond: bool) -> bool { + pub(crate) fn enabled_when(&mut self, key: &str, cond: bool) -> bool { if cond { self.enabled(key) } else { diff --git a/tooling/ast_fuzzer/src/program/func.rs b/tooling/ast_fuzzer/src/program/func.rs index 3119405527c..36e38b0bfe5 100644 --- a/tooling/ast_fuzzer/src/program/func.rs +++ b/tooling/ast_fuzzer/src/program/func.rs @@ -42,7 +42,7 @@ pub(super) struct FunctionDeclaration { impl FunctionDeclaration { /// Generate a HIR function signature. - pub fn signature(&self) -> hir_def::function::FunctionSignature { + pub(super) fn signature(&self) -> hir_def::function::FunctionSignature { let param_types = self .params .iter() @@ -140,7 +140,7 @@ pub(super) struct FunctionContext<'a> { } impl<'a> FunctionContext<'a> { - pub fn new(ctx: &'a mut Context, id: FuncId) -> Self { + pub(super) fn new(ctx: &'a mut Context, id: FuncId) -> Self { let decl = ctx.function_decl(id); let next_local_id = decl.params.iter().map(|p| p.0.0 + 1).max().unwrap_or_default(); let budget = ctx.config.max_function_size; @@ -206,7 +206,7 @@ impl<'a> FunctionContext<'a> { } /// Generate the function body. - pub fn gen_body(mut self, u: &mut Unstructured) -> arbitrary::Result { + pub(super) fn gen_body(mut self, u: &mut Unstructured) -> arbitrary::Result { // If we don't limit the budget according to the available data, // it gives us a lot of `false` and 0 and we end up with deep `!(!false)` if expressions. self.budget = self.budget.min(u.len()); @@ -220,7 +220,7 @@ impl<'a> FunctionContext<'a> { /// Generate the function body, wrapping a function call with literal arguments. /// This is used to test comptime functions, which can only take those. - pub fn gen_body_with_lit_call( + pub(super) fn gen_body_with_lit_call( mut self, u: &mut Unstructured, callee_id: FuncId, diff --git a/tooling/ast_fuzzer/src/program/scope.rs b/tooling/ast_fuzzer/src/program/scope.rs index e548b6dfdd9..30fd137e0d9 100644 --- a/tooling/ast_fuzzer/src/program/scope.rs +++ b/tooling/ast_fuzzer/src/program/scope.rs @@ -23,7 +23,7 @@ where K: Ord + Clone + Copy + Debug, { /// Create the initial scope from function parameters. - pub fn new(vars: impl Iterator) -> Self { + pub(super) fn new(vars: impl Iterator) -> Self { let mut scope = Self { variables: im::OrdMap::new(), producers: im::OrdMap::new() }; for (id, mutable, name, typ) in vars { scope.add(id, mutable, name, typ); @@ -72,7 +72,7 @@ where } /// Choose a random producer of a type, if there is one. - pub fn choose_producer( + pub(super) fn choose_producer( &self, u: &mut Unstructured, typ: &Type, @@ -87,7 +87,7 @@ where } /// Get a variable in scope. - pub fn get_variable(&self, id: &K) -> &Variable { + pub(super) fn get_variable(&self, id: &K) -> &Variable { self.variables.get(id).unwrap_or_else(|| panic!("variable doesn't exist: {:?}", id)) } } @@ -97,22 +97,22 @@ where K: Ord, { /// Check if there are any variables in scope. - pub fn is_empty(&self) -> bool { + pub(super) fn is_empty(&self) -> bool { self.variables.is_empty() } /// Iterate the variables in scope. - pub fn variables(&self) -> impl ExactSizeIterator { + pub(super) fn variables(&self) -> impl ExactSizeIterator { self.variables.iter() } /// Iterate the IDs of the variables in scope. - pub fn variable_ids(&self) -> impl ExactSizeIterator { + pub(super) fn variable_ids(&self) -> impl ExactSizeIterator { self.variables.keys() } /// Iterate the types we can produce from other variables. - pub fn types_produced(&self) -> impl ExactSizeIterator { + pub(super) fn types_produced(&self) -> impl ExactSizeIterator { self.producers.keys() } } @@ -125,34 +125,34 @@ where K: Ord + Clone + Copy + Debug, { /// Create a stack from the base variables. - pub fn new(vars: impl Iterator) -> Self { + pub(super) fn new(vars: impl Iterator) -> Self { Self(vec![Scope::new(vars)]) } /// The top scope in the stack. - pub fn current(&self) -> &Scope { + pub(super) fn current(&self) -> &Scope { self.0.last().expect("there is always the base layer") } /// Push a new scope on top of the current one. - pub fn enter(&mut self) { + pub(super) fn enter(&mut self) { // Instead of shallow cloning an immutable map, we could loop through layers when looking up variables. self.0.push(self.current().clone()); } /// Remove the last layer of block variables. - pub fn exit(&mut self) { + pub(super) fn exit(&mut self) { self.0.pop(); assert!(!self.0.is_empty(), "never pop the base layer"); } /// Add a new variable to the current scope. - pub fn add(&mut self, id: K, mutable: bool, name: String, typ: Type) { + pub(super) fn add(&mut self, id: K, mutable: bool, name: String, typ: Type) { self.0.last_mut().expect("there is always a layer").add(id, mutable, name, typ); } /// Remove a variable from all scopes. - pub fn remove(&mut self, id: &K) { + pub(super) fn remove(&mut self, id: &K) { for scope in self.0.iter_mut() { scope.remove(id); }