Skip to content

Commit b30eff7

Browse files
authored
Auto merge of #35365 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 30 pull requests - Successful merges: #34319, #35041, #35042, #35076, #35109, #35137, #35175, #35181, #35182, #35189, #35239, #35264, #35266, #35281, #35285, #35289, #35291, #35294, #35296, #35297, #35298, #35299, #35318, #35319, #35324, #35326, #35328, #35333, #35359, #35362 - Failed merges:
2 parents 4c02363 + cd48161 commit b30eff7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+709
-72
lines changed

src/doc/book/guessing-game.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ numbers. A bare number like above is actually shorthand for `^0.3.0`,
365365
meaning "anything compatible with 0.3.0".
366366
If we wanted to use only `0.3.0` exactly, we could say `rand="=0.3.0"`
367367
(note the two equal signs).
368-
And if we wanted to use the latest version we could use `*`.
368+
And if we wanted to use the latest version we could use `rand="*"`.
369369
We could also use a range of versions.
370370
[Cargo’s documentation][cargodoc] contains more details.
371371

src/doc/book/the-stack-and-the-heap.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ The stack is very fast, and is where memory is allocated in Rust by default.
2626
But the allocation is local to a function call, and is limited in size. The
2727
heap, on the other hand, is slower, and is explicitly allocated by your
2828
program. But it’s effectively unlimited in size, and is globally accessible.
29+
Note this meaning of heap, which allocates arbitrary-sized blocks of memory in arbitrary
30+
order, is quite different from the heap data structure.
2931

3032
# The Stack
3133

src/doc/reference.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,8 @@ as
30493049
== != < > <= >=
30503050
&&
30513051
||
3052-
= ..
3052+
.. ...
3053+
=
30533054
```
30543055

30553056
Operators at the same precedence level are evaluated left-to-right. [Unary

src/libcollections/range.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,45 @@ pub trait RangeArgument<T> {
2323
/// Start index (inclusive)
2424
///
2525
/// Return start value if present, else `None`.
26+
///
27+
/// # Examples
28+
///
29+
/// ```
30+
/// #![feature(collections)]
31+
/// #![feature(collections_range)]
32+
///
33+
/// extern crate collections;
34+
///
35+
/// # fn main() {
36+
/// use collections::range::RangeArgument;
37+
///
38+
/// assert_eq!((..10).start(), None);
39+
/// assert_eq!((3..10).start(), Some(&3));
40+
/// # }
41+
/// ```
2642
fn start(&self) -> Option<&T> {
2743
None
2844
}
2945

3046
/// End index (exclusive)
3147
///
3248
/// Return end value if present, else `None`.
49+
///
50+
/// # Examples
51+
///
52+
/// ```
53+
/// #![feature(collections)]
54+
/// #![feature(collections_range)]
55+
///
56+
/// extern crate collections;
57+
///
58+
/// # fn main() {
59+
/// use collections::range::RangeArgument;
60+
///
61+
/// assert_eq!((3..).end(), None);
62+
/// assert_eq!((3..10).end(), Some(&10));
63+
/// # }
64+
/// ```
3365
fn end(&self) -> Option<&T> {
3466
None
3567
}

