Skip to content

Commit 80f68dd

Browse files
committed
Auto merge of #155534 - jhpratt:rollup-yAM8Y9R, r=jhpratt
Rollup of 6 pull requests Successful merges: - #154654 (Move `std::io::ErrorKind` to `core::io`) - #155054 (constify `Index(Mut)`, `Deref(Mut)` for `Vec`) - #155507 (suggest expect instead of unwrap when arg provided) - #154664 (core/num: Implement feature `integer_cast_extras`) - #155474 (Rename incremental `cfail`/`cpass` revisions to `bfail`/`bpass`) - #155493 (docs(num): fix stale link to `mem::Alignment`)
2 parents e22c616 + b0c8117 commit 80f68dd

123 files changed

Lines changed: 3837 additions & 3562 deletions

File tree

Some content is hidden

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

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,6 +2346,17 @@ impl<'a, 'b, 'tcx> FnCallDiagCtxt<'a, 'b, 'tcx> {
23462346
provided_span,
23472347
format!("unexpected argument{idx}{provided_ty_name}"),
23482348
));
2349+
if self.provided_arg_tys.len() == 1
2350+
&& let Some(span) = self.maybe_suggest_expect_for_unwrap(provided_ty)
2351+
{
2352+
err.span_suggestion_verbose(
2353+
span,
2354+
"did you mean to use `expect`?",
2355+
"expect",
2356+
Applicability::MaybeIncorrect,
2357+
);
2358+
continue;
2359+
}
23492360
let mut span = provided_span;
23502361
if span.can_be_used_for_suggestions()
23512362
&& self.call_metadata.error_span.can_be_used_for_suggestions()
@@ -2776,6 +2787,22 @@ impl<'a, 'b, 'tcx> FnCallDiagCtxt<'a, 'b, 'tcx> {
27762787

27772788
(suggestion_span, suggestion)
27782789
}
2790+
2791+
fn maybe_suggest_expect_for_unwrap(&self, provided_ty: Ty<'tcx>) -> Option<Span> {
2792+
let tcx = self.tcx();
2793+
if let Some(call_ident) = self.call_metadata.call_ident
2794+
&& call_ident.name == sym::unwrap
2795+
&& let Some(callee_ty) = self.callee_ty
2796+
&& let ty::Adt(adt, _) = callee_ty.peel_refs().kind()
2797+
&& (tcx.is_diagnostic_item(sym::Option, adt.did())
2798+
|| tcx.is_diagnostic_item(sym::Result, adt.did()))
2799+
&& self.may_coerce(provided_ty, Ty::new_static_str(tcx))
2800+
{
2801+
Some(call_ident.span)
2802+
} else {
2803+
None
2804+
}
2805+
}
27792806
}
27802807

27812808
struct ArgMatchingCtxt<'a, 'b, 'tcx> {

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
#![feature(const_destruct)]
107107
#![feature(const_eval_select)]
108108
#![feature(const_heap)]
109+
#![feature(const_index)]
109110
#![feature(const_option_ops)]
110111
#![feature(const_try)]
111112
#![feature(copied_into_inner)]

library/alloc/src/vec/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3747,7 +3747,8 @@ impl<T: TrivialClone, A: Allocator> ExtendFromWithinSpec for Vec<T, A> {
37473747
////////////////////////////////////////////////////////////////////////////////
37483748

37493749
#[stable(feature = "rust1", since = "1.0.0")]
3750-
impl<T, A: Allocator> ops::Deref for Vec<T, A> {
3750+
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
3751+
impl<T, A: Allocator> const ops::Deref for Vec<T, A> {
37513752
type Target = [T];
37523753

37533754
#[inline]
@@ -3757,7 +3758,8 @@ impl<T, A: Allocator> ops::Deref for Vec<T, A> {
37573758
}
37583759

37593760
#[stable(feature = "rust1", since = "1.0.0")]
3760-
impl<T, A: Allocator> ops::DerefMut for Vec<T, A> {
3761+
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
3762+
impl<T, A: Allocator> const ops::DerefMut for Vec<T, A> {
37613763
#[inline]
37623764
fn deref_mut(&mut self) -> &mut [T] {
37633765
self.as_mut_slice()
@@ -3822,7 +3824,8 @@ impl<T: Hash, A: Allocator> Hash for Vec<T, A> {
38223824
}
38233825

38243826
#[stable(feature = "rust1", since = "1.0.0")]
3825-
impl<T, I: SliceIndex<[T]>, A: Allocator> Index<I> for Vec<T, A> {
3827+
#[rustc_const_unstable(feature = "const_index", issue = "143775")]
3828+
impl<T, I: [const] SliceIndex<[T]>, A: Allocator> const Index<I> for Vec<T, A> {
38263829
type Output = I::Output;
38273830

38283831
#[inline]
@@ -3832,7 +3835,8 @@ impl<T, I: SliceIndex<[T]>, A: Allocator> Index<I> for Vec<T, A> {
38323835
}
38333836

38343837
#[stable(feature = "rust1", since = "1.0.0")]
3835-
impl<T, I: SliceIndex<[T]>, A: Allocator> IndexMut<I> for Vec<T, A> {
3838+
#[rustc_const_unstable(feature = "const_index", issue = "143775")]
3839+
impl<T, I: [const] SliceIndex<[T]>, A: Allocator> const IndexMut<I> for Vec<T, A> {
38363840
#[inline]
38373841
fn index_mut(&mut self, index: I) -> &mut Self::Output {
38383842
IndexMut::index_mut(&mut **self, index)

0 commit comments

Comments
 (0)