Skip to content

Commit d461555

Browse files
committed
Auto merge of #61460 - Centril:rollup-8txhjx4, r=Centril
Rollup of 6 pull requests Successful merges: - #61380 (Fix some issues with `unwrap_usize` instead of `assert_usize`) - #61423 (codegen: change `$6d$` to `$u6d$`) - #61438 (Point at individual type args on arg count mismatch) - #61441 (Tweak wording when encountering `fn` call in pattern) - #61451 (Fix missing semicolon in doc) - #61458 (Fix typo in AsRef doc) Failed merges: r? @ghost
2 parents 4c7bb8b + aaf264b commit d461555

33 files changed

+313
-92
lines changed

src/libcore/convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub const fn identity<T>(x: T) -> T { x }
129129
/// # Examples
130130
///
131131
/// By using trait bounds we can accept arguments of different types as long as they can be
132-
/// converted a the specified type `T`.
132+
/// converted to the specified type `T`.
133133
///
134134
/// For example: By creating a generic function that takes an `AsRef<str>` we express that we
135135
/// want to accept all references that can be converted to `&str` as an argument.

src/librustc/hir/map/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,10 +628,6 @@ impl<'hir> Map<'hir> {
628628
})
629629
}
630630

631-
pub fn get_generics_span(&self, id: DefId) -> Option<Span> {
632-
self.get_generics(id).map(|generics| generics.span).filter(|sp| *sp != DUMMY_SP)
633-
}
634-
635631
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
636632
pub fn find(&self, id: NodeId) -> Option<Node<'hir>> {
637633
let hir_id = self.node_to_hir_id(id);

src/librustc/hir/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::util::nodemap::{NodeMap, FxHashSet};
1616
use crate::mir::mono::Linkage;
1717

1818
use errors::FatalError;
19-
use syntax_pos::{Span, DUMMY_SP, symbol::InternedString};
19+
use syntax_pos::{Span, DUMMY_SP, symbol::InternedString, MultiSpan};
2020
use syntax::source_map::Spanned;
2121
use rustc_target::spec::abi::Abi;
2222
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
@@ -625,6 +625,14 @@ impl Generics {
625625
}
626626
None
627627
}
628+
629+
pub fn spans(&self) -> MultiSpan {
630+
if self.params.is_empty() {
631+
self.span.into()
632+
} else {
633+
self.params.iter().map(|p| p.span).collect::<Vec<Span>>().into()
634+
}
635+
}
628636
}
629637

630638
/// Synthetic type parameters are converted to another form during lowering; this allows

src/librustc/traits/error_reporting.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
914914
}
915915

916916
// already reported in the query
917-
ConstEvalFailure(_) => {
918-
self.tcx.sess.delay_span_bug(span, "constant in type had an ignored error");
917+
ConstEvalFailure(err) => {
918+
self.tcx.sess.delay_span_bug(
919+
span,
920+
&format!("constant in type had an ignored error: {:?}", err),
921+
);
919922
return;
920923
}
921924

src/librustc/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
549549
}
550550
}
551551

552+
let count = count.assert_usize(tcx).ok_or(LayoutError::Unknown(ty))?;
552553
let element = self.layout_of(element)?;
553-
let count = count.unwrap_usize(tcx);
554554
let size = element.size.checked_mul(count, dl)
555555
.ok_or(LayoutError::SizeOverflow(ty))?;
556556

