mach: Do not use unstable rust for rustfmt (#31441)

We can use stable rust if we pass the unstable configuration as
command-line arguments to rustfmt itself. This prevents needing to
install an unstable rust toolchain.

The one downside here is that it doesn't seem that "ignore" is
supported so we have to start formatting the files in "third_party."
This shouldn't be a huge issue because we don't plan to check much more
rust code into those directories.
This commit is contained in:
Martin Robinson 2024-02-28 14:53:04 +01:00 committed by GitHub
parent 2afd5431b1
commit 98bd306816
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 32 additions and 21 deletions

View file

@ -4951,7 +4951,9 @@ where
// If there is no focus browsing context yet, the initial page has
// not loaded, so there is nothing to save yet.
let Some(top_level_browsing_context_id) = self.webviews.focused_webview().map(|(id, _)| id)
else { return ReadyToSave::NoTopLevelBrowsingContext };
else {
return ReadyToSave::NoTopLevelBrowsingContext;
};
// If there are pending loads, wait for those to complete.
if !self.pending_changes.is_empty() {

View file

@ -11,9 +11,8 @@ use app_units::Au;
use euclid::default::Point2D;
// Eventually we would like the shaper to be pluggable, as many operating systems have their own
// shapers. For now, however, HarfBuzz is a hard dependency.
use harfbuzz_sys::hb_blob_t;
use harfbuzz_sys::{
hb_blob_create, hb_bool_t, hb_buffer_add_utf8, hb_buffer_create, hb_buffer_destroy,
hb_blob_create, hb_blob_t, hb_bool_t, hb_buffer_add_utf8, hb_buffer_create, hb_buffer_destroy,
hb_buffer_get_glyph_infos, hb_buffer_get_glyph_positions, hb_buffer_get_length,
hb_buffer_set_direction, hb_buffer_set_script, hb_buffer_t, hb_codepoint_t,
hb_face_create_for_tables, hb_face_destroy, hb_face_t, hb_feature_t, hb_font_create,

View file

@ -269,8 +269,10 @@ where
buffer.get()
},
});
let Ok(array) = array as Result<CustomAutoRooterGuard<'_, TypedArray<T, *mut JSObject>>, &mut ()> else{
return Err(())
let Ok(array) =
array as Result<CustomAutoRooterGuard<'_, TypedArray<T, *mut JSObject>>, &mut ()>
else {
return Err(());
};
unsafe {
let slice = (*array).as_slice();
@ -305,9 +307,10 @@ where
buffer.get()
},
});
let Ok(mut array) = array as Result<CustomAutoRooterGuard<'_, TypedArray<T, *mut JSObject>>, &mut ()> else
{
return Err(())
let Ok(mut array) =
array as Result<CustomAutoRooterGuard<'_, TypedArray<T, *mut JSObject>>, &mut ()>
else {
return Err(());
};
unsafe {
let slice = (*array).as_mut_slice();

View file

@ -198,7 +198,9 @@ impl Minibrowser {
let rect = egui::Rect::from_min_size(min, size);
ui.allocate_space(size);
let Some(servo_fbo) = servo_framebuffer_id else { return };
let Some(servo_fbo) = servo_framebuffer_id else {
return;
};
ui.painter().add(PaintCallback {
rect,
callback: Arc::new(CallbackFn::new(move |info, painter| {

View file

@ -39,6 +39,15 @@ PROJECT_TOPLEVEL_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", ".."))
WEB_PLATFORM_TESTS_PATH = os.path.join("tests", "wpt", "tests")
SERVO_TESTS_PATH = os.path.join("tests", "wpt", "mozilla", "tests")
# Servo depends on several `rustfmt` options that are unstable. These are still
# supported by stable `rustfmt` if they are passed as these command-line arguments.
UNSTABLE_RUSTFMT_ARGUMENTS = [
"--config", "unstable_features=true",
"--config", "binop_separator=Back",
"--config", "imports_granularity=Module",
"--config", "group_imports=StdExternalCrate",
]
def format_toml_files_with_taplo(check_only: bool = True) -> int:
taplo = shutil.which("taplo")
@ -206,12 +215,12 @@ class MachCommands(CommandBase):
def test_tidy(self, all_files, no_progress):
tidy_failed = tidy.scan(not all_files, not no_progress)
call(["rustup", "install", "nightly-2023-03-18"])
call(["rustup", "component", "add", "rustfmt", "--toolchain", "nightly-2023-03-18"])
rustfmt_failed = call(["cargo", "+nightly-2023-03-18", "fmt", "--", "--check"])
print("\r ➤ Checking formatting of rust files...")
rustfmt_failed = call(["cargo", "fmt", "--", *UNSTABLE_RUSTFMT_ARGUMENTS, "--check"])
if rustfmt_failed:
print("Run `./mach fmt` to fix the formatting")
print("\r ➤ Checking formatting of toml files...")
taplo_failed = format_toml_files_with_taplo()
tidy_failed = tidy_failed or rustfmt_failed or taplo_failed
@ -323,9 +332,7 @@ class MachCommands(CommandBase):
if result != 0:
return result
call(["rustup", "install", "nightly-2023-03-18"])
call(["rustup", "component", "add", "rustfmt", "--toolchain", "nightly-2023-03-18"])
return call(["cargo", "+nightly-2023-03-18", "fmt"])
return call(["cargo", "fmt", "--", *UNSTABLE_RUSTFMT_ARGUMENTS])
@Command('update-wpt',
description='Update the web platform tests',

View file

@ -1,6 +1,2 @@
match_block_trailing_comma = true
binop_separator = "Back"
reorder_imports = true
group_imports = "StdExternalCrate"
imports_granularity = "Module"
ignore = ["third_party"]

View file

@ -485,6 +485,8 @@ pub mod cb {
// CBCentralManagerScanOption...Key
// CBAdvertisementData...Key
pub use self::link::CBAdvertisementDataServiceUUIDsKey as ADVERTISEMENTDATASERVICEUUIDSKEY;
pub use self::link::CBCentralManagerScanOptionAllowDuplicatesKey as CENTRALMANAGERSCANOPTIONALLOWDUPLICATESKEY;
pub use self::link::{
CBAdvertisementDataServiceUUIDsKey as ADVERTISEMENTDATASERVICEUUIDSKEY,
CBCentralManagerScanOptionAllowDuplicatesKey as CENTRALMANAGERSCANOPTIONALLOWDUPLICATESKEY,
};
}