Skip to content

Replace &Vec<_>s with &[_]s #97697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ impl Diagnostic {
self
}

pub fn styled_message(&self) -> &Vec<(DiagnosticMessage, Style)> {
pub fn styled_message(&self) -> &[(DiagnosticMessage, Style)] {
&self.message
}

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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())
}
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/build/expr/as_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
})?;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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>,
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir_transform/src/coverage/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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]
}

Expand Down
28 changes: 13 additions & 15 deletions compiler/rustc_mir_transform/src/coverage/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ use rustc_span::Span;

use std::iter;
use std::lazy::SyncOnceCell;
use std::ops::Deref;

pub const NESTED_INDENT: &str = " ";

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down