diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 643f3c12134c9..eaceecc166778 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -827,7 +827,7 @@ impl Diagnostic { self } - pub fn styled_message(&self) -> &Vec<(DiagnosticMessage, Style)> { + pub fn styled_message(&self) -> &[(DiagnosticMessage, Style)] { &self.message } @@ -888,11 +888,11 @@ impl Diagnostic { &self, ) -> ( &Level, - &Vec<(DiagnosticMessage, Style)>, + &[(DiagnosticMessage, Style)], &Option, &MultiSpan, &Result, SuggestionsDisabled>, - Option<&Vec>, + Option<&[SubDiagnostic]>, ) { ( &self.level, diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 579d7efb56803..97deb9d986d46 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -352,7 +352,7 @@ pub fn same_type_modulo_infer<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { } impl<'a, 'tcx> InferCtxt<'a, 'tcx> { - pub fn report_region_errors(&self, errors: &Vec>) { + pub fn report_region_errors(&self, errors: &[RegionResolutionError<'tcx>]) { debug!("report_region_errors(): {} errors to start", errors.len()); // try to pre-process the errors, which will group some of them diff --git a/compiler/rustc_middle/src/middle/region.rs b/compiler/rustc_middle/src/middle/region.rs index 30ef6b775f5e3..c886175c6ea0e 100644 --- a/compiler/rustc_middle/src/middle/region.rs +++ b/compiler/rustc_middle/src/middle/region.rs @@ -16,6 +16,7 @@ use rustc_query_system::ich::StableHashingContext; use rustc_span::{Span, DUMMY_SP}; use std::fmt; +use std::ops::Deref; /// Represents a statically-describable scope that can be used to /// bound the lifetime/region for values. @@ -407,8 +408,8 @@ impl ScopeTree { /// Checks whether the given scope contains a `yield`. If so, /// returns `Some(YieldData)`. If not, returns `None`. - pub fn yield_in_scope(&self, scope: Scope) -> Option<&Vec> { - self.yield_in_scope.get(&scope) + pub fn yield_in_scope(&self, scope: Scope) -> Option<&[YieldData]> { + self.yield_in_scope.get(&scope).map(Deref::deref) } /// Gives the number of expressions visited in a body. diff --git a/compiler/rustc_middle/src/mir/traversal.rs b/compiler/rustc_middle/src/mir/traversal.rs index 5e8226d356f56..7e395902ad324 100644 --- a/compiler/rustc_middle/src/mir/traversal.rs +++ b/compiler/rustc_middle/src/mir/traversal.rs @@ -310,7 +310,7 @@ pub fn reachable_as_bitset<'tcx>(body: &Body<'tcx>) -> BitSet { #[derive(Clone)] pub struct ReversePostorderIter<'a, 'tcx> { body: &'a Body<'tcx>, - blocks: &'a Vec, + blocks: &'a [BasicBlock], idx: usize, } @@ -358,9 +358,9 @@ impl PostorderCache { self.cache = OnceCell::new(); } - /// Returns the &Vec represents the postorder graph for this MIR. + /// Returns the `&[BasicBlocks]` represents the postorder graph for this MIR. #[inline] - pub(super) fn compute(&self, body: &Body<'_>) -> &Vec { + pub(super) fn compute(&self, body: &Body<'_>) -> &[BasicBlock] { self.cache.get_or_init(|| Postorder::new(body, START_BLOCK).map(|(bb, _)| bb).collect()) } } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index faeb729c88483..09fe8415652ac 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1032,6 +1032,13 @@ impl<'tcx, T> Binder<'tcx, T> { Binder(&self.0, self.1) } + pub fn as_deref(&self) -> Binder<'tcx, &T::Target> + where + T: Deref, + { + Binder(&self.0, self.1) + } + pub fn map_bound_ref_unchecked(&self, f: F) -> Binder<'tcx, U> where F: FnOnce(&T) -> U, diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index 045d6eb1c3021..5d55c4d637b6e 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -133,7 +133,7 @@ fn convert_to_hir_projections_and_truncate_for_capture<'tcx>( /// ancestor of `foo.x.y`. It's the caller's responsibility to ensure that both projections /// list are being applied to the same root variable. fn is_ancestor_or_same_capture( - proj_possible_ancestor: &Vec, + proj_possible_ancestor: &[HirProjectionKind], proj_capture: &[HirProjectionKind], ) -> bool { // We want to make sure `is_ancestor_or_same_capture("x.0.0", "x.0")` to return false. @@ -187,7 +187,7 @@ fn find_capture_matching_projections<'a, 'tcx>( // If an ancestor is found, `idx` is the index within the list of captured places // for root variable `var_hir_id` and `capture` is the `ty::CapturedPlace` itself. let (idx, capture) = root_variable_min_captures.iter().enumerate().find(|(_, capture)| { - let possible_ancestor_proj_kinds = + let possible_ancestor_proj_kinds: Vec<_> = capture.place.projections.iter().map(|proj| proj.kind).collect(); is_ancestor_or_same_capture(&possible_ancestor_proj_kinds, &hir_projections) })?; diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 15660365938a0..43a84f69699aa 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -409,7 +409,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { outer_source_info: SourceInfo, candidate: Candidate<'_, 'tcx>, guard: Option<&Guard<'tcx>>, - fake_borrow_temps: &Vec<(Place<'tcx>, Local)>, + fake_borrow_temps: &[(Place<'tcx>, Local)], scrutinee_span: Span, arm_span: Option, arm_scope: Option, @@ -1826,7 +1826,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { candidate: Candidate<'pat, 'tcx>, parent_bindings: &[(Vec>, Vec>)], guard: Option<&Guard<'tcx>>, - fake_borrows: &Vec<(Place<'tcx>, Local)>, + fake_borrows: &[(Place<'tcx>, Local)], scrutinee_span: Span, arm_span: Option, match_scope: Option, diff --git a/compiler/rustc_mir_transform/src/coverage/counters.rs b/compiler/rustc_mir_transform/src/coverage/counters.rs index 6726b669ff2aa..45de0c280352f 100644 --- a/compiler/rustc_mir_transform/src/coverage/counters.rs +++ b/compiler/rustc_mir_transform/src/coverage/counters.rs @@ -43,7 +43,7 @@ impl CoverageCounters { pub fn make_bcb_counters( &mut self, basic_coverage_blocks: &mut CoverageGraph, - coverage_spans: &Vec, + coverage_spans: &[CoverageSpan], ) -> Result, Error> { let mut bcb_counters = BcbCounters::new(self, basic_coverage_blocks); bcb_counters.make_bcb_counters(coverage_spans) @@ -349,7 +349,7 @@ impl<'a> BcbCounters<'a> { // counters and/or expressions of its incoming edges. This will recursively get or create // counters for those incoming edges first, then call `make_expression()` to sum them up, // with additional intermediate expressions as needed. - let mut predecessors = self.bcb_predecessors(bcb).clone().into_iter(); + let mut predecessors = self.bcb_predecessors(bcb).to_owned().into_iter(); debug!( "{}{:?} has multiple incoming edges and will get an expression that sums them up...", NESTED_INDENT.repeat(debug_indent_level), @@ -571,12 +571,12 @@ impl<'a> BcbCounters<'a> { } #[inline] - fn bcb_predecessors(&self, bcb: BasicCoverageBlock) -> &Vec { + fn bcb_predecessors(&self, bcb: BasicCoverageBlock) -> &[BasicCoverageBlock] { &self.basic_coverage_blocks.predecessors[bcb] } #[inline] - fn bcb_successors(&self, bcb: BasicCoverageBlock) -> &Vec { + fn bcb_successors(&self, bcb: BasicCoverageBlock) -> &[BasicCoverageBlock] { &self.basic_coverage_blocks.successors[bcb] } diff --git a/compiler/rustc_mir_transform/src/coverage/debug.rs b/compiler/rustc_mir_transform/src/coverage/debug.rs index 434bf9d849e5a..d31ac04274cb8 100644 --- a/compiler/rustc_mir_transform/src/coverage/debug.rs +++ b/compiler/rustc_mir_transform/src/coverage/debug.rs @@ -124,6 +124,7 @@ use rustc_span::Span; use std::iter; use std::lazy::SyncOnceCell; +use std::ops::Deref; pub const NESTED_INDENT: &str = " "; @@ -434,11 +435,11 @@ impl GraphvizData { pub fn get_bcb_coverage_spans_with_counters( &self, bcb: BasicCoverageBlock, - ) -> Option<&Vec<(CoverageSpan, CoverageKind)>> { + ) -> Option<&[(CoverageSpan, CoverageKind)]> { if let Some(bcb_to_coverage_spans_with_counters) = self.some_bcb_to_coverage_spans_with_counters.as_ref() { - bcb_to_coverage_spans_with_counters.get(&bcb) + bcb_to_coverage_spans_with_counters.get(&bcb).map(Deref::deref) } else { None } @@ -457,12 +458,9 @@ impl GraphvizData { } } - pub fn get_bcb_dependency_counters( - &self, - bcb: BasicCoverageBlock, - ) -> Option<&Vec> { + pub fn get_bcb_dependency_counters(&self, bcb: BasicCoverageBlock) -> Option<&[CoverageKind]> { if let Some(bcb_to_dependency_counters) = self.some_bcb_to_dependency_counters.as_ref() { - bcb_to_dependency_counters.get(&bcb) + bcb_to_dependency_counters.get(&bcb).map(Deref::deref) } else { None } @@ -571,11 +569,11 @@ impl UsedExpressions { /// associated with a coverage span). pub fn validate( &mut self, - bcb_counters_without_direct_coverage_spans: &Vec<( + bcb_counters_without_direct_coverage_spans: &[( Option, BasicCoverageBlock, CoverageKind, - )>, + )], ) { if self.is_enabled() { let mut not_validated = bcb_counters_without_direct_coverage_spans @@ -634,7 +632,7 @@ pub(super) fn dump_coverage_spanview<'tcx>( basic_coverage_blocks: &CoverageGraph, pass_name: &str, body_span: Span, - coverage_spans: &Vec, + coverage_spans: &[CoverageSpan], ) { let mir_source = mir_body.source; let def_id = mir_source.def_id(); @@ -654,7 +652,7 @@ fn span_viewables<'tcx>( tcx: TyCtxt<'tcx>, mir_body: &mir::Body<'tcx>, basic_coverage_blocks: &CoverageGraph, - coverage_spans: &Vec, + coverage_spans: &[CoverageSpan], ) -> Vec { let mut span_viewables = Vec::new(); for coverage_span in coverage_spans { @@ -676,7 +674,7 @@ pub(super) fn dump_coverage_graphviz<'tcx>( basic_coverage_blocks: &CoverageGraph, debug_counters: &DebugCounters, graphviz_data: &GraphvizData, - intermediate_expressions: &Vec, + intermediate_expressions: &[CoverageKind], debug_used_expressions: &UsedExpressions, ) { let mir_source = mir_body.source; @@ -753,9 +751,9 @@ fn bcb_to_string_sections<'tcx>( mir_body: &mir::Body<'tcx>, debug_counters: &DebugCounters, bcb_data: &BasicCoverageBlockData, - some_coverage_spans_with_counters: Option<&Vec<(CoverageSpan, CoverageKind)>>, - some_dependency_counters: Option<&Vec>, - some_intermediate_expressions: Option<&Vec>, + some_coverage_spans_with_counters: Option<&[(CoverageSpan, CoverageKind)]>, + some_dependency_counters: Option<&[CoverageKind]>, + some_intermediate_expressions: Option<&[CoverageKind]>, ) -> Vec { let len = bcb_data.basic_blocks.len(); let mut sections = Vec::new(); diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 288c89b0189c4..771eeee965bb8 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -631,7 +631,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { span, }, |this| { - this.visit_generic_param_vec(&bare_fn.generic_params, false); + this.visit_generic_params(&bare_fn.generic_params, false); this.with_lifetime_rib( LifetimeRibKind::AnonymousPassThrough(ty.id, false), |this| walk_list!(this, visit_param, &bare_fn.decl.inputs), @@ -662,7 +662,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { span, }, |this| { - this.visit_generic_param_vec(&tref.bound_generic_params, false); + this.visit_generic_params(&tref.bound_generic_params, false); this.smart_resolve_path( tref.trait_ref.ref_id, None, @@ -833,7 +833,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { } fn visit_generics(&mut self, generics: &'ast Generics) { - self.visit_generic_param_vec( + self.visit_generic_params( &generics.params, self.diagnostic_metadata.current_self_item.is_some(), ); @@ -941,7 +941,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { span, }, |this| { - this.visit_generic_param_vec(&bound_generic_params, false); + this.visit_generic_params(&bound_generic_params, false); this.visit_ty(bounded_ty); for bound in bounds { this.visit_param_bound(bound, BoundKind::Bound) @@ -1116,7 +1116,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { } } - fn visit_generic_param_vec(&mut self, params: &'ast Vec, add_self_upper: bool) { + fn visit_generic_params(&mut self, params: &'ast [GenericParam], add_self_upper: bool) { // For type parameter defaults, we have to ban access // to following type parameters, as the InternalSubsts can only // provide previous type parameters as they're built. We @@ -1870,7 +1870,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { fn with_generic_param_rib<'c, F>( &'c mut self, - params: &'c Vec, + params: &'c [GenericParam], kind: RibKind<'a>, lifetime_kind: LifetimeRibKind, f: F, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index d0f20022bfbad..fd0732f51d5e8 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -146,11 +146,13 @@ impl<'tcx, 'a> GeneratorData<'tcx, 'a> { /// that are live across the yield of this generator fn get_generator_interior_types( &self, - ) -> ty::Binder<'tcx, &Vec>> { + ) -> ty::Binder<'tcx, &[GeneratorInteriorTypeCause<'tcx>]> { match self { - GeneratorData::Local(typeck_result) => typeck_result.generator_interior_types.as_ref(), + GeneratorData::Local(typeck_result) => { + typeck_result.generator_interior_types.as_deref() + } GeneratorData::Foreign(generator_diagnostic_data) => { - generator_diagnostic_data.generator_interior_types.as_ref() + generator_diagnostic_data.generator_interior_types.as_deref() } } } diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 641b915f37362..17e0fae985315 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -773,7 +773,7 @@ pub struct PlaceholderReplacer<'me, 'tcx> { mapped_regions: BTreeMap, mapped_types: BTreeMap, mapped_consts: BTreeMap, ty::BoundVar>, - universe_indices: &'me Vec>, + universe_indices: &'me [Option], current_index: ty::DebruijnIndex, } @@ -783,7 +783,7 @@ impl<'me, 'tcx> PlaceholderReplacer<'me, 'tcx> { mapped_regions: BTreeMap, mapped_types: BTreeMap, mapped_consts: BTreeMap, ty::BoundVar>, - universe_indices: &'me Vec>, + universe_indices: &'me [Option], value: T, ) -> T { let mut replacer = PlaceholderReplacer { diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index ea81f1ef90c9a..e3e0063c4ec6a 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -2448,7 +2448,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, span: Span, base_t: Ty<'tcx>, - ) -> Option<(&Vec, SubstsRef<'tcx>)> { + ) -> Option<(&[ty::FieldDef], SubstsRef<'tcx>)> { debug!("get_field_candidates(span: {:?}, base_t: {:?}", span, base_t); for (base_t, _) in self.autoderef(span, base_t) { diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index f57d576105185..8074ff368cc8c 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -2039,7 +2039,7 @@ fn should_do_rust_2021_incompatible_closure_captures_analysis( /// - s2: Comma separated names of the variables being migrated. fn migration_suggestion_for_2229( tcx: TyCtxt<'_>, - need_migrations: &Vec, + need_migrations: &[NeededMigration], ) -> (String, String) { let need_migrations_variables = need_migrations .iter()