src/libcollections/vec.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,25 @@ impl<T> Vec<T> {
476476
/// Note that this will drop any excess capacity. Calling this and
477477
/// converting back to a vector with `into_vec()` is equivalent to calling
478478
/// `shrink_to_fit()`.
479+
///
480+
/// # Examples
481+
///
482+
/// ```
483+
/// let v = vec![1, 2, 3];
484+
///
485+
/// let slice = v.into_boxed_slice();
486+
/// ```
487+
///
488+
/// Any excess capacity is removed:
489+
///
490+
/// ```
491+
/// let mut vec = Vec::with_capacity(10);
492+
/// vec.extend([1, 2, 3].iter().cloned());
493+
///
494+
/// assert_eq!(vec.capacity(), 10);
495+
/// let slice = vec.into_boxed_slice();
496+
/// assert_eq!(slice.into_vec().capacity(), 3);
497+
/// ```
479498
#[stable(feature = "rust1", since = "1.0.0")]
480499
pub fn into_boxed_slice(mut self) -> Box<[T]> {
481500
unsafe {

src/libcore/marker.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ pub trait Unsize<T: ?Sized> {
144144
/// Generalizing the latter case, any type implementing `Drop` can't be `Copy`, because it's
145145
/// managing some resource besides its own `size_of::<T>()` bytes.
146146
///
147+
/// ## What if I derive `Copy` on a type that can't?
148+
///
149+
/// If you try to derive `Copy` on a struct or enum, you will get a compile-time error.
150+
/// Specifically, with structs you'll get [E0204](https://doc.rust-lang.org/error-index.html#E0204)
151+
/// and with enums you'll get [E0205](https://doc.rust-lang.org/error-index.html#E0205).
152+
///
147153
/// ## When should my type be `Copy`?
148154
///
149155
/// Generally speaking, if your type _can_ implement `Copy`, it should. There's one important thing

src/librustc/hir/mod.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use hir::def::Def;
3636
use hir::def_id::DefId;
3737
use util::nodemap::{NodeMap, FnvHashSet};
3838

39-
use syntax_pos::{mk_sp, Span, ExpnId};
39+
use syntax_pos::{BytePos, mk_sp, Span, ExpnId};
4040
use syntax::codemap::{self, respan, Spanned};
4141
use syntax::abi::Abi;
4242
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, AsmDialect};
@@ -326,6 +326,38 @@ impl Generics {
326326
pub fn is_parameterized(&self) -> bool {
327327
self.is_lt_parameterized() || self.is_type_parameterized()
328328
}
329+
330+
// Does return a span which includes lifetimes and type parameters,
331+
// not where clause.
332+
pub fn span(&self) -> Option<Span> {
333+
if !self.is_parameterized() {
334+
None
335+
} else {
336+
let mut span: Option<Span> = None;
337+
for lifetime in self.lifetimes.iter() {
338+
if let Some(ref mut span) = span {
339+
let life_span = lifetime.lifetime.span;
340+
span.hi = if span.hi > life_span.hi { span.hi } else { life_span.hi };
341+
span.lo = if span.lo < life_span.lo { span.lo } else { life_span.lo };
342+
} else {
343+
span = Some(lifetime.lifetime.span.clone());
344+
}
345+
}
346+
for ty_param in self.ty_params.iter() {
347+
if let Some(ref mut span) = span {
348+
span.lo = if span.lo < ty_param.span.lo { span.lo } else { ty_param.span.lo };
349+
span.hi = if span.hi > ty_param.span.hi { span.hi } else { ty_param.span.hi };
350+
} else {
351+
span = Some(ty_param.span.clone());
352+
}
353+
}
354+
if let Some(ref mut span) = span {
355+
span.lo = span.lo - BytePos(1);
356+
span.hi = span.hi + BytePos(1);
357+
}
358+
span
359+
}
360+
}
329361
}
330362

331363
/// A `where` clause in a definition

src/librustc/middle/astconv_util.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2424
pub fn prohibit_type_params(self, segments: &[ast::PathSegment]) {
2525
for segment in segments {
2626
for typ in segment.parameters.types() {
27-
span_err!(self.sess, typ.span, E0109,
28-
"type parameters are not allowed on this type");
27+
struct_span_err!(self.sess, typ.span, E0109,
28+
"type parameters are not allowed on this type")
29+
.span_label(typ.span, &format!("type parameter not allowed"))
30+
.emit();
2931
break;
3032
}
3133
for lifetime in segment.parameters.lifetimes() {
32-
span_err!(self.sess, lifetime.span, E0110,
33-
"lifetime parameters are not allowed on this type");
34+
struct_span_err!(self.sess, lifetime.span, E0110,
35+
"lifetime parameters are not allowed on this type")
36+
.span_label(lifetime.span,
37+
&format!("lifetime parameter not allowed on this type"))
38+
.emit();
3439
break;
3540
}
3641
for binding in segment.parameters.bindings() {

src/librustc/middle/entry.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ fn find_item(item: &Item, ctxt: &mut EntryContext, at_root: bool) {
121121
if ctxt.attr_main_fn.is_none() {
122122
ctxt.attr_main_fn = Some((item.id, item.span));
123123
} else {
124-
span_err!(ctxt.session, item.span, E0137,
125-
"multiple functions with a #[main] attribute");
124+
struct_span_err!(ctxt.session, item.span, E0137,
125+
"multiple functions with a #[main] attribute")
126+
.span_label(item.span, &format!("additional #[main] function"))
127+
.span_label(ctxt.attr_main_fn.unwrap().1, &format!("first #[main] function"))
128+
.emit();
126129
}
127130
},
128131
EntryPointType::Start => {

src/librustc_const_eval/check_match.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ fn check_arms(cx: &MatchCheckCtxt,
335335
hir::MatchSource::Normal => {
336336
let mut err = struct_span_err!(cx.tcx.sess, pat.span, E0001,
337337
"unreachable pattern");
338+
err.span_label(pat.span, &format!("this is an unreachable pattern"));
338339
// if we had a catchall pattern, hint at that
339340
for row in &seen.0 {
340341
if pat_is_catchall(&cx.tcx.def_map.borrow(), row[0].0) {

0 commit comments

Comments
 (0)