Skip to content

Commit 451987d

Browse files
committed
Auto merge of #55579 - pietroalbini:rollup, r=kennytm
Rollup of 13 pull requests Successful merges: - #55280 (Add libproc_macro to rust-src distribution) - #55469 (Regression tests for issue #54477.) - #55504 (Use vec![x; n] instead of iter::repeat(x).take(n).collect()) - #55522 (use String::from() instead of format!() macro to construct Strings.) - #55536 (Pass suggestions as impl Iterator instead of Vec) - #55542 (syntax: improve a few allocations) - #55558 (Tweak `MatcherPos::matches`) - #55561 (Fix double_check tests on big-endian targets) - #55573 (Make sure the `aws` executable is in $PATH on macOS) - #55574 (Use `SmallVec` within `MoveData`.) - #55575 (Fix invalid_const_promotion test on some archs) - #55578 (Made doc example of `impl Default for …` use `-> Self` instead of explicit self type) - #55582 (Remove unused import copy from publish_toolstate.py)
2 parents f6e9a6e + f76a8e3 commit 451987d

File tree

27 files changed

+86
-56
lines changed

27 files changed

+86
-56
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ matrix:
200200
before_install:
201201
# We'll use the AWS cli to download/upload cached docker layers as well as
202202
# push our deployments, so download that here.
203-
- pip install --user awscli; export PATH=$PATH:$HOME/.local/bin
203+
- pip install --user awscli; export PATH=$PATH:$HOME/.local/bin:$HOME/Library/Python/2.7/bin/
204204
- mkdir -p $HOME/rustsrc
205205
# FIXME(#46924): these two commands are required to enable IPv6,
206206
# they shouldn't exist, please revert once more official solutions appeared.

src/bootstrap/dist.rs

+1
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ impl Step for Src {
881881
"src/jemalloc",
882882
"src/libprofiler_builtins",
883883
"src/stdsimd",
884+
"src/libproc_macro",
884885
];
885886
let std_src_dirs_exclude = [
886887
"src/libcompiler_builtins/compiler-rt/test",

src/libcore/default.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
/// }
7777
///
7878
/// impl Default for Kind {
79-
/// fn default() -> Kind { Kind::A }
79+
/// fn default() -> Self { Kind::A }
8080
/// }
8181
/// ```
8282
///
@@ -118,7 +118,7 @@ pub trait Default: Sized {
118118
/// }
119119
///
120120
/// impl Default for Kind {
121-
/// fn default() -> Kind { Kind::A }
121+
/// fn default() -> Self { Kind::A }
122122
/// }
123123
/// ```
124124
#[stable(feature = "rust1", since = "1.0.0")]

src/librustc/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
12541254
Some(Node::MacroDef(_)) => {
12551255
format!("macro {}{}", path_str(), id_str)
12561256
}
1257-
Some(Node::Crate) => format!("root_crate"),
1257+
Some(Node::Crate) => String::from("root_crate"),
12581258
None => format!("unknown node{}", id_str),
12591259
}
12601260
}

src/librustc/mir/interpret/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,10 @@ impl AllocDecodingState {
295295
}
296296

297297
pub fn new(data_offsets: Vec<u32>) -> AllocDecodingState {
298-
let decoding_state: Vec<_> = ::std::iter::repeat(Mutex::new(State::Empty))
299-
.take(data_offsets.len())
300-
.collect();
298+
let decoding_state = vec![Mutex::new(State::Empty); data_offsets.len()];
301299

302300
AllocDecodingState {
303-
decoding_state: decoding_state,
301+
decoding_state,
304302
data_offsets,
305303
}
306304
}

