Skip to content

Commit 4190905

Browse files
committed
Rename downcast_[ref|mut]_unchecked -> downcast_unchecked_[ref|mut]
1 parent ab92564 commit 4190905

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

library/core/src/any.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl dyn Any {
227227
// SAFETY: just checked whether we are pointing to the correct type, and we can rely on
228228
// that check for memory safety because we have implemented Any for all types; no other
229229
// impls can exist as they would conflict with our impl.
230-
unsafe { Some(self.downcast_ref_unchecked()) }
230+
unsafe { Some(self.downcast_unchecked_ref()) }
231231
} else {
232232
None
233233
}
@@ -263,7 +263,7 @@ impl dyn Any {
263263
// SAFETY: just checked whether we are pointing to the correct type, and we can rely on
264264
// that check for memory safety because we have implemented Any for all types; no other
265265
// impls can exist as they would conflict with our impl.
266-
unsafe { Some(self.downcast_mut_unchecked()) }
266+
unsafe { Some(self.downcast_unchecked_mut()) }
267267
} else {
268268
None
269269
}
@@ -281,7 +281,7 @@ impl dyn Any {
281281
/// let x: Box<dyn Any> = Box::new(1_usize);
282282
///
283283
/// unsafe {
284-
/// assert_eq!(*x.downcast_ref_unchecked::<usize>(), 1);
284+
/// assert_eq!(*x.downcast_unchecked_ref::<usize>(), 1);
285285
/// }
286286
/// ```
287287
///
@@ -291,7 +291,7 @@ impl dyn Any {
291291
/// with the incorrect type is *undefined behavior*.
292292
#[unstable(feature = "downcast_unchecked", issue = "90850")]
293293
#[inline]
294-
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
294+
pub unsafe fn downcast_unchecked_ref<T: Any>(&self) -> &T {
295295
debug_assert!(self.is::<T>());
296296
// SAFETY: caller guarantees that T is the correct type
297297
unsafe { &*(self as *const dyn Any as *const T) }
@@ -309,7 +309,7 @@ impl dyn Any {
309309
/// let mut x: Box<dyn Any> = Box::new(1_usize);
310310
///
311311
/// unsafe {
312-
/// *x.downcast_mut_unchecked::<usize>() += 1;
312+
/// *x.downcast_unchecked_mut::<usize>() += 1;
313313
/// }
314314
///
315315
/// assert_eq!(*x.downcast_ref::<usize>().unwrap(), 2);
@@ -321,7 +321,7 @@ impl dyn Any {
321321
/// with the incorrect type is *undefined behavior*.
322322
#[unstable(feature = "downcast_unchecked", issue = "90850")]
323323
#[inline]
324-
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {
324+
pub unsafe fn downcast_unchecked_mut<T: Any>(&mut self) -> &mut T {
325325
debug_assert!(self.is::<T>());
326326
// SAFETY: caller guarantees that T is the correct type
327327
unsafe { &mut *(self as *mut dyn Any as *mut T) }
@@ -417,7 +417,7 @@ impl dyn Any + Send {
417417
/// let x: Box<dyn Any> = Box::new(1_usize);
418418
///
419419
/// unsafe {
420-
/// assert_eq!(*x.downcast_ref_unchecked::<usize>(), 1);
420+
/// assert_eq!(*x.downcast_unchecked_ref::<usize>(), 1);
421421
/// }
422422
/// ```
423423
///
@@ -427,9 +427,9 @@ impl dyn Any + Send {
427427
/// with the incorrect type is *undefined behavior*.
428428
#[unstable(feature = "downcast_unchecked", issue = "90850")]
429429
#[inline]
430-
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
430+
pub unsafe fn downcast_unchecked_ref<T: Any>(&self) -> &T {
431431
// SAFETY: guaranteed by caller
432-
unsafe { <dyn Any>::downcast_ref_unchecked::<T>(self) }
432+
unsafe { <dyn Any>::downcast_unchecked_ref::<T>(self) }
433433
}
434434

435435
/// Forwards to the method defined on the type `dyn Any`.
@@ -444,7 +444,7 @@ impl dyn Any + Send {
444444
/// let mut x: Box<dyn Any> = Box::new(1_usize);
445445
///
446446
/// unsafe {
447-
/// *x.downcast_mut_unchecked::<usize>() += 1;
447+
/// *x.downcast_unchecked_mut::<usize>() += 1;
448448
/// }
449449
///
450450
/// assert_eq!(*x.downcast_ref::<usize>().unwrap(), 2);
@@ -456,9 +456,9 @@ impl dyn Any + Send {
456456
/// with the incorrect type is *undefined behavior*.
457457
#[unstable(feature = "downcast_unchecked", issue = "90850")]
458458
#[inline]
459-
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {
459+
pub unsafe fn downcast_unchecked_mut<T: Any>(&mut self) -> &mut T {
460460
// SAFETY: guaranteed by caller
461-
unsafe { <dyn Any>::downcast_mut_unchecked::<T>(self) }
461+
unsafe { <dyn Any>::downcast_unchecked_mut::<T>(self) }
462462
}
463463
}
464464

@@ -551,7 +551,7 @@ impl dyn Any + Send + Sync {
551551
/// let x: Box<dyn Any> = Box::new(1_usize);
552552
///
553553
/// unsafe {
554-
/// assert_eq!(*x.downcast_ref_unchecked::<usize>(), 1);
554+
/// assert_eq!(*x.downcast_unchecked_ref::<usize>(), 1);
555555
/// }
556556
/// ```
557557
/// # Safety
@@ -560,9 +560,9 @@ impl dyn Any + Send + Sync {
560560
/// with the incorrect type is *undefined behavior*.
561561
#[unstable(feature = "downcast_unchecked", issue = "90850")]
562562
#[inline]
563-
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
563+
pub unsafe fn downcast_unchecked_ref<T: Any>(&self) -> &T {
564564
// SAFETY: guaranteed by caller
565-
unsafe { <dyn Any>::downcast_ref_unchecked::<T>(self) }
565+
unsafe { <dyn Any>::downcast_unchecked_ref::<T>(self) }
566566
}
567567

568568
/// Forwards to the method defined on the type `Any`.
@@ -577,7 +577,7 @@ impl dyn Any + Send + Sync {
577577
/// let mut x: Box<dyn Any> = Box::new(1_usize);
578578
///
579579
/// unsafe {
580-
/// *x.downcast_mut_unchecked::<usize>() += 1;
580+
/// *x.downcast_unchecked_mut::<usize>() += 1;
581581
/// }
582582
///
583583
/// assert_eq!(*x.downcast_ref::<usize>().unwrap(), 2);
@@ -588,9 +588,9 @@ impl dyn Any + Send + Sync {
588588
/// with the incorrect type is *undefined behavior*.
589589
#[unstable(feature = "downcast_unchecked", issue = "90850")]
590590
#[inline]
591-
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {
591+
pub unsafe fn downcast_unchecked_mut<T: Any>(&mut self) -> &mut T {
592592
// SAFETY: guaranteed by caller
593-
unsafe { <dyn Any>::downcast_mut_unchecked::<T>(self) }
593+
unsafe { <dyn Any>::downcast_unchecked_mut::<T>(self) }
594594
}
595595
}
596596

src/tools/rust-analyzer/bench_data/numerous_macro_rules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ macro_rules! __ra_macro_fixture313 {($name : ident , $($s : expr , $o : expr
315315
macro_rules! __ra_macro_fixture314 {($name : ident , min : $min : expr , max : $max : expr , imin : $imin : expr , imax : $imax : expr , $($s : expr ),* )=>{# [ test ] fn $name (){ let items : Vec <& 'static str > = vec ! [$($s ),*]; let items : Vec <_> = items . into_iter (). enumerate (). map (| ( i , k )| ( k , i as u64 )). collect (); let fst = fst_map ( items . clone ()); let mut rdr = Stream :: new ( fst . as_ref (), AlwaysMatch , $min , $max ); for i in $imin ..$imax { assert_eq ! ( rdr . next (). unwrap (), ( items [ i ]. 0 . as_bytes (), Output :: new ( items [ i ]. 1 )), ); } assert_eq ! ( rdr . next (), None ); }}}
316316
macro_rules! __ra_macro_fixture315 {($ty : ty , $tag : ident )=>{ impl TryFrom < Response > for $ty { type Error = & 'static str ; fn try_from ( value : Response )-> Result < Self , Self :: Error > { match value { Response ::$tag ( res )=> Ok ( res ), _ => Err ( concat ! ( "Failed to convert response to " , stringify ! ($tag ))), }}}}; }
317317
macro_rules! __ra_macro_fixture316 {( CloneAny )=>{# [ doc = " A type to emulate dynamic typing." ]# [ doc = "" ]# [ doc = " Every type with no non-`\\\'static` references implements `Any`." ] define ! ( CloneAny remainder ); }; ( Any )=>{# [ doc = " A type to emulate dynamic typing with cloning." ]# [ doc = "" ]# [ doc = " Every type with no non-`\\\'static` references that implements `Clone` implements `Any`." ] define ! ( Any remainder ); }; ($t : ident remainder )=>{# [ doc = " See the [`std::any` documentation](https://doc.rust-lang.org/std/any/index.html) for" ]# [ doc = " more details on `Any` in general." ]# [ doc = "" ]# [ doc = " This trait is not `std::any::Any` but rather a type extending that for this library\\u{2019}s" ]# [ doc = " purposes so that it can be combined with marker traits like " ]# [ doc = " <code><a class=trait title=core::marker::Send" ]# [ doc = " href=http://doc.rust-lang.org/std/marker/trait.Send.html>Send</a></code> and" ]# [ doc = " <code><a class=trait title=core::marker::Sync" ]# [ doc = " href=http://doc.rust-lang.org/std/marker/trait.Sync.html>Sync</a></code>." ]# [ doc = "" ] define ! ($t trait ); }; ( CloneAny trait )=>{# [ doc = " See also [`Any`](trait.Any.html) for a version without the `Clone` requirement." ] pub trait CloneAny : Any + CloneToAny {} impl < T : StdAny + Clone > CloneAny for T {}}; ( Any trait )=>{# [ doc = " See also [`CloneAny`](trait.CloneAny.html) for a cloneable version of this trait." ] pub trait Any : StdAny {} impl < T : StdAny > Any for T {}}; }
318-
macro_rules! __ra_macro_fixture317 {($base : ident , $(+ $bounds : ident )*)=>{ impl fmt :: Debug for $base $(+ $bounds )* {# [ inline ] fn fmt (& self , f : & mut fmt :: Formatter )-> fmt :: Result { f . pad ( stringify ! ($base $(+ $bounds )*))}} impl UncheckedAnyExt for $base $(+ $bounds )* {# [ inline ] unsafe fn downcast_ref_unchecked < T : 'static > (& self )-> & T {&* ( self as * const Self as * const T )}# [ inline ] unsafe fn downcast_mut_unchecked < T : 'static > (& mut self )-> & mut T {& mut * ( self as * mut Self as * mut T )}# [ inline ] unsafe fn downcast_unchecked < T : 'static > ( self : Box < Self >)-> Box < T > { Box :: from_raw ( Box :: into_raw ( self ) as * mut T )}} impl < T : $base $(+ $bounds )*> IntoBox <$base $(+ $bounds )*> for T {# [ inline ] fn into_box ( self )-> Box <$base $(+ $bounds )*> { Box :: new ( self )}}}}
318+
macro_rules! __ra_macro_fixture317 {($base : ident , $(+ $bounds : ident )*)=>{ impl fmt :: Debug for $base $(+ $bounds )* {# [ inline ] fn fmt (& self , f : & mut fmt :: Formatter )-> fmt :: Result { f . pad ( stringify ! ($base $(+ $bounds )*))}} impl UncheckedAnyExt for $base $(+ $bounds )* {# [ inline ] unsafe fn downcast_unchecked_ref < T : 'static > (& self )-> & T {&* ( self as * const Self as * const T )}# [ inline ] unsafe fn downcast_unchecked_mut < T : 'static > (& mut self )-> & mut T {& mut * ( self as * mut Self as * mut T )}# [ inline ] unsafe fn downcast_unchecked < T : 'static > ( self : Box < Self >)-> Box < T > { Box :: from_raw ( Box :: into_raw ( self ) as * mut T )}} impl < T : $base $(+ $bounds )*> IntoBox <$base $(+ $bounds )*> for T {# [ inline ] fn into_box ( self )-> Box <$base $(+ $bounds )*> { Box :: new ( self )}}}}
319319
macro_rules! __ra_macro_fixture318 {($t : ty , $method : ident )=>{ impl Clone for Box <$t > {# [ inline ] fn clone (& self )-> Box <$t > {(** self ).$method ()}}}}
320320
macro_rules! __ra_macro_fixture319 {( field : $t : ident .$field : ident ; new ()=>$new : expr ; with_capacity ($with_capacity_arg : ident )=>$with_capacity : expr ; )=>{ impl < A : ? Sized + UncheckedAnyExt > $t < A > {# [ doc = " Create an empty collection." ]# [ inline ] pub fn new ()-> $t < A > {$t {$field : $new , }}# [ doc = " Creates an empty collection with the given initial capacity." ]# [ inline ] pub fn with_capacity ($with_capacity_arg : usize )-> $t < A > {$t {$field : $with_capacity , }}# [ doc = " Returns the number of elements the collection can hold without reallocating." ]# [ inline ] pub fn capacity (& self )-> usize { self .$field . capacity ()}# [ doc = " Reserves capacity for at least `additional` more elements to be inserted" ]# [ doc = " in the collection. The collection may reserve more space to avoid" ]# [ doc = " frequent reallocations." ]# [ doc = "" ]# [ doc = " # Panics" ]# [ doc = "" ]# [ doc = " Panics if the new allocation size overflows `usize`." ]# [ inline ] pub fn reserve (& mut self , additional : usize ){ self .$field . reserve ( additional )}# [ doc = " Shrinks the capacity of the collection as much as possible. It will drop" ]# [ doc = " down as much as possible while maintaining the internal rules" ]# [ doc = " and possibly leaving some space in accordance with the resize policy." ]# [ inline ] pub fn shrink_to_fit (& mut self ){ self .$field . shrink_to_fit ()}# [ doc = " Returns the number of items in the collection." ]# [ inline ] pub fn len (& self )-> usize { self .$field . len ()}# [ doc = " Returns true if there are no items in the collection." ]# [ inline ] pub fn is_empty (& self )-> bool { self .$field . is_empty ()}# [ doc = " Removes all items from the collection. Keeps the allocated memory for reuse." ]# [ inline ] pub fn clear (& mut self ){ self .$field . clear ()}}}}
321321
macro_rules! __ra_macro_fixture320 {($name : ident , $init : ty )=>{# [ test ] fn $name (){ let mut map = <$init >:: new (); assert_eq ! ( map . insert ( A ( 10 )), None ); assert_eq ! ( map . insert ( B ( 20 )), None ); assert_eq ! ( map . insert ( C ( 30 )), None ); assert_eq ! ( map . insert ( D ( 40 )), None ); assert_eq ! ( map . insert ( E ( 50 )), None ); assert_eq ! ( map . insert ( F ( 60 )), None ); match map . entry ::< A > (){ Entry :: Vacant (_)=> unreachable ! (), Entry :: Occupied ( mut view )=>{ assert_eq ! ( view . get (), & A ( 10 )); assert_eq ! ( view . insert ( A ( 100 )), A ( 10 )); }} assert_eq ! ( map . get ::< A > (). unwrap (), & A ( 100 )); assert_eq ! ( map . len (), 6 ); match map . entry ::< B > (){ Entry :: Vacant (_)=> unreachable ! (), Entry :: Occupied ( mut view )=>{ let v = view . get_mut (); let new_v = B ( v . 0 * 10 ); * v = new_v ; }} assert_eq ! ( map . get ::< B > (). unwrap (), & B ( 200 )); assert_eq ! ( map . len (), 6 ); match map . entry ::< C > (){ Entry :: Vacant (_)=> unreachable ! (), Entry :: Occupied ( view )=>{ assert_eq ! ( view . remove (), C ( 30 )); }} assert_eq ! ( map . get ::< C > (), None ); assert_eq ! ( map . len (), 5 ); match map . entry ::< J > (){ Entry :: Occupied (_)=> unreachable ! (), Entry :: Vacant ( view )=>{ assert_eq ! (* view . insert ( J ( 1000 )), J ( 1000 )); }} assert_eq ! ( map . get ::< J > (). unwrap (), & J ( 1000 )); assert_eq ! ( map . len (), 6 ); map . entry ::< B > (). or_insert ( B ( 71 )). 0 += 1 ; assert_eq ! ( map . get ::< B > (). unwrap (), & B ( 201 )); assert_eq ! ( map . len (), 6 ); map . entry ::< C > (). or_insert ( C ( 300 )). 0 += 1 ; assert_eq ! ( map . get ::< C > (). unwrap (), & C ( 301 )); assert_eq ! ( map . len (), 7 ); }}}

src/tools/rust-analyzer/crates/stdx/src/anymap.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<A: ?Sized + Downcast> Map<A> {
117117
#[inline]
118118
#[must_use]
119119
pub fn get<T: IntoBox<A>>(&self) -> Option<&T> {
120-
self.raw.get(&TypeId::of::<T>()).map(|any| unsafe { any.downcast_ref_unchecked::<T>() })
120+
self.raw.get(&TypeId::of::<T>()).map(|any| unsafe { any.downcast_unchecked_ref::<T>() })
121121
}
122122

123123
/// Gets the entry for the given type in the collection for in-place manipulation
@@ -172,7 +172,7 @@ impl<'map, A: ?Sized + Downcast, V: IntoBox<A>> OccupiedEntry<'map, A, V> {
172172
#[inline]
173173
#[must_use]
174174
pub fn into_mut(self) -> &'map mut V {
175-
unsafe { self.inner.into_mut().downcast_mut_unchecked() }
175+
unsafe { self.inner.into_mut().downcast_unchecked_mut() }
176176
}
177177
}
178178

@@ -181,7 +181,7 @@ impl<'map, A: ?Sized + Downcast, V: IntoBox<A>> VacantEntry<'map, A, V> {
181181
/// and returns a mutable reference to it
182182
#[inline]
183183
pub fn insert(self, value: V) -> &'map mut V {
184-
unsafe { self.inner.insert(value.into_box()).downcast_mut_unchecked() }
184+
unsafe { self.inner.insert(value.into_box()).downcast_unchecked_mut() }
185185
}
186186
}
187187

@@ -244,14 +244,14 @@ pub trait Downcast {
244244
/// # Safety
245245
///
246246
/// The caller must ensure that `T` matches the trait object, on pain of *undefined behavior*.
247-
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T;
247+
unsafe fn downcast_unchecked_ref<T: 'static>(&self) -> &T;
248248

249249
/// Downcast from `&mut Any` to `&mut T`, without checking the type matches.
250250
///
251251
/// # Safety
252252
///
253253
/// The caller must ensure that `T` matches the trait object, on pain of *undefined behavior*.
254-
unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T;
254+
unsafe fn downcast_unchecked_mut<T: 'static>(&mut self) -> &mut T;
255255
}
256256

257257
/// A trait for the conversion of an object into a boxed trait object.
@@ -269,12 +269,12 @@ macro_rules! implement {
269269
}
270270

271271
#[inline]
272-
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T {
272+
unsafe fn downcast_unchecked_ref<T: 'static>(&self) -> &T {
273273
unsafe { &*std::ptr::from_ref::<Self>(self).cast::<T>() }
274274
}
275275

276276
#[inline]
277-
unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T {
277+
unsafe fn downcast_unchecked_mut<T: 'static>(&mut self) -> &mut T {
278278
unsafe { &mut *std::ptr::from_mut::<Self>(self).cast::<T>() }
279279
}
280280
}

tests/ui/suggestions/ambiguous-assoc-type-path-suggest-similar-item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() {
4444
//~^ ERROR ambiguous associated type [E0223]
4545
//~| HELP if there were a trait named `Example` with associated type `wrapping`
4646

47-
// this one ideally should suggest `downcast_mut_unchecked`
47+
// this one ideally should suggest `downcast_unchecked_mut`
4848
<dyn std::any::Any>::downcast::mut_unchecked;
4949
//~^ ERROR ambiguous associated type [E0223]
5050
//~| HELP if there were a trait named `Example` with associated type `downcast`

0 commit comments

Comments
 (0)