Skip to content

Commit 8787a12

Browse files
authored
Auto merge of #35592 - jonathandturner:rollup, r=jonathandturner
Rollup of 23 pull requests - Successful merges: #35279, #35331, #35358, #35375, #35445, #35448, #35482, #35486, #35505, #35528, #35530, #35532, #35536, #35537, #35541, #35552, #35554, #35555, #35557, #35562, #35565, #35569, #35576 - Failed merges: #35395, #35415, #35563
2 parents 11f8805 + d3af9a3 commit 8787a12

Some content is hidden

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

64 files changed

+543
-376
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ __pycache__/
5757
.project
5858
.settings/
5959
.valgrindrc
60+
.vscode/
6061
/*-*-*-*/
6162
/*-*-*/
6263
/Makefile

src/libcollections/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ impl String {
11801180
#[inline]
11811181
#[unstable(feature = "insert_str",
11821182
reason = "recent addition",
1183-
issue = "0")]
1183+
issue = "35553")]
11841184
pub fn insert_str(&mut self, idx: usize, string: &str) {
11851185
let len = self.len();
11861186
assert!(idx <= len);

src/libcore/macros.rs

+37-8
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,28 @@ macro_rules! try {
229229
})
230230
}
231231

232-
/// Use the `format!` syntax to write data into a buffer.
232+
/// Write formatted data into a buffer
233233
///
234-
/// This macro is typically used with a buffer of `&mut `[`Write`][write].
234+
/// This macro accepts any value with `write_fmt` method as a writer, a format string, and a list
235+
/// of arguments to format.
236+
///
237+
/// `write_fmt` method usually comes from an implementation of [`std::fmt::Write`][fmt_write] or
238+
/// [`std::io::Write`][io_write] traits. These are sometimes called 'writers'.
239+
///
240+
/// Passed arguments will be formatted according to the specified format string and the resulting
241+
/// string will be passed to the writer.
235242
///
236243
/// See [`std::fmt`][fmt] for more information on format syntax.
237244
///
245+
/// Return value is completely dependent on the 'write_fmt' method.
246+
///
247+
/// Common return values are: [`Result`][enum_result], [`io::Result`][type_result]
248+
///
238249
/// [fmt]: ../std/fmt/index.html
239-
/// [write]: ../std/io/trait.Write.html
250+
/// [fmt_write]: ../std/fmt/trait.Write.html
251+
/// [io_write]: ../std/io/trait.Write.html
252+
/// [enum_result]: ../std/result/enum.Result.html
253+
/// [type_result]: ../std/io/type.Result.html
240254
///
241255
/// # Examples
242256
///
@@ -255,16 +269,31 @@ macro_rules! write {
255269
($dst:expr, $($arg:tt)*) => ($dst.write_fmt(format_args!($($arg)*)))
256270
}
257271

258-
/// Use the `format!` syntax to write data into a buffer, appending a newline.
259-
/// On all platforms, the newline is the LINE FEED character (`\n`/`U+000A`)
260-
/// alone (no additional CARRIAGE RETURN (`\r`/`U+000D`).
272+
/// Write formatted data into a buffer, with appending a newline.
273+
///
274+
/// On all platforms, the newline is the LINE FEED character (`\n`/`U+000A`) alone
275+
/// (no additional CARRIAGE RETURN (`\r`/`U+000D`).
261276
///
262-
/// This macro is typically used with a buffer of `&mut `[`Write`][write].
277+
/// This macro accepts any value with `write_fmt` method as a writer, a format string, and a list
278+
/// of arguments to format.
279+
///
280+
/// `write_fmt` method usually comes from an implementation of [`std::fmt::Write`][fmt_write] or
281+
/// [`std::io::Write`][io_write] traits. These are sometimes called 'writers'.
282+
///
283+
/// Passed arguments will be formatted according to the specified format string and the resulting
284+
/// string will be passed to the writer.
263285
///
264286
/// See [`std::fmt`][fmt] for more information on format syntax.
265287
///
288+
/// Return value is completely dependent on the 'write_fmt' method.
289+
///
290+
/// Common return values are: [`Result`][enum_result], [`io::Result`][type_result]
291+
///
266292
/// [fmt]: ../std/fmt/index.html
267-
/// [write]: ../std/io/trait.Write.html
293+
/// [fmt_write]: ../std/fmt/trait.Write.html
294+
/// [io_write]: ../std/io/trait.Write.html
295+
/// [enum_result]: ../std/result/enum.Result.html
296+
/// [type_result]: ../std/io/type.Result.html
268297
///
269298
/// # Examples
270299
///

