Skip to content

Commit 6398df1

Browse files
authored
Rollup merge of rust-lang#56101 - frewsxcv:frewsxcv-dyn, r=steveklabnik
Incorporate `dyn` into more comments and docs. r? @rust-lang/docs
2 parents 45e5a85 + ebb1a48 commit 6398df1

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
@@ -633,15 +633,15 @@ impl<T: Clone> Rc<T> {
633633
impl Rc<dyn Any> {
634634
#[inline]
635635
#[stable(feature = "rc_downcast", since = "1.29.0")]
636-
/// Attempt to downcast the `Rc<Any>` to a concrete type.
636+
/// Attempt to downcast the `Rc<dyn Any>` to a concrete type.
637637
///
638638
/// # Examples
639639
///
640640
/// ```
641641
/// use std::any::Any;
642642
/// use std::rc::Rc;
643643
///
644-
/// fn print_if_string(value: Rc<Any>) {
644+
/// fn print_if_string(value: Rc<dyn Any>) {
645645
/// if let Ok(string) = value.downcast::<String>() {
646646
/// println!("String ({}): {}", string.len(), string);
647647
/// }

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>`.
24+
/// `Box<dyn AnotherTrait>`.
2525
///
2626
/// `TraitObject` is guaranteed to match layouts, but it is not the
2727
/// type of trait objects (e.g. the fields are not directly accessible

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,7 @@ pub enum CastKind {
22002200
/// "Unsize" -- convert a thin-or-fat pointer to a fat pointer.
22012201
/// codegen must figure out the details once full monomorphization
22022202
/// is known. For example, this could be used to cast from a
2203-
/// `&[i32;N]` to a `&[i32]`, or a `Box<T>` to a `Box<Trait>`
2203+
/// `&[i32;N]` to a `&[i32]`, or a `Box<T>` to a `Box<dyn Trait>`
22042204
/// (presuming `T: Trait`).
22052205
Unsize,
22062206
}

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)