Skip to content

Commit f565cdd

Browse files
committed
Auto merge of #58866 - kennytm:rollup, r=kennytm
Rollup of 14 pull requests Successful merges: - #58730 (Have all methods of Filter and FilterMap use internal iteration) - #58780 (ManuallyDrop != MaybeUninit) - #58782 (Replace `s` with `self` in docs for str methods taking self.) - #58785 (allow specifying attributes for tool lints) - #58802 (Ensure `record_layout_for_printing()` is inlined.) - #58821 (Fixed a syntax error in the pin docs) - #58830 (tidy: deny(rust_2018_idioms)) - #58832 (Revert switching to GCP on AppVeyor) - #58833 (tools/rustbook: deny(rust_2018_idioms)) - #58835 (tools/remote-test-{client,server}: deny(rust_2018_idioms)) - #58838 (Fix typo in Vec#resize_with documentation) - #58842 (Forbid duplicating Cargo as a dependency) - #58852 (Update toolchain to build NetBSD release) - #58865 (Fix C-variadic function printing)
2 parents ba43811 + 946e670 commit f565cdd

File tree

20 files changed

+125
-101
lines changed

20 files changed

+125
-101
lines changed

appveyor.yml

-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ environment:
55
# server goes down presumably. See #43333 for more info
66
CARGO_HTTP_CHECK_REVOKE: false
77

8-
# Execute the builds on GCE instead of Hyper-V. Those builders have a 3-4
9-
# minute startup overhead, but AppVeyor support recommended this as a
10-
# possible solution for #58160 (spurious 259 exit codes)
11-
appveyor_build_worker_cloud: gce
12-
138
matrix:
149
# 32/64 bit MSVC tests
1510
- MSYS_BITS: 64

src/ci/docker/dist-x86_64-netbsd/Dockerfile

+2-18
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,8 @@ FROM ubuntu:16.04
33
COPY scripts/cross-apt-packages.sh /scripts/
44
RUN sh /scripts/cross-apt-packages.sh
55

6-
# Ubuntu 16.04 (this container) ships with make 4, but something in the
7-
# toolchains we build below chokes on that, so go back to make 3
8-
COPY scripts/make3.sh /scripts/
9-
RUN sh /scripts/make3.sh
10-
11-
COPY scripts/crosstool-ng.sh /scripts/
12-
RUN sh /scripts/crosstool-ng.sh
13-
14-
COPY scripts/rustbuild-setup.sh /scripts/
15-
RUN sh /scripts/rustbuild-setup.sh
16-
USER rustbuild
17-
WORKDIR /tmp
18-
196
COPY dist-x86_64-netbsd/build-netbsd-toolchain.sh /tmp/
20-
RUN ./build-netbsd-toolchain.sh
21-
22-
USER root
7+
RUN /tmp/build-netbsd-toolchain.sh
238

249
COPY scripts/sccache.sh /scripts/
2510
RUN sh /scripts/sccache.sh
@@ -33,6 +18,5 @@ ENV \
3318

3419
ENV HOSTS=x86_64-unknown-netbsd
3520

36-
ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs \
37-
--set llvm.allow-old-toolchain
21+
ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs
3822
ENV SCRIPT python2.7 ../x.py dist --host $HOSTS --target $HOSTS

src/ci/docker/dist-x86_64-netbsd/build-netbsd-toolchain.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ mkdir -p /x-tools/x86_64-unknown-netbsd/sysroot
2828
URL=https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror
2929

3030
# Originally from ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-$BSD/source/sets/*.tgz
31-
curl $URL/2017-03-17-netbsd-src.tgz | tar xzf -
32-
curl $URL/2017-03-17-netbsd-gnusrc.tgz | tar xzf -
33-
curl $URL/2017-03-17-netbsd-sharesrc.tgz | tar xzf -
34-
curl $URL/2017-03-17-netbsd-syssrc.tgz | tar xzf -
31+
curl $URL/2018-03-01-netbsd-src.tgz | tar xzf -
32+
curl $URL/2018-03-01-netbsd-gnusrc.tgz | tar xzf -
33+
curl $URL/2018-03-01-netbsd-sharesrc.tgz | tar xzf -
34+
curl $URL/2018-03-01-netbsd-syssrc.tgz | tar xzf -
3535

3636
# Originally from ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-$BSD/amd64/binary/sets/*.tgz
37-
curl $URL/2017-03-17-netbsd-base.tgz | \
37+
curl $URL/2018-03-01-netbsd-base.tgz | \
3838
tar xzf - -C /x-tools/x86_64-unknown-netbsd/sysroot ./usr/include ./usr/lib ./lib
39-
curl $URL/2017-03-17-netbsd-comp.tgz | \
39+
curl $URL/2018-03-01-netbsd-comp.tgz | \
4040
tar xzf - -C /x-tools/x86_64-unknown-netbsd/sysroot ./usr/include ./usr/lib
4141

