Skip to content

Commit a6869a0

Browse files
committed
---
yaml --- r: 123900 b: refs/heads/snap-stage3 c: 6f96abf h: refs/heads/master v: v3
1 parent 9ad804f commit a6869a0

File tree

13 files changed

+593
-636
lines changed

13 files changed

+593
-636
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 4e2da7cb79143b0e7206a684629ed942599ec8e9
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: a1bd5d359b8e4ebc1b952f96e4f1d4658bc29b26
4+
refs/heads/snap-stage3: 6f96abf7389c6a031c549a9df0b672b7989fbe8b
55
refs/heads/try: 296eb104620b346d88bc4a2c2ab7693e6d3db019
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/intrinsics.rs

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,19 +326,73 @@ extern "rust-intrinsic" {
326326
/// integer, since the conversion would throw away aliasing information.
327327
pub fn offset<T>(dst: *const T, offset: int) -> *const T;
328328

329-
/// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
330-
/// a size of `count` * `size_of::<T>()` and an alignment of
331-
/// `min_align_of::<T>()`
329+
/// Copies data from one location to another.
330+
///
331+
/// Copies `count` elements (not bytes) from `src` to `dst`. The source
332+
/// and destination may *not* overlap.
333+
///
334+
/// `copy_nonoverlapping_memory` is semantically equivalent to C's `memcpy`.
335+
///
336+
/// # Example
337+
///
338+
/// A safe swap function:
339+
///
340+
/// ```
341+
/// use std::mem;
342+
/// use std::ptr;
343+
///
344+
/// fn swap<T>(x: &mut T, y: &mut T) {
345+
/// unsafe {
346+
/// // Give ourselves some scratch space to work with
347+
/// let mut t: T = mem::uninitialized();
348+
///
349+
/// // Perform the swap, `&mut` pointers never alias
350+
/// ptr::copy_nonoverlapping_memory(&mut t, &*x, 1);
351+
/// ptr::copy_nonoverlapping_memory(x, &*y, 1);
352+
/// ptr::copy_nonoverlapping_memory(y, &t, 1);
353+
///
354+
/// // y and t now point to the same thing, but we need to completely forget `tmp`
355+
/// // because it's no longer relevant.
356+
/// mem::forget(t);
357+
/// }
358+
/// }
359+
/// ```
360+
///
361+
/// # Safety Note
362+
///
363+
/// If the source and destination overlap then the behavior of this
364+
/// function is undefined.
365+
#[unstable]
332366
pub fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: uint);
333367

334-
/// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
335-
/// a size of `count` * `size_of::<T>()` and an alignment of
336-
/// `min_align_of::<T>()`
368+
/// Copies data from one location to another.
369+
///
370+
/// Copies `count` elements (not bytes) from `src` to `dst`. The source
371+
/// and destination may overlap.
372+
///
373+
/// `copy_memory` is semantically equivalent to C's `memmove`.
374+
///
375+
/// # Example
376+
///
377+
/// Efficiently create a Rust vector from an unsafe buffer:
378+
///
379+
/// ```
380+
/// use std::ptr;
381+
///
382+
/// unsafe fn from_buf_raw<T>(ptr: *const T, elts: uint) -> Vec<T> {
383+
/// let mut dst = Vec::with_capacity(elts);
384+
/// dst.set_len(elts);
385+
/// ptr::copy_memory(dst.as_mut_ptr(), ptr, elts);
386+
/// dst
387+
/// }
388+
/// ```
389+
///
390+
#[unstable]
337391
pub fn copy_memory<T>(dst: *mut T, src: *const T, count: uint);
338392

339-
/// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
340-
/// size of `count` * `size_of::<T>()` and an alignment of
341-
/// `min_align_of::<T>()`
393+
/// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
394+
/// bytes of memory starting at `dst` to `c`.
395+
#[experimental = "uncertain about naming and semantics"]
342396
pub fn set_memory<T>(dst: *mut T, val: u8, count: uint);
343397

344398
/// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with

