Auto merge of #97697 - WaffleLapkin:no_ref_vec, r=WaffleLapkin
Replace `&Vec<_>`s with `&[_]`s It's generally preferable to use `&[_]` since it's one less indirection and it can be created from types other that `Vec`. I've left `&Vec` in some locals where it doesn't really matter, in cases where `TypeFoldable` is expected (`TypeFoldable: Clone` so slice can't implement it) and in cases where it's `&TypeAliasThatIsActiallyVec`. Nothing important, really, I was just a little annoyed by `visit_generic_param_vec` :D r? `@compiler-errors`
This commit is contained in:
commit
4322a785cc
@ -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<DiagnosticId>,
|
||||
&MultiSpan,
|
||||
&Result<Vec<CodeSuggestion>, SuggestionsDisabled>,
|
||||
Option<&Vec<SubDiagnostic>>,
|
||||
Option<&[SubDiagnostic]>,
|
||||
) {
|
||||
(
|
||||
&self.level,
|
||||
|
@ -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<RegionResolutionError<'tcx>>) {
|
||||
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
|
||||
|
@ -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<YieldData>> {
|
||||
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.
|
||||
|
@ -310,7 +310,7 @@ pub fn reachable_as_bitset<'tcx>(body: &Body<'tcx>) -> BitSet<BasicBlock> {
|
||||
#[derive(Clone)]
|
||||
pub struct ReversePostorderIter<'a, 'tcx> {
|
||||
body: &'a Body<'tcx>,
|
||||
blocks: &'a Vec<BasicBlock>,
|
||||
blocks: &'a [BasicBlock],
|
||||
idx: usize,
|
||||
}
|
||||
|
||||
@ -358,9 +358,9 @@ impl PostorderCache {
|
||||
self.cache = OnceCell::new();
|
||||
}
|
||||
|
||||
/// Returns the &Vec<BasicBlocks> 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<BasicBlock> {
|
||||
pub(super) fn compute(&self, body: &Body<'_>) -> &[BasicBlock] {
|
||||
self.cache.get_or_init(|| Postorder::new(body, START_BLOCK).map(|(bb, _)| bb).collect())
|
||||
}
|
||||
}
|
||||
|
@ -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<F, U>(&self, f: F) -> Binder<'tcx, U>
|
||||
where
|
||||
F: FnOnce(&T) -> U,
|
||||
|
@ -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<HirProjectionKind>,
|
||||
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)
|
||||
})?;
|
||||
|
@ -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<Span>,
|
||||
arm_scope: Option<region::Scope>,
|
||||
@ -1826,7 +1826,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
candidate: Candidate<'pat, 'tcx>,
|
||||
parent_bindings: &[(Vec<Binding<'tcx>>, Vec<Ascription<'tcx>>)],
|
||||
guard: Option<&Guard<'tcx>>,
|
||||
fake_borrows: &Vec<(Place<'tcx>, Local)>,
|
||||
fake_borrows: &[(Place<'tcx>, Local)],
|
||||
scrutinee_span: Span,
|
||||
arm_span: Option<Span>,
|
||||
match_scope: Option<region::Scope>,
|
||||
|
@ -43,7 +43,7 @@ impl CoverageCounters {
|
||||
pub fn make_bcb_counters(
|
||||
&mut self,
|
||||
basic_coverage_blocks: &mut CoverageGraph,
|
||||
coverage_spans: &Vec<CoverageSpan>,
|
||||
coverage_spans: &[CoverageSpan],
|
||||
) -> Result<Vec<CoverageKind>, 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<BasicCoverageBlock> {
|
||||
fn bcb_predecessors(&self, bcb: BasicCoverageBlock) -> &[BasicCoverageBlock] {
|
||||
&self.basic_coverage_blocks.predecessors[bcb]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn bcb_successors(&self, bcb: BasicCoverageBlock) -> &Vec<BasicCoverageBlock> {
|
||||
fn bcb_successors(&self, bcb: BasicCoverageBlock) -> &[BasicCoverageBlock] {
|
||||
&self.basic_coverage_blocks.successors[bcb]
|
||||
}
|
||||
|
||||
|
@ -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<CoverageKind>> {
|
||||
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>,
|
||||
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<CoverageSpan>,
|
||||
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<CoverageSpan>,
|
||||
coverage_spans: &[CoverageSpan],
|
||||
) -> Vec<SpanViewable> {
|
||||
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<CoverageKind>,
|
||||
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<CoverageKind>>,
|
||||
some_intermediate_expressions: Option<&Vec<CoverageKind>>,
|
||||
some_coverage_spans_with_counters: Option<&[(CoverageSpan, CoverageKind)]>,
|
||||
some_dependency_counters: Option<&[CoverageKind]>,
|
||||
some_intermediate_expressions: Option<&[CoverageKind]>,
|
||||
) -> Vec<String> {
|
||||
let len = bcb_data.basic_blocks.len();
|
||||
let mut sections = Vec::new();
|
||||
|
@ -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<GenericParam>, 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<GenericParam>,
|
||||
params: &'c [GenericParam],
|
||||
kind: RibKind<'a>,
|
||||
lifetime_kind: LifetimeRibKind,
|
||||
f: F,
|
||||
|
@ -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<GeneratorInteriorTypeCause<'tcx>>> {
|
||||
) -> 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -773,7 +773,7 @@ pub struct PlaceholderReplacer<'me, 'tcx> {
|
||||
mapped_regions: BTreeMap<ty::PlaceholderRegion, ty::BoundRegion>,
|
||||
mapped_types: BTreeMap<ty::PlaceholderType, ty::BoundTy>,
|
||||
mapped_consts: BTreeMap<ty::PlaceholderConst<'tcx>, ty::BoundVar>,
|
||||
universe_indices: &'me Vec<Option<ty::UniverseIndex>>,
|
||||
universe_indices: &'me [Option<ty::UniverseIndex>],
|
||||
current_index: ty::DebruijnIndex,
|
||||
}
|
||||
|
||||
@ -783,7 +783,7 @@ impl<'me, 'tcx> PlaceholderReplacer<'me, 'tcx> {
|
||||
mapped_regions: BTreeMap<ty::PlaceholderRegion, ty::BoundRegion>,
|
||||
mapped_types: BTreeMap<ty::PlaceholderType, ty::BoundTy>,
|
||||
mapped_consts: BTreeMap<ty::PlaceholderConst<'tcx>, ty::BoundVar>,
|
||||
universe_indices: &'me Vec<Option<ty::UniverseIndex>>,
|
||||
universe_indices: &'me [Option<ty::UniverseIndex>],
|
||||
value: T,
|
||||
) -> T {
|
||||
let mut replacer = PlaceholderReplacer {
|
||||
|
@ -2448,7 +2448,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
span: Span,
|
||||
base_t: Ty<'tcx>,
|
||||
) -> Option<(&Vec<ty::FieldDef>, 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) {
|
||||
|
@ -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<NeededMigration>,
|
||||
need_migrations: &[NeededMigration],
|
||||
) -> (String, String) {
|
||||
let need_migrations_variables = need_migrations
|
||||
.iter()
|
||||
|
Loading…
x
Reference in New Issue
Block a user