From e2ec11502d077c33650a288d255c3c056bb7232f Mon Sep 17 00:00:00 2001 From: Slanterns Date: Wed, 14 Aug 2024 18:28:40 +0800 Subject: [PATCH 1/8] stabilize `is_none_or` --- compiler/rustc_const_eval/src/lib.rs | 1 - compiler/rustc_hir_typeck/src/lib.rs | 1 - library/core/src/option.rs | 4 +--- src/tools/miri/src/lib.rs | 1 - 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index 780404212c341..d825a47bfdf5d 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -6,7 +6,6 @@ #![feature(box_patterns)] #![feature(decl_macro)] #![feature(if_let_guard)] -#![feature(is_none_or)] #![feature(let_chains)] #![feature(never_type)] #![feature(rustdoc_internals)] diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 758a1cefe6341..9ec101196a43f 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -5,7 +5,6 @@ #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(if_let_guard)] -#![feature(is_none_or)] #![feature(let_chains)] #![feature(never_type)] #![feature(try_blocks)] diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 6c89c81018038..9c6819bc58f32 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -656,8 +656,6 @@ impl Option { /// # Examples /// /// ``` - /// #![feature(is_none_or)] - /// /// let x: Option = Some(2); /// assert_eq!(x.is_none_or(|x| x > 1), true); /// @@ -669,7 +667,7 @@ impl Option { /// ``` #[must_use] #[inline] - #[unstable(feature = "is_none_or", issue = "126383")] + #[stable(feature = "is_none_or", since = "CURRENT_RUSTC_VERSION")] pub fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool { match self { None => true, diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs index 966d38508f612..7a11e353f9d98 100644 --- a/src/tools/miri/src/lib.rs +++ b/src/tools/miri/src/lib.rs @@ -12,7 +12,6 @@ #![feature(let_chains)] #![feature(trait_upcasting)] #![feature(strict_overflow_ops)] -#![feature(is_none_or)] // Configure clippy and other lints #![allow( clippy::collapsible_else_if, From 14ac0a38db036fbe3620534ee1c142f7092364e5 Mon Sep 17 00:00:00 2001 From: Slanterns Date: Thu, 15 Aug 2024 01:22:42 +0800 Subject: [PATCH 2/8] fix r-a --- src/tools/rust-analyzer/crates/hir-ty/src/display.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs index a433ecfd778b9..f6f90faa4ef73 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs @@ -1462,7 +1462,7 @@ fn generic_args_sans_defaults<'ga>( // otherwise, if the arg is equal to the param default, hide it (unless the // default is an error which can happen for the trait Self type) #[allow(unstable_name_collisions)] - default_parameters.get(i).is_none_or(|default_parameter| { + IsNoneOr::is_none_or(default_parameters.get(i), |default_parameter| { // !is_err(default_parameter.skip_binders()) // && arg != &default_parameter.clone().substitute(Interner, ¶meters) From cd2b0309cc948a54a7bdbc3050b0d7d6b0826f93 Mon Sep 17 00:00:00 2001 From: Jaic1 <506933131@qq.com> Date: Tue, 13 Aug 2024 16:21:58 +0800 Subject: [PATCH 3/8] Special-case alias ty in `try_from_lit` --- compiler/rustc_middle/src/ty/consts.rs | 4 ++++ .../{crashes => ui/const-generics/adt_const_params}/116308.rs | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) rename tests/{crashes => ui/const-generics/adt_const_params}/116308.rs (81%) diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index c380019e63f47..e373292741b90 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -305,6 +305,10 @@ impl<'tcx> Const<'tcx> { // mir. match tcx.at(expr.span).lit_to_const(lit_input) { Ok(c) => return Some(c), + Err(_) if lit_input.ty.has_aliases() => { + // allow the `ty` to be an alias type, though we cannot handle it here + return None; + } Err(e) => { tcx.dcx().span_delayed_bug( expr.span, diff --git a/tests/crashes/116308.rs b/tests/ui/const-generics/adt_const_params/116308.rs similarity index 81% rename from tests/crashes/116308.rs rename to tests/ui/const-generics/adt_const_params/116308.rs index cb96c80d79bdc..9ea7022e29c8a 100644 --- a/tests/crashes/116308.rs +++ b/tests/ui/const-generics/adt_const_params/116308.rs @@ -1,6 +1,8 @@ -//@ known-bug: #116308 +//@ check-pass #![feature(adt_const_params)] +// Regression test for #116308 + pub trait Identity { type Identity; } From e03cc14b7a781f9b921da50928b0a480b4aaca16 Mon Sep 17 00:00:00 2001 From: Wafarm Date: Fri, 16 Aug 2024 20:58:13 +0800 Subject: [PATCH 4/8] Fix wrong source location for some incorrect macro definitions --- compiler/rustc_expand/src/mbe/quoted.rs | 19 +++++++++++++------ .../ui/macros/macro-match-nonterminal.stderr | 12 ++++++------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index e5a1c6c789928..b2f7c8f5183a2 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -54,18 +54,24 @@ pub(super) fn parse( // For each token tree in `input`, parse the token into a `self::TokenTree`, consuming // additional trees if need be. - let mut trees = input.trees(); + let mut trees = input.trees().peekable(); while let Some(tree) = trees.next() { // Given the parsed tree, if there is a metavar and we are expecting matchers, actually // parse out the matcher (i.e., in `$id:ident` this would parse the `:` and `ident`). let tree = parse_tree(tree, &mut trees, parsing_patterns, sess, node_id, features, edition); match tree { TokenTree::MetaVar(start_sp, ident) if parsing_patterns => { - let span = match trees.next() { + // Not consuming the next token immediately, as it may not be a colon + let span = match trees.peek() { Some(&tokenstream::TokenTree::Token( Token { kind: token::Colon, span: colon_span }, _, )) => { + // Consume the colon first + trees.next(); + + // It's ok to consume the next tree no matter how, + // since if it's not a token then it will be an invalid declaration. match trees.next() { Some(tokenstream::TokenTree::Token(token, _)) => match token.ident() { Some((fragment, _)) => { @@ -125,12 +131,13 @@ pub(super) fn parse( } _ => token.span, }, - Some(tree) => tree.span(), - None => colon_span, + // Invalid, return a nice source location + _ => colon_span.with_lo(start_sp.lo()), } } - Some(tree) => tree.span(), - None => start_sp, + // Whether it's none or some other tree, it doesn't belong to + // the current meta variable, returning the original span. + _ => start_sp, }; result.push(TokenTree::MetaVarDecl(span, ident, None)); diff --git a/tests/ui/macros/macro-match-nonterminal.stderr b/tests/ui/macros/macro-match-nonterminal.stderr index 831579c4fefd5..f221f92c3cda6 100644 --- a/tests/ui/macros/macro-match-nonterminal.stderr +++ b/tests/ui/macros/macro-match-nonterminal.stderr @@ -1,14 +1,14 @@ error: missing fragment specifier - --> $DIR/macro-match-nonterminal.rs:2:8 + --> $DIR/macro-match-nonterminal.rs:2:6 | LL | ($a, $b) => { - | ^ + | ^^ error: missing fragment specifier - --> $DIR/macro-match-nonterminal.rs:2:8 + --> $DIR/macro-match-nonterminal.rs:2:6 | LL | ($a, $b) => { - | ^ + | ^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #40107 @@ -27,10 +27,10 @@ error: aborting due to 3 previous errors Future incompatibility report: Future breakage diagnostic: error: missing fragment specifier - --> $DIR/macro-match-nonterminal.rs:2:8 + --> $DIR/macro-match-nonterminal.rs:2:6 | LL | ($a, $b) => { - | ^ + | ^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #40107 From a2a4f2bcb59115e5e7fbdeb1fbe1f261999b7bd6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 16 Aug 2024 12:19:39 +0200 Subject: [PATCH 5/8] Migrate `validate_json.py` script to rust in `run-make/rustdoc-map-file` test --- src/tools/run-make-support/src/lib.rs | 1 + tests/run-make/rustdoc-map-file/rmake.rs | 50 +++++++++++++++++-- .../rustdoc-map-file/validate_json.py | 41 --------------- 3 files changed, 48 insertions(+), 44 deletions(-) delete mode 100755 tests/run-make/rustdoc-map-file/validate_json.py diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 4bef4f0500784..fc20fd3b2e86a 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -38,6 +38,7 @@ pub use bstr; pub use gimli; pub use object; pub use regex; +pub use serde_json; pub use wasmparser; // Re-exports of external dependencies. diff --git a/tests/run-make/rustdoc-map-file/rmake.rs b/tests/run-make/rustdoc-map-file/rmake.rs index a4485165fd277..9b19279dee67b 100644 --- a/tests/run-make/rustdoc-map-file/rmake.rs +++ b/tests/run-make/rustdoc-map-file/rmake.rs @@ -1,4 +1,6 @@ -use run_make_support::{python_command, rustdoc}; +use run_make_support::path_helpers::read_dir_entries_recursive; +use run_make_support::rfs::read_to_string; +use run_make_support::{jzon, rustdoc}; fn main() { let out_dir = "out"; @@ -8,6 +10,48 @@ fn main() { .arg("--generate-redirect-map") .out_dir(&out_dir) .run(); - // FIXME (GuillaumeGomez): Port the python script to Rust as well. - python_command().arg("validate_json.py").arg(&out_dir).run(); + + let mut found_file = false; + read_dir_entries_recursive(&out_dir, |path| { + if !found_file + && path.is_file() + && path.file_name().map(|name| name == "redirect-map.json").unwrap_or(false) + { + found_file = true; + let generated = read_to_string(path); + let expected = read_to_string("expected.json"); + let generated = jzon::parse(&generated).expect("failed to parse JSON"); + let expected = jzon::parse(&expected).expect("failed to parse JSON"); + + let mut differences = Vec::new(); + for (key, expected_value) in expected.entries() { + match generated.get(key) { + Some(value) => { + if expected_value != value { + differences.push(format!("values for key `{key}` don't match")); + } + } + None => differences.push(format!("missing key `{key}`")), + } + } + for (key, data) in generated.entries() { + if !expected.has_key(key) { + differences + .push(format!("Extra data not expected: key: `{key}`, data: `{data}`")); + } + } + + if !differences.is_empty() { + eprintln!("Found differences in JSON files:"); + for diff in differences { + eprintln!("=> {diff}"); + } + std::process::exit(1); + } + } + }); + + if !found_file { + panic!("`redirect-map.json` file was not found"); + } } diff --git a/tests/run-make/rustdoc-map-file/validate_json.py b/tests/run-make/rustdoc-map-file/validate_json.py deleted file mode 100755 index 912dea3791bbf..0000000000000 --- a/tests/run-make/rustdoc-map-file/validate_json.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -import json - - -def find_redirect_map_file(folder, errors): - for root, _dirs, files in os.walk(folder): - for name in files: - if not name.endswith("redirect-map.json"): - continue - with open(os.path.join(root, name)) as f: - data = json.load(f) - with open("expected.json") as f: - expected = json.load(f) - for key in expected: - if expected[key] != data.get(key): - errors.append("Expected `{}` for key `{}`, found: `{}`".format( - expected[key], key, data.get(key))) - else: - del data[key] - for key in data: - errors.append("Extra data not expected: key: `{}`, data: `{}`".format( - key, data[key])) - return True - return False - - -if len(sys.argv) != 2: - print("Expected doc directory to check!") - sys.exit(1) - -errors = [] -if not find_redirect_map_file(sys.argv[1], errors): - print("Didn't find the map file in `{}`...".format(sys.argv[1])) - sys.exit(1) -for err in errors: - print("=> {}".format(err)) -if len(errors) != 0: - sys.exit(1) From 6b1637c477f9f40821c68a9452f7435d9707948d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 16 Aug 2024 15:09:04 +0200 Subject: [PATCH 6/8] Reexport `serde_json` crate from run-make-support to give it access to `run-make` tests --- Cargo.lock | 1 + src/tools/run-make-support/Cargo.toml | 1 + tests/run-make/rustdoc-map-file/rmake.rs | 75 ++++++++++++------------ 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1aa0b2ea4a398..0b546d6e5eee0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3149,6 +3149,7 @@ dependencies = [ "gimli 0.31.0", "object 0.36.2", "regex", + "serde_json", "similar", "wasmparser 0.214.0", ] diff --git a/src/tools/run-make-support/Cargo.toml b/src/tools/run-make-support/Cargo.toml index c4d5446a2481e..eae6022b803fd 100644 --- a/src/tools/run-make-support/Cargo.toml +++ b/src/tools/run-make-support/Cargo.toml @@ -11,3 +11,4 @@ wasmparser = { version = "0.214", default-features = false, features = ["std"] } regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace gimli = "0.31.0" build_helper = { path = "../build_helper" } +serde_json = "1.0" diff --git a/tests/run-make/rustdoc-map-file/rmake.rs b/tests/run-make/rustdoc-map-file/rmake.rs index 9b19279dee67b..d7e3510fe31e0 100644 --- a/tests/run-make/rustdoc-map-file/rmake.rs +++ b/tests/run-make/rustdoc-map-file/rmake.rs @@ -1,57 +1,54 @@ -use run_make_support::path_helpers::read_dir_entries_recursive; +// This test ensures that all items from `foo` are correctly generated into the `redirect-map.json` +// file with `--generate-redirect-map` rustdoc option. + +use std::path::Path; + use run_make_support::rfs::read_to_string; -use run_make_support::{jzon, rustdoc}; +use run_make_support::{path, rustdoc, serde_json}; fn main() { let out_dir = "out"; + let crate_name = "foo"; rustdoc() .input("foo.rs") + .crate_name(crate_name) .arg("-Zunstable-options") .arg("--generate-redirect-map") .out_dir(&out_dir) .run(); - let mut found_file = false; - read_dir_entries_recursive(&out_dir, |path| { - if !found_file - && path.is_file() - && path.file_name().map(|name| name == "redirect-map.json").unwrap_or(false) - { - found_file = true; - let generated = read_to_string(path); - let expected = read_to_string("expected.json"); - let generated = jzon::parse(&generated).expect("failed to parse JSON"); - let expected = jzon::parse(&expected).expect("failed to parse JSON"); + let generated = read_to_string(path(out_dir).join(crate_name).join("redirect-map.json")); + let expected = read_to_string("expected.json"); + let generated: serde_json::Value = + serde_json::from_str(&generated).expect("failed to parse JSON"); + let expected: serde_json::Value = + serde_json::from_str(&expected).expect("failed to parse JSON"); + let expected = expected.as_object().unwrap(); - let mut differences = Vec::new(); - for (key, expected_value) in expected.entries() { - match generated.get(key) { - Some(value) => { - if expected_value != value { - differences.push(format!("values for key `{key}` don't match")); - } - } - None => differences.push(format!("missing key `{key}`")), - } - } - for (key, data) in generated.entries() { - if !expected.has_key(key) { - differences - .push(format!("Extra data not expected: key: `{key}`, data: `{data}`")); + let mut differences = Vec::new(); + for (key, expected_value) in expected.iter() { + match generated.get(key) { + Some(value) => { + if expected_value != value { + differences.push(format!( + "values for key `{key}` don't match: `{expected_value:?}` != `{value:?}`" + )); } } - - if !differences.is_empty() { - eprintln!("Found differences in JSON files:"); - for diff in differences { - eprintln!("=> {diff}"); - } - std::process::exit(1); - } + None => differences.push(format!("missing key `{key}`")), + } + } + for (key, data) in generated.as_object().unwrap().iter() { + if !expected.contains_key(key) { + differences.push(format!("Extra data not expected: key: `{key}`, data: `{data}`")); } - }); + } - if !found_file { - panic!("`redirect-map.json` file was not found"); + if !differences.is_empty() { + eprintln!("Found differences in JSON files:"); + for diff in differences { + eprintln!("=> {diff}"); + } + panic!("Found differences in JSON files"); } } From c6815c04cb0761f6568168affd5f7b34398194f2 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sun, 11 Aug 2024 16:49:06 -0400 Subject: [PATCH 7/8] Re-enable debuginfo tests on freebsd --- tests/debuginfo/pretty-huge-vec.rs | 1 - tests/debuginfo/pretty-std-collections.rs | 1 - tests/debuginfo/pretty-std.rs | 1 - tests/debuginfo/pretty-uninitialized-vec.rs | 1 - 4 files changed, 4 deletions(-) diff --git a/tests/debuginfo/pretty-huge-vec.rs b/tests/debuginfo/pretty-huge-vec.rs index f4b5345b66d77..dcf3521175d4c 100644 --- a/tests/debuginfo/pretty-huge-vec.rs +++ b/tests/debuginfo/pretty-huge-vec.rs @@ -1,5 +1,4 @@ //@ ignore-windows failing on win32 bot -//@ ignore-freebsd: gdb package too new //@ ignore-android: FIXME(#10381) //@ compile-flags:-g //@ min-gdb-version: 8.1 diff --git a/tests/debuginfo/pretty-std-collections.rs b/tests/debuginfo/pretty-std-collections.rs index 7f518a886d700..3d5a30d19a9ce 100644 --- a/tests/debuginfo/pretty-std-collections.rs +++ b/tests/debuginfo/pretty-std-collections.rs @@ -1,5 +1,4 @@ //@ ignore-windows failing on win32 bot -//@ ignore-freebsd: gdb package too new //@ ignore-android: FIXME(#10381) //@ ignore-windows-gnu: #128981 //@ compile-flags:-g diff --git a/tests/debuginfo/pretty-std.rs b/tests/debuginfo/pretty-std.rs index cb5c825bb7217..933be9772343c 100644 --- a/tests/debuginfo/pretty-std.rs +++ b/tests/debuginfo/pretty-std.rs @@ -1,5 +1,4 @@ // ignore-tidy-linelength -//@ ignore-freebsd: gdb package too new //@ ignore-windows-gnu: #128981 //@ ignore-android: FIXME(#10381) //@ compile-flags:-g diff --git a/tests/debuginfo/pretty-uninitialized-vec.rs b/tests/debuginfo/pretty-uninitialized-vec.rs index 225b4a6d53452..5206ff23fd5ba 100644 --- a/tests/debuginfo/pretty-uninitialized-vec.rs +++ b/tests/debuginfo/pretty-uninitialized-vec.rs @@ -1,5 +1,4 @@ //@ ignore-windows failing on win32 bot -//@ ignore-freebsd: gdb package too new //@ ignore-android: FIXME(#10381) //@ compile-flags:-g //@ min-gdb-version: 8.1 From e6ac503ec19c6c356cfbb9b5f47aee1af4ce5626 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 16 Aug 2024 10:43:34 -0700 Subject: [PATCH 8/8] Stabilize std::thread::Builder::spawn_unchecked --- compiler/rustc_interface/src/lib.rs | 1 - library/std/src/thread/mod.rs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/rustc_interface/src/lib.rs b/compiler/rustc_interface/src/lib.rs index e37b30749ab30..3492df69b8d32 100644 --- a/compiler/rustc_interface/src/lib.rs +++ b/compiler/rustc_interface/src/lib.rs @@ -1,7 +1,6 @@ // tidy-alphabetical-start #![feature(decl_macro)] #![feature(let_chains)] -#![feature(thread_spawn_unchecked)] #![feature(try_blocks)] // tidy-alphabetical-end diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 88b31cd78a661..e29c28f3c7ec2 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -412,7 +412,6 @@ impl Builder { /// # Examples /// /// ``` - /// #![feature(thread_spawn_unchecked)] /// use std::thread; /// /// let builder = thread::Builder::new(); @@ -433,7 +432,7 @@ impl Builder { /// ``` /// /// [`io::Result`]: crate::io::Result - #[unstable(feature = "thread_spawn_unchecked", issue = "55132")] + #[stable(feature = "thread_spawn_unchecked", since = "CURRENT_RUSTC_VERSION")] pub unsafe fn spawn_unchecked(self, f: F) -> io::Result> where F: FnOnce() -> T,