branches/snap-stage3/src/libcore/iter.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,6 @@ impl<A, B, T: ExactSize<A>, U: ExactSize<B>> ExactSize<(A, B)> for Zip<T, U> {}
751751

752752
/// An double-ended iterator with the direction inverted
753753
#[deriving(Clone)]
754-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
755754
pub struct Rev<T> {
756755
iter: T
757756
}
@@ -780,7 +779,6 @@ impl<A, T: DoubleEndedIterator<A> + RandomAccessIterator<A>> RandomAccessIterato
780779
}
781780

782781
/// A mutable reference to an iterator
783-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
784782
pub struct ByRef<'a, T> {
785783
iter: &'a mut T
786784
}
@@ -1041,7 +1039,6 @@ impl<A, T: Clone + Iterator<A>> CloneableIterator for T {
10411039

10421040
/// An iterator that repeats endlessly
10431041
#[deriving(Clone)]
1044-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
10451042
pub struct Cycle<T> {
10461043
orig: T,
10471044
iter: T,
@@ -1093,7 +1090,6 @@ impl<A, T: Clone + RandomAccessIterator<A>> RandomAccessIterator<A> for Cycle<T>
10931090

10941091
/// An iterator which strings two iterators together
10951092
#[deriving(Clone)]
1096-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
10971093
pub struct Chain<T, U> {
10981094
a: T,
10991095
b: U,
@@ -1163,7 +1159,6 @@ for Chain<T, U> {
11631159

11641160
/// An iterator which iterates two other iterators simultaneously
11651161
#[deriving(Clone)]
1166-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
11671162
pub struct Zip<T, U> {
11681163
a: T,
11691164
b: U
@@ -1242,7 +1237,6 @@ RandomAccessIterator<(A, B)> for Zip<T, U> {
12421237
}
12431238

12441239
/// An iterator which maps the values of `iter` with `f`
1245-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
12461240
pub struct Map<'a, A, B, T> {
12471241
iter: T,
12481242
f: |A|: 'a -> B
@@ -1293,7 +1287,6 @@ impl<'a, A, B, T: RandomAccessIterator<A>> RandomAccessIterator<B> for Map<'a, A
12931287
}
12941288

12951289
/// An iterator which filters the elements of `iter` with `predicate`
1296-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
12971290
pub struct Filter<'a, A, T> {
12981291
iter: T,
12991292
predicate: |&A|: 'a -> bool
@@ -1338,7 +1331,6 @@ impl<'a, A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Filter<'a, A,
13381331
}
13391332

13401333
/// An iterator which uses `f` to both filter and map elements from `iter`
1341-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
13421334
pub struct FilterMap<'a, A, B, T> {
13431335
iter: T,
13441336
f: |A|: 'a -> Option<B>
@@ -1383,7 +1375,6 @@ for FilterMap<'a, A, B, T> {
13831375

13841376
/// An iterator which yields the current count and the element during iteration
13851377
#[deriving(Clone)]
1386-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
13871378
pub struct Enumerate<T> {
13881379
iter: T,
13891380
count: uint
@@ -1438,7 +1429,6 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<(uint, A)> for Enumerat
14381429
}
14391430

14401431
/// An iterator with a `peek()` that returns an optional reference to the next element.
1441-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
14421432
pub struct Peekable<A, T> {
14431433
iter: T,
14441434
peeked: Option<A>,
@@ -1489,7 +1479,6 @@ impl<'a, A, T: Iterator<A>> Peekable<A, T> {
14891479
}
14901480

14911481
/// An iterator which rejects elements while `predicate` is true
1492-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
14931482
pub struct SkipWhile<'a, A, T> {
14941483
iter: T,
14951484
flag: bool,
@@ -1528,7 +1517,6 @@ impl<'a, A, T: Iterator<A>> Iterator<A> for SkipWhile<'a, A, T> {
15281517
}
15291518

15301519
/// An iterator which only accepts elements while `predicate` is true
1531-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
15321520
pub struct TakeWhile<'a, A, T> {
15331521
iter: T,
15341522
flag: bool,
@@ -1564,7 +1552,6 @@ impl<'a, A, T: Iterator<A>> Iterator<A> for TakeWhile<'a, A, T> {
15641552

15651553
/// An iterator which skips over `n` elements of `iter`.
15661554
#[deriving(Clone)]
1567-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
15681555
pub struct Skip<T> {
15691556
iter: T,
15701557
n: uint
@@ -1629,7 +1616,6 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Skip<T> {
16291616

16301617
/// An iterator which only iterates over the first `n` iterations of `iter`.
16311618
#[deriving(Clone)]
1632-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
16331619
pub struct Take<T> {
16341620
iter: T,
16351621
n: uint
@@ -1679,7 +1665,6 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Take<T> {
16791665

16801666

16811667
/// An iterator to maintain state while iterating another iterator
1682-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
16831668
pub struct Scan<'a, A, B, T, St> {
16841669
iter: T,
16851670
f: |&mut St, A|: 'a -> Option<B>,
@@ -1704,7 +1689,6 @@ impl<'a, A, B, T: Iterator<A>, St> Iterator<B> for Scan<'a, A, B, T, St> {
17041689
/// An iterator that maps each element to an iterator,
17051690
/// and yields the elements of the produced iterators
17061691
///
1707-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
17081692
pub struct FlatMap<'a, A, T, U> {
17091693
iter: T,
17101694
f: |A|: 'a -> U,
@@ -1764,7 +1748,6 @@ impl<'a,
17641748
/// An iterator that yields `None` forever after the underlying iterator
17651749
/// yields `None` once.
17661750
#[deriving(Clone)]
1767-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
17681751
pub struct Fuse<T> {
17691752
iter: T,
17701753
done: bool
@@ -1837,7 +1820,6 @@ impl<T> Fuse<T> {
18371820

18381821
/// An iterator that calls a function with a reference to each
18391822
/// element before yielding it.
1840-
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
18411823
pub struct Inspect<'a, A, T> {
18421824
iter: T,
18431825
f: |&A|: 'a
@@ -2317,3 +2299,4 @@ pub mod order {
23172299
}
23182300
}
23192301
}
2302+

branches/snap-stage3/src/libcore/ptr.rs

Lines changed: 4 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ use option::{Some, None, Option};
9595

9696
use cmp::{PartialEq, Eq, PartialOrd, Equiv, Ordering, Less, Equal, Greater};
9797

98+
pub use intrinsics::copy_memory;
99+
pub use intrinsics::copy_nonoverlapping_memory;
100+
pub use intrinsics::set_memory;
101+
98102
/// Create a null pointer.
99103
///
100104
/// # Example
@@ -123,86 +127,6 @@ pub fn null<T>() -> *const T { 0 as *const T }
123127
#[unstable = "may need a different name after pending changes to pointer types"]
124128
pub fn mut_null<T>() -> *mut T { 0 as *mut T }
125129

126-
/// Copies data from one location to another.
127-
///
128-
/// Copies `count` elements (not bytes) from `src` to `dst`. The source
129-
/// and destination may overlap.
130-
///
131-
/// `copy_memory` is semantically equivalent to C's `memmove`.
132-
///
133-
/// # Example
134-
///
135-
/// Efficiently create a Rust vector from an unsafe buffer:
136-
///
137-
/// ```
138-
/// use std::ptr;
139-
///
140-
/// unsafe fn from_buf_raw<T>(ptr: *const T, elts: uint) -> Vec<T> {
141-
/// let mut dst = Vec::with_capacity(elts);
142-
/// dst.set_len(elts);
143-
/// ptr::copy_memory(dst.as_mut_ptr(), ptr, elts);
144-
/// dst
145-
/// }
146-
/// ```
147-
///
148-
#[inline]
149-
#[unstable]
150-
pub unsafe fn copy_memory<T>(dst: *mut T, src: *const T, count: uint) {
151-
intrinsics::copy_memory(dst, src, count)
152-
}
153-
154-
/// Copies data from one location to another.
155-
///
156-
/// Copies `count` elements (not bytes) from `src` to `dst`. The source
157-
/// and destination may *not* overlap.
158-
///
159-
/// `copy_nonoverlapping_memory` is semantically equivalent to C's `memcpy`.
160-
///
161-
/// # Example
162-
///
163-
/// A safe swap function:
164-
///
165-
/// ```
166-
/// use std::mem;
167-
/// use std::ptr;
168-
///
169-
/// fn swap<T>(x: &mut T, y: &mut T) {
170-
/// unsafe {
171-
/// // Give ourselves some scratch space to work with
172-
/// let mut t: T = mem::uninitialized();
173-
///
174-
/// // Perform the swap, `&mut` pointers never alias
175-
/// ptr::copy_nonoverlapping_memory(&mut t, &*x, 1);
176-
/// ptr::copy_nonoverlapping_memory(x, &*y, 1);
177-
/// ptr::copy_nonoverlapping_memory(y, &t, 1);
178-
///
179-
/// // y and t now point to the same thing, but we need to completely forget `tmp`
180-
/// // because it's no longer relevant.
181-
/// mem::forget(t);
182-
/// }
183-
/// }
184-
/// ```
185-
///
186-
/// # Safety Note
187-
///
188-
/// If the source and destination overlap then the behavior of this
189-
/// function is undefined.
190-
#[inline]
191-
#[unstable]
192-
pub unsafe fn copy_nonoverlapping_memory<T>(dst: *mut T,
193-
src: *const T,
194-
count: uint) {
195-
intrinsics::copy_nonoverlapping_memory(dst, src, count)
196-
}
197-
198-
/// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
199-
/// bytes of memory starting at `dst` to `c`.
200-
#[inline]
201-
#[experimental = "uncertain about naming and semantics"]
202-
pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
203-
intrinsics::set_memory(dst, c, count)
204-
}
205-
206130
/// Zeroes out `count * size_of::<T>` bytes of memory at `dst`
207131
#[inline]
208132
#[experimental = "uncertain about naming and semantics"]

branches/snap-stage3/src/librustc/lint/builtin.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -669,13 +669,22 @@ impl LintPass for UnusedResult {
669669
if ast_util::is_local(did) {
670670
match cx.tcx.map.get(did.node) {
671671
ast_map::NodeItem(it) => {
672-
warned |= check_must_use(cx, it.attrs.as_slice(), s.span);
672+
if attr::contains_name(it.attrs.as_slice(),
673+
"must_use") {
674+
cx.span_lint(UNUSED_MUST_USE, s.span,
675+
"unused result which must be used");
676+
warned = true;
677+
}
673678
}
674679
_ => {}
675680
}
676681
} else {
677682
csearch::get_item_attrs(&cx.sess().cstore, did, |attrs| {
678-
warned |= check_must_use(cx, attrs.as_slice(), s.span);
683+
if attr::contains_name(attrs.as_slice(), "must_use") {
684+
cx.span_lint(UNUSED_MUST_USE, s.span,
685+
"unused result which must be used");
686+
warned = true;
687+
}
679688
});
680689
}
681690
}
@@ -684,25 +693,6 @@ impl LintPass for UnusedResult {
684693
if !warned {
685694
cx.span_lint(UNUSED_RESULT, s.span, "unused result");
686695
}
687-
688-
fn check_must_use(cx: &Context, attrs: &[ast::Attribute], sp: Span) -> bool {
689-
for attr in attrs.iter() {
690-
if attr.check_name("must_use") {
691-
let mut msg = "unused result which must be used".to_string();
692-
// check for #[must_use="..."]
693-
match attr.value_str() {
694-
None => {}
695-
Some(s) => {
696-
msg.push_str(": ");
697-
msg.push_str(s.get());
698-
}
699-
}
700-
cx.span_lint(UNUSED_MUST_USE, sp, msg.as_slice());
701-
return true;
702-
}
703-
}
704-
false
705-
}
706696
}
707697
}
708698

0 commit comments

Comments
 (0)