src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,7 @@ fn fixed_vec_metadata(
342342
let (size, align) = cx.size_and_align_of(array_or_slice_type);
343343

344344
let upper_bound = match array_or_slice_type.sty {
345-
ty::Array(_, len) => {
346-
len.unwrap_usize(cx.tcx) as c_longlong
347-
}
345+
ty::Array(_, len) => len.unwrap_usize(cx.tcx) as c_longlong,
348346
_ => -1
349347
};
350348

src/librustc_codegen_utils/symbol_names/legacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl fmt::Write for SymbolPrinter<'_, '_> {
440440
'-' | ':' => self.path.temp_buf.push('.'),
441441

442442
// Avoid crashing LLVM in certain (LTO-related) situations, see #60925.
443-
'm' if self.path.temp_buf.ends_with(".llv") => self.path.temp_buf.push_str("$6d$"),
443+
'm' if self.path.temp_buf.ends_with(".llv") => self.path.temp_buf.push_str("$u6d$"),
444444

445445
// These are legal symbols
446446
'a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '.' | '$' => self.path.temp_buf.push(c),

src/librustc_mir/borrow_check/places_conflict.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ fn place_base_conflict<'a, 'gcx: 'tcx, 'tcx>(
332332
},
333333
(StaticKind::Promoted(promoted_1), StaticKind::Promoted(promoted_2)) => {
334334
if promoted_1 == promoted_2 {
335-
if let ty::Array(_, size) = s1.ty.sty {
336-
if size.unwrap_usize(tcx) == 0 {
335+
if let ty::Array(_, len) = s1.ty.sty {
336+
if let Some(0) = len.assert_usize(tcx) {
337337
// Ignore conflicts with promoted [T; 0].
338338
debug!("place_element_conflict: IGNORE-LEN-0-PROMOTED");
339339
return Overlap::Disjoint;

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,9 @@ impl Qualif for HasMutInterior {
316316
} else if let ty::Array(_, len) = ty.sty {
317317
// FIXME(eddyb) the `cx.mode == Mode::Fn` condition
318318
// seems unnecessary, given that this is merely a ZST.
319-
if !(len.unwrap_usize(cx.tcx) == 0 && cx.mode == Mode::Fn) {
320-
return true;
319+
match len.assert_usize(cx.tcx) {
320+
Some(0) if cx.mode == Mode::Fn => {},
321+
_ => return true,
321322
}
322323
} else {
323324
return true;

src/librustc_typeck/check/_match.rs

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -400,27 +400,36 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
400400
let expected_ty = self.structurally_resolved_type(pat.span, expected);
401401
let (inner_ty, slice_ty) = match expected_ty.sty {
402402
ty::Array(inner_ty, size) => {
403-
let size = size.unwrap_usize(tcx);
404-
let min_len = before.len() as u64 + after.len() as u64;
405-
if slice.is_none() {
406-
if min_len != size {
407-
struct_span_err!(
408-
tcx.sess, pat.span, E0527,
409-
"pattern requires {} elements but array has {}",
410-
min_len, size)
411-
.span_label(pat.span, format!("expected {} elements", size))
403+
if let Some(size) = size.assert_usize(tcx) {
404+
let min_len = before.len() as u64 + after.len() as u64;
405+
if slice.is_none() {
406+
if min_len != size {
407+
struct_span_err!(
408+
tcx.sess, pat.span, E0527,
409+
"pattern requires {} elements but array has {}",
410+
min_len, size)
411+
.span_label(pat.span, format!("expected {} elements", size))
412+
.emit();
413+
}
414+
(inner_ty, tcx.types.err)
415+
} else if let Some(rest) = size.checked_sub(min_len) {
416+
(inner_ty, tcx.mk_array(inner_ty, rest))
417+
} else {
418+
struct_span_err!(tcx.sess, pat.span, E0528,
419+
"pattern requires at least {} elements but array has {}",
420+
min_len, size)
421+
.span_label(pat.span,
422+
format!("pattern cannot match array of {} elements", size))
412423
.emit();
424+
(inner_ty, tcx.types.err)
413425
}
414-
(inner_ty, tcx.types.err)
415-
} else if let Some(rest) = size.checked_sub(min_len) {
416-
(inner_ty, tcx.mk_array(inner_ty, rest))
417426
} else {
418-
struct_span_err!(tcx.sess, pat.span, E0528,
419-
"pattern requires at least {} elements but array has {}",
420-
min_len, size)
421-
.span_label(pat.span,
422-
format!("pattern cannot match array of {} elements", size))
423-
.emit();
427+
struct_span_err!(
428+
tcx.sess,
429+
pat.span,
430+
E0730,
431+
"cannot pattern-match on an array without a fixed length",
432+
).emit();
424433
(inner_ty, tcx.types.err)
425434
}
426435
}
@@ -1080,8 +1089,18 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
10801089
let msg = format!("expected tuple struct/variant, found {} `{}`",
10811090
res.descr(),
10821091
hir::print::to_string(tcx.hir(), |s| s.print_qpath(qpath, false)));
1083-
struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg)
1084-
.span_label(pat.span, "not a tuple variant or struct").emit();
1092+
let mut err = struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg);
1093+
match (res, &pat.node) {
1094+
(Res::Def(DefKind::Fn, _), _) | (Res::Def(DefKind::Method, _), _) => {
1095+
err.span_label(pat.span, "`fn` calls are not allowed in patterns");
1096+
err.help("for more information, visit \
1097+
https://doc.rust-lang.org/book/ch18-00-patterns.html");
1098+
}
1099+
_ => {
1100+
err.span_label(pat.span, "not a tuple variant or struct");
1101+
}
1102+
}
1103+
err.emit();
10851104
on_error();
10861105
};
10871106

0 commit comments

Comments
 (0)