mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-17 22:46:50 +00:00
Auto merge of #101017 - JohnTitor:rollup-73f2fhb, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #99064 (distinguish the method and associated function diagnostic information) - #99920 (Custom allocator support in `rustc_serialize`) - #100034 ( Elaborate all box dereferences in `ElaborateBoxDerefs`) - #100076 (make slice::{split_at,split_at_unchecked} const functions) - #100604 (Remove unstable Result::into_ok_or_err) - #100933 (Reduce code size of `assert_matches_failed`) - #100978 (Handle `Err` in `ast::LitKind::to_token_lit`.) - #101010 (rustdoc: remove unused CSS for `.multi-column`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
13a6aaffdf
@ -199,7 +199,9 @@ impl LitKind {
|
||||
let symbol = if value { kw::True } else { kw::False };
|
||||
(token::Bool, symbol, None)
|
||||
}
|
||||
LitKind::Err => unreachable!(),
|
||||
// This only shows up in places like `-Zunpretty=hir` output, so we
|
||||
// don't bother to produce something useful.
|
||||
LitKind::Err => (token::Err, Symbol::intern("<bad-literal>"), None),
|
||||
};
|
||||
|
||||
token::Lit::new(kind, symbol, suffix)
|
||||
|
@ -14,7 +14,6 @@ index 06c7be0..359e2e7 100644
|
||||
@@ -75,7 +75,6 @@
|
||||
#![feature(never_type)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![feature(result_into_ok_or_err)]
|
||||
-#![feature(portable_simd)]
|
||||
#![feature(ptr_metadata)]
|
||||
#![feature(once_cell)]
|
||||
|
@ -1531,6 +1531,7 @@ impl<'tcx> Place<'tcx> {
|
||||
}
|
||||
|
||||
impl From<Local> for Place<'_> {
|
||||
#[inline]
|
||||
fn from(local: Local) -> Self {
|
||||
Place { local, projection: List::empty() }
|
||||
}
|
||||
|
@ -23,12 +23,6 @@ use crate::{Analysis, AnalysisDomain, Backward, CallReturnPlaces, GenKill, GenKi
|
||||
/// [liveness]: https://en.wikipedia.org/wiki/Live_variable_analysis
|
||||
pub struct MaybeLiveLocals;
|
||||
|
||||
impl MaybeLiveLocals {
|
||||
fn transfer_function<'a, T>(&self, trans: &'a mut T) -> TransferFunction<'a, T> {
|
||||
TransferFunction(trans)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> AnalysisDomain<'tcx> for MaybeLiveLocals {
|
||||
type Domain = ChunkedBitSet<Local>;
|
||||
type Direction = Backward;
|
||||
@ -54,7 +48,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
|
||||
statement: &mir::Statement<'tcx>,
|
||||
location: Location,
|
||||
) {
|
||||
self.transfer_function(trans).visit_statement(statement, location);
|
||||
TransferFunction(trans).visit_statement(statement, location);
|
||||
}
|
||||
|
||||
fn terminator_effect(
|
||||
@ -63,7 +57,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
|
||||
terminator: &mir::Terminator<'tcx>,
|
||||
location: Location,
|
||||
) {
|
||||
self.transfer_function(trans).visit_terminator(terminator, location);
|
||||
TransferFunction(trans).visit_terminator(terminator, location);
|
||||
}
|
||||
|
||||
fn call_return_effect(
|
||||
@ -85,9 +79,11 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
|
||||
_resume_block: mir::BasicBlock,
|
||||
resume_place: mir::Place<'tcx>,
|
||||
) {
|
||||
if let Some(local) = resume_place.as_local() {
|
||||
trans.kill(local);
|
||||
}
|
||||
YieldResumeEffect(trans).visit_place(
|
||||
&resume_place,
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Yield),
|
||||
Location::START,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,28 +94,51 @@ where
|
||||
T: GenKill<Local>,
|
||||
{
|
||||
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
|
||||
let local = place.local;
|
||||
|
||||
// We purposefully do not call `super_place` here to avoid calling `visit_local` for this
|
||||
// place with one of the `Projection` variants of `PlaceContext`.
|
||||
self.visit_projection(place.as_ref(), context, location);
|
||||
if let PlaceContext::MutatingUse(MutatingUseContext::Yield) = context {
|
||||
// The resume place is evaluated and assigned to only after generator resumes, so its
|
||||
// effect is handled separately in `yield_resume_effect`.
|
||||
return;
|
||||
}
|
||||
|
||||
match DefUse::for_place(*place, context) {
|
||||
Some(DefUse::Def) => self.0.kill(local),
|
||||
Some(DefUse::Use) => self.0.gen(local),
|
||||
Some(DefUse::Def) => {
|
||||
if let PlaceContext::MutatingUse(
|
||||
MutatingUseContext::Call | MutatingUseContext::AsmOutput,
|
||||
) = context
|
||||
{
|
||||
// For the associated terminators, this is only a `Def` when the terminator returns
|
||||
// "successfully." As such, we handle this case separately in `call_return_effect`
|
||||
// above. However, if the place looks like `*_5`, this is still unconditionally a use of
|
||||
// `_5`.
|
||||
} else {
|
||||
self.0.kill(place.local);
|
||||
}
|
||||
}
|
||||
Some(DefUse::Use) => self.0.gen(place.local),
|
||||
None => {}
|
||||
}
|
||||
|
||||
self.visit_projection(place.as_ref(), context, location);
|
||||
}
|
||||
|
||||
fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
|
||||
// Because we do not call `super_place` above, `visit_local` is only called for locals that
|
||||
// do not appear as part of a `Place` in the MIR. This handles cases like the implicit use
|
||||
// of the return place in a `Return` terminator or the index in an `Index` projection.
|
||||
match DefUse::for_place(local.into(), context) {
|
||||
Some(DefUse::Def) => self.0.kill(local),
|
||||
Some(DefUse::Use) => self.0.gen(local),
|
||||
None => {}
|
||||
}
|
||||
DefUse::apply(self.0, local.into(), context);
|
||||
}
|
||||
}
|
||||
|
||||
struct YieldResumeEffect<'a, T>(&'a mut T);
|
||||
|
||||
impl<'tcx, T> Visitor<'tcx> for YieldResumeEffect<'_, T>
|
||||
where
|
||||
T: GenKill<Local>,
|
||||
{
|
||||
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
|
||||
DefUse::apply(self.0, *place, context);
|
||||
self.visit_projection(place.as_ref(), context, location);
|
||||
}
|
||||
|
||||
fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
|
||||
DefUse::apply(self.0, local.into(), context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,11 +149,25 @@ enum DefUse {
|
||||
}
|
||||
|
||||
impl DefUse {
|
||||
fn apply<'tcx>(trans: &mut impl GenKill<Local>, place: Place<'tcx>, context: PlaceContext) {
|
||||
match DefUse::for_place(place, context) {
|
||||
Some(DefUse::Def) => trans.kill(place.local),
|
||||
Some(DefUse::Use) => trans.gen(place.local),
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn for_place<'tcx>(place: Place<'tcx>, context: PlaceContext) -> Option<DefUse> {
|
||||
match context {
|
||||
PlaceContext::NonUse(_) => None,
|
||||
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Store | MutatingUseContext::Deinit) => {
|
||||
PlaceContext::MutatingUse(
|
||||
MutatingUseContext::Call
|
||||
| MutatingUseContext::Yield
|
||||
| MutatingUseContext::AsmOutput
|
||||
| MutatingUseContext::Store
|
||||
| MutatingUseContext::Deinit,
|
||||
) => {
|
||||
if place.is_indirect() {
|
||||
// Treat derefs as a use of the base local. `*p = 4` is not a def of `p` but a
|
||||
// use.
|
||||
@ -152,16 +185,6 @@ impl DefUse {
|
||||
place.is_indirect().then_some(DefUse::Use)
|
||||
}
|
||||
|
||||
// For the associated terminators, this is only a `Def` when the terminator returns
|
||||
// "successfully." As such, we handle this case separately in `call_return_effect`
|
||||
// above. However, if the place looks like `*_5`, this is still unconditionally a use of
|
||||
// `_5`.
|
||||
PlaceContext::MutatingUse(
|
||||
MutatingUseContext::Call
|
||||
| MutatingUseContext::Yield
|
||||
| MutatingUseContext::AsmOutput,
|
||||
) => place.is_indirect().then_some(DefUse::Use),
|
||||
|
||||
// All other contexts are uses...
|
||||
PlaceContext::MutatingUse(
|
||||
MutatingUseContext::AddressOf
|
||||
@ -290,8 +313,10 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> {
|
||||
_resume_block: mir::BasicBlock,
|
||||
resume_place: mir::Place<'tcx>,
|
||||
) {
|
||||
if let Some(local) = resume_place.as_local() {
|
||||
trans.remove(local);
|
||||
}
|
||||
YieldResumeEffect(trans).visit_place(
|
||||
&resume_place,
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Yield),
|
||||
Location::START,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -107,27 +107,8 @@ impl<'tcx> MirPass<'tcx> for ElaborateBoxDerefs {
|
||||
let mut visitor =
|
||||
ElaborateBoxDerefVisitor { tcx, unique_did, nonnull_did, local_decls, patch };
|
||||
|
||||
for (block, BasicBlockData { statements, terminator, .. }) in
|
||||
body.basic_blocks.as_mut_preserves_cfg().iter_enumerated_mut()
|
||||
{
|
||||
let mut index = 0;
|
||||
for statement in statements {
|
||||
let location = Location { block, statement_index: index };
|
||||
visitor.visit_statement(statement, location);
|
||||
index += 1;
|
||||
}
|
||||
|
||||
let location = Location { block, statement_index: index };
|
||||
match terminator {
|
||||
// yielding into a box is handled when lowering generators
|
||||
Some(Terminator { kind: TerminatorKind::Yield { value, .. }, .. }) => {
|
||||
visitor.visit_operand(value, location);
|
||||
}
|
||||
Some(terminator) => {
|
||||
visitor.visit_terminator(terminator, location);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
for (block, data) in body.basic_blocks.as_mut_preserves_cfg().iter_enumerated_mut() {
|
||||
visitor.visit_basic_block_data(block, data);
|
||||
}
|
||||
|
||||
visitor.patch.apply(body);
|
||||
|
@ -1182,8 +1182,6 @@ fn create_cases<'tcx>(
|
||||
transform: &TransformVisitor<'tcx>,
|
||||
operation: Operation,
|
||||
) -> Vec<(usize, BasicBlock)> {
|
||||
let tcx = transform.tcx;
|
||||
|
||||
let source_info = SourceInfo::outermost(body.span);
|
||||
|
||||
transform
|
||||
@ -1216,85 +1214,13 @@ fn create_cases<'tcx>(
|
||||
if operation == Operation::Resume {
|
||||
// Move the resume argument to the destination place of the `Yield` terminator
|
||||
let resume_arg = Local::new(2); // 0 = return, 1 = self
|
||||
|
||||
// handle `box yield` properly
|
||||
let box_place = if let [projection @ .., ProjectionElem::Deref] =
|
||||
&**point.resume_arg.projection
|
||||
{
|
||||
let box_place =
|
||||
Place::from(point.resume_arg.local).project_deeper(projection, tcx);
|
||||
|
||||
let box_ty = box_place.ty(&body.local_decls, tcx).ty;
|
||||
|
||||
if box_ty.is_box() { Some((box_place, box_ty)) } else { None }
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some((box_place, box_ty)) = box_place {
|
||||
let unique_did = box_ty
|
||||
.ty_adt_def()
|
||||
.expect("expected Box to be an Adt")
|
||||
.non_enum_variant()
|
||||
.fields[0]
|
||||
.did;
|
||||
|
||||
let Some(nonnull_def) = tcx.type_of(unique_did).ty_adt_def() else {
|
||||
span_bug!(tcx.def_span(unique_did), "expected Box to contain Unique")
|
||||
};
|
||||
|
||||
let nonnull_did = nonnull_def.non_enum_variant().fields[0].did;
|
||||
|
||||
let (unique_ty, nonnull_ty, ptr_ty) =
|
||||
crate::elaborate_box_derefs::build_ptr_tys(
|
||||
tcx,
|
||||
box_ty.boxed_ty(),
|
||||
unique_did,
|
||||
nonnull_did,
|
||||
);
|
||||
|
||||
let ptr_local = body.local_decls.push(LocalDecl::new(ptr_ty, body.span));
|
||||
|
||||
statements.push(Statement {
|
||||
source_info,
|
||||
kind: StatementKind::StorageLive(ptr_local),
|
||||
});
|
||||
|
||||
statements.push(Statement {
|
||||
source_info,
|
||||
kind: StatementKind::Assign(Box::new((
|
||||
Place::from(ptr_local),
|
||||
Rvalue::Use(Operand::Copy(box_place.project_deeper(
|
||||
&crate::elaborate_box_derefs::build_projection(
|
||||
unique_ty, nonnull_ty, ptr_ty,
|
||||
),
|
||||
tcx,
|
||||
))),
|
||||
))),
|
||||
});
|
||||
|
||||
statements.push(Statement {
|
||||
source_info,
|
||||
kind: StatementKind::Assign(Box::new((
|
||||
Place::from(ptr_local)
|
||||
.project_deeper(&[ProjectionElem::Deref], tcx),
|
||||
Rvalue::Use(Operand::Move(resume_arg.into())),
|
||||
))),
|
||||
});
|
||||
|
||||
statements.push(Statement {
|
||||
source_info,
|
||||
kind: StatementKind::StorageDead(ptr_local),
|
||||
});
|
||||
} else {
|
||||
statements.push(Statement {
|
||||
source_info,
|
||||
kind: StatementKind::Assign(Box::new((
|
||||
point.resume_arg,
|
||||
Rvalue::Use(Operand::Move(resume_arg.into())),
|
||||
))),
|
||||
});
|
||||
}
|
||||
statements.push(Statement {
|
||||
source_info,
|
||||
kind: StatementKind::Assign(Box::new((
|
||||
point.resume_arg,
|
||||
Rvalue::Use(Operand::Move(resume_arg.into())),
|
||||
))),
|
||||
});
|
||||
}
|
||||
|
||||
// Then jump to the real target
|
||||
|
@ -16,6 +16,7 @@ Core encoding and decoding interfaces.
|
||||
#![feature(maybe_uninit_slice)]
|
||||
#![feature(let_else)]
|
||||
#![feature(new_uninit)]
|
||||
#![feature(allocator_api)]
|
||||
#![cfg_attr(test, feature(test))]
|
||||
#![allow(rustc::internal)]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
|
@ -4,6 +4,7 @@
|
||||
Core encoding and decoding interfaces.
|
||||
*/
|
||||
|
||||
use std::alloc::Allocator;
|
||||
use std::borrow::Cow;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::marker::PhantomData;
|
||||
@ -229,9 +230,9 @@ impl<D: Decoder, T> Decodable<D> for PhantomData<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Decoder, T: Decodable<D>> Decodable<D> for Box<[T]> {
|
||||
fn decode(d: &mut D) -> Box<[T]> {
|
||||
let v: Vec<T> = Decodable::decode(d);
|
||||
impl<D: Decoder, A: Allocator + Default, T: Decodable<D>> Decodable<D> for Box<[T], A> {
|
||||
fn decode(d: &mut D) -> Box<[T], A> {
|
||||
let v: Vec<T, A> = Decodable::decode(d);
|
||||
v.into_boxed_slice()
|
||||
}
|
||||
}
|
||||
@ -264,12 +265,13 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for Vec<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Decoder, T: Decodable<D>> Decodable<D> for Vec<T> {
|
||||
default fn decode(d: &mut D) -> Vec<T> {
|
||||
impl<D: Decoder, T: Decodable<D>, A: Allocator + Default> Decodable<D> for Vec<T, A> {
|
||||
default fn decode(d: &mut D) -> Vec<T, A> {
|
||||
let len = d.read_usize();
|
||||
let allocator = A::default();
|
||||
// SAFETY: we set the capacity in advance, only write elements, and
|
||||
// only set the length at the end once the writing has succeeded.
|
||||
let mut vec = Vec::with_capacity(len);
|
||||
let mut vec = Vec::with_capacity_in(len, allocator);
|
||||
unsafe {
|
||||
let ptr: *mut T = vec.as_mut_ptr();
|
||||
for i in 0..len {
|
||||
@ -457,13 +459,15 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Arc<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Encoder, T: ?Sized + Encodable<S>> Encodable<S> for Box<T> {
|
||||
impl<S: Encoder, T: ?Sized + Encodable<S>, A: Allocator + Default> Encodable<S> for Box<T, A> {
|
||||
fn encode(&self, s: &mut S) {
|
||||
(**self).encode(s);
|
||||
(**self).encode(s)
|
||||
}
|
||||
}
|
||||
impl<D: Decoder, T: Decodable<D>> Decodable<D> for Box<T> {
|
||||
fn decode(d: &mut D) -> Box<T> {
|
||||
Box::new(Decodable::decode(d))
|
||||
|
||||
impl<D: Decoder, A: Allocator + Default, T: Decodable<D>> Decodable<D> for Box<T, A> {
|
||||
fn decode(d: &mut D) -> Box<T, A> {
|
||||
let allocator = A::default();
|
||||
Box::new_in(Decodable::decode(d), allocator)
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
use super::{Byte, Def, Ref};
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@ -86,17 +87,18 @@ where
|
||||
F: Fn(D) -> bool,
|
||||
{
|
||||
match self {
|
||||
Self::Seq(elts) => elts
|
||||
.into_iter()
|
||||
.map(|elt| elt.prune(f))
|
||||
.try_fold(Tree::unit(), |elts, elt| {
|
||||
Self::Seq(elts) => match elts.into_iter().map(|elt| elt.prune(f)).try_fold(
|
||||
Tree::unit(),
|
||||
|elts, elt| {
|
||||
if elt == Tree::uninhabited() {
|
||||
Err(Tree::uninhabited())
|
||||
ControlFlow::Break(Tree::uninhabited())
|
||||
} else {
|
||||
Ok(elts.then(elt))
|
||||
ControlFlow::Continue(elts.then(elt))
|
||||
}
|
||||
})
|
||||
.into_ok_or_err(),
|
||||
},
|
||||
) {
|
||||
ControlFlow::Break(node) | ControlFlow::Continue(node) => node,
|
||||
},
|
||||
Self::Alt(alts) => alts
|
||||
.into_iter()
|
||||
.map(|alt| alt.prune(f))
|
||||
|
@ -1,11 +1,4 @@
|
||||
#![feature(
|
||||
alloc_layout_extra,
|
||||
control_flow_enum,
|
||||
decl_macro,
|
||||
iterator_try_reduce,
|
||||
never_type,
|
||||
result_into_ok_or_err
|
||||
)]
|
||||
#![feature(alloc_layout_extra, control_flow_enum, decl_macro, iterator_try_reduce, never_type)]
|
||||
#![allow(dead_code, unused_variables)]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
|
@ -1066,16 +1066,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// that had unsatisfied trait bounds
|
||||
if unsatisfied_predicates.is_empty() {
|
||||
let def_kind = lev_candidate.kind.as_def_kind();
|
||||
err.span_suggestion(
|
||||
span,
|
||||
&format!(
|
||||
"there is {} {} with a similar name",
|
||||
def_kind.article(),
|
||||
def_kind.descr(lev_candidate.def_id),
|
||||
),
|
||||
lev_candidate.name,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
// Methods are defined within the context of a struct and their first parameter is always self,
|
||||
// which represents the instance of the struct the method is being called on
|
||||
// Associated functions don’t take self as a parameter and
|
||||
// they are not methods because they don’t have an instance of the struct to work with.
|
||||
if def_kind == DefKind::AssocFn && lev_candidate.fn_has_self_parameter {
|
||||
err.span_suggestion(
|
||||
span,
|
||||
&format!("there is a method with a similar name",),
|
||||
lev_candidate.name,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
err.span_suggestion(
|
||||
span,
|
||||
&format!(
|
||||
"there is {} {} with a similar name",
|
||||
def_kind.article(),
|
||||
def_kind.descr(lev_candidate.def_id),
|
||||
),
|
||||
lev_candidate.name,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,6 +149,7 @@
|
||||
#![feature(maybe_uninit_uninit_array)]
|
||||
#![feature(ptr_metadata)]
|
||||
#![feature(slice_ptr_get)]
|
||||
#![feature(slice_split_at_unchecked)]
|
||||
#![feature(str_internals)]
|
||||
#![feature(utf16_extra)]
|
||||
#![feature(utf16_extra_const)]
|
||||
|
@ -190,11 +190,11 @@ pub fn assert_matches_failed<T: fmt::Debug + ?Sized>(
|
||||
right: &str,
|
||||
args: Option<fmt::Arguments<'_>>,
|
||||
) -> ! {
|
||||
// Use the Display implementation to display the pattern.
|
||||
// The pattern is a string so it can be displayed directly.
|
||||
struct Pattern<'a>(&'a str);
|
||||
impl fmt::Debug for Pattern<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(self.0, f)
|
||||
f.write_str(self.0)
|
||||
}
|
||||
}
|
||||
assert_failed_inner(AssertKind::Match, &left, &Pattern(right), args);
|
||||
|
@ -1776,40 +1776,6 @@ impl<T, E> Result<Result<T, E>, E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Result<T, T> {
|
||||
/// Returns the [`Ok`] value if `self` is `Ok`, and the [`Err`] value if
|
||||
/// `self` is `Err`.
|
||||
///
|
||||
/// In other words, this function returns the value (the `T`) of a
|
||||
/// `Result<T, T>`, regardless of whether or not that result is `Ok` or
|
||||
/// `Err`.
|
||||
///
|
||||
/// This can be useful in conjunction with APIs such as
|
||||
/// [`Atomic*::compare_exchange`], or [`slice::binary_search`], but only in
|
||||
/// cases where you don't care if the result was `Ok` or not.
|
||||
///
|
||||
/// [`Atomic*::compare_exchange`]: crate::sync::atomic::AtomicBool::compare_exchange
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(result_into_ok_or_err)]
|
||||
/// let ok: Result<u32, u32> = Ok(3);
|
||||
/// let err: Result<u32, u32> = Err(4);
|
||||
///
|
||||
/// assert_eq!(ok.into_ok_or_err(), 3);
|
||||
/// assert_eq!(err.into_ok_or_err(), 4);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "result_into_ok_or_err", reason = "newly added", issue = "82223")]
|
||||
pub const fn into_ok_or_err(self) -> T {
|
||||
match self {
|
||||
Ok(v) => v,
|
||||
Err(v) => v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is a separate function to reduce the code size of the methods
|
||||
#[cfg(not(feature = "panic_immediate_abort"))]
|
||||
#[inline(never)]
|
||||
|
@ -1541,13 +1541,14 @@ impl<T> [T] {
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_split_at_not_mut", issue = "none")]
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[must_use]
|
||||
pub fn split_at(&self, mid: usize) -> (&[T], &[T]) {
|
||||
pub const fn split_at(&self, mid: usize) -> (&[T], &[T]) {
|
||||
assert!(mid <= self.len());
|
||||
// SAFETY: `[ptr; mid]` and `[mid; len]` are inside `self`, which
|
||||
// fulfills the requirements of `from_raw_parts_mut`.
|
||||
// fulfills the requirements of `split_at_unchecked`.
|
||||
unsafe { self.split_at_unchecked(mid) }
|
||||
}
|
||||
|
||||
@ -1626,11 +1627,19 @@ impl<T> [T] {
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable(feature = "slice_split_at_unchecked", reason = "new API", issue = "76014")]
|
||||
#[rustc_const_unstable(feature = "slice_split_at_unchecked", issue = "76014")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub unsafe fn split_at_unchecked(&self, mid: usize) -> (&[T], &[T]) {
|
||||
pub const unsafe fn split_at_unchecked(&self, mid: usize) -> (&[T], &[T]) {
|
||||
// HACK: the const function `from_raw_parts` is used to make this
|
||||
// function const; previously the implementation used
|
||||
// `(self.get_unchecked(..mid), self.get_unchecked(mid..))`
|
||||
|
||||
let len = self.len();
|
||||
let ptr = self.as_ptr();
|
||||
|
||||
// SAFETY: Caller has to check that `0 <= mid <= self.len()`
|
||||
unsafe { (self.get_unchecked(..mid), self.get_unchecked(mid..)) }
|
||||
unsafe { (from_raw_parts(ptr, mid), from_raw_parts(ptr.add(mid), len - mid)) }
|
||||
}
|
||||
|
||||
/// Divides one mutable slice into two at an index, without doing bounds checking.
|
||||
|
@ -75,7 +75,6 @@
|
||||
#![feature(const_pin)]
|
||||
#![feature(never_type)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![feature(result_into_ok_or_err)]
|
||||
#![feature(pointer_byte_offsets)]
|
||||
#![feature(portable_simd)]
|
||||
#![feature(ptr_metadata)]
|
||||
|
@ -95,15 +95,6 @@ fn test_unwrap_or() {
|
||||
assert_eq!(ok_err.unwrap_or(50), 50);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ok_or_err() {
|
||||
let ok: Result<isize, isize> = Ok(100);
|
||||
let err: Result<isize, isize> = Err(200);
|
||||
|
||||
assert_eq!(ok.into_ok_or_err(), 100);
|
||||
assert_eq!(err.into_ok_or_err(), 200);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unwrap_or_else() {
|
||||
fn handler(msg: &'static str) -> isize {
|
||||
|
@ -750,16 +750,6 @@ pre, .rustdoc.source .example-wrap {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.content .multi-column {
|
||||
-moz-column-count: 5;
|
||||
-moz-column-gap: 2.5em;
|
||||
-webkit-column-count: 5;
|
||||
-webkit-column-gap: 2.5em;
|
||||
column-count: 5;
|
||||
column-gap: 2.5em;
|
||||
}
|
||||
.content .multi-column li { width: 100%; display: inline-block; }
|
||||
|
||||
.content > .methods > .method {
|
||||
font-size: 1rem;
|
||||
position: relative;
|
||||
|
@ -2,7 +2,7 @@ error[E0599]: no method named `test_mut` found for struct `Vec<{integer}>` in th
|
||||
--> $DIR/auto-ref-slice-plus-ref.rs:7:7
|
||||
|
|
||||
LL | a.test_mut();
|
||||
| ^^^^^^^^ help: there is an associated function with a similar name: `get_mut`
|
||||
| ^^^^^^^^ help: there is a method with a similar name: `get_mut`
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
note: `MyIter` defines an item `test_mut`, perhaps you need to implement it
|
||||
|
@ -2,7 +2,7 @@ error[E0599]: no method named `b` found for reference `&Self` in the current sco
|
||||
--> $DIR/issue-3563.rs:3:17
|
||||
|
|
||||
LL | || self.b()
|
||||
| ^ help: there is an associated function with a similar name: `a`
|
||||
| ^ help: there is a method with a similar name: `a`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -25,7 +25,7 @@ LL | let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
|
||||
| ^^^^^
|
||||
| |
|
||||
| function or associated item not found in `dyn BitXor<_>`
|
||||
| help: there is an associated function with a similar name: `bitxor`
|
||||
| help: there is a method with a similar name: `bitxor`
|
||||
|
||||
warning: trait objects without an explicit `dyn` are deprecated
|
||||
--> $DIR/issue-28344.rs:10:13
|
||||
@ -53,7 +53,7 @@ LL | let g = BitXor::bitor;
|
||||
| ^^^^^
|
||||
| |
|
||||
| function or associated item not found in `dyn BitXor<_>`
|
||||
| help: there is an associated function with a similar name: `bitxor`
|
||||
| help: there is a method with a similar name: `bitxor`
|
||||
|
||||
error: aborting due to 4 previous errors; 2 warnings emitted
|
||||
|
||||
|
@ -2,7 +2,7 @@ error[E0599]: no method named `set` found for array `[u8; 1]` in the current sco
|
||||
--> $DIR/dont-suggest-pin-array-dot-set.rs:14:7
|
||||
|
|
||||
LL | a.set(0, 3);
|
||||
| ^^^ help: there is an associated function with a similar name: `get`
|
||||
| ^^^ help: there is a method with a similar name: `get`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -5,25 +5,25 @@ LL | struct Foo;
|
||||
| ---------- method `bat` not found for this struct
|
||||
...
|
||||
LL | f.bat(1.0);
|
||||
| ^^^ help: there is an associated function with a similar name: `bar`
|
||||
| ^^^ help: there is a method with a similar name: `bar`
|
||||
|
||||
error[E0599]: no method named `is_emtpy` found for struct `String` in the current scope
|
||||
--> $DIR/suggest-methods.rs:21:15
|
||||
|
|
||||
LL | let _ = s.is_emtpy();
|
||||
| ^^^^^^^^ help: there is an associated function with a similar name: `is_empty`
|
||||
| ^^^^^^^^ help: there is a method with a similar name: `is_empty`
|
||||
|
||||
error[E0599]: no method named `count_eos` found for type `u32` in the current scope
|
||||
--> $DIR/suggest-methods.rs:25:19
|
||||
|
|
||||
LL | let _ = 63u32.count_eos();
|
||||
| ^^^^^^^^^ help: there is an associated function with a similar name: `count_zeros`
|
||||
| ^^^^^^^^^ help: there is a method with a similar name: `count_zeros`
|
||||
|
||||
error[E0599]: no method named `count_o` found for type `u32` in the current scope
|
||||
--> $DIR/suggest-methods.rs:28:19
|
||||
|
|
||||
LL | let _ = 63u32.count_o();
|
||||
| ^^^^^^^ help: there is an associated function with a similar name: `count_ones`
|
||||
| ^^^^^^^ help: there is a method with a similar name: `count_ones`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
@ -2,7 +2,7 @@ error[E0599]: no method named `c` found for reference `&dyn Bar` in the current
|
||||
--> $DIR/subtrait-method.rs:56:9
|
||||
|
|
||||
LL | bar.c();
|
||||
| ^ help: there is an associated function with a similar name: `a`
|
||||
| ^ help: there is a method with a similar name: `a`
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
note: `Baz` defines an item `c`, perhaps you need to implement it
|
||||
@ -15,7 +15,7 @@ error[E0599]: no method named `b` found for reference `&dyn Foo` in the current
|
||||
--> $DIR/subtrait-method.rs:60:9
|
||||
|
|
||||
LL | foo.b();
|
||||
| ^ help: there is an associated function with a similar name: `a`
|
||||
| ^ help: there is a method with a similar name: `a`
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
note: `Bar` defines an item `b`, perhaps you need to implement it
|
||||
@ -28,7 +28,7 @@ error[E0599]: no method named `c` found for reference `&dyn Foo` in the current
|
||||
--> $DIR/subtrait-method.rs:62:9
|
||||
|
|
||||
LL | foo.c();
|
||||
| ^ help: there is an associated function with a similar name: `a`
|
||||
| ^ help: there is a method with a similar name: `a`
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
note: `Baz` defines an item `c`, perhaps you need to implement it
|
||||
@ -41,7 +41,7 @@ error[E0599]: no method named `b` found for reference `&dyn Foo` in the current
|
||||
--> $DIR/subtrait-method.rs:66:9
|
||||
|
|
||||
LL | foo.b();
|
||||
| ^ help: there is an associated function with a similar name: `a`
|
||||
| ^ help: there is a method with a similar name: `a`
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
note: `Bar` defines an item `b`, perhaps you need to implement it
|
||||
@ -54,7 +54,7 @@ error[E0599]: no method named `c` found for reference `&dyn Foo` in the current
|
||||
--> $DIR/subtrait-method.rs:68:9
|
||||
|
|
||||
LL | foo.c();
|
||||
| ^ help: there is an associated function with a similar name: `a`
|
||||
| ^ help: there is a method with a similar name: `a`
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
note: `Baz` defines an item `c`, perhaps you need to implement it
|
||||
|
8
src/test/ui/unpretty/bad-literal.rs
Normal file
8
src/test/ui/unpretty/bad-literal.rs
Normal file
@ -0,0 +1,8 @@
|
||||
// compile-flags: -Zunpretty=hir
|
||||
// check-fail
|
||||
|
||||
// In #100948 this caused an ICE with -Zunpretty=hir.
|
||||
fn main() {
|
||||
1u;
|
||||
//~^ ERROR invalid suffix `u` for number literal
|
||||
}
|
10
src/test/ui/unpretty/bad-literal.stderr
Normal file
10
src/test/ui/unpretty/bad-literal.stderr
Normal file
@ -0,0 +1,10 @@
|
||||
error: invalid suffix `u` for number literal
|
||||
--> $DIR/bad-literal.rs:6:5
|
||||
|
|
||||
LL | 1u;
|
||||
| ^^ invalid suffix `u`
|
||||
|
|
||||
= help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
11
src/test/ui/unpretty/bad-literal.stdout
Normal file
11
src/test/ui/unpretty/bad-literal.stdout
Normal file
@ -0,0 +1,11 @@
|
||||
#[prelude_import]
|
||||
use ::std::prelude::rust_2015::*;
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
// compile-flags: -Zunpretty=hir
|
||||
// check-fail
|
||||
|
||||
// In #100948 this caused an ICE with -Zunpretty=hir.
|
||||
fn main() {
|
||||
<bad-literal>;
|
||||
}
|
Loading…
Reference in New Issue
Block a user