src/librustc/traits/error_reporting.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use hir::def_id::DefId;
3434
use infer::{self, InferCtxt};
3535
use infer::type_variable::TypeVariableOrigin;
3636
use std::fmt;
37-
use std::iter;
3837
use syntax::ast;
3938
use session::DiagnosticMessageId;
4039
use ty::{self, AdtKind, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
@@ -1095,10 +1094,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10951094
// found arguments is empty (assume the user just wants to ignore args in this case).
10961095
// For example, if `expected_args_length` is 2, suggest `|_, _|`.
10971096
if found_args.is_empty() && is_closure {
1098-
let underscores = iter::repeat("_")
1099-
.take(expected_args.len())
1100-
.collect::<Vec<_>>()
1101-
.join(", ");
1097+
let underscores = vec!["_"; expected_args.len()].join(", ");
11021098
err.span_suggestion_with_applicability(
11031099
found_span,
11041100
&format!(

src/librustc_errors/diagnostic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,10 @@ impl Diagnostic {
350350
}
351351

352352
pub fn span_suggestions_with_applicability(&mut self, sp: Span, msg: &str,
353-
suggestions: Vec<String>,
354-
applicability: Applicability) -> &mut Self {
353+
suggestions: impl Iterator<Item = String>, applicability: Applicability) -> &mut Self
354+
{
355355
self.suggestions.push(CodeSuggestion {
356-
substitutions: suggestions.into_iter().map(|snippet| Substitution {
356+
substitutions: suggestions.map(|snippet| Substitution {
357357
parts: vec![SubstitutionPart {
358358
snippet,
359359
span: sp,

src/librustc_errors/diagnostic_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl<'a> DiagnosticBuilder<'a> {
253253
pub fn span_suggestions_with_applicability(&mut self,
254254
sp: Span,
255255
msg: &str,
256-
suggestions: Vec<String>,
256+
suggestions: impl Iterator<Item = String>,
257257
applicability: Applicability)
258258
-> &mut Self {
259259
if !self.allow_suggestions {

src/librustc_mir/borrow_check/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
788788

789789
let what_was_dropped = match self.describe_place(place) {
790790
Some(name) => format!("`{}`", name.as_str()),
791-
None => format!("temporary value"),
791+
None => String::from("temporary value"),
792792
};
793793

794794
let label = match self.describe_place(&borrow.borrowed_place) {
@@ -1028,7 +1028,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
10281028

10291029
match category {
10301030
ConstraintCategory::Return => {
1031-
err.span_note(constraint_span, &format!("closure is returned here"));
1031+
err.span_note(constraint_span, "closure is returned here");
10321032
}
10331033
ConstraintCategory::CallArgument => {
10341034
fr_name.highlight_region_name(&mut err);

src/librustc_mir/dataflow/move_paths/builder.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use rustc::ty::{self, TyCtxt};
1212
use rustc::mir::*;
1313
use rustc::mir::tcx::RvalueInitializationState;
1414
use rustc_data_structures::indexed_vec::{IndexVec};
15+
use smallvec::{SmallVec, smallvec};
1516

1617
use std::collections::hash_map::Entry;
1718
use std::mem;
1819

1920
use super::abs_domain::Lift;
20-
2121
use super::{LocationMap, MoveData, MovePath, MovePathLookup, MovePathIndex, MoveOut, MoveOutIndex};
2222
use super::{MoveError, InitIndex, Init, InitLocation, LookupResult, InitKind};
2323
use super::IllegalMoveOriginKind::*;
@@ -64,8 +64,8 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> {
6464
}
6565

6666
fn new_move_path(move_paths: &mut IndexVec<MovePathIndex, MovePath<'tcx>>,
67-
path_map: &mut IndexVec<MovePathIndex, Vec<MoveOutIndex>>,
68-
init_path_map: &mut IndexVec<MovePathIndex, Vec<InitIndex>>,
67+
path_map: &mut IndexVec<MovePathIndex, SmallVec<[MoveOutIndex; 4]>>,
68+
init_path_map: &mut IndexVec<MovePathIndex, SmallVec<[InitIndex; 4]>>,
6969
parent: Option<MovePathIndex>,
7070
place: Place<'tcx>)
7171
-> MovePathIndex
@@ -83,10 +83,10 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> {
8383
move_paths[move_path].next_sibling = next_sibling;
8484
}
8585

86-
let path_map_ent = path_map.push(vec![]);
86+
let path_map_ent = path_map.push(smallvec![]);
8787
assert_eq!(path_map_ent, move_path);
8888

89-
let init_path_map_ent = init_path_map.push(vec![]);
89+
let init_path_map_ent = init_path_map.push(smallvec![]);
9090
assert_eq!(init_path_map_ent, move_path);
9191

9292
move_path

src/librustc_mir/dataflow/move_paths/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc::ty::{self, TyCtxt};
1313
use rustc::mir::*;
1414
use rustc::util::nodemap::FxHashMap;
1515
use rustc_data_structures::indexed_vec::{IndexVec};
16+
use smallvec::SmallVec;
1617
use syntax_pos::{Span};
1718

1819
use std::fmt;
@@ -141,14 +142,14 @@ pub struct MoveData<'tcx> {
141142
/// of executing the code at `l`. (There can be multiple MoveOut's
142143
/// for a given `l` because each MoveOut is associated with one
143144
/// particular path being moved.)
144-
pub loc_map: LocationMap<Vec<MoveOutIndex>>,
145-
pub path_map: IndexVec<MovePathIndex, Vec<MoveOutIndex>>,
145+
pub loc_map: LocationMap<SmallVec<[MoveOutIndex; 4]>>,
146+
pub path_map: IndexVec<MovePathIndex, SmallVec<[MoveOutIndex; 4]>>,
146147
pub rev_lookup: MovePathLookup<'tcx>,
147148
pub inits: IndexVec<InitIndex, Init>,
148149
/// Each Location `l` is mapped to the Inits that are effects
149150
/// of executing the code at `l`.
150-
pub init_loc_map: LocationMap<Vec<InitIndex>>,
151-
pub init_path_map: IndexVec<MovePathIndex, Vec<InitIndex>>,
151+
pub init_loc_map: LocationMap<SmallVec<[InitIndex; 4]>>,
152+
pub init_path_map: IndexVec<MovePathIndex, SmallVec<[InitIndex; 4]>>,
152153
}
153154

154155
pub trait HasMoveData<'tcx> {

src/librustc_mir/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
408408
),
409409
_ =>
410410
return validation_failure!(
411-
format!("non-integer enum discriminant"), path
411+
String::from("non-integer enum discriminant"), path
412412
),
413413
}
414414
};

src/librustc_mir/util/borrowck_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ pub trait BorrowckErrors<'cx>: Sized + Copy {
575575
OGN = o
576576
);
577577
err.span_label(mutate_span, format!("cannot {}", action));
578-
err.span_label(match_span, format!("value is immutable in match guard"));
578+
err.span_label(match_span, String::from("value is immutable in match guard"));
579579

580580
self.cancel_if_wrong_origin(err, o)
581581
}

src/librustc_resolve/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4948,7 +4948,7 @@ fn show_candidates(err: &mut DiagnosticBuilder,
49484948
err.span_suggestions_with_applicability(
49494949
span,
49504950
&msg,
4951-
path_strings,
4951+
path_strings.into_iter(),
49524952
Applicability::Unspecified,
49534953
);
49544954
} else {

src/librustc_typeck/check/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
132132
if compatible_variants.peek().is_some() {
133133
let expr_text = print::to_string(print::NO_ANN, |s| s.print_expr(expr));
134134
let suggestions = compatible_variants
135-
.map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>();
135+
.map(|v| format!("{}({})", v, expr_text));
136136
err.span_suggestions_with_applicability(
137137
expr.span,
138138
"try using a variant of the expected type",

src/librustc_typeck/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
521521
with_crate_prefix(|| self.tcx.item_path_str(*did)),
522522
additional_newline
523523
)
524-
}).collect();
524+
});
525525

526526
err.span_suggestions_with_applicability(
527527
span,

src/librustc_typeck/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4744,7 +4744,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
47444744
} else if !self.check_for_cast(err, expr, found, expected) {
47454745
let methods = self.get_conversion_methods(expr.span, expected, found);
47464746
if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) {
4747-
let suggestions = iter::repeat(&expr_text).zip(methods.iter())
4747+
let mut suggestions = iter::repeat(&expr_text).zip(methods.iter())
47484748
.filter_map(|(receiver, method)| {
47494749
let method_call = format!(".{}()", method.ident);
47504750
if receiver.ends_with(&method_call) {
@@ -4760,8 +4760,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
47604760
Some(format!("{}{}", receiver, method_call))
47614761
}
47624762
}
4763-
}).collect::<Vec<_>>();
4764-
if !suggestions.is_empty() {
4763+
}).peekable();
4764+
if suggestions.peek().is_some() {
47654765
err.span_suggestions_with_applicability(
47664766
expr.span,
47674767
"try using a conversion method",

src/libsyntax/ext/expand.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
387387
add_derived_markers(&mut self.cx, item.span(), &traits, item.clone());
388388
let derives = derives.entry(invoc.expansion_data.mark).or_default();
389389

390+
derives.reserve(traits.len());
391+
invocations.reserve(traits.len());
390392
for path in &traits {
391393
let mark = Mark::fresh(self.cx.current_expansion.mark);
392394
derives.push(mark);
@@ -687,7 +689,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
687689
"proc_macro_hygiene",
688690
self.span,
689691
GateIssue::Language,
690-
&format!("procedural macros cannot expand to macro definitions"),
692+
"procedural macros cannot expand to macro definitions",
691693
);
692694
}
693695
visit::walk_item(self, i);

src/libsyntax/ext/tt/macro_parser.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ struct MatcherTtFrame<'a> {
143143
idx: usize,
144144
}
145145

146+
type NamedMatchVec = SmallVec<[NamedMatch; 4]>;
147+
146148
/// Represents a single "position" (aka "matcher position", aka "item"), as described in the module
147149
/// documentation.
148150
#[derive(Clone)]
@@ -168,7 +170,7 @@ struct MatcherPos<'a> {
168170
/// all bound matches from the submatcher into the shared top-level `matches` vector. If `sep`
169171
/// and `up` are `Some`, then `matches` is _not_ the shared top-level list. Instead, if one
170172
/// wants the shared `matches`, one should use `up.matches`.
171-
matches: Vec<Rc<Vec<NamedMatch>>>,
173+
matches: Box<[Rc<NamedMatchVec>]>,
172174
/// The position in `matches` corresponding to the first metavar in this matcher's sequence of
173175
/// token trees. In other words, the first metavar in the first token of `top_elts` corresponds
174176
/// to `matches[match_lo]`.
@@ -278,9 +280,14 @@ pub fn count_names(ms: &[TokenTree]) -> usize {
278280
})
279281
}
280282

281-
/// Initialize `len` empty shared `Vec`s to be used to store matches of metavars.
282-
fn create_matches(len: usize) -> Vec<Rc<Vec<NamedMatch>>> {
283-
(0..len).into_iter().map(|_| Rc::new(Vec::new())).collect()
283+
/// `len` `Vec`s (initially shared and empty) that will store matches of metavars.
284+
fn create_matches(len: usize) -> Box<[Rc<NamedMatchVec>]> {
285+
if len == 0 {
286+
vec![]
287+
} else {
288+
let empty_matches = Rc::new(SmallVec::new());
289+
vec![empty_matches.clone(); len]
290+
}.into_boxed_slice()
284291
}
285292

286293
/// Generate the top-level matcher position in which the "dot" is before the first token of the
@@ -332,7 +339,7 @@ fn initial_matcher_pos(ms: &[TokenTree], open: Span) -> MatcherPos {
332339
/// token tree it was derived from.
333340
#[derive(Debug, Clone)]
334341
pub enum NamedMatch {
335-
MatchedSeq(Rc<Vec<NamedMatch>>, DelimSpan),
342+
MatchedSeq(Rc<NamedMatchVec>, DelimSpan),
336343
MatchedNonterminal(Rc<Nonterminal>),
337344
}
338345

@@ -540,7 +547,7 @@ fn inner_parse_loop<'a>(
540547
new_item.match_cur += seq.num_captures;
541548
new_item.idx += 1;
542549
for idx in item.match_cur..item.match_cur + seq.num_captures {
543-
new_item.push_match(idx, MatchedSeq(Rc::new(vec![]), sp));
550+
new_item.push_match(idx, MatchedSeq(Rc::new(smallvec![]), sp));
544551
}
545552
cur_items.push(new_item);
546553
}

src/libsyntax_ext/deriving/generic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ impl<'a> MethodDef<'a> {
13841384
// let __self2_vi = unsafe {
13851385
// std::intrinsics::discriminant_value(&arg2) } as i32;
13861386
// ```
1387-
let mut index_let_stmts: Vec<ast::Stmt> = Vec::new();
1387+
let mut index_let_stmts: Vec<ast::Stmt> = Vec::with_capacity(vi_idents.len() + 1);
13881388

13891389
// We also build an expression which checks whether all discriminants are equal
13901390
// discriminant_test = __self0_vi == __self1_vi && __self0_vi == __self2_vi && ...

src/test/run-pass/invalid_const_promotion.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ fn check_status(status: std::process::ExitStatus)
3939
use std::os::unix::process::ExitStatusExt;
4040

4141
assert!(status.signal() == Some(libc::SIGILL)
42+
|| status.signal() == Some(libc::SIGTRAP)
4243
|| status.signal() == Some(libc::SIGABRT));
4344
}
4445

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// rust-lang/rust#54477: runtime bug in the VecDeque library that was
2+
// exposed by this test case, derived from test suite of crates.io
3+
// `collection` crate.
4+
5+
use std::collections::VecDeque;
6+
7+
fn main() {
8+
let mut vecdeque_13 = VecDeque::from(vec![ ]);
9+
let mut vecdeque_29 = VecDeque::from(vec![ 0 ]);
10+
vecdeque_29.insert(0, 30 );
11+
vecdeque_29.insert(1, 31 );
12+
vecdeque_29.insert(2, 32 );
13+
vecdeque_29.insert(3, 33 );
14+
vecdeque_29.insert(4, 34 );
15+
vecdeque_29.insert(5, 35 );
16+
// println!("vecdeque_13: {:?}", vecdeque_13);
17+
// println!("vecdeque_29: {:?}", vecdeque_29);
18+
19+
// println!("Invoking: `vecdeque_13.append(&mut vecdeque_29)`");
20+
vecdeque_13.append(&mut vecdeque_29);
21+
22+
// println!("vecdeque_13: {:?}", vecdeque_13);
23+
24+
assert_eq!(vecdeque_13, VecDeque::from(vec![30, 31, 32, 33, 34, 35, 0]));
25+
}

src/test/ui/consts/const-eval/double_check.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ enum Bar {
2121
union Union {
2222
foo: &'static Foo,
2323
bar: &'static Bar,
24-
usize: &'static usize,
24+
u8: &'static u8,
2525
}
26-
static BAR: usize = 42;
26+
static BAR: u8 = 42;
2727
static FOO: (&Foo, &Bar) = unsafe {(
28-
Union { usize: &BAR }.foo,
29-
Union { usize: &BAR }.bar,
28+
Union { u8: &BAR }.foo,
29+
Union { u8: &BAR }.bar,
3030
)};
3131

3232
fn main() {}

src/test/ui/consts/const-eval/double_check2.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ enum Bar {
1919
union Union {
2020
foo: &'static Foo,
2121
bar: &'static Bar,
22-
usize: &'static usize,
22+
u8: &'static u8,
2323
}
24-
static BAR: usize = 5;
24+
static BAR: u8 = 5;
2525
static FOO: (&Foo, &Bar) = unsafe {( //~ undefined behavior
26-
Union { usize: &BAR }.foo,
27-
Union { usize: &BAR }.bar,
26+
Union { u8: &BAR }.foo,
27+
Union { u8: &BAR }.bar,
2828
)};
2929

3030
fn main() {}

0 commit comments

Comments
 (0)