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

+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/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_resolve/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
219219
name)
220220
}
221221
ResolutionError::IsNotATrait(name) => {
222-
struct_span_err!(resolver.session, span, E0404, "`{}` is not a trait", name)
222+
let mut err = struct_span_err!(resolver.session,
223+
span,
224+
E0404,
225+
"`{}` is not a trait",
226+
name);
227+
err.span_label(span, &format!("not a trait"));
228+
err
223229
}
224230
ResolutionError::UndeclaredTraitName(name, candidates) => {
225231
let mut err = struct_span_err!(resolver.session,

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

src/librustc_typeck/check/op.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
176176
// error types are considered "builtin"
177177
if !lhs_ty.references_error() {
178178
if let IsAssign::Yes = is_assign {
179-
span_err!(self.tcx.sess, lhs_expr.span, E0368,
180-
"binary assignment operation `{}=` \
181-
cannot be applied to type `{}`",
182-
op.node.as_str(),
183-
lhs_ty);
179+
struct_span_err!(self.tcx.sess, lhs_expr.span, E0368,
180+
"binary assignment operation `{}=` \
181+
cannot be applied to type `{}`",
182+
op.node.as_str(),
183+
lhs_ty)
184+
.span_label(lhs_expr.span,
185+
&format!("cannot use `{}=` on type `{}`",
186+
op.node.as_str(), lhs_ty))
187+
.emit();
184188
} else {
185189
let mut err = struct_span_err!(self.tcx.sess, lhs_expr.span, E0369,
186190
"binary operation `{}` cannot be applied to type `{}`",

src/librustc_typeck/coherence/mod.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,25 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
249249
if let Some(impl_node_id) = tcx.map.as_local_node_id(impl_did) {
250250
match tcx.map.find(impl_node_id) {
251251
Some(hir_map::NodeItem(item)) => {
252-
span_err!(tcx.sess, item.span, E0120,
253-
"the Drop trait may only be implemented on structures");
252+
let span = match item.node {
253+
ItemImpl(_, _, _, _, ref ty, _) => {
254+
ty.span
255+
},
256+
_ => item.span
257+
};
258+
struct_span_err!(tcx.sess, span, E0120,
259+
"the Drop trait may only be implemented on structures")
260+
.span_label(span,
261+
&format!("implementing Drop requires a struct"))
262+
.emit();
254263
}
255264
_ => {
256265
bug!("didn't find impl in ast map");
257266
}
258267
}
259268
} else {
260269
bug!("found external impl of Drop trait on \
261-
:omething other than a struct");
270+
something other than a struct");
262271
}
263272
}
264273
}

src/librustc_typeck/coherence/overlap.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,18 @@ impl<'cx, 'tcx,'v> intravisit::Visitor<'v> for OverlapChecker<'cx, 'tcx> {
141141
self.tcx.sess, self.tcx.span_of_impl(impl_def_id).unwrap(), E0119,
142142
"conflicting implementations of trait `{}`{}:",
143143
overlap.trait_desc,
144-
overlap.self_desc.map_or(String::new(),
145-
|ty| format!(" for type `{}`", ty)));
144+
overlap.self_desc.clone().map_or(String::new(),
145+
|ty| format!(" for type `{}`", ty)));
146146

147147
match self.tcx.span_of_impl(overlap.with_impl) {
148148
Ok(span) => {
149-
err.span_note(span, "conflicting implementation is here:");
149+
err.span_label(span,
150+
&format!("first implementation here"));
151+
err.span_label(self.tcx.span_of_impl(impl_def_id).unwrap(),
152+
&format!("conflicting implementation{}",
153+
overlap.self_desc
154+
.map_or(String::new(),
155+
|ty| format!(" for `{}`", ty))));
150156
}
151157
Err(cname) => {
152158
err.note(&format!("conflicting implementation in crate `{}`",

0 commit comments

Comments
 (0)