Skip to content

Commit 033cbfe

Browse files
committed
Incorporate dyn into more comments and docs.
1 parent 7a0cef7 commit 033cbfe

File tree

9 files changed

+19
-18
lines changed

9 files changed

+19
-18
lines changed

src/liballoc/boxed.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ impl Box<dyn Any> {
489489
/// ```
490490
/// use std::any::Any;
491491
///
492-
/// fn print_if_string(value: Box<Any>) {
492+
/// fn print_if_string(value: Box<dyn Any>) {
493493
/// if let Ok(string) = value.downcast::<String>() {
494494
/// println!("String ({}): {}", string.len(), string);
495495
/// }
@@ -523,7 +523,7 @@ impl Box<dyn Any + Send> {
523523
/// ```
524524
/// use std::any::Any;
525525
///
526-
/// fn print_if_string(value: Box<Any + Send>) {
526+
/// fn print_if_string(value: Box<dyn Any + Send>) {
527527
/// if let Ok(string) = value.downcast::<String>() {
528528
/// println!("String ({}): {}", string.len(), string);
529529
/// }
@@ -618,18 +618,18 @@ impl<I: FusedIterator + ?Sized> FusedIterator for Box<I> {}
618618

619619
/// `FnBox` is a version of the `FnOnce` intended for use with boxed
620620
/// closure objects. The idea is that where one would normally store a
621-
/// `Box<FnOnce()>` in a data structure, you should use
622-
/// `Box<FnBox()>`. The two traits behave essentially the same, except
621+
/// `Box<dyn FnOnce()>` in a data structure, you should use
622+
/// `Box<dyn FnBox()>`. The two traits behave essentially the same, except
623623
/// that a `FnBox` closure can only be called if it is boxed. (Note
624-
/// that `FnBox` may be deprecated in the future if `Box<FnOnce()>`
624+
/// that `FnBox` may be deprecated in the future if `Box<dyn FnOnce()>`
625625
/// closures become directly usable.)
626626
///
627627
/// # Examples
628628
///
629629
/// Here is a snippet of code which creates a hashmap full of boxed
630630
/// once closures and then removes them one by one, calling each
631631
/// closure as it is removed. Note that the type of the closures
632-
/// stored in the map is `Box<FnBox() -> i32>` and not `Box<FnOnce()
632+
/// stored in the map is `Box<dyn FnBox() -> i32>` and not `Box<dyn FnOnce()
633633
/// -> i32>`.
634634
///
635635
/// ```
@@ -638,8 +638,8 @@ impl<I: FusedIterator + ?Sized> FusedIterator for Box<I> {}
638638
/// use std::boxed::FnBox;
639639
/// use std::collections::HashMap;
640640
///
641-
/// fn make_map() -> HashMap<i32, Box<FnBox() -> i32>> {
642-
/// let mut map: HashMap<i32, Box<FnBox() -> i32>> = HashMap::new();
641+
/// fn make_map() -> HashMap<i32, Box<dyn FnBox() -> i32>> {
642+
/// let mut map: HashMap<i32, Box<dyn FnBox() -> i32>> = HashMap::new();
643643
/// map.insert(1, Box::new(|| 22));
644644
/// map.insert(2, Box::new(|| 44));
645645
/// map

src/liballoc/rc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -634,15 +634,15 @@ impl<T: Clone> Rc<T> {
634634
impl Rc<dyn Any> {
635635
#[inline]
636636
#[stable(feature = "rc_downcast", since = "1.29.0")]
637-
/// Attempt to downcast the `Rc<Any>` to a concrete type.
637+
/// Attempt to downcast the `Rc<dyn Any>` to a concrete type.
638638
///
639639
/// # Examples
640640
///
641641
/// ```
642642
/// use std::any::Any;
643643
/// use std::rc::Rc;
644644
///
645-
/// fn print_if_string(value: Rc<Any>) {
645+
/// fn print_if_string(value: Rc<dyn Any>) {
646646
/// if let Ok(string) = value.downcast::<String>() {
647647
/// println!("String ({}): {}", string.len(), string);
648648
/// }

src/libcore/raw.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/// The representation of a trait object like `&SomeTrait`.
2222
///
2323
/// This struct has the same layout as types like `&SomeTrait` and
24-
/// `Box<AnotherTrait>`. The [Trait Objects chapter of the
24+
/// `Box<dyn AnotherTrait>`. The [Trait Objects chapter of the
2525
/// Book][moreinfo] contains more details about the precise nature of
2626
/// these internals.
2727
///

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2207,7 +2207,7 @@ pub enum CastKind {
22072207
/// "Unsize" -- convert a thin-or-fat pointer to a fat pointer.
22082208
/// codegen must figure out the details once full monomorphization
22092209
/// is known. For example, this could be used to cast from a
2210-
/// `&[i32;N]` to a `&[i32]`, or a `Box<T>` to a `Box<Trait>`
2210+
/// `&[i32;N]` to a `&[i32]`, or a `Box<T>` to a `Box<dyn Trait>`
22112211
/// (presuming `T: Trait`).
22122212
Unsize,
22132213
}

src/librustc/ty/adjustment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use ty::subst::Substs;
4848
/// stored in `unsize` is `Foo<[i32]>`, we don't store any further detail about
4949
/// the underlying conversions from `[i32; 4]` to `[i32]`.
5050
///
51-
/// 3. Coercing a `Box<T>` to `Box<Trait>` is an interesting special case. In
51+
/// 3. Coercing a `Box<T>` to `Box<dyn Trait>` is an interesting special case. In
5252
/// that case, we have the pointer we need coming in, so there are no
5353
/// autoderefs, and no autoref. Instead we just do the `Unsize` transformation.
5454
/// At some point, of course, `Box` should move out of the compiler, in which

src/librustc/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
303303
/// Same as applying struct_tail on `source` and `target`, but only
304304
/// keeps going as long as the two types are instances of the same
305305
/// structure definitions.
306-
/// For `(Foo<Foo<T>>, Foo<Trait>)`, the result will be `(Foo<T>, Trait)`,
306+
/// For `(Foo<Foo<T>>, Foo<dyn Trait>)`, the result will be `(Foo<T>, Trait)`,
307307
/// whereas struct_tail produces `T`, and `Trait`, respectively.
308308
pub fn struct_lockstep_tails(self,
309309
source: Ty<'tcx>,

src/librustc_codegen_ssa/meth.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'a, 'tcx: 'a> VirtualIndex {
7474
/// The vtables are cached instead of created on every call.
7575
///
7676
/// The `trait_ref` encodes the erased self type. Hence if we are
77-
/// making an object `Foo<Trait>` from a value of type `Foo<T>`, then
77+
/// making an object `Foo<dyn Trait>` from a value of type `Foo<T>`, then
7878
/// `trait_ref` would map `T:Trait`.
7979
pub fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>(
8080
cx: &Cx,

src/libstd/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ fn initial_buffer_size(file: &File) -> usize {
256256
/// use std::fs;
257257
/// use std::net::SocketAddr;
258258
///
259-
/// fn main() -> Result<(), Box<std::error::Error + 'static>> {
259+
/// fn main() -> Result<(), Box<dyn std::error::Error + 'static>> {
260260
/// let foo: SocketAddr = String::from_utf8_lossy(&fs::read("address.txt")?).parse()?;
261261
/// Ok(())
262262
/// }
@@ -298,7 +298,7 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
298298
/// use std::fs;
299299
/// use std::net::SocketAddr;
300300
///
301-
/// fn main() -> Result<(), Box<std::error::Error + 'static>> {
301+
/// fn main() -> Result<(), Box<dyn std::error::Error + 'static>> {
302302
/// let foo: SocketAddr = fs::read_to_string("address.txt")?.parse()?;
303303
/// Ok(())
304304
/// }

src/test/run-pass/string-box-error.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// Ensure that both `Box<Error + Send + Sync>` and `Box<Error>` can be obtained from `String`.
11+
// Ensure that both `Box<dyn Error + Send + Sync>` and `Box<dyn Error>` can be
12+
// obtained from `String`.
1213

1314
use std::error::Error;
1415

0 commit comments

Comments
 (0)