Refactor allow to expect (#41586)

Replace `allow` with `expect` lints for `unused`, `unsafe_code`,
`dead_code`, and `non_upper_case_globals`.

Testing: So far just check it compiled on `x86_64-linux` on NixOS. Need
to use the module `system.fontconfig.enable = true;` I think in my NixOS
config.
Part of: #40383 

Searching `allow\(.*\)` for `.rs` files shows the following. for
(total_results:total_files) went from `707:386` to `675:368`, a
reduction of `32:18`.

How many files is too many files per PR? I feel like the 20-30 I have is
too big.

---------

Signed-off-by: Wayne Van Son <waynevanson@gmail.com>
This commit is contained in:
Wayne Van Son
2026-01-02 00:40:20 +11:00
committed by GitHub
parent 96ddb0bbf0
commit 5b9263690d
26 changed files with 41 additions and 51 deletions

View File

@@ -45,11 +45,11 @@ unsafe extern "C" fn enclosing_size_impl(ptr: *const c_void) -> usize {
size
}
#[allow(non_upper_case_globals)]
#[expect(non_upper_case_globals)]
#[cfg(feature = "allocation-tracking")]
pub static enclosing_size: Option<EnclosingSizeFn> = Some(crate::enclosing_size_impl);
#[allow(non_upper_case_globals)]
#[expect(non_upper_case_globals)]
#[cfg(not(feature = "allocation-tracking"))]
pub static enclosing_size: Option<EnclosingSizeFn> = None;

View File

@@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// TODO: Remove once the actor is used
#![allow(dead_code)]
#![expect(dead_code)]
use serde::Serialize;
use serde_json::{Map, Value};

View File

@@ -5,7 +5,7 @@
use crate::actor::Actor;
// TODO: Remove once the actor is used.
#[allow(dead_code)]
#[expect(dead_code)]
/// Referenced by `ThreadActor` when replying to `interupt` messages.
/// <https://searchfox.org/firefox-main/source/devtools/server/actors/thread.js#1699>
pub struct PauseActor {

View File

@@ -112,7 +112,7 @@ fn expand_dom_object(input: syn::DeriveInput) -> proc_macro2::TokenStream {
proc_macro2::Span::call_site(),
);
let tokens = quote! {
#[allow(non_upper_case_globals)]
#[expect(non_upper_case_globals)]
const #dummy_const: () = { #dummy_items };
#items
};

View File

@@ -45,7 +45,7 @@ pub(crate) enum EmojiPresentationPreference {
pub struct FallbackFontSelectionOptions {
pub(crate) character: char,
pub(crate) presentation_preference: EmojiPresentationPreference,
#[cfg_attr(any(target_os = "android", target_os = "windows"), allow(dead_code))]
#[cfg_attr(any(target_os = "android", target_os = "windows"), expect(dead_code))]
pub(crate) lang: Option<String>,
}

View File

@@ -388,7 +388,7 @@ where
}
}
/// <https://streams.spec.whatwg.org/#abstract-opdef-cloneasuint8array>
#[allow(unsafe_code)]
#[expect(unsafe_code)]
pub(crate) fn clone_as_uint8_array(
&self,
cx: JSContext,

View File

@@ -431,7 +431,6 @@ impl ByteTeeUnderlyingSource {
/// Let cancel1Algorithm be the following steps, taking a reason argument
/// and
/// Let cancel2Algorithm be the following steps, taking a reason argument
#[allow(unsafe_code)]
pub(crate) fn cancel_algorithm(
&self,
reason: SafeHandleValue,
@@ -470,7 +469,7 @@ impl ByteTeeUnderlyingSource {
}
}
#[allow(unsafe_code)]
#[expect(unsafe_code)]
fn resolve_cancel_promise(&self, can_gc: CanGc) {
// Let compositeReason be ! CreateArrayFromList(« reason_1, reason_2 »).
let cx = GlobalScope::get_cx();

View File

@@ -43,22 +43,6 @@ impl CommandEvent {
}
}
#[allow(clippy::too_many_arguments)]
#[allow(dead_code)]
pub(crate) fn new(
window: &Window,
type_: Atom,
bubbles: EventBubbles,
cancelable: EventCancelable,
source: Option<DomRoot<Element>>,
command: DOMString,
can_gc: CanGc,
) -> DomRoot<CommandEvent> {
Self::new_with_proto(
window, None, type_, bubbles, cancelable, source, command, can_gc,
)
}
#[allow(clippy::too_many_arguments)]
fn new_with_proto(
window: &Window,

View File

@@ -2093,7 +2093,7 @@ pub(crate) fn capture_webgl_backtrace() -> WebGLCommandBacktrace {
}
#[cfg(feature = "webgl_backtrace")]
#[cfg_attr(feature = "webgl_backtrace", allow(unsafe_code))]
#[cfg_attr(feature = "webgl_backtrace", expect(unsafe_code))]
pub(crate) fn capture_webgl_backtrace() -> WebGLCommandBacktrace {
let bt = Backtrace::new();
unsafe {

View File

@@ -290,7 +290,7 @@ impl DedicatedWorkerGlobalScope {
}
}
#[allow(unsafe_code, clippy::too_many_arguments)]
#[expect(clippy::too_many_arguments)]
pub(crate) fn new(
init: WorkerGlobalScopeInit,
webview_id: WebViewId,

View File

@@ -348,7 +348,7 @@ fn queue_deferred_fetch(
}
/// <https://fetch.spec.whatwg.org/#dom-window-fetchlater>
#[allow(non_snake_case, unsafe_code)]
#[expect(non_snake_case, unsafe_code)]
pub(crate) fn FetchLater(
window: &Window,
input: RequestInfo,

View File

@@ -7472,7 +7472,7 @@ class CGNonNamespacedEnum(CGThing):
entries = [f"{names[0]} = {first}"] + names[1:]
# Append a Last.
entries.append(f'#[allow(dead_code)] Last = {first + len(entries)}')
entries.append(f'Last = {first + len(entries)}')
# Indent.
entries = [f' {e}' for e in entries]
@@ -7900,7 +7900,7 @@ class CGRegisterProxyHandlers(CGThing):
)
self.root = CGList([
CGGeneric(
"#[allow(non_upper_case_globals)]\n"
"#[expect(non_upper_case_globals)]\n"
"pub(crate) mod proxy_handlers {\n"
f"{body}}}\n"
),

View File

@@ -88,7 +88,7 @@ pub(crate) struct WebViewDelegateImpl {
pub(crate) number_of_controls_hidden: Cell<usize>,
}
#[allow(dead_code)]
#[allow(dead_code)] // Used by some tests and not others
impl WebViewDelegateImpl {
pub(crate) fn reset(&self) {
self.url_changed.set(false);
@@ -140,7 +140,7 @@ impl WebViewDelegate for WebViewDelegateImpl {
}
}
#[allow(dead_code)]
#[allow(dead_code)] // Used by some tests and not others
pub(crate) fn evaluate_javascript(
servo_test: &ServoTest,
webview: WebView,

View File

@@ -261,7 +261,7 @@ pub struct App {
platform_window: Rc<EmbeddedPlatformWindow>,
}
#[allow(unused)]
#[expect(unused)]
impl App {
pub(super) fn new(init: AppInitOptions) -> Rc<Self> {
let mut servo_builder = ServoBuilder::default()
@@ -618,7 +618,6 @@ pub(crate) struct XrDiscoveryWebXrRegistry {
}
#[cfg(feature = "webxr")]
#[cfg_attr(target_env = "ohos", allow(dead_code))]
impl XrDiscoveryWebXrRegistry {
pub(crate) fn new(xr_discovery: Option<servo::webxr::Discovery>) -> Self {
Self {

View File

@@ -812,7 +812,7 @@ fn register_xcomponent_callbacks(env: &Env, xcomponent: &Object) -> napi_ohos::R
Ok(())
}
#[allow(unused)]
#[expect(unused)]
fn debug_jsobject(obj: &Object, obj_name: &str) -> napi_ohos::Result<()> {
let names = obj.get_property_names()?;
error!("Getting property names of object {obj_name}");
@@ -1053,7 +1053,7 @@ impl Ime for ServoIme {
}
}
#[allow(unused)]
#[expect(unused)]
impl HostTrait for HostCallbacks {
fn show_alert(&self, message: String) {
// forward it to tracing

View File

@@ -42,7 +42,7 @@ pub(crate) static EXPERIMENTAL_PREFS: &[&str] = &[
"layout_variable_fonts_enabled",
];
#[cfg_attr(any(target_os = "android", target_env = "ohos"), allow(dead_code))]
#[cfg_attr(any(target_os = "android", target_env = "ohos"), expect(dead_code))]
#[derive(Clone)]
pub(crate) struct ServoShellPreferences {
/// A URL to load when starting servoshell.
@@ -213,7 +213,7 @@ pub fn read_prefs_map(txt: &str) -> HashMap<String, PrefValue> {
}
#[expect(clippy::large_enum_variant)]
#[cfg_attr(any(target_os = "android", target_env = "ohos"), allow(dead_code))]
#[cfg_attr(any(target_os = "android", target_env = "ohos"), expect(dead_code))]
pub(crate) enum ArgumentParsingResult {
ChromeProcess(Opts, Preferences, ServoShellPreferences),
ContentProcess(String),

View File

@@ -222,17 +222,25 @@ fn test_cmd_and_location_bar_url() {
}
/// Like [test_url] but will produce test for Windows or non Windows using `#[cfg(target_os)]` internally.
#[cfg(not(target_os = "windows"))]
fn test_url_any_os(
input: &str,
location: &str,
#[allow(unused)] if_exists: &str,
#[allow(unused)] if_exists_windows: &str,
if_exists: &str,
_if_exists_windows: &str,
otherwise: &str,
) {
#[cfg(not(target_os = "windows"))]
test_url(input, location, if_exists, otherwise);
}
#[cfg(target_os = "windows")]
#[cfg(target_os = "windows")]
fn test_url_any_os(
input: &str,
location: &str,
_if_exists: &str,
if_exists_windows: &str,
otherwise: &str,
) {
test_url(input, location, if_exists_windows, otherwise);
}

View File

@@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//@rustc-env:RUSTC_BOOTSTRAP=1
#![allow(dead_code)]
#![expect(dead_code)]
use std::rc::Rc;

View File

@@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//@rustc-env:RUSTC_BOOTSTRAP=1
#![allow(dead_code)]
#![expect(dead_code)]
#[crown::unrooted_must_root_lint::must_root]
struct MustBeRooted;

View File

@@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//@rustc-env:RUSTC_BOOTSTRAP=1
#![allow(dead_code)]
#![expect(dead_code)]
trait TypeHolderTrait {
#[crown::unrooted_must_root_lint::must_root]

View File

@@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//@rustc-env:RUSTC_BOOTSTRAP=1
#![allow(dead_code)]
#![expect(dead_code)]
fn main() {}

View File

@@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//@rustc-env:RUSTC_BOOTSTRAP=1
#![allow(dead_code)]
#![expect(dead_code)]
trait TypeHolderTrait {
#[crown::unrooted_must_root_lint::must_root]

View File

@@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//@rustc-env:RUSTC_BOOTSTRAP=1
#![allow(dead_code)]
#![expect(dead_code)]
use std::rc::Rc;

View File

@@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//@rustc-env:RUSTC_BOOTSTRAP=1
#![allow(dead_code)]
#![expect(dead_code)]
#[crown::unrooted_must_root_lint::must_root]
struct MustBeRooted;

View File

@@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//@rustc-env:RUSTC_BOOTSTRAP=1
#![allow(dead_code)]
#![expect(dead_code)]
const _: () = assert!(cfg!(crown), "cfg(crown) not set!");

View File

@@ -9,7 +9,7 @@ use std::os::raw::{c_char, c_int, c_uint};
use objc2::runtime::{BOOL, Class, Object};
#[allow(non_upper_case_globals)]
#[expect(non_upper_case_globals)]
pub const nil: *mut Object = 0 as *mut Object;
pub mod ns {