Skip to content

Commit 59f8422

Browse files
authored
Rollup merge of #52781 - ljedrz:avoid_vec_arguments, r=nikomatsakis
Use a slice where a vector is not necessary
2 parents f0efbc0 + 1cca420 commit 59f8422

File tree

15 files changed

+30
-30
lines changed

15 files changed

+30
-30
lines changed

src/librustc/hir/lowering.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ impl<'a> LoweringContext<'a> {
746746
// This is used to track which lifetimes have already been defined, and
747747
// which are new in-band lifetimes that need to have a definition created
748748
// for them.
749-
fn with_in_scope_lifetime_defs<T, F>(&mut self, params: &Vec<GenericParam>, f: F) -> T
749+
fn with_in_scope_lifetime_defs<T, F>(&mut self, params: &[GenericParam], f: F) -> T
750750
where
751751
F: FnOnce(&mut LoweringContext) -> T,
752752
{
@@ -2237,7 +2237,7 @@ impl<'a> LoweringContext<'a> {
22372237

22382238
fn lower_generic_params(
22392239
&mut self,
2240-
params: &Vec<GenericParam>,
2240+
params: &[GenericParam],
22412241
add_bounds: &NodeMap<Vec<GenericBound>>,
22422242
mut itctx: ImplTraitContext,
22432243
) -> hir::HirVec<hir::GenericParam> {

src/librustc/ich/hcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
396396
pub fn hash_stable_trait_impls<'a, 'gcx, W, R>(
397397
hcx: &mut StableHashingContext<'a>,
398398
hasher: &mut StableHasher<W>,
399-
blanket_impls: &Vec<DefId>,
399+
blanket_impls: &[DefId],
400400
non_blanket_impls: &HashMap<fast_reject::SimplifiedType, Vec<DefId>, R>)
401401
where W: StableHasherResult,
402402
R: std_hash::BuildHasher,

src/librustc/traits/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use syntax_pos::{DUMMY_SP, Span};
4848

4949
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
5050
pub fn report_fulfillment_errors(&self,
51-
errors: &Vec<FulfillmentError<'tcx>>,
51+
errors: &[FulfillmentError<'tcx>],
5252
body_id: Option<hir::BodyId>,
5353
fallback_has_occurred: bool) {
5454
#[derive(Debug)]
@@ -1015,7 +1015,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10151015
) -> DiagnosticBuilder<'tcx> {
10161016
let kind = if is_closure { "closure" } else { "function" };
10171017

1018-
let args_str = |arguments: &Vec<ArgKind>, other: &Vec<ArgKind>| {
1018+
let args_str = |arguments: &[ArgKind], other: &[ArgKind]| {
10191019
let arg_length = arguments.len();
10201020
let distinct = match &other[..] {
10211021
&[ArgKind::Tuple(..)] => true,

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub struct GroupedMoveErrors<'tcx> {
6868
move_to_places: Vec<MovePlace<'tcx>>
6969
}
7070

71-
fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &Vec<MoveError<'tcx>>) {
71+
fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &[MoveError<'tcx>]) {
7272
let grouped_errors = group_errors_with_same_origin(errors);
7373
for error in &grouped_errors {
7474
let mut err = report_cannot_move_out_of(bccx, error.move_from.clone());
@@ -103,7 +103,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &Vec<Move
103103
}
104104
}
105105

106-
fn group_errors_with_same_origin<'tcx>(errors: &Vec<MoveError<'tcx>>)
106+
fn group_errors_with_same_origin<'tcx>(errors: &[MoveError<'tcx>])
107107
-> Vec<GroupedMoveErrors<'tcx>> {
108108
let mut grouped_errors = Vec::new();
109109
for error in errors {

src/librustc_driver/driver.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ fn generated_output_paths(
13951395

13961396
// Runs `f` on every output file path and returns the first non-None result, or None if `f`
13971397
// returns None for every file path.
1398-
fn check_output<F, T>(output_paths: &Vec<PathBuf>, f: F) -> Option<T>
1398+
fn check_output<F, T>(output_paths: &[PathBuf], f: F) -> Option<T>
13991399
where
14001400
F: Fn(&PathBuf) -> Option<T>,
14011401
{
@@ -1407,7 +1407,7 @@ where
14071407
None
14081408
}
14091409

1410-
pub fn output_contains_path(output_paths: &Vec<PathBuf>, input_path: &PathBuf) -> bool {
1410+
pub fn output_contains_path(output_paths: &[PathBuf], input_path: &PathBuf) -> bool {
14111411
let input_path = input_path.canonicalize().ok();
14121412
if input_path.is_none() {
14131413
return false;
@@ -1422,7 +1422,7 @@ pub fn output_contains_path(output_paths: &Vec<PathBuf>, input_path: &PathBuf) -
14221422
check_output(output_paths, check).is_some()
14231423
}
14241424

1425-
pub fn output_conflicts_with_dir(output_paths: &Vec<PathBuf>) -> Option<PathBuf> {
1425+
pub fn output_conflicts_with_dir(output_paths: &[PathBuf]) -> Option<PathBuf> {
14261426
let check = |output_path: &PathBuf| {
14271427
if output_path.is_dir() {
14281428
Some(output_path.clone())
@@ -1433,7 +1433,7 @@ pub fn output_conflicts_with_dir(output_paths: &Vec<PathBuf>) -> Option<PathBuf>
14331433
check_output(output_paths, check)
14341434
}
14351435

1436-
fn write_out_deps(sess: &Session, outputs: &OutputFilenames, out_filenames: &Vec<PathBuf>) {
1436+
fn write_out_deps(sess: &Session, outputs: &OutputFilenames, out_filenames: &[PathBuf]) {
14371437
// Write out dependency rules to the dep-info file if requested
14381438
if !sess.opts.output_types.contains_key(&OutputType::DepInfo) {
14391439
return;

src/librustc_driver/profile/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct StackFrame {
6262
pub traces: Vec<trace::Rec>,
6363
}
6464

65-
fn total_duration(traces: &Vec<trace::Rec>) -> Duration {
65+
fn total_duration(traces: &[trace::Rec]) -> Duration {
6666
let mut sum : Duration = Duration::new(0,0);
6767
for t in traces.iter() { sum += t.dur_total; }
6868
return sum

src/librustc_driver/profile/trace.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn html_of_fraction(frac: f64) -> (String, String) {
107107
else { (format!("< 0.1%", ), css) }
108108
}
109109

110-
fn total_duration(traces: &Vec<Rec>) -> Duration {
110+
fn total_duration(traces: &[Rec]) -> Duration {
111111
let mut sum : Duration = Duration::new(0,0);
112112
for t in traces.iter() {
113113
sum += t.dur_total;
@@ -123,7 +123,7 @@ fn duration_div(nom: Duration, den: Duration) -> f64 {
123123
to_nanos(nom) as f64 / to_nanos(den) as f64
124124
}
125125

126-
fn write_traces_rec(file: &mut File, traces: &Vec<Rec>, total: Duration, depth: usize) {
126+
fn write_traces_rec(file: &mut File, traces: &[Rec], total: Duration, depth: usize) {
127127
for t in traces {
128128
let (eff_text, eff_css_classes) = html_of_effect(&t.effect);
129129
let (dur_text, dur_css_classes) = html_of_duration(&t.start, &t.dur_total);
@@ -149,7 +149,7 @@ fn write_traces_rec(file: &mut File, traces: &Vec<Rec>, total: Duration, depth:
149149
}
150150
}
151151

152-
fn compute_counts_rec(counts: &mut HashMap<String,QueryMetric>, traces: &Vec<Rec>) {
152+
fn compute_counts_rec(counts: &mut HashMap<String,QueryMetric>, traces: &[Rec]) {
153153
for t in traces.iter() {
154154
match t.effect {
155155
Effect::TimeBegin(ref msg) => {
@@ -218,7 +218,7 @@ pub fn write_counts(count_file: &mut File, counts: &mut HashMap<String,QueryMetr
218218
}
219219
}
220220

221-
pub fn write_traces(html_file: &mut File, counts_file: &mut File, traces: &Vec<Rec>) {
221+
pub fn write_traces(html_file: &mut File, counts_file: &mut File, traces: &[Rec]) {
222222
let capacity = traces.iter().fold(0, |acc, t| acc + 1 + t.extent.len());
223223
let mut counts : HashMap<String, QueryMetric> = HashMap::with_capacity(capacity);
224224
compute_counts_rec(&mut counts, traces);

src/librustc_errors/emitter.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ impl EmitterWriter {
749749
max
750750
}
751751

752-
fn get_max_line_num(&mut self, span: &MultiSpan, children: &Vec<SubDiagnostic>) -> usize {
752+
fn get_max_line_num(&mut self, span: &MultiSpan, children: &[SubDiagnostic]) -> usize {
753753
let mut max = 0;
754754

755755
let primary = self.get_multispan_max_line_num(span);
@@ -954,7 +954,7 @@ impl EmitterWriter {
954954

955955
fn emit_message_default(&mut self,
956956
msp: &MultiSpan,
957-
msg: &Vec<(String, Style)>,
957+
msg: &[(String, Style)],
958958
code: &Option<DiagnosticId>,
959959
level: &Level,
960960
max_line_num_len: usize,
@@ -1317,10 +1317,10 @@ impl EmitterWriter {
13171317

13181318
fn emit_messages_default(&mut self,
13191319
level: &Level,
1320-
message: &Vec<(String, Style)>,
1320+
message: &[(String, Style)],
13211321
code: &Option<DiagnosticId>,
13221322
span: &MultiSpan,
1323-
children: &Vec<SubDiagnostic>,
1323+
children: &[SubDiagnostic],
13241324
suggestions: &[CodeSuggestion]) {
13251325
let max_line_num_len = if self.ui_testing {
13261326
ANONYMIZED_LINE_NUM.len()
@@ -1433,7 +1433,7 @@ fn overlaps(a1: &Annotation, a2: &Annotation, padding: usize) -> bool {
14331433
num_overlap(a1.start_col, a1.end_col + padding, a2.start_col, a2.end_col, false)
14341434
}
14351435

1436-
fn emit_to_destination(rendered_buffer: &Vec<Vec<StyledString>>,
1436+
fn emit_to_destination(rendered_buffer: &[Vec<StyledString>],
14371437
lvl: &Level,
14381438
dst: &mut Destination,
14391439
short_message: bool)

src/librustc_mir/borrow_check/nll/facts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct FactWriter<'w> {
120120
impl<'w> FactWriter<'w> {
121121
fn write_facts_to_path<T>(
122122
&self,
123-
rows: &Vec<T>,
123+
rows: &[T],
124124
file_name: &str,
125125
) -> Result<(), Box<dyn Error>>
126126
where

src/librustc_mir/interpret/terminator/drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
7878
self.eval_fn_call(
7979
instance,
8080
Some((Place::undef(), target)),
81-
&vec![valty],
81+
&[valty],
8282
span,
8383
fn_sig,
8484
)

src/librustc_mir/transform/uniform_array_move_out.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl RestoreSubsliceArrayMoveOut {
222222
// indices is an integer interval. If all checks pass do the replacent.
223223
// items are Vec<Option<LocalUse, index in source array, source place for init local>>
224224
fn check_and_patch<'tcx>(candidate: Location,
225-
items: &Vec<Option<(&LocalUse, u32, &Place<'tcx>)>>,
225+
items: &[Option<(&LocalUse, u32, &Place<'tcx>)>],
226226
opt_size: Option<u64>,
227227
patch: &mut MirPatch<'tcx>,
228228
dst_place: &Place<'tcx>) {

src/librustc_passes/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a> AstValidator<'a> {
147147
}
148148
}
149149

150-
fn check_late_bound_lifetime_defs(&self, params: &Vec<GenericParam>) {
150+
fn check_late_bound_lifetime_defs(&self, params: &[GenericParam]) {
151151
// Check only lifetime parameters are present and that the lifetime
152152
// parameters that are present have no bounds.
153153
let non_lt_param_spans: Vec<_> = params.iter().filter_map(|param| match param.kind {

src/librustc_resolve/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ impl<'a> Resolver<'a> {
783783
}
784784
};
785785
let ident = Ident::new(Symbol::intern(name), span);
786-
self.lookup_typo_candidate(&vec![ident], MacroNS, is_macro, span)
786+
self.lookup_typo_candidate(&[ident], MacroNS, is_macro, span)
787787
});
788788

789789
if let Some(suggestion) = suggestion {

src/librustdoc/html/render.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2690,7 +2690,7 @@ fn render_implementor(cx: &Context, implementor: &Impl, w: &mut fmt::Formatter,
26902690
for it in &implementor.inner_impl().items {
26912691
if let clean::TypedefItem(ref tydef, _) = it.inner {
26922692
write!(w, "<span class=\"where fmt-newline\"> ")?;
2693-
assoc_type(w, it, &vec![], Some(&tydef.type_), AssocItemLink::Anchor(None))?;
2693+
assoc_type(w, it, &[], Some(&tydef.type_), AssocItemLink::Anchor(None))?;
26942694
write!(w, ";</span>")?;
26952695
}
26962696
}
@@ -3040,7 +3040,7 @@ fn assoc_const(w: &mut fmt::Formatter,
30403040
}
30413041

30423042
fn assoc_type<W: fmt::Write>(w: &mut W, it: &clean::Item,
3043-
bounds: &Vec<clean::GenericBound>,
3043+
bounds: &[clean::GenericBound],
30443044
default: Option<&clean::Type>,
30453045
link: AssocItemLink) -> fmt::Result {
30463046
write!(w, "type <a href='{}' class=\"type\">{}</a>",
@@ -3749,7 +3749,7 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
37493749
for it in &impl_.items {
37503750
if let clean::TypedefItem(ref tydef, _) = it.inner {
37513751
out.push_str("<span class=\"where fmt-newline\"> ");
3752-
assoc_type(&mut out, it, &vec![],
3752+
assoc_type(&mut out, it, &[],
37533753
Some(&tydef.type_),
37543754
AssocItemLink::GotoSource(t_did, &FxHashSet()))?;
37553755
out.push_str(";</span>");

src/libsyntax/print/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3065,7 +3065,7 @@ impl<'a> State<'a> {
30653065
unsafety: ast::Unsafety,
30663066
decl: &ast::FnDecl,
30673067
name: Option<ast::Ident>,
3068-
generic_params: &Vec<ast::GenericParam>)
3068+
generic_params: &[ast::GenericParam])
30693069
-> io::Result<()> {
30703070
self.ibox(INDENT_UNIT)?;
30713071
if !generic_params.is_empty() {

0 commit comments

Comments
 (0)