Skip to content

Commit 9b701e7

Browse files
committed
Auto merge of rust-lang#95090 - matthiaskrgr:rollup-pho6x6s, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#94115 (Let `try_collect` take advantage of `try_fold` overrides) - rust-lang#94295 (Always evaluate all cfg predicate in all() and any()) - rust-lang#94848 (Compare installed browser-ui-test version to the one used in CI) - rust-lang#94993 (Add test for >65535 hashes in lexing raw string) - rust-lang#95017 (Derive Eq for std::cmp::Ordering, instead of using manual impl.) - rust-lang#95058 (Add use of bool::then in sys/unix/process) - rust-lang#95083 (Document that `Option<extern "abi" fn>` discriminant elision applies for any ABI) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1bfe40d + 9c40db2 commit 9b701e7

File tree

17 files changed

+215
-31
lines changed

17 files changed

+215
-31
lines changed

compiler/rustc_attr/src/builtin.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,18 @@ pub fn eval_condition(
603603
match cfg.name_or_empty() {
604604
sym::any => mis
605605
.iter()
606-
.any(|mi| eval_condition(mi.meta_item().unwrap(), sess, features, eval)),
606+
// We don't use any() here, because we want to evaluate all cfg condition
607+
// as eval_condition can (and does) extra checks
608+
.fold(false, |res, mi| {
609+
res | eval_condition(mi.meta_item().unwrap(), sess, features, eval)
610+
}),
607611
sym::all => mis
608612
.iter()
609-
.all(|mi| eval_condition(mi.meta_item().unwrap(), sess, features, eval)),
613+
// We don't use all() here, because we want to evaluate all cfg condition
614+
// as eval_condition can (and does) extra checks
615+
.fold(true, |res, mi| {
616+
res & eval_condition(mi.meta_item().unwrap(), sess, features, eval)
617+
}),
610618
sym::not => {
611619
if mis.len() != 1 {
612620
struct_span_err!(

compiler/rustc_lexer/src/tests.rs

+17
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ fn test_unterminated_no_pound() {
6666
);
6767
}
6868

69+
#[test]
70+
fn test_too_many_hashes() {
71+
let max_count = u16::MAX;
72+
let mut hashes: String = "#".repeat(max_count.into());
73+
74+
// Valid number of hashes (65535 = 2^16 - 1), but invalid string.
75+
check_raw_str(&hashes, max_count, Some(RawStrError::InvalidStarter { bad_char: '\u{0}' }));
76+
77+
// One more hash sign (65536 = 2^16) becomes too many.
78+
hashes.push('#');
79+
check_raw_str(
80+
&hashes,
81+
0,
82+
Some(RawStrError::TooManyDelimiters { found: usize::from(max_count) + 1 }),
83+
);
84+
}
85+
6986
#[test]
7087
fn test_valid_shebang() {
7188
// https://github.com/rust-lang/rust/issues/70528

library/core/src/cmp.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ pub struct AssertParamIsEq<T: Eq + ?Sized> {
333333
/// let result = 2.cmp(&1);
334334
/// assert_eq!(Ordering::Greater, result);
335335
/// ```
336-
#[derive(Clone, Copy, PartialEq, Debug, Hash)]
336+
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
337337
#[stable(feature = "rust1", since = "1.0.0")]
338338
#[repr(i8)]
339339
pub enum Ordering {
@@ -861,9 +861,6 @@ pub macro Ord($item:item) {
861861
/* compiler built-in */
862862
}
863863

864-
#[stable(feature = "rust1", since = "1.0.0")]
865-
impl Eq for Ordering {}
866-
867864
#[stable(feature = "rust1", since = "1.0.0")]
868865
impl Ord for Ordering {
869866
#[inline]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use crate::ops::Try;
2+
3+
/// Like `Iterator::by_ref`, but requiring `Sized` so it can forward generics.
4+
///
5+
/// Ideally this will no longer be required, eventually, but as can be seen in
6+
/// the benchmarks (as of Feb 2022 at least) `by_ref` can have performance cost.
7+
pub(crate) struct ByRefSized<'a, I>(pub &'a mut I);
8+
9+
impl<I: Iterator> Iterator for ByRefSized<'_, I> {
10+
type Item = I::Item;
11+
12+
fn next(&mut self) -> Option<Self::Item> {
13+
self.0.next()
14+
}
15+
16+
fn size_hint(&self) -> (usize, Option<usize>) {
17+
self.0.size_hint()
18+
}
19+
20+
fn advance_by(&mut self, n: usize) -> Result<(), usize> {
21+
self.0.advance_by(n)
22+
}
23+
24+
fn nth(&mut self, n: usize) -> Option<Self::Item> {
25+
self.0.nth(n)
26+
}
27+
28+
fn fold<B, F>(self, init: B, f: F) -> B
29+
where
30+
F: FnMut(B, Self::Item) -> B,
31+
{
32+
self.0.fold(init, f)
33+
}
34+
35+
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
36+
where
37+
F: FnMut(B, Self::Item) -> R,
38+
R: Try<Output = B>,
39+
{
40+
self.0.try_fold(init, f)
41+
}
42+
}

library/core/src/iter/adapters/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::iter::{InPlaceIterable, Iterator};
22
use crate::ops::{ChangeOutputType, ControlFlow, FromResidual, NeverShortCircuit, Residual, Try};
33

4+
mod by_ref_sized;
45
mod chain;
56
mod cloned;
67
mod copied;
@@ -31,6 +32,8 @@ pub use self::{
3132
scan::Scan, skip::Skip, skip_while::SkipWhile, take::Take, take_while::TakeWhile, zip::Zip,
3233
};
3334

35+
pub(crate) use self::by_ref_sized::ByRefSized;
36+
3437
#[stable(feature = "iter_cloned", since = "1.1.0")]
3538
pub use self::cloned::Cloned;
3639

library/core/src/iter/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ pub use self::adapters::{
417417
#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
418418
pub use self::adapters::{Intersperse, IntersperseWith};
419419

420-
pub(crate) use self::adapters::try_process;
420+
pub(crate) use self::adapters::{try_process, ByRefSized};
421421

422422
mod adapters;
423423
mod range;

library/core/src/iter/traits/iterator.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::cmp::{self, Ordering};
22
use crate::ops::{ChangeOutputType, ControlFlow, FromResidual, Residual, Try};
33

44
use super::super::try_process;
5+
use super::super::ByRefSized;
56
use super::super::TrustedRandomAccessNoCoerce;
67
use super::super::{Chain, Cloned, Copied, Cycle, Enumerate, Filter, FilterMap, Fuse};
78
use super::super::{FlatMap, Flatten};
@@ -1861,7 +1862,7 @@ pub trait Iterator {
18611862
<<Self as Iterator>::Item as Try>::Residual: Residual<B>,
18621863
B: FromIterator<<Self::Item as Try>::Output>,
18631864
{
1864-
try_process(self, |i| i.collect())
1865+
try_process(ByRefSized(self), |i| i.collect())
18651866
}
18661867

18671868
/// Collects all the items from an iterator into a collection.

library/core/src/option.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@
8080
//! * [`Box<U>`]
8181
//! * `&U`
8282
//! * `&mut U`
83-
//! * `fn`, `extern "C" fn`
83+
//! * `fn`, `extern "C" fn`[^extern_fn]
8484
//! * [`num::NonZero*`]
8585
//! * [`ptr::NonNull<U>`]
8686
//! * `#[repr(transparent)]` struct around one of the types in this list.
8787
//!
88+
//! [^extern_fn]: this remains true for any other ABI: `extern "abi" fn` (_e.g._, `extern "system" fn`)
89+
//!
8890
//! [`Box<U>`]: ../../std/boxed/struct.Box.html
8991
//! [`num::NonZero*`]: crate::num
9092
//! [`ptr::NonNull<U>`]: crate::ptr::NonNull

library/core/tests/cmp.rs

+13
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ fn ordering_const() {
133133
assert_eq!(THEN, Greater);
134134
}
135135

136+
#[test]
137+
fn ordering_structural_eq() {
138+
// test that consts of type `Ordering` are usable in patterns
139+
140+
const ORDERING: Ordering = Greater;
141+
142+
const REVERSE: Ordering = ORDERING.reverse();
143+
match Ordering::Less {
144+
REVERSE => {}
145+
_ => unreachable!(),
146+
};
147+
}
148+
136149
#[test]
137150
fn cmp_default() {
138151
// Test default methods in PartialOrd and PartialEq

library/core/tests/iter/traits/iterator.rs

+24
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,30 @@ fn test_collect_into() {
551551
assert!(a == b);
552552
}
553553

554+
#[test]
555+
fn iter_try_collect_uses_try_fold_not_next() {
556+
// This makes sure it picks up optimizations, and doesn't use the `&mut I` impl.
557+
struct PanicOnNext<I>(I);
558+
impl<I: Iterator> Iterator for PanicOnNext<I> {
559+
type Item = I::Item;
560+
fn next(&mut self) -> Option<Self::Item> {
561+
panic!("Iterator::next should not be called!")
562+
}
563+
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
564+
where
565+
Self: Sized,
566+
F: FnMut(B, Self::Item) -> R,
567+
R: std::ops::Try<Output = B>,
568+
{
569+
self.0.try_fold(init, f)
570+
}
571+
}
572+
573+
let it = (0..10).map(Some);
574+
let _ = PanicOnNext(it).try_collect::<Vec<_>>();
575+
// validation is just that it didn't panic.
576+
}
577+
554578
// just tests by whether or not this compiles
555579
fn _empty_impl_all_auto_traits<T>() {
556580
use std::panic::{RefUnwindSafe, UnwindSafe};

library/std/src/sys/unix/process/process_unix.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -648,19 +648,19 @@ impl ExitStatus {
648648
}
649649

650650
pub fn code(&self) -> Option<i32> {
651-
if self.exited() { Some(libc::WEXITSTATUS(self.0)) } else { None }
651+
self.exited().then(|| libc::WEXITSTATUS(self.0))
652652
}
653653

654654
pub fn signal(&self) -> Option<i32> {
655-
if libc::WIFSIGNALED(self.0) { Some(libc::WTERMSIG(self.0)) } else { None }
655+
libc::WIFSIGNALED(self.0).then(|| libc::WTERMSIG(self.0))
656656
}
657657

658658
pub fn core_dumped(&self) -> bool {
659659
libc::WIFSIGNALED(self.0) && libc::WCOREDUMP(self.0)
660660
}
661661

662662
pub fn stopped_signal(&self) -> Option<i32> {
663-
if libc::WIFSTOPPED(self.0) { Some(libc::WSTOPSIG(self.0)) } else { None }
663+
libc::WIFSTOPPED(self.0).then(|| libc::WSTOPSIG(self.0))
664664
}
665665

666666
pub fn continued(&self) -> bool {

src/bootstrap/test.rs

+41-17
Original file line numberDiff line numberDiff line change
@@ -836,22 +836,39 @@ impl Step for RustdocJSNotStd {
836836
}
837837
}
838838

839-
fn check_if_browser_ui_test_is_installed_global(npm: &Path, global: bool) -> bool {
839+
fn get_browser_ui_test_version_inner(npm: &Path, global: bool) -> Option<String> {
840840
let mut command = Command::new(&npm);
841-
command.arg("list").arg("--depth=0");
841+
command.arg("list").arg("--parseable").arg("--long").arg("--depth=0");
842842
if global {
843843
command.arg("--global");
844844
}
845845
let lines = command
846846
.output()
847847
.map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
848848
.unwrap_or(String::new());
849-
lines.contains(&" browser-ui-test@")
849+
lines.lines().find_map(|l| l.split(":browser-ui-test@").skip(1).next()).map(|v| v.to_owned())
850850
}
851851

852-
fn check_if_browser_ui_test_is_installed(npm: &Path) -> bool {
853-
check_if_browser_ui_test_is_installed_global(npm, false)
854-
|| check_if_browser_ui_test_is_installed_global(npm, true)
852+
fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
853+
get_browser_ui_test_version_inner(npm, false)
854+
.or_else(|| get_browser_ui_test_version_inner(npm, true))
855+
}
856+
857+
fn compare_browser_ui_test_version(installed_version: &str, src: &Path) {
858+
match fs::read_to_string(
859+
src.join("src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version"),
860+
) {
861+
Ok(v) => {
862+
if v.trim() != installed_version {
863+
eprintln!(
864+
"⚠️ Installed version of browser-ui-test (`{}`) is different than the \
865+
one used in the CI (`{}`)",
866+
installed_version, v
867+
);
868+
}
869+
}
870+
Err(e) => eprintln!("Couldn't find the CI browser-ui-test version: {:?}", e),
871+
}
855872
}
856873

857874
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
@@ -874,7 +891,7 @@ impl Step for RustdocGUI {
874891
.config
875892
.npm
876893
.as_ref()
877-
.map(|p| check_if_browser_ui_test_is_installed(p))
894+
.map(|p| get_browser_ui_test_version(p).is_some())
878895
.unwrap_or(false)
879896
}))
880897
}
@@ -892,16 +909,23 @@ impl Step for RustdocGUI {
892909

893910
// The goal here is to check if the necessary packages are installed, and if not, we
894911
// panic.
895-
if !check_if_browser_ui_test_is_installed(&npm) {
896-
eprintln!(
897-
"error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
898-
dependency is missing",
899-
);
900-
eprintln!(
901-
"If you want to install the `{0}` dependency, run `npm install {0}`",
902-
"browser-ui-test",
903-
);
904-
panic!("Cannot run rustdoc-gui tests");
912+
match get_browser_ui_test_version(&npm) {
913+
Some(version) => {
914+
// We also check the version currently used in CI and emit a warning if it's not the
915+
// same one.
916+
compare_browser_ui_test_version(&version, &builder.build.src);
917+
}
918+
None => {
919+
eprintln!(
920+
"error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
921+
dependency is missing",
922+
);
923+
eprintln!(
924+
"If you want to install the `{0}` dependency, run `npm install {0}`",
925+
"browser-ui-test",
926+
);
927+
panic!("Cannot run rustdoc-gui tests");
928+
}
905929
}
906930

907931
let out_dir = builder.test_out(self.target).join("rustdoc-gui");

src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile

+8-2
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,20 @@ RUN /scripts/cmake.sh
6565
COPY host-x86_64/x86_64-gnu-tools/checktools.sh /tmp/
6666

6767
RUN curl -sL https://nodejs.org/dist/v14.4.0/node-v14.4.0-linux-x64.tar.xz | tar -xJ
68-
ENV PATH="/node-v14.4.0-linux-x64/bin:${PATH}"
68+
ENV NODE_FOLDER=/node-v14.4.0-linux-x64/bin
69+
ENV PATH="$NODE_FOLDER:${PATH}"
70+
71+
COPY host-x86_64/x86_64-gnu-tools/browser-ui-test.version /tmp/
6972

7073
# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
7174
# to create a new folder. For reference:
7275
# https://github.com/puppeteer/puppeteer/issues/375
7376
#
7477
# We also specify the version in case we need to update it to go around cache limitations.
75-
RUN npm install -g browser-ui-test@0.8.3 --unsafe-perm=true
78+
#
79+
# The `browser-ui-test.version` file is also used by bootstrap to emit warnings in case
80+
# the local version of the package is different than the one used by the CI.
81+
RUN npm install -g browser-ui-test@$(head -n 1 /tmp/browser-ui-test.version) --unsafe-perm=true
7682

7783
ENV RUST_CONFIGURE_ARGS \
7884
--build=x86_64-unknown-linux-gnu \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.8.3

src/ci/scripts/should-skip-this.sh

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ if [[ -n "${CI_ONLY_WHEN_SUBMODULES_CHANGED-}" ]]; then
2626
src/test/rustdoc-gui \
2727
src/librustdoc \
2828
src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile \
29+
src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version \
2930
src/tools/rustdoc-gui); then
3031
# There was a change in either rustdoc or in its GUI tests.
3132
echo "Rustdoc was updated"

src/test/ui/cfg/cfg-path-error.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// check-fail
2+
3+
#[cfg(any(foo, foo::bar))]
4+
//~^ERROR `cfg` predicate key must be an identifier
5+
fn foo1() {}
6+
7+
#[cfg(any(foo::bar, foo))]
8+
//~^ERROR `cfg` predicate key must be an identifier
9+
fn foo2() {}
10+
11+
#[cfg(all(foo, foo::bar))]
12+
//~^ERROR `cfg` predicate key must be an identifier
13+
fn foo3() {}
14+
15+
#[cfg(all(foo::bar, foo))]
16+
//~^ERROR `cfg` predicate key must be an identifier
17+
fn foo4() {}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)