src/libcore/result.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ impl<T, E> Result<T, E> {
402402
/// ```
403403
/// fn mutate(r: &mut Result<i32, i32>) {
404404
/// match r.as_mut() {
405-
/// Ok(&mut ref mut v) => *v = 42,
406-
/// Err(&mut ref mut e) => *e = 0,
405+
/// Ok(v) => *v = 42,
406+
/// Err(e) => *e = 0,
407407
/// }
408408
/// }
409409
///

src/librustc/middle/effect.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ impl<'a, 'tcx> EffectCheckVisitor<'a, 'tcx> {
6363
match self.unsafe_context.root {
6464
SafeContext => {
6565
// Report an error.
66-
span_err!(self.tcx.sess, span, E0133,
67-
"{} requires unsafe function or block",
68-
description);
66+
struct_span_err!(
67+
self.tcx.sess, span, E0133,
68+
"{} requires unsafe function or block", description)
69+
.span_label(span, &format!("unsafe call requires unsafe function or block"))
70+
.emit();
6971
}
7072
UnsafeBlock(block_id) => {
7173
// OK, but record this.

src/librustc/middle/resolve_lifetime.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
718718
let lifetime_j = &lifetimes[j];
719719

720720
if lifetime_i.lifetime.name == lifetime_j.lifetime.name {
721-
span_err!(self.sess, lifetime_j.lifetime.span, E0263,
722-
"lifetime name `{}` declared twice in \
723-
the same scope",
724-
lifetime_j.lifetime.name);
721+
struct_span_err!(self.sess, lifetime_j.lifetime.span, E0263,
722+
"lifetime name `{}` declared twice in the same scope",
723+
lifetime_j.lifetime.name)
724+
.span_label(lifetime_j.lifetime.span,
725+
&format!("declared twice"))
726+
.span_label(lifetime_i.lifetime.span,
727+
&format!("previous declaration here"))
728+
.emit();
725729
}
726730
}
727731

src/librustc/traits/error_reporting.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
654654
let mut err = struct_span_err!(self.sess, span, E0072,
655655
"recursive type `{}` has infinite size",
656656
self.item_path_str(type_def_id));
657+
err.span_label(span, &format!("recursive type has infinite size"));
657658
err.help(&format!("insert indirection (e.g., a `Box`, `Rc`, or `&`) \
658659
at some point to make `{}` representable",
659660
self.item_path_str(type_def_id)));
@@ -670,10 +671,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
670671
let mut err = match warning_node_id {
671672
Some(_) => None,
672673
None => {
673-
Some(struct_span_err!(
674-
self.sess, span, E0038,
675-
"the trait `{}` cannot be made into an object",
676-
self.item_path_str(trait_def_id)))
674+
let trait_str = self.item_path_str(trait_def_id);
675+
let mut db = struct_span_err!(
676+
self.sess, span, E0038,
677+
"the trait `{}` cannot be made into an object",
678+
trait_str);
679+
db.span_label(span,
680+
&format!("the trait `{}` cannot be made \
681+
into an object", trait_str));
682+
Some(db)
677683
}
678684
};
679685

src/librustc_borrowck/borrowck/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -760,12 +760,16 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
760760
lp: &LoanPath<'tcx>,
761761
assign:
762762
&move_data::Assignment) {
763-
struct_span_err!(
763+
let mut err = struct_span_err!(
764764
self.tcx.sess, span, E0384,
765765
"re-assignment of immutable variable `{}`",
766-
self.loan_path_to_string(lp))
767-
.span_note(assign.span, "prior assignment occurs here")
768-
.emit();
766+
self.loan_path_to_string(lp));
767+
err.span_label(span, &format!("re-assignment of immutable variable"));
768+
if span != assign.span {
769+
err.span_label(assign.span, &format!("first assignment to `{}`",
770+
self.loan_path_to_string(lp)));
771+
}
772+
err.emit();
769773
}
770774

771775
pub fn span_err(&self, s: Span, m: &str) {

src/librustc_const_eval/check_match.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) {
235235
.flat_map(|arm| &arm.0)
236236
.map(|pat| vec![wrap_pat(cx, &pat)])
237237
.collect();
238-
let match_span = Span {
239-
lo: ex.span.lo,
240-
hi: scrut.span.hi,
241-
expn_id: ex.span.expn_id
242-
};
243-
check_exhaustive(cx, match_span, &matrix, source);
238+
check_exhaustive(cx, scrut.span, &matrix, source);
244239
},
245240
_ => ()
246241
}
@@ -1115,9 +1110,15 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
11151110

11161111
// x @ Foo(..) is legal, but x @ Foo(y) isn't.
11171112
if sub.map_or(false, |p| pat_contains_bindings(&p)) {
1118-
span_err!(cx.tcx.sess, p.span, E0007, "cannot bind by-move with sub-bindings");
1113+
struct_span_err!(cx.tcx.sess, p.span, E0007,
1114+
"cannot bind by-move with sub-bindings")
1115+
.span_label(p.span, &format!("binds an already bound by-move value by moving it"))
1116+
.emit();
11191117
} else if has_guard {
1120-
span_err!(cx.tcx.sess, p.span, E0008, "cannot bind by-move into a pattern guard");
1118+
struct_span_err!(cx.tcx.sess, p.span, E0008,
1119+
"cannot bind by-move into a pattern guard")
1120+
.span_label(p.span, &format!("moves value into pattern guard"))
1121+
.emit();
11211122
} else if by_ref_span.is_some() {
11221123
let mut err = struct_span_err!(cx.tcx.sess, p.span, E0009,
11231124
"cannot bind by-move and by-ref in the same pattern");

src/librustc_mir/transform/qualify_consts.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
615615
if !allow {
616616
self.add(Qualif::NOT_CONST);
617617
if self.mode != Mode::Fn {
618-
span_err!(self.tcx.sess, self.span, E0017,
619-
"references in {}s may only refer \
620-
to immutable values", self.mode);
618+
struct_span_err!(self.tcx.sess, self.span, E0017,
619+
"references in {}s may only refer \
620+
to immutable values", self.mode)
621+
.span_label(self.span, &format!("{}s require immutable values",
622+
self.mode))
623+
.emit();
621624
}
622625
}
623626
} else {

src/librustc_passes/ast_validation.rs

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ impl<'a> Visitor for AstValidator<'a> {
183183
E0130,
184184
"patterns aren't allowed in foreign function \
185185
declarations");
186+
err.span_label(span, &format!("pattern not allowed in foreign function"));
186187
if is_recent {
187188
err.span_note(span,
188189
"this is a recent error, see issue #35203 for more details");

src/librustc_resolve/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,10 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
412412
struct_span_err!(resolver.session, span, E0432, "{}", msg)
413413
}
414414
ResolutionError::FailedToResolve(msg) => {
415-
struct_span_err!(resolver.session, span, E0433, "failed to resolve. {}", msg)
415+
let mut err = struct_span_err!(resolver.session, span, E0433,
416+
"failed to resolve. {}", msg);
417+
err.span_label(span, &msg);
418+
err
416419
}
417420
ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => {
418421
struct_span_err!(resolver.session,

src/librustc_typeck/check/compare_method.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use rustc::ty;
1414
use rustc::traits::{self, ProjectionMode};
1515
use rustc::ty::error::ExpectedFound;
1616
use rustc::ty::subst::{self, Subst, Substs, VecPerParamSpace};
17+
use rustc::hir::map::Node;
18+
use rustc::hir::{ImplItemKind, TraitItem_};
1719

1820
use syntax::ast;
1921
use syntax_pos::Span;
@@ -461,7 +463,7 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
461463
// Compute skolemized form of impl and trait const tys.
462464
let impl_ty = impl_c.ty.subst(tcx, impl_to_skol_substs);
463465
let trait_ty = trait_c.ty.subst(tcx, &trait_to_skol_substs);
464-
let origin = TypeOrigin::Misc(impl_c_span);
466+
let mut origin = TypeOrigin::Misc(impl_c_span);
465467

466468
let err = infcx.commit_if_ok(|_| {
467469
// There is no "body" here, so just pass dummy id.
@@ -496,11 +498,31 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
496498
debug!("checking associated const for compatibility: impl ty {:?}, trait ty {:?}",
497499
impl_ty,
498500
trait_ty);
501+
502+
// Locate the Span containing just the type of the offending impl
503+
if let Some(impl_trait_node) = tcx.map.get_if_local(impl_c.def_id) {
504+
if let Node::NodeImplItem(impl_trait_item) = impl_trait_node {
505+
if let ImplItemKind::Const(ref ty, _) = impl_trait_item.node {
506+
origin = TypeOrigin::Misc(ty.span);
507+
}
508+
}
509+
}
510+
499511
let mut diag = struct_span_err!(
500512
tcx.sess, origin.span(), E0326,
501513
"implemented const `{}` has an incompatible type for trait",
502514
trait_c.name
503515
);
516+
517+
// Add a label to the Span containing just the type of the item
518+
if let Some(orig_trait_node) = tcx.map.get_if_local(trait_c.def_id) {
519+
if let Node::NodeTraitItem(orig_trait_item) = orig_trait_node {
520+
if let TraitItem_::ConstTraitItem(ref ty, _) = orig_trait_item.node {
521+
diag.span_label(ty.span, &format!("original trait requirement"));
522+
}
523+
}
524+
}
525+
504526
infcx.note_type_err(
505527
&mut diag, origin,
506528
Some(infer::ValuePairs::Types(ExpectedFound {

src/librustc_typeck/check/intrinsic.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &hir::ForeignItem) {
9797
(0, Vec::new(), tcx.mk_nil())
9898
}
9999
op => {
100-
span_err!(tcx.sess, it.span, E0092,
101-
"unrecognized atomic operation function: `{}`", op);
100+
struct_span_err!(tcx.sess, it.span, E0092,
101+
"unrecognized atomic operation function: `{}`", op)
102+
.span_label(it.span, &format!("unrecognized atomic operation"))
103+
.emit();
102104
return;
103105
}
104106
};

src/librustc_typeck/check/mod.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -1272,13 +1272,21 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
12721272

12731273
// Check for duplicate discriminant values
12741274
if let Some(i) = disr_vals.iter().position(|&x| x == current_disr_val) {
1275-
let mut err = struct_span_err!(ccx.tcx.sess, v.span, E0081,
1276-
"discriminant value `{}` already exists", disr_vals[i]);
12771275
let variant_i_node_id = ccx.tcx.map.as_local_node_id(variants[i].did).unwrap();
1278-
err.span_label(ccx.tcx.map.span(variant_i_node_id),
1279-
&format!("first use of `{}`", disr_vals[i]));
1280-
err.span_label(v.span , &format!("enum already has `{}`", disr_vals[i]));
1281-
err.emit();
1276+
let variant_i = ccx.tcx.map.expect_variant(variant_i_node_id);
1277+
let i_span = match variant_i.node.disr_expr {
1278+
Some(ref expr) => expr.span,
1279+
None => ccx.tcx.map.span(variant_i_node_id)
1280+
};
1281+
let span = match v.node.disr_expr {
1282+
Some(ref expr) => expr.span,
1283+
None => v.span
1284+
};
1285+
struct_span_err!(ccx.tcx.sess, span, E0081,
1286+
"discriminant value `{}` already exists", disr_vals[i])
1287+
.span_label(i_span, &format!("first use of `{}`", disr_vals[i]))
1288+
.span_label(span , &format!("enum already has `{}`", disr_vals[i]))
1289+
.emit();
12821290
}
12831291
disr_vals.push(current_disr_val);
12841292
}
@@ -4640,9 +4648,11 @@ pub fn check_bounds_are_used<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
46404648

46414649
for (i, b) in tps_used.iter().enumerate() {
46424650
if !*b {
4643-
span_err!(ccx.tcx.sess, tps[i].span, E0091,
4651+
struct_span_err!(ccx.tcx.sess, tps[i].span, E0091,
46444652
"type parameter `{}` is unused",
4645-
tps[i].name);
4653+
tps[i].name)
4654+
.span_label(tps[i].span, &format!("unused type parameter"))
4655+
.emit();
46464656
}
46474657
}
46484658
}

src/librustc_typeck/collect.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1903,9 +1903,12 @@ fn convert_default_type_parameter<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
19031903
for leaf_ty in ty.walk() {
19041904
if let ty::TyParam(p) = leaf_ty.sty {
19051905
if p.space == space && p.idx >= index {
1906-
span_err!(ccx.tcx.sess, path.span, E0128,
1907-
"type parameters with a default cannot use \
1908-
forward declared identifiers");
1906+
struct_span_err!(ccx.tcx.sess, path.span, E0128,
1907+
"type parameters with a default cannot use \
1908+
forward declared identifiers")
1909+
.span_label(path.span, &format!("defaulted type parameters \
1910+
cannot be forward declared"))
1911+
.emit();
19091912

19101913
return ccx.tcx.types.err
19111914
}

src/librustc_typeck/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ fn require_c_abi_if_variadic(tcx: TyCtxt,
178178
abi: Abi,
179179
span: Span) {
180180
if decl.variadic && abi != Abi::C {
181-
span_err!(tcx.sess, span, E0045,
181+
let mut err = struct_span_err!(tcx.sess, span, E0045,
182182
"variadic function must have C calling convention");
183+
err.span_label(span, &("variadics require C calling conventions").to_string())
184+
.emit();
183185
}
184186
}
185187

0 commit comments

Comments
 (0)