Skip to content

Commit bdc9291

Browse files
committed
where possible, pass slices instead of &Vec or &String (clippy::ptr_arg)
1 parent b9c403b commit bdc9291

File tree

13 files changed

+21
-27
lines changed

13 files changed

+21
-27
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
522522
mut bx: Bx,
523523
terminator: &mir::Terminator<'tcx>,
524524
func: &mir::Operand<'tcx>,
525-
args: &Vec<mir::Operand<'tcx>>,
525+
args: &[mir::Operand<'tcx>],
526526
destination: &Option<(mir::Place<'tcx>, mir::BasicBlock)>,
527527
cleanup: Option<mir::BasicBlock>,
528528
fn_span: Span,

compiler/rustc_driver/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
603603
}
604604
}
605605

606-
fn show_content_with_pager(content: &String) {
606+
fn show_content_with_pager(content: &str) {
607607
let pager_name = env::var_os("PAGER").unwrap_or_else(|| {
608608
if cfg!(windows) { OsString::from("more.com") } else { OsString::from("less") }
609609
});

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
417417
// obviously it never weeds out ALL errors.
418418
fn process_errors(
419419
&self,
420-
errors: &Vec<RegionResolutionError<'tcx>>,
420+
errors: &[RegionResolutionError<'tcx>],
421421
) -> Vec<RegionResolutionError<'tcx>> {
422422
debug!("process_errors()");
423423

@@ -442,7 +442,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
442442
};
443443

444444
let mut errors = if errors.iter().all(|e| is_bound_failure(e)) {
445-
errors.clone()
445+
errors.to_owned()
446446
} else {
447447
errors.iter().filter(|&e| !is_bound_failure(e)).cloned().collect()
448448
};

compiler/rustc_macros/src/session_diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
574574
/// format!("Expected a point greater than ({x}, {y})", x = self.x, y = self.y)
575575
/// ```
576576
/// This function builds the entire call to format!.
577-
fn build_format(&self, input: &String, span: proc_macro2::Span) -> proc_macro2::TokenStream {
577+
fn build_format(&self, input: &str, span: proc_macro2::Span) -> proc_macro2::TokenStream {
578578
// This set is used later to generate the final format string. To keep builds reproducible,
579579
// the iteration order needs to be deterministic, hence why we use a BTreeSet here instead
580580
// of a HashSet.

compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
954954
&self,
955955
def_id: DefId,
956956
target_place: PlaceRef<'tcx>,
957-
places: &Vec<Operand<'tcx>>,
957+
places: &[Operand<'tcx>],
958958
) -> Option<(Span, Option<GeneratorKind>, Span)> {
959959
debug!(
960960
"closure_span: def_id={:?} target_place={:?} places={:?}",

compiler/rustc_mir/src/borrow_check/type_check/liveness/local_use_map.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ impl vll::LinkElem for Appearance {
5858
}
5959

6060
impl LocalUseMap {
61-
crate fn build(
62-
live_locals: &Vec<Local>,
63-
elements: &RegionValueElements,
64-
body: &Body<'_>,
65-
) -> Self {
61+
crate fn build(live_locals: &[Local], elements: &RegionValueElements, body: &Body<'_>) -> Self {
6662
let nones = IndexVec::from_elem_n(None, body.local_decls.len());
6763
let mut local_use_map = LocalUseMap {
6864
first_def_at: nones.clone(),

compiler/rustc_mir/src/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<T: Copy + Eq + Hash + std::fmt::Debug, PATH: Default> RefTracking<T, PATH>
153153
}
154154

155155
/// Format a path
156-
fn write_path(out: &mut String, path: &Vec<PathElem>) {
156+
fn write_path(out: &mut String, path: &[PathElem]) {
157157
use self::PathElem::*;
158158

159159
for elem in path.iter() {

compiler/rustc_mir/src/transform/coverage/counters.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<'a> BcbCounters<'a> {
140140
/// message for subsequent debugging.
141141
fn make_bcb_counters(
142142
&mut self,
143-
coverage_spans: &Vec<CoverageSpan>,
143+
coverage_spans: &[CoverageSpan],
144144
) -> Result<Vec<CoverageKind>, Error> {
145145
debug!("make_bcb_counters(): adding a counter or expression to each BasicCoverageBlock");
146146
let num_bcbs = self.basic_coverage_blocks.num_nodes();
@@ -465,7 +465,7 @@ impl<'a> BcbCounters<'a> {
465465
fn choose_preferred_expression_branch(
466466
&self,
467467
traversal: &TraverseCoverageGraphWithLoops,
468-
branches: &Vec<BcbBranch>,
468+
branches: &[BcbBranch],
469469
) -> BcbBranch {
470470
let branch_needs_a_counter =
471471
|branch: &BcbBranch| branch.counter(&self.basic_coverage_blocks).is_none();
@@ -509,7 +509,7 @@ impl<'a> BcbCounters<'a> {
509509
fn find_some_reloop_branch(
510510
&self,
511511
traversal: &TraverseCoverageGraphWithLoops,
512-
branches: &Vec<BcbBranch>,
512+
branches: &[BcbBranch],
513513
) -> Option<BcbBranch> {
514514
let branch_needs_a_counter =
515515
|branch: &BcbBranch| branch.counter(&self.basic_coverage_blocks).is_none();

compiler/rustc_mir/src/transform/function_item_references.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'a, 'tcx> FunctionItemRefChecker<'a, 'tcx> {
9999
&self,
100100
def_id: DefId,
101101
substs_ref: SubstsRef<'tcx>,
102-
args: &Vec<Operand<'tcx>>,
102+
args: &[Operand<'tcx>],
103103
source_info: SourceInfo,
104104
) {
105105
let param_env = self.tcx.param_env(def_id);
@@ -162,7 +162,7 @@ impl<'a, 'tcx> FunctionItemRefChecker<'a, 'tcx> {
162162
.unwrap_or(None)
163163
}
164164

165-
fn nth_arg_span(&self, args: &Vec<Operand<'tcx>>, n: usize) -> Span {
165+
fn nth_arg_span(&self, args: &[Operand<'tcx>], n: usize) -> Span {
166166
match &args[n] {
167167
Operand::Copy(place) | Operand::Move(place) => {
168168
self.body.local_decls[place.local].source_info.span

compiler/rustc_mir_build/src/build/expr/as_place.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ crate struct PlaceBuilder<'tcx> {
7979
/// part of a path that is captued by a closure. We stop applying projections once we see the first
8080
/// projection that isn't captured by a closure.
8181
fn convert_to_hir_projections_and_truncate_for_capture<'tcx>(
82-
mir_projections: &Vec<PlaceElem<'tcx>>,
82+
mir_projections: &[PlaceElem<'tcx>],
8383
) -> Vec<HirProjectionKind> {
8484

8585
let mut hir_projections = Vec::new();
@@ -128,7 +128,7 @@ fn convert_to_hir_projections_and_truncate_for_capture<'tcx>(
128128
/// list are being applied to the same root variable.
129129
fn is_ancestor_or_same_capture(
130130
proj_possible_ancestor: &Vec<HirProjectionKind>,
131-
proj_capture: &Vec<HirProjectionKind>,
131+
proj_capture: &[HirProjectionKind],
132132
) -> bool {
133133
// We want to make sure `is_ancestor_or_same_capture("x.0.0", "x.0")` to return false.
134134
// Therefore we can't just check if all projections are same in the zipped iterator below.
@@ -171,7 +171,7 @@ fn find_capture_matching_projections<'a, 'tcx>(
171171
typeck_results: &'a ty::TypeckResults<'tcx>,
172172
var_hir_id: HirId,
173173
closure_def_id: DefId,
174-
projections: &Vec<PlaceElem<'tcx>>,
174+
projections: &[PlaceElem<'tcx>],
175175
) -> Option<(usize, &'a ty::CapturedPlace<'tcx>)> {
176176
let closure_min_captures = typeck_results.closure_min_captures.get(&closure_def_id)?;
177177
let root_variable_min_captures = closure_min_captures.get(&var_hir_id)?;

compiler/rustc_resolve/src/late.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1151,13 +1151,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
11511151
/// When evaluating a `trait` use its associated types' idents for suggestions in E0412.
11521152
fn with_trait_items<T>(
11531153
&mut self,
1154-
trait_items: &'ast Vec<P<AssocItem>>,
1154+
trait_items: &'ast [P<AssocItem>],
11551155
f: impl FnOnce(&mut Self) -> T,
11561156
) -> T {
1157-
let trait_assoc_items = replace(
1158-
&mut self.diagnostic_metadata.current_trait_assoc_items,
1159-
Some(&trait_items[..]),
1160-
);
1157+
let trait_assoc_items =
1158+
replace(&mut self.diagnostic_metadata.current_trait_assoc_items, Some(&trait_items));
11611159
let result = f(self);
11621160
self.diagnostic_metadata.current_trait_assoc_items = trait_assoc_items;
11631161
result

compiler/rustc_session/src/filesearch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'a> FileSearch<'a> {
7676
pub fn new(
7777
sysroot: &'a Path,
7878
triple: &'a str,
79-
search_paths: &'a Vec<SearchPath>,
79+
search_paths: &'a [SearchPath],
8080
tlib_path: &'a SearchPath,
8181
kind: PathKind,
8282
) -> FileSearch<'a> {

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3483,7 +3483,7 @@ enum AssocItemLink<'a> {
34833483
}
34843484

34853485
impl<'a> AssocItemLink<'a> {
3486-
fn anchor(&self, id: &'a String) -> Self {
3486+
fn anchor(&self, id: &'a str) -> Self {
34873487
match *self {
34883488
AssocItemLink::Anchor(_) => AssocItemLink::Anchor(Some(&id)),
34893489
ref other => *other,

0 commit comments

Comments
 (0)