diff options
Diffstat (limited to 'compiler')
34 files changed, 360 insertions, 593 deletions
diff --git a/compiler/rustc_borrowck/src/borrow_set.rs b/compiler/rustc_borrowck/src/borrow_set.rs index a8ade54732f..16b3d901956 100644 --- a/compiler/rustc_borrowck/src/borrow_set.rs +++ b/compiler/rustc_borrowck/src/borrow_set.rs @@ -20,18 +20,18 @@ pub struct BorrowSet<'tcx> { /// by the `Location` of the assignment statement in which it /// appears on the right hand side. Thus the location is the map /// key, and its position in the map corresponds to `BorrowIndex`. - pub location_map: FxIndexMap<Location, BorrowData<'tcx>>, + pub(crate) location_map: FxIndexMap<Location, BorrowData<'tcx>>, /// Locations which activate borrows. /// NOTE: a given location may activate more than one borrow in the future /// when more general two-phase borrow support is introduced, but for now we /// only need to store one borrow index. - pub activation_map: FxIndexMap<Location, Vec<BorrowIndex>>, + pub(crate) activation_map: FxIndexMap<Location, Vec<BorrowIndex>>, /// Map from local to all the borrows on that local. - pub local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>, + pub(crate) local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>, - pub locals_state_at_exit: LocalsStateAtExit, + pub(crate) locals_state_at_exit: LocalsStateAtExit, } impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> { @@ -45,7 +45,7 @@ impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> { /// Location where a two-phase borrow is activated, if a borrow /// is in fact a two-phase borrow. #[derive(Copy, Clone, PartialEq, Eq, Debug)] -pub enum TwoPhaseActivation { +pub(crate) enum TwoPhaseActivation { NotTwoPhase, NotActivated, ActivatedAt(Location), @@ -55,17 +55,17 @@ pub enum TwoPhaseActivation { pub struct BorrowData<'tcx> { /// Location where the borrow reservation starts. /// In many cases, this will be equal to the activation location but not always. - pub reserve_location: Location, + pub(crate) reserve_location: Location, /// Location where the borrow is activated. - pub activation_location: TwoPhaseActivation, + pub(crate) activation_location: TwoPhaseActivation, /// What kind of borrow this is - pub kind: mir::BorrowKind, + pub(crate) kind: mir::BorrowKind, /// The region for which this borrow is live - pub region: RegionVid, + pub(crate) region: RegionVid, /// Place from which we are borrowing - pub borrowed_place: mir::Place<'tcx>, + pub(crate) borrowed_place: mir::Place<'tcx>, /// Place to which the borrow was stored - pub assigned_place: mir::Place<'tcx>, + pub(crate) assigned_place: mir::Place<'tcx>, } impl<'tcx> fmt::Display for BorrowData<'tcx> { @@ -120,7 +120,7 @@ impl LocalsStateAtExit { } impl<'tcx> BorrowSet<'tcx> { - pub fn build( + pub(crate) fn build( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, locals_are_invalidated_at_exit: bool, @@ -156,7 +156,7 @@ impl<'tcx> BorrowSet<'tcx> { self.activation_map.get(&location).map_or(&[], |activations| &activations[..]) } - pub fn len(&self) -> usize { + pub(crate) fn len(&self) -> usize { self.location_map.len() } diff --git a/compiler/rustc_borrowck/src/constraints/mod.rs b/compiler/rustc_borrowck/src/constraints/mod.rs index ca435ee0865..a52269df682 100644 --- a/compiler/rustc_borrowck/src/constraints/mod.rs +++ b/compiler/rustc_borrowck/src/constraints/mod.rs @@ -210,7 +210,7 @@ impl<'tcx> fmt::Debug for OutlivesConstraint<'tcx> { rustc_index::newtype_index! { #[debug_format = "OutlivesConstraintIndex({})"] - pub struct OutlivesConstraintIndex {} + pub(crate) struct OutlivesConstraintIndex {} } rustc_index::newtype_index! { diff --git a/compiler/rustc_borrowck/src/dataflow.rs b/compiler/rustc_borrowck/src/dataflow.rs index 89ff12c1479..d832decc170 100644 --- a/compiler/rustc_borrowck/src/dataflow.rs +++ b/compiler/rustc_borrowck/src/dataflow.rs @@ -254,8 +254,8 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> { let sccs = self.regioncx.constraint_sccs(); let universal_regions = self.regioncx.universal_regions(); - // We first handle the cases where the loan doesn't go out of scope, depending on the issuing - // region's successors. + // We first handle the cases where the loan doesn't go out of scope, depending on the + // issuing region's successors. for successor in graph::depth_first_search(&self.regioncx.region_graph(), issuing_region) { // 1. Via applied member constraints // diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index 2fa752384a1..0897d140d60 100644 --- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -3,7 +3,6 @@ use std::rc::Rc; use rustc_errors::Diag; use rustc_hir::def_id::LocalDefId; -use rustc_infer::infer::canonical::CanonicalQueryInput; use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData}; use rustc_infer::infer::{ InferCtxt, RegionResolutionError, RegionVariableOrigin, SubregionOrigin, TyCtxtInferExt as _, @@ -21,7 +20,6 @@ use rustc_span::Span; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::error_reporting::infer::nice_region_error::NiceRegionError; use rustc_trait_selection::traits::ObligationCtxt; -use rustc_trait_selection::traits::query::type_op; use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_cause}; use tracing::{debug, instrument}; @@ -31,12 +29,9 @@ use crate::session_diagnostics::{ HigherRankedErrorCause, HigherRankedLifetimeError, HigherRankedSubtypeError, }; -#[derive(Clone)] -pub(crate) struct UniverseInfo<'tcx>(UniverseInfoInner<'tcx>); - /// What operation a universe was created for. #[derive(Clone)] -enum UniverseInfoInner<'tcx> { +pub(crate) enum UniverseInfo<'tcx> { /// Relating two types which have binders. RelateTys { expected: Ty<'tcx>, found: Ty<'tcx> }, /// Created from performing a `TypeOp`. @@ -47,11 +42,11 @@ enum UniverseInfoInner<'tcx> { impl<'tcx> UniverseInfo<'tcx> { pub(crate) fn other() -> UniverseInfo<'tcx> { - UniverseInfo(UniverseInfoInner::Other) + UniverseInfo::Other } pub(crate) fn relate(expected: Ty<'tcx>, found: Ty<'tcx>) -> UniverseInfo<'tcx> { - UniverseInfo(UniverseInfoInner::RelateTys { expected, found }) + UniverseInfo::RelateTys { expected, found } } pub(crate) fn report_error( @@ -61,8 +56,8 @@ impl<'tcx> UniverseInfo<'tcx> { error_element: RegionElement, cause: ObligationCause<'tcx>, ) { - match self.0 { - UniverseInfoInner::RelateTys { expected, found } => { + match *self { + UniverseInfo::RelateTys { expected, found } => { let err = mbcx.infcx.err_ctxt().report_mismatched_types( &cause, mbcx.param_env, @@ -72,10 +67,10 @@ impl<'tcx> UniverseInfo<'tcx> { ); mbcx.buffer_error(err); } - UniverseInfoInner::TypeOp(ref type_op_info) => { + UniverseInfo::TypeOp(ref type_op_info) => { type_op_info.report_error(mbcx, placeholder, error_element, cause); } - UniverseInfoInner::Other => { + UniverseInfo::Other => { // FIXME: This error message isn't great, but it doesn't show // up in the existing UI tests. Consider investigating this // some more. @@ -93,19 +88,16 @@ pub(crate) trait ToUniverseInfo<'tcx> { impl<'tcx> ToUniverseInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> { fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> { - UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(crate::type_check::InstantiateOpaqueType { + UniverseInfo::TypeOp(Rc::new(crate::type_check::InstantiateOpaqueType { base_universe: Some(base_universe), ..self - }))) + })) } } impl<'tcx> ToUniverseInfo<'tcx> for CanonicalTypeOpProvePredicateGoal<'tcx> { fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> { - UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(PredicateQuery { - canonical_query: self, - base_universe, - }))) + UniverseInfo::TypeOp(Rc::new(PredicateQuery { canonical_query: self, base_universe })) } } @@ -113,26 +105,13 @@ impl<'tcx, T: Copy + fmt::Display + TypeFoldable<TyCtxt<'tcx>> + 'tcx> ToUnivers for CanonicalTypeOpNormalizeGoal<'tcx, T> { fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> { - UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(NormalizeQuery { - canonical_query: self, - base_universe, - }))) + UniverseInfo::TypeOp(Rc::new(NormalizeQuery { canonical_query: self, base_universe })) } } impl<'tcx> ToUniverseInfo<'tcx> for CanonicalTypeOpAscribeUserTypeGoal<'tcx> { fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> { - UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(AscribeUserTypeQuery { - canonical_query: self, - base_universe, - }))) - } -} - -impl<'tcx, F> ToUniverseInfo<'tcx> for CanonicalQueryInput<'tcx, type_op::custom::CustomTypeOp<F>> { - fn to_universe_info(self, _base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> { - // We can't rerun custom type ops. - UniverseInfo::other() + UniverseInfo::TypeOp(Rc::new(AscribeUserTypeQuery { canonical_query: self, base_universe })) } } @@ -143,7 +122,7 @@ impl<'tcx> ToUniverseInfo<'tcx> for ! { } #[allow(unused_lifetimes)] -trait TypeOpInfo<'tcx> { +pub(crate) trait TypeOpInfo<'tcx> { /// Returns an error to be reported if rerunning the type op fails to /// recover the error's cause. fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx>; @@ -289,8 +268,8 @@ where // `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the // `ObligationCause`. The normalization results are currently different between // `QueryNormalizeExt::query_normalize` used in the query and `normalize` called below: - // the former fails to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test. - // Check after #85499 lands to see if its fixes have erased this difference. + // the former fails to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` + // test. Check after #85499 lands to see if its fixes have erased this difference. let (param_env, value) = key.into_parts(); let _ = ocx.normalize(&cause, param_env, value.value); diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 511313cca6f..e5b28289faa 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -1345,11 +1345,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { // See `tests/ui/moves/needs-clone-through-deref.rs` return false; } - // We don't want to suggest `.clone()` in a move closure, since the value has already been captured. + // We don't want to suggest `.clone()` in a move closure, since the value has already been + // captured. if self.in_move_closure(expr) { return false; } - // We also don't want to suggest cloning a closure itself, since the value has already been captured. + // We also don't want to suggest cloning a closure itself, since the value has already been + // captured. if let hir::ExprKind::Closure(_) = expr.kind { return false; } @@ -1381,7 +1383,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { } } } - // Cloning the raw pointer doesn't make sense in some cases and would cause a type mismatch error. (see #126863) + // Cloning the raw pointer doesn't make sense in some cases and would cause a type mismatch + // error. (see #126863) if inner_expr.span.lo() != expr.span.lo() && !is_raw_ptr { // Remove "(*" or "(&" sugg.push((expr.span.with_hi(inner_expr.span.lo()), String::new())); @@ -1553,8 +1556,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { let use_spans = self.move_spans(place.as_ref(), location); let span = use_spans.var_or_use(); - // If the attempted use is in a closure then we do not care about the path span of the place we are currently trying to use - // we call `var_span_label` on `borrow_spans` to annotate if the existing borrow was in a closure + // If the attempted use is in a closure then we do not care about the path span of the + // place we are currently trying to use we call `var_span_label` on `borrow_spans` to + // annotate if the existing borrow was in a closure. let mut err = self.cannot_use_when_mutably_borrowed( span, &self.describe_any_place(place.as_ref()), @@ -2480,7 +2484,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { if let hir::ExprKind::Closure(closure) = ex.kind && ex.span.contains(self.borrow_span) // To support cases like `|| { v.call(|this| v.get()) }` - // FIXME: actually support such cases (need to figure out how to move from the capture place to original local) + // FIXME: actually support such cases (need to figure out how to move from the + // capture place to original local). && self.res.as_ref().map_or(true, |(prev_res, _)| prev_res.span.contains(ex.span)) { self.res = Some((ex, closure)); @@ -2733,7 +2738,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { /// cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as /// mutable (via `a.u.s.b`) [E0502] /// ``` - pub(crate) fn describe_place_for_conflicting_borrow( + fn describe_place_for_conflicting_borrow( &self, first_borrowed_place: Place<'tcx>, second_borrowed_place: Place<'tcx>, @@ -3188,8 +3193,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { /// misleading users in cases like `tests/ui/nll/borrowed-temporary-error.rs`. /// We could expand the analysis to suggest hoising all of the relevant parts of /// the users' code to make the code compile, but that could be too much. - /// We found the `prop_expr` by the way to check whether the expression is a `FormatArguments`, - /// which is a special case since it's generated by the compiler. + /// We found the `prop_expr` by the way to check whether the expression is a + /// `FormatArguments`, which is a special case since it's generated by the + /// compiler. struct NestedStatementVisitor<'tcx> { span: Span, current: usize, @@ -3420,7 +3426,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { let (sugg_span, suggestion) = match tcx.sess.source_map().span_to_snippet(args_span) { Ok(string) => { let coro_prefix = if string.starts_with("async") { - // `async` is 5 chars long. Not using `.len()` to avoid the cast from `usize` to `u32` + // `async` is 5 chars long. Not using `.len()` to avoid the cast from `usize` + // to `u32`. Some(5) } else if string.starts_with("gen") { // `gen` is 3 chars long @@ -3618,10 +3625,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { let stmt_kind = self.body[location.block].statements.get(location.statement_index).map(|s| &s.kind); if let Some(StatementKind::StorageDead(..)) = stmt_kind { - // this analysis only tries to find moves explicitly - // written by the user, so we ignore the move-outs - // created by `StorageDead` and at the beginning - // of a function. + // This analysis only tries to find moves explicitly written by the user, so we + // ignore the move-outs created by `StorageDead` and at the beginning of a + // function. } else { // If we are found a use of a.b.c which was in error, then we want to look for // moves not only of a.b.c but also a.b and a. @@ -3706,13 +3712,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { } } if (is_argument || !reached_start) && result.is_empty() { - /* Process back edges (moves in future loop iterations) only if - the move path is definitely initialized upon loop entry, - to avoid spurious "in previous iteration" errors. - During DFS, if there's a path from the error back to the start - of the function with no intervening init or move, then the - move path may be uninitialized at loop entry. - */ + // Process back edges (moves in future loop iterations) only if + // the move path is definitely initialized upon loop entry, + // to avoid spurious "in previous iteration" errors. + // During DFS, if there's a path from the error back to the start + // of the function with no intervening init or move, then the + // move path may be uninitialized at loop entry. while let Some(location) = back_edge_stack.pop() { if dfs_iter(&mut result, location, true) { continue; diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index 31a5d451ff6..45a8ef0adb6 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -130,7 +130,8 @@ impl<'tcx> BorrowExplanation<'tcx> { { suggest_rewrite_if_let(tcx, expr, &pat, init, conseq, alt, err); } else if path_span.map_or(true, |path_span| path_span == var_or_use_span) { - // We can use `var_or_use_span` if either `path_span` is not present, or both spans are the same + // We can use `var_or_use_span` if either `path_span` is not present, or both + // spans are the same. if borrow_span.map_or(true, |sp| !sp.overlaps(var_or_use_span)) { err.span_label( var_or_use_span, @@ -165,7 +166,8 @@ impl<'tcx> BorrowExplanation<'tcx> { LaterUseKind::FakeLetRead => "borrow later stored here", LaterUseKind::Other => "borrow used here, in later iteration of loop", }; - // We can use `var_or_use_span` if either `path_span` is not present, or both spans are the same + // We can use `var_or_use_span` if either `path_span` is not present, or both spans + // are the same. if path_span.map(|path_span| path_span == var_or_use_span).unwrap_or(true) { err.span_label(var_or_use_span, format!("{borrow_desc}{message}")); } else { @@ -285,7 +287,8 @@ impl<'tcx> BorrowExplanation<'tcx> { span: _, pat, init, - // FIXME(#101728): enable rewrite when type ascription is stabilized again + // FIXME(#101728): enable rewrite when type ascription is + // stabilized again. ty: None, recovered: _, }) = cond.kind @@ -353,8 +356,8 @@ impl<'tcx> BorrowExplanation<'tcx> { unsize_ty: Ty<'tcx>, ) { if let ty::Adt(def, args) = unsize_ty.kind() { - // We try to elaborate the object lifetime defaults and present those to the user. This should - // make it clear where the region constraint is coming from. + // We try to elaborate the object lifetime defaults and present those to the user. This + // should make it clear where the region constraint is coming from. let generics = tcx.generics_of(def.did()); let mut has_dyn = false; @@ -531,9 +534,10 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { let mut use_in_later_iteration_of_loop = false; if region_sub == borrow_region_vid { - // When `region_sub` is the same as `borrow_region_vid` (the location where the borrow is - // issued is the same location that invalidates the reference), this is likely a loop iteration - // - in this case, try using the loop terminator location in `find_sub_region_live_at`. + // When `region_sub` is the same as `borrow_region_vid` (the location where the borrow + // is issued is the same location that invalidates the reference), this is likely a + // loop iteration. In this case, try using the loop terminator location in + // `find_sub_region_live_at`. if let Some(loop_terminator_location) = regioncx.find_loop_terminator_location(borrow.region, body) { diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 07b3c295eaa..0797bb49bf9 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -763,7 +763,7 @@ impl<'tcx> BorrowedContentSource<'tcx> { } } -///helper struct for explain_captures() +/// Helper struct for `explain_captures`. struct CapturedMessageOpt { is_partial_move: bool, is_loop_message: bool, diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 33bd4f37b7f..a2194a1cf2a 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -793,7 +793,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { let reason = if let PlaceBase::Upvar(upvar_id) = closure_kind_origin.base { let upvar = ty::place_to_string_for_capture(tcx, closure_kind_origin); let root_hir_id = upvar_id.var_path.hir_id; - // we have an origin for this closure kind starting at this root variable so it's safe to unwrap here + // We have an origin for this closure kind starting at this root variable so it's + // safe to unwrap here. let captured_places = tables.closure_min_captures[&closure_local_def_id].get(&root_hir_id).unwrap(); @@ -966,8 +967,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { } }; - // If we can detect the expression to be an function or method call where the closure was an argument, - // we point at the function or method definition argument... + // If we can detect the expression to be an function or method call where the closure was + // an argument, we point at the function or method definition argument... if let Some((callee_def_id, call_span, call_args)) = get_call_details() { let arg_pos = call_args .iter() diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 6ca7251295d..8a2987b6d4a 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -30,8 +30,8 @@ pub(crate) struct RegionName { } /// Denotes the source of a region that is named by a `RegionName`. For example, a free region that -/// was named by the user would get `NamedLateParamRegion` and `'static` lifetime would get `Static`. -/// This helps to print the right kinds of diagnostics. +/// was named by the user would get `NamedLateParamRegion` and `'static` lifetime would get +/// `Static`. This helps to print the right kinds of diagnostics. #[derive(Debug, Clone, Copy)] pub(crate) enum RegionNameSource { /// A bound (not free) region that was instantiated at the def site (not an HRTB). @@ -825,8 +825,8 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { /// async fn foo() -> i32 { 2 } /// ``` /// - /// this function, given the lowered return type of `foo`, an [`OpaqueDef`] that implements `Future<Output=i32>`, - /// returns the `i32`. + /// this function, given the lowered return type of `foo`, an [`OpaqueDef`] that implements + /// `Future<Output=i32>`, returns the `i32`. /// /// [`OpaqueDef`]: hir::TyKind::OpaqueDef fn get_future_inner_return_ty(&self, hir_ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> { diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index ae23f004593..657e6e0907c 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -20,7 +20,6 @@ use std::collections::BTreeMap; use std::marker::PhantomData; use std::ops::Deref; -use consumers::{BodyWithBorrowckFacts, ConsumerOptions}; use rustc_abi::FieldIdx; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::graph::dominators::Dominators; @@ -49,13 +48,21 @@ use rustc_span::{Span, Symbol}; use smallvec::SmallVec; use tracing::{debug, instrument}; -use self::diagnostics::{AccessKind, IllegalMoveOriginKind, MoveError, RegionName}; -use self::location::LocationTable; -use self::path_utils::*; -use self::prefixes::PrefixSet; +use crate::borrow_set::{BorrowData, BorrowSet}; +use crate::consumers::{BodyWithBorrowckFacts, ConsumerOptions}; +use crate::dataflow::{BorrowIndex, BorrowckDomain, BorrowckResults, Borrows}; +use crate::diagnostics::{AccessKind, IllegalMoveOriginKind, MoveError, RegionName}; +use crate::location::LocationTable; +use crate::nll::PoloniusOutput; +use crate::path_utils::*; +use crate::place_ext::PlaceExt; +use crate::places_conflict::{PlaceConflictBias, places_conflict}; +use crate::prefixes::PrefixSet; +use crate::region_infer::RegionInferenceContext; +use crate::renumber::RegionCtxt; use crate::session_diagnostics::VarNeedNotMut; -pub mod borrow_set; +mod borrow_set; mod borrowck_errors; mod constraints; mod dataflow; @@ -81,18 +88,11 @@ mod util; /// A public API provided for the Rust compiler consumers. pub mod consumers; -use borrow_set::{BorrowData, BorrowSet}; -use dataflow::{BorrowIndex, BorrowckDomain, BorrowckResults, Borrows}; -use nll::PoloniusOutput; -use place_ext::PlaceExt; -use places_conflict::{PlaceConflictBias, places_conflict}; -use region_infer::RegionInferenceContext; -use renumber::RegionCtxt; - rustc_fluent_macro::fluent_messages! { "../messages.ftl" } /// Associate some local constants with the `'tcx` lifetime struct TyCtxtConsts<'tcx>(PhantomData<&'tcx ()>); + impl<'tcx> TyCtxtConsts<'tcx> { const DEREF_PROJECTION: &'tcx [PlaceElem<'tcx>; 1] = &[ProjectionElem::Deref]; } @@ -162,7 +162,7 @@ fn do_mir_borrowck<'tcx>( } } - let mut diags = diags::BorrowckDiags::new(); + let diags = &mut diags::BorrowckDiags::new(); // Gather the upvars of a closure, if any. if let Some(e) = input_body.tainted_by_errors { @@ -227,14 +227,7 @@ fn do_mir_borrowck<'tcx>( // We also have a `#[rustc_regions]` annotation that causes us to dump // information. - nll::dump_annotation( - &infcx, - body, - ®ioncx, - &opt_closure_req, - &opaque_type_values, - &mut diags, - ); + nll::dump_annotation(&infcx, body, ®ioncx, &opt_closure_req, &opaque_type_values, diags); // The various `flow_*` structures can be large. We drop `flow_inits` here // so it doesn't overlap with the others below. This reduces peak memory @@ -299,7 +292,6 @@ fn do_mir_borrowck<'tcx>( }; MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body); promoted_mbcx.report_move_errors(); - diags = promoted_mbcx.diags; struct MoveVisitor<'a, 'b, 'infcx, 'tcx> { ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>, @@ -434,7 +426,7 @@ fn do_mir_borrowck<'tcx>( (result, body_with_facts) } -pub struct BorrowckInferCtxt<'tcx> { +pub(crate) struct BorrowckInferCtxt<'tcx> { pub(crate) infcx: InferCtxt<'tcx>, pub(crate) reg_var_to_origin: RefCell<FxIndexMap<ty::RegionVid, RegionCtxt>>, } @@ -587,7 +579,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> { /// Results of Polonius analysis. polonius_output: Option<Box<PoloniusOutput>>, - diags: diags::BorrowckDiags<'infcx, 'tcx>, + diags: &'a mut diags::BorrowckDiags<'infcx, 'tcx>, move_errors: Vec<MoveError<'tcx>>, } @@ -638,7 +630,9 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R> ); } StatementKind::Intrinsic(box kind) => match kind { - NonDivergingIntrinsic::Assume(op) => self.consume_operand(location, (op, span), state), + NonDivergingIntrinsic::Assume(op) => { + self.consume_operand(location, (op, span), state); + } NonDivergingIntrinsic::CopyNonOverlapping(..) => span_bug!( span, "Unexpected CopyNonOverlapping, should only appear after lower_intrinsics", @@ -2105,7 +2099,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> { | Write(WriteKind::MutableBorrow(BorrowKind::Mut { kind: mut_borrow_kind })) => { let is_local_mutation_allowed = match mut_borrow_kind { // `ClosureCapture` is used for mutable variable with an immutable binding. - // This is only behaviour difference between `ClosureCapture` and mutable borrows. + // This is only behaviour difference between `ClosureCapture` and mutable + // borrows. MutBorrowKind::ClosureCapture => LocalMutationIsAllowed::Yes, MutBorrowKind::Default | MutBorrowKind::TwoPhaseBorrow => { is_local_mutation_allowed @@ -2350,23 +2345,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> { ) => Err(place), (Mutability::Not, LocalMutationIsAllowed::Yes) | (Mutability::Mut, _) => { - // Subtle: this is an upvar - // reference, so it looks like - // `self.foo` -- we want to double - // check that the location `*self` - // is mutable (i.e., this is not a - // `Fn` closure). But if that - // check succeeds, we want to - // *blame* the mutability on - // `place` (that is, - // `self.foo`). This is used to - // propagate the info about - // whether mutability declarations - // are used outwards, so that we register - // the outer variable as mutable. Otherwise a - // test like this fails to record the `mut` - // as needed: - // + // Subtle: this is an upvar reference, so it looks like + // `self.foo` -- we want to double check that the location + // `*self` is mutable (i.e., this is not a `Fn` closure). But + // if that check succeeds, we want to *blame* the mutability on + // `place` (that is, `self.foo`). This is used to propagate the + // info about whether mutability declarations are used + // outwards, so that we register the outer variable as mutable. + // Otherwise a test like this fails to record the `mut` as + // needed: // ``` // fn foo<F: FnOnce()>(_f: F) { } // fn main() { @@ -2511,7 +2498,7 @@ mod diags { // Buffer any move errors that we collected and de-duplicated. for (_, (_, diag)) in std::mem::take(&mut self.diags.buffered_move_errors) { // We have already set tainted for this error, so just buffer it. - self.diags.buffered_diags.push(BufferedDiag::Error(diag)); + self.diags.buffer_error(diag); } for (_, (mut diag, count)) in std::mem::take(&mut self.diags.buffered_mut_errors) { if count > 10 { @@ -2519,7 +2506,7 @@ mod diags { #[allow(rustc::untranslatable_diagnostic)] diag.note(format!("...and {} other attempted mutable borrows", count - 10)); } - self.diags.buffered_diags.push(BufferedDiag::Error(diag)); + self.diags.buffer_error(diag); } if !self.diags.buffered_diags.is_empty() { diff --git a/compiler/rustc_borrowck/src/prefixes.rs b/compiler/rustc_borrowck/src/prefixes.rs index aeb8a6c014a..fc7e6e58641 100644 --- a/compiler/rustc_borrowck/src/prefixes.rs +++ b/compiler/rustc_borrowck/src/prefixes.rs @@ -53,7 +53,7 @@ impl<'tcx> Iterator for Prefixes<'tcx> { // may hold one further down (e.g., we never return // downcasts here, but may return a base of a downcast). - 'cursor: loop { + loop { match cursor.last_projection() { None => { self.next = None; @@ -72,7 +72,6 @@ impl<'tcx> Iterator for Prefixes<'tcx> { | ProjectionElem::ConstantIndex { .. } | ProjectionElem::Index(_) => { cursor = cursor_base; - continue 'cursor; } ProjectionElem::Subtype(..) => { panic!("Subtype projection is not allowed before borrow check") diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index d5c2796932e..7e317ea6554 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -99,9 +99,9 @@ impl RegionTracker { pub(crate) fn new(rvid: RegionVid, definition: &RegionDefinition<'_>) -> Self { let (representative_is_placeholder, representative_is_existential) = match definition.origin { - rustc_infer::infer::NllRegionVariableOrigin::FreeRegion => (false, false), - rustc_infer::infer::NllRegionVariableOrigin::Placeholder(_) => (true, false), - rustc_infer::infer::NllRegionVariableOrigin::Existential { .. } => (false, true), + NllRegionVariableOrigin::FreeRegion => (false, false), + NllRegionVariableOrigin::Placeholder(_) => (true, false), + NllRegionVariableOrigin::Existential { .. } => (false, true), }; let placeholder_universe = @@ -553,7 +553,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { } /// Returns an iterator over all the region indices. - pub fn regions(&self) -> impl Iterator<Item = RegionVid> + 'tcx { + pub(crate) fn regions(&self) -> impl Iterator<Item = RegionVid> + 'tcx { self.definitions.indices() } @@ -561,12 +561,14 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// corresponding index. /// /// (Panics if `r` is not a registered universal region.) - pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid { + pub(crate) fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid { self.universal_regions.to_region_vid(r) } /// Returns an iterator over all the outlives constraints. - pub fn outlives_constraints(&self) -> impl Iterator<Item = OutlivesConstraint<'tcx>> + '_ { + pub(crate) fn outlives_constraints( + &self, + ) -> impl Iterator<Item = OutlivesConstraint<'tcx>> + '_ { self.constraints.outlives().iter().copied() } @@ -1495,6 +1497,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn scc_universe(&self, scc: ConstraintSccIndex) -> UniverseIndex { self.constraint_sccs().annotation(scc).min_universe() } + /// Checks the final value for the free region `fr` to see if it /// grew too large. In particular, examine what `end(X)` points /// wound up in `fr`'s final value; for each `end(X)` where `X != @@ -1667,7 +1670,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { placeholder, }); - // Stop after the first error, it gets too noisy otherwise, and does not provide more information. + // Stop after the first error, it gets too noisy otherwise, and does not provide more + // information. break; } debug!("check_bound_universal_region: all bounds satisfied"); @@ -2000,8 +2004,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { // We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint. // Instead, we use it to produce an improved `ObligationCauseCode`. - // FIXME - determine what we should do if we encounter multiple `ConstraintCategory::Predicate` - // constraints. Currently, we just pick the first one. + // FIXME - determine what we should do if we encounter multiple + // `ConstraintCategory::Predicate` constraints. Currently, we just pick the first one. let cause_code = path .iter() .find_map(|constraint| { diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index 3a2f5c35c72..f9dd649ab9f 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -145,9 +145,9 @@ impl<'tcx> RegionInferenceContext<'tcx> { continue; } // Sometimes two opaque types are the same only after we remap the generic parameters - // back to the opaque type definition. E.g. we may have `OpaqueType<X, Y>` mapped to `(X, Y)` - // and `OpaqueType<Y, X>` mapped to `(Y, X)`, and those are the same, but we only know that - // once we convert the generic parameters to those of the opaque type. + // back to the opaque type definition. E.g. we may have `OpaqueType<X, Y>` mapped to + // `(X, Y)` and `OpaqueType<Y, X>` mapped to `(Y, X)`, and those are the same, but we + // only know that once we convert the generic parameters to those of the opaque type. if let Some(prev) = result.get_mut(&opaque_type_key.def_id) { if prev.ty != ty { let guar = ty.error_reported().err().unwrap_or_else(|| { diff --git a/compiler/rustc_borrowck/src/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs index 662e6fa46b5..519edfafda5 100644 --- a/compiler/rustc_borrowck/src/region_infer/values.rs +++ b/compiler/rustc_borrowck/src/region_infer/values.rs @@ -15,7 +15,7 @@ use crate::BorrowIndex; rustc_index::newtype_index! { /// A single integer representing a `ty::Placeholder`. #[debug_format = "PlaceholderIndex({})"] - pub struct PlaceholderIndex {} + pub(crate) struct PlaceholderIndex {} } /// An individual element in a region value -- the value of a diff --git a/compiler/rustc_borrowck/src/type_check/canonical.rs b/compiler/rustc_borrowck/src/type_check/canonical.rs index fde68615cc0..aee13ca8cd7 100644 --- a/compiler/rustc_borrowck/src/type_check/canonical.rs +++ b/compiler/rustc_borrowck/src/type_check/canonical.rs @@ -62,7 +62,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { { let universe_info = error_info.to_universe_info(old_universe); for u in (old_universe + 1)..=universe { - self.borrowck_context.constraints.universe_causes.insert(u, universe_info.clone()); + self.constraints.universe_causes.insert(u, universe_info.clone()); } } diff --git a/compiler/rustc_borrowck/src/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs index 141f251244b..7effd5c5a68 100644 --- a/compiler/rustc_borrowck/src/type_check/input_output.rs +++ b/compiler/rustc_borrowck/src/type_check/input_output.rs @@ -48,9 +48,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // FIXME(async_closures): It's kind of wacky that we must apply this // transformation here, since we do the same thing in HIR typeck. // Maybe we could just fix up the canonicalized signature during HIR typeck? - if let DefiningTy::CoroutineClosure(_, args) = - self.borrowck_context.universal_regions.defining_ty - { + if let DefiningTy::CoroutineClosure(_, args) = self.universal_regions.defining_ty { assert_matches!( self.tcx().coroutine_kind(self.tcx().coroutine_for_closure(mir_def_id)), Some(hir::CoroutineKind::Desugared( @@ -59,8 +57,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { )), "this needs to be modified if we're lowering non-async closures" ); - // Make sure to use the args from `DefiningTy` so the right NLL region vids are prepopulated - // into the type. + // Make sure to use the args from `DefiningTy` so the right NLL region vids are + // prepopulated into the type. let args = args.as_coroutine_closure(); let tupled_upvars_ty = ty::CoroutineClosureSignature::tupled_upvars_by_closure_kind( self.tcx(), @@ -195,8 +193,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // doing so ends up causing some other trouble. let b = self.normalize(b, Locations::All(span)); - // Note: if we have to introduce new placeholders during normalization above, then we won't have - // added those universes to the universe info, which we would want in `relate_tys`. + // Note: if we have to introduce new placeholders during normalization above, then we + // won't have added those universes to the universe info, which we would want in + // `relate_tys`. if let Err(terr) = self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation) { diff --git a/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs b/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs index ccd9fb25739..695a1cdac0d 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs @@ -137,56 +137,22 @@ struct LocalUseMapBuild<'me> { locals_with_use_data: IndexVec<Local, bool>, } -impl LocalUseMapBuild<'_> { - fn insert_def(&mut self, local: Local, location: Location) { - Self::insert( - self.elements, - &mut self.local_use_map.first_def_at[local], - &mut self.local_use_map.appearances, - location, - ); - } - - fn insert_use(&mut self, local: Local, location: Location) { - Self::insert( - self.elements, - &mut self.local_use_map.first_use_at[local], - &mut self.local_use_map.appearances, - location, - ); - } - - fn insert_drop(&mut self, local: Local, location: Location) { - Self::insert( - self.elements, - &mut self.local_use_map.first_drop_at[local], - &mut self.local_use_map.appearances, - location, - ); - } - - fn insert( - elements: &DenseLocationMap, - first_appearance: &mut Option<AppearanceIndex>, - appearances: &mut Appearances, - location: Location, - ) { - let point_index = elements.point_from_location(location); - let appearance_index = - appearances.push(Appearance { point_index, next: *first_appearance }); - *first_appearance = Some(appearance_index); - } -} - impl Visitor<'_> for LocalUseMapBuild<'_> { fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) { - if self.locals_with_use_data[local] { - match def_use::categorize(context) { - Some(DefUse::Def) => self.insert_def(local, location), - Some(DefUse::Use) => self.insert_use(local, location), - Some(DefUse::Drop) => self.insert_drop(local, location), - _ => (), - } + if self.locals_with_use_data[local] + && let Some(def_use) = def_use::categorize(context) + { + let first_appearance = match def_use { + DefUse::Def => &mut self.local_use_map.first_def_at[local], + DefUse::Use => &mut self.local_use_map.first_use_at[local], + DefUse::Drop => &mut self.local_use_map.first_drop_at[local], + }; + let point_index = self.elements.point_from_location(location); + let appearance_index = self + .local_use_map + .appearances + .push(Appearance { point_index, next: *first_appearance }); + *first_appearance = Some(appearance_index); } } } diff --git a/compiler/rustc_borrowck/src/type_check/liveness/mod.rs b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs index b8e35f882ec..84fb36dd32a 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs @@ -39,8 +39,8 @@ pub(super) fn generate<'a, 'tcx>( let free_regions = regions_that_outlive_free_regions( typeck.infcx.num_region_vars(), - typeck.borrowck_context.universal_regions, - &typeck.borrowck_context.constraints.outlives_constraints, + typeck.universal_regions, + &typeck.constraints.outlives_constraints, ); let (relevant_live_locals, boring_locals) = compute_relevant_live_locals(typeck.tcx(), &free_regions, body); @@ -59,11 +59,7 @@ pub(super) fn generate<'a, 'tcx>( // Mark regions that should be live where they appear within rvalues or within a call: like // args, regions, and types. - record_regular_live_regions( - typeck.tcx(), - &mut typeck.borrowck_context.constraints.liveness_constraints, - body, - ); + record_regular_live_regions(typeck.tcx(), &mut typeck.constraints.liveness_constraints, body); } // The purpose of `compute_relevant_live_locals` is to define the subset of `Local` diff --git a/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs index 3a458731f28..e8d8ae0850b 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs @@ -88,9 +88,9 @@ pub(super) fn populate_access_facts<'a, 'tcx>( body: &Body<'tcx>, move_data: &MoveData<'tcx>, ) { - if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() { + if let Some(facts) = typeck.all_facts.as_mut() { debug!("populate_access_facts()"); - let location_table = typeck.borrowck_context.location_table; + let location_table = typeck.location_table; let mut extractor = UseFactsExtractor { var_defined_at: &mut facts.var_defined_at, @@ -108,7 +108,7 @@ pub(super) fn populate_access_facts<'a, 'tcx>( local, local_decl.ty ); let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation"); - let universal_regions = &typeck.borrowck_context.universal_regions; + let universal_regions = &typeck.universal_regions; typeck.infcx.tcx.for_each_free_region(&local_decl.ty, |region| { let region_vid = universal_regions.to_region_vid(region); facts.use_of_var_derefs_origin.push((local, region_vid.into())); @@ -125,9 +125,9 @@ pub(super) fn add_drop_of_var_derefs_origin<'tcx>( kind: &GenericArg<'tcx>, ) { debug!("add_drop_of_var_derefs_origin(local={:?}, kind={:?}", local, kind); - if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() { + if let Some(facts) = typeck.all_facts.as_mut() { let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation"); - let universal_regions = &typeck.borrowck_context.universal_regions; + let universal_regions = &typeck.universal_regions; typeck.infcx.tcx.for_each_free_region(kind, |drop_live_region| { let region_vid = universal_regions.to_region_vid(drop_live_region); facts.drop_of_var_derefs_origin.push((local, region_vid.into())); diff --git a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs index 35963228181..72f6a605279 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs @@ -47,13 +47,12 @@ pub(super) fn trace<'a, 'tcx>( // When using `-Zpolonius=next`, compute the set of loans that can reach a given region. if typeck.tcx().sess.opts.unstable_opts.polonius.is_next_enabled() { - let borrowck_context = &mut typeck.borrowck_context; - let borrow_set = &borrowck_context.borrow_set; + let borrow_set = &typeck.borrow_set; let mut live_loans = LiveLoans::new(borrow_set.len()); - let outlives_constraints = &borrowck_context.constraints.outlives_constraints; + let outlives_constraints = &typeck.constraints.outlives_constraints; let graph = outlives_constraints.graph(typeck.infcx.num_region_vars()); let region_graph = - graph.region_graph(outlives_constraints, borrowck_context.universal_regions.fr_static); + graph.region_graph(outlives_constraints, typeck.universal_regions.fr_static); // Traverse each issuing region's constraints, and record the loan as flowing into the // outlived region. @@ -73,7 +72,7 @@ pub(super) fn trace<'a, 'tcx>( // Store the inflowing loans in the liveness constraints: they will be used to compute live // loans when liveness data is recorded there. - borrowck_context.constraints.liveness_constraints.loans = Some(live_loans); + typeck.constraints.liveness_constraints.loans = Some(live_loans); }; let cx = LivenessContext { @@ -222,7 +221,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> { // It may be necessary to just pick out the parts of // `add_drop_live_facts_for()` that make sense. let facts_to_add: Vec<_> = { - let drop_used = &self.cx.typeck.borrowck_context.all_facts.as_ref()?.var_dropped_at; + let drop_used = &self.cx.typeck.all_facts.as_ref()?.var_dropped_at; let relevant_live_locals: FxIndexSet<_> = relevant_live_locals.iter().copied().collect(); @@ -235,12 +234,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> { return None; } - let location = match self - .cx - .typeck - .borrowck_context - .location_table - .to_location(*location_index) + let location = match self.cx.typeck.location_table.to_location(*location_index) { RichLocation::Start(l) => l, RichLocation::Mid(l) => l, @@ -251,7 +245,8 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> { .collect() }; - // FIXME: these locations seem to have a special meaning (e.g. everywhere, at the end, ...), but I don't know which one. Please help me rename it to something descriptive! + // FIXME: these locations seem to have a special meaning (e.g. everywhere, at the end, + // ...), but I don't know which one. Please help me rename it to something descriptive! // Also, if this IntervalSet is used in many places, it maybe should have a newtype'd // name with a description of what it means for future mortals passing by. let locations = IntervalSet::new(self.cx.elements.num_points()); @@ -615,13 +610,9 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> { tcx: typeck.tcx(), param_env: typeck.param_env, op: |r| { - let live_region_vid = typeck.borrowck_context.universal_regions.to_region_vid(r); + let live_region_vid = typeck.universal_regions.to_region_vid(r); - typeck - .borrowck_context - .constraints - .liveness_constraints - .add_points(live_region_vid, live_at); + typeck.constraints.liveness_constraints.add_points(live_region_vid, live_at); }, }); } diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index dffdfb8ac1d..ffb7836872d 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -156,25 +156,24 @@ pub(crate) fn type_check<'a, 'tcx>( debug!(?normalized_inputs_and_output); - let mut borrowck_context = BorrowCheckContext { + let mut checker = TypeChecker { + infcx, + param_env, + last_span: body.span, + body, + user_type_annotations: &body.user_type_annotations, + region_bound_pairs: ®ion_bound_pairs, + known_type_outlives_obligations, + implicit_region_bound, + reported_errors: Default::default(), universal_regions: &universal_regions, location_table, - borrow_set, all_facts, + borrow_set, constraints: &mut constraints, upvars, }; - let mut checker = TypeChecker::new( - infcx, - body, - param_env, - ®ion_bound_pairs, - known_type_outlives_obligations, - implicit_region_bound, - &mut borrowck_context, - ); - checker.check_user_type_annotations(); let mut verifier = TypeVerifier::new(&mut checker, promoted); @@ -221,13 +220,12 @@ pub(crate) fn type_check<'a, 'tcx>( infcx.tcx.fold_regions((opaque_type_key, hidden_type), |region, _| { match region.kind() { ty::ReVar(_) => region, - ty::RePlaceholder(placeholder) => checker - .borrowck_context - .constraints - .placeholder_region(infcx, placeholder), + ty::RePlaceholder(placeholder) => { + checker.constraints.placeholder_region(infcx, placeholder) + } _ => ty::Region::new_var( infcx.tcx, - checker.borrowck_context.universal_regions.to_region_vid(region), + checker.universal_regions.to_region_vid(region), ), } }); @@ -240,25 +238,26 @@ pub(crate) fn type_check<'a, 'tcx>( } fn translate_outlives_facts(typeck: &mut TypeChecker<'_, '_>) { - let cx = &mut typeck.borrowck_context; - if let Some(facts) = cx.all_facts { + if let Some(facts) = typeck.all_facts { let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation"); - let location_table = cx.location_table; - facts.subset_base.extend(cx.constraints.outlives_constraints.outlives().iter().flat_map( - |constraint: &OutlivesConstraint<'_>| { - if let Some(from_location) = constraint.locations.from_location() { - Either::Left(iter::once(( - constraint.sup.into(), - constraint.sub.into(), - location_table.mid_index(from_location), - ))) - } else { - Either::Right(location_table.all_points().map(move |location| { - (constraint.sup.into(), constraint.sub.into(), location) - })) - } - }, - )); + let location_table = typeck.location_table; + facts.subset_base.extend( + typeck.constraints.outlives_constraints.outlives().iter().flat_map( + |constraint: &OutlivesConstraint<'_>| { + if let Some(from_location) = constraint.locations.from_location() { + Either::Left(iter::once(( + constraint.sup.into(), + constraint.sub.into(), + location_table.mid_index(from_location), + ))) + } else { + Either::Right(location_table.all_points().map(move |location| { + (constraint.sup.into(), constraint.sub.into(), location) + })) + } + }, + ), + ); } } @@ -303,13 +302,8 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { let ty = self.sanitize_type(constant, constant.const_.ty()); self.cx.infcx.tcx.for_each_free_region(&ty, |live_region| { - let live_region_vid = - self.cx.borrowck_context.universal_regions.to_region_vid(live_region); - self.cx - .borrowck_context - .constraints - .liveness_constraints - .add_location(live_region_vid, location); + let live_region_vid = self.cx.universal_regions.to_region_vid(live_region); + self.cx.constraints.liveness_constraints.add_location(live_region_vid, location); }); // HACK(compiler-errors): Constants that are gathered into Body.required_consts @@ -561,15 +555,9 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { // Don't try to add borrow_region facts for the promoted MIR let mut swap_constraints = |this: &mut Self| { - mem::swap(this.cx.borrowck_context.all_facts, all_facts); - mem::swap( - &mut this.cx.borrowck_context.constraints.outlives_constraints, - &mut constraints, - ); - mem::swap( - &mut this.cx.borrowck_context.constraints.liveness_constraints, - &mut liveness_constraints, - ); + mem::swap(this.cx.all_facts, all_facts); + mem::swap(&mut this.cx.constraints.outlives_constraints, &mut constraints); + mem::swap(&mut this.cx.constraints.liveness_constraints, &mut liveness_constraints); }; swap_constraints(self); @@ -594,7 +582,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { // temporary from the user's point of view. constraint.category = ConstraintCategory::Boring; } - self.cx.borrowck_context.constraints.outlives_constraints.push(constraint) + self.cx.constraints.outlives_constraints.push(constraint) } // If the region is live at least one location in the promoted MIR, // then add a liveness constraint to the main MIR for this region @@ -604,11 +592,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { // unordered. #[allow(rustc::potential_query_instability)] for region in liveness_constraints.live_regions_unordered() { - self.cx - .borrowck_context - .constraints - .liveness_constraints - .add_location(region, location); + self.cx.constraints.liveness_constraints.add_location(region, location); } } @@ -863,15 +847,11 @@ struct TypeChecker<'a, 'tcx> { known_type_outlives_obligations: &'tcx [ty::PolyTypeOutlivesPredicate<'tcx>], implicit_region_bound: ty::Region<'tcx>, reported_errors: FxIndexSet<(Ty<'tcx>, Span)>, - borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>, -} - -struct BorrowCheckContext<'a, 'tcx> { - pub(crate) universal_regions: &'a UniversalRegions<'tcx>, + universal_regions: &'a UniversalRegions<'tcx>, location_table: &'a LocationTable, all_facts: &'a mut Option<AllFacts>, borrow_set: &'a BorrowSet<'tcx>, - pub(crate) constraints: &'a mut MirTypeckRegionConstraints<'tcx>, + constraints: &'a mut MirTypeckRegionConstraints<'tcx>, upvars: &'a [&'a ty::CapturedPlace<'tcx>], } @@ -1006,29 +986,6 @@ impl Locations { } impl<'a, 'tcx> TypeChecker<'a, 'tcx> { - fn new( - infcx: &'a BorrowckInferCtxt<'tcx>, - body: &'a Body<'tcx>, - param_env: ty::ParamEnv<'tcx>, - region_bound_pairs: &'a RegionBoundPairs<'tcx>, - known_type_outlives_obligations: &'tcx [ty::PolyTypeOutlivesPredicate<'tcx>], - implicit_region_bound: ty::Region<'tcx>, - borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>, - ) -> Self { - Self { - infcx, - last_span: body.span, - body, - user_type_annotations: &body.user_type_annotations, - param_env, - region_bound_pairs, - known_type_outlives_obligations, - implicit_region_bound, - borrowck_context, - reported_errors: Default::default(), - } - } - fn body(&self) -> &Body<'tcx> { self.body } @@ -1067,7 +1024,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { constraint_conversion::ConstraintConversion::new( self.infcx, - self.borrowck_context.universal_regions, + self.universal_regions, self.region_bound_pairs, self.implicit_region_bound, self.param_env, @@ -1075,7 +1032,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { locations, locations.span(self.body), category, - self.borrowck_context.constraints, + self.constraints, ) .convert_all(data); } @@ -1191,7 +1148,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // though. let category = match place.as_local() { Some(RETURN_PLACE) => { - let defining_ty = &self.borrowck_context.universal_regions.defining_ty; + let defining_ty = &self.universal_regions.defining_ty; if defining_ty.is_const() { if tcx.is_static(defining_ty.def_id()) { ConstraintCategory::UseAsStatic @@ -1439,12 +1396,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // output) types in the signature must be live, since // all the inputs that fed into it were live. for &late_bound_region in map.values() { - let region_vid = - self.borrowck_context.universal_regions.to_region_vid(late_bound_region); - self.borrowck_context - .constraints - .liveness_constraints - .add_location(region_vid, term_location); + let region_vid = self.universal_regions.to_region_vid(late_bound_region); + self.constraints.liveness_constraints.add_location(region_vid, term_location); } self.check_call_inputs(body, term, func, &sig, args, term_location, call_source); @@ -1532,18 +1485,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let dest_ty = self.normalize(dest_ty, term_location); let category = match destination.as_local() { Some(RETURN_PLACE) => { - if let BorrowCheckContext { - universal_regions: - UniversalRegions { - defining_ty: - DefiningTy::Const(def_id, _) - | DefiningTy::InlineConst(def_id, _), - .. - }, - .. - } = self.borrowck_context + if let DefiningTy::Const(def_id, _) | DefiningTy::InlineConst(def_id, _) = + self.universal_regions.defining_ty { - if tcx.is_static(*def_id) { + if tcx.is_static(def_id) { ConstraintCategory::UseAsStatic } else { ConstraintCategory::UseAsConst @@ -1606,9 +1551,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let func_ty = func.ty(body, self.infcx.tcx); if let ty::FnDef(def_id, _) = *func_ty.kind() { - // Some of the SIMD intrinsics are special: they need a particular argument to be a constant. - // (Eventually this should use const-generics, but those are not up for the task yet: - // https://github.com/rust-lang/rust/issues/85229.) + // Some of the SIMD intrinsics are special: they need a particular argument to be a + // constant. (Eventually this should use const-generics, but those are not up for the + // task yet: https://github.com/rust-lang/rust/issues/85229.) if let Some(name @ (sym::simd_shuffle | sym::simd_insert | sym::simd_extract)) = self.tcx().intrinsic(def_id).map(|i| i.name) { @@ -1921,7 +1866,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { if len.try_to_target_usize(tcx).is_none_or(|len| len > 1) { match operand { Operand::Copy(..) | Operand::Constant(..) => { - // These are always okay: direct use of a const, or a value that can evidently be copied. + // These are always okay: direct use of a const, or a value that can + // evidently be copied. } Operand::Move(place) => { // Make sure that repeated elements implement `Copy`. @@ -2402,9 +2348,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let dst_tail = self.struct_tail(dst.ty, location); // This checks (lifetime part of) vtable validity for pointer casts, - // which is irrelevant when there are aren't principal traits on both sides (aka only auto traits). + // which is irrelevant when there are aren't principal traits on + // both sides (aka only auto traits). // - // Note that other checks (such as denying `dyn Send` -> `dyn Debug`) are in `rustc_hir_typeck`. + // Note that other checks (such as denying `dyn Send` -> `dyn + // Debug`) are in `rustc_hir_typeck`. if let ty::Dynamic(src_tty, ..) = src_tail.kind() && let ty::Dynamic(dst_tty, ..) = dst_tail.kind() && src_tty.principal().is_some() @@ -2427,8 +2375,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ty::Dyn, )); - // Replace trait object lifetimes with fresh vars, to allow casts like - // `*mut dyn FnOnce() + 'a` -> `*mut dyn FnOnce() + 'static`, + // Replace trait object lifetimes with fresh vars, to allow + // casts like + // `*mut dyn FnOnce() + 'a` -> `*mut dyn FnOnce() + 'static` let src_obj = freshen_single_trait_object_lifetime(self.infcx, src_obj); let dst_obj = @@ -2650,8 +2599,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { borrowed_place: &Place<'tcx>, ) { // These constraints are only meaningful during borrowck: - let BorrowCheckContext { borrow_set, location_table, all_facts, constraints, .. } = - self.borrowck_context; + let Self { borrow_set, location_table, all_facts, constraints, .. } = self; // In Polonius mode, we also push a `loan_issued_at` fact // linking the loan to the region (in some cases, though, @@ -2681,12 +2629,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ); let tcx = self.infcx.tcx; - let field = path_utils::is_upvar_field_projection( - tcx, - self.borrowck_context.upvars, - borrowed_place.as_ref(), - body, - ); + let field = + path_utils::is_upvar_field_projection(tcx, self.upvars, borrowed_place.as_ref(), body); let category = if let Some(field) = field { ConstraintCategory::ClosureUpvar(field) } else { @@ -2840,7 +2784,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { if let Some(closure_requirements) = &tcx.mir_borrowck(def_id).closure_requirements { constraint_conversion::ConstraintConversion::new( self.infcx, - self.borrowck_context.universal_regions, + self.universal_regions, self.region_bound_pairs, self.implicit_region_bound, self.param_env, @@ -2848,7 +2792,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { locations, self.body.span, // irrelevant; will be overridden. ConstraintCategory::Boring, // same as above. - self.borrowck_context.constraints, + self.constraints, ) .apply_closure_requirements(closure_requirements, def_id.to_def_id(), args); } diff --git a/compiler/rustc_borrowck/src/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs index cfc14d146bd..54c35c8573a 100644 --- a/compiler/rustc_borrowck/src/type_check/relate_tys.rs +++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs @@ -240,11 +240,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> { fn create_next_universe(&mut self) -> ty::UniverseIndex { let universe = self.type_checker.infcx.create_next_universe(); - self.type_checker - .borrowck_context - .constraints - .universe_causes - .insert(universe, self.universe_info.clone()); + self.type_checker.constraints.universe_causes.insert(universe, self.universe_info.clone()); universe } @@ -264,11 +260,8 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> { #[instrument(skip(self), level = "debug")] fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx> { - let reg = self - .type_checker - .borrowck_context - .constraints - .placeholder_region(self.type_checker.infcx, placeholder); + let reg = + self.type_checker.constraints.placeholder_region(self.type_checker.infcx, placeholder); let reg_info = match placeholder.bound.kind { ty::BoundRegionKind::BrAnon => sym::anon, @@ -294,19 +287,17 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> { sub: ty::Region<'tcx>, info: ty::VarianceDiagInfo<TyCtxt<'tcx>>, ) { - let sub = self.type_checker.borrowck_context.universal_regions.to_region_vid(sub); - let sup = self.type_checker.borrowck_context.universal_regions.to_region_vid(sup); - self.type_checker.borrowck_context.constraints.outlives_constraints.push( - OutlivesConstraint { - sup, - sub, - locations: self.locations, - span: self.locations.span(self.type_checker.body), - category: self.category, - variance_info: info, - from_closure: false, - }, - ); + let sub = self.type_checker.universal_regions.to_region_vid(sub); + let sup = self.type_checker.universal_regions.to_region_vid(sup); + self.type_checker.constraints.outlives_constraints.push(OutlivesConstraint { + sup, + sub, + locations: self.locations, + span: self.locations.span(self.type_checker.body), + category: self.category, + variance_info: info, + from_closure: false, + }); } } diff --git a/compiler/rustc_codegen_gcc/src/consts.rs b/compiler/rustc_codegen_gcc/src/consts.rs index 660badb6a50..07c7a54de1c 100644 --- a/compiler/rustc_codegen_gcc/src/consts.rs +++ b/compiler/rustc_codegen_gcc/src/consts.rs @@ -146,7 +146,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> { // Wasm statics with custom link sections get special treatment as they // go into custom sections of the wasm executable. - if self.tcx.sess.opts.target_triple.tuple().starts_with("wasm32") { + if self.tcx.sess.target.is_like_wasm { if let Some(_section) = attrs.link_section { unimplemented!(); } diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 647e9e13fbc..a65ae4df1e3 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -945,23 +945,10 @@ fn create_section_with_flags_asm(section_name: &str, section_flags: &str, data: asm } -fn target_is_apple(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool { - let triple = cgcx.opts.target_triple.tuple(); - triple.contains("-ios") - || triple.contains("-darwin") - || triple.contains("-tvos") - || triple.contains("-watchos") - || triple.contains("-visionos") -} - -fn target_is_aix(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool { - cgcx.opts.target_triple.tuple().contains("-aix") -} - pub(crate) fn bitcode_section_name(cgcx: &CodegenContext<LlvmCodegenBackend>) -> &'static CStr { - if target_is_apple(cgcx) { + if cgcx.target_is_like_osx { c"__LLVM,__bitcode" - } else if target_is_aix(cgcx) { + } else if cgcx.target_is_like_aix { c".ipa" } else { c".llvmbc" @@ -1028,10 +1015,12 @@ unsafe fn embed_bitcode( // Unfortunately, LLVM provides no way to set custom section flags. For ELF // and COFF we emit the sections using module level inline assembly for that // reason (see issue #90326 for historical background). - let is_aix = target_is_aix(cgcx); - let is_apple = target_is_apple(cgcx); unsafe { - if is_apple || is_aix || cgcx.opts.target_triple.tuple().starts_with("wasm") { + if cgcx.target_is_like_osx + || cgcx.target_is_like_aix + || cgcx.target_arch == "wasm32" + || cgcx.target_arch == "wasm64" + { // We don't need custom section flags, create LLVM globals. let llconst = common::bytes_in_context(llcx, bitcode); let llglobal = llvm::LLVMAddGlobal( @@ -1052,9 +1041,9 @@ unsafe fn embed_bitcode( c"rustc.embedded.cmdline".as_ptr(), ); llvm::LLVMSetInitializer(llglobal, llconst); - let section = if is_apple { + let section = if cgcx.target_is_like_osx { c"__LLVM,__cmdline" - } else if is_aix { + } else if cgcx.target_is_like_aix { c".info" } else { c".llvmcmd" diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 20920d16f3c..39ff00baf6d 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -85,11 +85,7 @@ pub fn link_binary( } if invalid_output_for_target(sess, crate_type) { - bug!( - "invalid output type `{:?}` for target os `{}`", - crate_type, - sess.opts.target_triple - ); + bug!("invalid output type `{:?}` for target `{}`", crate_type, sess.opts.target_triple); } sess.time("link_binary_check_files_are_writeable", || { @@ -996,6 +992,7 @@ fn link_natively( && (code < 1000 || code > 9999) { let is_vs_installed = windows_registry::find_vs_version().is_ok(); + // FIXME(cc-rs#1265) pass only target arch to find_tool() let has_linker = windows_registry::find_tool( sess.opts.target_triple.tuple(), "link.exe", diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 3b4429535d4..4f3664a503d 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -47,6 +47,7 @@ pub(crate) fn get_linker<'a>( self_contained: bool, target_cpu: &'a str, ) -> Box<dyn Linker + 'a> { + // FIXME(cc-rs#1265) pass only target arch to find_tool() let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.tuple(), "link.exe"); // If our linker looks like a batch script on Windows then to execute this diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index dad21bb309f..3f3cb8b4073 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -211,7 +211,15 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static "powerpc64" => (Architecture::PowerPc64, None), "riscv32" => (Architecture::Riscv32, None), "riscv64" => (Architecture::Riscv64, None), - "sparc" => (Architecture::Sparc32Plus, None), + "sparc" => { + if sess.target.options.cpu == "v9" { + // Target uses V8+, aka EM_SPARC32PLUS, aka 64-bit V9 but in 32-bit mode + (Architecture::Sparc32Plus, None) + } else { + // Target uses V7 or V8, aka EM_SPARC + (Architecture::Sparc, None) + } + } "sparc64" => (Architecture::Sparc64, None), "avr" => (Architecture::Avr, None), "msp430" => (Architecture::Msp430, None), diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index d977cca247e..a2285bf9204 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -345,6 +345,8 @@ pub struct CodegenContext<B: WriteBackendMethods> { pub is_pe_coff: bool, pub target_can_use_split_dwarf: bool, pub target_arch: String, + pub target_is_like_osx: bool, + pub target_is_like_aix: bool, pub split_debuginfo: rustc_target::spec::SplitDebuginfo, pub split_dwarf_kind: rustc_session::config::SplitDwarfKind, @@ -1195,6 +1197,8 @@ fn start_executing_work<B: ExtraBackendMethods>( is_pe_coff: tcx.sess.target.is_like_windows, target_can_use_split_dwarf: tcx.sess.target_can_use_split_dwarf(), target_arch: tcx.sess.target.arch.to_string(), + target_is_like_osx: tcx.sess.target.is_like_osx, + target_is_like_aix: tcx.sess.target.is_like_aix, split_debuginfo: tcx.sess.split_debuginfo(), split_dwarf_kind: tcx.sess.opts.unstable_opts.split_dwarf_kind, parallel: backend.supports_parallel() && !sess.opts.unstable_opts.no_parallel_backend, diff --git a/compiler/rustc_const_eval/messages.ftl b/compiler/rustc_const_eval/messages.ftl index 3e4f83c8242..2bc5adb2dce 100644 --- a/compiler/rustc_const_eval/messages.ftl +++ b/compiler/rustc_const_eval/messages.ftl @@ -1,9 +1,6 @@ const_eval_address_space_full = there are no more free addresses in the address space -const_eval_align_offset_invalid_align = - `align_offset` called with non-power-of-two align: {$target_align} - const_eval_alignment_check_failed = {$msg -> [AccessedPtr] accessing memory diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 851e6a587bc..62115aef4a7 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -1,7 +1,6 @@ use std::borrow::{Borrow, Cow}; use std::fmt; use std::hash::Hash; -use std::ops::ControlFlow; use rustc_abi::{Align, ExternAbi, Size}; use rustc_ast::Mutability; @@ -10,7 +9,7 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self as hir, CRATE_HIR_ID, LangItem}; use rustc_middle::mir::AssertMessage; use rustc_middle::query::TyCtxtAt; -use rustc_middle::ty::layout::{FnAbiOf, TyAndLayout}; +use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::{bug, mir}; use rustc_span::Span; @@ -22,9 +21,9 @@ use crate::errors::{LongRunning, LongRunningWarn}; use crate::fluent_generated as fluent; use crate::interpret::{ self, AllocId, AllocRange, ConstAllocation, CtfeProvenance, FnArg, Frame, GlobalAlloc, ImmTy, - InterpCx, InterpResult, MPlaceTy, OpTy, Pointer, PointerArithmetic, RangeSet, Scalar, - StackPopCleanup, compile_time_machine, interp_ok, throw_exhaust, throw_inval, throw_ub, - throw_ub_custom, throw_unsup, throw_unsup_format, + InterpCx, InterpResult, MPlaceTy, OpTy, Pointer, RangeSet, Scalar, compile_time_machine, + interp_ok, throw_exhaust, throw_inval, throw_ub, throw_ub_custom, throw_unsup, + throw_unsup_format, }; /// When hitting this many interpreted terminators we emit a deny by default lint @@ -226,8 +225,8 @@ impl<'tcx> CompileTimeInterpCx<'tcx> { &mut self, instance: ty::Instance<'tcx>, args: &[FnArg<'tcx>], - dest: &MPlaceTy<'tcx>, - ret: Option<mir::BasicBlock>, + _dest: &MPlaceTy<'tcx>, + _ret: Option<mir::BasicBlock>, ) -> InterpResult<'tcx, Option<ty::Instance<'tcx>>> { let def_id = instance.def_id(); @@ -259,85 +258,10 @@ impl<'tcx> CompileTimeInterpCx<'tcx> { ); return interp_ok(Some(new_instance)); - } else if self.tcx.is_lang_item(def_id, LangItem::AlignOffset) { - let args = self.copy_fn_args(args); - // For align_offset, we replace the function call if the pointer has no address. - match self.align_offset(instance, &args, dest, ret)? { - ControlFlow::Continue(()) => return interp_ok(Some(instance)), - ControlFlow::Break(()) => return interp_ok(None), - } } interp_ok(Some(instance)) } - /// `align_offset(ptr, target_align)` needs special handling in const eval, because the pointer - /// may not have an address. - /// - /// If `ptr` does have a known address, then we return `Continue(())` and the function call should - /// proceed as normal. - /// - /// If `ptr` doesn't have an address, but its underlying allocation's alignment is at most - /// `target_align`, then we call the function again with an dummy address relative to the - /// allocation. - /// - /// If `ptr` doesn't have an address and `target_align` is stricter than the underlying - /// allocation's alignment, then we return `usize::MAX` immediately. - fn align_offset( - &mut self, - instance: ty::Instance<'tcx>, - args: &[OpTy<'tcx>], - dest: &MPlaceTy<'tcx>, - ret: Option<mir::BasicBlock>, - ) -> InterpResult<'tcx, ControlFlow<()>> { - assert_eq!(args.len(), 2); - - let ptr = self.read_pointer(&args[0])?; - let target_align = self.read_scalar(&args[1])?.to_target_usize(self)?; - - if !target_align.is_power_of_two() { - throw_ub_custom!( - fluent::const_eval_align_offset_invalid_align, - target_align = target_align, - ); - } - - match self.ptr_try_get_alloc_id(ptr, 0) { - Ok((alloc_id, offset, _extra)) => { - let (_size, alloc_align, _kind) = self.get_alloc_info(alloc_id); - - if target_align <= alloc_align.bytes() { - // Extract the address relative to the allocation base that is definitely - // sufficiently aligned and call `align_offset` again. - let addr = ImmTy::from_uint(offset.bytes(), args[0].layout).into(); - let align = ImmTy::from_uint(target_align, args[1].layout).into(); - let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty())?; - - // Push the stack frame with our own adjusted arguments. - self.init_stack_frame( - instance, - self.load_mir(instance.def, None)?, - fn_abi, - &[FnArg::Copy(addr), FnArg::Copy(align)], - /* with_caller_location = */ false, - dest, - StackPopCleanup::Goto { ret, unwind: mir::UnwindAction::Unreachable }, - )?; - interp_ok(ControlFlow::Break(())) - } else { - // Not alignable in const, return `usize::MAX`. - let usize_max = Scalar::from_target_usize(self.target_usize_max(), self); - self.write_scalar(usize_max, dest)?; - self.return_to_block(ret)?; - interp_ok(ControlFlow::Break(())) - } - } - Err(_addr) => { - // The pointer has an address, continue with function call. - interp_ok(ControlFlow::Continue(())) - } - } - } - /// See documentation on the `ptr_guaranteed_cmp` intrinsic. fn guaranteed_cmp(&mut self, a: Scalar, b: Scalar) -> InterpResult<'tcx, u8> { interp_ok(match (a, b) { diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 7d81f977c22..c952d5f6d77 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -348,9 +348,6 @@ language_item_table! { MaybeUninit, sym::maybe_uninit, maybe_uninit, Target::Union, GenericRequirement::None; - /// Align offset for stride != 1; must not panic. - AlignOffset, sym::align_offset, align_offset_fn, Target::Fn, GenericRequirement::None; - Termination, sym::termination, termination, Target::Trait, GenericRequirement::None; Try, sym::Try, try_trait, Target::Trait, GenericRequirement::None; diff --git a/compiler/rustc_passes/src/hir_stats.rs b/compiler/rustc_passes/src/hir_stats.rs index 27714a0fdcc..55fdbac8ad6 100644 --- a/compiler/rustc_passes/src/hir_stats.rs +++ b/compiler/rustc_passes/src/hir_stats.rs @@ -3,7 +3,7 @@ // completely accurate (some things might be counted twice, others missed). use rustc_ast::visit::BoundKind; -use rustc_ast::{self as ast, AttrId, NodeId, visit as ast_visit}; +use rustc_ast::{self as ast, NodeId, visit as ast_visit}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::{HirId, intravisit as hir_visit}; @@ -13,13 +13,6 @@ use rustc_middle::util::common::to_readable_str; use rustc_span::Span; use rustc_span::def_id::LocalDefId; -#[derive(Copy, Clone, PartialEq, Eq, Hash)] -enum Id { - Node(HirId), - Attr(AttrId), - None, -} - struct NodeStats { count: usize, size: usize, @@ -62,7 +55,7 @@ impl Node { struct StatCollector<'k> { krate: Option<Map<'k>>, nodes: FxHashMap<&'static str, Node>, - seen: FxHashSet<Id>, + seen: FxHashSet<HirId>, } pub fn print_hir_stats(tcx: TyCtxt<'_>) { @@ -87,12 +80,18 @@ pub fn print_ast_stats(krate: &ast::Crate, title: &str, prefix: &str) { impl<'k> StatCollector<'k> { // Record a top-level node. - fn record<T>(&mut self, label: &'static str, id: Id, val: &T) { + fn record<T>(&mut self, label: &'static str, id: Option<HirId>, val: &T) { self.record_inner(label, None, id, val); } // Record a two-level entry, with a top-level enum type and a variant. - fn record_variant<T>(&mut self, label1: &'static str, label2: &'static str, id: Id, val: &T) { + fn record_variant<T>( + &mut self, + label1: &'static str, + label2: &'static str, + id: Option<HirId>, + val: &T, + ) { self.record_inner(label1, Some(label2), id, val); } @@ -100,10 +99,10 @@ impl<'k> StatCollector<'k> { &mut self, label1: &'static str, label2: Option<&'static str>, - id: Id, + id: Option<HirId>, val: &T, ) { - if id != Id::None && !self.seen.insert(id) { + if id.is_some_and(|x| !self.seen.insert(x)) { return; } @@ -191,7 +190,7 @@ macro_rules! record_variants { impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { fn visit_param(&mut self, param: &'v hir::Param<'v>) { - self.record("Param", Id::Node(param.hir_id), param); + self.record("Param", Some(param.hir_id), param); hir_visit::walk_param(self, param) } @@ -221,7 +220,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_item(&mut self, i: &'v hir::Item<'v>) { - record_variants!((self, i, i.kind, Id::Node(i.hir_id()), hir, Item, ItemKind), [ + record_variants!((self, i, i.kind, Some(i.hir_id()), hir, Item, ItemKind), [ ExternCrate, Use, Static, @@ -243,47 +242,46 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_body(&mut self, b: &hir::Body<'v>) { - self.record("Body", Id::None, b); + self.record("Body", None, b); hir_visit::walk_body(self, b); } fn visit_mod(&mut self, m: &'v hir::Mod<'v>, _s: Span, n: HirId) { - self.record("Mod", Id::None, m); + self.record("Mod", None, m); hir_visit::walk_mod(self, m, n) } fn visit_foreign_item(&mut self, i: &'v hir::ForeignItem<'v>) { - record_variants!( - (self, i, i.kind, Id::Node(i.hir_id()), hir, ForeignItem, ForeignItemKind), - [Fn, Static, Type] - ); + record_variants!((self, i, i.kind, Some(i.hir_id()), hir, ForeignItem, ForeignItemKind), [ + Fn, Static, Type + ]); hir_visit::walk_foreign_item(self, i) } fn visit_local(&mut self, l: &'v hir::LetStmt<'v>) { - self.record("Local", Id::Node(l.hir_id), l); + self.record("Local", Some(l.hir_id), l); hir_visit::walk_local(self, l) } fn visit_block(&mut self, b: &'v hir::Block<'v>) { - self.record("Block", Id::Node(b.hir_id), b); + self.record("Block", Some(b.hir_id), b); hir_visit::walk_block(self, b) } fn visit_stmt(&mut self, s: &'v hir::Stmt<'v>) { - record_variants!((self, s, s.kind, Id::Node(s.hir_id), hir, Stmt, StmtKind), [ + record_variants!((self, s, s.kind, Some(s.hir_id), hir, Stmt, StmtKind), [ Let, Item, Expr, Semi ]); hir_visit::walk_stmt(self, s) } fn visit_arm(&mut self, a: &'v hir::Arm<'v>) { - self.record("Arm", Id::Node(a.hir_id), a); + self.record("Arm", Some(a.hir_id), a); hir_visit::walk_arm(self, a) } fn visit_pat(&mut self, p: &'v hir::Pat<'v>) { - record_variants!((self, p, p.kind, Id::Node(p.hir_id), hir, Pat, PatKind), [ + record_variants!((self, p, p.kind, Some(p.hir_id), hir, Pat, PatKind), [ Wild, Binding, Struct, @@ -304,12 +302,12 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_pat_field(&mut self, f: &'v hir::PatField<'v>) { - self.record("PatField", Id::Node(f.hir_id), f); + self.record("PatField", Some(f.hir_id), f); hir_visit::walk_pat_field(self, f) } fn visit_expr(&mut self, e: &'v hir::Expr<'v>) { - record_variants!((self, e, e.kind, Id::Node(e.hir_id), hir, Expr, ExprKind), [ + record_variants!((self, e, e.kind, Some(e.hir_id), hir, Expr, ExprKind), [ ConstBlock, Array, Call, MethodCall, Tup, Binary, Unary, Lit, Cast, Type, DropTemps, Let, If, Loop, Match, Closure, Block, Assign, AssignOp, Field, Index, Path, AddrOf, Break, Continue, Ret, Become, InlineAsm, OffsetOf, Struct, Repeat, Yield, Err @@ -318,12 +316,12 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_expr_field(&mut self, f: &'v hir::ExprField<'v>) { - self.record("ExprField", Id::Node(f.hir_id), f); + self.record("ExprField", Some(f.hir_id), f); hir_visit::walk_expr_field(self, f) } fn visit_ty(&mut self, t: &'v hir::Ty<'v>) { - record_variants!((self, t, t.kind, Id::Node(t.hir_id), hir, Ty, TyKind), [ + record_variants!((self, t, t.kind, Some(t.hir_id), hir, Ty, TyKind), [ InferDelegation, Slice, Array, @@ -345,17 +343,17 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_generic_param(&mut self, p: &'v hir::GenericParam<'v>) { - self.record("GenericParam", Id::Node(p.hir_id), p); + self.record("GenericParam", Some(p.hir_id), p); hir_visit::walk_generic_param(self, p) } fn visit_generics(&mut self, g: &'v hir::Generics<'v>) { - self.record("Generics", Id::None, g); + self.record("Generics", None, g); hir_visit::walk_generics(self, g) } fn visit_where_predicate(&mut self, p: &'v hir::WherePredicate<'v>) { - record_variants!((self, p, p, Id::None, hir, WherePredicate, WherePredicate), [ + record_variants!((self, p, p, None, hir, WherePredicate, WherePredicate), [ BoundPredicate, RegionPredicate, EqPredicate @@ -371,66 +369,64 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { _: Span, id: LocalDefId, ) { - self.record("FnDecl", Id::None, fd); + self.record("FnDecl", None, fd); hir_visit::walk_fn(self, fk, fd, b, id) } fn visit_use(&mut self, p: &'v hir::UsePath<'v>, hir_id: HirId) { // This is `visit_use`, but the type is `Path` so record it that way. - self.record("Path", Id::None, p); + self.record("Path", None, p); hir_visit::walk_use(self, p, hir_id) } fn visit_trait_item(&mut self, ti: &'v hir::TraitItem<'v>) { - record_variants!( - (self, ti, ti.kind, Id::Node(ti.hir_id()), hir, TraitItem, TraitItemKind), - [Const, Fn, Type] - ); + record_variants!((self, ti, ti.kind, Some(ti.hir_id()), hir, TraitItem, TraitItemKind), [ + Const, Fn, Type + ]); hir_visit::walk_trait_item(self, ti) } fn visit_trait_item_ref(&mut self, ti: &'v hir::TraitItemRef) { - self.record("TraitItemRef", Id::Node(ti.id.hir_id()), ti); + self.record("TraitItemRef", Some(ti.id.hir_id()), ti); hir_visit::walk_trait_item_ref(self, ti) } fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) { - record_variants!( - (self, ii, ii.kind, Id::Node(ii.hir_id()), hir, ImplItem, ImplItemKind), - [Const, Fn, Type] - ); + record_variants!((self, ii, ii.kind, Some(ii.hir_id()), hir, ImplItem, ImplItemKind), [ + Const, Fn, Type + ]); hir_visit::walk_impl_item(self, ii) } fn visit_foreign_item_ref(&mut self, fi: &'v hir::ForeignItemRef) { - self.record("ForeignItemRef", Id::Node(fi.id.hir_id()), fi); + self.record("ForeignItemRef", Some(fi.id.hir_id()), fi); hir_visit::walk_foreign_item_ref(self, fi) } fn visit_impl_item_ref(&mut self, ii: &'v hir::ImplItemRef) { - self.record("ImplItemRef", Id::Node(ii.id.hir_id()), ii); + self.record("ImplItemRef", Some(ii.id.hir_id()), ii); hir_visit::walk_impl_item_ref(self, ii) } fn visit_param_bound(&mut self, b: &'v hir::GenericBound<'v>) { - record_variants!((self, b, b, Id::None, hir, GenericBound, GenericBound), [ + record_variants!((self, b, b, None, hir, GenericBound, GenericBound), [ Trait, Outlives, Use ]); hir_visit::walk_param_bound(self, b) } fn visit_field_def(&mut self, s: &'v hir::FieldDef<'v>) { - self.record("FieldDef", Id::Node(s.hir_id), s); + self.record("FieldDef", Some(s.hir_id), s); hir_visit::walk_field_def(self, s) } fn visit_variant(&mut self, v: &'v hir::Variant<'v>) { - self.record("Variant", Id::None, v); + self.record("Variant", None, v); hir_visit::walk_variant(self, v) } fn visit_generic_arg(&mut self, ga: &'v hir::GenericArg<'v>) { - record_variants!((self, ga, ga, Id::Node(ga.hir_id()), hir, GenericArg, GenericArg), [ + record_variants!((self, ga, ga, Some(ga.hir_id()), hir, GenericArg, GenericArg), [ Lifetime, Type, Const, Infer ]); match ga { @@ -442,50 +438,50 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_lifetime(&mut self, lifetime: &'v hir::Lifetime) { - self.record("Lifetime", Id::Node(lifetime.hir_id), lifetime); + self.record("Lifetime", Some(lifetime.hir_id), lifetime); hir_visit::walk_lifetime(self, lifetime) } fn visit_path(&mut self, path: &hir::Path<'v>, _id: HirId) { - self.record("Path", Id::None, path); + self.record("Path", None, path); hir_visit::walk_path(self, path) } fn visit_path_segment(&mut self, path_segment: &'v hir::PathSegment<'v>) { - self.record("PathSegment", Id::None, path_segment); + self.record("PathSegment", None, path_segment); hir_visit::walk_path_segment(self, path_segment) } fn visit_generic_args(&mut self, ga: &'v hir::GenericArgs<'v>) { - self.record("GenericArgs", Id::None, ga); + self.record("GenericArgs", None, ga); hir_visit::walk_generic_args(self, ga) } fn visit_assoc_item_constraint(&mut self, constraint: &'v hir::AssocItemConstraint<'v>) { - self.record("AssocItemConstraint", Id::Node(constraint.hir_id), constraint); + self.record("AssocItemConstraint", Some(constraint.hir_id), constraint); hir_visit::walk_assoc_item_constraint(self, constraint) } fn visit_attribute(&mut self, attr: &'v ast::Attribute) { - self.record("Attribute", Id::Attr(attr.id), attr); + self.record("Attribute", None, attr); } fn visit_inline_asm(&mut self, asm: &'v hir::InlineAsm<'v>, id: HirId) { - self.record("InlineAsm", Id::None, asm); + self.record("InlineAsm", None, asm); hir_visit::walk_inline_asm(self, asm, id); } } impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { fn visit_foreign_item(&mut self, i: &'v ast::ForeignItem) { - record_variants!((self, i, i.kind, Id::None, ast, ForeignItem, ForeignItemKind), [ + record_variants!((self, i, i.kind, None, ast, ForeignItem, ForeignItemKind), [ Static, Fn, TyAlias, MacCall ]); ast_visit::walk_item(self, i) } fn visit_item(&mut self, i: &'v ast::Item) { - record_variants!((self, i, i.kind, Id::None, ast, Item, ItemKind), [ + record_variants!((self, i, i.kind, None, ast, Item, ItemKind), [ ExternCrate, Use, Static, @@ -510,34 +506,34 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { } fn visit_local(&mut self, l: &'v ast::Local) { - self.record("Local", Id::None, l); + self.record("Local", None, l); ast_visit::walk_local(self, l) } fn visit_block(&mut self, b: &'v ast::Block) { - self.record("Block", Id::None, b); + self.record("Block", None, b); ast_visit::walk_block(self, b) } fn visit_stmt(&mut self, s: &'v ast::Stmt) { - record_variants!((self, s, s.kind, Id::None, ast, Stmt, StmtKind), [ + record_variants!((self, s, s.kind, None, ast, Stmt, StmtKind), [ Let, Item, Expr, Semi, Empty, MacCall ]); ast_visit::walk_stmt(self, s) } fn visit_param(&mut self, p: &'v ast::Param) { - self.record("Param", Id::None, p); + self.record("Param", None, p); ast_visit::walk_param(self, p) } fn visit_arm(&mut self, a: &'v ast::Arm) { - self.record("Arm", Id::None, a); + self.record("Arm", None, a); ast_visit::walk_arm(self, a) } fn visit_pat(&mut self, p: &'v ast::Pat) { - record_variants!((self, p, p.kind, Id::None, ast, Pat, PatKind), [ + record_variants!((self, p, p.kind, None, ast, Pat, PatKind), [ Wild, Ident, Struct, @@ -563,7 +559,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { fn visit_expr(&mut self, e: &'v ast::Expr) { #[rustfmt::skip] record_variants!( - (self, e, e.kind, Id::None, ast, Expr, ExprKind), + (self, e, e.kind, None, ast, Expr, ExprKind), [ Array, ConstBlock, Call, MethodCall, Tup, Binary, Unary, Lit, Cast, Type, Let, If, While, ForLoop, Loop, Match, Closure, Block, Await, TryBlock, Assign, @@ -576,7 +572,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { } fn visit_ty(&mut self, t: &'v ast::Ty) { - record_variants!((self, t, t.kind, Id::None, ast, Ty, TyKind), [ + record_variants!((self, t, t.kind, None, ast, Ty, TyKind), [ Slice, Array, Ptr, @@ -603,12 +599,12 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { } fn visit_generic_param(&mut self, g: &'v ast::GenericParam) { - self.record("GenericParam", Id::None, g); + self.record("GenericParam", None, g); ast_visit::walk_generic_param(self, g) } fn visit_where_predicate(&mut self, p: &'v ast::WherePredicate) { - record_variants!((self, p, p, Id::None, ast, WherePredicate, WherePredicate), [ + record_variants!((self, p, p, None, ast, WherePredicate, WherePredicate), [ BoundPredicate, RegionPredicate, EqPredicate @@ -617,12 +613,12 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { } fn visit_fn(&mut self, fk: ast_visit::FnKind<'v>, _: Span, _: NodeId) { - self.record("FnDecl", Id::None, fk.decl()); + self.record("FnDecl", None, fk.decl()); ast_visit::walk_fn(self, fk) } fn visit_assoc_item(&mut self, i: &'v ast::AssocItem, ctxt: ast_visit::AssocCtxt) { - record_variants!((self, i, i.kind, Id::None, ast, AssocItem, AssocItemKind), [ + record_variants!((self, i, i.kind, None, ast, AssocItem, AssocItemKind), [ Const, Fn, Type, @@ -634,19 +630,19 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { } fn visit_param_bound(&mut self, b: &'v ast::GenericBound, _ctxt: BoundKind) { - record_variants!((self, b, b, Id::None, ast, GenericBound, GenericBound), [ + record_variants!((self, b, b, None, ast, GenericBound, GenericBound), [ Trait, Outlives, Use ]); ast_visit::walk_param_bound(self, b) } fn visit_field_def(&mut self, s: &'v ast::FieldDef) { - self.record("FieldDef", Id::None, s); + self.record("FieldDef", None, s); ast_visit::walk_field_def(self, s) } fn visit_variant(&mut self, v: &'v ast::Variant) { - self.record("Variant", Id::None, v); + self.record("Variant", None, v); ast_visit::walk_variant(self, v) } @@ -660,7 +656,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { // common than the former case, so we implement this visitor and tolerate // the double counting in the former case. fn visit_path_segment(&mut self, path_segment: &'v ast::PathSegment) { - self.record("PathSegment", Id::None, path_segment); + self.record("PathSegment", None, path_segment); ast_visit::walk_path_segment(self, path_segment) } @@ -669,7 +665,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { // common, so we implement `visit_generic_args` and tolerate the double // counting in the former case. fn visit_generic_args(&mut self, g: &'v ast::GenericArgs) { - record_variants!((self, g, g, Id::None, ast, GenericArgs, GenericArgs), [ + record_variants!((self, g, g, None, ast, GenericArgs, GenericArgs), [ AngleBracketed, Parenthesized, ParenthesizedElided @@ -678,24 +674,24 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { } fn visit_attribute(&mut self, attr: &'v ast::Attribute) { - record_variants!((self, attr, attr.kind, Id::None, ast, Attribute, AttrKind), [ + record_variants!((self, attr, attr.kind, None, ast, Attribute, AttrKind), [ Normal, DocComment ]); ast_visit::walk_attribute(self, attr) } fn visit_expr_field(&mut self, f: &'v ast::ExprField) { - self.record("ExprField", Id::None, f); + self.record("ExprField", None, f); ast_visit::walk_expr_field(self, f) } fn visit_crate(&mut self, krate: &'v ast::Crate) { - self.record("Crate", Id::None, krate); + self.record("Crate", None, krate); ast_visit::walk_crate(self, krate) } fn visit_inline_asm(&mut self, asm: &'v ast::InlineAsm) { - self.record("InlineAsm", Id::None, asm); + self.record("InlineAsm", None, asm); ast_visit::walk_inline_asm(self, asm) } } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 890c4fdafef..fac2180d63b 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -378,7 +378,6 @@ symbols! { aggregate_raw_ptr, alias, align, - align_offset, alignment, all, alloc, diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 06408e0b210..cef11fe1c9e 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1595,11 +1595,10 @@ macro_rules! supported_targets { pub const TARGETS: &[&str] = &[$($tuple),+]; fn load_builtin(target: &str) -> Option<Target> { - let mut t = match target { + let t = match target { $( $tuple => targets::$module::target(), )+ _ => return None, }; - t.is_builtin = true; debug!("got builtin target: {:?}", t); Some(t) } @@ -2128,9 +2127,6 @@ type StaticCow<T> = Cow<'static, T>; /// through `Deref` impls. #[derive(PartialEq, Clone, Debug)] pub struct TargetOptions { - /// Whether the target is built-in or loaded from a custom target specification. - pub is_builtin: bool, - /// Used as the `target_endian` `cfg` variable. Defaults to little endian. pub endian: Endian, /// Width of c_int type. Defaults to "32". @@ -2606,7 +2602,6 @@ impl Default for TargetOptions { /// incomplete, and if used for compilation, will certainly not work. fn default() -> TargetOptions { TargetOptions { - is_builtin: false, endian: Endian::Little, c_int_width: "32".into(), os: "none".into(), @@ -3349,7 +3344,6 @@ impl Target { } } - key!(is_builtin, bool); key!(c_int_width = "target-c-int-width"); key!(c_enum_min_bits, Option<u64>); // if None, matches c_int_width key!(os); @@ -3462,10 +3456,6 @@ impl Target { key!(entry_abi, Conv)?; key!(supports_xray, bool); - if base.is_builtin { - // This can cause unfortunate ICEs later down the line. - return Err("may not set is_builtin for targets not built-in".into()); - } base.update_from_cli(); // Each field should have been read using `Json::remove` so any keys remaining are unused. @@ -3635,7 +3625,6 @@ impl ToJson for Target { target_val!(arch); target_val!(data_layout); - target_option_val!(is_builtin); target_option_val!(endian, "target-endian"); target_option_val!(c_int_width, "target-c-int-width"); target_option_val!(os); |
