From 5f50c0f7ac668bf1b2a29aa706d5b645e7060f65 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 7 Apr 2023 18:36:48 +0000 Subject: [PATCH 1/7] Document that `&T` and `&mut T` are `Sync` if `T` is --- library/core/src/primitive_docs.rs | 1 + library/std/src/primitive_docs.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/library/core/src/primitive_docs.rs b/library/core/src/primitive_docs.rs index bf8339335dd7c..51e6947a9c25a 100644 --- a/library/core/src/primitive_docs.rs +++ b/library/core/src/primitive_docs.rs @@ -1362,6 +1362,7 @@ mod prim_usize {} /// * [`Hash`] /// * [`ToSocketAddrs`] /// * [`Send`] \(`&T` references also require T: [Sync]) +/// * [`Sync`] /// /// [`std::fmt`]: fmt /// [`Hash`]: hash::Hash diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index bf8339335dd7c..51e6947a9c25a 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -1362,6 +1362,7 @@ mod prim_usize {} /// * [`Hash`] /// * [`ToSocketAddrs`] /// * [`Send`] \(`&T` references also require T: [Sync]) +/// * [`Sync`] /// /// [`std::fmt`]: fmt /// [`Hash`]: hash::Hash From c4f686401dab0a532a6acd09aaaa2ba8ea99346c Mon Sep 17 00:00:00 2001 From: Matt Harding Date: Sat, 8 Apr 2023 06:36:59 +0100 Subject: [PATCH 2/7] Correct missed rename of config.example.toml This commit: fcb2a3665f6 (Rename `config.toml.example` to `config.example.toml`, 2023-03-11) missed an instance in `config.example.toml` itself. --- config.example.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.example.toml b/config.example.toml index 5ef83760aed2d..15c6bc0f12376 100644 --- a/config.example.toml +++ b/config.example.toml @@ -16,7 +16,7 @@ # Use different pre-set defaults than the global defaults. # # See `src/bootstrap/defaults` for more information. -# Note that this has no default value (x.py uses the defaults in `config.toml.example`). +# Note that this has no default value (x.py uses the defaults in `config.example.toml`). #profile = # Keeps track of the last version of `x.py` used. From c80a69440c39aca92e73577cbeb0699415ecfcea Mon Sep 17 00:00:00 2001 From: Gimbles <93856041+gimbles@users.noreply.github.com> Date: Fri, 7 Apr 2023 23:15:25 +0530 Subject: [PATCH 3/7] s/ignore_git/omit_git_hash --- config.example.toml | 2 +- src/bootstrap/channel.rs | 6 +++--- src/bootstrap/config.rs | 12 ++++++------ src/bootstrap/lib.rs | 16 ++++++++-------- src/bootstrap/tool.rs | 2 +- .../host-x86_64/x86_64-gnu-distcheck/Dockerfile | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/config.example.toml b/config.example.toml index 5ef83760aed2d..edc72d3ec1cb4 100644 --- a/config.example.toml +++ b/config.example.toml @@ -585,7 +585,7 @@ changelog-seen = 2 # Having the git information can cause a lot of rebuilds during development. # # FIXME(#76720): this can causes bugs if different compilers reuse the same metadata cache. -#ignore-git = if rust.channel == "dev" { true } else { false } +#omit-git-hash = if rust.channel == "dev" { true } else { false } # Whether to create a source tarball by default when running `x dist`. # diff --git a/src/bootstrap/channel.rs b/src/bootstrap/channel.rs index eae81b9fc69c8..390047f6fdce1 100644 --- a/src/bootstrap/channel.rs +++ b/src/bootstrap/channel.rs @@ -19,7 +19,7 @@ pub enum GitInfo { #[default] Absent, /// This is a git repository. - /// If the info should be used (`ignore_git` is false), this will be + /// If the info should be used (`omit_git_hash` is false), this will be /// `Some`, otherwise it will be `None`. Present(Option), /// This is not a git repostory, but the info can be fetched from the @@ -35,7 +35,7 @@ pub struct Info { } impl GitInfo { - pub fn new(ignore_git: bool, dir: &Path) -> GitInfo { + pub fn new(omit_git_hash: bool, dir: &Path) -> GitInfo { // See if this even begins to look like a git dir if !dir.join(".git").exists() { match read_commit_info_file(dir) { @@ -52,7 +52,7 @@ impl GitInfo { // If we're ignoring the git info, we don't actually need to collect it, just make sure this // was a git repo in the first place. - if ignore_git { + if omit_git_hash { return GitInfo::Present(None); } diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index b8b6b7b2d4e9a..7a934e16f5a35 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -77,7 +77,7 @@ pub struct Config { pub tools: Option>, pub sanitizers: bool, pub profiler: bool, - pub ignore_git: bool, + pub omit_git_hash: bool, pub exclude: Vec, pub include_default_paths: bool, pub rustc_error_format: Option, @@ -755,7 +755,7 @@ define_config! { verbose_tests: Option = "verbose-tests", optimize_tests: Option = "optimize-tests", codegen_tests: Option = "codegen-tests", - ignore_git: Option = "ignore-git", + omit_git_hash: Option = "omit-git-hash", dist_src: Option = "dist-src", save_toolstates: Option = "save-toolstates", codegen_backends: Option> = "codegen-backends", @@ -1088,7 +1088,7 @@ impl Config { let mut debuginfo_level_tools = None; let mut debuginfo_level_tests = None; let mut optimize = None; - let mut ignore_git = None; + let mut omit_git_hash = None; if let Some(rust) = toml.rust { debug = rust.debug; @@ -1109,7 +1109,7 @@ impl Config { .map(|v| v.expect("invalid value for rust.split_debuginfo")) .unwrap_or(SplitDebuginfo::default_for_platform(&config.build.triple)); optimize = rust.optimize; - ignore_git = rust.ignore_git; + omit_git_hash = rust.omit_git_hash; config.rust_new_symbol_mangling = rust.new_symbol_mangling; set(&mut config.rust_optimize_tests, rust.optimize_tests); set(&mut config.codegen_tests, rust.codegen_tests); @@ -1166,8 +1166,8 @@ impl Config { // rust_info must be set before is_ci_llvm_available() is called. let default = config.channel == "dev"; - config.ignore_git = ignore_git.unwrap_or(default); - config.rust_info = GitInfo::new(config.ignore_git, &config.src); + config.omit_git_hash = omit_git_hash.unwrap_or(default); + config.rust_info = GitInfo::new(config.omit_git_hash, &config.src); if let Some(llvm) = toml.llvm { match llvm.ccache { diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index e3f3ab5243e2c..5ee18cf641104 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -358,14 +358,14 @@ impl Build { #[cfg(not(unix))] let is_sudo = false; - let ignore_git = config.ignore_git; - let rust_info = channel::GitInfo::new(ignore_git, &src); - let cargo_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/cargo")); + let omit_git_hash = config.omit_git_hash; + let rust_info = channel::GitInfo::new(omit_git_hash, &src); + let cargo_info = channel::GitInfo::new(omit_git_hash, &src.join("src/tools/cargo")); let rust_analyzer_info = - channel::GitInfo::new(ignore_git, &src.join("src/tools/rust-analyzer")); - let clippy_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/clippy")); - let miri_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/miri")); - let rustfmt_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/rustfmt")); + channel::GitInfo::new(omit_git_hash, &src.join("src/tools/rust-analyzer")); + let clippy_info = channel::GitInfo::new(omit_git_hash, &src.join("src/tools/clippy")); + let miri_info = channel::GitInfo::new(omit_git_hash, &src.join("src/tools/miri")); + let rustfmt_info = channel::GitInfo::new(omit_git_hash, &src.join("src/tools/rustfmt")); // we always try to use git for LLVM builds let in_tree_llvm_info = channel::GitInfo::new(false, &src.join("src/llvm-project")); @@ -1233,7 +1233,7 @@ impl Build { match &self.config.channel[..] { "stable" => num.to_string(), "beta" => { - if self.rust_info().is_managed_git_subrepository() && !self.config.ignore_git { + if self.rust_info().is_managed_git_subrepository() && !self.config.omit_git_hash { format!("{}-beta.{}", num, self.beta_prerelease_version()) } else { format!("{}-beta", num) diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 3c9a154da9ab1..6a687a7903e0f 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -320,7 +320,7 @@ pub fn prepare_tool_cargo( cargo.env("CFG_RELEASE_NUM", &builder.version); cargo.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel()); - let info = GitInfo::new(builder.config.ignore_git, &dir); + let info = GitInfo::new(builder.config.omit_git_hash, &dir); if let Some(sha) = info.sha() { cargo.env("CFG_COMMIT_HASH", sha); } diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-distcheck/Dockerfile b/src/ci/docker/host-x86_64/x86_64-gnu-distcheck/Dockerfile index 7e640c49f015a..2217e6ee7043a 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu-distcheck/Dockerfile +++ b/src/ci/docker/host-x86_64/x86_64-gnu-distcheck/Dockerfile @@ -24,6 +24,6 @@ RUN sh /scripts/sccache.sh # We are disabling CI LLVM since distcheck is an offline build. ENV NO_DOWNLOAD_CI_LLVM 1 -ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu --set rust.ignore-git=false +ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu --set rust.omit-git-hash=false ENV SCRIPT python3 ../x.py --stage 2 test distcheck ENV DIST_SRC 1 From f1ded91a48034c3649f72202894811c3e669a65a Mon Sep 17 00:00:00 2001 From: Gimbles <93856041+gimbles@users.noreply.github.com> Date: Fri, 7 Apr 2023 22:50:03 +0530 Subject: [PATCH 4/7] rm box_items fix in plugin.md fmt --- .../src/language-features/lang-items.md | 16 ++++++++++++---- .../src/language-features/plugin.md | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/doc/unstable-book/src/language-features/lang-items.md b/src/doc/unstable-book/src/language-features/lang-items.md index 39238dffa1031..6adb3506e646a 100644 --- a/src/doc/unstable-book/src/language-features/lang-items.md +++ b/src/doc/unstable-book/src/language-features/lang-items.md @@ -16,18 +16,26 @@ and one for deallocation. A freestanding program that uses the `Box` sugar for dynamic allocations via `malloc` and `free`: ```rust,ignore (libc-is-finicky) -#![feature(lang_items, box_syntax, start, libc, core_intrinsics, rustc_private)] +#![feature(lang_items, start, libc, core_intrinsics, rustc_private, rustc_attrs)] #![no_std] use core::intrinsics; use core::panic::PanicInfo; +use core::ptr::NonNull; extern crate libc; -struct Unique(*mut T); +struct Unique(NonNull); #[lang = "owned_box"] pub struct Box(Unique); +impl Box { + pub fn new(x: T) -> Self { + #[rustc_box] + Box::new(x) + } +} + #[lang = "exchange_malloc"] unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { let p = libc::malloc(size as libc::size_t) as *mut u8; @@ -47,13 +55,13 @@ unsafe fn box_free(ptr: *mut T) { #[start] fn main(_argc: isize, _argv: *const *const u8) -> isize { - let _x = box 1; + let _x = Box::new(1); 0 } #[lang = "eh_personality"] extern fn rust_eh_personality() {} -#[lang = "panic_impl"] extern fn rust_begin_panic(info: &PanicInfo) -> ! { unsafe { intrinsics::abort() } } +#[lang = "panic_impl"] extern fn rust_begin_panic(_info: &PanicInfo) -> ! { intrinsics::abort() } #[no_mangle] pub extern fn rust_eh_register_frames () {} #[no_mangle] pub extern fn rust_eh_unregister_frames () {} ``` diff --git a/src/doc/unstable-book/src/language-features/plugin.md b/src/doc/unstable-book/src/language-features/plugin.md index dfbb468d4df94..1fade6ce95b89 100644 --- a/src/doc/unstable-book/src/language-features/plugin.md +++ b/src/doc/unstable-book/src/language-features/plugin.md @@ -37,7 +37,7 @@ additional checks for code style, safety, etc. Now let's write a plugin that warns about any item named `lintme`. ```rust,ignore (requires-stage-2) -#![feature(box_syntax, rustc_private)] +#![feature(rustc_private)] extern crate rustc_ast; @@ -68,7 +68,7 @@ impl EarlyLintPass for Pass { #[no_mangle] fn __rustc_plugin_registrar(reg: &mut Registry) { reg.lint_store.register_lints(&[&TEST_LINT]); - reg.lint_store.register_early_pass(|| box Pass); + reg.lint_store.register_early_pass(|| Box::new(Pass)); } ``` From ee554e24445effe121393f06d1f4f6dae9332ad4 Mon Sep 17 00:00:00 2001 From: Matt Harding Date: Sat, 8 Apr 2023 07:16:24 +0100 Subject: [PATCH 5/7] Make "codegen" config.toml profile build llvm --- src/bootstrap/defaults/config.codegen.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bootstrap/defaults/config.codegen.toml b/src/bootstrap/defaults/config.codegen.toml index 20b2699c761bf..113df88d7c349 100644 --- a/src/bootstrap/defaults/config.codegen.toml +++ b/src/bootstrap/defaults/config.codegen.toml @@ -9,6 +9,8 @@ compiler-docs = true assertions = true # enable warnings during the llvm compilation enable-warnings = true +# build llvm from source +download-ci-llvm = false [rust] # This enables `RUSTC_LOG=debug`, avoiding confusing situations From e6dc69ab4bef90e0f99e32f72b6dbeabaf7ab29e Mon Sep 17 00:00:00 2001 From: beetrees Date: Sat, 8 Apr 2023 00:22:03 +0100 Subject: [PATCH 6/7] Add `max_line_length` to `.editorconfig`, matching rustfmt --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index ec6e107d547f0..03aab32bfc6e1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,6 +11,7 @@ trim_trailing_whitespace = true insert_final_newline = true indent_style = space indent_size = 4 +max_line_length = 100 [*.md] # double whitespace at end of line From fbc3457d3582c44882ed20c5b11c6ba589163ab1 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 8 Apr 2023 21:32:36 +0000 Subject: [PATCH 7/7] Tweak tuple indexing suggestion --- compiler/rustc_hir_typeck/src/expr.rs | 29 +++++++++++++++------------ tests/ui/index_message.rs | 4 ++-- tests/ui/index_message.stderr | 2 +- tests/ui/issues/issue-27842.rs | 5 +++++ tests/ui/issues/issue-27842.stderr | 12 ++++++++++- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index c17aae22ba540..68e096e3bd023 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -2810,23 +2810,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { "cannot index into a value of type `{base_t}`", ); // Try to give some advice about indexing tuples. - if let ty::Tuple(..) = base_t.kind() { + if let ty::Tuple(types) = base_t.kind() { let mut needs_note = true; // If the index is an integer, we can show the actual // fixed expression: - if let ExprKind::Lit(ref lit) = idx.kind { - if let ast::LitKind::Int(i, ast::LitIntType::Unsuffixed) = lit.node { - let snip = self.tcx.sess.source_map().span_to_snippet(base.span); - if let Ok(snip) = snip { - err.span_suggestion( - expr.span, - "to access tuple elements, use", - format!("{snip}.{i}"), - Applicability::MachineApplicable, - ); - needs_note = false; - } + if let ExprKind::Lit(ref lit) = idx.kind + && let ast::LitKind::Int(i, ast::LitIntType::Unsuffixed) = lit.node + && i < types.len().try_into().expect("expected tuple index to be < usize length") + { + let snip = self.tcx.sess.source_map().span_to_snippet(base.span); + if let Ok(snip) = snip { + err.span_suggestion( + expr.span, + "to access tuple elements, use", + format!("{snip}.{i}"), + Applicability::MachineApplicable, + ); + needs_note = false; } + } else if let ExprKind::Path(..) = idx.peel_borrows().kind { + err.span_label(idx.span, "cannot access tuple elements at a variable index"); } if needs_note { err.help( diff --git a/tests/ui/index_message.rs b/tests/ui/index_message.rs index 87e0cde591959..88b848d6f8574 100644 --- a/tests/ui/index_message.rs +++ b/tests/ui/index_message.rs @@ -1,4 +1,4 @@ fn main() { - let z = (); - let _ = z[0]; //~ ERROR cannot index into a value of type `()` + let z = (10,); + let _ = z[0]; //~ ERROR cannot index into a value of type `({integer},)` } diff --git a/tests/ui/index_message.stderr b/tests/ui/index_message.stderr index 6c2b126734b05..56d1d70809db8 100644 --- a/tests/ui/index_message.stderr +++ b/tests/ui/index_message.stderr @@ -1,4 +1,4 @@ -error[E0608]: cannot index into a value of type `()` +error[E0608]: cannot index into a value of type `({integer},)` --> $DIR/index_message.rs:3:13 | LL | let _ = z[0]; diff --git a/tests/ui/issues/issue-27842.rs b/tests/ui/issues/issue-27842.rs index 3bcfa13307018..060d3b34e09d9 100644 --- a/tests/ui/issues/issue-27842.rs +++ b/tests/ui/issues/issue-27842.rs @@ -8,4 +8,9 @@ fn main() { let i = 0_usize; let _ = tup[i]; //~^ ERROR cannot index into a value of type + + // the case where the index is out of bounds + let tup = (10,); + let _ = tup[3]; + //~^ ERROR cannot index into a value of type } diff --git a/tests/ui/issues/issue-27842.stderr b/tests/ui/issues/issue-27842.stderr index 784666a639e1e..83333aa0c47b9 100644 --- a/tests/ui/issues/issue-27842.stderr +++ b/tests/ui/issues/issue-27842.stderr @@ -8,10 +8,20 @@ error[E0608]: cannot index into a value of type `({integer}, {integer}, {integer --> $DIR/issue-27842.rs:9:13 | LL | let _ = tup[i]; + | ^^^^-^ + | | + | cannot access tuple elements at a variable index + | + = help: to access tuple elements, use tuple indexing syntax (e.g., `tuple.0`) + +error[E0608]: cannot index into a value of type `({integer},)` + --> $DIR/issue-27842.rs:14:13 + | +LL | let _ = tup[3]; | ^^^^^^ | = help: to access tuple elements, use tuple indexing syntax (e.g., `tuple.0`) -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0608`.