Skip to content

Commit 9aa4912

Browse files
committed
Fix more clippy lints.
1 parent dffdade commit 9aa4912

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ needless_lifetimes = "allow"
77
option_if_let_else = "allow"
88
# see: https://github.com/bevyengine/bevy/pull/15375#issuecomment-2366966219
99
too_long_first_doc_paragraph = "allow"
10+
missing_panics_doc = "allow"
11+
doc-markdown = "allow"
1012

1113
nursery = { priority = -1, level = "warn" }
1214
pedantic = { priority = -1, level = "warn" }

trait_cast_impl_rs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Parse for TraitCastTargets {
2222
let targets: Vec<TypePath> = Punctuated::<TypePath, Token![,]>::parse_terminated(input)?
2323
.into_iter()
2424
.collect();
25-
Ok(TraitCastTargets { targets })
25+
Ok(Self { targets })
2626
}
2727
}
2828

trait_cast_rs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Note: No modifications on the *target* traits are necessary. Which allows you to
3939
## Example
4040

4141
```rust
42-
#![feature(ptr_metadata, min_specialization)]
42+
#![cfg_attr(feature = "min_specialization", feature(min_specialization))]
43+
#![feature(ptr_metadata)]
4344
use trait_cast_rs::{
4445
make_trait_castable, TraitcastableAny, TraitcastableAnyInfra, TraitcastableAnyInfraExt,
4546
};

trait_cast_rs/src/test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{make_trait_castable_decl, TraitcastableAny, TraitcastableAnyInfra};
22
use alloc::boxed::Box;
3-
use trait_cast_impl_rs::make_trait_castable;
43

54
const fn _test_empty_trait_cast_targets() {
65
struct Woof {}

trait_cast_rs/src/trait_cast.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ pub trait TraitcastableAnyInfra<Target: ?Sized>: 'static {
101101
fn downcast_ref(&self) -> Option<&Target>;
102102

103103
/// Unchecked variant of `downcast_ref`
104+
/// # Safety
105+
/// This function is unsafe because the caller must ensure that the cast is valid.
104106
#[cfg(feature = "downcast_unchecked")]
105107
#[doc(cfg(feature = "downcast_unchecked"))]
106108
unsafe fn downcast_ref_unchecked(&self) -> &Target;
@@ -114,6 +116,8 @@ pub trait TraitcastableAnyInfra<Target: ?Sized>: 'static {
114116
fn downcast_mut(&mut self) -> Option<&mut Target>;
115117

116118
/// Unchecked variant of `downcast_ref`
119+
/// # Safety
120+
/// This function is unsafe because the caller must ensure that the cast is valid.
117121
#[cfg(feature = "downcast_unchecked")]
118122
#[doc(cfg(feature = "downcast_unchecked"))]
119123
unsafe fn downcast_mut_unchecked(&mut self) -> &mut Target;
@@ -140,6 +144,8 @@ pub trait TraitcastableAnyInfraExt<Target: ?Sized + 'static>: Sized {
140144
fn downcast(self) -> Result<Self::Output, Self>;
141145

142146
/// Unchecked variant of `downcast`
147+
/// # Safety
148+
/// This function is unsafe because the caller must ensure that the cast is valid.
143149
#[cfg(feature = "downcast_unchecked")]
144150
#[doc(cfg(feature = "downcast_unchecked"))]
145151
unsafe fn downcast_unchecked(self) -> Self::Output;
@@ -202,7 +208,8 @@ macro_rules! implement_with_markers {
202208
}
203209
#[cfg(feature = "downcast_unchecked")]
204210
default unsafe fn downcast_ref_unchecked(&self) -> &Target {
205-
self.downcast_ref().unwrap_unchecked()
211+
// SAFETY: The caller must ensure that the cast is valid.
212+
unsafe { self.downcast_ref().unwrap_unchecked() }
206213
}
207214

208215
default fn downcast_mut(&mut self) -> Option<&mut Target> {
@@ -224,7 +231,8 @@ macro_rules! implement_with_markers {
224231
}
225232
#[cfg(feature = "downcast_unchecked")]
226233
default unsafe fn downcast_mut_unchecked(&mut self) -> &mut Target {
227-
self.downcast_mut().unwrap_unchecked()
234+
// SAFETY: The caller must ensure that the cast is valid.
235+
unsafe { self.downcast_mut().unwrap_unchecked() }
228236
}
229237
}
230238
impl<Target: Sized + 'static + $($traits +)*> TraitcastableAnyInfra<Target> for dyn TraitcastableAny $(+ $traits)* {
@@ -239,15 +247,17 @@ macro_rules! implement_with_markers {
239247
}
240248
#[cfg(feature = "downcast_unchecked")]
241249
unsafe fn downcast_ref_unchecked(&self) -> &Target {
242-
<dyn Any>::downcast_ref_unchecked::<Target>(self)
250+
// SAFETY: We are just forwarding the call to the `Any` trait.
251+
unsafe { <dyn Any>::downcast_ref_unchecked::<Target>(self) }
243252
}
244253

245254
fn downcast_mut(&mut self) -> Option<&mut Target> {
246255
<dyn Any>::downcast_mut::<Target>(self)
247256
}
248257
#[cfg(feature = "downcast_unchecked")]
249258
unsafe fn downcast_mut_unchecked(&mut self) -> &mut Target {
250-
<dyn Any>::downcast_mut_unchecked::<Target>(self)
259+
// SAFETY: We are just forwarding the call to the `Any` trait.
260+
unsafe { <dyn Any>::downcast_mut_unchecked::<Target>(self) }
251261
}
252262
}
253263
};
@@ -277,7 +287,8 @@ impl<Src: TraitcastableAnyInfra<Target> + ?Sized, Target: ?Sized + 'static>
277287
}
278288
#[cfg(feature = "downcast_unchecked")]
279289
default unsafe fn downcast_unchecked(self) -> Self::Output {
280-
<Self as TraitcastableAnyInfraExt<Target>>::downcast(self).unwrap_unchecked()
290+
// SAFETY: The caller must ensure that the cast is valid.
291+
unsafe { <Self as TraitcastableAnyInfraExt<Target>>::downcast(self).unwrap_unchecked() }
281292
}
282293
}
283294

@@ -304,7 +315,8 @@ impl<Src: TraitcastableAnyInfra<Target>, Target: Sized + 'static> TraitcastableA
304315

305316
#[cfg(feature = "downcast_unchecked")]
306317
unsafe fn downcast_unchecked(self) -> Self::Output {
307-
<Box<dyn Any>>::downcast_unchecked::<Target>(self)
318+
// SAFETY: The caller must ensure that the cast is valid.
319+
unsafe { <Box<dyn Any>>::downcast_unchecked::<Target>(self) }
308320
}
309321
}
310322

@@ -332,7 +344,8 @@ impl<Src: TraitcastableAnyInfra<Target> + ?Sized, Target: ?Sized + 'static>
332344
}
333345
#[cfg(feature = "downcast_unchecked")]
334346
default unsafe fn downcast_unchecked(self) -> Self::Output {
335-
<Self as TraitcastableAnyInfraExt<Target>>::downcast(self).unwrap_unchecked()
347+
// SAFETY: The caller must ensure that the cast is valid.
348+
unsafe { <Self as TraitcastableAnyInfraExt<Target>>::downcast(self).unwrap_unchecked() }
336349
}
337350
}
338351

@@ -359,7 +372,8 @@ impl<Src: TraitcastableAnyInfra<Target>, Target: Sized + 'static> TraitcastableA
359372

360373
#[cfg(feature = "downcast_unchecked")]
361374
unsafe fn downcast_unchecked(self) -> Self::Output {
362-
<Rc<dyn Any>>::downcast_unchecked::<Target>(self)
375+
// SAFETY: The caller must ensure that the cast is valid.
376+
unsafe { <Rc<dyn Any>>::downcast_unchecked::<Target>(self) }
363377
}
364378
}
365379

@@ -389,7 +403,8 @@ impl<
389403
}
390404
#[cfg(feature = "downcast_unchecked")]
391405
default unsafe fn downcast_unchecked(self) -> Self::Output {
392-
<Self as TraitcastableAnyInfraExt<Target>>::downcast(self).unwrap_unchecked()
406+
// SAFETY: The caller must ensure that the cast is valid.
407+
unsafe { <Self as TraitcastableAnyInfraExt<Target>>::downcast(self).unwrap_unchecked() }
393408
}
394409
}
395410

@@ -416,7 +431,8 @@ impl<Src: TraitcastableAnyInfra<Target> + Send + Sync, Target: Sized + 'static +
416431

417432
#[cfg(feature = "downcast_unchecked")]
418433
unsafe fn downcast_unchecked(self) -> Self::Output {
419-
<Arc<dyn Any + Send + Sync>>::downcast_unchecked::<Target>(self)
434+
// SAFETY: The caller must ensure that the cast is valid.
435+
unsafe { <Arc<dyn Any + Send + Sync>>::downcast_unchecked::<Target>(self) }
420436
}
421437
}
422438

0 commit comments

Comments
 (0)