clippy: Fix let_and_return warnings (#31964)

This commit is contained in:
Oluwatobi Sofela 2024-04-01 16:43:24 +01:00 committed by GitHub
parent 0da2508e4d
commit c7b73e1ef4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 17 additions and 31 deletions

View file

@ -751,10 +751,7 @@ fn consume_body_with_promise<T: BodyMixin + DomObject>(
// Step 2. // Step 2.
let stream = match object.body() { let stream = match object.body() {
Some(stream) => stream, Some(stream) => stream,
None => { None => ReadableStream::new_from_bytes(&global, Vec::with_capacity(0)),
let stream = ReadableStream::new_from_bytes(&global, Vec::with_capacity(0));
stream
},
}; };
// Step 3. // Step 3.

View file

@ -122,7 +122,7 @@ impl BaseAudioContext {
let client_context_id = let client_context_id =
ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get()); ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get());
let context = BaseAudioContext { BaseAudioContext {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
audio_context_impl: ServoMedia::get() audio_context_impl: ServoMedia::get()
.unwrap() .unwrap()
@ -135,9 +135,7 @@ impl BaseAudioContext {
sample_rate, sample_rate,
state: Cell::new(AudioContextState::Suspended), state: Cell::new(AudioContextState::Suspended),
channel_count: channel_count.into(), channel_count: channel_count.into(),
}; }
context
} }
/// Tells whether this is an OfflineAudioContext or not. /// Tells whether this is an OfflineAudioContext or not.

View file

@ -309,11 +309,10 @@ impl BlobMethods for Blob {
/// see <https://github.com/w3c/FileAPI/issues/43> /// see <https://github.com/w3c/FileAPI/issues/43>
pub fn normalize_type_string(s: &str) -> String { pub fn normalize_type_string(s: &str) -> String {
if is_ascii_printable(s) { if is_ascii_printable(s) {
let s_lower = s.to_ascii_lowercase(); s.to_ascii_lowercase()
// match s_lower.parse() as Result<Mime, ()> { // match s_lower.parse() as Result<Mime, ()> {
// Ok(_) => s_lower, // Ok(_) => s_lower,
// Err(_) => "".to_string() // Err(_) => "".to_string()
s_lower
} else { } else {
"".to_string() "".to_string()
} }

View file

@ -73,8 +73,7 @@ impl CSSStyleOwner {
let lock = attr.as_ref().unwrap(); let lock = attr.as_ref().unwrap();
let mut guard = shared_lock.write(); let mut guard = shared_lock.write();
let pdb = lock.write_with(&mut guard); let pdb = lock.write_with(&mut guard);
let result = f(pdb, &mut changed); f(pdb, &mut changed)
result
} else { } else {
let mut pdb = PropertyDeclarationBlock::new(); let mut pdb = PropertyDeclarationBlock::new();
let result = f(&mut pdb, &mut changed); let result = f(&mut pdb, &mut changed);

View file

@ -2771,7 +2771,7 @@ impl GlobalScope {
return p; return p;
} }
let promise = match image { match image {
ImageBitmapSource::HTMLCanvasElement(ref canvas) => { ImageBitmapSource::HTMLCanvasElement(ref canvas) => {
// https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument // https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument
if !canvas.is_valid() { if !canvas.is_valid() {
@ -2815,8 +2815,7 @@ impl GlobalScope {
p.reject_error(Error::NotSupported); p.reject_error(Error::NotSupported);
return p; return p;
}, },
}; }
promise
} }
pub fn fire_timer(&self, handle: TimerEventId) { pub fn fire_timer(&self, handle: TimerEventId) {

View file

@ -50,14 +50,13 @@ pub struct MediaSession {
impl MediaSession { impl MediaSession {
#[allow(crown::unrooted_must_root)] #[allow(crown::unrooted_must_root)]
fn new_inherited() -> MediaSession { fn new_inherited() -> MediaSession {
let media_session = MediaSession { MediaSession {
reflector_: Reflector::new(), reflector_: Reflector::new(),
metadata: DomRefCell::new(None), metadata: DomRefCell::new(None),
playback_state: DomRefCell::new(MediaSessionPlaybackState::None), playback_state: DomRefCell::new(MediaSessionPlaybackState::None),
action_handlers: DomRefCell::new(HashMapTracedValues::new()), action_handlers: DomRefCell::new(HashMapTracedValues::new()),
media_instance: Default::default(), media_instance: Default::default(),
}; }
media_session
} }
pub fn new(window: &Window) -> DomRoot<MediaSession> { pub fn new(window: &Window) -> DomRoot<MediaSession> {

View file

@ -72,7 +72,7 @@ impl RTCDataChannel {
.expect("Expected data channel id"), .expect("Expected data channel id"),
); );
let channel = RTCDataChannel { RTCDataChannel {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
servo_media_id, servo_media_id,
peer_connection: Dom::from_ref(peer_connection), peer_connection: Dom::from_ref(peer_connection),
@ -85,9 +85,7 @@ impl RTCDataChannel {
id: options.id, id: options.id,
ready_state: Cell::new(RTCDataChannelState::Connecting), ready_state: Cell::new(RTCDataChannelState::Connecting),
binary_type: DomRefCell::new(DOMString::from("blob")), binary_type: DomRefCell::new(DOMString::from("blob")),
}; }
channel
} }
pub fn new( pub fn new(

View file

@ -427,10 +427,9 @@ impl WebGL2RenderingContext {
let last_row_bytes = bytes_per_pixel let last_row_bytes = bytes_per_pixel
.checked_mul(width as usize) .checked_mul(width as usize)
.ok_or(InvalidOperation)?; .ok_or(InvalidOperation)?;
let result = full_row_bytes full_row_bytes
.checked_add(last_row_bytes) .checked_add(last_row_bytes)
.ok_or(InvalidOperation)?; .ok_or(InvalidOperation)?
result
}; };
let skipped_bytes = { let skipped_bytes = {
let skipped_row_bytes = self let skipped_row_bytes = self
@ -443,10 +442,9 @@ impl WebGL2RenderingContext {
.get() .get()
.checked_mul(bytes_per_pixel) .checked_mul(bytes_per_pixel)
.ok_or(InvalidOperation)?; .ok_or(InvalidOperation)?;
let result = skipped_row_bytes skipped_row_bytes
.checked_add(skipped_pixel_bytes) .checked_add(skipped_pixel_bytes)
.ok_or(InvalidOperation)?; .ok_or(InvalidOperation)?
result
}; };
Ok(ReadPixelsSizes { Ok(ReadPixelsSizes {
row_stride, row_stride,
@ -4119,12 +4117,11 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
self.base.validate_ownership(program), self.base.validate_ownership(program),
return constants::INVALID_INDEX return constants::INVALID_INDEX
); );
let index = handle_potential_webgl_error!( handle_potential_webgl_error!(
self.base, self.base,
program.get_uniform_block_index(block_name), program.get_uniform_block_index(block_name),
return constants::INVALID_INDEX return constants::INVALID_INDEX
); )
index
} }
/// <https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.16> /// <https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.16>