Skip to content

Commit 5101d6e

Browse files
authored
Auto merge of #35332 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 30 pull requests - Successful merges: #34319, #34894, #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, #35331 - Failed merges:
2 parents 41fe4b7 + 854532a commit 5101d6e

Some content is hidden

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

55 files changed

+701
-74
lines changed

src/doc/book/guessing-game.md

+1-1
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

+2
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

+2-1
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

+32
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

+19
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

+6
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/libcore/raw.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@
3434
/// only designed to be used by unsafe code that needs to manipulate
3535
/// the low-level details.
3636
///
37-
/// There is no `Repr` implementation for `TraitObject` because there
38-
/// is no way to refer to all trait objects generically, so the only
37+
/// There is no way to refer to all trait objects generically, so the only
3938
/// way to create values of this type is with functions like
40-
/// `std::mem::transmute`. Similarly, the only way to create a true
39+
/// [`std::mem::transmute`][transmute]. Similarly, the only way to create a true
4140
/// trait object from a `TraitObject` value is with `transmute`.
4241
///
42+
/// [transmute]: ../mem/fn.transmute.html
43+
///
4344
/// Synthesizing a trait object with mismatched types—one where the
4445
/// vtable does not correspond to the type of the value to which the
4546
/// data pointer points—is highly likely to lead to undefined
@@ -50,13 +51,13 @@
5051
/// ```
5152
/// #![feature(raw)]
5253
///
53-
/// use std::mem;
54-
/// use std::raw;
54+
/// use std::{mem, raw};
5555
///
5656
/// // an example trait
5757
/// trait Foo {
5858
/// fn bar(&self) -> i32;
5959
/// }
60+
///
6061
/// impl Foo for i32 {
6162
/// fn bar(&self) -> i32 {
6263
/// *self + 1
@@ -74,19 +75,18 @@
7475
/// // the data pointer is the address of `value`
7576
/// assert_eq!(raw_object.data as *const i32, &value as *const _);
7677
///
77-
///
7878
/// let other_value: i32 = 456;
7979
///
8080
/// // construct a new object, pointing to a different `i32`, being
8181
/// // careful to use the `i32` vtable from `object`
8282
/// let synthesized: &Foo = unsafe {
8383
/// mem::transmute(raw::TraitObject {
8484
/// data: &other_value as *const _ as *mut (),
85-
/// vtable: raw_object.vtable
85+
/// vtable: raw_object.vtable,
8686
/// })
8787
/// };
8888
///
89-
/// // it should work just like we constructed a trait object out of
89+
/// // it should work just as if we had constructed a trait object out of
9090
/// // `other_value` directly
9191
/// assert_eq!(synthesized.bar(), 457);
9292
/// ```

src/librustc/hir/mod.rs

+33-1
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

+9-4
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

+5-2
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

