Merge from rustc
This commit is contained in:
@@ -164,7 +164,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
||||
fn visit_item(&mut self, i: &'hir Item<'hir>) {
|
||||
debug_assert_eq!(i.owner_id, self.owner);
|
||||
self.with_parent(i.hir_id(), |this| {
|
||||
if let ItemKind::Struct(_, struct_def, _) = &i.kind {
|
||||
if let ItemKind::Struct(_, _, struct_def) = &i.kind {
|
||||
// If this is a tuple or unit-like struct, register the constructor.
|
||||
if let Some(ctor_hir_id) = struct_def.ctor_hir_id() {
|
||||
this.insert(i.span, ctor_hir_id, Node::Ctor(struct_def));
|
||||
|
||||
@@ -180,7 +180,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
let (ty, body_id) =
|
||||
self.lower_const_item(t, span, e.as_deref(), ImplTraitPosition::StaticTy);
|
||||
self.lower_define_opaque(hir_id, define_opaque);
|
||||
hir::ItemKind::Static(ident, ty, *m, body_id)
|
||||
hir::ItemKind::Static(*m, ident, ty, body_id)
|
||||
}
|
||||
ItemKind::Const(box ast::ConstItem {
|
||||
ident,
|
||||
@@ -200,7 +200,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
},
|
||||
);
|
||||
self.lower_define_opaque(hir_id, &define_opaque);
|
||||
hir::ItemKind::Const(ident, ty, generics, body_id)
|
||||
hir::ItemKind::Const(ident, generics, ty, body_id)
|
||||
}
|
||||
ItemKind::Fn(box Fn {
|
||||
sig: FnSig { decl, header, span: fn_sig_span },
|
||||
@@ -304,7 +304,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
),
|
||||
},
|
||||
);
|
||||
hir::ItemKind::TyAlias(ident, ty, generics)
|
||||
hir::ItemKind::TyAlias(ident, generics, ty)
|
||||
}
|
||||
ItemKind::Enum(ident, generics, enum_definition) => {
|
||||
let ident = self.lower_ident(*ident);
|
||||
@@ -318,7 +318,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
)
|
||||
},
|
||||
);
|
||||
hir::ItemKind::Enum(ident, hir::EnumDef { variants }, generics)
|
||||
hir::ItemKind::Enum(ident, generics, hir::EnumDef { variants })
|
||||
}
|
||||
ItemKind::Struct(ident, generics, struct_def) => {
|
||||
let ident = self.lower_ident(*ident);
|
||||
@@ -328,7 +328,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
||||
|this| this.lower_variant_data(hir_id, struct_def),
|
||||
);
|
||||
hir::ItemKind::Struct(ident, struct_def, generics)
|
||||
hir::ItemKind::Struct(ident, generics, struct_def)
|
||||
}
|
||||
ItemKind::Union(ident, generics, vdata) => {
|
||||
let ident = self.lower_ident(*ident);
|
||||
@@ -338,7 +338,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
||||
|this| this.lower_variant_data(hir_id, vdata),
|
||||
);
|
||||
hir::ItemKind::Union(ident, vdata, generics)
|
||||
hir::ItemKind::Union(ident, generics, vdata)
|
||||
}
|
||||
ItemKind::Impl(box Impl {
|
||||
safety,
|
||||
@@ -467,8 +467,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
ItemKind::Delegation(box delegation) => {
|
||||
let delegation_results = self.lower_delegation(delegation, id, false);
|
||||
hir::ItemKind::Fn {
|
||||
ident: delegation_results.ident,
|
||||
sig: delegation_results.sig,
|
||||
ident: delegation_results.ident,
|
||||
generics: delegation_results.generics,
|
||||
body: delegation_results.body_id,
|
||||
has_body: true,
|
||||
|
||||
@@ -40,9 +40,7 @@ use rustc_middle::ty::{
|
||||
self, ParamEnv, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypingMode, fold_regions,
|
||||
};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_mir_dataflow::impls::{
|
||||
EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
|
||||
};
|
||||
use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
|
||||
use rustc_mir_dataflow::move_paths::{
|
||||
InitIndex, InitLocation, LookupResult, MoveData, MovePathIndex,
|
||||
};
|
||||
@@ -324,10 +322,6 @@ fn do_mir_borrowck<'tcx>(
|
||||
|
||||
let move_data = MoveData::gather_moves(body, tcx, |_| true);
|
||||
|
||||
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
|
||||
.iterate_to_fixpoint(tcx, body, Some("borrowck"))
|
||||
.into_results_cursor(body);
|
||||
|
||||
let locals_are_invalidated_at_exit = tcx.hir_body_owner_kind(def).is_fn_or_closure();
|
||||
let borrow_set = BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &move_data);
|
||||
|
||||
@@ -346,7 +340,6 @@ fn do_mir_borrowck<'tcx>(
|
||||
body,
|
||||
&promoted,
|
||||
&location_table,
|
||||
flow_inits,
|
||||
&move_data,
|
||||
&borrow_set,
|
||||
consumer_options,
|
||||
|
||||
@@ -11,8 +11,6 @@ use rustc_middle::mir::pretty::{PrettyPrintMirOptions, dump_mir_with_options};
|
||||
use rustc_middle::mir::{Body, PassWhere, Promoted, create_dump_file, dump_enabled, dump_mir};
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_mir_dataflow::ResultsCursor;
|
||||
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
|
||||
use rustc_mir_dataflow::move_paths::MoveData;
|
||||
use rustc_mir_dataflow::points::DenseLocationMap;
|
||||
use rustc_session::config::MirIncludeSpans;
|
||||
@@ -75,14 +73,13 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
|
||||
/// Computes the (non-lexical) regions from the input MIR.
|
||||
///
|
||||
/// This may result in errors being reported.
|
||||
pub(crate) fn compute_regions<'a, 'tcx>(
|
||||
pub(crate) fn compute_regions<'tcx>(
|
||||
root_cx: &mut BorrowCheckRootCtxt<'tcx>,
|
||||
infcx: &BorrowckInferCtxt<'tcx>,
|
||||
universal_regions: UniversalRegions<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
promoted: &IndexSlice<Promoted, Body<'tcx>>,
|
||||
location_table: &PoloniusLocationTable,
|
||||
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
||||
move_data: &MoveData<'tcx>,
|
||||
borrow_set: &BorrowSet<'tcx>,
|
||||
consumer_options: Option<ConsumerOptions>,
|
||||
@@ -112,7 +109,6 @@ pub(crate) fn compute_regions<'a, 'tcx>(
|
||||
location_table,
|
||||
borrow_set,
|
||||
&mut polonius_facts,
|
||||
flow_inits,
|
||||
move_data,
|
||||
Rc::clone(&location_map),
|
||||
);
|
||||
|
||||
@@ -5,8 +5,6 @@ use rustc_middle::mir::{Body, Local, Location, SourceInfo};
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::relate::Relate;
|
||||
use rustc_middle::ty::{GenericArgsRef, Region, RegionVid, Ty, TyCtxt, TypeVisitable};
|
||||
use rustc_mir_dataflow::ResultsCursor;
|
||||
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
|
||||
use rustc_mir_dataflow::move_paths::MoveData;
|
||||
use rustc_mir_dataflow::points::DenseLocationMap;
|
||||
use tracing::debug;
|
||||
@@ -28,10 +26,9 @@ mod trace;
|
||||
///
|
||||
/// N.B., this computation requires normalization; therefore, it must be
|
||||
/// performed before
|
||||
pub(super) fn generate<'a, 'tcx>(
|
||||
pub(super) fn generate<'tcx>(
|
||||
typeck: &mut TypeChecker<'_, 'tcx>,
|
||||
location_map: &DenseLocationMap,
|
||||
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
||||
move_data: &MoveData<'tcx>,
|
||||
) {
|
||||
debug!("liveness::generate");
|
||||
@@ -58,7 +55,7 @@ pub(super) fn generate<'a, 'tcx>(
|
||||
let (relevant_live_locals, boring_locals) =
|
||||
compute_relevant_live_locals(typeck.tcx(), &free_regions, typeck.body);
|
||||
|
||||
trace::trace(typeck, location_map, flow_inits, move_data, relevant_live_locals, boring_locals);
|
||||
trace::trace(typeck, location_map, move_data, relevant_live_locals, boring_locals);
|
||||
|
||||
// Mark regions that should be live where they appear within rvalues or within a call: like
|
||||
// args, regions, and types.
|
||||
|
||||
@@ -7,10 +7,10 @@ use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, HasLocalDecls, Loc
|
||||
use rustc_middle::traits::query::DropckOutlivesResult;
|
||||
use rustc_middle::ty::relate::Relate;
|
||||
use rustc_middle::ty::{Ty, TyCtxt, TypeVisitable, TypeVisitableExt};
|
||||
use rustc_mir_dataflow::ResultsCursor;
|
||||
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
|
||||
use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex};
|
||||
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
|
||||
use rustc_mir_dataflow::{Analysis, ResultsCursor};
|
||||
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
|
||||
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
|
||||
use rustc_trait_selection::traits::ObligationCtxt;
|
||||
@@ -37,10 +37,9 @@ use crate::type_check::{NormalizeLocation, TypeChecker};
|
||||
/// DROP-LIVE set are to the liveness sets for regions found in the
|
||||
/// `dropck_outlives` result of the variable's type (in particular,
|
||||
/// this respects `#[may_dangle]` annotations).
|
||||
pub(super) fn trace<'a, 'tcx>(
|
||||
pub(super) fn trace<'tcx>(
|
||||
typeck: &mut TypeChecker<'_, 'tcx>,
|
||||
location_map: &DenseLocationMap,
|
||||
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
||||
move_data: &MoveData<'tcx>,
|
||||
relevant_live_locals: Vec<Local>,
|
||||
boring_locals: Vec<Local>,
|
||||
@@ -48,7 +47,7 @@ pub(super) fn trace<'a, 'tcx>(
|
||||
let local_use_map = &LocalUseMap::build(&relevant_live_locals, location_map, typeck.body);
|
||||
let cx = LivenessContext {
|
||||
typeck,
|
||||
flow_inits,
|
||||
flow_inits: None,
|
||||
location_map,
|
||||
local_use_map,
|
||||
move_data,
|
||||
@@ -65,7 +64,7 @@ pub(super) fn trace<'a, 'tcx>(
|
||||
}
|
||||
|
||||
/// Contextual state for the type-liveness coroutine.
|
||||
struct LivenessContext<'a, 'typeck, 'b, 'tcx> {
|
||||
struct LivenessContext<'a, 'typeck, 'tcx> {
|
||||
/// Current type-checker, giving us our inference context etc.
|
||||
///
|
||||
/// This also stores the body we're currently analyzing.
|
||||
@@ -81,8 +80,8 @@ struct LivenessContext<'a, 'typeck, 'b, 'tcx> {
|
||||
drop_data: FxIndexMap<Ty<'tcx>, DropData<'tcx>>,
|
||||
|
||||
/// Results of dataflow tracking which variables (and paths) have been
|
||||
/// initialized.
|
||||
flow_inits: ResultsCursor<'b, 'tcx, MaybeInitializedPlaces<'b, 'tcx>>,
|
||||
/// initialized. Computed lazily when needed by drop-liveness.
|
||||
flow_inits: Option<ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>>,
|
||||
|
||||
/// Index indicating where each variable is assigned, used, or
|
||||
/// dropped.
|
||||
@@ -94,8 +93,8 @@ struct DropData<'tcx> {
|
||||
region_constraint_data: Option<&'tcx QueryRegionConstraints<'tcx>>,
|
||||
}
|
||||
|
||||
struct LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||
cx: LivenessContext<'a, 'typeck, 'b, 'tcx>,
|
||||
struct LivenessResults<'a, 'typeck, 'tcx> {
|
||||
cx: LivenessContext<'a, 'typeck, 'tcx>,
|
||||
|
||||
/// Set of points that define the current local.
|
||||
defs: DenseBitSet<PointIndex>,
|
||||
@@ -116,8 +115,8 @@ struct LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||
stack: Vec<PointIndex>,
|
||||
}
|
||||
|
||||
impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||
fn new(cx: LivenessContext<'a, 'typeck, 'b, 'tcx>) -> Self {
|
||||
impl<'a, 'typeck, 'tcx> LivenessResults<'a, 'typeck, 'tcx> {
|
||||
fn new(cx: LivenessContext<'a, 'typeck, 'tcx>) -> Self {
|
||||
let num_points = cx.location_map.num_points();
|
||||
LivenessResults {
|
||||
cx,
|
||||
@@ -459,20 +458,56 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
||||
impl<'a, 'typeck, 'tcx> LivenessContext<'a, 'typeck, 'tcx> {
|
||||
/// Computes the `MaybeInitializedPlaces` dataflow analysis if it hasn't been done already.
|
||||
///
|
||||
/// In practice, the results of this dataflow analysis are rarely needed but can be expensive to
|
||||
/// compute on big functions, so we compute them lazily as a fast path when:
|
||||
/// - there are relevant live locals
|
||||
/// - there are drop points for these relevant live locals.
|
||||
///
|
||||
/// This happens as part of the drop-liveness computation: it's the only place checking for
|
||||
/// maybe-initializedness of `MovePathIndex`es.
|
||||
fn flow_inits(&mut self) -> &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>> {
|
||||
self.flow_inits.get_or_insert_with(|| {
|
||||
let tcx = self.typeck.tcx();
|
||||
let body = self.typeck.body;
|
||||
// FIXME: reduce the `MaybeInitializedPlaces` domain to the useful `MovePath`s.
|
||||
//
|
||||
// This dataflow analysis computes maybe-initializedness of all move paths, which
|
||||
// explains why it can be expensive on big functions. But this data is only used in
|
||||
// drop-liveness. Therefore, most of the move paths computed here are ultimately unused,
|
||||
// even if the results are computed lazily and "no relevant live locals with drop
|
||||
// points" is the common case.
|
||||
//
|
||||
// So we only need the ones for 1) relevant live locals 2) that have drop points. That's
|
||||
// a much, much smaller domain: in our benchmarks, when it's not zero (the most likely
|
||||
// case), there are a few dozens compared to e.g. thousands or tens of thousands of
|
||||
// locals and move paths.
|
||||
let flow_inits = MaybeInitializedPlaces::new(tcx, body, self.move_data)
|
||||
.iterate_to_fixpoint(tcx, body, Some("borrowck"))
|
||||
.into_results_cursor(body);
|
||||
flow_inits
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> LivenessContext<'_, '_, 'tcx> {
|
||||
fn body(&self) -> &Body<'tcx> {
|
||||
self.typeck.body
|
||||
}
|
||||
|
||||
/// Returns `true` if the local variable (or some part of it) is initialized at the current
|
||||
/// cursor position. Callers should call one of the `seek` methods immediately before to point
|
||||
/// the cursor to the desired location.
|
||||
fn initialized_at_curr_loc(&self, mpi: MovePathIndex) -> bool {
|
||||
let state = self.flow_inits.get();
|
||||
fn initialized_at_curr_loc(&mut self, mpi: MovePathIndex) -> bool {
|
||||
let flow_inits = self.flow_inits();
|
||||
let state = flow_inits.get();
|
||||
if state.contains(mpi) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let move_paths = &self.flow_inits.analysis().move_data().move_paths;
|
||||
let move_paths = &flow_inits.analysis().move_data().move_paths;
|
||||
move_paths[mpi].find_descendant(move_paths, |mpi| state.contains(mpi)).is_some()
|
||||
}
|
||||
|
||||
@@ -481,7 +516,8 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
||||
/// DROP of some local variable will have an effect -- note that
|
||||
/// drops, as they may unwind, are always terminators.
|
||||
fn initialized_at_terminator(&mut self, block: BasicBlock, mpi: MovePathIndex) -> bool {
|
||||
self.flow_inits.seek_before_primary_effect(self.body().terminator_loc(block));
|
||||
let terminator_location = self.body().terminator_loc(block);
|
||||
self.flow_inits().seek_before_primary_effect(terminator_location);
|
||||
self.initialized_at_curr_loc(mpi)
|
||||
}
|
||||
|
||||
@@ -491,7 +527,8 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
||||
/// **Warning:** Does not account for the result of `Call`
|
||||
/// instructions.
|
||||
fn initialized_at_exit(&mut self, block: BasicBlock, mpi: MovePathIndex) -> bool {
|
||||
self.flow_inits.seek_after_primary_effect(self.body().terminator_loc(block));
|
||||
let terminator_location = self.body().terminator_loc(block);
|
||||
self.flow_inits().seek_after_primary_effect(terminator_location);
|
||||
self.initialized_at_curr_loc(mpi)
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,6 @@ use rustc_middle::ty::{
|
||||
TypeVisitableExt, UserArgs, UserTypeAnnotationIndex, fold_regions,
|
||||
};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_mir_dataflow::ResultsCursor;
|
||||
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
|
||||
use rustc_mir_dataflow::move_paths::MoveData;
|
||||
use rustc_mir_dataflow::points::DenseLocationMap;
|
||||
use rustc_span::def_id::CRATE_DEF_ID;
|
||||
@@ -97,10 +95,9 @@ mod relate_tys;
|
||||
/// - `location_table` -- for datalog polonius, the map between `Location`s and `RichLocation`s
|
||||
/// - `borrow_set` -- information about borrows occurring in `body`
|
||||
/// - `polonius_facts` -- when using Polonius, this is the generated set of Polonius facts
|
||||
/// - `flow_inits` -- results of a maybe-init dataflow analysis
|
||||
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
|
||||
/// - `location_map` -- map between MIR `Location` and `PointIndex`
|
||||
pub(crate) fn type_check<'a, 'tcx>(
|
||||
pub(crate) fn type_check<'tcx>(
|
||||
root_cx: &mut BorrowCheckRootCtxt<'tcx>,
|
||||
infcx: &BorrowckInferCtxt<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
@@ -109,7 +106,6 @@ pub(crate) fn type_check<'a, 'tcx>(
|
||||
location_table: &PoloniusLocationTable,
|
||||
borrow_set: &BorrowSet<'tcx>,
|
||||
polonius_facts: &mut Option<PoloniusFacts>,
|
||||
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
||||
move_data: &MoveData<'tcx>,
|
||||
location_map: Rc<DenseLocationMap>,
|
||||
) -> MirTypeckResults<'tcx> {
|
||||
@@ -167,7 +163,7 @@ pub(crate) fn type_check<'a, 'tcx>(
|
||||
typeck.equate_inputs_and_outputs(&normalized_inputs_and_output);
|
||||
typeck.check_signature_annotation();
|
||||
|
||||
liveness::generate(&mut typeck, &location_map, flow_inits, move_data);
|
||||
liveness::generate(&mut typeck, &location_map, move_data);
|
||||
|
||||
let opaque_type_values =
|
||||
opaque_types::take_opaques_and_register_member_constraints(&mut typeck);
|
||||
|
||||
@@ -518,6 +518,103 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||
sym::fabsf64 => self.float_abs_intrinsic::<Double>(args, dest)?,
|
||||
sym::fabsf128 => self.float_abs_intrinsic::<Quad>(args, dest)?,
|
||||
|
||||
sym::floorf16 => self.float_round_intrinsic::<Half>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::TowardNegative,
|
||||
)?,
|
||||
sym::floorf32 => self.float_round_intrinsic::<Single>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::TowardNegative,
|
||||
)?,
|
||||
sym::floorf64 => self.float_round_intrinsic::<Double>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::TowardNegative,
|
||||
)?,
|
||||
sym::floorf128 => self.float_round_intrinsic::<Quad>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::TowardNegative,
|
||||
)?,
|
||||
|
||||
sym::ceilf16 => self.float_round_intrinsic::<Half>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::TowardPositive,
|
||||
)?,
|
||||
sym::ceilf32 => self.float_round_intrinsic::<Single>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::TowardPositive,
|
||||
)?,
|
||||
sym::ceilf64 => self.float_round_intrinsic::<Double>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::TowardPositive,
|
||||
)?,
|
||||
sym::ceilf128 => self.float_round_intrinsic::<Quad>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::TowardPositive,
|
||||
)?,
|
||||
|
||||
sym::truncf16 => {
|
||||
self.float_round_intrinsic::<Half>(args, dest, rustc_apfloat::Round::TowardZero)?
|
||||
}
|
||||
sym::truncf32 => {
|
||||
self.float_round_intrinsic::<Single>(args, dest, rustc_apfloat::Round::TowardZero)?
|
||||
}
|
||||
sym::truncf64 => {
|
||||
self.float_round_intrinsic::<Double>(args, dest, rustc_apfloat::Round::TowardZero)?
|
||||
}
|
||||
sym::truncf128 => {
|
||||
self.float_round_intrinsic::<Quad>(args, dest, rustc_apfloat::Round::TowardZero)?
|
||||
}
|
||||
|
||||
sym::roundf16 => self.float_round_intrinsic::<Half>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::NearestTiesToAway,
|
||||
)?,
|
||||
sym::roundf32 => self.float_round_intrinsic::<Single>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::NearestTiesToAway,
|
||||
)?,
|
||||
sym::roundf64 => self.float_round_intrinsic::<Double>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::NearestTiesToAway,
|
||||
)?,
|
||||
sym::roundf128 => self.float_round_intrinsic::<Quad>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::NearestTiesToAway,
|
||||
)?,
|
||||
|
||||
sym::round_ties_even_f16 => self.float_round_intrinsic::<Half>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::NearestTiesToEven,
|
||||
)?,
|
||||
sym::round_ties_even_f32 => self.float_round_intrinsic::<Single>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::NearestTiesToEven,
|
||||
)?,
|
||||
sym::round_ties_even_f64 => self.float_round_intrinsic::<Double>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::NearestTiesToEven,
|
||||
)?,
|
||||
sym::round_ties_even_f128 => self.float_round_intrinsic::<Quad>(
|
||||
args,
|
||||
dest,
|
||||
rustc_apfloat::Round::NearestTiesToEven,
|
||||
)?,
|
||||
|
||||
// Unsupported intrinsic: skip the return_to_block below.
|
||||
_ => return interp_ok(false),
|
||||
}
|
||||
@@ -900,4 +997,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||
self.write_scalar(x.abs(), dest)?;
|
||||
interp_ok(())
|
||||
}
|
||||
|
||||
fn float_round_intrinsic<F>(
|
||||
&mut self,
|
||||
args: &[OpTy<'tcx, M::Provenance>],
|
||||
dest: &PlaceTy<'tcx, M::Provenance>,
|
||||
mode: rustc_apfloat::Round,
|
||||
) -> InterpResult<'tcx, ()>
|
||||
where
|
||||
F: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F> + Into<Scalar<M::Provenance>>,
|
||||
{
|
||||
let x: F = self.read_scalar(&args[0])?.to_float()?;
|
||||
let res = x.round_to_integral(mode).value;
|
||||
let res = self.adjust_nan(res, &[x]);
|
||||
self.write_scalar(res, dest)?;
|
||||
interp_ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#![feature(decl_macro)]
|
||||
#![feature(panic_backtrace_config)]
|
||||
#![feature(panic_update_hook)]
|
||||
#![feature(result_flattening)]
|
||||
#![feature(rustdoc_internals)]
|
||||
#![feature(try_blocks)]
|
||||
// tidy-alphabetical-end
|
||||
|
||||
@@ -4106,11 +4106,11 @@ impl<'hir> Item<'hir> {
|
||||
|
||||
expect_use, (&'hir UsePath<'hir>, UseKind), ItemKind::Use(p, uk), (p, *uk);
|
||||
|
||||
expect_static, (Ident, &'hir Ty<'hir>, Mutability, BodyId),
|
||||
ItemKind::Static(ident, ty, mutbl, body), (*ident, ty, *mutbl, *body);
|
||||
expect_static, (Mutability, Ident, &'hir Ty<'hir>, BodyId),
|
||||
ItemKind::Static(mutbl, ident, ty, body), (*mutbl, *ident, ty, *body);
|
||||
|
||||
expect_const, (Ident, &'hir Ty<'hir>, &'hir Generics<'hir>, BodyId),
|
||||
ItemKind::Const(ident, ty, generics, body), (*ident, ty, generics, *body);
|
||||
expect_const, (Ident, &'hir Generics<'hir>, &'hir Ty<'hir>, BodyId),
|
||||
ItemKind::Const(ident, generics, ty, body), (*ident, generics, ty, *body);
|
||||
|
||||
expect_fn, (Ident, &FnSig<'hir>, &'hir Generics<'hir>, BodyId),
|
||||
ItemKind::Fn { ident, sig, generics, body, .. }, (*ident, sig, generics, *body);
|
||||
@@ -4125,17 +4125,17 @@ impl<'hir> Item<'hir> {
|
||||
|
||||
expect_global_asm, &'hir InlineAsm<'hir>, ItemKind::GlobalAsm { asm, .. }, asm;
|
||||
|
||||
expect_ty_alias, (Ident, &'hir Ty<'hir>, &'hir Generics<'hir>),
|
||||
ItemKind::TyAlias(ident, ty, generics), (*ident, ty, generics);
|
||||
expect_ty_alias, (Ident, &'hir Generics<'hir>, &'hir Ty<'hir>),
|
||||
ItemKind::TyAlias(ident, generics, ty), (*ident, generics, ty);
|
||||
|
||||
expect_enum, (Ident, &EnumDef<'hir>, &'hir Generics<'hir>),
|
||||
ItemKind::Enum(ident, def, generics), (*ident, def, generics);
|
||||
expect_enum, (Ident, &'hir Generics<'hir>, &EnumDef<'hir>),
|
||||
ItemKind::Enum(ident, generics, def), (*ident, generics, def);
|
||||
|
||||
expect_struct, (Ident, &VariantData<'hir>, &'hir Generics<'hir>),
|
||||
ItemKind::Struct(ident, data, generics), (*ident, data, generics);
|
||||
expect_struct, (Ident, &'hir Generics<'hir>, &VariantData<'hir>),
|
||||
ItemKind::Struct(ident, generics, data), (*ident, generics, data);
|
||||
|
||||
expect_union, (Ident, &VariantData<'hir>, &'hir Generics<'hir>),
|
||||
ItemKind::Union(ident, data, generics), (*ident, data, generics);
|
||||
expect_union, (Ident, &'hir Generics<'hir>, &VariantData<'hir>),
|
||||
ItemKind::Union(ident, generics, data), (*ident, generics, data);
|
||||
|
||||
expect_trait,
|
||||
(
|
||||
@@ -4278,13 +4278,13 @@ pub enum ItemKind<'hir> {
|
||||
Use(&'hir UsePath<'hir>, UseKind),
|
||||
|
||||
/// A `static` item.
|
||||
Static(Ident, &'hir Ty<'hir>, Mutability, BodyId),
|
||||
Static(Mutability, Ident, &'hir Ty<'hir>, BodyId),
|
||||
/// A `const` item.
|
||||
Const(Ident, &'hir Ty<'hir>, &'hir Generics<'hir>, BodyId),
|
||||
Const(Ident, &'hir Generics<'hir>, &'hir Ty<'hir>, BodyId),
|
||||
/// A function declaration.
|
||||
Fn {
|
||||
ident: Ident,
|
||||
sig: FnSig<'hir>,
|
||||
ident: Ident,
|
||||
generics: &'hir Generics<'hir>,
|
||||
body: BodyId,
|
||||
/// Whether this function actually has a body.
|
||||
@@ -4309,13 +4309,13 @@ pub enum ItemKind<'hir> {
|
||||
fake_body: BodyId,
|
||||
},
|
||||
/// A type alias, e.g., `type Foo = Bar<u8>`.
|
||||
TyAlias(Ident, &'hir Ty<'hir>, &'hir Generics<'hir>),
|
||||
TyAlias(Ident, &'hir Generics<'hir>, &'hir Ty<'hir>),
|
||||
/// An enum definition, e.g., `enum Foo<A, B> { C<A>, D<B> }`.
|
||||
Enum(Ident, EnumDef<'hir>, &'hir Generics<'hir>),
|
||||
Enum(Ident, &'hir Generics<'hir>, EnumDef<'hir>),
|
||||
/// A struct definition, e.g., `struct Foo<A> {x: A}`.
|
||||
Struct(Ident, VariantData<'hir>, &'hir Generics<'hir>),
|
||||
Struct(Ident, &'hir Generics<'hir>, VariantData<'hir>),
|
||||
/// A union definition, e.g., `union Foo<A, B> {x: A, y: B}`.
|
||||
Union(Ident, VariantData<'hir>, &'hir Generics<'hir>),
|
||||
Union(Ident, &'hir Generics<'hir>, VariantData<'hir>),
|
||||
/// A trait definition.
|
||||
Trait(IsAuto, Safety, Ident, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
|
||||
/// A trait alias.
|
||||
@@ -4352,7 +4352,7 @@ impl ItemKind<'_> {
|
||||
match *self {
|
||||
ItemKind::ExternCrate(_, ident)
|
||||
| ItemKind::Use(_, UseKind::Single(ident))
|
||||
| ItemKind::Static(ident, ..)
|
||||
| ItemKind::Static(_, ident, ..)
|
||||
| ItemKind::Const(ident, ..)
|
||||
| ItemKind::Fn { ident, .. }
|
||||
| ItemKind::Macro(ident, ..)
|
||||
@@ -4374,11 +4374,11 @@ impl ItemKind<'_> {
|
||||
pub fn generics(&self) -> Option<&Generics<'_>> {
|
||||
Some(match self {
|
||||
ItemKind::Fn { generics, .. }
|
||||
| ItemKind::TyAlias(_, _, generics)
|
||||
| ItemKind::Const(_, _, generics, _)
|
||||
| ItemKind::Enum(_, _, generics)
|
||||
| ItemKind::Struct(_, _, generics)
|
||||
| ItemKind::Union(_, _, generics)
|
||||
| ItemKind::TyAlias(_, generics, _)
|
||||
| ItemKind::Const(_, generics, _, _)
|
||||
| ItemKind::Enum(_, generics, _)
|
||||
| ItemKind::Struct(_, generics, _)
|
||||
| ItemKind::Union(_, generics, _)
|
||||
| ItemKind::Trait(_, _, _, generics, _, _)
|
||||
| ItemKind::TraitAlias(_, generics, _)
|
||||
| ItemKind::Impl(Impl { generics, .. }) => generics,
|
||||
@@ -4802,9 +4802,9 @@ impl<'hir> Node<'hir> {
|
||||
pub fn ty(self) -> Option<&'hir Ty<'hir>> {
|
||||
match self {
|
||||
Node::Item(it) => match it.kind {
|
||||
ItemKind::TyAlias(_, ty, _)
|
||||
| ItemKind::Static(_, ty, _, _)
|
||||
| ItemKind::Const(_, ty, _, _) => Some(ty),
|
||||
ItemKind::TyAlias(_, _, ty)
|
||||
| ItemKind::Static(_, _, ty, _)
|
||||
| ItemKind::Const(_, _, ty, _) => Some(ty),
|
||||
ItemKind::Impl(impl_item) => Some(&impl_item.self_ty),
|
||||
_ => None,
|
||||
},
|
||||
@@ -4824,7 +4824,7 @@ impl<'hir> Node<'hir> {
|
||||
|
||||
pub fn alias_ty(self) -> Option<&'hir Ty<'hir>> {
|
||||
match self {
|
||||
Node::Item(Item { kind: ItemKind::TyAlias(_, ty, _), .. }) => Some(ty),
|
||||
Node::Item(Item { kind: ItemKind::TyAlias(_, _, ty), .. }) => Some(ty),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,15 +545,15 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
|
||||
UseKind::Glob | UseKind::ListStem => {}
|
||||
}
|
||||
}
|
||||
ItemKind::Static(ident, ref typ, _, body) => {
|
||||
ItemKind::Static(_, ident, ref typ, body) => {
|
||||
try_visit!(visitor.visit_ident(ident));
|
||||
try_visit!(visitor.visit_ty_unambig(typ));
|
||||
try_visit!(visitor.visit_nested_body(body));
|
||||
}
|
||||
ItemKind::Const(ident, ref typ, ref generics, body) => {
|
||||
ItemKind::Const(ident, ref generics, ref typ, body) => {
|
||||
try_visit!(visitor.visit_ident(ident));
|
||||
try_visit!(visitor.visit_ty_unambig(typ));
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
try_visit!(visitor.visit_ty_unambig(typ));
|
||||
try_visit!(visitor.visit_nested_body(body));
|
||||
}
|
||||
ItemKind::Fn { ident, sig, generics, body: body_id, .. } => {
|
||||
@@ -583,12 +583,12 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
|
||||
// typeck results set correctly.
|
||||
try_visit!(visitor.visit_nested_body(fake_body));
|
||||
}
|
||||
ItemKind::TyAlias(ident, ref ty, ref generics) => {
|
||||
ItemKind::TyAlias(ident, ref generics, ref ty) => {
|
||||
try_visit!(visitor.visit_ident(ident));
|
||||
try_visit!(visitor.visit_ty_unambig(ty));
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
try_visit!(visitor.visit_ty_unambig(ty));
|
||||
}
|
||||
ItemKind::Enum(ident, ref enum_definition, ref generics) => {
|
||||
ItemKind::Enum(ident, ref generics, ref enum_definition) => {
|
||||
try_visit!(visitor.visit_ident(ident));
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
try_visit!(visitor.visit_enum_def(enum_definition));
|
||||
@@ -609,8 +609,8 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
|
||||
try_visit!(visitor.visit_ty_unambig(self_ty));
|
||||
walk_list!(visitor, visit_impl_item_ref, *items);
|
||||
}
|
||||
ItemKind::Struct(ident, ref struct_definition, ref generics)
|
||||
| ItemKind::Union(ident, ref struct_definition, ref generics) => {
|
||||
ItemKind::Struct(ident, ref generics, ref struct_definition)
|
||||
| ItemKind::Union(ident, ref generics, ref struct_definition) => {
|
||||
try_visit!(visitor.visit_ident(ident));
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
try_visit!(visitor.visit_variant_data(struct_definition));
|
||||
|
||||
@@ -265,6 +265,7 @@ pub(crate) fn check_intrinsic_type(
|
||||
vec![Ty::new_imm_ptr(tcx, param(0)), tcx.types.isize],
|
||||
Ty::new_imm_ptr(tcx, param(0)),
|
||||
),
|
||||
sym::slice_get_unchecked => (3, 0, vec![param(1), tcx.types.usize], param(0)),
|
||||
sym::ptr_mask => (
|
||||
1,
|
||||
0,
|
||||
|
||||
@@ -297,32 +297,30 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
|
||||
hir::ItemKind::Fn { ident, sig, .. } => {
|
||||
check_item_fn(tcx, def_id, ident, item.span, sig.decl)
|
||||
}
|
||||
hir::ItemKind::Static(_, ty, ..) => {
|
||||
hir::ItemKind::Static(_, _, ty, _) => {
|
||||
check_static_item(tcx, def_id, ty.span, UnsizedHandling::Forbid)
|
||||
}
|
||||
hir::ItemKind::Const(_, ty, ..) => check_const_item(tcx, def_id, ty.span, item.span),
|
||||
hir::ItemKind::Struct(_, _, hir_generics) => {
|
||||
hir::ItemKind::Const(_, _, ty, _) => check_const_item(tcx, def_id, ty.span, item.span),
|
||||
hir::ItemKind::Struct(_, generics, _) => {
|
||||
let res = check_type_defn(tcx, item, false);
|
||||
check_variances_for_type_defn(tcx, item, hir_generics);
|
||||
check_variances_for_type_defn(tcx, item, generics);
|
||||
res
|
||||
}
|
||||
hir::ItemKind::Union(_, _, hir_generics) => {
|
||||
hir::ItemKind::Union(_, generics, _) => {
|
||||
let res = check_type_defn(tcx, item, true);
|
||||
check_variances_for_type_defn(tcx, item, hir_generics);
|
||||
check_variances_for_type_defn(tcx, item, generics);
|
||||
res
|
||||
}
|
||||
hir::ItemKind::Enum(_, _, hir_generics) => {
|
||||
hir::ItemKind::Enum(_, generics, _) => {
|
||||
let res = check_type_defn(tcx, item, true);
|
||||
check_variances_for_type_defn(tcx, item, hir_generics);
|
||||
check_variances_for_type_defn(tcx, item, generics);
|
||||
res
|
||||
}
|
||||
hir::ItemKind::Trait(..) => check_trait(tcx, item),
|
||||
hir::ItemKind::TraitAlias(..) => check_trait(tcx, item),
|
||||
// `ForeignItem`s are handled separately.
|
||||
hir::ItemKind::ForeignMod { .. } => Ok(()),
|
||||
hir::ItemKind::TyAlias(_, hir_ty, hir_generics)
|
||||
if tcx.type_alias_is_lazy(item.owner_id) =>
|
||||
{
|
||||
hir::ItemKind::TyAlias(_, generics, hir_ty) if tcx.type_alias_is_lazy(item.owner_id) => {
|
||||
let res = enter_wf_checking_ctxt(tcx, item.span, def_id, |wfcx| {
|
||||
let ty = tcx.type_of(def_id).instantiate_identity();
|
||||
let item_ty =
|
||||
@@ -335,7 +333,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
|
||||
check_where_clauses(wfcx, item.span, def_id);
|
||||
Ok(())
|
||||
});
|
||||
check_variances_for_type_defn(tcx, item, hir_generics);
|
||||
check_variances_for_type_defn(tcx, item, generics);
|
||||
res
|
||||
}
|
||||
_ => Ok(()),
|
||||
|
||||
@@ -248,13 +248,13 @@ fn reject_placeholder_type_signatures_in_item<'tcx>(
|
||||
item: &'tcx hir::Item<'tcx>,
|
||||
) {
|
||||
let (generics, suggest) = match &item.kind {
|
||||
hir::ItemKind::Union(_, _, generics)
|
||||
| hir::ItemKind::Enum(_, _, generics)
|
||||
hir::ItemKind::Union(_, generics, _)
|
||||
| hir::ItemKind::Enum(_, generics, _)
|
||||
| hir::ItemKind::TraitAlias(_, generics, _)
|
||||
| hir::ItemKind::Trait(_, _, _, generics, ..)
|
||||
| hir::ItemKind::Impl(hir::Impl { generics, .. })
|
||||
| hir::ItemKind::Struct(_, _, generics) => (generics, true),
|
||||
hir::ItemKind::TyAlias(_, _, generics) => (generics, false),
|
||||
| hir::ItemKind::Struct(_, generics, _) => (generics, true),
|
||||
hir::ItemKind::TyAlias(_, generics, _) => (generics, false),
|
||||
// `static`, `fn` and `const` are handled elsewhere to suggest appropriate type.
|
||||
_ => return,
|
||||
};
|
||||
@@ -470,9 +470,9 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
||||
.tcx
|
||||
.hir_expect_item(self.tcx.hir_get_parent_item(self.hir_id()).def_id);
|
||||
match &item.kind {
|
||||
hir::ItemKind::Enum(_, _, generics)
|
||||
| hir::ItemKind::Struct(_, _, generics)
|
||||
| hir::ItemKind::Union(_, _, generics) => {
|
||||
hir::ItemKind::Enum(_, generics, _)
|
||||
| hir::ItemKind::Struct(_, generics, _)
|
||||
| hir::ItemKind::Union(_, generics, _) => {
|
||||
let lt_name = get_new_lifetime_name(self.tcx, poly_trait_ref, generics);
|
||||
let (lt_sp, sugg) = match generics.params {
|
||||
[] => (generics.span, format!("<{lt_name}>")),
|
||||
@@ -740,7 +740,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
||||
tcx.at(it.span).explicit_super_predicates_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
}
|
||||
hir::ItemKind::Struct(_, struct_def, _) | hir::ItemKind::Union(_, struct_def, _) => {
|
||||
hir::ItemKind::Struct(_, _, struct_def) | hir::ItemKind::Union(_, _, struct_def) => {
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
@@ -762,7 +762,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
}
|
||||
|
||||
hir::ItemKind::Static(_, ty, ..) | hir::ItemKind::Const(_, ty, ..) => {
|
||||
hir::ItemKind::Static(_, _, ty, _) | hir::ItemKind::Const(_, _, ty, _) => {
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
@@ -1093,7 +1093,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
|
||||
|
||||
let repr = tcx.repr_options_of_def(def_id);
|
||||
let (kind, variants) = match &item.kind {
|
||||
ItemKind::Enum(_, def, _) => {
|
||||
ItemKind::Enum(_, _, def) => {
|
||||
let mut distance_from_explicit = 0;
|
||||
let variants = def
|
||||
.variants
|
||||
@@ -1121,7 +1121,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
|
||||
|
||||
(AdtKind::Enum, variants)
|
||||
}
|
||||
ItemKind::Struct(ident, def, _) | ItemKind::Union(ident, def, _) => {
|
||||
ItemKind::Struct(ident, _, def) | ItemKind::Union(ident, _, def) => {
|
||||
let adt_kind = match item.kind {
|
||||
ItemKind::Struct(..) => AdtKind::Struct,
|
||||
_ => AdtKind::Union,
|
||||
|
||||
@@ -634,11 +634,11 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
||||
// These sorts of items have no lifetime parameters at all.
|
||||
intravisit::walk_item(self, item);
|
||||
}
|
||||
hir::ItemKind::TyAlias(_, _, generics)
|
||||
| hir::ItemKind::Const(_, _, generics, _)
|
||||
| hir::ItemKind::Enum(_, _, generics)
|
||||
| hir::ItemKind::Struct(_, _, generics)
|
||||
| hir::ItemKind::Union(_, _, generics)
|
||||
hir::ItemKind::TyAlias(_, generics, _)
|
||||
| hir::ItemKind::Const(_, generics, _, _)
|
||||
| hir::ItemKind::Enum(_, generics, _)
|
||||
| hir::ItemKind::Struct(_, generics, _)
|
||||
| hir::ItemKind::Union(_, generics, _)
|
||||
| hir::ItemKind::Trait(_, _, _, generics, ..)
|
||||
| hir::ItemKind::TraitAlias(_, generics, ..)
|
||||
| hir::ItemKind::Impl(&hir::Impl { generics, .. }) => {
|
||||
|
||||
@@ -206,7 +206,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
|
||||
},
|
||||
|
||||
Node::Item(item) => match item.kind {
|
||||
ItemKind::Static(ident, ty, .., body_id) => {
|
||||
ItemKind::Static(_, ident, ty, body_id) => {
|
||||
if ty.is_suggestable_infer_ty() {
|
||||
infer_placeholder_type(
|
||||
icx.lowerer(),
|
||||
@@ -220,7 +220,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
|
||||
icx.lower_ty(ty)
|
||||
}
|
||||
}
|
||||
ItemKind::Const(ident, ty, _, body_id) => {
|
||||
ItemKind::Const(ident, _, ty, body_id) => {
|
||||
if ty.is_suggestable_infer_ty() {
|
||||
infer_placeholder_type(
|
||||
icx.lowerer(),
|
||||
@@ -234,7 +234,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
|
||||
icx.lower_ty(ty)
|
||||
}
|
||||
}
|
||||
ItemKind::TyAlias(_, self_ty, _) => icx.lower_ty(self_ty),
|
||||
ItemKind::TyAlias(_, _, self_ty) => icx.lower_ty(self_ty),
|
||||
ItemKind::Impl(hir::Impl { self_ty, .. }) => match self_ty.find_self_aliases() {
|
||||
spans if spans.len() > 0 => {
|
||||
let guar = tcx
|
||||
@@ -532,5 +532,5 @@ pub(crate) fn type_alias_is_lazy<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) ->
|
||||
}
|
||||
}
|
||||
}
|
||||
HasTait.visit_ty_unambig(tcx.hir_expect_item(def_id).expect_ty_alias().1).is_break()
|
||||
HasTait.visit_ty_unambig(tcx.hir_expect_item(def_id).expect_ty_alias().2).is_break()
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||
|
||||
let generics = match tcx.hir_node_by_def_id(parent_item) {
|
||||
hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Struct(_, variant, generics),
|
||||
kind: hir::ItemKind::Struct(_, generics, variant),
|
||||
..
|
||||
}) => {
|
||||
if !variant.fields().iter().any(|field| field.hir_id == parent_hir_id) {
|
||||
@@ -149,7 +149,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||
}
|
||||
generics
|
||||
}
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Enum(_, def, generics), .. }) => {
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Enum(_, generics, def), .. }) => {
|
||||
if !def
|
||||
.variants
|
||||
.iter()
|
||||
@@ -269,7 +269,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||
hir::Node::Field(field) => {
|
||||
// Enums can't have unsized fields, fields can only have an unsized tail field.
|
||||
if let hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Struct(_, variant, _), ..
|
||||
kind: hir::ItemKind::Struct(_, _, variant), ..
|
||||
}) = tcx.parent_hir_node(field.hir_id)
|
||||
&& variant
|
||||
.fields()
|
||||
|
||||
@@ -145,9 +145,9 @@ fn diagnostic_hir_wf_check<'tcx>(
|
||||
ref item => bug!("Unexpected TraitItem {:?}", item),
|
||||
},
|
||||
hir::Node::Item(item) => match item.kind {
|
||||
hir::ItemKind::TyAlias(_, ty, _)
|
||||
| hir::ItemKind::Static(_, ty, _, _)
|
||||
| hir::ItemKind::Const(_, ty, _, _) => vec![ty],
|
||||
hir::ItemKind::TyAlias(_, _, ty)
|
||||
| hir::ItemKind::Static(_, _, ty, _)
|
||||
| hir::ItemKind::Const(_, _, ty, _) => vec![ty],
|
||||
hir::ItemKind::Impl(impl_) => match &impl_.of_trait {
|
||||
Some(t) => t
|
||||
.path
|
||||
|
||||
@@ -477,10 +477,10 @@ impl<'a> State<'a> {
|
||||
hir::ForeignItemKind::Fn(sig, arg_idents, generics) => {
|
||||
let (cb, ib) = self.head("");
|
||||
self.print_fn(
|
||||
sig.decl,
|
||||
sig.header,
|
||||
Some(item.ident.name),
|
||||
generics,
|
||||
sig.decl,
|
||||
arg_idents,
|
||||
None,
|
||||
);
|
||||
@@ -593,7 +593,7 @@ impl<'a> State<'a> {
|
||||
self.end(ib);
|
||||
self.end(cb);
|
||||
}
|
||||
hir::ItemKind::Static(ident, ty, m, expr) => {
|
||||
hir::ItemKind::Static(m, ident, ty, expr) => {
|
||||
let (cb, ib) = self.head("static");
|
||||
if m.is_mut() {
|
||||
self.word_space("mut");
|
||||
@@ -609,7 +609,7 @@ impl<'a> State<'a> {
|
||||
self.word(";");
|
||||
self.end(cb);
|
||||
}
|
||||
hir::ItemKind::Const(ident, ty, generics, expr) => {
|
||||
hir::ItemKind::Const(ident, generics, ty, expr) => {
|
||||
let (cb, ib) = self.head("const");
|
||||
self.print_ident(ident);
|
||||
self.print_generic_params(generics.params);
|
||||
@@ -626,7 +626,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
hir::ItemKind::Fn { ident, sig, generics, body, .. } => {
|
||||
let (cb, ib) = self.head("");
|
||||
self.print_fn(sig.decl, sig.header, Some(ident.name), generics, &[], Some(body));
|
||||
self.print_fn(sig.header, Some(ident.name), generics, sig.decl, &[], Some(body));
|
||||
self.word(" ");
|
||||
self.end(ib);
|
||||
self.end(cb);
|
||||
@@ -660,7 +660,7 @@ impl<'a> State<'a> {
|
||||
self.end(cb);
|
||||
self.end(ib);
|
||||
}
|
||||
hir::ItemKind::TyAlias(ident, ty, generics) => {
|
||||
hir::ItemKind::TyAlias(ident, generics, ty) => {
|
||||
let (cb, ib) = self.head("type");
|
||||
self.print_ident(ident);
|
||||
self.print_generic_params(generics.params);
|
||||
@@ -673,16 +673,16 @@ impl<'a> State<'a> {
|
||||
self.word(";");
|
||||
self.end(cb);
|
||||
}
|
||||
hir::ItemKind::Enum(ident, ref enum_definition, params) => {
|
||||
self.print_enum_def(enum_definition, params, ident.name, item.span);
|
||||
hir::ItemKind::Enum(ident, generics, ref enum_def) => {
|
||||
self.print_enum_def(ident.name, generics, enum_def, item.span);
|
||||
}
|
||||
hir::ItemKind::Struct(ident, ref struct_def, generics) => {
|
||||
hir::ItemKind::Struct(ident, generics, ref struct_def) => {
|
||||
let (cb, ib) = self.head("struct");
|
||||
self.print_struct(struct_def, generics, ident.name, item.span, true, cb, ib);
|
||||
self.print_struct(ident.name, generics, struct_def, item.span, true, cb, ib);
|
||||
}
|
||||
hir::ItemKind::Union(ident, ref struct_def, generics) => {
|
||||
hir::ItemKind::Union(ident, generics, ref struct_def) => {
|
||||
let (cb, ib) = self.head("union");
|
||||
self.print_struct(struct_def, generics, ident.name, item.span, true, cb, ib);
|
||||
self.print_struct(ident.name, generics, struct_def, item.span, true, cb, ib);
|
||||
}
|
||||
hir::ItemKind::Impl(&hir::Impl {
|
||||
constness,
|
||||
@@ -791,9 +791,9 @@ impl<'a> State<'a> {
|
||||
|
||||
fn print_enum_def(
|
||||
&mut self,
|
||||
enum_definition: &hir::EnumDef<'_>,
|
||||
generics: &hir::Generics<'_>,
|
||||
name: Symbol,
|
||||
generics: &hir::Generics<'_>,
|
||||
enum_def: &hir::EnumDef<'_>,
|
||||
span: rustc_span::Span,
|
||||
) {
|
||||
let (cb, ib) = self.head("enum");
|
||||
@@ -801,7 +801,7 @@ impl<'a> State<'a> {
|
||||
self.print_generic_params(generics.params);
|
||||
self.print_where_clause(generics);
|
||||
self.space();
|
||||
self.print_variants(enum_definition.variants, span, cb, ib);
|
||||
self.print_variants(enum_def.variants, span, cb, ib);
|
||||
}
|
||||
|
||||
fn print_variants(
|
||||
@@ -834,9 +834,9 @@ impl<'a> State<'a> {
|
||||
|
||||
fn print_struct(
|
||||
&mut self,
|
||||
struct_def: &hir::VariantData<'_>,
|
||||
generics: &hir::Generics<'_>,
|
||||
name: Symbol,
|
||||
generics: &hir::Generics<'_>,
|
||||
struct_def: &hir::VariantData<'_>,
|
||||
span: rustc_span::Span,
|
||||
print_finalizer: bool,
|
||||
cb: BoxMarker,
|
||||
@@ -886,7 +886,7 @@ impl<'a> State<'a> {
|
||||
pub fn print_variant(&mut self, v: &hir::Variant<'_>) {
|
||||
let (cb, ib) = self.head("");
|
||||
let generics = hir::Generics::empty();
|
||||
self.print_struct(&v.data, generics, v.ident.name, v.span, false, cb, ib);
|
||||
self.print_struct(v.ident.name, generics, &v.data, v.span, false, cb, ib);
|
||||
if let Some(ref d) = v.disr_expr {
|
||||
self.space();
|
||||
self.word_space("=");
|
||||
@@ -902,7 +902,7 @@ impl<'a> State<'a> {
|
||||
arg_idents: &[Option<Ident>],
|
||||
body_id: Option<hir::BodyId>,
|
||||
) {
|
||||
self.print_fn(m.decl, m.header, Some(ident.name), generics, arg_idents, body_id);
|
||||
self.print_fn(m.header, Some(ident.name), generics, m.decl, arg_idents, body_id);
|
||||
}
|
||||
|
||||
fn print_trait_item(&mut self, ti: &hir::TraitItem<'_>) {
|
||||
@@ -2141,10 +2141,10 @@ impl<'a> State<'a> {
|
||||
|
||||
fn print_fn(
|
||||
&mut self,
|
||||
decl: &hir::FnDecl<'_>,
|
||||
header: hir::FnHeader,
|
||||
name: Option<Symbol>,
|
||||
generics: &hir::Generics<'_>,
|
||||
decl: &hir::FnDecl<'_>,
|
||||
arg_idents: &[Option<Ident>],
|
||||
body_id: Option<hir::BodyId>,
|
||||
) {
|
||||
@@ -2483,7 +2483,6 @@ impl<'a> State<'a> {
|
||||
self.print_formal_generic_params(generic_params);
|
||||
let generics = hir::Generics::empty();
|
||||
self.print_fn(
|
||||
decl,
|
||||
hir::FnHeader {
|
||||
safety: safety.into(),
|
||||
abi,
|
||||
@@ -2492,6 +2491,7 @@ impl<'a> State<'a> {
|
||||
},
|
||||
name,
|
||||
generics,
|
||||
decl,
|
||||
arg_idents,
|
||||
None,
|
||||
);
|
||||
|
||||
@@ -408,6 +408,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||
self.expr_ty,
|
||||
fcx.ty_to_string(self.cast_ty)
|
||||
);
|
||||
|
||||
if let Ok(snippet) = fcx.tcx.sess.source_map().span_to_snippet(self.expr_span)
|
||||
&& matches!(self.expr.kind, ExprKind::AddrOf(..))
|
||||
{
|
||||
err.note(format!(
|
||||
"casting reference expression `{}` because `&` binds tighter than `as`",
|
||||
snippet
|
||||
));
|
||||
}
|
||||
|
||||
let mut sugg = None;
|
||||
let mut sugg_mutref = false;
|
||||
if let ty::Ref(reg, cast_ty, mutbl) = *self.cast_ty.kind() {
|
||||
|
||||
@@ -722,8 +722,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
)) => {
|
||||
if let Some(hir::Node::Item(hir::Item {
|
||||
kind:
|
||||
hir::ItemKind::Static(ident, ty, ..)
|
||||
| hir::ItemKind::Const(ident, ty, ..),
|
||||
hir::ItemKind::Static(_, ident, ty, _)
|
||||
| hir::ItemKind::Const(ident, _, ty, _),
|
||||
..
|
||||
})) = self.tcx.hir_get_if_local(*def_id)
|
||||
{
|
||||
|
||||
@@ -2713,6 +2713,31 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
));
|
||||
}
|
||||
|
||||
// Don't try to suggest ref/deref on an `if` expression, because:
|
||||
// - The `if` could be part of a desugared `if else` statement,
|
||||
// which would create impossible suggestions such as `if ... { ... } else &if { ... } else { ... }`.
|
||||
// - In general the suggestions it creates such as `&if ... { ... } else { ... }` are not very helpful.
|
||||
// We try to generate a suggestion such as `if ... { &... } else { &... }` instead.
|
||||
if let hir::ExprKind::If(_c, then, els) = expr.kind {
|
||||
// The `then` of a `Expr::If` always contains a block, and that block may have a final expression that we can borrow
|
||||
// If the block does not have a final expression, it will return () and we do not make a suggestion to borrow that.
|
||||
let ExprKind::Block(then, _) = then.kind else { return None };
|
||||
let Some(then) = then.expr else { return None };
|
||||
let (mut suggs, help, app, verbose, mutref) =
|
||||
self.suggest_deref_or_ref(then, checked_ty, expected)?;
|
||||
|
||||
// If there is no `else`, the return type of this `if` will be (), so suggesting to change the `then` block is useless
|
||||
let els_expr = match els?.kind {
|
||||
ExprKind::Block(block, _) => block.expr?,
|
||||
_ => els?,
|
||||
};
|
||||
let (else_suggs, ..) =
|
||||
self.suggest_deref_or_ref(els_expr, checked_ty, expected)?;
|
||||
suggs.extend(else_suggs);
|
||||
|
||||
return Some((suggs, help, app, verbose, mutref));
|
||||
}
|
||||
|
||||
if let Some((sugg, msg)) = self.can_use_as_ref(expr) {
|
||||
return Some((
|
||||
sugg,
|
||||
|
||||
@@ -545,22 +545,22 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
|
||||
return;
|
||||
}
|
||||
let (def, ty) = match item.kind {
|
||||
hir::ItemKind::Struct(_, _, ast_generics) => {
|
||||
if !ast_generics.params.is_empty() {
|
||||
hir::ItemKind::Struct(_, generics, _) => {
|
||||
if !generics.params.is_empty() {
|
||||
return;
|
||||
}
|
||||
let def = cx.tcx.adt_def(item.owner_id);
|
||||
(def, Ty::new_adt(cx.tcx, def, ty::List::empty()))
|
||||
}
|
||||
hir::ItemKind::Union(_, _, ast_generics) => {
|
||||
if !ast_generics.params.is_empty() {
|
||||
hir::ItemKind::Union(_, generics, _) => {
|
||||
if !generics.params.is_empty() {
|
||||
return;
|
||||
}
|
||||
let def = cx.tcx.adt_def(item.owner_id);
|
||||
(def, Ty::new_adt(cx.tcx, def, ty::List::empty()))
|
||||
}
|
||||
hir::ItemKind::Enum(_, _, ast_generics) => {
|
||||
if !ast_generics.params.is_empty() {
|
||||
hir::ItemKind::Enum(_, generics, _) => {
|
||||
if !generics.params.is_empty() {
|
||||
return;
|
||||
}
|
||||
let def = cx.tcx.adt_def(item.owner_id);
|
||||
@@ -1422,7 +1422,7 @@ impl TypeAliasBounds {
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
|
||||
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
|
||||
let hir::ItemKind::TyAlias(_, hir_ty, generics) = item.kind else { return };
|
||||
let hir::ItemKind::TyAlias(_, generics, hir_ty) = item.kind else { return };
|
||||
|
||||
// There must not be a where clause.
|
||||
if generics.predicates.is_empty() {
|
||||
@@ -2125,9 +2125,9 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
||||
use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
|
||||
|
||||
let def_id = item.owner_id.def_id;
|
||||
if let hir::ItemKind::Struct(_, _, hir_generics)
|
||||
| hir::ItemKind::Enum(_, _, hir_generics)
|
||||
| hir::ItemKind::Union(_, _, hir_generics) = item.kind
|
||||
if let hir::ItemKind::Struct(_, generics, _)
|
||||
| hir::ItemKind::Enum(_, generics, _)
|
||||
| hir::ItemKind::Union(_, generics, _) = item.kind
|
||||
{
|
||||
let inferred_outlives = cx.tcx.inferred_outlives_of(def_id);
|
||||
if inferred_outlives.is_empty() {
|
||||
@@ -2135,7 +2135,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
||||
}
|
||||
|
||||
let ty_generics = cx.tcx.generics_of(def_id);
|
||||
let num_where_predicates = hir_generics
|
||||
let num_where_predicates = generics
|
||||
.predicates
|
||||
.iter()
|
||||
.filter(|predicate| predicate.kind.in_where_clause())
|
||||
@@ -2145,7 +2145,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
||||
let mut lint_spans = Vec::new();
|
||||
let mut where_lint_spans = Vec::new();
|
||||
let mut dropped_where_predicate_count = 0;
|
||||
for (i, where_predicate) in hir_generics.predicates.iter().enumerate() {
|
||||
for (i, where_predicate) in generics.predicates.iter().enumerate() {
|
||||
let (relevant_lifetimes, bounds, predicate_span, in_where_clause) =
|
||||
match where_predicate.kind {
|
||||
hir::WherePredicateKind::RegionPredicate(predicate) => {
|
||||
@@ -2228,7 +2228,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
||||
} else if i + 1 < num_where_predicates {
|
||||
// If all the bounds on a predicate were inferable and there are
|
||||
// further predicates, we want to eat the trailing comma.
|
||||
let next_predicate_span = hir_generics.predicates[i + 1].span;
|
||||
let next_predicate_span = generics.predicates[i + 1].span;
|
||||
if next_predicate_span.from_expansion() {
|
||||
where_lint_spans.push(predicate_span);
|
||||
} else {
|
||||
@@ -2237,7 +2237,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
||||
}
|
||||
} else {
|
||||
// Eat the optional trailing comma after the last predicate.
|
||||
let where_span = hir_generics.where_clause_span;
|
||||
let where_span = generics.where_clause_span;
|
||||
if where_span.from_expansion() {
|
||||
where_lint_spans.push(predicate_span);
|
||||
} else {
|
||||
@@ -2255,18 +2255,18 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
||||
|
||||
// If all predicates in where clause are inferable, drop the entire clause
|
||||
// (including the `where`)
|
||||
if hir_generics.has_where_clause_predicates
|
||||
if generics.has_where_clause_predicates
|
||||
&& dropped_where_predicate_count == num_where_predicates
|
||||
{
|
||||
let where_span = hir_generics.where_clause_span;
|
||||
let where_span = generics.where_clause_span;
|
||||
// Extend the where clause back to the closing `>` of the
|
||||
// generics, except for tuple struct, which have the `where`
|
||||
// after the fields of the struct.
|
||||
let full_where_span =
|
||||
if let hir::ItemKind::Struct(_, hir::VariantData::Tuple(..), _) = item.kind {
|
||||
if let hir::ItemKind::Struct(_, _, hir::VariantData::Tuple(..)) = item.kind {
|
||||
where_span
|
||||
} else {
|
||||
hir_generics.span.shrink_to_hi().to(where_span)
|
||||
generics.span.shrink_to_hi().to(where_span)
|
||||
};
|
||||
|
||||
// Due to macro expansions, the `full_where_span` might not actually contain all
|
||||
|
||||
@@ -95,8 +95,8 @@ impl<'tcx> LateLintPass<'tcx> for DefaultCouldBeDerived {
|
||||
kind:
|
||||
hir::ItemKind::Struct(
|
||||
_,
|
||||
hir::VariantData::Struct { fields, recovered: _ },
|
||||
_generics,
|
||||
hir::VariantData::Struct { fields, recovered: _ },
|
||||
),
|
||||
..
|
||||
})) => fields.iter().map(|f| (f.ident.name, f)).collect::<FxHashMap<_, _>>(),
|
||||
|
||||
@@ -183,7 +183,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
|
||||
&& parent_opt_item_name != Some(kw::Underscore)
|
||||
&& let Some(parent) = parent.as_local()
|
||||
&& let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent)
|
||||
&& let ItemKind::Const(ident, ty, _, _) = item.kind
|
||||
&& let ItemKind::Const(ident, _, ty, _) = item.kind
|
||||
&& let TyKind::Tup(&[]) = ty.kind
|
||||
{
|
||||
Some(ident.span)
|
||||
|
||||
@@ -513,7 +513,7 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
|
||||
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
|
||||
let attrs = cx.tcx.hir_attrs(it.hir_id());
|
||||
match it.kind {
|
||||
hir::ItemKind::Static(ident, ..)
|
||||
hir::ItemKind::Static(_, ident, ..)
|
||||
if !ast::attr::contains_name(attrs, sym::no_mangle) =>
|
||||
{
|
||||
NonUpperCaseGlobals::check_upper_case(cx, "static variable", &ident);
|
||||
|
||||
@@ -1710,7 +1710,7 @@ impl ImproperCTypesDefinitions {
|
||||
&& cx.tcx.sess.target.os == "aix"
|
||||
&& !adt_def.all_fields().next().is_none()
|
||||
{
|
||||
let struct_variant_data = item.expect_struct().1;
|
||||
let struct_variant_data = item.expect_struct().2;
|
||||
for field_def in struct_variant_data.fields().iter().skip(1) {
|
||||
// Struct fields (after the first field) are checked for the
|
||||
// power alignment rule, as fields after the first are likely
|
||||
@@ -1735,9 +1735,9 @@ impl ImproperCTypesDefinitions {
|
||||
impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDefinitions {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
||||
match item.kind {
|
||||
hir::ItemKind::Static(_, ty, ..)
|
||||
| hir::ItemKind::Const(_, ty, ..)
|
||||
| hir::ItemKind::TyAlias(_, ty, ..) => {
|
||||
hir::ItemKind::Static(_, _, ty, _)
|
||||
| hir::ItemKind::Const(_, _, ty, _)
|
||||
| hir::ItemKind::TyAlias(_, _, ty) => {
|
||||
self.check_ty_maybe_containing_foreign_fnptr(
|
||||
cx,
|
||||
ty,
|
||||
@@ -1804,7 +1804,7 @@ declare_lint_pass!(VariantSizeDifferences => [VARIANT_SIZE_DIFFERENCES]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
|
||||
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
|
||||
if let hir::ItemKind::Enum(_, ref enum_definition, _) = it.kind {
|
||||
if let hir::ItemKind::Enum(_, _, ref enum_definition) = it.kind {
|
||||
let t = cx.tcx.type_of(it.owner_id).instantiate_identity();
|
||||
let ty = cx.tcx.erase_regions(t);
|
||||
let Ok(layout) = cx.layout_of(ty) else { return };
|
||||
|
||||
@@ -920,7 +920,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
}) => until_within(*outer_span, generics.where_clause_span),
|
||||
// Constants and Statics.
|
||||
Node::Item(Item {
|
||||
kind: ItemKind::Const(_, ty, ..) | ItemKind::Static(_, ty, ..),
|
||||
kind: ItemKind::Const(_, _, ty, _) | ItemKind::Static(_, _, ty, _),
|
||||
span: outer_span,
|
||||
..
|
||||
})
|
||||
|
||||
@@ -558,7 +558,7 @@ fn construct_const<'a, 'tcx>(
|
||||
// Figure out what primary body this item has.
|
||||
let (span, const_ty_span) = match tcx.hir_node(hir_id) {
|
||||
Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Static(_, ty, _, _) | hir::ItemKind::Const(_, ty, _, _),
|
||||
kind: hir::ItemKind::Static(_, _, ty, _) | hir::ItemKind::Const(_, _, ty, _),
|
||||
span,
|
||||
..
|
||||
})
|
||||
|
||||
@@ -262,6 +262,52 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
||||
});
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
sym::slice_get_unchecked => {
|
||||
let target = target.unwrap();
|
||||
let Ok([ptrish, index]) = take_array(args) else {
|
||||
span_bug!(
|
||||
terminator.source_info.span,
|
||||
"Wrong number of arguments for {intrinsic:?}",
|
||||
);
|
||||
};
|
||||
|
||||
let place = ptrish.node.place().unwrap();
|
||||
assert!(!place.is_indirect());
|
||||
let updated_place = place.project_deeper(
|
||||
&[
|
||||
ProjectionElem::Deref,
|
||||
ProjectionElem::Index(
|
||||
index.node.place().unwrap().as_local().unwrap(),
|
||||
),
|
||||
],
|
||||
tcx,
|
||||
);
|
||||
|
||||
let ret_ty = generic_args.type_at(0);
|
||||
let rvalue = match *ret_ty.kind() {
|
||||
ty::RawPtr(_, Mutability::Not) => {
|
||||
Rvalue::RawPtr(RawPtrKind::Const, updated_place)
|
||||
}
|
||||
ty::RawPtr(_, Mutability::Mut) => {
|
||||
Rvalue::RawPtr(RawPtrKind::Mut, updated_place)
|
||||
}
|
||||
ty::Ref(region, _, Mutability::Not) => {
|
||||
Rvalue::Ref(region, BorrowKind::Shared, updated_place)
|
||||
}
|
||||
ty::Ref(region, _, Mutability::Mut) => Rvalue::Ref(
|
||||
region,
|
||||
BorrowKind::Mut { kind: MutBorrowKind::Default },
|
||||
updated_place,
|
||||
),
|
||||
_ => bug!("Unknown return type {ret_ty:?}"),
|
||||
};
|
||||
|
||||
block.statements.push(Statement {
|
||||
source_info: terminator.source_info,
|
||||
kind: StatementKind::Assign(Box::new((*destination, rvalue))),
|
||||
});
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
sym::transmute | sym::transmute_unchecked => {
|
||||
let dst_ty = destination.ty(local_decls, tcx).ty;
|
||||
let Ok([arg]) = take_array(args) else {
|
||||
|
||||
@@ -802,7 +802,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||
match target {
|
||||
Target::Struct => {
|
||||
if let Some(ItemLike::Item(hir::Item {
|
||||
kind: hir::ItemKind::Struct(_, hir::VariantData::Struct { fields, .. }, _),
|
||||
kind: hir::ItemKind::Struct(_, _, hir::VariantData::Struct { fields, .. }),
|
||||
..
|
||||
})) = item
|
||||
&& !fields.is_empty()
|
||||
@@ -1130,12 +1130,12 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||
return;
|
||||
};
|
||||
match item.kind {
|
||||
ItemKind::Enum(_, _, generics) | ItemKind::Struct(_, _, generics)
|
||||
ItemKind::Enum(_, generics, _) | ItemKind::Struct(_, generics, _)
|
||||
if generics.params.len() != 0 => {}
|
||||
ItemKind::Trait(_, _, _, generics, _, items)
|
||||
if generics.params.len() != 0
|
||||
|| items.iter().any(|item| matches!(item.kind, AssocItemKind::Type)) => {}
|
||||
ItemKind::TyAlias(_, _, generics) if generics.params.len() != 0 => {}
|
||||
ItemKind::TyAlias(_, generics, _) if generics.params.len() != 0 => {}
|
||||
_ => {
|
||||
self.dcx().emit_err(errors::DocSearchUnboxInvalid { span: meta.span() });
|
||||
}
|
||||
@@ -2792,7 +2792,7 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
||||
}
|
||||
|
||||
fn is_c_like_enum(item: &Item<'_>) -> bool {
|
||||
if let ItemKind::Enum(_, ref def, _) = item.kind {
|
||||
if let ItemKind::Enum(_, _, ref def) = item.kind {
|
||||
for variant in def.variants {
|
||||
match variant.data {
|
||||
hir::VariantData::Unit(..) => { /* continue */ }
|
||||
|
||||
@@ -736,7 +736,7 @@ fn check_item<'tcx>(
|
||||
match tcx.def_kind(id.owner_id) {
|
||||
DefKind::Enum => {
|
||||
let item = tcx.hir_item(id);
|
||||
if let hir::ItemKind::Enum(_, ref enum_def, _) = item.kind {
|
||||
if let hir::ItemKind::Enum(_, _, ref enum_def) = item.kind {
|
||||
if let Some(comes_from_allow) = allow_dead_code {
|
||||
worklist.extend(
|
||||
enum_def.variants.iter().map(|variant| (variant.def_id, comes_from_allow)),
|
||||
@@ -783,7 +783,7 @@ fn check_item<'tcx>(
|
||||
}
|
||||
DefKind::Struct => {
|
||||
let item = tcx.hir_item(id);
|
||||
if let hir::ItemKind::Struct(_, ref variant_data, _) = item.kind
|
||||
if let hir::ItemKind::Struct(_, _, ref variant_data) = item.kind
|
||||
&& let Some(ctor_def_id) = variant_data.ctor_def_id()
|
||||
{
|
||||
struct_constructors.insert(ctor_def_id, item.owner_id.def_id);
|
||||
@@ -1055,7 +1055,7 @@ impl<'tcx> DeadVisitor<'tcx> {
|
||||
let tuple_fields = if let Some(parent_id) = parent_item
|
||||
&& let node = tcx.hir_node_by_def_id(parent_id)
|
||||
&& let hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Struct(_, hir::VariantData::Tuple(fields, _, _), _),
|
||||
kind: hir::ItemKind::Struct(_, _, hir::VariantData::Tuple(fields, _, _)),
|
||||
..
|
||||
}) = node
|
||||
{
|
||||
|
||||
@@ -430,7 +430,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
||||
kind = AnnotationKind::DeprecationProhibited;
|
||||
const_stab_inherit = InheritConstStability::Yes;
|
||||
}
|
||||
hir::ItemKind::Struct(_, ref sd, _) => {
|
||||
hir::ItemKind::Struct(_, _, ref sd) => {
|
||||
if let Some(ctor_def_id) = sd.ctor_def_id() {
|
||||
self.annotate(
|
||||
ctor_def_id,
|
||||
|
||||
@@ -599,8 +599,8 @@ impl<'tcx> EmbargoVisitor<'tcx> {
|
||||
DefKind::Struct | DefKind::Union => {
|
||||
// While structs and unions have type privacy, their fields do not.
|
||||
let item = self.tcx.hir_expect_item(def_id);
|
||||
if let hir::ItemKind::Struct(_, ref struct_def, _)
|
||||
| hir::ItemKind::Union(_, ref struct_def, _) = item.kind
|
||||
if let hir::ItemKind::Struct(_, _, ref struct_def)
|
||||
| hir::ItemKind::Union(_, _, ref struct_def) = item.kind
|
||||
{
|
||||
for field in struct_def.fields() {
|
||||
let field_vis = self.tcx.local_visibility(field.def_id);
|
||||
@@ -725,7 +725,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
hir::ItemKind::Enum(_, ref def, _) => {
|
||||
hir::ItemKind::Enum(_, _, ref def) => {
|
||||
if let Some(item_ev) = item_ev {
|
||||
self.reach(item.owner_id.def_id, item_ev).generics().predicates();
|
||||
}
|
||||
@@ -763,8 +763,8 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
hir::ItemKind::Struct(_, ref struct_def, _)
|
||||
| hir::ItemKind::Union(_, ref struct_def, _) => {
|
||||
hir::ItemKind::Struct(_, _, ref struct_def)
|
||||
| hir::ItemKind::Union(_, _, ref struct_def) => {
|
||||
if let Some(item_ev) = item_ev {
|
||||
self.reach(item.owner_id.def_id, item_ev).generics().predicates();
|
||||
for field in struct_def.fields() {
|
||||
@@ -868,7 +868,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TestReachabilityVisitor<'a, 'tcx> {
|
||||
self.effective_visibility_diagnostic(item.owner_id.def_id);
|
||||
|
||||
match item.kind {
|
||||
hir::ItemKind::Enum(_, ref def, _) => {
|
||||
hir::ItemKind::Enum(_, _, ref def) => {
|
||||
for variant in def.variants.iter() {
|
||||
self.effective_visibility_diagnostic(variant.def_id);
|
||||
if let Some(ctor_def_id) = variant.data.ctor_def_id() {
|
||||
@@ -879,7 +879,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TestReachabilityVisitor<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
hir::ItemKind::Struct(_, ref def, _) | hir::ItemKind::Union(_, ref def, _) => {
|
||||
hir::ItemKind::Struct(_, _, ref def) | hir::ItemKind::Union(_, _, ref def) => {
|
||||
if let Some(ctor_def_id) = def.ctor_def_id() {
|
||||
self.effective_visibility_diagnostic(ctor_def_id);
|
||||
}
|
||||
@@ -1651,7 +1651,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
|
||||
}
|
||||
DefKind::Enum => {
|
||||
let item = tcx.hir_item(id);
|
||||
if let hir::ItemKind::Enum(_, ref def, _) = item.kind {
|
||||
if let hir::ItemKind::Enum(_, _, ref def) = item.kind {
|
||||
self.check_unnameable(item.owner_id.def_id, effective_vis);
|
||||
|
||||
self.check(item.owner_id.def_id, item_visibility, effective_vis)
|
||||
@@ -1689,8 +1689,8 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
|
||||
// Subitems of structs and unions have their own publicity.
|
||||
DefKind::Struct | DefKind::Union => {
|
||||
let item = tcx.hir_item(id);
|
||||
if let hir::ItemKind::Struct(_, ref struct_def, _)
|
||||
| hir::ItemKind::Union(_, ref struct_def, _) = item.kind
|
||||
if let hir::ItemKind::Struct(_, _, ref struct_def)
|
||||
| hir::ItemKind::Union(_, _, ref struct_def) = item.kind
|
||||
{
|
||||
self.check_unnameable(item.owner_id.def_id, effective_vis);
|
||||
self.check(item.owner_id.def_id, item_visibility, effective_vis)
|
||||
|
||||
@@ -2000,6 +2000,7 @@ symbols! {
|
||||
slice,
|
||||
slice_from_raw_parts,
|
||||
slice_from_raw_parts_mut,
|
||||
slice_get_unchecked,
|
||||
slice_into_vec,
|
||||
slice_iter,
|
||||
slice_len_fn,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::spec::{Target, TargetMetadata, base};
|
||||
use crate::spec::{FramePointer, Target, TargetMetadata, base};
|
||||
|
||||
pub(crate) fn target() -> Target {
|
||||
let mut base = base::windows_gnullvm::opts();
|
||||
@@ -6,6 +6,12 @@ pub(crate) fn target() -> Target {
|
||||
base.features = "+v8a,+neon,+fp-armv8".into();
|
||||
base.linker = Some("aarch64-w64-mingw32-clang".into());
|
||||
|
||||
// Microsoft recommends enabling frame pointers on Arm64 Windows.
|
||||
// From https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#integer-registers
|
||||
// "The frame pointer (x29) is required for compatibility with fast stack walking used by ETW
|
||||
// and other services. It must point to the previous {x29, x30} pair on the stack."
|
||||
base.frame_pointer = FramePointer::NonLeaf;
|
||||
|
||||
Target {
|
||||
llvm_target: "aarch64-pc-windows-gnu".into(),
|
||||
metadata: TargetMetadata {
|
||||
|
||||
@@ -2026,7 +2026,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
}
|
||||
LetVisitor { span }.visit_body(body).break_value()
|
||||
}
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(_, ty, _, _), .. }) => {
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(_, _, ty, _), .. }) => {
|
||||
Some(&ty.peel_refs().kind)
|
||||
}
|
||||
_ => None,
|
||||
|
||||
@@ -351,14 +351,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
|
||||
hir::Node::Item(hir::Item {
|
||||
kind:
|
||||
hir::ItemKind::Struct(_, _, generics)
|
||||
| hir::ItemKind::Enum(_, _, generics)
|
||||
| hir::ItemKind::Union(_, _, generics)
|
||||
hir::ItemKind::Struct(_, generics, _)
|
||||
| hir::ItemKind::Enum(_, generics, _)
|
||||
| hir::ItemKind::Union(_, generics, _)
|
||||
| hir::ItemKind::Trait(_, _, _, generics, ..)
|
||||
| hir::ItemKind::Impl(hir::Impl { generics, .. })
|
||||
| hir::ItemKind::Fn { generics, .. }
|
||||
| hir::ItemKind::TyAlias(_, _, generics)
|
||||
| hir::ItemKind::Const(_, _, generics, _)
|
||||
| hir::ItemKind::TyAlias(_, generics, _)
|
||||
| hir::ItemKind::Const(_, generics, _, _)
|
||||
| hir::ItemKind::TraitAlias(_, generics, _),
|
||||
..
|
||||
})
|
||||
@@ -411,14 +411,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
|
||||
hir::Node::Item(hir::Item {
|
||||
kind:
|
||||
hir::ItemKind::Struct(_, _, generics)
|
||||
| hir::ItemKind::Enum(_, _, generics)
|
||||
| hir::ItemKind::Union(_, _, generics)
|
||||
hir::ItemKind::Struct(_, generics, _)
|
||||
| hir::ItemKind::Enum(_, generics, _)
|
||||
| hir::ItemKind::Union(_, generics, _)
|
||||
| hir::ItemKind::Trait(_, _, _, generics, ..)
|
||||
| hir::ItemKind::Impl(hir::Impl { generics, .. })
|
||||
| hir::ItemKind::Fn { generics, .. }
|
||||
| hir::ItemKind::TyAlias(_, _, generics)
|
||||
| hir::ItemKind::Const(_, _, generics, _)
|
||||
| hir::ItemKind::TyAlias(_, generics, _)
|
||||
| hir::ItemKind::Const(_, generics, _, _)
|
||||
| hir::ItemKind::TraitAlias(_, generics, _),
|
||||
..
|
||||
}) if !param_ty => {
|
||||
|
||||
@@ -61,9 +61,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "compiler_builtins"
|
||||
version = "0.1.159"
|
||||
version = "0.1.160"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "448068da8f2326b2a0472353cb401dd8795a89c007ef30fff90f50706e862e72"
|
||||
checksum = "6376049cfa92c0aa8b9ac95fae22184b981c658208d4ed8a1dc553cd83612895"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"rustc-std-workspace-core",
|
||||
|
||||
@@ -16,7 +16,7 @@ bench = false
|
||||
|
||||
[dependencies]
|
||||
core = { path = "../core", public = true }
|
||||
compiler_builtins = { version = "=0.1.159", features = ['rustc-dep-of-std'] }
|
||||
compiler_builtins = { version = "=0.1.160", features = ['rustc-dep-of-std'] }
|
||||
|
||||
[features]
|
||||
compiler-builtins-mem = ['compiler_builtins/mem']
|
||||
|
||||
@@ -38,7 +38,16 @@
|
||||
|
||||
mod uninit;
|
||||
|
||||
/// A common trait for the ability to explicitly duplicate an object.
|
||||
/// A common trait that allows explicit creation of a duplicate value.
|
||||
///
|
||||
/// Calling [`clone`] always produces a new value.
|
||||
/// However, for types that are references to other data (such as smart pointers or references),
|
||||
/// the new value may still point to the same underlying data, rather than duplicating it.
|
||||
/// See [`Clone::clone`] for more details.
|
||||
///
|
||||
/// This distinction is especially important when using `#[derive(Clone)]` on structs containing
|
||||
/// smart pointers like `Arc<Mutex<T>>` - the cloned struct will share mutable state with the
|
||||
/// original.
|
||||
///
|
||||
/// Differs from [`Copy`] in that [`Copy`] is implicit and an inexpensive bit-wise copy, while
|
||||
/// `Clone` is always explicit and may or may not be expensive. In order to enforce
|
||||
@@ -147,7 +156,16 @@ mod uninit;
|
||||
#[rustc_diagnostic_item = "Clone"]
|
||||
#[rustc_trivial_field_reads]
|
||||
pub trait Clone: Sized {
|
||||
/// Returns a copy of the value.
|
||||
/// Returns a duplicate of the value.
|
||||
///
|
||||
/// Note that what "duplicate" means varies by type:
|
||||
/// - For most types, this creates a deep, independent copy
|
||||
/// - For reference types like `&T`, this creates another reference to the same value
|
||||
/// - For smart pointers like [`Arc`] or [`Rc`], this increments the reference count
|
||||
/// but still points to the same underlying data
|
||||
///
|
||||
/// [`Arc`]: ../../std/sync/struct.Arc.html
|
||||
/// [`Rc`]: ../../std/rc/struct.Rc.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@@ -157,6 +175,23 @@ pub trait Clone: Sized {
|
||||
///
|
||||
/// assert_eq!("Hello", hello.clone());
|
||||
/// ```
|
||||
///
|
||||
/// Example with a reference-counted type:
|
||||
///
|
||||
/// ```
|
||||
/// use std::sync::{Arc, Mutex};
|
||||
///
|
||||
/// let data = Arc::new(Mutex::new(vec![1, 2, 3]));
|
||||
/// let data_clone = data.clone(); // Creates another Arc pointing to the same Mutex
|
||||
///
|
||||
/// {
|
||||
/// let mut lock = data.lock().unwrap();
|
||||
/// lock.push(4);
|
||||
/// }
|
||||
///
|
||||
/// // Changes are visible through the clone because they share the same underlying data
|
||||
/// assert_eq!(*data_clone.lock().unwrap(), vec![1, 2, 3, 4]);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use = "cloning is often expensive and is not expected to have side effects"]
|
||||
// Clone::clone is special because the compiler generates MIR to implement it for some types.
|
||||
|
||||
39
library/core/src/intrinsics/bounds.rs
Normal file
39
library/core/src/intrinsics/bounds.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
//! Various traits used to restrict intrinsics to not-completely-wrong types.
|
||||
|
||||
/// Types with a built-in dereference operator in runtime MIR,
|
||||
/// aka references and raw pointers.
|
||||
///
|
||||
/// # Safety
|
||||
/// Must actually *be* such a type.
|
||||
pub unsafe trait BuiltinDeref: Sized {
|
||||
type Pointee: ?Sized;
|
||||
}
|
||||
|
||||
unsafe impl<T: ?Sized> BuiltinDeref for &mut T {
|
||||
type Pointee = T;
|
||||
}
|
||||
unsafe impl<T: ?Sized> BuiltinDeref for &T {
|
||||
type Pointee = T;
|
||||
}
|
||||
unsafe impl<T: ?Sized> BuiltinDeref for *mut T {
|
||||
type Pointee = T;
|
||||
}
|
||||
unsafe impl<T: ?Sized> BuiltinDeref for *const T {
|
||||
type Pointee = T;
|
||||
}
|
||||
|
||||
pub trait ChangePointee<U: ?Sized>: BuiltinDeref {
|
||||
type Output;
|
||||
}
|
||||
impl<'a, T: ?Sized + 'a, U: ?Sized + 'a> ChangePointee<U> for &'a mut T {
|
||||
type Output = &'a mut U;
|
||||
}
|
||||
impl<'a, T: ?Sized + 'a, U: ?Sized + 'a> ChangePointee<U> for &'a T {
|
||||
type Output = &'a U;
|
||||
}
|
||||
impl<T: ?Sized, U: ?Sized> ChangePointee<U> for *mut T {
|
||||
type Output = *mut U;
|
||||
}
|
||||
impl<T: ?Sized, U: ?Sized> ChangePointee<U> for *const T {
|
||||
type Output = *const U;
|
||||
}
|
||||
@@ -53,6 +53,7 @@
|
||||
use crate::marker::{ConstParamTy, DiscriminantKind, Tuple};
|
||||
use crate::ptr;
|
||||
|
||||
mod bounds;
|
||||
pub mod fallback;
|
||||
pub mod mir;
|
||||
pub mod simd;
|
||||
@@ -1730,7 +1731,7 @@ pub const fn needs_drop<T: ?Sized>() -> bool;
|
||||
#[rustc_intrinsic_const_stable_indirect]
|
||||
#[rustc_nounwind]
|
||||
#[rustc_intrinsic]
|
||||
pub const unsafe fn offset<Ptr, Delta>(dst: Ptr, offset: Delta) -> Ptr;
|
||||
pub const unsafe fn offset<Ptr: bounds::BuiltinDeref, Delta>(dst: Ptr, offset: Delta) -> Ptr;
|
||||
|
||||
/// Calculates the offset from a pointer, potentially wrapping.
|
||||
///
|
||||
@@ -1751,6 +1752,33 @@ pub const unsafe fn offset<Ptr, Delta>(dst: Ptr, offset: Delta) -> Ptr;
|
||||
#[rustc_intrinsic]
|
||||
pub const unsafe fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
|
||||
|
||||
/// Projects to the `index`-th element of `slice_ptr`, as the same kind of pointer
|
||||
/// as the slice was provided -- so `&mut [T] → &mut T`, `&[T] → &T`,
|
||||
/// `*mut [T] → *mut T`, or `*const [T] → *const T` -- without a bounds check.
|
||||
///
|
||||
/// This is exposed via `<usize as SliceIndex>::get(_unchecked)(_mut)`,
|
||||
/// and isn't intended to be used elsewhere.
|
||||
///
|
||||
/// Expands in MIR to `{&, &mut, &raw const, &raw mut} (*slice_ptr)[index]`,
|
||||
/// depending on the types involved, so no backend support is needed.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// - `index < PtrMetadata(slice_ptr)`, so the indexing is in-bounds for the slice
|
||||
/// - the resulting offsetting is in-bounds of the allocated object, which is
|
||||
/// always the case for references, but needs to be upheld manually for pointers
|
||||
#[cfg(not(bootstrap))]
|
||||
#[rustc_nounwind]
|
||||
#[rustc_intrinsic]
|
||||
pub const unsafe fn slice_get_unchecked<
|
||||
ItemPtr: bounds::ChangePointee<[T], Pointee = T, Output = SlicePtr>,
|
||||
SlicePtr,
|
||||
T,
|
||||
>(
|
||||
slice_ptr: SlicePtr,
|
||||
index: usize,
|
||||
) -> ItemPtr;
|
||||
|
||||
/// Masks out bits of the pointer according to a mask.
|
||||
///
|
||||
/// Note that, unlike most intrinsics, this is safe to call;
|
||||
@@ -2212,28 +2240,28 @@ pub unsafe fn fmuladdf128(a: f128, b: f128, c: f128) -> f128;
|
||||
/// [`f16::floor`](../../std/primitive.f16.html#method.floor)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn floorf16(x: f16) -> f16;
|
||||
pub const unsafe fn floorf16(x: f16) -> f16;
|
||||
/// Returns the largest integer less than or equal to an `f32`.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is
|
||||
/// [`f32::floor`](../../std/primitive.f32.html#method.floor)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn floorf32(x: f32) -> f32;
|
||||
pub const unsafe fn floorf32(x: f32) -> f32;
|
||||
/// Returns the largest integer less than or equal to an `f64`.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is
|
||||
/// [`f64::floor`](../../std/primitive.f64.html#method.floor)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn floorf64(x: f64) -> f64;
|
||||
pub const unsafe fn floorf64(x: f64) -> f64;
|
||||
/// Returns the largest integer less than or equal to an `f128`.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is
|
||||
/// [`f128::floor`](../../std/primitive.f128.html#method.floor)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn floorf128(x: f128) -> f128;
|
||||
pub const unsafe fn floorf128(x: f128) -> f128;
|
||||
|
||||
/// Returns the smallest integer greater than or equal to an `f16`.
|
||||
///
|
||||
@@ -2241,28 +2269,28 @@ pub unsafe fn floorf128(x: f128) -> f128;
|
||||
/// [`f16::ceil`](../../std/primitive.f16.html#method.ceil)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn ceilf16(x: f16) -> f16;
|
||||
pub const unsafe fn ceilf16(x: f16) -> f16;
|
||||
/// Returns the smallest integer greater than or equal to an `f32`.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is
|
||||
/// [`f32::ceil`](../../std/primitive.f32.html#method.ceil)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn ceilf32(x: f32) -> f32;
|
||||
pub const unsafe fn ceilf32(x: f32) -> f32;
|
||||
/// Returns the smallest integer greater than or equal to an `f64`.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is
|
||||
/// [`f64::ceil`](../../std/primitive.f64.html#method.ceil)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn ceilf64(x: f64) -> f64;
|
||||
pub const unsafe fn ceilf64(x: f64) -> f64;
|
||||
/// Returns the smallest integer greater than or equal to an `f128`.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is
|
||||
/// [`f128::ceil`](../../std/primitive.f128.html#method.ceil)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn ceilf128(x: f128) -> f128;
|
||||
pub const unsafe fn ceilf128(x: f128) -> f128;
|
||||
|
||||
/// Returns the integer part of an `f16`.
|
||||
///
|
||||
@@ -2270,28 +2298,28 @@ pub unsafe fn ceilf128(x: f128) -> f128;
|
||||
/// [`f16::trunc`](../../std/primitive.f16.html#method.trunc)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn truncf16(x: f16) -> f16;
|
||||
pub const unsafe fn truncf16(x: f16) -> f16;
|
||||
/// Returns the integer part of an `f32`.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is
|
||||
/// [`f32::trunc`](../../std/primitive.f32.html#method.trunc)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn truncf32(x: f32) -> f32;
|
||||
pub const unsafe fn truncf32(x: f32) -> f32;
|
||||
/// Returns the integer part of an `f64`.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is
|
||||
/// [`f64::trunc`](../../std/primitive.f64.html#method.trunc)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn truncf64(x: f64) -> f64;
|
||||
pub const unsafe fn truncf64(x: f64) -> f64;
|
||||
/// Returns the integer part of an `f128`.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is
|
||||
/// [`f128::trunc`](../../std/primitive.f128.html#method.trunc)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn truncf128(x: f128) -> f128;
|
||||
pub const unsafe fn truncf128(x: f128) -> f128;
|
||||
|
||||
/// Returns the nearest integer to an `f16`. Rounds half-way cases to the number with an even
|
||||
/// least significant digit.
|
||||
@@ -2300,7 +2328,7 @@ pub unsafe fn truncf128(x: f128) -> f128;
|
||||
/// [`f16::round_ties_even`](../../std/primitive.f16.html#method.round_ties_even)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub fn round_ties_even_f16(x: f16) -> f16;
|
||||
pub const fn round_ties_even_f16(x: f16) -> f16;
|
||||
|
||||
/// Returns the nearest integer to an `f32`. Rounds half-way cases to the number with an even
|
||||
/// least significant digit.
|
||||
@@ -2309,7 +2337,7 @@ pub fn round_ties_even_f16(x: f16) -> f16;
|
||||
/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub fn round_ties_even_f32(x: f32) -> f32;
|
||||
pub const fn round_ties_even_f32(x: f32) -> f32;
|
||||
|
||||
/// Returns the nearest integer to an `f64`. Rounds half-way cases to the number with an even
|
||||
/// least significant digit.
|
||||
@@ -2318,7 +2346,7 @@ pub fn round_ties_even_f32(x: f32) -> f32;
|
||||
/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub fn round_ties_even_f64(x: f64) -> f64;
|
||||
pub const fn round_ties_even_f64(x: f64) -> f64;
|
||||
|
||||
/// Returns the nearest integer to an `f128`. Rounds half-way cases to the number with an even
|
||||
/// least significant digit.
|
||||
@@ -2327,7 +2355,7 @@ pub fn round_ties_even_f64(x: f64) -> f64;
|
||||
/// [`f128::round_ties_even`](../../std/primitive.f128.html#method.round_ties_even)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub fn round_ties_even_f128(x: f128) -> f128;
|
||||
pub const fn round_ties_even_f128(x: f128) -> f128;
|
||||
|
||||
/// Returns the nearest integer to an `f16`. Rounds half-way cases away from zero.
|
||||
///
|
||||
@@ -2335,28 +2363,28 @@ pub fn round_ties_even_f128(x: f128) -> f128;
|
||||
/// [`f16::round`](../../std/primitive.f16.html#method.round)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn roundf16(x: f16) -> f16;
|
||||
pub const unsafe fn roundf16(x: f16) -> f16;
|
||||
/// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is
|
||||
/// [`f32::round`](../../std/primitive.f32.html#method.round)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn roundf32(x: f32) -> f32;
|
||||
pub const unsafe fn roundf32(x: f32) -> f32;
|
||||
/// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is
|
||||
/// [`f64::round`](../../std/primitive.f64.html#method.round)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn roundf64(x: f64) -> f64;
|
||||
pub const unsafe fn roundf64(x: f64) -> f64;
|
||||
/// Returns the nearest integer to an `f128`. Rounds half-way cases away from zero.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is
|
||||
/// [`f128::round`](../../std/primitive.f128.html#method.round)
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn roundf128(x: f128) -> f128;
|
||||
pub const unsafe fn roundf128(x: f128) -> f128;
|
||||
|
||||
/// Float addition that allows optimizations based on algebraic rules.
|
||||
/// May assume inputs are finite.
|
||||
@@ -3575,18 +3603,9 @@ pub const fn type_id<T: ?Sized + 'static>() -> u128;
|
||||
#[unstable(feature = "core_intrinsics", issue = "none")]
|
||||
#[rustc_intrinsic_const_stable_indirect]
|
||||
#[rustc_intrinsic]
|
||||
pub const fn aggregate_raw_ptr<P: AggregateRawPtr<D, Metadata = M>, D, M>(data: D, meta: M) -> P;
|
||||
|
||||
#[unstable(feature = "core_intrinsics", issue = "none")]
|
||||
pub trait AggregateRawPtr<D> {
|
||||
type Metadata: Copy;
|
||||
}
|
||||
impl<P: ?Sized, T: ptr::Thin> AggregateRawPtr<*const T> for *const P {
|
||||
type Metadata = <P as ptr::Pointee>::Metadata;
|
||||
}
|
||||
impl<P: ?Sized, T: ptr::Thin> AggregateRawPtr<*mut T> for *mut P {
|
||||
type Metadata = <P as ptr::Pointee>::Metadata;
|
||||
}
|
||||
pub const fn aggregate_raw_ptr<P: bounds::BuiltinDeref, D, M>(data: D, meta: M) -> P
|
||||
where
|
||||
<P as bounds::BuiltinDeref>::Pointee: ptr::Pointee<Metadata = M>;
|
||||
|
||||
/// Lowers in MIR to `Rvalue::UnaryOp` with `UnOp::PtrMetadata`.
|
||||
///
|
||||
|
||||
@@ -1447,8 +1447,10 @@ impl f128 {
|
||||
#[inline]
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[unstable(feature = "f128", issue = "116909")]
|
||||
#[rustc_const_unstable(feature = "f128", issue = "116909")]
|
||||
// #[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn floor(self) -> f128 {
|
||||
pub const fn floor(self) -> f128 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::floorf128(self) }
|
||||
}
|
||||
@@ -1477,8 +1479,10 @@ impl f128 {
|
||||
#[doc(alias = "ceiling")]
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[unstable(feature = "f128", issue = "116909")]
|
||||
#[rustc_const_unstable(feature = "f128", issue = "116909")]
|
||||
// #[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn ceil(self) -> f128 {
|
||||
pub const fn ceil(self) -> f128 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::ceilf128(self) }
|
||||
}
|
||||
@@ -1513,8 +1517,10 @@ impl f128 {
|
||||
#[inline]
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[unstable(feature = "f128", issue = "116909")]
|
||||
#[rustc_const_unstable(feature = "f128", issue = "116909")]
|
||||
// #[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn round(self) -> f128 {
|
||||
pub const fn round(self) -> f128 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::roundf128(self) }
|
||||
}
|
||||
@@ -1547,8 +1553,10 @@ impl f128 {
|
||||
#[inline]
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[unstable(feature = "f128", issue = "116909")]
|
||||
#[rustc_const_unstable(feature = "f128", issue = "116909")]
|
||||
// #[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn round_ties_even(self) -> f128 {
|
||||
pub const fn round_ties_even(self) -> f128 {
|
||||
intrinsics::round_ties_even_f128(self)
|
||||
}
|
||||
|
||||
@@ -1579,8 +1587,10 @@ impl f128 {
|
||||
#[doc(alias = "truncate")]
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[unstable(feature = "f128", issue = "116909")]
|
||||
#[rustc_const_unstable(feature = "f128", issue = "116909")]
|
||||
// #[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn trunc(self) -> f128 {
|
||||
pub const fn trunc(self) -> f128 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::truncf128(self) }
|
||||
}
|
||||
@@ -1610,8 +1620,10 @@ impl f128 {
|
||||
#[inline]
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[unstable(feature = "f128", issue = "116909")]
|
||||
#[rustc_const_unstable(feature = "f128", issue = "116909")]
|
||||
// #[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn fract(self) -> f128 {
|
||||
pub const fn fract(self) -> f128 {
|
||||
self - self.trunc()
|
||||
}
|
||||
|
||||
|
||||
@@ -1423,8 +1423,10 @@ impl f16 {
|
||||
#[inline]
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[unstable(feature = "f16", issue = "116909")]
|
||||
#[rustc_const_unstable(feature = "f16", issue = "116909")]
|
||||
// #[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn floor(self) -> f16 {
|
||||
pub const fn floor(self) -> f16 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::floorf16(self) }
|
||||
}
|
||||
@@ -1453,8 +1455,10 @@ impl f16 {
|
||||
#[doc(alias = "ceiling")]
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[unstable(feature = "f16", issue = "116909")]
|
||||
#[rustc_const_unstable(feature = "f16", issue = "116909")]
|
||||
// #[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn ceil(self) -> f16 {
|
||||
pub const fn ceil(self) -> f16 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::ceilf16(self) }
|
||||
}
|
||||
@@ -1489,8 +1493,10 @@ impl f16 {
|
||||
#[inline]
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[unstable(feature = "f16", issue = "116909")]
|
||||
#[rustc_const_unstable(feature = "f16", issue = "116909")]
|
||||
// #[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn round(self) -> f16 {
|
||||
pub const fn round(self) -> f16 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::roundf16(self) }
|
||||
}
|
||||
@@ -1523,8 +1529,10 @@ impl f16 {
|
||||
#[inline]
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[unstable(feature = "f16", issue = "116909")]
|
||||
#[rustc_const_unstable(feature = "f16", issue = "116909")]
|
||||
// #[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn round_ties_even(self) -> f16 {
|
||||
pub const fn round_ties_even(self) -> f16 {
|
||||
intrinsics::round_ties_even_f16(self)
|
||||
}
|
||||
|
||||
@@ -1555,8 +1563,10 @@ impl f16 {
|
||||
#[doc(alias = "truncate")]
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[unstable(feature = "f16", issue = "116909")]
|
||||
#[rustc_const_unstable(feature = "f16", issue = "116909")]
|
||||
// #[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn trunc(self) -> f16 {
|
||||
pub const fn trunc(self) -> f16 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::truncf16(self) }
|
||||
}
|
||||
@@ -1586,8 +1596,10 @@ impl f16 {
|
||||
#[inline]
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[unstable(feature = "f16", issue = "116909")]
|
||||
#[rustc_const_unstable(feature = "f16", issue = "116909")]
|
||||
// #[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn fract(self) -> f16 {
|
||||
pub const fn fract(self) -> f16 {
|
||||
self - self.trunc()
|
||||
}
|
||||
|
||||
|
||||
@@ -1591,8 +1591,9 @@ pub mod math {
|
||||
/// [`f32::floor`]: ../../../std/primitive.f32.html#method.floor
|
||||
#[inline]
|
||||
#[unstable(feature = "core_float_math", issue = "137578")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn floor(x: f32) -> f32 {
|
||||
pub const fn floor(x: f32) -> f32 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::floorf32(x) }
|
||||
}
|
||||
@@ -1621,7 +1622,8 @@ pub mod math {
|
||||
#[doc(alias = "ceiling")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "core_float_math", issue = "137578")]
|
||||
pub fn ceil(x: f32) -> f32 {
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
pub const fn ceil(x: f32) -> f32 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::ceilf32(x) }
|
||||
}
|
||||
@@ -1655,7 +1657,8 @@ pub mod math {
|
||||
#[inline]
|
||||
#[unstable(feature = "core_float_math", issue = "137578")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn round(x: f32) -> f32 {
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
pub const fn round(x: f32) -> f32 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::roundf32(x) }
|
||||
}
|
||||
@@ -1688,7 +1691,8 @@ pub mod math {
|
||||
#[inline]
|
||||
#[unstable(feature = "core_float_math", issue = "137578")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn round_ties_even(x: f32) -> f32 {
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
pub const fn round_ties_even(x: f32) -> f32 {
|
||||
intrinsics::round_ties_even_f32(x)
|
||||
}
|
||||
|
||||
@@ -1718,7 +1722,8 @@ pub mod math {
|
||||
#[doc(alias = "truncate")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[unstable(feature = "core_float_math", issue = "137578")]
|
||||
pub fn trunc(x: f32) -> f32 {
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
pub const fn trunc(x: f32) -> f32 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::truncf32(x) }
|
||||
}
|
||||
@@ -1747,8 +1752,9 @@ pub mod math {
|
||||
/// [`f32::fract`]: ../../../std/primitive.f32.html#method.fract
|
||||
#[inline]
|
||||
#[unstable(feature = "core_float_math", issue = "137578")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn fract(x: f32) -> f32 {
|
||||
pub const fn fract(x: f32) -> f32 {
|
||||
x - trunc(x)
|
||||
}
|
||||
|
||||
|
||||
@@ -1589,8 +1589,9 @@ pub mod math {
|
||||
/// [`f64::floor`]: ../../../std/primitive.f64.html#method.floor
|
||||
#[inline]
|
||||
#[unstable(feature = "core_float_math", issue = "137578")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn floor(x: f64) -> f64 {
|
||||
pub const fn floor(x: f64) -> f64 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::floorf64(x) }
|
||||
}
|
||||
@@ -1618,8 +1619,9 @@ pub mod math {
|
||||
#[inline]
|
||||
#[doc(alias = "ceiling")]
|
||||
#[unstable(feature = "core_float_math", issue = "137578")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn ceil(x: f64) -> f64 {
|
||||
pub const fn ceil(x: f64) -> f64 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::ceilf64(x) }
|
||||
}
|
||||
@@ -1652,8 +1654,9 @@ pub mod math {
|
||||
/// [`f64::round`]: ../../../std/primitive.f64.html#method.round
|
||||
#[inline]
|
||||
#[unstable(feature = "core_float_math", issue = "137578")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn round(x: f64) -> f64 {
|
||||
pub const fn round(x: f64) -> f64 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::roundf64(x) }
|
||||
}
|
||||
@@ -1685,8 +1688,9 @@ pub mod math {
|
||||
/// [`f64::round_ties_even`]: ../../../std/primitive.f64.html#method.round_ties_even
|
||||
#[inline]
|
||||
#[unstable(feature = "core_float_math", issue = "137578")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn round_ties_even(x: f64) -> f64 {
|
||||
pub const fn round_ties_even(x: f64) -> f64 {
|
||||
intrinsics::round_ties_even_f64(x)
|
||||
}
|
||||
|
||||
@@ -1715,8 +1719,9 @@ pub mod math {
|
||||
#[inline]
|
||||
#[doc(alias = "truncate")]
|
||||
#[unstable(feature = "core_float_math", issue = "137578")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn trunc(x: f64) -> f64 {
|
||||
pub const fn trunc(x: f64) -> f64 {
|
||||
// SAFETY: intrinsic with no preconditions
|
||||
unsafe { intrinsics::truncf64(x) }
|
||||
}
|
||||
@@ -1745,8 +1750,9 @@ pub mod math {
|
||||
/// [`f64::fract`]: ../../../std/primitive.f64.html#method.fract
|
||||
#[inline]
|
||||
#[unstable(feature = "core_float_math", issue = "137578")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
pub fn fract(x: f64) -> f64 {
|
||||
pub const fn fract(x: f64) -> f64 {
|
||||
x - trunc(x)
|
||||
}
|
||||
|
||||
|
||||
@@ -1722,7 +1722,6 @@ impl<T, E> Result<Result<T, E>, E> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(result_flattening)]
|
||||
/// let x: Result<Result<&'static str, u32>, u32> = Ok(Ok("hello"));
|
||||
/// assert_eq!(Ok("hello"), x.flatten());
|
||||
///
|
||||
@@ -1736,14 +1735,14 @@ impl<T, E> Result<Result<T, E>, E> {
|
||||
/// Flattening only removes one level of nesting at a time:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(result_flattening)]
|
||||
/// let x: Result<Result<Result<&'static str, u32>, u32>, u32> = Ok(Ok(Ok("hello")));
|
||||
/// assert_eq!(Ok(Ok("hello")), x.flatten());
|
||||
/// assert_eq!(Ok("hello"), x.flatten().flatten());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "result_flattening", issue = "70142")]
|
||||
#[rustc_const_unstable(feature = "result_flattening", issue = "70142")]
|
||||
#[stable(feature = "result_flattening", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[rustc_allow_const_fn_unstable(const_precise_live_drops)]
|
||||
#[rustc_const_stable(feature = "result_flattening", since = "CURRENT_RUSTC_VERSION")]
|
||||
pub const fn flatten(self) -> Result<T, E> {
|
||||
// FIXME(const-hack): could be written with `and_then`
|
||||
match self {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
//! Indexing implementations for `[T]`.
|
||||
|
||||
#[cfg(not(bootstrap))]
|
||||
use crate::intrinsics::slice_get_unchecked;
|
||||
use crate::panic::const_panic;
|
||||
use crate::ub_checks::assert_unsafe_precondition;
|
||||
use crate::{ops, range};
|
||||
@@ -83,6 +85,7 @@ const fn slice_end_index_overflow_fail() -> ! {
|
||||
// Both the safe and unsafe public methods share these helpers,
|
||||
// which use intrinsics directly to get *no* extra checks.
|
||||
|
||||
#[cfg(bootstrap)]
|
||||
#[inline(always)]
|
||||
const unsafe fn get_noubcheck<T>(ptr: *const [T], index: usize) -> *const T {
|
||||
let ptr = ptr as *const T;
|
||||
@@ -90,6 +93,7 @@ const unsafe fn get_noubcheck<T>(ptr: *const [T], index: usize) -> *const T {
|
||||
unsafe { crate::intrinsics::offset(ptr, index) }
|
||||
}
|
||||
|
||||
#[cfg(bootstrap)]
|
||||
#[inline(always)]
|
||||
const unsafe fn get_mut_noubcheck<T>(ptr: *mut [T], index: usize) -> *mut T {
|
||||
let ptr = ptr as *mut T;
|
||||
@@ -103,8 +107,9 @@ const unsafe fn get_offset_len_noubcheck<T>(
|
||||
offset: usize,
|
||||
len: usize,
|
||||
) -> *const [T] {
|
||||
let ptr = ptr as *const T;
|
||||
// SAFETY: The caller already checked these preconditions
|
||||
let ptr = unsafe { get_noubcheck(ptr, offset) };
|
||||
let ptr = unsafe { crate::intrinsics::offset(ptr, offset) };
|
||||
crate::intrinsics::aggregate_raw_ptr(ptr, len)
|
||||
}
|
||||
|
||||
@@ -114,8 +119,9 @@ const unsafe fn get_offset_len_mut_noubcheck<T>(
|
||||
offset: usize,
|
||||
len: usize,
|
||||
) -> *mut [T] {
|
||||
let ptr = ptr as *mut T;
|
||||
// SAFETY: The caller already checked these preconditions
|
||||
let ptr = unsafe { get_mut_noubcheck(ptr, offset) };
|
||||
let ptr = unsafe { crate::intrinsics::offset(ptr, offset) };
|
||||
crate::intrinsics::aggregate_raw_ptr(ptr, len)
|
||||
}
|
||||
|
||||
@@ -224,15 +230,35 @@ unsafe impl<T> SliceIndex<[T]> for usize {
|
||||
|
||||
#[inline]
|
||||
fn get(self, slice: &[T]) -> Option<&T> {
|
||||
// SAFETY: `self` is checked to be in bounds.
|
||||
if self < slice.len() { unsafe { Some(&*get_noubcheck(slice, self)) } } else { None }
|
||||
if self < slice.len() {
|
||||
#[cfg(bootstrap)]
|
||||
// SAFETY: `self` is checked to be in bounds.
|
||||
unsafe {
|
||||
Some(&*get_noubcheck(slice, self))
|
||||
}
|
||||
#[cfg(not(bootstrap))]
|
||||
// SAFETY: `self` is checked to be in bounds.
|
||||
unsafe {
|
||||
Some(slice_get_unchecked(slice, self))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_mut(self, slice: &mut [T]) -> Option<&mut T> {
|
||||
if self < slice.len() {
|
||||
#[cfg(bootstrap)]
|
||||
// SAFETY: `self` is checked to be in bounds.
|
||||
unsafe { Some(&mut *get_mut_noubcheck(slice, self)) }
|
||||
unsafe {
|
||||
Some(&mut *get_mut_noubcheck(slice, self))
|
||||
}
|
||||
#[cfg(not(bootstrap))]
|
||||
// SAFETY: `self` is checked to be in bounds.
|
||||
unsafe {
|
||||
Some(slice_get_unchecked(slice, self))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -254,7 +280,14 @@ unsafe impl<T> SliceIndex<[T]> for usize {
|
||||
// Use intrinsics::assume instead of hint::assert_unchecked so that we don't check the
|
||||
// precondition of this function twice.
|
||||
crate::intrinsics::assume(self < slice.len());
|
||||
get_noubcheck(slice, self)
|
||||
#[cfg(bootstrap)]
|
||||
{
|
||||
get_noubcheck(slice, self)
|
||||
}
|
||||
#[cfg(not(bootstrap))]
|
||||
{
|
||||
slice_get_unchecked(slice, self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,7 +300,16 @@ unsafe impl<T> SliceIndex<[T]> for usize {
|
||||
(this: usize = self, len: usize = slice.len()) => this < len
|
||||
);
|
||||
// SAFETY: see comments for `get_unchecked` above.
|
||||
unsafe { get_mut_noubcheck(slice, self) }
|
||||
unsafe {
|
||||
#[cfg(bootstrap)]
|
||||
{
|
||||
get_mut_noubcheck(slice, self)
|
||||
}
|
||||
#[cfg(not(bootstrap))]
|
||||
{
|
||||
slice_get_unchecked(slice, self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -6,6 +6,8 @@ use crate::{mem, ptr};
|
||||
|
||||
/// Converts a slice of bytes to a string slice.
|
||||
///
|
||||
/// This is an alias to [`str::from_utf8`].
|
||||
///
|
||||
/// A string slice ([`&str`]) is made of bytes ([`u8`]), and a byte slice
|
||||
/// ([`&[u8]`][byteslice]) is made of bytes, so this function converts between
|
||||
/// the two. Not all byte slices are valid string slices, however: [`&str`] requires
|
||||
@@ -97,6 +99,8 @@ pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> {
|
||||
|
||||
/// Converts a mutable slice of bytes to a mutable string slice.
|
||||
///
|
||||
/// This is an alias to [`str::from_utf8_mut`].
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
@@ -142,6 +146,8 @@ pub const fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> {
|
||||
/// Converts a slice of bytes to a string slice without checking
|
||||
/// that the string contains valid UTF-8.
|
||||
///
|
||||
/// This is an alias to [`str::from_utf8_unchecked`].
|
||||
///
|
||||
/// See the safe version, [`from_utf8`], for more information.
|
||||
///
|
||||
/// # Safety
|
||||
@@ -178,6 +184,8 @@ pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
|
||||
/// Converts a slice of bytes to a string slice without checking
|
||||
/// that the string contains valid UTF-8; mutable version.
|
||||
///
|
||||
/// This is an alias to [`str::from_utf8_unchecked_mut`].
|
||||
///
|
||||
/// See the immutable version, [`from_utf8_unchecked()`] for documentation and safety requirements.
|
||||
///
|
||||
/// # Examples
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#![feature(char_max_len)]
|
||||
#![feature(clone_to_uninit)]
|
||||
#![feature(const_eval_select)]
|
||||
#![feature(const_float_round_methods)]
|
||||
#![feature(const_trait_impl)]
|
||||
#![feature(core_float_math)]
|
||||
#![feature(core_intrinsics)]
|
||||
|
||||
@@ -731,6 +731,9 @@ assume_usize_width! {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(141726): there is a lot of duplication between the following tests and
|
||||
// the tests in `coretests/tests/floats/f*.rs`
|
||||
// See issue https://github.com/rust-lang/rust/issues/141726 for more details.
|
||||
macro_rules! test_float {
|
||||
($modname: ident, $fassert: ident, $fty: ty) => {
|
||||
mod $modname {
|
||||
@@ -947,6 +950,117 @@ macro_rules! test_float {
|
||||
assert!(<$fty>::INFINITY.div_euclid(<$fty>::NAN).is_nan());
|
||||
assert!(<$fty>::NAN.div_euclid(<$fty>::INFINITY).is_nan());
|
||||
}
|
||||
#[test]
|
||||
#[cfg(not(bootstrap))]
|
||||
fn floor() {
|
||||
$fassert!((0.0 as $fty).floor(), 0.0);
|
||||
$fassert!((0.0 as $fty).floor().is_sign_positive());
|
||||
$fassert!((-0.0 as $fty).floor(), -0.0);
|
||||
$fassert!((-0.0 as $fty).floor().is_sign_negative());
|
||||
$fassert!((0.5 as $fty).floor(), 0.0);
|
||||
$fassert!((-0.5 as $fty).floor(), -1.0);
|
||||
$fassert!((1.5 as $fty).floor(), 1.0);
|
||||
$fassert!(<$fty>::MAX.floor(), <$fty>::MAX);
|
||||
$fassert!(<$fty>::MIN.floor(), <$fty>::MIN);
|
||||
$fassert!(<$fty>::MIN_POSITIVE.floor(), 0.0);
|
||||
$fassert!((-<$fty>::MIN_POSITIVE).floor(), -1.0);
|
||||
$fassert!(<$fty>::NAN.floor().is_nan());
|
||||
$fassert!(<$fty>::INFINITY.floor(), <$fty>::INFINITY);
|
||||
$fassert!(<$fty>::NEG_INFINITY.floor(), <$fty>::NEG_INFINITY);
|
||||
}
|
||||
#[test]
|
||||
#[cfg(not(bootstrap))]
|
||||
fn ceil() {
|
||||
$fassert!((0.0 as $fty).ceil(), 0.0);
|
||||
$fassert!((0.0 as $fty).ceil().is_sign_positive());
|
||||
$fassert!((-0.0 as $fty).ceil(), 0.0);
|
||||
$fassert!((-0.0 as $fty).ceil().is_sign_negative());
|
||||
$fassert!((0.5 as $fty).ceil(), 1.0);
|
||||
$fassert!((-0.5 as $fty).ceil(), 0.0);
|
||||
$fassert!(<$fty>::MAX.ceil(), <$fty>::MAX);
|
||||
$fassert!(<$fty>::MIN.ceil(), <$fty>::MIN);
|
||||
$fassert!(<$fty>::MIN_POSITIVE.ceil(), 1.0);
|
||||
$fassert!((-<$fty>::MIN_POSITIVE).ceil(), 0.0);
|
||||
$fassert!(<$fty>::NAN.ceil().is_nan());
|
||||
$fassert!(<$fty>::INFINITY.ceil(), <$fty>::INFINITY);
|
||||
$fassert!(<$fty>::NEG_INFINITY.ceil(), <$fty>::NEG_INFINITY);
|
||||
}
|
||||
#[test]
|
||||
#[cfg(not(bootstrap))]
|
||||
fn round() {
|
||||
$fassert!((0.0 as $fty).round(), 0.0);
|
||||
$fassert!((0.0 as $fty).round().is_sign_positive());
|
||||
$fassert!((-0.0 as $fty).round(), -0.0);
|
||||
$fassert!((-0.0 as $fty).round().is_sign_negative());
|
||||
$fassert!((0.5 as $fty).round(), 1.0);
|
||||
$fassert!((-0.5 as $fty).round(), -1.0);
|
||||
$fassert!(<$fty>::MAX.round(), <$fty>::MAX);
|
||||
$fassert!(<$fty>::MIN.round(), <$fty>::MIN);
|
||||
$fassert!(<$fty>::MIN_POSITIVE.round(), 0.0);
|
||||
$fassert!((-<$fty>::MIN_POSITIVE).round(), 0.0);
|
||||
$fassert!(<$fty>::NAN.round().is_nan());
|
||||
$fassert!(<$fty>::INFINITY.round(), <$fty>::INFINITY);
|
||||
$fassert!(<$fty>::NEG_INFINITY.round(), <$fty>::NEG_INFINITY);
|
||||
}
|
||||
#[test]
|
||||
#[cfg(not(bootstrap))]
|
||||
fn round_ties_even() {
|
||||
$fassert!((0.0 as $fty).round_ties_even(), 0.0);
|
||||
$fassert!((0.0 as $fty).round_ties_even().is_sign_positive());
|
||||
$fassert!((-0.0 as $fty).round_ties_even(), -0.0);
|
||||
$fassert!((-0.0 as $fty).round_ties_even().is_sign_negative());
|
||||
$fassert!((0.5 as $fty).round_ties_even(), 0.0);
|
||||
$fassert!((0.5 as $fty).round_ties_even().is_sign_positive());
|
||||
$fassert!((-0.5 as $fty).round_ties_even(), -0.0);
|
||||
$fassert!((-0.5 as $fty).round_ties_even().is_sign_negative());
|
||||
$fassert!(<$fty>::MAX.round_ties_even(), <$fty>::MAX);
|
||||
$fassert!(<$fty>::MIN.round_ties_even(), <$fty>::MIN);
|
||||
$fassert!(<$fty>::MIN_POSITIVE.round_ties_even(), 0.0);
|
||||
$fassert!((-<$fty>::MIN_POSITIVE).round_ties_even(), 0.0);
|
||||
$fassert!(<$fty>::NAN.round_ties_even().is_nan());
|
||||
$fassert!(<$fty>::INFINITY.round_ties_even(), <$fty>::INFINITY);
|
||||
$fassert!(<$fty>::NEG_INFINITY.round_ties_even(), <$fty>::NEG_INFINITY);
|
||||
}
|
||||
#[test]
|
||||
#[cfg(not(bootstrap))]
|
||||
fn trunc() {
|
||||
$fassert!((0.0 as $fty).trunc(), 0.0);
|
||||
$fassert!((0.0 as $fty).trunc().is_sign_positive());
|
||||
$fassert!((-0.0 as $fty).trunc(), -0.0);
|
||||
$fassert!((-0.0 as $fty).trunc().is_sign_negative());
|
||||
$fassert!((0.5 as $fty).trunc(), 0.0);
|
||||
$fassert!((0.5 as $fty).trunc().is_sign_positive());
|
||||
$fassert!((-0.5 as $fty).trunc(), -0.0);
|
||||
$fassert!((-0.5 as $fty).trunc().is_sign_negative());
|
||||
$fassert!(<$fty>::MAX.trunc(), <$fty>::MAX);
|
||||
$fassert!(<$fty>::MIN.trunc(), <$fty>::MIN);
|
||||
$fassert!(<$fty>::MIN_POSITIVE.trunc(), 0.0);
|
||||
$fassert!((-<$fty>::MIN_POSITIVE).trunc(), 0.0);
|
||||
$fassert!(<$fty>::NAN.trunc().is_nan());
|
||||
$fassert!(<$fty>::INFINITY.trunc(), <$fty>::INFINITY);
|
||||
$fassert!(<$fty>::NEG_INFINITY.trunc(), <$fty>::NEG_INFINITY);
|
||||
}
|
||||
#[test]
|
||||
#[cfg(not(bootstrap))]
|
||||
fn fract() {
|
||||
$fassert!((0.0 as $fty).fract(), 0.0);
|
||||
$fassert!((0.0 as $fty).fract().is_sign_positive());
|
||||
$fassert!((-0.0 as $fty).fract(), 0.0);
|
||||
$fassert!((-0.0 as $fty).fract().is_sign_positive());
|
||||
$fassert!((0.5 as $fty).fract(), 0.5);
|
||||
$fassert!((0.5 as $fty).fract().is_sign_positive());
|
||||
$fassert!((-0.5 as $fty).fract(), -0.5);
|
||||
$fassert!((-0.5 as $fty).fract().is_sign_negative());
|
||||
$fassert!(<$fty>::MAX.fract(), 0.0);
|
||||
$fassert!(<$fty>::MIN.fract(), 0.0);
|
||||
$fassert!(<$fty>::MIN_POSITIVE.fract(), <$fty>::MIN_POSITIVE);
|
||||
$fassert!(<$fty>::MIN_POSITIVE.fract().is_sign_positive());
|
||||
$fassert!((-<$fty>::MIN_POSITIVE).fract(), -<$fty>::MIN_POSITIVE);
|
||||
$fassert!((-<$fty>::MIN_POSITIVE).fract().is_sign_negative());
|
||||
$fassert!(<$fty>::NAN.fract().is_nan());
|
||||
$fassert!(<$fty>::INFINITY.fract().is_nan());
|
||||
$fassert!(<$fty>::NEG_INFINITY.fract().is_nan());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
|
||||
panic_unwind = { path = "../panic_unwind", optional = true }
|
||||
panic_abort = { path = "../panic_abort" }
|
||||
core = { path = "../core", public = true }
|
||||
compiler_builtins = { version = "=0.1.159" }
|
||||
compiler_builtins = { version = "=0.1.160" }
|
||||
unwind = { path = "../unwind" }
|
||||
hashbrown = { version = "0.15", default-features = false, features = [
|
||||
'rustc-dep-of-std',
|
||||
|
||||
@@ -2915,17 +2915,28 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
|
||||
///
|
||||
/// # Platform-specific behavior
|
||||
///
|
||||
/// This function currently corresponds to `openat`, `fdopendir`, `unlinkat` and `lstat` functions
|
||||
/// on Unix (except for REDOX) and the `CreateFileW`, `GetFileInformationByHandleEx`,
|
||||
/// `SetFileInformationByHandle`, and `NtCreateFile` functions on Windows. Note that, this
|
||||
/// [may change in the future][changes].
|
||||
/// These implementation details [may change in the future][changes].
|
||||
///
|
||||
/// - "Unix-like": By default, this function currently corresponds to
|
||||
/// `openat`, `fdopendir`, `unlinkat` and `lstat`
|
||||
/// on Unix-family platforms, except where noted otherwise.
|
||||
/// - "Windows": This function currently corresponds to `CreateFileW`,
|
||||
/// `GetFileInformationByHandleEx`, `SetFileInformationByHandle`, and `NtCreateFile`.
|
||||
///
|
||||
/// ## Time-of-check to time-of-use (TOCTOU) race conditions
|
||||
/// On a few platforms there is no way to remove a directory's contents without following symlinks
|
||||
/// unless you perform a check and then operate on paths based on that directory.
|
||||
/// This allows concurrently-running code to replace the directory with a symlink after the check,
|
||||
/// causing a removal to instead operate on a path based on the symlink. This is a TOCTOU race.
|
||||
/// By default, `fs::remove_dir_all` protects against a symlink TOCTOU race on all platforms
|
||||
/// except the following. It should not be used in security-sensitive contexts on these platforms:
|
||||
/// - Miri: Even when emulating targets where the underlying implementation will protect against
|
||||
/// TOCTOU races, Miri will not do so.
|
||||
/// - Redox OS: This function does not protect against TOCTOU races, as Redox does not implement
|
||||
/// the required platform support to do so.
|
||||
///
|
||||
/// [changes]: io#platform-specific-behavior
|
||||
///
|
||||
/// On REDOX, as well as when running in Miri for any target, this function is not protected against
|
||||
/// time-of-check to time-of-use (TOCTOU) race conditions, and should not be used in
|
||||
/// security-sensitive code on those platforms. All other platforms are protected.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// See [`fs::remove_file`] and [`fs::remove_dir`].
|
||||
|
||||
@@ -335,6 +335,7 @@
|
||||
#![feature(bstr_internals)]
|
||||
#![feature(char_internals)]
|
||||
#![feature(clone_to_uninit)]
|
||||
#![feature(const_float_round_methods)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(core_io_borrowed_buf)]
|
||||
#![feature(duration_constants)]
|
||||
|
||||
@@ -44,8 +44,9 @@ impl f32 {
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[inline]
|
||||
pub fn floor(self) -> f32 {
|
||||
pub const fn floor(self) -> f32 {
|
||||
core::f32::math::floor(self)
|
||||
}
|
||||
|
||||
@@ -66,8 +67,9 @@ impl f32 {
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[inline]
|
||||
pub fn ceil(self) -> f32 {
|
||||
pub const fn ceil(self) -> f32 {
|
||||
core::f32::math::ceil(self)
|
||||
}
|
||||
|
||||
@@ -94,8 +96,9 @@ impl f32 {
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[inline]
|
||||
pub fn round(self) -> f32 {
|
||||
pub const fn round(self) -> f32 {
|
||||
core::f32::math::round(self)
|
||||
}
|
||||
|
||||
@@ -120,8 +123,9 @@ impl f32 {
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "round_ties_even", since = "1.77.0")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[inline]
|
||||
pub fn round_ties_even(self) -> f32 {
|
||||
pub const fn round_ties_even(self) -> f32 {
|
||||
core::f32::math::round_ties_even(self)
|
||||
}
|
||||
|
||||
@@ -145,8 +149,9 @@ impl f32 {
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[inline]
|
||||
pub fn trunc(self) -> f32 {
|
||||
pub const fn trunc(self) -> f32 {
|
||||
core::f32::math::trunc(self)
|
||||
}
|
||||
|
||||
@@ -168,8 +173,9 @@ impl f32 {
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[inline]
|
||||
pub fn fract(self) -> f32 {
|
||||
pub const fn fract(self) -> f32 {
|
||||
core::f32::math::fract(self)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,9 @@ impl f64 {
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[inline]
|
||||
pub fn floor(self) -> f64 {
|
||||
pub const fn floor(self) -> f64 {
|
||||
core::f64::math::floor(self)
|
||||
}
|
||||
|
||||
@@ -66,8 +67,9 @@ impl f64 {
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[inline]
|
||||
pub fn ceil(self) -> f64 {
|
||||
pub const fn ceil(self) -> f64 {
|
||||
core::f64::math::ceil(self)
|
||||
}
|
||||
|
||||
@@ -94,8 +96,9 @@ impl f64 {
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[inline]
|
||||
pub fn round(self) -> f64 {
|
||||
pub const fn round(self) -> f64 {
|
||||
core::f64::math::round(self)
|
||||
}
|
||||
|
||||
@@ -120,8 +123,9 @@ impl f64 {
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "round_ties_even", since = "1.77.0")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[inline]
|
||||
pub fn round_ties_even(self) -> f64 {
|
||||
pub const fn round_ties_even(self) -> f64 {
|
||||
core::f64::math::round_ties_even(self)
|
||||
}
|
||||
|
||||
@@ -145,8 +149,9 @@ impl f64 {
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[inline]
|
||||
pub fn trunc(self) -> f64 {
|
||||
pub const fn trunc(self) -> f64 {
|
||||
core::f64::math::trunc(self)
|
||||
}
|
||||
|
||||
@@ -168,8 +173,9 @@ impl f64 {
|
||||
#[rustc_allow_incoherent_impl]
|
||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]
|
||||
#[inline]
|
||||
pub fn fract(self) -> f64 {
|
||||
pub const fn fract(self) -> f64 {
|
||||
core::f64::math::fract(self)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::cell::UnsafeCell;
|
||||
use crate::hint::unreachable_unchecked;
|
||||
use crate::cell::{Cell, UnsafeCell};
|
||||
use crate::mem::MaybeUninit;
|
||||
use crate::ptr;
|
||||
use crate::sys::thread_local::{abort_on_dtor_unwind, destructors};
|
||||
|
||||
pub unsafe trait DestroyedState: Sized {
|
||||
pub unsafe trait DestroyedState: Sized + Copy {
|
||||
fn register_dtor<T>(s: &Storage<T, Self>);
|
||||
}
|
||||
|
||||
@@ -19,15 +19,17 @@ unsafe impl DestroyedState for () {
|
||||
}
|
||||
}
|
||||
|
||||
enum State<T, D> {
|
||||
Initial,
|
||||
Alive(T),
|
||||
#[derive(Copy, Clone)]
|
||||
enum State<D> {
|
||||
Uninitialized,
|
||||
Alive,
|
||||
Destroyed(D),
|
||||
}
|
||||
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct Storage<T, D> {
|
||||
state: UnsafeCell<State<T, D>>,
|
||||
state: Cell<State<D>>,
|
||||
value: UnsafeCell<MaybeUninit<T>>,
|
||||
}
|
||||
|
||||
impl<T, D> Storage<T, D>
|
||||
@@ -35,7 +37,10 @@ where
|
||||
D: DestroyedState,
|
||||
{
|
||||
pub const fn new() -> Storage<T, D> {
|
||||
Storage { state: UnsafeCell::new(State::Initial) }
|
||||
Storage {
|
||||
state: Cell::new(State::Uninitialized),
|
||||
value: UnsafeCell::new(MaybeUninit::uninit()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets a pointer to the TLS value, potentially initializing it with the
|
||||
@@ -49,35 +54,49 @@ where
|
||||
/// The `self` reference must remain valid until the TLS destructor is run.
|
||||
#[inline]
|
||||
pub unsafe fn get_or_init(&self, i: Option<&mut Option<T>>, f: impl FnOnce() -> T) -> *const T {
|
||||
let state = unsafe { &*self.state.get() };
|
||||
match state {
|
||||
State::Alive(v) => v,
|
||||
State::Destroyed(_) => ptr::null(),
|
||||
State::Initial => unsafe { self.initialize(i, f) },
|
||||
if let State::Alive = self.state.get() {
|
||||
self.value.get().cast()
|
||||
} else {
|
||||
unsafe { self.get_or_init_slow(i, f) }
|
||||
}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
/// The `self` reference must remain valid until the TLS destructor is run.
|
||||
#[cold]
|
||||
unsafe fn initialize(&self, i: Option<&mut Option<T>>, f: impl FnOnce() -> T) -> *const T {
|
||||
// Perform initialization
|
||||
unsafe fn get_or_init_slow(
|
||||
&self,
|
||||
i: Option<&mut Option<T>>,
|
||||
f: impl FnOnce() -> T,
|
||||
) -> *const T {
|
||||
match self.state.get() {
|
||||
State::Uninitialized => {}
|
||||
State::Alive => return self.value.get().cast(),
|
||||
State::Destroyed(_) => return ptr::null(),
|
||||
}
|
||||
|
||||
let v = i.and_then(Option::take).unwrap_or_else(f);
|
||||
|
||||
let old = unsafe { self.state.get().replace(State::Alive(v)) };
|
||||
match old {
|
||||
// SAFETY: we cannot be inside a `LocalKey::with` scope, as the initializer
|
||||
// has already returned and the next scope only starts after we return
|
||||
// the pointer. Therefore, there can be no references to the old value,
|
||||
// even if it was initialized. Thus because we are !Sync we have exclusive
|
||||
// access to self.value and may replace it.
|
||||
let mut old_value = unsafe { self.value.get().replace(MaybeUninit::new(v)) };
|
||||
match self.state.replace(State::Alive) {
|
||||
// If the variable is not being recursively initialized, register
|
||||
// the destructor. This might be a noop if the value does not need
|
||||
// destruction.
|
||||
State::Initial => D::register_dtor(self),
|
||||
// Else, drop the old value. This might be changed to a panic.
|
||||
val => drop(val),
|
||||
State::Uninitialized => D::register_dtor(self),
|
||||
|
||||
// Recursive initialization, we only need to drop the old value
|
||||
// as we've already registered the destructor.
|
||||
State::Alive => unsafe { old_value.assume_init_drop() },
|
||||
|
||||
State::Destroyed(_) => unreachable!(),
|
||||
}
|
||||
|
||||
// SAFETY: the state was just set to `Alive`
|
||||
unsafe {
|
||||
let State::Alive(v) = &*self.state.get() else { unreachable_unchecked() };
|
||||
v
|
||||
}
|
||||
self.value.get().cast()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,9 +111,12 @@ unsafe extern "C" fn destroy<T>(ptr: *mut u8) {
|
||||
// Print a nice abort message if a panic occurs.
|
||||
abort_on_dtor_unwind(|| {
|
||||
let storage = unsafe { &*(ptr as *const Storage<T, ()>) };
|
||||
// Update the state before running the destructor as it may attempt to
|
||||
// access the variable.
|
||||
let val = unsafe { storage.state.get().replace(State::Destroyed(())) };
|
||||
drop(val);
|
||||
if let State::Alive = storage.state.replace(State::Destroyed(())) {
|
||||
// SAFETY: we ensured the state was Alive so the value was initialized.
|
||||
// We also updated the state to Destroyed to prevent the destructor
|
||||
// from accessing the thread-local variable, as this would violate
|
||||
// the exclusive access provided by &mut T in Drop::drop.
|
||||
unsafe { (*storage.value.get()).assume_init_drop() }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1409,7 +1409,7 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
|
||||
cargo.env("LLVM_LINKER_FLAGS", llvm_linker_flags);
|
||||
}
|
||||
|
||||
// Building with a static libstdc++ is only supported on linux right now,
|
||||
// Building with a static libstdc++ is only supported on Linux and windows-gnu* right now,
|
||||
// not for MSVC or macOS
|
||||
if builder.config.llvm_static_stdcpp
|
||||
&& !target.contains("freebsd")
|
||||
@@ -1417,12 +1417,14 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
|
||||
&& !target.contains("apple")
|
||||
&& !target.contains("solaris")
|
||||
{
|
||||
let libstdcxx_name =
|
||||
if target.contains("windows-gnullvm") { "libc++.a" } else { "libstdc++.a" };
|
||||
let file = compiler_file(
|
||||
builder,
|
||||
&builder.cxx(target).unwrap(),
|
||||
target,
|
||||
CLang::Cxx,
|
||||
"libstdc++.a",
|
||||
libstdcxx_name,
|
||||
);
|
||||
cargo.env("LLVM_STATIC_STDCPP", file);
|
||||
}
|
||||
|
||||
@@ -285,7 +285,8 @@ impl Step for Llvm {
|
||||
LlvmBuildStatus::ShouldBuild(m) => m,
|
||||
};
|
||||
|
||||
if builder.llvm_link_shared() && target.is_windows() {
|
||||
if builder.llvm_link_shared() && target.is_windows() && !target.ends_with("windows-gnullvm")
|
||||
{
|
||||
panic!("shared linking to LLVM is not currently supported on {}", target.triple);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,4 +29,5 @@ pub const RUSTC_PGO_CRATES: &[&str] = &[
|
||||
"tuple-stress",
|
||||
"diesel-2.2.10",
|
||||
"bitmaps-3.2.1",
|
||||
"serde-1.0.219-new-solver",
|
||||
];
|
||||
|
||||
@@ -53,8 +53,8 @@ MIRIFLAGS="-Zmiri-force-intrinsic-fallback --cfg force_intrinsic_fallback -O -Zm
|
||||
case $HOST_TARGET in
|
||||
x86_64-unknown-linux-gnu)
|
||||
# Only this branch runs in PR CI.
|
||||
# Fully test all main OSes, including a 32bit target.
|
||||
python3 "$X_PY" test --stage 2 src/tools/miri src/tools/miri/cargo-miri --target x86_64-apple-darwin
|
||||
# Fully test all main OSes, and all main architectures.
|
||||
python3 "$X_PY" test --stage 2 src/tools/miri src/tools/miri/cargo-miri --target aarch64-apple-darwin
|
||||
python3 "$X_PY" test --stage 2 src/tools/miri src/tools/miri/cargo-miri --target i686-pc-windows-msvc
|
||||
# Only run "pass" tests for the remaining targets, which is quite a bit faster.
|
||||
python3 "$X_PY" test --stage 2 src/tools/miri --target x86_64-pc-windows-gnu --test-args pass
|
||||
@@ -69,7 +69,7 @@ case $HOST_TARGET in
|
||||
#FIXME: Re-enable this once CI issues are fixed
|
||||
# See <https://github.com/rust-lang/rust/issues/127883>
|
||||
# For now, these tests are moved to `x86_64-msvc-ext2` in `src/ci/github-actions/jobs.yml`.
|
||||
#python3 "$X_PY" test --stage 2 src/tools/miri --target aarch64-apple-darwin --test-args pass
|
||||
#python3 "$X_PY" test --stage 2 src/tools/miri --target x86_64-apple-darwin --test-args pass
|
||||
;;
|
||||
*)
|
||||
echo "FATAL: unexpected host $HOST_TARGET"
|
||||
|
||||
@@ -530,11 +530,13 @@ auto:
|
||||
- name: x86_64-msvc-ext2
|
||||
env:
|
||||
SCRIPT: >
|
||||
python x.py test --stage 2 src/tools/miri --target aarch64-apple-darwin --test-args pass &&
|
||||
python x.py test --stage 2 src/tools/miri --target x86_64-apple-darwin --test-args pass &&
|
||||
python x.py test --stage 2 src/tools/miri --target x86_64-pc-windows-gnu --test-args pass &&
|
||||
python x.py miri --stage 2 library/core --test-args notest &&
|
||||
python x.py miri --stage 2 library/alloc --test-args notest &&
|
||||
python x.py miri --stage 2 library/std --test-args notest
|
||||
# The last 3 lines smoke-test `x.py miri`. This doesn't run any actual tests (that would take
|
||||
# too long), but it ensures that the crates build properly when tested with Miri.
|
||||
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-lld
|
||||
<<: *job-windows
|
||||
|
||||
|
||||
@@ -1749,7 +1749,7 @@ fn maybe_expand_private_type_alias<'tcx>(
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
let hir::ItemKind::TyAlias(_, ty, generics) = alias else { return None };
|
||||
let hir::ItemKind::TyAlias(_, generics, ty) = alias else { return None };
|
||||
|
||||
let final_seg = &path.segments.last().expect("segments were empty");
|
||||
let mut args = DefIdMap::default();
|
||||
@@ -2803,21 +2803,21 @@ fn clean_maybe_renamed_item<'tcx>(
|
||||
let mut name = get_name(cx, item, renamed).unwrap();
|
||||
|
||||
let kind = match item.kind {
|
||||
ItemKind::Static(_, ty, mutability, body_id) => StaticItem(Static {
|
||||
ItemKind::Static(mutability, _, ty, body_id) => StaticItem(Static {
|
||||
type_: Box::new(clean_ty(ty, cx)),
|
||||
mutability,
|
||||
expr: Some(body_id),
|
||||
}),
|
||||
ItemKind::Const(_, ty, generics, body_id) => ConstantItem(Box::new(Constant {
|
||||
ItemKind::Const(_, generics, ty, body_id) => ConstantItem(Box::new(Constant {
|
||||
generics: clean_generics(generics, cx),
|
||||
type_: clean_ty(ty, cx),
|
||||
kind: ConstantKind::Local { body: body_id, def_id },
|
||||
})),
|
||||
ItemKind::TyAlias(_, hir_ty, generics) => {
|
||||
ItemKind::TyAlias(_, generics, ty) => {
|
||||
*cx.current_type_aliases.entry(def_id).or_insert(0) += 1;
|
||||
let rustdoc_ty = clean_ty(hir_ty, cx);
|
||||
let rustdoc_ty = clean_ty(ty, cx);
|
||||
let type_ =
|
||||
clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, hir_ty)), cx, None, None);
|
||||
clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, ty)), cx, None, None);
|
||||
let generics = clean_generics(generics, cx);
|
||||
if let Some(count) = cx.current_type_aliases.get_mut(&def_id) {
|
||||
*count -= 1;
|
||||
@@ -2846,7 +2846,7 @@ fn clean_maybe_renamed_item<'tcx>(
|
||||
));
|
||||
return ret;
|
||||
}
|
||||
ItemKind::Enum(_, def, generics) => EnumItem(Enum {
|
||||
ItemKind::Enum(_, generics, def) => EnumItem(Enum {
|
||||
variants: def.variants.iter().map(|v| clean_variant(v, cx)).collect(),
|
||||
generics: clean_generics(generics, cx),
|
||||
}),
|
||||
@@ -2854,11 +2854,11 @@ fn clean_maybe_renamed_item<'tcx>(
|
||||
generics: clean_generics(generics, cx),
|
||||
bounds: bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
|
||||
}),
|
||||
ItemKind::Union(_, variant_data, generics) => UnionItem(Union {
|
||||
ItemKind::Union(_, generics, variant_data) => UnionItem(Union {
|
||||
generics: clean_generics(generics, cx),
|
||||
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
|
||||
}),
|
||||
ItemKind::Struct(_, variant_data, generics) => StructItem(Struct {
|
||||
ItemKind::Struct(_, generics, variant_data) => StructItem(Struct {
|
||||
ctor_kind: variant_data.ctor_kind(),
|
||||
generics: clean_generics(generics, cx),
|
||||
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
|
||||
|
||||
@@ -241,7 +241,7 @@ impl DocVisitor<'_> for CoverageCalculator<'_, '_> {
|
||||
data: hir::VariantData::Tuple(_, _, _),
|
||||
..
|
||||
}) | hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Struct(_, hir::VariantData::Tuple(_, _, _), _),
|
||||
kind: hir::ItemKind::Struct(_, _, hir::VariantData::Tuple(_, _, _)),
|
||||
..
|
||||
})
|
||||
)
|
||||
|
||||
@@ -272,7 +272,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
|
||||
return;
|
||||
}
|
||||
match &item.kind {
|
||||
ItemKind::Enum(_, enum_def, _generics) if self.enable_ordering_for_enum => {
|
||||
ItemKind::Enum(_, _generics, enum_def) if self.enable_ordering_for_enum => {
|
||||
let mut cur_v: Option<&Variant<'_>> = None;
|
||||
for variant in enum_def.variants {
|
||||
if variant.span.in_external_macro(cx.sess().source_map()) {
|
||||
@@ -288,7 +288,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
|
||||
cur_v = Some(variant);
|
||||
}
|
||||
},
|
||||
ItemKind::Struct(_, VariantData::Struct { fields, .. }, _generics) if self.enable_ordering_for_struct => {
|
||||
ItemKind::Struct(_, _generics, VariantData::Struct { fields, .. }) if self.enable_ordering_for_struct => {
|
||||
let mut cur_f: Option<&FieldDef<'_>> = None;
|
||||
for field in *fields {
|
||||
if field.span.in_external_macro(cx.sess().source_map()) {
|
||||
|
||||
@@ -92,7 +92,7 @@ impl_lint_pass!(EmptyWithBrackets => [EMPTY_STRUCTS_WITH_BRACKETS, EMPTY_ENUM_VA
|
||||
|
||||
impl LateLintPass<'_> for EmptyWithBrackets {
|
||||
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
|
||||
if let ItemKind::Struct(ident, var_data, _) = &item.kind
|
||||
if let ItemKind::Struct(ident, _, var_data) = &item.kind
|
||||
&& !item.span.from_expansion()
|
||||
&& has_brackets(var_data)
|
||||
&& let span_after_ident = item.span.with_lo(ident.span.hi())
|
||||
|
||||
@@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant {
|
||||
if cx.tcx.data_layout.pointer_size.bits() != 64 {
|
||||
return;
|
||||
}
|
||||
if let ItemKind::Enum(_, def, _) = &item.kind {
|
||||
if let ItemKind::Enum(_, _, def) = &item.kind {
|
||||
for var in def.variants {
|
||||
if let Some(anon_const) = &var.disr_expr {
|
||||
let def_id = cx.tcx.hir_body_owner_def_id(anon_const.body);
|
||||
|
||||
@@ -127,7 +127,7 @@ fn check_fn_decl(cx: &LateContext<'_>, decl: &FnDecl<'_>, sp: Span, max: u64) {
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for ExcessiveBools {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
||||
if let ItemKind::Struct(_, variant_data, _) = &item.kind
|
||||
if let ItemKind::Struct(_, _, variant_data) = &item.kind
|
||||
&& variant_data.fields().len() as u64 > self.max_struct_bools
|
||||
&& has_n_bools(
|
||||
variant_data.fields().iter().map(|field| field.ty),
|
||||
|
||||
@@ -76,7 +76,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
|
||||
"exported enums should not be exhaustive",
|
||||
[].as_slice(),
|
||||
),
|
||||
ItemKind::Struct(_, v, ..) => (
|
||||
ItemKind::Struct(_, _, v) => (
|
||||
EXHAUSTIVE_STRUCTS,
|
||||
"exported structs should not be exhaustive",
|
||||
v.fields(),
|
||||
|
||||
@@ -103,7 +103,7 @@ fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty
|
||||
.did()
|
||||
.as_local()
|
||||
&& let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(local_def_id)
|
||||
&& let hir::ItemKind::Enum(_, ref def, _) = item.kind
|
||||
&& let hir::ItemKind::Enum(_, _, ref def) = item.kind
|
||||
{
|
||||
let variants_size = AdtVariantInfo::new(cx, *adt, subst);
|
||||
if let Some((first_variant, variants)) = variants_size.split_first()
|
||||
|
||||
@@ -535,10 +535,10 @@ impl LateLintPass<'_> for ItemNameRepetitions {
|
||||
|
||||
if span_is_local(item.span) {
|
||||
match item.kind {
|
||||
ItemKind::Enum(_, def, _) => {
|
||||
ItemKind::Enum(_, _, def) => {
|
||||
self.check_variants(cx, item, &def);
|
||||
},
|
||||
ItemKind::Struct(_, VariantData::Struct { fields, .. }, _) => {
|
||||
ItemKind::Struct(_, _, VariantData::Struct { fields, .. }) => {
|
||||
self.check_fields(cx, item, fields);
|
||||
},
|
||||
_ => (),
|
||||
|
||||
@@ -48,7 +48,7 @@ impl_lint_pass!(LargeConstArrays => [LARGE_CONST_ARRAYS]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
if let ItemKind::Const(ident, _, generics, _) = &item.kind
|
||||
if let ItemKind::Const(ident, generics, _, _) = &item.kind
|
||||
// Since static items may not have generics, skip generic const items.
|
||||
// FIXME(generic_const_items): I don't think checking `generics.hwcp` suffices as it
|
||||
// doesn't account for empty where-clauses that only consist of keyword `where` IINM.
|
||||
|
||||
@@ -73,7 +73,7 @@ impl_lint_pass!(LargeEnumVariant => [LARGE_ENUM_VARIANT]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) {
|
||||
if let ItemKind::Enum(ident, ref def, _) = item.kind
|
||||
if let ItemKind::Enum(ident, _, ref def) = item.kind
|
||||
&& let ty = cx.tcx.type_of(item.owner_id).instantiate_identity()
|
||||
&& let ty::Adt(adt, subst) = ty.kind()
|
||||
&& adt.variants().len() > 1
|
||||
|
||||
@@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustive {
|
||||
}
|
||||
|
||||
match item.kind {
|
||||
ItemKind::Enum(_, def, _) if def.variants.len() > 1 => {
|
||||
ItemKind::Enum(_, _, def) if def.variants.len() > 1 => {
|
||||
let iter = def.variants.iter().filter_map(|v| {
|
||||
(matches!(v.data, VariantData::Unit(_, _)) && is_doc_hidden(cx.tcx.hir_attrs(v.hir_id)))
|
||||
.then_some((v.def_id, v.span))
|
||||
@@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustive {
|
||||
self.potential_enums.push((item.owner_id.def_id, id, item.span, span));
|
||||
}
|
||||
},
|
||||
ItemKind::Struct(_, variant_data, _) => {
|
||||
ItemKind::Struct(_, _, variant_data) => {
|
||||
let fields = variant_data.fields();
|
||||
let private_fields = fields
|
||||
.iter()
|
||||
|
||||
@@ -225,7 +225,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug {
|
||||
&& let typeck_results = cx.tcx.typeck_body(*body_id)
|
||||
&& should_lint(cx, typeck_results, block)
|
||||
// we intentionally only lint structs, see lint description
|
||||
&& let ItemKind::Struct(_, data, _) = &self_item.kind
|
||||
&& let ItemKind::Struct(_, _, data) = &self_item.kind
|
||||
{
|
||||
check_struct(cx, typeck_results, block, self_ty, item, data);
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ struct LazyInfo {
|
||||
impl LazyInfo {
|
||||
fn from_item(cx: &LateContext<'_>, item: &Item<'_>) -> Option<Self> {
|
||||
// Check if item is a `once_cell:sync::Lazy` static.
|
||||
if let ItemKind::Static(_, ty, _, body_id) = item.kind
|
||||
if let ItemKind::Static(_, _, ty, body_id) = item.kind
|
||||
&& let Some(path_def_id) = path_def_id(cx, ty)
|
||||
&& let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind
|
||||
&& paths::ONCE_CELL_SYNC_LAZY.matches(cx, path_def_id)
|
||||
|
||||
@@ -58,7 +58,7 @@ impl PubUnderscoreFields {
|
||||
impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
// This lint only pertains to structs.
|
||||
let ItemKind::Struct(_, variant_data, _) = &item.kind else {
|
||||
let ItemKind::Struct(_, _, variant_data) = &item.kind else {
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for TrailingEmptyArray {
|
||||
}
|
||||
|
||||
fn is_struct_with_trailing_zero_sized_array<'tcx>(cx: &LateContext<'tcx>, item: &Item<'tcx>) -> bool {
|
||||
if let ItemKind::Struct(_, data, _) = &item.kind
|
||||
if let ItemKind::Struct(_, _, data) = &item.kind
|
||||
&& let Some(last_field) = data.fields().last()
|
||||
&& let field_ty = cx.tcx.normalize_erasing_regions(
|
||||
cx.typing_env(),
|
||||
|
||||
@@ -447,7 +447,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
|
||||
let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id);
|
||||
|
||||
match item.kind {
|
||||
ItemKind::Static(_, ty, _, _) | ItemKind::Const(_, ty, _, _) => self.check_ty(
|
||||
ItemKind::Static(_, _, ty, _) | ItemKind::Const(_, _, ty, _) => self.check_ty(
|
||||
cx,
|
||||
ty,
|
||||
CheckTyContext {
|
||||
|
||||
@@ -134,7 +134,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms {
|
||||
ItemKind::TyAlias(ident, ..) | ItemKind::Struct(ident, ..) | ItemKind::Trait(_, _, ident, ..) => {
|
||||
check_ident(cx, &ident, it.hir_id(), self.upper_case_acronyms_aggressive);
|
||||
},
|
||||
ItemKind::Enum(ident, ref enumdef, _) => {
|
||||
ItemKind::Enum(ident, _, ref enumdef) => {
|
||||
check_ident(cx, &ident, it.hir_id(), self.upper_case_acronyms_aggressive);
|
||||
// check enum variants separately because again we only want to lint on private enums and
|
||||
// the fn check_variant does not know about the vis of the enum of its variants
|
||||
|
||||
@@ -249,7 +249,7 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) {
|
||||
ItemKind::ForeignMod { .. } => (Pat::Str("extern"), Pat::Str("}")),
|
||||
ItemKind::TyAlias(..) => (Pat::Str("type"), Pat::Str(";")),
|
||||
ItemKind::Enum(..) => (Pat::Str("enum"), Pat::Str("}")),
|
||||
ItemKind::Struct(_, VariantData::Struct { .. }, _) => (Pat::Str("struct"), Pat::Str("}")),
|
||||
ItemKind::Struct(_, _, VariantData::Struct { .. }) => (Pat::Str("struct"), Pat::Str("}")),
|
||||
ItemKind::Struct(..) => (Pat::Str("struct"), Pat::Str(";")),
|
||||
ItemKind::Union(..) => (Pat::Str("union"), Pat::Str("}")),
|
||||
ItemKind::Trait(_, Safety::Unsafe, ..)
|
||||
|
||||
@@ -2362,7 +2362,7 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl FnOnce(&
|
||||
for id in tcx.hir_module_free_items(module) {
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Const)
|
||||
&& let item = tcx.hir_item(id)
|
||||
&& let ItemKind::Const(ident, ty, _generics, _body) = item.kind
|
||||
&& let ItemKind::Const(ident, _generics, ty, _body) = item.kind
|
||||
&& let TyKind::Path(QPath::Resolved(_, path)) = ty.kind
|
||||
// We could also check for the type name `test::TestDescAndFn`
|
||||
&& let Res::Def(DefKind::Struct, _) = path.res
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![warn(clippy::map_flatten)]
|
||||
#![feature(result_flattening)]
|
||||
|
||||
//@no-rustfix
|
||||
// issue #8506, multi-line
|
||||
#[rustfmt::skip]
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#![feature(result_flattening)]
|
||||
#![allow(
|
||||
clippy::let_underscore_untyped,
|
||||
clippy::missing_docs_in_private_items,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#![feature(result_flattening)]
|
||||
#![allow(
|
||||
clippy::let_underscore_untyped,
|
||||
clippy::missing_docs_in_private_items,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error: called `map(..).flatten()` on `Iterator`
|
||||
--> tests/ui/map_flatten_fixable.rs:17:47
|
||||
--> tests/ui/map_flatten_fixable.rs:16:47
|
||||
|
|
||||
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id)`
|
||||
@@ -8,43 +8,43 @@ LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().coll
|
||||
= help: to override `-D warnings` add `#[allow(clippy::map_flatten)]`
|
||||
|
||||
error: called `map(..).flatten()` on `Iterator`
|
||||
--> tests/ui/map_flatten_fixable.rs:19:47
|
||||
--> tests/ui/map_flatten_fixable.rs:18:47
|
||||
|
|
||||
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_ref).flatten().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id_ref)`
|
||||
|
||||
error: called `map(..).flatten()` on `Iterator`
|
||||
--> tests/ui/map_flatten_fixable.rs:21:47
|
||||
--> tests/ui/map_flatten_fixable.rs:20:47
|
||||
|
|
||||
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_closure).flatten().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id_closure)`
|
||||
|
||||
error: called `map(..).flatten()` on `Iterator`
|
||||
--> tests/ui/map_flatten_fixable.rs:23:47
|
||||
--> tests/ui/map_flatten_fixable.rs:22:47
|
||||
|
|
||||
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| x.checked_add(1)).flatten().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(|x| x.checked_add(1))`
|
||||
|
||||
error: called `map(..).flatten()` on `Iterator`
|
||||
--> tests/ui/map_flatten_fixable.rs:27:47
|
||||
--> tests/ui/map_flatten_fixable.rs:26:47
|
||||
|
|
||||
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `flat_map` and remove the `.flatten()`: `flat_map(|x| 0..x)`
|
||||
|
||||
error: called `map(..).flatten()` on `Option`
|
||||
--> tests/ui/map_flatten_fixable.rs:31:40
|
||||
--> tests/ui/map_flatten_fixable.rs:30:40
|
||||
|
|
||||
LL | let _: Option<_> = (Some(Some(1))).map(|x| x).flatten();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|x| x)`
|
||||
|
||||
error: called `map(..).flatten()` on `Result`
|
||||
--> tests/ui/map_flatten_fixable.rs:35:42
|
||||
--> tests/ui/map_flatten_fixable.rs:34:42
|
||||
|
|
||||
LL | let _: Result<_, &str> = (Ok(Ok(1))).map(|x| x).flatten();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|x| x)`
|
||||
|
||||
error: called `map(..).flatten()` on `Iterator`
|
||||
--> tests/ui/map_flatten_fixable.rs:45:10
|
||||
--> tests/ui/map_flatten_fixable.rs:44:10
|
||||
|
|
||||
LL | .map(|n| match n {
|
||||
| __________^
|
||||
@@ -74,7 +74,7 @@ LL ~ });
|
||||
|
|
||||
|
||||
error: called `map(..).flatten()` on `Option`
|
||||
--> tests/ui/map_flatten_fixable.rs:66:10
|
||||
--> tests/ui/map_flatten_fixable.rs:65:10
|
||||
|
|
||||
LL | .map(|_| {
|
||||
| __________^
|
||||
|
||||
@@ -159,67 +159,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
this.write_scalar(Scalar::from_bool(branch), dest)?;
|
||||
}
|
||||
|
||||
"floorf16" | "ceilf16" | "truncf16" | "roundf16" | "round_ties_even_f16" => {
|
||||
let [f] = check_intrinsic_arg_count(args)?;
|
||||
let f = this.read_scalar(f)?.to_f16()?;
|
||||
let mode = match intrinsic_name {
|
||||
"floorf16" => Round::TowardNegative,
|
||||
"ceilf16" => Round::TowardPositive,
|
||||
"truncf16" => Round::TowardZero,
|
||||
"roundf16" => Round::NearestTiesToAway,
|
||||
"round_ties_even_f16" => Round::NearestTiesToEven,
|
||||
_ => bug!(),
|
||||
};
|
||||
let res = f.round_to_integral(mode).value;
|
||||
let res = this.adjust_nan(res, &[f]);
|
||||
this.write_scalar(res, dest)?;
|
||||
}
|
||||
"floorf32" | "ceilf32" | "truncf32" | "roundf32" | "round_ties_even_f32" => {
|
||||
let [f] = check_intrinsic_arg_count(args)?;
|
||||
let f = this.read_scalar(f)?.to_f32()?;
|
||||
let mode = match intrinsic_name {
|
||||
"floorf32" => Round::TowardNegative,
|
||||
"ceilf32" => Round::TowardPositive,
|
||||
"truncf32" => Round::TowardZero,
|
||||
"roundf32" => Round::NearestTiesToAway,
|
||||
"round_ties_even_f32" => Round::NearestTiesToEven,
|
||||
_ => bug!(),
|
||||
};
|
||||
let res = f.round_to_integral(mode).value;
|
||||
let res = this.adjust_nan(res, &[f]);
|
||||
this.write_scalar(res, dest)?;
|
||||
}
|
||||
"floorf64" | "ceilf64" | "truncf64" | "roundf64" | "round_ties_even_f64" => {
|
||||
let [f] = check_intrinsic_arg_count(args)?;
|
||||
let f = this.read_scalar(f)?.to_f64()?;
|
||||
let mode = match intrinsic_name {
|
||||
"floorf64" => Round::TowardNegative,
|
||||
"ceilf64" => Round::TowardPositive,
|
||||
"truncf64" => Round::TowardZero,
|
||||
"roundf64" => Round::NearestTiesToAway,
|
||||
"round_ties_even_f64" => Round::NearestTiesToEven,
|
||||
_ => bug!(),
|
||||
};
|
||||
let res = f.round_to_integral(mode).value;
|
||||
let res = this.adjust_nan(res, &[f]);
|
||||
this.write_scalar(res, dest)?;
|
||||
}
|
||||
"floorf128" | "ceilf128" | "truncf128" | "roundf128" | "round_ties_even_f128" => {
|
||||
let [f] = check_intrinsic_arg_count(args)?;
|
||||
let f = this.read_scalar(f)?.to_f128()?;
|
||||
let mode = match intrinsic_name {
|
||||
"floorf128" => Round::TowardNegative,
|
||||
"ceilf128" => Round::TowardPositive,
|
||||
"truncf128" => Round::TowardZero,
|
||||
"roundf128" => Round::NearestTiesToAway,
|
||||
"round_ties_even_f128" => Round::NearestTiesToEven,
|
||||
_ => bug!(),
|
||||
};
|
||||
let res = f.round_to_integral(mode).value;
|
||||
let res = this.adjust_nan(res, &[f]);
|
||||
this.write_scalar(res, dest)?;
|
||||
}
|
||||
|
||||
"sqrtf32" => {
|
||||
let [f] = check_intrinsic_arg_count(args)?;
|
||||
let f = this.read_scalar(f)?.to_f32()?;
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
digraph graph_for_def_id_0_3 {
|
||||
graph[fontname="Courier, monospace"];
|
||||
node[fontname="Courier, monospace"];
|
||||
edge[fontname="Courier, monospace"];
|
||||
bb_0[label=<<table border="1" cellborder="1" cellspacing="0" cellpadding="3" sides="rb"><tr><td colspan="3" sides="tl">bb0</td></tr><tr><td colspan="2" bgcolor="#a0a0a0" sides="tl">MIR</td><td bgcolor="#a0a0a0" sides="tl">STATE</td></tr><tr><td valign="bottom" sides="tl" align="right"></td><td valign="bottom" sides="tl" align="left">(on start)</td><td colspan="1" valign="bottom" sides="tl" align="left">{}</td></tr><tr><td valign="top" sides="tl" bgcolor="#f0f0f0" align="right">0</td><td valign="top" sides="tl" bgcolor="#f0f0f0" align="left">_0 = const ()</td><td valign="top" sides="tl" bgcolor="#f0f0f0" align="left"><font color="darkgreen">+_0</font></td></tr><tr><td valign="top" sides="tl" align="right">T</td><td valign="top" sides="tl" align="left">return</td><td valign="top" sides="tl" align="left"></td></tr><tr><td valign="bottom" sides="tl" bgcolor="#f0f0f0" align="right"></td><td valign="bottom" sides="tl" bgcolor="#f0f0f0" align="left">(on end)</td><td colspan="1" valign="bottom" sides="tl" bgcolor="#f0f0f0" align="left">{_0}</td></tr></table>>][shape="none"];
|
||||
}
|
||||
6
tests/mir-opt/dataflow.main.maybe_uninit.borrowck.dot
Normal file
6
tests/mir-opt/dataflow.main.maybe_uninit.borrowck.dot
Normal file
@@ -0,0 +1,6 @@
|
||||
digraph graph_for_def_id_0_3 {
|
||||
graph[fontname="Courier, monospace"];
|
||||
node[fontname="Courier, monospace"];
|
||||
edge[fontname="Courier, monospace"];
|
||||
bb_0[label=<<table border="1" cellborder="1" cellspacing="0" cellpadding="3" sides="rb"><tr><td colspan="3" sides="tl">bb0</td></tr><tr><td colspan="2" bgcolor="#a0a0a0" sides="tl">MIR</td><td bgcolor="#a0a0a0" sides="tl">STATE</td></tr><tr><td valign="bottom" sides="tl" align="right"></td><td valign="bottom" sides="tl" align="left">(on start)</td><td colspan="1" valign="bottom" sides="tl" align="left">{_0}</td></tr><tr><td valign="top" sides="tl" bgcolor="#f0f0f0" align="right">0</td><td valign="top" sides="tl" bgcolor="#f0f0f0" align="left">_0 = const ()</td><td valign="top" sides="tl" bgcolor="#f0f0f0" align="left"><font color="red">-_0</font></td></tr><tr><td valign="top" sides="tl" align="right">T</td><td valign="top" sides="tl" align="left">return</td><td valign="top" sides="tl" align="left"></td></tr><tr><td valign="bottom" sides="tl" bgcolor="#f0f0f0" align="right"></td><td valign="bottom" sides="tl" bgcolor="#f0f0f0" align="left">(on end)</td><td colspan="1" valign="bottom" sides="tl" bgcolor="#f0f0f0" align="left">{}</td></tr></table>>][shape="none"];
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
// Test graphviz dataflow output
|
||||
//@ compile-flags: -Z dump-mir=main -Z dump-mir-dataflow
|
||||
|
||||
// EMIT_MIR dataflow.main.maybe_init.borrowck.dot
|
||||
// EMIT_MIR dataflow.main.maybe_uninit.borrowck.dot
|
||||
fn main() {}
|
||||
|
||||
@@ -263,3 +263,24 @@ pub fn get_metadata(a: *const i32, b: *const [u8], c: *const dyn std::fmt::Debug
|
||||
let _usize = ptr_metadata(b);
|
||||
let _vtable = ptr_metadata(c);
|
||||
}
|
||||
|
||||
// EMIT_MIR lower_intrinsics.slice_get.LowerIntrinsics.diff
|
||||
pub unsafe fn slice_get<'a, 'b>(
|
||||
r: &'a [i8],
|
||||
rm: &'b mut [i16],
|
||||
p: *const [i32],
|
||||
pm: *mut [i64],
|
||||
i: usize,
|
||||
) -> (&'a i8, &'b mut i16, *const i32, *mut i64) {
|
||||
use std::intrinsics::slice_get_unchecked;
|
||||
// CHECK: = &(*_{{[0-9]+}})[_{{[0-9]+}}]
|
||||
// CHECK: = &mut (*_{{[0-9]+}})[_{{[0-9]+}}]
|
||||
// CHECK: = &raw const (*_{{[0-9]+}})[_{{[0-9]+}}]
|
||||
// CHECK: = &raw mut (*_{{[0-9]+}})[_{{[0-9]+}}]
|
||||
(
|
||||
slice_get_unchecked(r, i),
|
||||
slice_get_unchecked(rm, i),
|
||||
slice_get_unchecked(p, i),
|
||||
slice_get_unchecked(pm, i),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
- // MIR for `slice_get` before LowerIntrinsics
|
||||
+ // MIR for `slice_get` after LowerIntrinsics
|
||||
|
||||
fn slice_get(_1: &[i8], _2: &mut [i16], _3: *const [i32], _4: *mut [i64], _5: usize) -> (&i8, &mut i16, *const i32, *mut i64) {
|
||||
debug r => _1;
|
||||
debug rm => _2;
|
||||
debug p => _3;
|
||||
debug pm => _4;
|
||||
debug i => _5;
|
||||
let mut _0: (&i8, &mut i16, *const i32, *mut i64);
|
||||
let mut _6: &i8;
|
||||
let mut _7: &[i8];
|
||||
let mut _8: usize;
|
||||
let mut _9: &mut i16;
|
||||
let mut _10: &mut [i16];
|
||||
let mut _11: usize;
|
||||
let mut _12: *const i32;
|
||||
let mut _13: *const [i32];
|
||||
let mut _14: usize;
|
||||
let mut _15: *mut i64;
|
||||
let mut _16: *mut [i64];
|
||||
let mut _17: usize;
|
||||
|
||||
bb0: {
|
||||
StorageLive(_6);
|
||||
StorageLive(_7);
|
||||
_7 = copy _1;
|
||||
StorageLive(_8);
|
||||
_8 = copy _5;
|
||||
- _6 = slice_get_unchecked::<&i8, &[i8], i8>(move _7, move _8) -> [return: bb1, unwind unreachable];
|
||||
+ _6 = &(*_7)[_8];
|
||||
+ goto -> bb1;
|
||||
}
|
||||
|
||||
bb1: {
|
||||
StorageDead(_8);
|
||||
StorageDead(_7);
|
||||
StorageLive(_9);
|
||||
StorageLive(_10);
|
||||
_10 = move _2;
|
||||
StorageLive(_11);
|
||||
_11 = copy _5;
|
||||
- _9 = slice_get_unchecked::<&mut i16, &mut [i16], i16>(move _10, move _11) -> [return: bb2, unwind unreachable];
|
||||
+ _9 = &mut (*_10)[_11];
|
||||
+ goto -> bb2;
|
||||
}
|
||||
|
||||
bb2: {
|
||||
StorageDead(_11);
|
||||
StorageDead(_10);
|
||||
StorageLive(_12);
|
||||
StorageLive(_13);
|
||||
_13 = copy _3;
|
||||
StorageLive(_14);
|
||||
_14 = copy _5;
|
||||
- _12 = slice_get_unchecked::<*const i32, *const [i32], i32>(move _13, move _14) -> [return: bb3, unwind unreachable];
|
||||
+ _12 = &raw const (*_13)[_14];
|
||||
+ goto -> bb3;
|
||||
}
|
||||
|
||||
bb3: {
|
||||
StorageDead(_14);
|
||||
StorageDead(_13);
|
||||
StorageLive(_15);
|
||||
StorageLive(_16);
|
||||
_16 = copy _4;
|
||||
StorageLive(_17);
|
||||
_17 = copy _5;
|
||||
- _15 = slice_get_unchecked::<*mut i64, *mut [i64], i64>(move _16, move _17) -> [return: bb4, unwind unreachable];
|
||||
+ _15 = &raw mut (*_16)[_17];
|
||||
+ goto -> bb4;
|
||||
}
|
||||
|
||||
bb4: {
|
||||
StorageDead(_17);
|
||||
StorageDead(_16);
|
||||
_0 = (move _6, move _9, move _12, move _15);
|
||||
StorageDead(_15);
|
||||
StorageDead(_12);
|
||||
StorageDead(_9);
|
||||
StorageDead(_6);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
- // MIR for `slice_get` before LowerIntrinsics
|
||||
+ // MIR for `slice_get` after LowerIntrinsics
|
||||
|
||||
fn slice_get(_1: &[i8], _2: &mut [i16], _3: *const [i32], _4: *mut [i64], _5: usize) -> (&i8, &mut i16, *const i32, *mut i64) {
|
||||
debug r => _1;
|
||||
debug rm => _2;
|
||||
debug p => _3;
|
||||
debug pm => _4;
|
||||
debug i => _5;
|
||||
let mut _0: (&i8, &mut i16, *const i32, *mut i64);
|
||||
let mut _6: &i8;
|
||||
let mut _7: &[i8];
|
||||
let mut _8: usize;
|
||||
let mut _9: &mut i16;
|
||||
let mut _10: &mut [i16];
|
||||
let mut _11: usize;
|
||||
let mut _12: *const i32;
|
||||
let mut _13: *const [i32];
|
||||
let mut _14: usize;
|
||||
let mut _15: *mut i64;
|
||||
let mut _16: *mut [i64];
|
||||
let mut _17: usize;
|
||||
|
||||
bb0: {
|
||||
StorageLive(_6);
|
||||
StorageLive(_7);
|
||||
_7 = copy _1;
|
||||
StorageLive(_8);
|
||||
_8 = copy _5;
|
||||
- _6 = slice_get_unchecked::<&i8, &[i8], i8>(move _7, move _8) -> [return: bb1, unwind unreachable];
|
||||
+ _6 = &(*_7)[_8];
|
||||
+ goto -> bb1;
|
||||
}
|
||||
|
||||
bb1: {
|
||||
StorageDead(_8);
|
||||
StorageDead(_7);
|
||||
StorageLive(_9);
|
||||
StorageLive(_10);
|
||||
_10 = move _2;
|
||||
StorageLive(_11);
|
||||
_11 = copy _5;
|
||||
- _9 = slice_get_unchecked::<&mut i16, &mut [i16], i16>(move _10, move _11) -> [return: bb2, unwind unreachable];
|
||||
+ _9 = &mut (*_10)[_11];
|
||||
+ goto -> bb2;
|
||||
}
|
||||
|
||||
bb2: {
|
||||
StorageDead(_11);
|
||||
StorageDead(_10);
|
||||
StorageLive(_12);
|
||||
StorageLive(_13);
|
||||
_13 = copy _3;
|
||||
StorageLive(_14);
|
||||
_14 = copy _5;
|
||||
- _12 = slice_get_unchecked::<*const i32, *const [i32], i32>(move _13, move _14) -> [return: bb3, unwind unreachable];
|
||||
+ _12 = &raw const (*_13)[_14];
|
||||
+ goto -> bb3;
|
||||
}
|
||||
|
||||
bb3: {
|
||||
StorageDead(_14);
|
||||
StorageDead(_13);
|
||||
StorageLive(_15);
|
||||
StorageLive(_16);
|
||||
_16 = copy _4;
|
||||
StorageLive(_17);
|
||||
_17 = copy _5;
|
||||
- _15 = slice_get_unchecked::<*mut i64, *mut [i64], i64>(move _16, move _17) -> [return: bb4, unwind unreachable];
|
||||
+ _15 = &raw mut (*_16)[_17];
|
||||
+ goto -> bb4;
|
||||
}
|
||||
|
||||
bb4: {
|
||||
StorageDead(_17);
|
||||
StorageDead(_16);
|
||||
_0 = (move _6, move _9, move _12, move _15);
|
||||
StorageDead(_15);
|
||||
StorageDead(_12);
|
||||
StorageDead(_9);
|
||||
StorageDead(_6);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,19 +8,11 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> {
|
||||
scope 2 (inlined <usize as SliceIndex<[u32]>>::get_mut) {
|
||||
let mut _3: usize;
|
||||
let mut _4: bool;
|
||||
let mut _5: *mut [u32];
|
||||
let mut _7: *mut u32;
|
||||
let mut _8: &mut u32;
|
||||
scope 3 (inlined core::slice::index::get_mut_noubcheck::<u32>) {
|
||||
let _6: *mut u32;
|
||||
scope 4 {
|
||||
}
|
||||
}
|
||||
let mut _5: &mut u32;
|
||||
}
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_8);
|
||||
StorageLive(_4);
|
||||
StorageLive(_3);
|
||||
_3 = PtrMetadata(copy _1);
|
||||
@@ -36,23 +28,15 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> {
|
||||
|
||||
bb2: {
|
||||
StorageDead(_3);
|
||||
StorageLive(_7);
|
||||
StorageLive(_5);
|
||||
_5 = &raw mut (*_1);
|
||||
StorageLive(_6);
|
||||
_6 = copy _5 as *mut u32 (PtrToPtr);
|
||||
_7 = Offset(copy _6, copy _2);
|
||||
StorageDead(_6);
|
||||
_5 = &mut (*_1)[_2];
|
||||
_0 = Option::<&mut u32>::Some(move _5);
|
||||
StorageDead(_5);
|
||||
_8 = &mut (*_7);
|
||||
_0 = Option::<&mut u32>::Some(copy _8);
|
||||
StorageDead(_7);
|
||||
goto -> bb3;
|
||||
}
|
||||
|
||||
bb3: {
|
||||
StorageDead(_4);
|
||||
StorageDead(_8);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,19 +8,11 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> {
|
||||
scope 2 (inlined <usize as SliceIndex<[u32]>>::get_mut) {
|
||||
let mut _3: usize;
|
||||
let mut _4: bool;
|
||||
let mut _5: *mut [u32];
|
||||
let mut _7: *mut u32;
|
||||
let mut _8: &mut u32;
|
||||
scope 3 (inlined core::slice::index::get_mut_noubcheck::<u32>) {
|
||||
let _6: *mut u32;
|
||||
scope 4 {
|
||||
}
|
||||
}
|
||||
let mut _5: &mut u32;
|
||||
}
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_8);
|
||||
StorageLive(_4);
|
||||
StorageLive(_3);
|
||||
_3 = PtrMetadata(copy _1);
|
||||
@@ -36,23 +28,15 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> {
|
||||
|
||||
bb2: {
|
||||
StorageDead(_3);
|
||||
StorageLive(_7);
|
||||
StorageLive(_5);
|
||||
_5 = &raw mut (*_1);
|
||||
StorageLive(_6);
|
||||
_6 = copy _5 as *mut u32 (PtrToPtr);
|
||||
_7 = Offset(copy _6, copy _2);
|
||||
StorageDead(_6);
|
||||
_5 = &mut (*_1)[_2];
|
||||
_0 = Option::<&mut u32>::Some(move _5);
|
||||
StorageDead(_5);
|
||||
_8 = &mut (*_7);
|
||||
_0 = Option::<&mut u32>::Some(copy _8);
|
||||
StorageDead(_7);
|
||||
goto -> bb3;
|
||||
}
|
||||
|
||||
bb3: {
|
||||
StorageDead(_4);
|
||||
StorageDead(_8);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,10 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
|
||||
let _8: usize;
|
||||
scope 3 {
|
||||
scope 6 (inlined core::slice::index::get_offset_len_mut_noubcheck::<u32>) {
|
||||
let _10: *mut u32;
|
||||
let _9: *mut u32;
|
||||
scope 7 {
|
||||
}
|
||||
scope 8 (inlined core::slice::index::get_mut_noubcheck::<u32>) {
|
||||
let _9: *mut u32;
|
||||
scope 9 {
|
||||
let _10: *mut u32;
|
||||
scope 8 {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,13 +45,13 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
|
||||
bb1: {
|
||||
StorageDead(_6);
|
||||
_8 = SubUnchecked(copy _4, copy _3);
|
||||
StorageLive(_10);
|
||||
StorageLive(_9);
|
||||
StorageLive(_10);
|
||||
_9 = copy _5 as *mut u32 (PtrToPtr);
|
||||
_10 = Offset(copy _9, copy _3);
|
||||
StorageDead(_9);
|
||||
_11 = *mut [u32] from (copy _10, copy _8);
|
||||
StorageDead(_10);
|
||||
StorageDead(_9);
|
||||
StorageDead(_8);
|
||||
StorageDead(_5);
|
||||
_0 = &mut (*_11);
|
||||
|
||||
@@ -15,12 +15,10 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
|
||||
let _8: usize;
|
||||
scope 3 {
|
||||
scope 6 (inlined core::slice::index::get_offset_len_mut_noubcheck::<u32>) {
|
||||
let _10: *mut u32;
|
||||
let _9: *mut u32;
|
||||
scope 7 {
|
||||
}
|
||||
scope 8 (inlined core::slice::index::get_mut_noubcheck::<u32>) {
|
||||
let _9: *mut u32;
|
||||
scope 9 {
|
||||
let _10: *mut u32;
|
||||
scope 8 {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,13 +45,13 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
|
||||
bb1: {
|
||||
StorageDead(_6);
|
||||
_8 = SubUnchecked(copy _4, copy _3);
|
||||
StorageLive(_10);
|
||||
StorageLive(_9);
|
||||
StorageLive(_10);
|
||||
_9 = copy _5 as *mut u32 (PtrToPtr);
|
||||
_10 = Offset(copy _9, copy _3);
|
||||
StorageDead(_9);
|
||||
_11 = *mut [u32] from (copy _10, copy _8);
|
||||
StorageDead(_10);
|
||||
StorageDead(_9);
|
||||
StorageDead(_8);
|
||||
StorageDead(_5);
|
||||
_0 = &mut (*_11);
|
||||
|
||||
@@ -13,12 +13,10 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range<usize>) -
|
||||
let _7: usize;
|
||||
scope 3 {
|
||||
scope 6 (inlined core::slice::index::get_offset_len_noubcheck::<u32>) {
|
||||
let _9: *const u32;
|
||||
let _8: *const u32;
|
||||
scope 7 {
|
||||
}
|
||||
scope 8 (inlined core::slice::index::get_noubcheck::<u32>) {
|
||||
let _8: *const u32;
|
||||
scope 9 {
|
||||
let _9: *const u32;
|
||||
scope 8 {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,13 +40,13 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range<usize>) -
|
||||
bb1: {
|
||||
StorageDead(_5);
|
||||
_7 = SubUnchecked(copy _4, copy _3);
|
||||
StorageLive(_9);
|
||||
StorageLive(_8);
|
||||
StorageLive(_9);
|
||||
_8 = copy _1 as *const u32 (PtrToPtr);
|
||||
_9 = Offset(copy _8, copy _3);
|
||||
StorageDead(_8);
|
||||
_0 = *const [u32] from (copy _9, copy _7);
|
||||
StorageDead(_9);
|
||||
StorageDead(_8);
|
||||
StorageDead(_7);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,12 +13,10 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range<usize>) -
|
||||
let _7: usize;
|
||||
scope 3 {
|
||||
scope 6 (inlined core::slice::index::get_offset_len_noubcheck::<u32>) {
|
||||
let _9: *const u32;
|
||||
let _8: *const u32;
|
||||
scope 7 {
|
||||
}
|
||||
scope 8 (inlined core::slice::index::get_noubcheck::<u32>) {
|
||||
let _8: *const u32;
|
||||
scope 9 {
|
||||
let _9: *const u32;
|
||||
scope 8 {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,13 +40,13 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range<usize>) -
|
||||
bb1: {
|
||||
StorageDead(_5);
|
||||
_7 = SubUnchecked(copy _4, copy _3);
|
||||
StorageLive(_9);
|
||||
StorageLive(_8);
|
||||
StorageLive(_9);
|
||||
_8 = copy _1 as *const u32 (PtrToPtr);
|
||||
_9 = Offset(copy _8, copy _3);
|
||||
StorageDead(_8);
|
||||
_0 = *const [u32] from (copy _9, copy _7);
|
||||
StorageDead(_9);
|
||||
StorageDead(_8);
|
||||
StorageDead(_7);
|
||||
return;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user