Skip to content

Commit cb94b1e

Browse files
committed
---
yaml --- r: 189357 b: refs/heads/master c: 0e0bb8a h: refs/heads/master i: 189355: 9257c40 v: v3
1 parent 1478660 commit cb94b1e

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 509c6fc9c172fefaeeabb815a4b8feac6e0d075d
2+
refs/heads/master: 0e0bb8a128baee4ec074b6d82bdd73b48a4b8283
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 270a677d4d698916f5ad103f0afc3c070b8dbeb4
55
refs/heads/try: 649d35e4d830b27806705dc5352c86ab6d6fd1a1

trunk/src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ pub trait IteratorExt: Iterator + Sized {
611611
///
612612
/// ```
613613
/// let a = [1, 2, 3, 4, 5];
614-
/// assert!(a.iter().fold(0, |a, &b| a + b) == 15);
614+
/// assert!(a.iter().fold(0, |acc, &item| acc + item) == 15);
615615
/// ```
616616
#[inline]
617617
#[stable(feature = "rust1", since = "1.0.0")]

trunk/src/libcore/marker.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,45 @@ pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
351351
/// instance, it will behave *as if* an instance of the type `T` were
352352
/// present for the purpose of various automatic analyses.
353353
///
354-
/// For example, embedding a `PhantomData<T>` will inform the compiler
354+
/// # Examples
355+
///
356+
/// When handling external resources over a foreign function interface, `PhantomData<T>` can
357+
/// prevent mismatches by enforcing types in the method implementations, although the struct
358+
/// doesn't actually contain values of the resource type.
359+
///
360+
/// ```
361+
/// # trait ResType { fn foo(&self); };
362+
/// # struct ParamType;
363+
/// # mod foreign_lib {
364+
/// # pub fn new(_: usize) -> *mut () { 42 as *mut () }
365+
/// # pub fn do_stuff(_: *mut (), _: usize) {}
366+
/// # }
367+
/// # fn convert_params(_: ParamType) -> usize { 42 }
368+
/// use std::marker::PhantomData;
369+
/// use std::mem;
370+
///
371+
/// struct ExternalResource<R> {
372+
/// resource_handle: *mut (),
373+
/// resource_type: PhantomData<R>,
374+
/// }
375+
///
376+
/// impl<R: ResType> ExternalResource<R> {
377+
/// fn new() -> ExternalResource<R> {
378+
/// let size_of_res = mem::size_of::<R>();
379+
/// ExternalResource {
380+
/// resource_handle: foreign_lib::new(size_of_res),
381+
/// resource_type: PhantomData,
382+
/// }
383+
/// }
384+
///
385+
/// fn do_stuff(&self, param: ParamType) {
386+
/// let foreign_params = convert_params(param);
387+
/// foreign_lib::do_stuff(self.resource_handle, foreign_params);
388+
/// }
389+
/// }
390+
/// ```
391+
///
392+
/// Another example: embedding a `PhantomData<T>` will inform the compiler
355393
/// that one or more instances of the type `T` could be dropped when
356394
/// instances of the type itself is dropped, though that may not be
357395
/// apparent from the other structure of the type itself. This is

trunk/src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ pub struct BareFnTy {
12641264
/// The different kinds of types recognized by the compiler
12651265
pub enum Ty_ {
12661266
TyVec(P<Ty>),
1267-
/// A fixed length array (`[T, ..n]`)
1267+
/// A fixed length array (`[T; n]`)
12681268
TyFixedLengthVec(P<Ty>, P<Expr>),
12691269
/// A raw pointer (`*const T` or `*mut T`)
12701270
TyPtr(MutTy),

0 commit comments

Comments
 (0)