+1
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) {

src/librustc_passes/ast_validation.rs

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ impl<'a> Visitor for AstValidator<'a> {
169169
self.check_decl_no_pat(decl, |span, is_recent| {
170170
let mut err = struct_span_err!(self.session, span, E0130,
171171
"patterns aren't allowed in foreign function declarations");
172+
err.span_label(span, &format!("pattern not allowed in foreign function"));
173+
172174
if is_recent {
173175
err.span_note(span, "this is a recent error, see \
174176
issue #35203 for more details");

src/librustc_typeck/astconv.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1075,8 +1075,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
10751075
Ok((trait_ref, projection_bounds))
10761076
}
10771077
_ => {
1078-
span_err!(self.tcx().sess, ty.span, E0172,
1079-
"expected a reference to a trait");
1078+
struct_span_err!(self.tcx().sess, ty.span, E0172,
1079+
"expected a reference to a trait")
1080+
.span_label(ty.span, &format!("expected a trait"))
1081+
.emit();
10801082
Err(ErrorReported)
10811083
}
10821084
}
@@ -1086,6 +1088,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
10861088
"expected a path on the left-hand side \
10871089
of `+`, not `{}`",
10881090
pprust::ty_to_string(ty));
1091+
err.span_label(ty.span, &format!("expected a path"));
10891092
let hi = bounds.iter().map(|x| match *x {
10901093
hir::TraitTyParamBound(ref tr, _) => tr.span.hi,
10911094
hir::RegionTyParamBound(ref r) => r.span.hi,

src/librustc_typeck/check/autoderef.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> {
5454

5555
if self.steps.len() == tcx.sess.recursion_limit.get() {
5656
// We've reached the recursion limit, error gracefully.
57-
span_err!(tcx.sess, self.span, E0055,
57+
struct_span_err!(tcx.sess, self.span, E0055,
5858
"reached the recursion limit while auto-dereferencing {:?}",
59-
self.cur_ty);
59+
self.cur_ty)
60+
.span_label(self.span, &format!("deref recursion limit reached"))
61+
.emit();
6062
return None;
6163
}
6264

src/librustc_typeck/check/mod.rs

+29-6
Original file line numberDiff line numberDiff line change
@@ -2384,6 +2384,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
23842384
arg_count,
23852385
if arg_count == 1 {" was"} else {"s were"}),
23862386
error_code);
2387+
2388+
err.span_label(sp, &format!("expected {}{} parameter{}",
2389+
if variadic {"at least "} else {""},
2390+
expected_count,
2391+
if expected_count == 1 {""} else {"s"}));
2392+
23872393
let input_types = fn_inputs.iter().map(|i| format!("{:?}", i)).collect::<Vec<String>>();
23882394
if input_types.len() > 0 {
23892395
err.note(&format!("the following parameter type{} expected: {}",
@@ -3063,6 +3069,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
30633069
remaining_fields.insert(field.name, field);
30643070
}
30653071

3072+
let mut seen_fields = FnvHashMap();
3073+
30663074
let mut error_happened = false;
30673075

30683076
// Typecheck each field.
@@ -3071,13 +3079,25 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
30713079

30723080
if let Some(v_field) = remaining_fields.remove(&field.name.node) {
30733081
expected_field_type = self.field_ty(field.span, v_field, substs);
3082+
3083+
seen_fields.insert(field.name.node, field.span);
30743084
} else {
30753085
error_happened = true;
30763086
expected_field_type = tcx.types.err;
30773087
if let Some(_) = variant.find_field_named(field.name.node) {
3078-
span_err!(self.tcx.sess, field.name.span, E0062,
3079-
"field `{}` specified more than once",
3080-
field.name.node);
3088+
let mut err = struct_span_err!(self.tcx.sess,
3089+
field.name.span,
3090+
E0062,
3091+
"field `{}` specified more than once",
3092+
field.name.node);
3093+
3094+
err.span_label(field.name.span, &format!("used more than once"));
3095+
3096+
if let Some(prev_span) = seen_fields.get(&field.name.node) {
3097+
err.span_label(*prev_span, &format!("first use of `{}`", field.name.node));
3098+
}
3099+
3100+
err.emit();
30813101
} else {
30823102
self.report_unknown_field(adt_ty, variant, field, ast_fields);
30833103
}
@@ -3147,9 +3167,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
31473167
};
31483168
if variant.is_none() || variant.unwrap().kind == ty::VariantKind::Tuple {
31493169
// Reject tuple structs for now, braced and unit structs are allowed.
3150-
span_err!(self.tcx.sess, span, E0071,
3151-
"`{}` does not name a struct or a struct variant",
3152-
pprust::path_to_string(path));
3170+
struct_span_err!(self.tcx.sess, path.span, E0071,
3171+
"`{}` does not name a struct or a struct variant",
3172+
pprust::path_to_string(path))
3173+
.span_label(path.span, &format!("not a struct"))
3174+
.emit();
3175+
31533176
return None;
31543177
}
31553178

0 commit comments

Comments
 (0)