From 420c58fb119325325ec2f58f1686d7bcb63b51ad Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 27 Feb 2024 15:05:02 +0000 Subject: [PATCH 01/19] sess: stabilize relro-level Signed-off-by: David Wood --- compiler/rustc_codegen_ssa/src/back/link.rs | 2 +- compiler/rustc_interface/src/tests.rs | 2 +- compiler/rustc_session/src/options.rs | 4 ++-- compiler/rustc_session/src/session.rs | 2 +- src/doc/rustc/src/codegen-options/index.md | 20 ++++++++++++++++++++ tests/run-make/relro-levels/Makefile | 8 ++++---- 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index e4a050dcfc9bd..5cc286e86eb5a 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -2013,7 +2013,7 @@ fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained: /// Add options making relocation sections in the produced ELF files read-only /// and suppressing lazy binding. fn add_relro_args(cmd: &mut dyn Linker, sess: &Session) { - match sess.opts.unstable_opts.relro_level.unwrap_or(sess.target.relro_level) { + match sess.opts.cg.relro_level.unwrap_or(sess.target.relro_level) { RelroLevel::Full => cmd.full_relro(), RelroLevel::Partial => cmd.partial_relro(), RelroLevel::Off => cmd.no_relro(), diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 112553b2f7031..f22d727c391f5 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -608,6 +608,7 @@ fn test_codegen_options_tracking_hash() { tracked!(profile_generate, SwitchWithOptPath::Enabled(None)); tracked!(profile_use, Some(PathBuf::from("abc"))); tracked!(relocation_model, Some(RelocModel::Pic)); + tracked!(relro_level, Some(RelroLevel::Full)); tracked!(soft_float, true); tracked!(split_debuginfo, Some(SplitDebuginfo::Packed)); tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0)); @@ -805,7 +806,6 @@ fn test_unstable_options_tracking_hash() { tracked!(profile_sample_use, Some(PathBuf::from("abc"))); tracked!(profiler_runtime, "abc".to_string()); tracked!(relax_elf_relocations, Some(true)); - tracked!(relro_level, Some(RelroLevel::Full)); tracked!(remap_cwd_prefix, Some(PathBuf::from("abc"))); tracked!(sanitizer, SanitizerSet::ADDRESS); tracked!(sanitizer_cfi_canonical_jump_tables, None); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 743f476033935..9bb252f89c833 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1494,6 +1494,8 @@ options! { relocation_model: Option = (None, parse_relocation_model, [TRACKED], "control generation of position-independent code (PIC) \ (`rustc --print relocation-models` for details)"), + relro_level: Option = (None, parse_relro_level, [TRACKED], + "choose which RELRO level to use"), remark: Passes = (Passes::Some(Vec::new()), parse_passes, [UNTRACKED], "output remarks for these optimization passes (space separated, or \"all\")"), rpath: bool = (false, parse_bool, [UNTRACKED], @@ -1829,8 +1831,6 @@ options! { "randomize the layout of types (default: no)"), relax_elf_relocations: Option = (None, parse_opt_bool, [TRACKED], "whether ELF relocations can be relaxed"), - relro_level: Option = (None, parse_relro_level, [TRACKED], - "choose which RELRO level to use"), remap_cwd_prefix: Option = (None, parse_opt_pathbuf, [TRACKED], "remap paths under the current working directory to this path prefix"), remap_path_scope: RemapPathScopeComponents = (RemapPathScopeComponents::all(), parse_remap_path_scope, [TRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index b6c1948689892..b243fe8eb4d58 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -587,7 +587,7 @@ impl Session { let dbg_opts = &self.opts.unstable_opts; - let relro_level = dbg_opts.relro_level.unwrap_or(self.target.relro_level); + let relro_level = self.opts.cg.relro_level.unwrap_or(self.target.relro_level); // Only enable this optimization by default if full relro is also enabled. // In this case, lazy binding was already unavailable, so nothing is lost. diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index 4a4f1ae98e407..0cba925bb4fc6 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -479,6 +479,26 @@ then `-C target-feature=+crt-static` "wins" over `-C relocation-model=pic`, and the linker is instructed (`-static`) to produce a statically linked but not position-independent executable. +## relro-level + +This flag controls what level of RELRO (Relocation Read-Only) is enabled. RELRO is an exploit +mitigation which makes the Global Offset Table (GOT) read-only. + +Supported values for this option are: + +- `off`: Dynamically linked functions are resolved lazily and the GOT is writable. +- `partial`: Dynamically linked functions are resolved lazily and written into the Procedure + Linking Table (PLT) part of the GOT (`.got.plt`). The non-PLT part of the GOT (`.got`) is made + read-only and both are moved to prevent writing from buffer overflows. +- `full`: Dynamically linked functions are resolved at the start of program execution and the + Global Offset Table (`.got`/`.got.plt`) is populated eagerly and then made read-only. The GOT is + also moved to prevent writing from buffer overflows. Full RELRO uses more memory and increases + process startup time. + +This flag is ignored on platforms where RELRO is not supported (targets which do not use the ELF +binary format), such as Windows or macOS. Each rustc target has its own default for RELRO. rustc +enables Full RELRO by default on platforms where it is supported. + ## remark This flag lets you print remarks for optimization passes. diff --git a/tests/run-make/relro-levels/Makefile b/tests/run-make/relro-levels/Makefile index e0402f59f12dd..94f08bcb4945c 100644 --- a/tests/run-make/relro-levels/Makefile +++ b/tests/run-make/relro-levels/Makefile @@ -3,20 +3,20 @@ include ../tools.mk # only-linux # -# This tests the different -Zrelro-level values, and makes sure that they work properly. +# This tests the different -Crelro-level values, and makes sure that they work properly. all: # Ensure that binaries built with the full relro level links them with both # RELRO and BIND_NOW for doing eager symbol resolving. - $(RUSTC) -Zrelro-level=full hello.rs + $(RUSTC) -Crelro-level=full hello.rs readelf -l $(TMPDIR)/hello | grep -q GNU_RELRO readelf -d $(TMPDIR)/hello | grep -q BIND_NOW - $(RUSTC) -Zrelro-level=partial hello.rs + $(RUSTC) -Crelro-level=partial hello.rs readelf -l $(TMPDIR)/hello | grep -q GNU_RELRO # Ensure that we're *not* built with RELRO when setting it to off. We do # not want to check for BIND_NOW however, as the linker might have that # enabled by default. - $(RUSTC) -Zrelro-level=off hello.rs + $(RUSTC) -Crelro-level=off hello.rs ! readelf -l $(TMPDIR)/hello | grep -q GNU_RELRO From a0bb25f11c99905b03785de0b5173f9b1bd7bded Mon Sep 17 00:00:00 2001 From: Bryant Le Date: Thu, 14 Mar 2024 18:31:09 -0500 Subject: [PATCH 02/19] doc(bootstrap): add top-level doc-comment to utils/tarball.rs --- src/bootstrap/src/utils/tarball.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/bootstrap/src/utils/tarball.rs b/src/bootstrap/src/utils/tarball.rs index 03f56cba29d8d..47f135fae9ed7 100644 --- a/src/bootstrap/src/utils/tarball.rs +++ b/src/bootstrap/src/utils/tarball.rs @@ -1,3 +1,10 @@ +//! Facilitates the management and generation of tarballs. +//! +//! Tarballs efficiently hold Rust compiler build artifacts and +//! capture a snapshot of each boostrap stage. +//! In uplifting, a tarball from Stage N captures essential components +//! to assemble Stage N + 1 compiler. + use std::{ path::{Path, PathBuf}, process::Command, From dacfbfccc5da7c88e466af06be9468f2d10da03e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 9 Apr 2024 17:44:20 +0000 Subject: [PATCH 03/19] Update ar_archive_writer to 0.2.0 This adds a whole bunch of tests checking for any difference with llvm's archive writer. It also fixes two mistakes in the porting from C++ to Rust. The first one causes a divergence for Mach-O archives which may or may not be harmless. The second will definitively cause issues, but only applies to thin archives, which rustc currently doesn't create. --- Cargo.lock | 4 ++-- compiler/rustc_codegen_ssa/Cargo.toml | 2 +- compiler/rustc_codegen_ssa/src/back/archive.rs | 9 +-------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b1bdaef81ff83..d8044c67a47b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -210,9 +210,9 @@ dependencies = [ [[package]] name = "ar_archive_writer" -version = "0.1.5" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9792d37ca5173d7e7f4fe453739a0671d0557915a030a383d6b866476bbc3e71" +checksum = "f0c269894b6fe5e9d7ada0cf69b5bf847ff35bc25fc271f08e1d080fce80339a" dependencies = [ "object 0.32.2", ] diff --git a/compiler/rustc_codegen_ssa/Cargo.toml b/compiler/rustc_codegen_ssa/Cargo.toml index baf10622a6df6..f347a7fb0bb10 100644 --- a/compiler/rustc_codegen_ssa/Cargo.toml +++ b/compiler/rustc_codegen_ssa/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -ar_archive_writer = "0.1.5" +ar_archive_writer = "0.2.0" bitflags = "2.4.1" cc = "1.0.90" itertools = "0.12" diff --git a/compiler/rustc_codegen_ssa/src/back/archive.rs b/compiler/rustc_codegen_ssa/src/back/archive.rs index ef55682d541ec..d336973d2b9c8 100644 --- a/compiler/rustc_codegen_ssa/src/back/archive.rs +++ b/compiler/rustc_codegen_ssa/src/back/archive.rs @@ -285,14 +285,7 @@ impl<'a> ArArchiveBuilder<'a> { .tempfile_in(output.parent().unwrap_or_else(|| Path::new(""))) .map_err(|err| io_error_context("couldn't create a temp file", err))?; - write_archive_to_stream( - archive_tmpfile.as_file_mut(), - &entries, - true, - archive_kind, - true, - false, - )?; + write_archive_to_stream(archive_tmpfile.as_file_mut(), &entries, archive_kind, false)?; let any_entries = !entries.is_empty(); drop(entries); From efbbfa24a5b309c713079486908c1754721548f9 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 10 Apr 2024 15:02:04 +0200 Subject: [PATCH 04/19] visionOS: Fix logic for finding the SDK root The `sdk_name` is `xros`/`xrsimulator`, not `visionos`/`visionossimulator`. --- compiler/rustc_codegen_ssa/src/back/link.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index ac278de02af2e..cc3f18294caca 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -3029,9 +3029,10 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result {} "watchsimulator" if sdkroot.contains("WatchOS.platform") || sdkroot.contains("MacOSX.platform") => {} - "visionos" - if sdkroot.contains("XROS.platform") || sdkroot.contains("MacOSX.platform") => {} - "visionossimulator" + "xros" + if sdkroot.contains("XRSimulator.platform") + || sdkroot.contains("MacOSX.platform") => {} + "xrsimulator" if sdkroot.contains("XROS.platform") || sdkroot.contains("MacOSX.platform") => {} // Ignore `SDKROOT` if it's not a valid path. _ if !p.is_absolute() || p == Path::new("/") || !p.exists() => {} From 69a3b0e213a8b197c1099fb129dac6ce8185d39b Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 10 Apr 2024 14:59:11 +0200 Subject: [PATCH 05/19] visionOS: Fix unused import warning The import is used once in this file, inside `posix_spawn`, so let's move the import into that function instead, to reduce the number of `cfg`s that need to be kept in sync. --- .../std/src/sys/pal/unix/process/process_unix.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/library/std/src/sys/pal/unix/process/process_unix.rs b/library/std/src/sys/pal/unix/process/process_unix.rs index e798510f9e64c..d65657790c48b 100644 --- a/library/std/src/sys/pal/unix/process/process_unix.rs +++ b/library/std/src/sys/pal/unix/process/process_unix.rs @@ -11,18 +11,6 @@ use crate::os::linux::process::PidFd; #[cfg(target_os = "linux")] use crate::os::unix::io::AsRawFd; -#[cfg(any( - target_os = "macos", - target_os = "watchos", - target_os = "visionos", - target_os = "tvos", - target_os = "freebsd", - all(target_os = "linux", target_env = "gnu"), - all(target_os = "linux", target_env = "musl"), - target_os = "nto", -))] -use crate::sys::weak::weak; - #[cfg(target_os = "vxworks")] use libc::RTP_ID as pid_t; @@ -466,6 +454,7 @@ impl Command { envp: Option<&CStringArray>, ) -> io::Result> { use crate::mem::MaybeUninit; + use crate::sys::weak::weak; use crate::sys::{self, cvt_nz, unix_sigpipe_attr_specified}; if self.get_gid().is_some() From 1a7238407c8964fb902f259d712eac9e87052680 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 10 Apr 2024 18:00:43 +0200 Subject: [PATCH 06/19] Allow specifying SDKROOT as containing XRSimulator.platform Checking this was missing from the `link_env_remove` function, so compilation might fail if set when compiling for macOS --- compiler/rustc_target/src/spec/base/apple/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_target/src/spec/base/apple/mod.rs b/compiler/rustc_target/src/spec/base/apple/mod.rs index 021457b145fa9..d667bad44e3b7 100644 --- a/compiler/rustc_target/src/spec/base/apple/mod.rs +++ b/compiler/rustc_target/src/spec/base/apple/mod.rs @@ -298,6 +298,7 @@ fn link_env_remove(os: &'static str) -> StaticCow<[StaticCow]> { || sdkroot.contains("WatchOS.platform") || sdkroot.contains("WatchSimulator.platform") || sdkroot.contains("XROS.platform") + || sdkroot.contains("XRSimulator.platform") { env_remove.push("SDKROOT".into()) } From 800c50608ca992bce2b90bd7361ad908bb4045e2 Mon Sep 17 00:00:00 2001 From: Amanda Stjerna Date: Thu, 11 Apr 2024 16:56:45 +0200 Subject: [PATCH 07/19] Slightly more readable NLL/constraint graph dumps --- .../src/region_infer/graphviz.rs | 40 +++++++++++++++++-- .../rustc_borrowck/src/region_infer/mod.rs | 2 +- .../src/region_infer/opaque_types.rs | 2 +- compiler/rustc_type_ir/src/lib.rs | 5 +++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_borrowck/src/region_infer/graphviz.rs b/compiler/rustc_borrowck/src/region_infer/graphviz.rs index c103ba3c40709..f145d30fe38a9 100644 --- a/compiler/rustc_borrowck/src/region_infer/graphviz.rs +++ b/compiler/rustc_borrowck/src/region_infer/graphviz.rs @@ -6,7 +6,38 @@ use std::borrow::Cow; use std::io::{self, Write}; use super::*; +use itertools::Itertools; use rustc_graphviz as dot; +use rustc_middle::ty::UniverseIndex; + +fn render_outlives_constraint(constraint: &OutlivesConstraint<'_>) -> String { + match constraint.locations { + Locations::All(_) => "All(...)".to_string(), + Locations::Single(loc) => format!("{loc:?}"), + } +} + +fn render_universe(u: UniverseIndex) -> String { + if u.is_root() { + return "".to_string(); + } + + format!("/{:?}", u) +} + +fn render_region_vid(rvid: RegionVid, regioncx: &RegionInferenceContext<'_>) -> String { + let universe_str = render_universe(regioncx.region_definition(rvid).universe); + + let external_name_str = if let Some(external_name) = + regioncx.region_definition(rvid).external_name.and_then(|e| e.get_name()) + { + format!(" ({external_name})") + } else { + "".to_string() + }; + + format!("{:?}{universe_str}{external_name_str}", rvid) +} impl<'tcx> RegionInferenceContext<'tcx> { /// Write out the region constraint graph. @@ -46,10 +77,10 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for RawConstraints<'a, 'tcx> { Some(dot::LabelText::LabelStr(Cow::Borrowed("box"))) } fn node_label(&'this self, n: &RegionVid) -> dot::LabelText<'this> { - dot::LabelText::LabelStr(format!("{n:?}").into()) + dot::LabelText::LabelStr(render_region_vid(*n, self.regioncx).into()) } fn edge_label(&'this self, e: &OutlivesConstraint<'tcx>) -> dot::LabelText<'this> { - dot::LabelText::LabelStr(format!("{:?}", e.locations).into()) + dot::LabelText::LabelStr(render_outlives_constraint(e).into()) } } @@ -96,8 +127,9 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for SccConstraints<'a, 'tcx> { Some(dot::LabelText::LabelStr(Cow::Borrowed("box"))) } fn node_label(&'this self, n: &ConstraintSccIndex) -> dot::LabelText<'this> { - let nodes = &self.nodes_per_scc[*n]; - dot::LabelText::LabelStr(format!("{n:?} = {nodes:?}").into()) + let nodes_str = + self.nodes_per_scc[*n].iter().map(|n| render_region_vid(*n, self.regioncx)).join(", "); + dot::LabelText::LabelStr(format!("SCC({n}) = {{{nodes_str}}}", n = n.as_usize()).into()) } } diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 599f7dd18c3ea..dd75548a15df7 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -1562,7 +1562,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // Because this free region must be in the ROOT universe, we // know it cannot contain any bound universes. - assert!(self.scc_universes[longer_fr_scc] == ty::UniverseIndex::ROOT); + assert!(self.scc_universes[longer_fr_scc].is_root()); debug_assert!(self.scc_values.placeholders_contained_in(longer_fr_scc).next().is_none()); // Only check all of the relations for the main representative of each diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index 9f0e54febe4cd..73ba5bee13b7f 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -213,7 +213,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { let scc = self.constraint_sccs.scc(vid); // Special handling of higher-ranked regions. - if self.scc_universes[scc] != ty::UniverseIndex::ROOT { + if !self.scc_universes[scc].is_root() { match self.scc_values.placeholders_contained_in(scc).enumerate().last() { // If the region contains a single placeholder then they're equal. Some((0, placeholder)) => { diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index 45e22b12a8b06..a5b33a8125d50 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -346,6 +346,11 @@ impl UniverseIndex { pub fn cannot_name(self, other: UniverseIndex) -> bool { self < other } + + /// Returns `true` if `self` is the root universe, otherwise false. + pub fn is_root(self) -> bool { + self == Self::ROOT + } } impl Default for UniverseIndex { From 31052bb8a493acbecbdd38860dc20c3c9903069a Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 6 Apr 2024 14:41:09 -0700 Subject: [PATCH 08/19] Add URL and crate_name to test cases --- tests/rustdoc/issue-56701.rs | 1 + tests/rustdoc/issue-56822.rs | 5 ++++- tests/rustdoc/issue-57180.rs | 1 + tests/rustdoc/issue-60482.rs | 1 + tests/rustdoc/issue-60726.rs | 5 ++++- tests/rustdoc/issue-61592.rs | 6 ++++-- tests/rustdoc/issue-67851-both.rs | 6 ++++-- tests/rustdoc/issue-67851-hidden.rs | 6 ++++-- tests/rustdoc/issue-67851-neither.rs | 7 +++++-- tests/rustdoc/issue-67851-private.rs | 6 ++++-- tests/rustdoc/issue-72340.rs | 2 ++ tests/rustdoc/issue-74083.rs | 5 ++++- tests/rustdoc/issue-75588.rs | 1 + tests/rustdoc/issue-76501.rs | 7 +++++-- tests/rustdoc/issue-78673.rs | 1 + tests/rustdoc/issue-78701.rs | 1 + tests/rustdoc/issue-79201.rs | 5 ++++- 17 files changed, 50 insertions(+), 16 deletions(-) diff --git a/tests/rustdoc/issue-56701.rs b/tests/rustdoc/issue-56701.rs index ba00743fcd12e..d4e94323846d7 100644 --- a/tests/rustdoc/issue-56701.rs +++ b/tests/rustdoc/issue-56701.rs @@ -1,4 +1,5 @@ // This shouldn't cause a stack overflow when rustdoc is run +// https://github.com/rust-lang/rust/issues/56701 use std::ops::Deref; use std::ops::DerefMut; diff --git a/tests/rustdoc/issue-56822.rs b/tests/rustdoc/issue-56822.rs index c9a74335702d5..315b20ddd7041 100644 --- a/tests/rustdoc/issue-56822.rs +++ b/tests/rustdoc/issue-56822.rs @@ -1,3 +1,6 @@ +// https://github.com/rust-lang/rust/issues/56822 +#![crate_name="foo"] + struct Wrapper(T); trait MyTrait { @@ -16,7 +19,7 @@ impl<'a, T> MyTrait for Inner<'a, T> { type Output = &'a T; } -// @has issue_56822/struct.Parser.html +// @has foo/struct.Parser.html // @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//h3[@class="code-header"]' \ // "impl<'a> Send for Parser<'a>" pub struct Parser<'a> { diff --git a/tests/rustdoc/issue-57180.rs b/tests/rustdoc/issue-57180.rs index aa6b775839932..264b53cbd9ada 100644 --- a/tests/rustdoc/issue-57180.rs +++ b/tests/rustdoc/issue-57180.rs @@ -1,4 +1,5 @@ //@ aux-build:issue-57180.rs +// https://github.com/rust-lang/rust/issues/57180 extern crate issue_57180; use issue_57180::Trait; diff --git a/tests/rustdoc/issue-60482.rs b/tests/rustdoc/issue-60482.rs index 0fd1daa746d41..e40af12e02258 100644 --- a/tests/rustdoc/issue-60482.rs +++ b/tests/rustdoc/issue-60482.rs @@ -1,4 +1,5 @@ // This code caused a panic in `pulldown-cmark` 0.4.1. +// https://github.com/rust-lang/rust/issues/60482 pub const BASIC_UNICODE: bool = true; diff --git a/tests/rustdoc/issue-60726.rs b/tests/rustdoc/issue-60726.rs index e337e4a4f7ad1..ea10aee58e45c 100644 --- a/tests/rustdoc/issue-60726.rs +++ b/tests/rustdoc/issue-60726.rs @@ -1,3 +1,6 @@ +// https://github.com/rust-lang/rust/issues/60726 +#![crate_name="foo"] + use std::marker::PhantomData; pub struct True; @@ -25,7 +28,7 @@ where I:InterfaceType {} -// @has issue_60726/struct.IntoIter.html +// @has foo/struct.IntoIter.html // @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//h3[@class="code-header"]' \ // "impl !Send for IntoIter" // @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//h3[@class="code-header"]' \ diff --git a/tests/rustdoc/issue-61592.rs b/tests/rustdoc/issue-61592.rs index 068310fa6a33a..d403f2cc7ab1b 100644 --- a/tests/rustdoc/issue-61592.rs +++ b/tests/rustdoc/issue-61592.rs @@ -1,14 +1,16 @@ //@ aux-build:issue-61592.rs +// https://github.com/rust-lang/rust/issues/61592 +#![crate_name="bar"] extern crate foo; -// @has issue_61592/index.html +// @has bar/index.html // @has - '//a[@href="#reexports"]' 'Re-exports' // @has - '//code' 'pub use foo::FooTrait as _;' // @!has - '//a[@href="trait._.html"]' '' pub use foo::FooTrait as _; -// @has issue_61592/index.html +// @has bar/index.html // @has - '//a[@href="#reexports"]' 'Re-exports' // @has - '//code' 'pub use foo::FooStruct as _;' // @!has - '//a[@href="struct._.html"]' '' diff --git a/tests/rustdoc/issue-67851-both.rs b/tests/rustdoc/issue-67851-both.rs index ed59652838e12..e6eb6a68ffdb9 100644 --- a/tests/rustdoc/issue-67851-both.rs +++ b/tests/rustdoc/issue-67851-both.rs @@ -1,8 +1,10 @@ //@ compile-flags: -Zunstable-options --document-private-items --document-hidden-items +// https://github.com/rust-lang/rust/issues/67851 +#![crate_name="foo"] -// @has issue_67851_both/struct.Hidden.html +// @has foo/struct.Hidden.html #[doc(hidden)] pub struct Hidden; -// @has issue_67851_both/struct.Private.html +// @has foo/struct.Private.html struct Private; diff --git a/tests/rustdoc/issue-67851-hidden.rs b/tests/rustdoc/issue-67851-hidden.rs index 6d532adc06fd8..9767f9c84f9f4 100644 --- a/tests/rustdoc/issue-67851-hidden.rs +++ b/tests/rustdoc/issue-67851-hidden.rs @@ -1,8 +1,10 @@ //@ compile-flags: -Zunstable-options --document-hidden-items +// https://github.com/rust-lang/rust/issues/67851 +#![crate_name="foo"] -// @has issue_67851_hidden/struct.Hidden.html +// @has foo/struct.Hidden.html #[doc(hidden)] pub struct Hidden; -// @!has issue_67851_hidden/struct.Private.html +// @!has foo/struct.Private.html struct Private; diff --git a/tests/rustdoc/issue-67851-neither.rs b/tests/rustdoc/issue-67851-neither.rs index 4e3cd83285388..6c6e84da43d5e 100644 --- a/tests/rustdoc/issue-67851-neither.rs +++ b/tests/rustdoc/issue-67851-neither.rs @@ -1,6 +1,9 @@ -// @!has issue_67851_neither/struct.Hidden.html +// https://github.com/rust-lang/rust/issues/67851 +#![crate_name="foo"] + +// @!has foo/struct.Hidden.html #[doc(hidden)] pub struct Hidden; -// @!has issue_67851_neither/struct.Private.html +// @!has foo/struct.Private.html struct Private; diff --git a/tests/rustdoc/issue-67851-private.rs b/tests/rustdoc/issue-67851-private.rs index ead7ddf397f8f..4aa39f5b789c1 100644 --- a/tests/rustdoc/issue-67851-private.rs +++ b/tests/rustdoc/issue-67851-private.rs @@ -1,8 +1,10 @@ //@ compile-flags: --document-private-items +// https://github.com/rust-lang/rust/issues/67851 +#![crate_name="foo"] -// @!has issue_67851_private/struct.Hidden.html +// @!has foo/struct.Hidden.html #[doc(hidden)] pub struct Hidden; -// @has issue_67851_private/struct.Private.html +// @has foo/struct.Private.html struct Private; diff --git a/tests/rustdoc/issue-72340.rs b/tests/rustdoc/issue-72340.rs index 64044cfe94720..880a308f9ab11 100644 --- a/tests/rustdoc/issue-72340.rs +++ b/tests/rustdoc/issue-72340.rs @@ -1,3 +1,5 @@ +// https://github.com/rust-lang/rust/issues/72340 + #![crate_name = "foo"] pub struct Body; diff --git a/tests/rustdoc/issue-74083.rs b/tests/rustdoc/issue-74083.rs index c7f5d7eaa5855..0bed7e2fb628c 100644 --- a/tests/rustdoc/issue-74083.rs +++ b/tests/rustdoc/issue-74083.rs @@ -1,3 +1,6 @@ +// https://github.com/rust-lang/rust/issues/74083 +#![crate_name="foo"] + use std::ops::Deref; pub struct Foo; @@ -6,7 +9,7 @@ impl Foo { pub fn foo(&mut self) {} } -// @has issue_74083/struct.Bar.html +// @has foo/struct.Bar.html // @!has - '//div[@class="sidebar-links"]/a[@href="#method.foo"]' 'foo' pub struct Bar { foo: Foo, diff --git a/tests/rustdoc/issue-75588.rs b/tests/rustdoc/issue-75588.rs index 4f790994b419b..befddf6b7889f 100644 --- a/tests/rustdoc/issue-75588.rs +++ b/tests/rustdoc/issue-75588.rs @@ -2,6 +2,7 @@ //@ aux-build:real_gimli.rs // Ensure unstably exported traits have their Implementors sections. +// https://github.com/rust-lang/rust/issues/75588 #![crate_name = "foo"] #![feature(extremely_unstable_foo)] diff --git a/tests/rustdoc/issue-76501.rs b/tests/rustdoc/issue-76501.rs index 5caea0ec99244..4a7284f98512e 100644 --- a/tests/rustdoc/issue-76501.rs +++ b/tests/rustdoc/issue-76501.rs @@ -1,4 +1,7 @@ -// @has 'issue_76501/fn.bloop.html' '//pre' 'pub const fn bloop() -> i32' +// https://github.com/rust-lang/rust/issues/76501 +#![crate_name="foo"] + +// @has 'foo/fn.bloop.html' '//pre' 'pub const fn bloop() -> i32' /// A useless function that always returns 1. pub const fn bloop() -> i32 { 1 @@ -8,7 +11,7 @@ pub const fn bloop() -> i32 { pub struct Struct {} impl Struct { - // @has 'issue_76501/struct.Struct.html' '//*[@class="method"]' \ + // @has 'foo/struct.Struct.html' '//*[@class="method"]' \ // 'pub const fn blurp() -> i32' /// A useless function that always returns 1. pub const fn blurp() -> i32 { diff --git a/tests/rustdoc/issue-78673.rs b/tests/rustdoc/issue-78673.rs index d09141c320473..d7ceef2c05772 100644 --- a/tests/rustdoc/issue-78673.rs +++ b/tests/rustdoc/issue-78673.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/78673 #![crate_name = "issue_78673"] pub trait Something {} diff --git a/tests/rustdoc/issue-78701.rs b/tests/rustdoc/issue-78701.rs index 3f1638d5ffc4e..89b7ccb52229f 100644 --- a/tests/rustdoc/issue-78701.rs +++ b/tests/rustdoc/issue-78701.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/78701 #![crate_name = "foo"] // This test ensures that if a blanket impl has the same ID as another impl, it'll diff --git a/tests/rustdoc/issue-79201.rs b/tests/rustdoc/issue-79201.rs index f95d79cd493ea..76260c4a502b4 100644 --- a/tests/rustdoc/issue-79201.rs +++ b/tests/rustdoc/issue-79201.rs @@ -1,6 +1,9 @@ +// https://github.com/rust-lang/rust/issues/79201 +#![crate_name="foo"] + #![feature(doc_cfg)] -// @has 'issue_79201/trait.Foo.html' +// @has 'foo/trait.Foo.html' // @count - '//*[@class="stab portability"]' 6 // @matches - '//*[@class="stab portability"]' 'crate feature foo-root' // @matches - '//*[@class="stab portability"]' 'crate feature foo-public-mod' From 381a0e3cb0a71cbef439be974135562e64d40f38 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 6 Apr 2024 14:41:59 -0700 Subject: [PATCH 09/19] Move ice tests to rustdoc-ui --- tests/{rustdoc => rustdoc-ui}/auxiliary/issue-73061.rs | 0 .../issue-56701.rs => rustdoc-ui/ice-blanket-impl-56701.rs} | 1 + .../ice-cross-crate-opaque-assoc-type-73061.rs} | 3 ++- 3 files changed, 3 insertions(+), 1 deletion(-) rename tests/{rustdoc => rustdoc-ui}/auxiliary/issue-73061.rs (100%) rename tests/{rustdoc/issue-56701.rs => rustdoc-ui/ice-blanket-impl-56701.rs} (98%) rename tests/{rustdoc/issue-73061-cross-crate-opaque-assoc-type.rs => rustdoc-ui/ice-cross-crate-opaque-assoc-type-73061.rs} (71%) diff --git a/tests/rustdoc/auxiliary/issue-73061.rs b/tests/rustdoc-ui/auxiliary/issue-73061.rs similarity index 100% rename from tests/rustdoc/auxiliary/issue-73061.rs rename to tests/rustdoc-ui/auxiliary/issue-73061.rs diff --git a/tests/rustdoc/issue-56701.rs b/tests/rustdoc-ui/ice-blanket-impl-56701.rs similarity index 98% rename from tests/rustdoc/issue-56701.rs rename to tests/rustdoc-ui/ice-blanket-impl-56701.rs index d4e94323846d7..13b0fc9032a8a 100644 --- a/tests/rustdoc/issue-56701.rs +++ b/tests/rustdoc-ui/ice-blanket-impl-56701.rs @@ -1,3 +1,4 @@ +//@ check-pass // This shouldn't cause a stack overflow when rustdoc is run // https://github.com/rust-lang/rust/issues/56701 diff --git a/tests/rustdoc/issue-73061-cross-crate-opaque-assoc-type.rs b/tests/rustdoc-ui/ice-cross-crate-opaque-assoc-type-73061.rs similarity index 71% rename from tests/rustdoc/issue-73061-cross-crate-opaque-assoc-type.rs rename to tests/rustdoc-ui/ice-cross-crate-opaque-assoc-type-73061.rs index e16aeac65cc56..1434bef49e0e4 100644 --- a/tests/rustdoc/issue-73061-cross-crate-opaque-assoc-type.rs +++ b/tests/rustdoc-ui/ice-cross-crate-opaque-assoc-type-73061.rs @@ -1,5 +1,6 @@ -// Regression test for ICE #73061 +// Regression test for ICE https://github.com/rust-lang/rust/issues/73061 +//@ check-pass //@ aux-build:issue-73061.rs extern crate issue_73061; From 9a577e81c38e7ba88089c68c3e37d36a9816717b Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 6 Apr 2024 14:58:34 -0700 Subject: [PATCH 10/19] rustdoc: rename `issue-\d+.rs` tests to have meaningful names --- tests/rustdoc/{issue-56822.rs => auto-trait-lifetimes-56822.rs} | 0 tests/rustdoc/{issue-78673.rs => blanket-impl-78673.rs} | 0 tests/rustdoc/{issue-76501.rs => const-fn-76501.rs} | 0 .../{issue-79201.rs => doc-cfg-inherit-from-module-79201.rs} | 0 .../{issue-67851-both.rs => doc-hidden-private-67851-both.rs} | 0 .../{issue-67851-hidden.rs => doc-hidden-private-67851-hidden.rs} | 0 ...issue-67851-neither.rs => doc-hidden-private-67851-neither.rs} | 0 ...issue-67851-private.rs => doc-hidden-private-67851-private.rs} | 0 ...licated-glob-reexport.rs => duplicated-glob-reexport-60522.rs} | 0 ...sue-74083.rs => hide-mut-methods-if-no-derefmut-impl-74083.rs} | 0 tests/rustdoc/{issue-57180.rs => ice-import-crate-57180.rs} | 0 tests/rustdoc/{issue-75588.rs => implementors-unstable-75588.rs} | 0 .../{issue-72340.rs => intra-doc-link-method-trait-impl-72340.rs} | 0 tests/rustdoc/{issue-60482.rs => markdown-60482.rs} | 0 tests/rustdoc/{issue-60726.rs => send-impl-conditional-60726.rs} | 0 .../{issue-78701.rs => sidebar-trait-impl-disambiguate-78701.rs} | 0 tests/rustdoc/{issue-61592.rs => underscore-import-61592.rs} | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename tests/rustdoc/{issue-56822.rs => auto-trait-lifetimes-56822.rs} (100%) rename tests/rustdoc/{issue-78673.rs => blanket-impl-78673.rs} (100%) rename tests/rustdoc/{issue-76501.rs => const-fn-76501.rs} (100%) rename tests/rustdoc/{issue-79201.rs => doc-cfg-inherit-from-module-79201.rs} (100%) rename tests/rustdoc/{issue-67851-both.rs => doc-hidden-private-67851-both.rs} (100%) rename tests/rustdoc/{issue-67851-hidden.rs => doc-hidden-private-67851-hidden.rs} (100%) rename tests/rustdoc/{issue-67851-neither.rs => doc-hidden-private-67851-neither.rs} (100%) rename tests/rustdoc/{issue-67851-private.rs => doc-hidden-private-67851-private.rs} (100%) rename tests/rustdoc/{issue-60522-duplicated-glob-reexport.rs => duplicated-glob-reexport-60522.rs} (100%) rename tests/rustdoc/{issue-74083.rs => hide-mut-methods-if-no-derefmut-impl-74083.rs} (100%) rename tests/rustdoc/{issue-57180.rs => ice-import-crate-57180.rs} (100%) rename tests/rustdoc/{issue-75588.rs => implementors-unstable-75588.rs} (100%) rename tests/rustdoc/{issue-72340.rs => intra-doc-link-method-trait-impl-72340.rs} (100%) rename tests/rustdoc/{issue-60482.rs => markdown-60482.rs} (100%) rename tests/rustdoc/{issue-60726.rs => send-impl-conditional-60726.rs} (100%) rename tests/rustdoc/{issue-78701.rs => sidebar-trait-impl-disambiguate-78701.rs} (100%) rename tests/rustdoc/{issue-61592.rs => underscore-import-61592.rs} (100%) diff --git a/tests/rustdoc/issue-56822.rs b/tests/rustdoc/auto-trait-lifetimes-56822.rs similarity index 100% rename from tests/rustdoc/issue-56822.rs rename to tests/rustdoc/auto-trait-lifetimes-56822.rs diff --git a/tests/rustdoc/issue-78673.rs b/tests/rustdoc/blanket-impl-78673.rs similarity index 100% rename from tests/rustdoc/issue-78673.rs rename to tests/rustdoc/blanket-impl-78673.rs diff --git a/tests/rustdoc/issue-76501.rs b/tests/rustdoc/const-fn-76501.rs similarity index 100% rename from tests/rustdoc/issue-76501.rs rename to tests/rustdoc/const-fn-76501.rs diff --git a/tests/rustdoc/issue-79201.rs b/tests/rustdoc/doc-cfg-inherit-from-module-79201.rs similarity index 100% rename from tests/rustdoc/issue-79201.rs rename to tests/rustdoc/doc-cfg-inherit-from-module-79201.rs diff --git a/tests/rustdoc/issue-67851-both.rs b/tests/rustdoc/doc-hidden-private-67851-both.rs similarity index 100% rename from tests/rustdoc/issue-67851-both.rs rename to tests/rustdoc/doc-hidden-private-67851-both.rs diff --git a/tests/rustdoc/issue-67851-hidden.rs b/tests/rustdoc/doc-hidden-private-67851-hidden.rs similarity index 100% rename from tests/rustdoc/issue-67851-hidden.rs rename to tests/rustdoc/doc-hidden-private-67851-hidden.rs diff --git a/tests/rustdoc/issue-67851-neither.rs b/tests/rustdoc/doc-hidden-private-67851-neither.rs similarity index 100% rename from tests/rustdoc/issue-67851-neither.rs rename to tests/rustdoc/doc-hidden-private-67851-neither.rs diff --git a/tests/rustdoc/issue-67851-private.rs b/tests/rustdoc/doc-hidden-private-67851-private.rs similarity index 100% rename from tests/rustdoc/issue-67851-private.rs rename to tests/rustdoc/doc-hidden-private-67851-private.rs diff --git a/tests/rustdoc/issue-60522-duplicated-glob-reexport.rs b/tests/rustdoc/duplicated-glob-reexport-60522.rs similarity index 100% rename from tests/rustdoc/issue-60522-duplicated-glob-reexport.rs rename to tests/rustdoc/duplicated-glob-reexport-60522.rs diff --git a/tests/rustdoc/issue-74083.rs b/tests/rustdoc/hide-mut-methods-if-no-derefmut-impl-74083.rs similarity index 100% rename from tests/rustdoc/issue-74083.rs rename to tests/rustdoc/hide-mut-methods-if-no-derefmut-impl-74083.rs diff --git a/tests/rustdoc/issue-57180.rs b/tests/rustdoc/ice-import-crate-57180.rs similarity index 100% rename from tests/rustdoc/issue-57180.rs rename to tests/rustdoc/ice-import-crate-57180.rs diff --git a/tests/rustdoc/issue-75588.rs b/tests/rustdoc/implementors-unstable-75588.rs similarity index 100% rename from tests/rustdoc/issue-75588.rs rename to tests/rustdoc/implementors-unstable-75588.rs diff --git a/tests/rustdoc/issue-72340.rs b/tests/rustdoc/intra-doc-link-method-trait-impl-72340.rs similarity index 100% rename from tests/rustdoc/issue-72340.rs rename to tests/rustdoc/intra-doc-link-method-trait-impl-72340.rs diff --git a/tests/rustdoc/issue-60482.rs b/tests/rustdoc/markdown-60482.rs similarity index 100% rename from tests/rustdoc/issue-60482.rs rename to tests/rustdoc/markdown-60482.rs diff --git a/tests/rustdoc/issue-60726.rs b/tests/rustdoc/send-impl-conditional-60726.rs similarity index 100% rename from tests/rustdoc/issue-60726.rs rename to tests/rustdoc/send-impl-conditional-60726.rs diff --git a/tests/rustdoc/issue-78701.rs b/tests/rustdoc/sidebar-trait-impl-disambiguate-78701.rs similarity index 100% rename from tests/rustdoc/issue-78701.rs rename to tests/rustdoc/sidebar-trait-impl-disambiguate-78701.rs diff --git a/tests/rustdoc/issue-61592.rs b/tests/rustdoc/underscore-import-61592.rs similarity index 100% rename from tests/rustdoc/issue-61592.rs rename to tests/rustdoc/underscore-import-61592.rs From ecbe327e71f71eeb069fba8919391471f18a573e Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 15 Apr 2024 13:49:50 -0700 Subject: [PATCH 11/19] rustdoc: move tests into applicable subdirectories --- tests/rustdoc/{ => inline_cross}/auxiliary/issue-57180.rs | 0 tests/rustdoc/{ => inline_cross}/ice-import-crate-57180.rs | 0 tests/rustdoc/{ => synthetic_auto}/auto-trait-lifetimes-56822.rs | 0 tests/rustdoc/{ => synthetic_auto}/send-impl-conditional-60726.rs | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename tests/rustdoc/{ => inline_cross}/auxiliary/issue-57180.rs (100%) rename tests/rustdoc/{ => inline_cross}/ice-import-crate-57180.rs (100%) rename tests/rustdoc/{ => synthetic_auto}/auto-trait-lifetimes-56822.rs (100%) rename tests/rustdoc/{ => synthetic_auto}/send-impl-conditional-60726.rs (100%) diff --git a/tests/rustdoc/auxiliary/issue-57180.rs b/tests/rustdoc/inline_cross/auxiliary/issue-57180.rs similarity index 100% rename from tests/rustdoc/auxiliary/issue-57180.rs rename to tests/rustdoc/inline_cross/auxiliary/issue-57180.rs diff --git a/tests/rustdoc/ice-import-crate-57180.rs b/tests/rustdoc/inline_cross/ice-import-crate-57180.rs similarity index 100% rename from tests/rustdoc/ice-import-crate-57180.rs rename to tests/rustdoc/inline_cross/ice-import-crate-57180.rs diff --git a/tests/rustdoc/auto-trait-lifetimes-56822.rs b/tests/rustdoc/synthetic_auto/auto-trait-lifetimes-56822.rs similarity index 100% rename from tests/rustdoc/auto-trait-lifetimes-56822.rs rename to tests/rustdoc/synthetic_auto/auto-trait-lifetimes-56822.rs diff --git a/tests/rustdoc/send-impl-conditional-60726.rs b/tests/rustdoc/synthetic_auto/send-impl-conditional-60726.rs similarity index 100% rename from tests/rustdoc/send-impl-conditional-60726.rs rename to tests/rustdoc/synthetic_auto/send-impl-conditional-60726.rs From 81bf9ae263ffbe75dc74b467b80e9ec4184d444a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 15 Apr 2024 20:08:21 -0400 Subject: [PATCH 12/19] Make thir_tree and thir_flat into hooks --- compiler/rustc_middle/src/hooks/mod.rs | 6 ++++++ compiler/rustc_middle/src/query/mod.rs | 14 -------------- compiler/rustc_mir_build/src/lib.rs | 4 ++-- compiler/rustc_mir_build/src/thir/print.rs | 11 ++++++----- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_middle/src/hooks/mod.rs b/compiler/rustc_middle/src/hooks/mod.rs index f7ce15d0a8dcb..1872f568907c8 100644 --- a/compiler/rustc_middle/src/hooks/mod.rs +++ b/compiler/rustc_middle/src/hooks/mod.rs @@ -102,4 +102,10 @@ declare_hooks! { /// turn a deserialized `DefPathHash` into its current `DefId`. /// Will fetch a DefId from a DefPathHash for a foreign crate. hook def_path_hash_to_def_id_extern(hash: DefPathHash, stable_crate_id: StableCrateId) -> DefId; + + /// Create a THIR tree for debugging. + hook thir_tree(key: LocalDefId) -> String; + + /// Create a list-like THIR representation for debugging. + hook thir_flat(key: LocalDefId) -> String; } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 394515f091f27..2bef8f1fe3da9 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -474,20 +474,6 @@ rustc_queries! { desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key) } } - /// Create a THIR tree for debugging. - query thir_tree(key: LocalDefId) -> &'tcx String { - no_hash - arena_cache - desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key) } - } - - /// Create a list-like THIR representation for debugging. - query thir_flat(key: LocalDefId) -> &'tcx String { - no_hash - arena_cache - desc { |tcx| "constructing flat THIR representation for `{}`", tcx.def_path_str(key) } - } - /// Set of all the `DefId`s in this crate that have MIR associated with /// them. This includes all the body owners, but also things like struct /// constructors. diff --git a/compiler/rustc_mir_build/src/lib.rs b/compiler/rustc_mir_build/src/lib.rs index 82fb7d1ae4af5..442f5fa7d172b 100644 --- a/compiler/rustc_mir_build/src/lib.rs +++ b/compiler/rustc_mir_build/src/lib.rs @@ -34,6 +34,6 @@ pub fn provide(providers: &mut Providers) { build::closure_saved_names_of_captured_variables; providers.check_unsafety = check_unsafety::check_unsafety; providers.thir_body = thir::cx::thir_body; - providers.thir_tree = thir::print::thir_tree; - providers.thir_flat = thir::print::thir_flat; + providers.hooks.thir_tree = thir::print::thir_tree; + providers.hooks.thir_flat = thir::print::thir_flat; } diff --git a/compiler/rustc_mir_build/src/thir/print.rs b/compiler/rustc_mir_build/src/thir/print.rs index ef15082a48138..49e48427b6555 100644 --- a/compiler/rustc_mir_build/src/thir/print.rs +++ b/compiler/rustc_mir_build/src/thir/print.rs @@ -1,10 +1,11 @@ +use rustc_middle::query::TyCtxtAt; use rustc_middle::thir::*; -use rustc_middle::ty::{self, TyCtxt}; +use rustc_middle::ty; use rustc_span::def_id::LocalDefId; use std::fmt::{self, Write}; -pub(crate) fn thir_tree(tcx: TyCtxt<'_>, owner_def: LocalDefId) -> String { - match super::cx::thir_body(tcx, owner_def) { +pub(crate) fn thir_tree(tcx: TyCtxtAt<'_>, owner_def: LocalDefId) -> String { + match super::cx::thir_body(*tcx, owner_def) { Ok((thir, _)) => { let thir = thir.steal(); let mut printer = ThirPrinter::new(&thir); @@ -15,8 +16,8 @@ pub(crate) fn thir_tree(tcx: TyCtxt<'_>, owner_def: LocalDefId) -> String { } } -pub(crate) fn thir_flat(tcx: TyCtxt<'_>, owner_def: LocalDefId) -> String { - match super::cx::thir_body(tcx, owner_def) { +pub(crate) fn thir_flat(tcx: TyCtxtAt<'_>, owner_def: LocalDefId) -> String { + match super::cx::thir_body(*tcx, owner_def) { Ok((thir, _)) => format!("{:#?}", thir.steal()), Err(_) => "error".into(), } From 8d07d90572868e0ee099600e5e7b1ea9f1458943 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 15 Apr 2024 21:27:26 -0400 Subject: [PATCH 13/19] Opaque types have no namespace --- compiler/rustc_hir/src/def.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 2662f5661ba50..37d9b2ffd6ab8 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -207,7 +207,6 @@ impl DefKind { | DefKind::Enum | DefKind::Variant | DefKind::Trait - | DefKind::OpaqueTy | DefKind::TyAlias | DefKind::ForeignTy | DefKind::TraitAlias @@ -234,7 +233,8 @@ impl DefKind { | DefKind::Use | DefKind::ForeignMod | DefKind::GlobalAsm - | DefKind::Impl { .. } => None, + | DefKind::Impl { .. } + | DefKind::OpaqueTy => None, } } From 24e9a0c41b9fcd2d6cad9098ff479ab8ca286c34 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 15 Apr 2024 19:22:19 -0700 Subject: [PATCH 14/19] Fix docs for unstable_features lint. --- src/tools/lint-docs/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tools/lint-docs/src/lib.rs b/src/tools/lint-docs/src/lib.rs index b7c8b9ed2e318..2566124a0375c 100644 --- a/src/tools/lint-docs/src/lib.rs +++ b/src/tools/lint-docs/src/lib.rs @@ -270,7 +270,6 @@ impl<'a> LintExtractor<'a> { if matches!( lint.name.as_str(), "unused_features" // broken lint - | "unstable_features" // deprecated ) { return Ok(()); } From 00838b314046fb4e1d203346465f787a69f7159e Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 15 Apr 2024 17:49:24 -0400 Subject: [PATCH 15/19] Make suggest_deref_closure_return more idiomatic/easier to understand --- .../src/diagnostics/region_errors.rs | 137 ++++++++---------- 1 file changed, 64 insertions(+), 73 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index d3b0a9a85a350..2fe75fe2a2bff 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -26,7 +26,6 @@ use rustc_middle::ty::{self, RegionVid, Ty}; use rustc_middle::ty::{Region, TyCtxt}; use rustc_span::symbol::{kw, Ident}; use rustc_span::Span; -use rustc_trait_selection::infer::type_variable::TypeVariableOrigin; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::{Obligation, ObligationCtxt}; @@ -813,7 +812,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { self.add_static_impl_trait_suggestion(&mut diag, *fr, fr_name, *outlived_fr); self.suggest_adding_lifetime_params(&mut diag, *fr, *outlived_fr); self.suggest_move_on_borrowing_closure(&mut diag); - self.suggest_deref_closure_value(&mut diag); + self.suggest_deref_closure_return(&mut diag); diag } @@ -1048,115 +1047,107 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { /// When encountering a lifetime error caused by the return type of a closure, check the /// corresponding trait bound and see if dereferencing the closure return value would satisfy /// them. If so, we produce a structured suggestion. - fn suggest_deref_closure_value(&self, diag: &mut Diag<'_>) { + fn suggest_deref_closure_return(&self, diag: &mut Diag<'_>) { let tcx = self.infcx.tcx; - let map = tcx.hir(); // Get the closure return value and type. - let body_id = map.body_owned_by(self.mir_def_id()); - let body = &map.body(body_id); - let value = &body.value.peel_blocks(); - let hir::Node::Expr(closure_expr) = tcx.hir_node_by_def_id(self.mir_def_id()) else { + let closure_def_id = self.mir_def_id(); + let hir::Node::Expr( + closure_expr @ hir::Expr { + kind: hir::ExprKind::Closure(hir::Closure { body, .. }), .. + }, + ) = tcx.hir_node_by_def_id(closure_def_id) + else { return; }; - let fn_call_id = tcx.parent_hir_id(self.mir_hir_id()); - let hir::Node::Expr(expr) = tcx.hir_node(fn_call_id) else { return }; - let def_id = map.enclosing_body_owner(fn_call_id); - let tables = tcx.typeck(def_id); - let Some(return_value_ty) = tables.node_type_opt(value.hir_id) else { return }; - let return_value_ty = self.infcx.resolve_vars_if_possible(return_value_ty); + let ty::Closure(_, args) = *tcx.type_of(closure_def_id).instantiate_identity().kind() + else { + return; + }; + let args = args.as_closure(); + + // Make sure that the parent expression is a method call. + let parent_expr_id = tcx.parent_hir_id(self.mir_hir_id()); + let hir::Node::Expr( + parent_expr @ hir::Expr { + kind: hir::ExprKind::MethodCall(_, rcvr, call_args, _), .. + }, + ) = tcx.hir_node(parent_expr_id) + else { + return; + }; + let typeck_results = tcx.typeck(self.mir_def_id()); // We don't use `ty.peel_refs()` to get the number of `*`s needed to get the root type. - let mut ty = return_value_ty; + let liberated_sig = tcx.liberate_late_bound_regions(closure_def_id.to_def_id(), args.sig()); + let mut peeled_ty = liberated_sig.output(); let mut count = 0; - while let ty::Ref(_, t, _) = ty.kind() { - ty = *t; + while let ty::Ref(_, ref_ty, _) = *peeled_ty.kind() { + peeled_ty = ref_ty; count += 1; } - if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty) { + if !self.infcx.type_is_copy_modulo_regions(self.param_env, peeled_ty) { return; } // Build a new closure where the return type is an owned value, instead of a ref. - let Some(ty::Closure(did, args)) = - tables.node_type_opt(closure_expr.hir_id).as_ref().map(|ty| ty.kind()) - else { - return; - }; - let sig = args.as_closure().sig(); let closure_sig_as_fn_ptr_ty = Ty::new_fn_ptr( tcx, - sig.map_bound(|s| { - let unsafety = hir::Unsafety::Normal; - use rustc_target::spec::abi; - tcx.mk_fn_sig( - [s.inputs()[0]], - s.output().peel_refs(), - s.c_variadic, - unsafety, - abi::Abi::Rust, - ) - }), - ); - let parent_args = GenericArgs::identity_for_item( - tcx, - tcx.typeck_root_def_id(self.mir_def_id().to_def_id()), + ty::Binder::dummy(tcx.mk_fn_sig( + liberated_sig.inputs().iter().copied(), + peeled_ty, + liberated_sig.c_variadic, + hir::Unsafety::Normal, + rustc_target::spec::abi::Abi::Rust, + )), ); - let closure_kind = args.as_closure().kind(); - let closure_kind_ty = Ty::from_closure_kind(tcx, closure_kind); - let tupled_upvars_ty = self - .infcx - .next_ty_var(TypeVariableOrigin { param_def_id: None, span: closure_expr.span }); - let closure_args = ty::ClosureArgs::new( + let closure_ty = Ty::new_closure( tcx, - ty::ClosureArgsParts { - parent_args, - closure_kind_ty, - closure_sig_as_fn_ptr_ty, - tupled_upvars_ty, - }, + closure_def_id.to_def_id(), + ty::ClosureArgs::new( + tcx, + ty::ClosureArgsParts { + parent_args: args.parent_args(), + closure_kind_ty: args.kind_ty(), + tupled_upvars_ty: args.tupled_upvars_ty(), + closure_sig_as_fn_ptr_ty, + }, + ) + .args, ); - let closure_ty = Ty::new_closure(tcx, *did, closure_args.args); - let closure_ty = tcx.erase_regions(closure_ty); - - let hir::ExprKind::MethodCall(_, rcvr, args, _) = expr.kind else { return }; - let Some(pos) = args - .iter() - .enumerate() - .find(|(_, arg)| arg.hir_id == closure_expr.hir_id) - .map(|(i, _)| i) + + let Some((closure_arg_pos, _)) = + call_args.iter().enumerate().find(|(_, arg)| arg.hir_id == closure_expr.hir_id) else { return; }; - // The found `Self` type of the method call. - let Some(possible_rcvr_ty) = tables.node_type_opt(rcvr.hir_id) else { return }; - let Some(method_def_id) = tables.type_dependent_def_id(expr.hir_id) else { return }; - // Get the type for the parameter corresponding to the argument the closure with the // lifetime error we had. - let Some(input) = tcx + let Some(method_def_id) = typeck_results.type_dependent_def_id(parent_expr.hir_id) else { + return; + }; + let Some(input_arg) = tcx .fn_sig(method_def_id) - .instantiate_identity() + .skip_binder() .inputs() .skip_binder() // Methods have a `self` arg, so `pos` is actually `+ 1` to match the method call arg. - .get(pos + 1) + .get(closure_arg_pos + 1) else { return; }; - - trace!(?input); - - let ty::Param(closure_param) = input.kind() else { return }; + // If this isn't a param, then we can't substitute a new closure. + let ty::Param(closure_param) = input_arg.kind() else { return }; // Get the arguments for the found method, only specifying that `Self` is the receiver type. + let Some(possible_rcvr_ty) = typeck_results.node_type_opt(rcvr.hir_id) else { return }; let args = GenericArgs::for_item(tcx, method_def_id, |param, _| { if param.index == 0 { possible_rcvr_ty.into() } else if param.index == closure_param.index { closure_ty.into() } else { - self.infcx.var_for_def(expr.span, param) + self.infcx.var_for_def(parent_expr.span, param) } }); @@ -1170,7 +1161,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { if ocx.select_all_or_error().is_empty() { diag.span_suggestion_verbose( - value.span.shrink_to_lo(), + tcx.hir().body(*body).value.peel_blocks().span.shrink_to_lo(), "dereference the return value", "*".repeat(count), Applicability::MachineApplicable, From c0e7659cae9413210148b60278d5c9c2571308b7 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Tue, 16 Apr 2024 15:03:58 +1000 Subject: [PATCH 16/19] Move size assertions for `mir::syntax` types into the same file A redundant size assertion for `StatementKind` was added in #122937, because the existing assertion was in a different file. This patch cleans that up, and also moves the `TerminatorKind` assertion into the same file where it belongs, to avoid the same thing happening again. --- compiler/rustc_middle/src/mir/mod.rs | 2 -- compiler/rustc_middle/src/mir/syntax.rs | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 601bfc770f4d7..ff5afbbe5d05c 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1823,9 +1823,7 @@ mod size_asserts { static_assert_size!(LocalDecl<'_>, 40); static_assert_size!(SourceScopeData<'_>, 64); static_assert_size!(Statement<'_>, 32); - static_assert_size!(StatementKind<'_>, 16); static_assert_size!(Terminator<'_>, 112); - static_assert_size!(TerminatorKind<'_>, 96); static_assert_size!(VarDebugInfo<'_>, 88); // tidy-alphabetical-end } diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index c78c225b0cdf8..9b4095740264a 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -1463,5 +1463,6 @@ mod size_asserts { static_assert_size!(PlaceElem<'_>, 24); static_assert_size!(Rvalue<'_>, 40); static_assert_size!(StatementKind<'_>, 16); + static_assert_size!(TerminatorKind<'_>, 96); // tidy-alphabetical-end } From c30e15adedba70d99a09146707814d14a93364a1 Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Tue, 16 Apr 2024 12:42:48 +0530 Subject: [PATCH 17/19] Fail candidate assembly for erroneous types Trait predicates for types which have errors may still evaluate to OK leading to downstream ICEs. Now we return a selection error for such types in candidate assembly and thereby prevent such issues --- .../error_reporting/type_err_ctxt_ext.rs | 5 +++- .../src/traits/select/candidate_assembly.rs | 8 +++++++ compiler/rustc_ty_utils/src/ty.rs | 4 ++-- tests/crashes/123154.rs | 12 ---------- tests/ui/closures/issue-78720.rs | 1 - tests/ui/closures/issue-78720.stderr | 16 ++++--------- .../ice-type-mismatch-when-copying-112824.rs | 1 - ...e-type-mismatch-when-copying-112824.stderr | 8 +------ .../ice-unsized-struct-const-eval-123154.rs | 15 ++++++++++++ ...ce-unsized-struct-const-eval-123154.stderr | 24 +++++++++++++++++++ .../issue-68830-spurious-diagnostics.rs | 1 + .../issue-68830-spurious-diagnostics.stderr | 14 +++++++++-- 12 files changed, 72 insertions(+), 37 deletions(-) delete mode 100644 tests/crashes/123154.rs create mode 100644 tests/ui/consts/const-eval/ice-unsized-struct-const-eval-123154.rs create mode 100644 tests/ui/consts/const-eval/ice-unsized-struct-const-eval-123154.stderr diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 3dc54b338017a..925fe98d29375 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -984,7 +984,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // Already reported in the query. SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(guar)) | // Already reported. - Overflow(OverflowError::Error(guar)) => return guar, + Overflow(OverflowError::Error(guar)) => { + self.set_tainted_by_errors(guar); + return guar + }, Overflow(_) => { bug!("overflow should be handled before the `report_selection_error` path"); diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 974e5ef0e166a..3ef7cc01f9021 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -87,6 +87,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } else if lang_items.sized_trait() == Some(def_id) { // Sized is never implementable by end-users, it is // always automatically computed. + + // FIXME: Consider moving this check to the top level as it + // may also be useful for predicates other than `Sized` + // Error type cannot possibly implement `Sized` (fixes #123154) + if let Err(e) = obligation.predicate.skip_binder().self_ty().error_reported() { + return Err(SelectionError::Overflow(e.into())); + } + let sized_conditions = self.sized_conditions(obligation); self.assemble_builtin_bound_candidates(sized_conditions, &mut candidates); } else if lang_items.unsize_trait() == Some(def_id) { diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index f33234122c9d3..2139b8c665bf4 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -91,8 +91,8 @@ fn adt_sized_constraint<'tcx>( let tail_ty = tcx.type_of(tail_def.did).instantiate_identity(); let constraint_ty = sized_constraint_for_ty(tcx, tail_ty)?; - if constraint_ty.references_error() { - return None; + if let Err(guar) = constraint_ty.error_reported() { + return Some(ty::EarlyBinder::bind(Ty::new_error(tcx, guar))); } // perf hack: if there is a `constraint_ty: Sized` bound, then we know diff --git a/tests/crashes/123154.rs b/tests/crashes/123154.rs deleted file mode 100644 index 510ae8adf350d..0000000000000 --- a/tests/crashes/123154.rs +++ /dev/null @@ -1,12 +0,0 @@ -//@ known-bug: #123154 -struct AA { - pub data: [&usize] -} - -impl AA { - const fn new() -> Self { } -} - -static AA = AA::new(); - -fn main() { } diff --git a/tests/ui/closures/issue-78720.rs b/tests/ui/closures/issue-78720.rs index 0c4f337ba57b8..81af030fe5568 100644 --- a/tests/ui/closures/issue-78720.rs +++ b/tests/ui/closures/issue-78720.rs @@ -1,6 +1,5 @@ fn server() -> impl { //~^ ERROR at least one trait must be specified - //~| ERROR type annotations needed ().map2(|| "") } diff --git a/tests/ui/closures/issue-78720.stderr b/tests/ui/closures/issue-78720.stderr index 2f57c7616f121..5d65c87b0fd61 100644 --- a/tests/ui/closures/issue-78720.stderr +++ b/tests/ui/closures/issue-78720.stderr @@ -5,7 +5,7 @@ LL | fn server() -> impl { | ^^^^ error[E0412]: cannot find type `F` in this scope - --> $DIR/issue-78720.rs:14:12 + --> $DIR/issue-78720.rs:13:12 | LL | _func: F, | ^ @@ -22,14 +22,8 @@ help: you might be missing a type parameter LL | struct Map2 { | +++ -error[E0282]: type annotations needed - --> $DIR/issue-78720.rs:1:16 - | -LL | fn server() -> impl { - | ^^^^ cannot infer type - error[E0308]: mismatched types - --> $DIR/issue-78720.rs:8:39 + --> $DIR/issue-78720.rs:7:39 | LL | fn map2(self, f: F) -> Map2 {} | ^^ expected `Map2`, found `()` @@ -38,7 +32,7 @@ LL | fn map2(self, f: F) -> Map2 {} found unit type `()` error[E0277]: the size for values of type `Self` cannot be known at compilation time - --> $DIR/issue-78720.rs:8:16 + --> $DIR/issue-78720.rs:7:16 | LL | fn map2(self, f: F) -> Map2 {} | ^^^^ doesn't have a size known at compile-time @@ -53,7 +47,7 @@ help: function arguments must have a statically known size, borrowed types alway LL | fn map2(&self, f: F) -> Map2 {} | + -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0277, E0282, E0308, E0412. +Some errors have detailed explanations: E0277, E0308, E0412. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.rs b/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.rs index dc9782295c136..a41a159c1fd7c 100644 --- a/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.rs +++ b/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.rs @@ -13,7 +13,6 @@ impl Opcode2 { pub fn example2(msg_type: Opcode2) -> impl FnMut(&[u8]) { move |i| match msg_type { Opcode2::OP2 => unimplemented!(), - //~^ ERROR could not evaluate constant pattern } } diff --git a/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.stderr b/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.stderr index 9442eac0cf54a..d95a8861230e0 100644 --- a/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.stderr +++ b/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.stderr @@ -17,13 +17,7 @@ help: you might be missing a type parameter LL | pub struct Opcode2(&'a S); | +++ -error: could not evaluate constant pattern - --> $DIR/ice-type-mismatch-when-copying-112824.rs:15:9 - | -LL | Opcode2::OP2 => unimplemented!(), - | ^^^^^^^^^^^^ - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0261, E0412. For more information about an error, try `rustc --explain E0261`. diff --git a/tests/ui/consts/const-eval/ice-unsized-struct-const-eval-123154.rs b/tests/ui/consts/const-eval/ice-unsized-struct-const-eval-123154.rs new file mode 100644 index 0000000000000..24a2cd19b187f --- /dev/null +++ b/tests/ui/consts/const-eval/ice-unsized-struct-const-eval-123154.rs @@ -0,0 +1,15 @@ +// Regression test for #123154 + +struct AA { + pub data: [&usize] + //~^ ERROR missing lifetime specifier +} + +impl AA { + const fn new() -> Self { } + //~^ ERROR mismatched types +} + +static ST: AA = AA::new(); + +fn main() {} diff --git a/tests/ui/consts/const-eval/ice-unsized-struct-const-eval-123154.stderr b/tests/ui/consts/const-eval/ice-unsized-struct-const-eval-123154.stderr new file mode 100644 index 0000000000000..9657e5cdda15d --- /dev/null +++ b/tests/ui/consts/const-eval/ice-unsized-struct-const-eval-123154.stderr @@ -0,0 +1,24 @@ +error[E0106]: missing lifetime specifier + --> $DIR/ice-unsized-struct-const-eval-123154.rs:4:16 + | +LL | pub data: [&usize] + | ^ expected named lifetime parameter + | +help: consider introducing a named lifetime parameter + | +LL ~ struct AA<'a> { +LL ~ pub data: [&'a usize] + | + +error[E0308]: mismatched types + --> $DIR/ice-unsized-struct-const-eval-123154.rs:9:23 + | +LL | const fn new() -> Self { } + | --- ^^^^ expected `AA`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0106, E0308. +For more information about an error, try `rustc --explain E0106`. diff --git a/tests/ui/specialization/issue-68830-spurious-diagnostics.rs b/tests/ui/specialization/issue-68830-spurious-diagnostics.rs index d11ec79833217..a7487b8aecb9c 100644 --- a/tests/ui/specialization/issue-68830-spurious-diagnostics.rs +++ b/tests/ui/specialization/issue-68830-spurious-diagnostics.rs @@ -17,6 +17,7 @@ impl MyTrait for D { } impl MyTrait for BadStruct { +//~^ ERROR: conflicting implementations of trait `MyTrait<_>` for type `BadStruct` fn foo() {} } diff --git a/tests/ui/specialization/issue-68830-spurious-diagnostics.stderr b/tests/ui/specialization/issue-68830-spurious-diagnostics.stderr index 0ecec03a023eb..13f6ae0805dad 100644 --- a/tests/ui/specialization/issue-68830-spurious-diagnostics.stderr +++ b/tests/ui/specialization/issue-68830-spurious-diagnostics.stderr @@ -4,6 +4,16 @@ error[E0412]: cannot find type `MissingType` in this scope LL | err: MissingType | ^^^^^^^^^^^ not found in this scope -error: aborting due to 1 previous error +error[E0119]: conflicting implementations of trait `MyTrait<_>` for type `BadStruct` + --> $DIR/issue-68830-spurious-diagnostics.rs:19:1 + | +LL | impl MyTrait for D { + | --------------------------- first implementation here +... +LL | impl MyTrait for BadStruct { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `BadStruct` + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0412`. +Some errors have detailed explanations: E0119, E0412. +For more information about an error, try `rustc --explain E0119`. From a5a1775c117e8238cc58b4db1ad8e731177795ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Tue, 16 Apr 2024 13:26:51 +0200 Subject: [PATCH 18/19] rustdoc: update module-level docs of `rustdoc::clean` --- src/librustdoc/clean/mod.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 925d41e67f8fa..fc4f48262e5dc 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1,5 +1,25 @@ -//! This module contains the "cleaned" pieces of the AST, and the functions -//! that clean them. +//! This module defines the primary IR[^1] used in rustdoc together with the procedures that +//! transform rustc data types into it. +//! +//! This IR — commonly referred to as the *cleaned AST* — is modeled after the [AST][ast]. +//! +//! There are two kinds of transformation — *cleaning* — procedures: +//! +//! 1. Cleans [HIR][hir] types. Used for user-written code and inlined local re-exports +//! both found in the local crate. +//! 2. Cleans [`rustc_middle::ty`] types. Used for inlined cross-crate re-exports and anything +//! output by the trait solver (e.g., when synthesizing blanket and auto-trait impls). +//! They usually have `ty` or `middle` in their name. +//! +//! Their name is prefixed by `clean_`. +//! +//! Both the HIR and the `rustc_middle::ty` IR are quite removed from the source code. +//! The cleaned AST on the other hand is closer to it which simplifies the rendering process. +//! Furthermore, operating on a single IR instead of two avoids duplicating efforts down the line. +//! +//! This IR is consumed by both the HTML and the JSON backend. +//! +//! [^1]: Intermediate representation. mod auto_trait; mod blanket_impl; From d8745f934650115821b2af5755871e9c4df408fd Mon Sep 17 00:00:00 2001 From: Hrvoje Niksic Date: Thu, 8 Feb 2024 12:25:30 +0100 Subject: [PATCH 19/19] Update usage note on OpenOptions::append() Avoid implying that concatenating data before passing it to `write()` (with or without `BufWriter`) ensures atomicity. --- library/std/src/fs.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 8a24949631c56..1293abddaf364 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -980,15 +980,21 @@ impl OpenOptions { /// Note that setting `.write(true).append(true)` has the same effect as /// setting only `.append(true)`. /// - /// For most filesystems, the operating system guarantees that all writes are - /// atomic: no writes get mangled because another process writes at the same - /// time. - /// - /// One maybe obvious note when using append-mode: make sure that all data - /// that belongs together is written to the file in one operation. This - /// can be done by concatenating strings before passing them to [`write()`], - /// or using a buffered writer (with a buffer of adequate size), - /// and calling [`flush()`] when the message is complete. + /// Append mode guarantees that writes will be positioned at the current end of file, + /// even when there are other processes or threads appending to the same file. This is + /// unlike [seek]\([SeekFrom]::[End]\(0)) followed by `write()`, which + /// has a race between seeking and writing during which another writer can write, with + /// our `write()` overwriting their data. + /// + /// Keep in mind that this does not necessarily guarantee that data appended by + /// different processes or threads does not interleave. The amount of data accepted a + /// single `write()` call depends on the operating system and file system. A + /// successful `write()` is allowed to write only part of the given data, so even if + /// you're careful to provide the whole message in a single call to `write()`, there + /// is no guarantee that it will be written out in full. If you rely on the filesystem + /// accepting the message in a single write, make sure that all data that belongs + /// together is written in one operation. This can be done by concatenating strings + /// before passing them to [`write()`]. /// /// If a file is opened with both read and append access, beware that after /// opening, and after every write, the position for reading may be set at the @@ -1003,6 +1009,9 @@ impl OpenOptions { /// [`write()`]: Write::write "io::Write::write" /// [`flush()`]: Write::flush "io::Write::flush" /// [stream_position]: Seek::stream_position "io::Seek::stream_position" + /// [seek]: Seek::seek "io::Seek::seek" + /// [Current]: SeekFrom::Current "io::SeekFrom::Current" + /// [End]: SeekFrom::End "io::SeekFrom::End" /// /// # Examples ///