4242
cd usr/src

src/liballoc/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ impl<T> Vec<T> {
12601260
/// This method uses a closure to create new values on every push. If
12611261
/// you'd rather [`Clone`] a given value, use [`resize`]. If you want
12621262
/// to use the [`Default`] trait to generate values, you can pass
1263-
/// [`Default::default()`] as the second argument..
1263+
/// [`Default::default()`] as the second argument.
12641264
///
12651265
/// # Examples
12661266
///

src/libcore/benches/iter.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ bench_sums! {
185185
bench_sums! {
186186
bench_filter_sum,
187187
bench_filter_ref_sum,
188-
(0i64..1000000).filter(|x| x % 2 == 0)
188+
(0i64..1000000).filter(|x| x % 3 == 0)
189189
}
190190

191191
bench_sums! {
192192
bench_filter_chain_sum,
193193
bench_filter_chain_ref_sum,
194-
(0i64..1000000).chain(0..1000000).filter(|x| x % 2 == 0)
194+
(0i64..1000000).chain(0..1000000).filter(|x| x % 3 == 0)
195195
}
196196

197197
bench_sums! {
@@ -306,3 +306,31 @@ fn bench_skip_then_zip(b: &mut Bencher) {
306306
assert_eq!(s, 2009900);
307307
});
308308
}
309+
310+
#[bench]
311+
fn bench_filter_count(b: &mut Bencher) {
312+
b.iter(|| {
313+
(0i64..1000000).map(black_box).filter(|x| x % 3 == 0).count()
314+
})
315+
}
316+
317+
#[bench]
318+
fn bench_filter_ref_count(b: &mut Bencher) {
319+
b.iter(|| {
320+
(0i64..1000000).map(black_box).by_ref().filter(|x| x % 3 == 0).count()
321+
})
322+
}
323+
324+
#[bench]
325+
fn bench_filter_chain_count(b: &mut Bencher) {
326+
b.iter(|| {
327+
(0i64..1000000).chain(0..1000000).map(black_box).filter(|x| x % 3 == 0).count()
328+
})
329+
}
330+
331+
#[bench]
332+
fn bench_filter_chain_ref_count(b: &mut Bencher) {
333+
b.iter(|| {
334+
(0i64..1000000).chain(0..1000000).map(black_box).by_ref().filter(|x| x % 3 == 0).count()
335+
})
336+
}

src/libcore/iter/adapters/mod.rs

+7-30
Original file line numberDiff line numberDiff line change
@@ -681,12 +681,7 @@ impl<I: Iterator, P> Iterator for Filter<I, P> where P: FnMut(&I::Item) -> bool
681681

682682
#[inline]
683683
fn next(&mut self) -> Option<I::Item> {
684-
for x in &mut self.iter {
685-
if (self.predicate)(&x) {
686-
return Some(x);
687-
}
688-
}
689-
None
684+
self.try_for_each(Err).err()
690685
}
691686

692687
#[inline]
@@ -707,12 +702,9 @@ impl<I: Iterator, P> Iterator for Filter<I, P> where P: FnMut(&I::Item) -> bool
707702
// Using the branchless version will also simplify the LLVM byte code, thus
708703
// leaving more budget for LLVM optimizations.
709704
#[inline]
710-
fn count(mut self) -> usize {
711-
let mut count = 0;
712-
for x in &mut self.iter {
713-
count += (self.predicate)(&x) as usize;
714-
}
715-
count
705+
fn count(self) -> usize {
706+
let mut predicate = self.predicate;
707+
self.iter.map(|x| predicate(&x) as usize).sum()
716708
}
717709

718710
#[inline]
@@ -746,12 +738,7 @@ impl<I: DoubleEndedIterator, P> DoubleEndedIterator for Filter<I, P>
746738
{
747739
#[inline]
748740
fn next_back(&mut self) -> Option<I::Item> {
749-
for x in self.iter.by_ref().rev() {
750-
if (self.predicate)(&x) {
751-
return Some(x);
752-
}
753-
}
754-
None
741+
self.try_rfold((), |_, x| Err(x)).err()
755742
}
756743

757744
#[inline]
@@ -820,12 +807,7 @@ impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
820807

821808
#[inline]
822809
fn next(&mut self) -> Option<B> {
823-
for x in self.iter.by_ref() {
824-
if let Some(y) = (self.f)(x) {
825-
return Some(y);
826-
}
827-
}
828-
None
810+
self.try_for_each(Err).err()
829811
}
830812

831813
#[inline]
@@ -863,12 +845,7 @@ impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for FilterMap<I, F>
863845
{
864846
#[inline]
865847
fn next_back(&mut self) -> Option<B> {
866-
for x in self.iter.by_ref().rev() {
867-
if let Some(y) = (self.f)(x) {
868-
return Some(y);
869-
}
870-
}
871-
None
848+
self.try_rfold((), |_, x| Err(x)).err()
872849
}
873850

874851
#[inline]

src/libcore/mem.rs

+8
Original file line numberDiff line numberDiff line change
@@ -900,10 +900,16 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> {
900900
}
901901
}
902902

903+
// FIXME: Reference `MaybeUninit` from these docs, once that is stable.
903904
/// A wrapper to inhibit compiler from automatically calling `T`’s destructor.
904905
///
905906
/// This wrapper is 0-cost.
906907
///
908+
/// `ManuallyDrop<T>` is subject to the same layout optimizations as `T`.
909+
/// As a consequence, it has *no effect* on the assumptions that the compiler makes
910+
/// about all values being initialized at their type. In particular, initializing
911+
/// a `ManuallyDrop<&mut T>` with [`mem::zeroed`] is undefined behavior.
912+
///
907913
/// # Examples
908914
///
909915
/// This wrapper helps with explicitly documenting the drop order dependencies between fields of
@@ -935,6 +941,8 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> {
935941
/// }
936942
/// }
937943
/// ```
944+
///
945+
/// [`mem::zeroed`]: fn.zeroed.html
938946
#[stable(feature = "manually_drop", since = "1.20.0")]
939947
#[lang = "manually_drop"]
940948
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]

src/libcore/pin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
//! had a method `fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut T>`.
216216
//! Then we could do the following:
217217
//! ```compile_fail
218-
//! fn exploit_ref_cell<T>(rc: Pin<&mut RefCell<T>) {
218+
//! fn exploit_ref_cell<T>(rc: Pin<&mut RefCell<T>>) {
219219
//! { let p = rc.as_mut().get_pin_mut(); } // Here we get pinned access to the `T`.
220220
//! let rc_shr: &RefCell<T> = rc.into_ref().get_ref();
221221
//! let b = rc_shr.borrow_mut();

src/libcore/str/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3965,7 +3965,7 @@ impl str {
39653965
me.make_ascii_lowercase()
39663966
}
39673967

3968-
/// Return an iterator that escapes each char in `s` with [`char::escape_debug`].
3968+
/// Return an iterator that escapes each char in `self` with [`char::escape_debug`].
39693969
///
39703970
/// Note: only extended grapheme codepoints that begin the string will be
39713971
/// escaped.
@@ -4013,7 +4013,7 @@ impl str {
40134013
}
40144014
}
40154015

4016-
/// Return an iterator that escapes each char in `s` with [`char::escape_default`].
4016+
/// Return an iterator that escapes each char in `self` with [`char::escape_default`].
40174017
///
40184018
/// [`char::escape_default`]: ../std/primitive.char.html#method.escape_default
40194019
///
@@ -4051,7 +4051,7 @@ impl str {
40514051
EscapeDefault { inner: self.chars().flat_map(CharEscapeDefault) }
40524052
}
40534053

4054-
/// Return an iterator that escapes each char in `s` with [`char::escape_unicode`].
4054+
/// Return an iterator that escapes each char in `self` with [`char::escape_unicode`].
40554055
///
40564056
/// [`char::escape_unicode`]: ../std/primitive.char.html#method.escape_unicode
40574057
///

src/librustc/lint/mod.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,22 @@ macro_rules! declare_lint {
132132

133133
#[macro_export]
134134
macro_rules! declare_tool_lint {
135-
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr) => (
136-
declare_tool_lint!{$vis $tool::$NAME, $Level, $desc, false}
135+
(
136+
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr
137+
) => (
138+
declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false}
137139
);
138-
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr,
139-
report_in_external_macro: $rep: expr) => (
140-
declare_tool_lint!{$vis $tool::$NAME, $Level, $desc, $rep}
140+
(
141+
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
142+
report_in_external_macro: $rep:expr
143+
) => (
144+
declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep}
141145
);
142-
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr, $external: expr) => (
146+
(
147+
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
148+
$external:expr
149+
) => (
150+
$(#[$attr])*
143151
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
144152
name: &concat!(stringify!($tool), "::", stringify!($NAME)),
145153
default_level: $crate::lint::$Level,

src/librustc/ty/layout.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1176,25 +1176,27 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
11761176

11771177
/// This is invoked by the `layout_raw` query to record the final
11781178
/// layout of each type.
1179-
#[inline]
1179+
#[inline(always)]
11801180
fn record_layout_for_printing(&self, layout: TyLayout<'tcx>) {
1181-
// If we are running with `-Zprint-type-sizes`, record layouts for
1182-
// dumping later. Ignore layouts that are done with non-empty
1183-
// environments or non-monomorphic layouts, as the user only wants
1184-
// to see the stuff resulting from the final codegen session.
1181+
// If we are running with `-Zprint-type-sizes`, maybe record layouts
1182+
// for dumping later.
1183+
if self.tcx.sess.opts.debugging_opts.print_type_sizes {
1184+
self.record_layout_for_printing_outlined(layout)
1185+
}
1186+
}
1187+
1188+
fn record_layout_for_printing_outlined(&self, layout: TyLayout<'tcx>) {
1189+
// Ignore layouts that are done with non-empty environments or
1190+
// non-monomorphic layouts, as the user only wants to see the stuff
1191+
// resulting from the final codegen session.
11851192
if
1186-
!self.tcx.sess.opts.debugging_opts.print_type_sizes ||
11871193
layout.ty.has_param_types() ||
11881194
layout.ty.has_self_ty() ||
11891195
!self.param_env.caller_bounds.is_empty()
11901196
{
11911197
return;
11921198
}
11931199

1194-
self.record_layout_for_printing_outlined(layout)
1195-
}
1196-
1197-
fn record_layout_for_printing_outlined(&self, layout: TyLayout<'tcx>) {
11981200
// (delay format until we actually need it)
11991201
let record = |kind, packed, opt_discr_size, variants| {
12001202
let type_desc = format!("{:?}", layout.ty);

src/libsyntax/print/pprust.rs

-3
Original file line numberDiff line numberDiff line change
@@ -2814,9 +2814,6 @@ impl<'a> State<'a> {
28142814
-> io::Result<()> {
28152815
self.popen()?;
28162816
self.commasep(Inconsistent, &decl.inputs, |s, arg| s.print_arg(arg, false))?;
2817-
if decl.c_variadic {
2818-
self.s.word(", ...")?;
2819-
}
28202817
self.pclose()?;
28212818

28222819
self.print_fn_output(decl)

src/test/pretty/fn-variadic.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Check that `fn foo(x: i32, ...)` does not print as `fn foo(x: i32, ..., ...)`.
2+
// See issue #58853.
3+
4+
// pp-exact
5+
#![feature(c_variadic)]
6+
7+
extern "C" {
8+
pub fn foo(x: i32, ...);
9+
}
10+
11+
pub unsafe extern "C" fn bar(_: i32, mut ap: ...) -> usize {
12+
ap.arg::<usize>()
13+
}
14+
15+
fn main() { }

src/test/ui-fulldeps/auxiliary/lint_tool_test.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ use rustc::lint::{EarlyContext, LintContext, LintPass, EarlyLintPass,
1313
use rustc_plugin::Registry;
1414
use syntax::ast;
1515
declare_tool_lint!(pub clippy::TEST_LINT, Warn, "Warn about stuff");
16-
declare_tool_lint!(pub clippy::TEST_GROUP, Warn, "Warn about other stuff");
16+
declare_tool_lint!(
17+
/// Some docs
18+
pub clippy::TEST_GROUP,
19+
Warn, "Warn about other stuff"
20+
);
1721

1822
struct Pass;
1923

src/tools/remote-test-client/src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rust_2018_idioms)]
2+
13
/// This is a small client program intended to pair with `remote-test-server` in
24
/// this repository. This client connects to the server over TCP and is used to
35
/// push artifacts and run tests on the server instead of locally.
@@ -15,7 +17,7 @@ use std::process::{Command, Stdio};
1517
use std::thread;
1618
use std::time::Duration;
1719

18-
const REMOTE_ADDR_ENV: &'static str = "TEST_DEVICE_ADDR";
20+
const REMOTE_ADDR_ENV: &str = "TEST_DEVICE_ADDR";
1921

2022
macro_rules! t {
2123
($e:expr) => (match $e {

src/tools/remote-test-server/src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rust_2018_idioms)]
2+
13
/// This is a small server which is intended to run inside of an emulator or
24
/// on a remote test device. This server pairs with the `remote-test-client`
35
/// program in this repository. The `remote-test-client` connects to this
@@ -120,7 +122,7 @@ struct RemoveOnDrop<'a> {
120122
inner: &'a Path,
121123
}
122124

123-
impl<'a> Drop for RemoveOnDrop<'a> {
125+
impl Drop for RemoveOnDrop<'_> {
124126
fn drop(&mut self) {
125127
t!(fs::remove_dir_all(self.inner));
126128
}

0 commit comments

Comments
 (0)