From 4e73d90ce0f32d685f97080a784a30502b073711 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Tue, 19 Jul 2022 21:23:17 +0200 Subject: [PATCH 01/11] rustdoc-json: De-duplicate `FromWithTcx` --- src/librustdoc/json/conversions.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 2598b9b0b28c2..791553631ae6f 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -679,24 +679,18 @@ impl FromWithTcx for Variant { impl FromWithTcx for Import { fn from_tcx(import: clean::Import, tcx: TyCtxt<'_>) -> Self { use clean::ImportKind::*; - match import.kind { - Simple(s) => Import { - source: import.source.path.whole_name(), - name: s.to_string(), - id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)), - glob: false, - }, - Glob => Import { - source: import.source.path.whole_name(), - name: import - .source - .path - .last_opt() - .unwrap_or_else(|| Symbol::intern("*")) - .to_string(), - id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)), - glob: true, - }, + let (name, glob) = match import.kind { + Simple(s) => (s.to_string(), false), + Glob => ( + import.source.path.last_opt().unwrap_or_else(|| Symbol::intern("*")).to_string(), + true, + ), + }; + Import { + source: import.source.path.whole_name(), + name, + id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)), + glob, } } } From 3dfd2687455802acd66ae2c78d22be3ef387125b Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Tue, 19 Jul 2022 21:24:14 +0200 Subject: [PATCH 02/11] rustdoc-json: Add tests for re-exports of primitives --- src/test/rustdoc-json/primitive.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/rustdoc-json/primitive.rs b/src/test/rustdoc-json/primitive.rs index b84c2f7c6ac39..878a1a4a79ce7 100644 --- a/src/test/rustdoc-json/primitive.rs +++ b/src/test/rustdoc-json/primitive.rs @@ -12,3 +12,9 @@ mod usize {} // @has - "$.index[*][?(@.name=='checked_add')]" // @!is - "$.index[*][?(@.name=='checked_add')]" $local_crate_id // @!has - "$.index[*][?(@.name=='is_ascii_uppercase')]" + +// @is - "$.index[*][?(@.kind=='import' && @.inner.name=='my_i32')].inner.id" null +pub use i32 as my_i32; + +// @is - "$.index[*][?(@.kind=='import' && @.inner.name=='u32')].inner.id" null +pub use u32; From 1b6f6296e9a5d8881983c11115aa9e31ae80a512 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Tue, 19 Jul 2022 22:33:47 +0200 Subject: [PATCH 03/11] rustdoc-json: Remove doc FIXME for Import::id and explain --- src/rustdoc-json-types/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 761e94c7ebbc4..170da7655f60a 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -561,8 +561,11 @@ pub struct Import { /// May be different from the last segment of `source` when renaming imports: /// `use source as name;` pub name: String, - /// The ID of the item being imported. - pub id: Option, // FIXME is this actually ever None? + /// The ID of the item being imported. Will be `None` in case of re-exports of primitives: + /// ```rust + /// pub use i32 as my_i32; + /// ``` + pub id: Option, /// Whether this import uses a glob: `use source::*;` pub glob: bool, } From d5e9e94741fd16320f5491397645fb137195eb06 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 5 Aug 2022 16:39:06 -0400 Subject: [PATCH 04/11] add method to get the mutability of an AllocId --- compiler/rustc_const_eval/src/interpret/memory.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index ed2c4edf9dd72..75528d6140ce5 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -520,6 +520,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { /// Gives raw access to the `Allocation`, without bounds or alignment checks. /// The caller is responsible for calling the access hooks! + /// + /// You almost certainly want to use `get_ptr_alloc`/`get_ptr_alloc_mut` instead. fn get_alloc_raw( &self, id: AllocId, @@ -589,6 +591,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Ok(&self.get_alloc_raw(id)?.extra) } + /// Return the `mutability` field of the given allocation. + pub fn get_alloc_mutability<'a>(&'a self, id: AllocId) -> InterpResult<'tcx, Mutability> { + Ok(self.get_alloc_raw(id)?.mutability) + } + /// Gives raw mutable access to the `Allocation`, without bounds or alignment checks. /// The caller is responsible for calling the access hooks! /// From 54b122e9132937bb0aa3514b3d5852b68e7ddf04 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 5 Aug 2022 17:59:47 -0400 Subject: [PATCH 05/11] propagate --bless to Miri --- src/bootstrap/test.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 05403cf48c7c5..782cbd8f5ffad 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -628,6 +628,10 @@ impl Step for Miri { cargo.env("MIRI_HOST_SYSROOT", sysroot); cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler)); cargo.env("MIRI", miri); + // propagate --bless + if builder.config.cmd.bless() { + cargo.env("MIRI_BLESS", "Gesundheit"); + } cargo.arg("--").args(builder.config.cmd.test_args()); From fc83a0cb57eaad7104cc8861ba354fc76da79684 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Sun, 7 Aug 2022 04:03:28 -0700 Subject: [PATCH 06/11] Don't ICE while suggesting updating item path. When an item isn't found, we may suggest an appropriate import to `use`. Along with that, we also suggest updating the path to work with the `use`. Unfortunately, if the code in question originates from a macro, the span used to indicate which part of the path needs updating may not be suitable and cause an ICE. Since, such code is not adjustable directly by the user without modifying the macro, just skip the suggestion in such cases. --- compiler/rustc_resolve/src/diagnostics.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 8839fb1a15120..325b0458638af 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -2544,12 +2544,15 @@ fn show_candidates( Applicability::MaybeIncorrect, ); if let [first, .., last] = &path[..] { - err.span_suggestion_verbose( - first.ident.span.until(last.ident.span), - &format!("if you import `{}`, refer to it directly", last.ident), - "", - Applicability::Unspecified, - ); + let sp = first.ident.span.until(last.ident.span); + if sp.can_be_used_for_suggestions() { + err.span_suggestion_verbose( + sp, + &format!("if you import `{}`, refer to it directly", last.ident), + "", + Applicability::Unspecified, + ); + } } } else { msg.push(':'); From 926f58745eca4995c16ced841074055bfbae58cf Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Sun, 7 Aug 2022 19:30:05 +0200 Subject: [PATCH 07/11] Fix HorizonOS regression in FileTimes --- library/std/src/sys/unix/fs.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index b5cc8038ca44f..e0c74a5be560d 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -544,11 +544,11 @@ impl Default for FileTimes { fn default() -> Self { // Redox doesn't appear to support `UTIME_OMIT`, so we stub it out here, and always return // an error in `set_times`. - // ESP-IDF does not support `futimens` at all and the behavior for that OS is therefore + // ESP-IDF and HorizonOS do not support `futimens` at all and the behavior for those OS is therefore // the same as for Redox. - #[cfg(any(target_os = "redox", target_os = "espidf"))] + #[cfg(any(target_os = "redox", target_os = "espidf", target_os = "horizon"))] let omit = libc::timespec { tv_sec: 0, tv_nsec: 0 }; - #[cfg(not(any(target_os = "redox", target_os = "espidf")))] + #[cfg(not(any(target_os = "redox", target_os = "espidf", target_os = "horizon")))] let omit = libc::timespec { tv_sec: 0, tv_nsec: libc::UTIME_OMIT as _ }; Self([omit; 2]) } @@ -1079,9 +1079,9 @@ impl File { pub fn set_times(&self, times: FileTimes) -> io::Result<()> { cfg_if::cfg_if! { - if #[cfg(any(target_os = "redox", target_os = "espidf"))] { + if #[cfg(any(target_os = "redox", target_os = "espidf", target_os = "horizon"))] { // Redox doesn't appear to support `UTIME_OMIT`. - // ESP-IDF does not support `futimens` at all and the behavior for that OS is therefore + // ESP-IDF and HorizonOS do not support `futimens` at all and the behavior for those OS is therefore // the same as for Redox. drop(times); Err(io::const_io_error!( From 15b1daaca3fd4020d7a93cff14507b9104ec6d02 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Sun, 7 Aug 2022 13:55:36 -0700 Subject: [PATCH 08/11] Add UI test for #100199 --- src/test/ui/macros/auxiliary/issue-100199.rs | 18 ++++++++++++++++++ src/test/ui/macros/issue-100199.rs | 16 ++++++++++++++++ src/test/ui/macros/issue-100199.stderr | 15 +++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 src/test/ui/macros/auxiliary/issue-100199.rs create mode 100644 src/test/ui/macros/issue-100199.rs create mode 100644 src/test/ui/macros/issue-100199.stderr diff --git a/src/test/ui/macros/auxiliary/issue-100199.rs b/src/test/ui/macros/auxiliary/issue-100199.rs new file mode 100644 index 0000000000000..9e190b542db49 --- /dev/null +++ b/src/test/ui/macros/auxiliary/issue-100199.rs @@ -0,0 +1,18 @@ +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] +#![feature(proc_macro_quote)] + +extern crate proc_macro; + +use proc_macro::{quote, Ident, Span, TokenStream, TokenTree}; + +#[proc_macro_attribute] +pub fn struct_with_bound(_: TokenStream, _: TokenStream) -> TokenStream { + let crate_ident = TokenTree::Ident(Ident::new("crate", Span::call_site())); + let trait_ident = TokenTree::Ident(Ident::new("MyTrait", Span::call_site())); + quote!( + struct Foo {} + ) +} diff --git a/src/test/ui/macros/issue-100199.rs b/src/test/ui/macros/issue-100199.rs new file mode 100644 index 0000000000000..6e50afa075984 --- /dev/null +++ b/src/test/ui/macros/issue-100199.rs @@ -0,0 +1,16 @@ +#[issue_100199::struct_with_bound] //~ ERROR cannot find trait `MyTrait` in the crate root +struct Foo {} +// The above must be on the first line so that it's span points to pos 0. +// This used to trigger an ICE because the diagnostic emitter would get +// an unexpected dummy span (lo == 0 == hi) while attempting to print a +// suggestion. + +// aux-build: issue-100199.rs + +extern crate issue_100199; + +mod traits { + pub trait MyTrait {} +} + +fn main() {} diff --git a/src/test/ui/macros/issue-100199.stderr b/src/test/ui/macros/issue-100199.stderr new file mode 100644 index 0000000000000..2cb45dc12473e --- /dev/null +++ b/src/test/ui/macros/issue-100199.stderr @@ -0,0 +1,15 @@ +error[E0405]: cannot find trait `MyTrait` in the crate root + --> $DIR/issue-100199.rs:1:1 + | +LL | #[issue_100199::struct_with_bound] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in the crate root + | + = note: this error originates in the attribute macro `issue_100199::struct_with_bound` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider importing this trait + | +LL | use traits::MyTrait; + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0405`. From 1f75142c8c3383684ac7a02222f08db7a3b30ccf Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sun, 7 Aug 2022 19:11:47 -0700 Subject: [PATCH 09/11] Add some high-level docs to `FnCtxt` and `ItemCtxt` I haven't understood the difference between these before, but `@compiler-errors` helped me clear it up. Hopefully this will help other people who've been confused! --- compiler/rustc_typeck/src/check/fn_ctxt/mod.rs | 2 ++ compiler/rustc_typeck/src/collect.rs | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs index 05bcc710e1625..bfc7c4ac2889a 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs @@ -26,6 +26,8 @@ use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode}; use std::cell::{Cell, RefCell}; use std::ops::Deref; +/// The `FnCtxt` stores type-checking context needed to type-check function bodies, +/// in contrast to [`ItemCtxt`], which is used to type-check item *signatures*. pub struct FnCtxt<'a, 'tcx> { pub(super) body_id: hir::HirId, diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 99996e80c9ce9..e7bdb4a9b20c2 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -94,7 +94,12 @@ pub fn provide(providers: &mut Providers) { /////////////////////////////////////////////////////////////////////////// /// Context specific to some particular item. This is what implements -/// `AstConv`. It has information about the predicates that are defined +/// `AstConv`. +/// +/// `ItemCtxt` is primarily used to type-check item signatures, in contrast to [`FnCtxt`], +/// which is used to type-check function bodies. +/// +/// It has information about the predicates that are defined /// on the trait. Unfortunately, this predicate information is /// available in various different forms at various points in the /// process. So we can't just store a pointer to e.g., the AST or the From 2887e03411d1c9767d165a44bf478887bc694787 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sun, 7 Aug 2022 21:16:47 -0700 Subject: [PATCH 10/11] Address review comments --- .../rustc_typeck/src/check/fn_ctxt/mod.rs | 13 +++++++++-- compiler/rustc_typeck/src/collect.rs | 22 +++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs index bfc7c4ac2889a..e008d50aa514a 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs @@ -26,8 +26,17 @@ use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode}; use std::cell::{Cell, RefCell}; use std::ops::Deref; -/// The `FnCtxt` stores type-checking context needed to type-check function bodies, -/// in contrast to [`ItemCtxt`], which is used to type-check item *signatures*. +/// The `FnCtxt` stores type-checking context needed to type-check bodies of +/// functions, closures, and `const`s, including performing type inference +/// with [`InferCtxt`]. +/// +/// This is in contrast to [`ItemCtxt`], which is used to type-check item *signatures* +/// and thus does not perform type inference. +/// +/// See [`ItemCtxt`]'s docs for more. +/// +/// [`ItemCtxt`]: crate::collect::ItemCtxt +/// [`InferCtxt`]: infer::InferCtxt pub struct FnCtxt<'a, 'tcx> { pub(super) body_id: hir::HirId, diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index e7bdb4a9b20c2..b7c26455e55d6 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -94,12 +94,26 @@ pub fn provide(providers: &mut Providers) { /////////////////////////////////////////////////////////////////////////// /// Context specific to some particular item. This is what implements -/// `AstConv`. +/// [`AstConv`]. /// -/// `ItemCtxt` is primarily used to type-check item signatures, in contrast to [`FnCtxt`], -/// which is used to type-check function bodies. +/// # `ItemCtxt` vs `FnCtxt` /// -/// It has information about the predicates that are defined +/// `ItemCtxt` is primarily used to type-check item signatures and lower them +/// from HIR to their [`ty::Ty`] representation, which is exposed using [`AstConv`]. +/// It's also used for the bodies of items like structs where the body (the fields) +/// are just signatures. +/// +/// This is in contrast to [`FnCtxt`], which is used to type-check bodies of +/// functions, closures, and `const`s -- anywhere that expressions and statements show up. +/// +/// An important thing to note is that `ItemCtxt` does no inference -- it has no [`InferCtxt`] -- +/// while `FnCtxt` does do inference. +/// +/// [`FnCtxt`]: crate::check::fn_ctxt::FnCtxt +/// +/// # Trait predicates +/// +/// `ItemCtxt` has information about the predicates that are defined /// on the trait. Unfortunately, this predicate information is /// available in various different forms at various points in the /// process. So we can't just store a pointer to e.g., the AST or the From 92ce2c1dab935cae5f97774252b86d6a12bc70f5 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 8 Aug 2022 09:04:26 -0400 Subject: [PATCH 11/11] also update anyhow in codegen_cranelift --- compiler/rustc_codegen_cranelift/Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/Cargo.lock b/compiler/rustc_codegen_cranelift/Cargo.lock index 532049c858d4f..402fbb16f97ee 100644 --- a/compiler/rustc_codegen_cranelift/Cargo.lock +++ b/compiler/rustc_codegen_cranelift/Cargo.lock @@ -15,9 +15,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.56" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27" +checksum = "c794e162a5eff65c72ef524dfe393eb923c354e350bb78b9c7383df13f3bc142" [[package]] name = "ar"