From a7e0bab76bf28f7fe9791a2b412f8bccb061696f Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Sun, 18 Sep 2022 20:23:32 +0100 Subject: [PATCH 1/8] rand: freebsd update, using getrandom. supported since the 12th release, while 11.4 is EOL since 2021. --- library/std/src/sys/unix/rand.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/library/std/src/sys/unix/rand.rs b/library/std/src/sys/unix/rand.rs index a6fe07873d7ee..e846f885044f9 100644 --- a/library/std/src/sys/unix/rand.rs +++ b/library/std/src/sys/unix/rand.rs @@ -16,7 +16,6 @@ pub fn hashmap_random_keys() -> (u64, u64) { not(target_os = "ios"), not(target_os = "watchos"), not(target_os = "openbsd"), - not(target_os = "freebsd"), not(target_os = "netbsd"), not(target_os = "fuchsia"), not(target_os = "redox"), @@ -65,11 +64,25 @@ mod imp { unsafe { libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) } } + #[cfg(target_os = "freebsd")] + fn getrandom(buf: &mut [u8]) -> libc::ssize_t { + // FIXME: using the above when libary std's libc is updated + extern "C" { + fn getrandom( + buffer: *mut libc::c_void, + length: libc::size_t, + flags: libc::c_uint, + ) -> libc::ssize_t; + } + unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) } + } + #[cfg(not(any( target_os = "linux", target_os = "android", target_os = "espidf", - target_os = "horizon" + target_os = "horizon", + target_os = "freebsd" )))] fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool { false @@ -79,7 +92,8 @@ mod imp { target_os = "linux", target_os = "android", target_os = "espidf", - target_os = "horizon" + target_os = "horizon", + target_os = "freebsd" ))] fn getrandom_fill_bytes(v: &mut [u8]) -> bool { use crate::sync::atomic::{AtomicBool, Ordering}; @@ -219,7 +233,7 @@ mod imp { } } -#[cfg(any(target_os = "freebsd", target_os = "netbsd"))] +#[cfg(target_os = "netbsd")] mod imp { use crate::ptr; From a0538db82606eee92834f5fb0e3ae36951ca1c60 Mon Sep 17 00:00:00 2001 From: Alex Zepeda Date: Sat, 22 Jul 2023 04:04:53 -0700 Subject: [PATCH 2/8] bootstrap: Define CMake platform if DragonFly. CMAKE_SYSTEM_NAME is defined on a cross build if the target is recognized. Without this explicit definition cmake will assume that we're building for the host platform which can bring in unwanted compiler and linker flags. Also, add a warning on cross builds with unknown target to aid in cross builds for future platforms. --- src/bootstrap/download-ci-llvm-stamp | 2 +- src/bootstrap/llvm.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/download-ci-llvm-stamp b/src/bootstrap/download-ci-llvm-stamp index 120b3c9c4d28a..ffc38057900ad 100644 --- a/src/bootstrap/download-ci-llvm-stamp +++ b/src/bootstrap/download-ci-llvm-stamp @@ -1,4 +1,4 @@ Change this file to make users of the `download-ci-llvm` configuration download a new version of LLVM from CI, even if the LLVM submodule hasn’t changed. -Last change is for: https://github.com/rust-lang/rust/pull/112931 +Last change is for: https://github.com/rust-lang/rust/pull/113996 diff --git a/src/bootstrap/llvm.rs b/src/bootstrap/llvm.rs index 07719a711788e..02fef4b3e8302 100644 --- a/src/bootstrap/llvm.rs +++ b/src/bootstrap/llvm.rs @@ -559,6 +559,8 @@ fn configure_cmake( if target.contains("netbsd") { cfg.define("CMAKE_SYSTEM_NAME", "NetBSD"); + } else if target.contains("dragonfly") { + cfg.define("CMAKE_SYSTEM_NAME", "DragonFly"); } else if target.contains("freebsd") { cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD"); } else if target.contains("windows") { @@ -569,7 +571,12 @@ fn configure_cmake( cfg.define("CMAKE_SYSTEM_NAME", "SunOS"); } else if target.contains("linux") { cfg.define("CMAKE_SYSTEM_NAME", "Linux"); + } else { + builder.info( + "could not determine CMAKE_SYSTEM_NAME from the target `{target}`, build may fail", + ); } + // When cross-compiling we should also set CMAKE_SYSTEM_VERSION, but in // that case like CMake we cannot easily determine system version either. // From 2d92f4f2aa88b8f1740fd2d593b82820cdd336c5 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 25 Jul 2023 14:00:56 -0700 Subject: [PATCH 3/8] Remove -Z diagnostic-width --- compiler/rustc_session/src/options.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index ff433fdf16dc4..16d2029626eb6 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1433,8 +1433,6 @@ options! { dep_tasks: bool = (false, parse_bool, [UNTRACKED], "print tasks that execute and the color their dep node gets (requires debug build) \ (default: no)"), - diagnostic_width: Option = (None, parse_opt_number, [UNTRACKED], - "set the current output width for diagnostic truncation"), dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED], "emit diagnostics rather than buffering (breaks NLL error downgrading, sorting) \ (default: no)"), From 654b9243407df9079e5877b445e669c35cea5b63 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Tue, 25 Jul 2023 20:22:41 +0000 Subject: [PATCH 4/8] Add `sym::iter_mut` + `sym::as_mut_ptr` --- compiler/rustc_span/src/symbol.rs | 2 ++ src/tools/clippy/clippy_lints/src/methods/bytecount.rs | 2 +- tests/ui/proc-macro/meta-macro-hygiene.stdout | 2 +- tests/ui/proc-macro/nonterminal-token-hygiene.stdout | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 08925761b393c..54eb7bef5f205 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -372,6 +372,7 @@ symbols! { arm_target_feature, array, arrays, + as_mut_ptr, as_ptr, as_ref, as_str, @@ -858,6 +859,7 @@ symbols! { item, item_like_imports, iter, + iter_mut, iter_repeat, iterator_collect_fn, kcfi, diff --git a/src/tools/clippy/clippy_lints/src/methods/bytecount.rs b/src/tools/clippy/clippy_lints/src/methods/bytecount.rs index fef90f6eba495..f490a71755407 100644 --- a/src/tools/clippy/clippy_lints/src/methods/bytecount.rs +++ b/src/tools/clippy/clippy_lints/src/methods/bytecount.rs @@ -45,7 +45,7 @@ pub(super) fn check<'tcx>( let haystack = if let ExprKind::MethodCall(path, receiver, [], _) = filter_recv.kind { let p = path.ident.name; - if p == sym::iter || p == sym!(iter_mut) { + if p == sym::iter || p == sym::iter_mut { receiver } else { filter_recv diff --git a/tests/ui/proc-macro/meta-macro-hygiene.stdout b/tests/ui/proc-macro/meta-macro-hygiene.stdout index 17b69daa4f0e8..4a2200091b27e 100644 --- a/tests/ui/proc-macro/meta-macro-hygiene.stdout +++ b/tests/ui/proc-macro/meta-macro-hygiene.stdout @@ -18,7 +18,7 @@ Respanned: TokenStream [Ident { ident: "$crate", span: $DIR/auxiliary/make-macro use core /* 0#1 */::prelude /* 0#1 */::rust_2018 /* 0#1 */::*; #[macro_use /* 0#1 */] extern crate core /* 0#1 */; -extern crate compiler_builtins /* 442 */ as _ /* 0#1 */; +extern crate compiler_builtins /* 443 */ as _ /* 0#1 */; // Don't load unnecessary hygiene information from std extern crate std /* 0#0 */; diff --git a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout index 76d54ab2f1386..077a728a7a6ba 100644 --- a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout +++ b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout @@ -39,7 +39,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [ use ::core /* 0#1 */::prelude /* 0#1 */::rust_2015 /* 0#1 */::*; #[macro_use /* 0#1 */] extern crate core /* 0#2 */; -extern crate compiler_builtins /* 442 */ as _ /* 0#2 */; +extern crate compiler_builtins /* 443 */ as _ /* 0#2 */; // Don't load unnecessary hygiene information from std extern crate std /* 0#0 */; From 7d773c3304731716cc54db3531ba54067ca55a4a Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Wed, 26 Jul 2023 10:28:53 +0100 Subject: [PATCH 5/8] compiletest: remove ci-specific remap-path-prefix Now that we have fixed the underlying cause of long type name inconsistencies in #113893, we can remove the remap-path-prefix logic from CI --- src/tools/compiletest/src/header.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 4ae2249097f65..269d9384376f9 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -6,7 +6,6 @@ use std::io::BufReader; use std::path::{Path, PathBuf}; use std::process::Command; -use build_helper::ci::CiEnv; use tracing::*; use crate::common::{Config, Debugger, FailMode, Mode, PassMode}; @@ -298,13 +297,6 @@ impl TestProps { /// `//[foo]`), then the property is ignored unless `cfg` is /// `Some("foo")`. fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) { - // In CI, we've sometimes encountered non-determinism related to truncating very long paths. - // Set a consistent (short) prefix to avoid issues, but only in CI to avoid regressing the - // contributor experience. - if CiEnv::is_ci() { - self.remap_src_base = config.mode == Mode::Ui && !config.suite.contains("rustdoc"); - } - let mut has_edition = false; if !testfile.is_dir() { let file = File::open(testfile).unwrap(); From 648cf070ebcb52a42fb2e10febace4e8027557c7 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 21 Jul 2023 14:18:32 -0300 Subject: [PATCH 6/8] Add Param ty to SMIR --- compiler/rustc_smir/src/rustc_smir/mod.rs | 10 +++++++++- compiler/rustc_smir/src/stable_mir/ty.rs | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 044e2f8f32569..0e7673d25fb7d 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -825,7 +825,7 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> { ty::Alias(alias_kind, alias_ty) => { TyKind::Alias(alias_kind.stable(tables), alias_ty.stable(tables)) } - ty::Param(_) => todo!(), + ty::Param(param_ty) => TyKind::Param(param_ty.stable(tables)), ty::Bound(_, _) => todo!(), ty::Placeholder(..) | ty::GeneratorWitness(_) @@ -837,3 +837,11 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> { } } } + +impl<'tcx> Stable<'tcx> for rustc_middle::ty::ParamTy { + type T = stable_mir::ty::ParamTy; + fn stable(&self, _: &mut Tables<'tcx>) -> Self::T { + use stable_mir::ty::ParamTy; + ParamTy { index: self.index, name: self.name.to_string() } + } +} diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/rustc_smir/src/stable_mir/ty.rs index 7b4747a7fe29e..62dd02c1808a7 100644 --- a/compiler/rustc_smir/src/stable_mir/ty.rs +++ b/compiler/rustc_smir/src/stable_mir/ty.rs @@ -18,6 +18,7 @@ type Span = Opaque; pub enum TyKind { RigidTy(RigidTy), Alias(AliasKind, AliasTy), + Param(ParamTy), } #[derive(Clone, Debug)] @@ -228,3 +229,9 @@ pub struct ExistentialProjection { pub generic_args: GenericArgs, pub term: TermKind, } + +#[derive(Clone, Debug)] +pub struct ParamTy { + pub index: u32, + pub name: String, +} From 7af1697138de14dbfebe75d37d83d035c29a2bf8 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 21 Jul 2023 14:52:45 -0300 Subject: [PATCH 7/8] Add Bound ty to SMIR --- compiler/rustc_smir/src/rustc_smir/mod.rs | 12 +++++++++++- compiler/rustc_smir/src/stable_mir/ty.rs | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 0e7673d25fb7d..cefcab1e18f59 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -826,7 +826,9 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> { TyKind::Alias(alias_kind.stable(tables), alias_ty.stable(tables)) } ty::Param(param_ty) => TyKind::Param(param_ty.stable(tables)), - ty::Bound(_, _) => todo!(), + ty::Bound(debruijn_idx, bound_ty) => { + TyKind::Bound(debruijn_idx.as_usize(), bound_ty.stable(tables)) + } ty::Placeholder(..) | ty::GeneratorWitness(_) | ty::GeneratorWitnessMIR(_, _) @@ -845,3 +847,11 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::ParamTy { ParamTy { index: self.index, name: self.name.to_string() } } } + +impl<'tcx> Stable<'tcx> for rustc_middle::ty::BoundTy { + type T = stable_mir::ty::BoundTy; + fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { + use stable_mir::ty::BoundTy; + BoundTy { var: self.var.as_usize(), kind: self.kind.stable(tables) } + } +} diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/rustc_smir/src/stable_mir/ty.rs index 62dd02c1808a7..7a72afd666cf1 100644 --- a/compiler/rustc_smir/src/stable_mir/ty.rs +++ b/compiler/rustc_smir/src/stable_mir/ty.rs @@ -19,6 +19,7 @@ pub enum TyKind { RigidTy(RigidTy), Alias(AliasKind, AliasTy), Param(ParamTy), + Bound(usize, BoundTy), } #[derive(Clone, Debug)] @@ -235,3 +236,9 @@ pub struct ParamTy { pub index: u32, pub name: String, } + +#[derive(Clone, Debug)] +pub struct BoundTy { + pub var: usize, + pub kind: BoundTyKind, +} From 9914ae3292801299b35475ae5f9f3f004916fb21 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 21 Jul 2023 18:17:12 -0700 Subject: [PATCH 8/8] Squelch a noisy rustc_expand unittest --- compiler/rustc_expand/src/parse/tests.rs | 12 +++-- compiler/rustc_expand/src/tests.rs | 69 ++++++++++++++++-------- 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_expand/src/parse/tests.rs b/compiler/rustc_expand/src/parse/tests.rs index 8b37728b60fea..e133501c5d0a8 100644 --- a/compiler/rustc_expand/src/parse/tests.rs +++ b/compiler/rustc_expand/src/parse/tests.rs @@ -1,4 +1,6 @@ -use crate::tests::{matches_codepattern, string_to_stream, with_error_checking_parse}; +use crate::tests::{ + matches_codepattern, string_to_stream, with_error_checking_parse, with_expected_parse_error, +}; use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter, Token}; @@ -51,11 +53,15 @@ fn string_to_item(source_str: String) -> Option> { with_error_checking_parse(source_str, &sess(), |p| p.parse_item(ForceCollect::No)) } -#[should_panic] #[test] fn bad_path_expr_1() { + // This should trigger error: expected identifier, found keyword `return` create_default_session_globals_then(|| { - string_to_expr("::abc::def::return".to_string()); + with_expected_parse_error( + "::abc::def::return", + "expected identifier, found keyword `return`", + |p| p.parse_expr(), + ); }) } diff --git a/compiler/rustc_expand/src/tests.rs b/compiler/rustc_expand/src/tests.rs index aec0a1c6d8e2a..30fa5fea40769 100644 --- a/compiler/rustc_expand/src/tests.rs +++ b/compiler/rustc_expand/src/tests.rs @@ -22,6 +22,33 @@ fn string_to_parser(ps: &ParseSess, source_str: String) -> Parser<'_> { new_parser_from_source_str(ps, PathBuf::from("bogofile").into(), source_str) } +fn create_test_handler() -> (Handler, Lrc, Arc>>) { + let output = Arc::new(Mutex::new(Vec::new())); + let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty())); + let fallback_bundle = rustc_errors::fallback_fluent_bundle( + vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE], + false, + ); + let emitter = EmitterWriter::new( + Box::new(Shared { data: output.clone() }), + Some(source_map.clone()), + None, + fallback_bundle, + false, + false, + false, + Some(140), + false, + false, + TerminalUrl::No, + ); + let handler = Handler::with_emitter(Box::new(emitter)); + (handler, source_map, output) +} + +/// Returns the result of parsing the given string via the given callback. +/// +/// If there are any errors, this will panic. pub(crate) fn with_error_checking_parse<'a, T, F>(s: String, ps: &'a ParseSess, f: F) -> T where F: FnOnce(&mut Parser<'a>) -> PResult<'a, T>, @@ -32,6 +59,26 @@ where x } +/// Verifies that parsing the given string using the given callback will +/// generate an error that contains the given text. +pub(crate) fn with_expected_parse_error(source_str: &str, expected_output: &str, f: F) +where + F: for<'a> FnOnce(&mut Parser<'a>) -> PResult<'a, T>, +{ + let (handler, source_map, output) = create_test_handler(); + let ps = ParseSess::with_span_handler(handler, source_map); + let mut p = string_to_parser(&ps, source_str.to_string()); + let result = f(&mut p); + assert!(result.is_ok()); + + let bytes = output.lock().unwrap(); + let actual_output = str::from_utf8(&bytes).unwrap(); + println!("expected output:\n------\n{}------", expected_output); + println!("actual output:\n------\n{}------", actual_output); + + assert!(actual_output.contains(expected_output)) +} + /// Maps a string to tts, using a made-up filename. pub(crate) fn string_to_stream(source_str: String) -> TokenStream { let ps = ParseSess::new( @@ -130,13 +177,7 @@ impl Write for Shared { fn test_harness(file_text: &str, span_labels: Vec, expected_output: &str) { create_default_session_if_not_set_then(|_| { - let output = Arc::new(Mutex::new(Vec::new())); - - let fallback_bundle = rustc_errors::fallback_fluent_bundle( - vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE], - false, - ); - let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty())); + let (handler, source_map, output) = create_test_handler(); source_map.new_source_file(Path::new("test.rs").to_owned().into(), file_text.to_owned()); let primary_span = make_span(&file_text, &span_labels[0].start, &span_labels[0].end); @@ -148,20 +189,6 @@ fn test_harness(file_text: &str, span_labels: Vec, expected_output: & println!("text: {:?}", source_map.span_to_snippet(span)); } - let emitter = EmitterWriter::new( - Box::new(Shared { data: output.clone() }), - Some(source_map.clone()), - None, - fallback_bundle, - false, - false, - false, - None, - false, - false, - TerminalUrl::No, - ); - let handler = Handler::with_emitter(Box::new(emitter)); #[allow(rustc::untranslatable_diagnostic)] handler.span_err(msp, "foo");