Auto merge of #29758 - michaelgrigoryan25:master, r=jdm

Patch: Applied code patches for clippy warnings

<!-- Please describe your changes on the following line: -->

This pull request fixes:

- Some of the warnings generated by `./mach cargo-clippy`
- A namespacing error in `headed_window.rs`

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [X] These changes do not require tests because there are no functional changes.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2023-05-22 01:43:35 +02:00 committed by GitHub
commit 4e61168d68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 40 deletions

View file

@ -19,7 +19,7 @@ use servo::Servo;
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::env;
use std::mem;
use std::rc::Rc;
use webxr::glwindow::GlWindowDiscovery;
@ -138,7 +138,7 @@ impl App {
}
fn get_events(&self) -> Vec<WindowEvent> {
mem::replace(&mut *self.event_queue.borrow_mut(), Vec::new())
std::mem::take(&mut *self.event_queue.borrow_mut())
}
// This function decides whether the event should be handled during `run_forever`.

View file

@ -23,7 +23,7 @@ use servo::webrender_api::ScrollLocation;
use std::env;
use std::fs::File;
use std::io::Write;
use std::mem;
use std::rc::Rc;
use std::thread;
use std::time::Duration;
@ -59,7 +59,7 @@ where
current_url: None,
browser_id: None,
browsers: Vec::new(),
window: window,
window,
clipboard_ctx: match ClipboardContext::new() {
Ok(c) => Some(c),
Err(e) => {
@ -73,7 +73,7 @@ where
}
pub fn get_events(&mut self) -> Vec<WindowEvent> {
mem::replace(&mut self.event_queue, Vec::new())
std::mem::take(&mut self.event_queue)
}
pub fn handle_window_events(&mut self, events: Vec<WindowEvent>) {
@ -279,7 +279,7 @@ where
String::from("Untitled")
};
let title = match self.title {
Some(ref title) if title.len() > 0 => &**title,
Some(ref title) if !title.is_empty() => &**title,
_ => &fallback_title,
};
let title = format!("{} - Servo", title);
@ -563,7 +563,7 @@ fn platform_get_selected_devices(devices: Vec<String>) -> Option<String> {
match tinyfiledialogs::list_dialog("Choose a device", &["Id", "Name"], dialog_rows) {
Some(device) => {
// The device string format will be "Address|Name". We need the first part of it.
device.split("|").next().map(|s| s.to_string())
device.split('|').next().map(|s| s.to_string())
},
None => None,
}
@ -598,7 +598,7 @@ fn get_selected_files(patterns: Vec<FilterPattern>, multiple_files: bool) -> Opt
filters.push(tiny_dialog_escape(&s))
}
let filter_ref = &(filters.iter().map(|s| s.as_str()).collect::<Vec<&str>>()[..]);
let filter_opt = if filters.len() > 0 {
let filter_opt = if !filters.is_empty() {
Some((filter_ref, ""))
} else {
None
@ -618,7 +618,7 @@ fn get_selected_files(patterns: Vec<FilterPattern>, multiple_files: bool) -> Opt
fn sanitize_url(request: &str) -> Option<ServoUrl> {
let request = request.trim();
ServoUrl::parse(&request)
ServoUrl::parse(request)
.ok()
.or_else(|| {
if request.contains('/') || is_reg_domain(request) {
@ -650,7 +650,7 @@ fn tiny_dialog_escape(raw: &str) -> String {
_ => Some(c),
})
.collect();
return shellwords::escape(&s);
shellwords::escape(&s)
}
#[cfg(not(target_os = "linux"))]

View file

@ -26,7 +26,7 @@ pub fn install() {
if let Some(name) = thread::current().name() {
let _ = write!(&mut stderr, " in thread \"{}\"", name);
}
let _ = write!(&mut stderr, "\n");
let _ = writeln!(&mut stderr);
// This call always allocates, which in practice will segfault if
// were handling a non-main-thread (e.g. layout) segfault. Strictly

View file

@ -7,7 +7,7 @@
use servo::embedder_traits::EventLoopWaker;
use std::sync::{Arc, Condvar, Mutex};
use std::time;
use winit;
#[cfg(target_os = "macos")]
use winit::platform::macos::{ActivationPolicy, EventLoopBuilderExtMacOS};
@ -66,7 +66,7 @@ impl EventsLoop {
let events_loop = events_loop
.as_ref()
.expect("Can't create waker for unavailable event loop.");
Box::new(HeadedEventLoopWaker::new(&events_loop))
Box::new(HeadedEventLoopWaker::new(events_loop))
},
EventLoop::Headless(ref data) => Box::new(HeadlessEventLoopWaker(data.clone())),
}
@ -95,7 +95,7 @@ impl EventsLoop {
});
}
EventLoop::Headless(ref data) => {
let &(ref flag, ref condvar) = &**data;
let (flag, condvar) = &**data;
let mut event = winit::event::Event::NewEvents(winit::event::StartCause::Init);
loop {
self.sleep(flag, condvar);

View file

@ -14,9 +14,8 @@ use euclid::{
#[cfg(any(target_os = "linux", target_os = "windows"))]
use winit::window::Icon;
use winit::event::{ElementState, KeyboardInput, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode};
#[cfg(any(target_os = "linux", target_os = "windows"))]
use image;
use keyboard_types::{Key, KeyState, KeyboardEvent};
use servo::keyboard_types::{Key, KeyState, KeyboardEvent};
use servo::compositing::windowing::{AnimationState, MouseWindowEvent, WindowEvent};
use servo::compositing::windowing::{EmbedderCoordinates, WindowMethods};
use servo::embedder_traits::Cursor;
@ -31,7 +30,7 @@ use servo::webrender_surfman::WebrenderSurfman;
use servo_media::player::context::{GlApi, GlContext as PlayerGLContext, NativeDisplay};
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::mem;
use std::rc::Rc;
#[cfg(target_os = "linux")]
use surfman::platform::generic::multi::connection::NativeConnection;
@ -120,10 +119,10 @@ impl Window {
let PhysicalSize {
width: screen_width,
height: screen_height,
} = primary_monitor.clone().size();
let screen_size = Size2D::new(screen_width as u32, screen_height as u32);
} = primary_monitor.size();
let screen_size = Size2D::new(screen_width, screen_height);
let PhysicalSize { width, height } = winit_window.inner_size();
let inner_size = Size2D::new(width as u32, height as u32);
let inner_size = Size2D::new(width, height);
// Initialize surfman
let connection =
@ -298,7 +297,7 @@ impl Window {
impl WindowPortsMethods for Window {
fn get_events(&self) -> Vec<WindowEvent> {
mem::replace(&mut *self.event_queue.borrow_mut(), Vec::new())
std::mem::take(&mut *self.event_queue.borrow_mut())
}
fn has_events(&self) -> bool {
@ -319,12 +318,12 @@ impl WindowPortsMethods for Window {
fn set_inner_size(&self, size: DeviceIntSize) {
self.winit_window
.set_inner_size::<PhysicalSize<i32>>(PhysicalSize::new(size.width.into(), size.height.into()))
.set_inner_size::<PhysicalSize<i32>>(PhysicalSize::new(size.width, size.height))
}
fn set_position(&self, point: DeviceIntPoint) {
self.winit_window
.set_outer_position::<PhysicalPosition<i32>>(PhysicalPosition::new(point.x.into(), point.y.into()))
.set_outer_position::<PhysicalPosition<i32>>(PhysicalPosition::new(point.x, point.y))
}
fn set_fullscreen(&self, state: bool) {
@ -340,7 +339,7 @@ impl WindowPortsMethods for Window {
}
fn get_fullscreen(&self) -> bool {
return self.fullscreen.get();
self.fullscreen.get()
}
fn set_cursor(&self, cursor: Cursor) {
@ -532,7 +531,7 @@ impl WindowMethods for Window {
viewport,
framebuffer,
window: (win_size, win_origin),
screen: screen,
screen,
// FIXME: Winit doesn't have API for available size. Fallback to screen size
screen_avail: screen,
hidpi_factor: self.servo_hidpi_factor(),
@ -672,11 +671,11 @@ impl webxr::glwindow::GlWindow for XRWindow {
}
fn get_rotation(&self) -> Rotation3D<f32, UnknownUnit, UnknownUnit> {
self.pose.xr_rotation.get().clone()
self.pose.xr_rotation.get()
}
fn get_translation(&self) -> Vector3D<f32, UnknownUnit> {
self.pose.xr_translation.get().clone()
self.pose.xr_translation.get()
}
fn get_mode(&self) -> webxr::glwindow::GlWindowMode {
@ -736,8 +735,8 @@ impl XRWindowPose {
_ => return,
};
if modifiers.shift() {
x = 10.0 * x;
y = 10.0 * y;
x *= 10.0;
y *= 10.0;
}
let x: Rotation3D<_, UnknownUnit, UnknownUnit> = Rotation3D::around_x(Angle::degrees(x));
let y: Rotation3D<_, UnknownUnit, UnknownUnit> = Rotation3D::around_y(Angle::degrees(y));

View file

@ -20,7 +20,7 @@ use surfman::Connection;
use surfman::Context;
use surfman::Device;
use surfman::SurfaceType;
use winit;
pub struct Window {
webrender_surfman: WebrenderSurfman,
@ -91,7 +91,7 @@ impl WindowPortsMethods for Window {
}
fn get_fullscreen(&self) -> bool {
return self.fullscreen.get();
self.fullscreen.get()
}
fn is_animating(&self) -> bool {

View file

@ -17,12 +17,12 @@ pub fn register_user_prefs(opts_matches: &Matches) {
let user_prefs_path = opts::get()
.config_dir
.clone()
.or_else(|| basedir::default_config_dir())
.or_else(basedir::default_config_dir)
.map(|path| path.join("prefs.json"))
.filter(|path| path.exists());
let mut userprefs = if let Some(path) = user_prefs_path {
let mut file = File::open(&path).expect("Error opening user prefs");
let mut file = File::open(path).expect("Error opening user prefs");
let mut txt = String::new();
file.read_to_string(&mut txt)
.expect("Can't read user prefs file");
@ -41,9 +41,9 @@ pub fn register_user_prefs(opts_matches: &Matches) {
Some("true") | None => PrefValue::Bool(true),
Some("false") => PrefValue::Bool(false),
Some(string) => {
if let Some(int) = string.parse::<i64>().ok() {
if let Ok(int) = string.parse::<i64>() {
PrefValue::Int(int)
} else if let Some(float) = string.parse::<f64>().ok() {
} else if let Ok(float) = string.parse::<f64>() {
PrefValue::Float(float)
} else {
PrefValue::from(string)
@ -83,14 +83,14 @@ fn test_parse_pref_from_command_line() {
prefs::pref_map().get("dom.bluetooth.enabled"),
PrefValue::Bool(true)
);
assert_eq!(pref!(dom.bluetooth.enabled), true);
assert!(pref!(dom.bluetooth.enabled));
test_parse_pref("dom.bluetooth.enabled=false");
assert_eq!(
prefs::pref_map().get("dom.bluetooth.enabled"),
PrefValue::Bool(false)
);
assert_eq!(pref!(dom.bluetooth.enabled), false);
assert!(pref!(dom.bluetooth.enabled));
// Test with numbers
test_parse_pref("layout.threads=42");
@ -105,7 +105,7 @@ fn test_parse_pref_from_command_line() {
.set("dom.bluetooth.enabled", false)
.unwrap();
test_parse_pref("dom.bluetooth.enabled");
assert_eq!(pref!(dom.bluetooth.enabled), true);
assert!(pref!(dom.bluetooth.enabled));
}
#[test]

View file

@ -9,7 +9,7 @@ use crate::events_loop::ServoEvent;
use servo::compositing::windowing::{WindowEvent, WindowMethods};
use servo::embedder_traits::Cursor;
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize};
use winit;
// This should vary by zoom level and maybe actual text size (focused or under cursor)
pub const LINE_HEIGHT: f32 = 38.0;