Skip to content

Commit 618b5d3

Browse files
authored
Merge pull request #1571 from alexcrichton/less-warnings
Use `dyn` with all trait objects
2 parents c876bd6 + 82467f9 commit 618b5d3

File tree

15 files changed

+148
-146
lines changed

15 files changed

+148
-146
lines changed

crates/backend/src/codegen.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl ToTokens for ast::Struct {
166166
impl wasm_bindgen::convert::IntoWasmAbi for #name {
167167
type Abi = u32;
168168

169-
fn into_abi(self, _extra: &mut wasm_bindgen::convert::Stack)
169+
fn into_abi(self, _extra: &mut dyn wasm_bindgen::convert::Stack)
170170
-> u32
171171
{
172172
use wasm_bindgen::__rt::std::boxed::Box;
@@ -179,7 +179,7 @@ impl ToTokens for ast::Struct {
179179
impl wasm_bindgen::convert::FromWasmAbi for #name {
180180
type Abi = u32;
181181

182-
unsafe fn from_abi(js: u32, _extra: &mut wasm_bindgen::convert::Stack)
182+
unsafe fn from_abi(js: u32, _extra: &mut dyn wasm_bindgen::convert::Stack)
183183
-> Self
184184
{
185185
use wasm_bindgen::__rt::std::boxed::Box;
@@ -210,7 +210,7 @@ impl ToTokens for ast::Struct {
210210
}
211211

212212
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
213-
unsafe fn #new_fn(ptr: u32) -> u32 {
213+
unsafe fn #new_fn(_: u32) -> u32 {
214214
panic!("cannot convert to JsValue outside of the wasm target")
215215
}
216216

@@ -242,7 +242,7 @@ impl ToTokens for ast::Struct {
242242

243243
unsafe fn ref_from_abi(
244244
js: Self::Abi,
245-
_extra: &mut wasm_bindgen::convert::Stack,
245+
_extra: &mut dyn wasm_bindgen::convert::Stack,
246246
) -> Self::Anchor {
247247
let js = js as *mut wasm_bindgen::__rt::WasmRefCell<#name>;
248248
wasm_bindgen::__rt::assert_not_null(js);
@@ -257,7 +257,7 @@ impl ToTokens for ast::Struct {
257257

258258
unsafe fn ref_mut_from_abi(
259259
js: Self::Abi,
260-
_extra: &mut wasm_bindgen::convert::Stack,
260+
_extra: &mut dyn wasm_bindgen::convert::Stack,
261261
) -> Self::Anchor {
262262
let js = js as *mut wasm_bindgen::__rt::WasmRefCell<#name>;
263263
wasm_bindgen::__rt::assert_not_null(js);
@@ -637,7 +637,7 @@ impl ToTokens for ast::ImportType {
637637
type Abi = <JsValue as IntoWasmAbi>::Abi;
638638

639639
#[inline]
640-
fn into_abi(self, extra: &mut Stack) -> Self::Abi {
640+
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi {
641641
self.obj.into_abi(extra)
642642
}
643643
}
@@ -656,7 +656,7 @@ impl ToTokens for ast::ImportType {
656656
type Abi = <JsValue as FromWasmAbi>::Abi;
657657

658658
#[inline]
659-
unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self {
659+
unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self {
660660
#rust_name {
661661
obj: JsValue::from_abi(js, extra).into(),
662662
}
@@ -672,7 +672,7 @@ impl ToTokens for ast::ImportType {
672672
type Abi = <&'a JsValue as IntoWasmAbi>::Abi;
673673

674674
#[inline]
675-
fn into_abi(self, extra: &mut Stack) -> Self::Abi {
675+
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi {
676676
(&self.obj).into_abi(extra)
677677
}
678678
}
@@ -682,7 +682,7 @@ impl ToTokens for ast::ImportType {
682682
type Anchor = core::mem::ManuallyDrop<#rust_name>;
683683

684684
#[inline]
685-
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor {
685+
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor {
686686
let tmp = <JsValue as RefFromWasmAbi>::ref_from_abi(js, extra);
687687
core::mem::ManuallyDrop::new(#rust_name {
688688
obj: core::mem::ManuallyDrop::into_inner(tmp).into(),
@@ -719,7 +719,7 @@ impl ToTokens for ast::ImportType {
719719
fn #instanceof_shim(val: u32) -> u32;
720720
}
721721
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
722-
unsafe fn #instanceof_shim(val: u32) -> u32 {
722+
unsafe fn #instanceof_shim(_: u32) -> u32 {
723723
panic!("cannot check instanceof on non-wasm targets");
724724
}
725725
unsafe {
@@ -838,7 +838,7 @@ impl ToTokens for ast::ImportEnum {
838838
wasm_bindgen::convert::IntoWasmAbi>::Abi;
839839

840840
#[inline]
841-
fn into_abi(self, extra: &mut wasm_bindgen::convert::Stack) -> Self::Abi {
841+
fn into_abi(self, extra: &mut dyn wasm_bindgen::convert::Stack) -> Self::Abi {
842842
wasm_bindgen::JsValue::from(self).into_abi(extra)
843843
}
844844
}
@@ -850,7 +850,7 @@ impl ToTokens for ast::ImportEnum {
850850

851851
unsafe fn from_abi(
852852
js: Self::Abi,
853-
extra: &mut wasm_bindgen::convert::Stack,
853+
extra: &mut dyn wasm_bindgen::convert::Stack,
854854
) -> Self {
855855
#name::from_js_value(&wasm_bindgen::JsValue::from_abi(js, extra)).unwrap_or(#name::__Nonexhaustive)
856856
}
@@ -997,6 +997,7 @@ impl TryToTokens for ast::ImportFunction {
997997
let attrs = &self.function.rust_attrs;
998998
let arguments = &arguments;
999999
let abi_arguments = &abi_arguments;
1000+
let abi_argument_names = &abi_argument_names;
10001001

10011002
let doc_comment = match &self.doc_comment {
10021003
None => "",
@@ -1032,6 +1033,7 @@ impl TryToTokens for ast::ImportFunction {
10321033
}
10331034
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
10341035
unsafe fn #import_name(#(#abi_arguments),*) -> #abi_ret {
1036+
drop((#(#abi_argument_names),*));
10351037
panic!("cannot call wasm-bindgen imported functions on \
10361038
non-wasm targets");
10371039
}
@@ -1125,7 +1127,7 @@ impl ToTokens for ast::Enum {
11251127
type Abi = u32;
11261128

11271129
#[inline]
1128-
fn into_abi(self, _extra: &mut wasm_bindgen::convert::Stack) -> u32 {
1130+
fn into_abi(self, _extra: &mut dyn wasm_bindgen::convert::Stack) -> u32 {
11291131
self as u32
11301132
}
11311133
}
@@ -1137,7 +1139,7 @@ impl ToTokens for ast::Enum {
11371139
#[inline]
11381140
unsafe fn from_abi(
11391141
js: u32,
1140-
_extra: &mut wasm_bindgen::convert::Stack,
1142+
_extra: &mut dyn wasm_bindgen::convert::Stack,
11411143
) -> Self {
11421144
#(#cast_clauses else)* {
11431145
wasm_bindgen::throw_str("invalid enum value passed")
@@ -1331,23 +1333,23 @@ impl ToTokens for ast::Dictionary {
13311333
impl IntoWasmAbi for #name {
13321334
type Abi = <Object as IntoWasmAbi>::Abi;
13331335
#[inline]
1334-
fn into_abi(self, extra: &mut Stack) -> Self::Abi {
1336+
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi {
13351337
self.obj.into_abi(extra)
13361338
}
13371339
}
13381340

13391341
impl<'a> IntoWasmAbi for &'a #name {
13401342
type Abi = <&'a Object as IntoWasmAbi>::Abi;
13411343
#[inline]
1342-
fn into_abi(self, extra: &mut Stack) -> Self::Abi {
1344+
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi {
13431345
(&self.obj).into_abi(extra)
13441346
}
13451347
}
13461348

13471349
impl FromWasmAbi for #name {
13481350
type Abi = <Object as FromWasmAbi>::Abi;
13491351
#[inline]
1350-
unsafe fn from_abi(abi: Self::Abi, extra: &mut Stack) -> Self {
1352+
unsafe fn from_abi(abi: Self::Abi, extra: &mut dyn Stack) -> Self {
13511353
#name { obj: Object::from_abi(abi, extra) }
13521354
}
13531355
}
@@ -1370,7 +1372,7 @@ impl ToTokens for ast::Dictionary {
13701372
type Anchor = ManuallyDrop<#name>;
13711373

13721374
#[inline]
1373-
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor {
1375+
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor {
13741376
let tmp = <Object as RefFromWasmAbi>::ref_from_abi(js, extra);
13751377
ManuallyDrop::new(#name {
13761378
obj: ManuallyDrop::into_inner(tmp),

crates/backend/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Diagnostic {
5252
}
5353
}
5454

55-
pub fn spanned_error<T: Into<String>>(node: &ToTokens, text: T) -> Diagnostic {
55+
pub fn spanned_error<T: Into<String>>(node: &dyn ToTokens, text: T) -> Diagnostic {
5656
Diagnostic {
5757
inner: Repr::Single {
5858
text: text.into(),
@@ -89,7 +89,7 @@ impl From<Error> for Diagnostic {
8989
}
9090
}
9191

92-
fn extract_spans(node: &ToTokens) -> Option<(Span, Span)> {
92+
fn extract_spans(node: &dyn ToTokens) -> Option<(Span, Span)> {
9393
let mut t = TokenStream::new();
9494
node.to_tokens(&mut t);
9595
let mut tokens = t.into_iter();

crates/cli-support/src/js/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ impl<'a> Context<'a> {
10861086
fn bind(
10871087
&mut self,
10881088
name: &str,
1089-
f: &Fn(&mut Self) -> Result<String, Error>,
1089+
f: &dyn Fn(&mut Self) -> Result<String, Error>,
10901090
) -> Result<(), Error> {
10911091
if !self.wasm_import_needed(name) {
10921092
return Ok(());

crates/futures/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ use wasm_bindgen::prelude::*;
130130
pub struct JsFuture {
131131
resolved: oneshot::Receiver<JsValue>,
132132
rejected: oneshot::Receiver<JsValue>,
133-
callbacks: Option<(Closure<FnMut(JsValue)>, Closure<FnMut(JsValue)>)>,
133+
callbacks: Option<(Closure<dyn FnMut(JsValue)>, Closure<dyn FnMut(JsValue)>)>,
134134
}
135135

136136
impl fmt::Debug for JsFuture {
@@ -152,11 +152,11 @@ impl From<Promise> for JsFuture {
152152
let mut tx1 = Some(tx1);
153153
let resolve = Closure::wrap(Box::new(move |val| {
154154
drop(tx1.take().unwrap().send(val));
155-
}) as Box<FnMut(_)>);
155+
}) as Box<dyn FnMut(_)>);
156156
let mut tx2 = Some(tx2);
157157
let reject = Closure::wrap(Box::new(move |val| {
158158
drop(tx2.take().unwrap().send(val));
159-
}) as Box<FnMut(_)>);
159+
}) as Box<dyn FnMut(_)>);
160160

161161
js.then2(&resolve, &reject);
162162

@@ -233,7 +233,7 @@ where
233233
//
234234
// This isn't necessarily the greatest future executor in the world, but it
235235
// should get the job done for now hopefully.
236-
fn _future_to_promise(future: Box<Future<Item = JsValue, Error = JsValue>>) -> Promise {
236+
fn _future_to_promise(future: Box<dyn Future<Item = JsValue, Error = JsValue>>) -> Promise {
237237
let mut future = Some(executor::spawn(future));
238238
return Promise::new(&mut |resolve, reject| {
239239
Package::poll(&Arc::new(Package {
@@ -247,7 +247,7 @@ fn _future_to_promise(future: Box<Future<Item = JsValue, Error = JsValue>>) -> P
247247
struct Package {
248248
// Our "spawned future". This'll have everything we need to poll the
249249
// future and continue to move it forward.
250-
spawn: RefCell<Spawn<Box<Future<Item = JsValue, Error = JsValue>>>>,
250+
spawn: RefCell<Spawn<Box<dyn Future<Item = JsValue, Error = JsValue>>>>,
251251

252252
// The current state of this future, expressed in an enum below. This
253253
// indicates whether we're currently polling the future, received a
@@ -379,7 +379,7 @@ fn _future_to_promise(future: Box<Future<Item = JsValue, Error = JsValue>>) -> P
379379
let myself = slot2.borrow_mut().take();
380380
debug_assert!(myself.is_some());
381381
Package::poll(&me);
382-
}) as Box<FnMut(JsValue)>);
382+
}) as Box<dyn FnMut(JsValue)>);
383383
promise.then(&closure);
384384
*slot.borrow_mut() = Some(closure);
385385
}

0 commit comments

Comments
 (0)