From c8f73e79b33428664d8e7e98690612a6a79e3fe7 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 28 Aug 2022 10:26:59 +0100 Subject: [PATCH 01/11] fs::get_mode enable getting the data via fcntl/F_GETFL on major BSD supporting this flag. --- library/std/src/sys/unix/fs.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index f38d2fd3d704e..2c2435fd2853d 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -1260,7 +1260,14 @@ impl fmt::Debug for File { None } - #[cfg(any(target_os = "linux", target_os = "macos", target_os = "vxworks"))] + #[cfg(any( + target_os = "linux", + target_os = "macos", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd", + target_os = "vxworks" + ))] fn get_mode(fd: c_int) -> Option<(bool, bool)> { let mode = unsafe { libc::fcntl(fd, libc::F_GETFL) }; if mode == -1 { @@ -1274,7 +1281,14 @@ impl fmt::Debug for File { } } - #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "vxworks")))] + #[cfg(not(any( + target_os = "linux", + target_os = "macos", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd", + target_os = "vxworks" + )))] fn get_mode(_fd: c_int) -> Option<(bool, bool)> { // FIXME(#24570): implement this for other Unix platforms None From 585bcc69807b3730e3de11c5dbceccbab12e874d Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Tue, 20 Sep 2022 14:20:21 -0700 Subject: [PATCH 02/11] Add `ptr::Alignment` type Essentially no new code here, just exposing the previously-`pub(crate)` `ValidAlign` type under the name from the ACP. --- library/core/src/mem/mod.rs | 9 +- .../{mem/valid_align.rs => ptr/alignment.rs} | 130 +++++++++++------- library/core/src/ptr/mod.rs | 4 + 3 files changed, 90 insertions(+), 53 deletions(-) rename library/core/src/{mem/valid_align.rs => ptr/alignment.rs} (63%) diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index d2dd2941d590f..3ccab15a365cc 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -21,11 +21,10 @@ mod maybe_uninit; #[stable(feature = "maybe_uninit", since = "1.36.0")] pub use maybe_uninit::MaybeUninit; -mod valid_align; -// For now this type is left crate-local. It could potentially make sense to expose -// it publicly, as it would be a nice parameter type for methods which need to take -// alignment as a parameter, such as `Layout::padding_needed_for`. -pub(crate) use valid_align::ValidAlign; +// FIXME: This is left here for now to avoid complications around pending reverts. +// Once is fully resolved, +// this should be removed and the references in `alloc::Layout` updated. +pub(crate) use ptr::Alignment as ValidAlign; mod transmutability; #[unstable(feature = "transmutability", issue = "99571")] diff --git a/library/core/src/mem/valid_align.rs b/library/core/src/ptr/alignment.rs similarity index 63% rename from library/core/src/mem/valid_align.rs rename to library/core/src/ptr/alignment.rs index 32b2afb72b0dc..5e7628c5a187e 100644 --- a/library/core/src/mem/valid_align.rs +++ b/library/core/src/ptr/alignment.rs @@ -1,4 +1,4 @@ -use crate::convert::TryFrom; +use crate::convert::{TryFrom, TryInto}; use crate::intrinsics::assert_unsafe_precondition; use crate::num::NonZeroUsize; use crate::{cmp, fmt, hash, mem, num}; @@ -8,16 +8,43 @@ use crate::{cmp, fmt, hash, mem, num}; /// /// Note that particularly large alignments, while representable in this type, /// are likely not to be supported by actual allocators and linkers. +#[unstable(feature = "ptr_alignment_type", issue = "102070")] #[derive(Copy, Clone)] #[repr(transparent)] -pub(crate) struct ValidAlign(ValidAlignEnum); +pub struct Alignment(AlignmentEnum); -// ValidAlign is `repr(usize)`, but via extra steps. -const _: () = assert!(mem::size_of::() == mem::size_of::()); -const _: () = assert!(mem::align_of::() == mem::align_of::()); +// Alignment is `repr(usize)`, but via extra steps. +const _: () = assert!(mem::size_of::() == mem::size_of::()); +const _: () = assert!(mem::align_of::() == mem::align_of::()); -impl ValidAlign { - /// Creates a `ValidAlign` from a power-of-two `usize`. +impl Alignment { + /// Returns the alignment for a type. + /// + /// This provides the same numerical value as [`mem::align_of`], + /// but in an `Alignment` instead of a `usize. + #[unstable(feature = "ptr_alignment_type", issue = "102070")] + #[inline] + pub(crate) fn of() -> Self { + // SAFETY: rustc ensures that type alignment is always a power of two. + unsafe { Alignment::new_unchecked(mem::align_of::()) } + } + + /// Creates an `Alignment` from a `usize`, or returns `None` if it's + /// not a power of two. + /// + /// Note that `0` is not a power of two, nor a valid alignment. + #[unstable(feature = "ptr_alignment_type", issue = "102070")] + #[inline] + pub const fn new(align: usize) -> Option { + if align.is_power_of_two() { + // SAFETY: Just checked it only has one bit set + Some(unsafe { Self::new_unchecked(align) }) + } else { + None + } + } + + /// Creates an `Alignment` from a power-of-two `usize`. /// /// # Safety /// @@ -25,101 +52,108 @@ impl ValidAlign { /// /// Equivalently, it must be `1 << exp` for some `exp` in `0..usize::BITS`. /// It must *not* be zero. + #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] - pub(crate) const unsafe fn new_unchecked(align: usize) -> Self { + pub const unsafe fn new_unchecked(align: usize) -> Self { // SAFETY: Precondition passed to the caller. unsafe { assert_unsafe_precondition!((align: usize) => align.is_power_of_two()) }; // SAFETY: By precondition, this must be a power of two, and // our variants encompass all possible powers of two. - unsafe { mem::transmute::(align) } + unsafe { mem::transmute::(align) } } + /// Returns the alignment as a [`NonZeroUsize`] + #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] - pub(crate) const fn as_usize(self) -> usize { + pub const fn as_usize(self) -> usize { self.0 as usize } + /// Returns the alignment as a [`usize`] + #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] - pub(crate) const fn as_nonzero(self) -> NonZeroUsize { + pub const fn as_nonzero(self) -> NonZeroUsize { // SAFETY: All the discriminants are non-zero. unsafe { NonZeroUsize::new_unchecked(self.as_usize()) } } - /// Returns the base 2 logarithm of the alignment. + /// Returns the base-2 logarithm of the alignment. /// /// This is always exact, as `self` represents a power of two. + /// + /// # Examples + /// + /// ``` + /// #![feature(ptr_alignment_type)] + /// use std::ptr::Alignment; + /// + /// assert_eq!(Alignment::of::().log2(), 0); + /// assert_eq!(Alignment::new(1024).unwrap().log2(), 10); + /// ``` + #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] - pub(crate) fn log2(self) -> u32 { + pub fn log2(self) -> u32 { self.as_nonzero().trailing_zeros() } - - /// Returns the alignment for a type. - #[inline] - pub(crate) fn of() -> Self { - // SAFETY: rustc ensures that type alignment is always a power of two. - unsafe { ValidAlign::new_unchecked(mem::align_of::()) } - } } -impl fmt::Debug for ValidAlign { +#[unstable(feature = "ptr_alignment_type", issue = "102070")] +impl fmt::Debug for Alignment { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?} (1 << {:?})", self.as_nonzero(), self.log2()) } } -impl TryFrom for ValidAlign { +#[unstable(feature = "ptr_alignment_type", issue = "102070")] +impl TryFrom for Alignment { type Error = num::TryFromIntError; #[inline] - fn try_from(align: NonZeroUsize) -> Result { - if align.is_power_of_two() { - // SAFETY: Just checked for power-of-two - unsafe { Ok(ValidAlign::new_unchecked(align.get())) } - } else { - Err(num::TryFromIntError(())) - } + fn try_from(align: NonZeroUsize) -> Result { + align.get().try_into() } } -impl TryFrom for ValidAlign { +#[unstable(feature = "ptr_alignment_type", issue = "102070")] +impl TryFrom for Alignment { type Error = num::TryFromIntError; #[inline] - fn try_from(align: usize) -> Result { - if align.is_power_of_two() { - // SAFETY: Just checked for power-of-two - unsafe { Ok(ValidAlign::new_unchecked(align)) } - } else { - Err(num::TryFromIntError(())) - } + fn try_from(align: usize) -> Result { + Self::new(align).ok_or(num::TryFromIntError(())) } } -impl cmp::Eq for ValidAlign {} +#[unstable(feature = "ptr_alignment_type", issue = "102070")] +impl cmp::Eq for Alignment {} -impl cmp::PartialEq for ValidAlign { +#[unstable(feature = "ptr_alignment_type", issue = "102070")] +impl cmp::PartialEq for Alignment { #[inline] fn eq(&self, other: &Self) -> bool { self.as_nonzero() == other.as_nonzero() } } -impl cmp::Ord for ValidAlign { +#[unstable(feature = "ptr_alignment_type", issue = "102070")] +impl cmp::Ord for Alignment { #[inline] fn cmp(&self, other: &Self) -> cmp::Ordering { self.as_nonzero().cmp(&other.as_nonzero()) } } -impl cmp::PartialOrd for ValidAlign { +#[unstable(feature = "ptr_alignment_type", issue = "102070")] +impl cmp::PartialOrd for Alignment { #[inline] fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } -impl hash::Hash for ValidAlign { +#[unstable(feature = "ptr_alignment_type", issue = "102070")] +impl hash::Hash for Alignment { #[inline] fn hash(&self, state: &mut H) { self.as_nonzero().hash(state) @@ -127,15 +161,15 @@ impl hash::Hash for ValidAlign { } #[cfg(target_pointer_width = "16")] -type ValidAlignEnum = ValidAlignEnum16; +type AlignmentEnum = AlignmentEnum16; #[cfg(target_pointer_width = "32")] -type ValidAlignEnum = ValidAlignEnum32; +type AlignmentEnum = AlignmentEnum32; #[cfg(target_pointer_width = "64")] -type ValidAlignEnum = ValidAlignEnum64; +type AlignmentEnum = AlignmentEnum64; #[derive(Copy, Clone)] #[repr(u16)] -enum ValidAlignEnum16 { +enum AlignmentEnum16 { _Align1Shl0 = 1 << 0, _Align1Shl1 = 1 << 1, _Align1Shl2 = 1 << 2, @@ -156,7 +190,7 @@ enum ValidAlignEnum16 { #[derive(Copy, Clone)] #[repr(u32)] -enum ValidAlignEnum32 { +enum AlignmentEnum32 { _Align1Shl0 = 1 << 0, _Align1Shl1 = 1 << 1, _Align1Shl2 = 1 << 2, @@ -193,7 +227,7 @@ enum ValidAlignEnum32 { #[derive(Copy, Clone)] #[repr(u64)] -enum ValidAlignEnum64 { +enum AlignmentEnum64 { _Align1Shl0 = 1 << 0, _Align1Shl1 = 1 << 1, _Align1Shl2 = 1 << 2, diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index e976abed774b8..8f94335b4014c 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -377,6 +377,10 @@ use crate::intrinsics::{ use crate::mem::{self, MaybeUninit}; +mod alignment; +#[unstable(feature = "ptr_alignment_type", issue = "102070")] +pub use alignment::Alignment; + #[stable(feature = "rust1", since = "1.0.0")] #[doc(inline)] pub use crate::intrinsics::copy_nonoverlapping; From e2d7cdcf2badf4d8d2d89dadb65a32a2eba01aff Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Wed, 21 Sep 2022 13:43:21 -0700 Subject: [PATCH 03/11] Add `rustc_allow_const_fn_unstable` annotations to pre-existing `Layout` methods --- library/core/src/alloc/layout.rs | 3 +++ library/core/src/lib.rs | 1 + library/core/src/ptr/alignment.rs | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs index f03502429ab21..03681a16b9d2a 100644 --- a/library/core/src/alloc/layout.rs +++ b/library/core/src/alloc/layout.rs @@ -65,6 +65,7 @@ impl Layout { #[stable(feature = "alloc_layout", since = "1.28.0")] #[rustc_const_stable(feature = "const_alloc_layout_size_align", since = "1.50.0")] #[inline] + #[rustc_allow_const_fn_unstable(ptr_alignment_type)] pub const fn from_size_align(size: usize, align: usize) -> Result { if !align.is_power_of_two() { return Err(LayoutError); @@ -114,6 +115,7 @@ impl Layout { #[rustc_const_stable(feature = "const_alloc_layout_unchecked", since = "1.36.0")] #[must_use] #[inline] + #[rustc_allow_const_fn_unstable(ptr_alignment_type)] pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self { // SAFETY: the caller is required to uphold the preconditions. unsafe { Layout { size, align: ValidAlign::new_unchecked(align) } } @@ -134,6 +136,7 @@ impl Layout { #[must_use = "this returns the minimum alignment, \ without modifying the layout"] #[inline] + #[rustc_allow_const_fn_unstable(ptr_alignment_type)] pub const fn align(&self) -> usize { self.align.as_usize() } diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 5621d15c1cd6f..eeb5cb45f614f 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -148,6 +148,7 @@ #![feature(core_panic)] #![feature(duration_consts_float)] #![feature(maybe_uninit_uninit_array)] +#![feature(ptr_alignment_type)] #![feature(ptr_metadata)] #![feature(slice_ptr_get)] #![feature(slice_split_at_unchecked)] diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index 5e7628c5a187e..d0df316c77014 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -24,7 +24,7 @@ impl Alignment { /// but in an `Alignment` instead of a `usize. #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] - pub(crate) fn of() -> Self { + pub const fn of() -> Self { // SAFETY: rustc ensures that type alignment is always a power of two. unsafe { Alignment::new_unchecked(mem::align_of::()) } } @@ -53,6 +53,7 @@ impl Alignment { /// Equivalently, it must be `1 << exp` for some `exp` in `0..usize::BITS`. /// It must *not* be zero. #[unstable(feature = "ptr_alignment_type", issue = "102070")] + #[rustc_const_unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] pub const unsafe fn new_unchecked(align: usize) -> Self { // SAFETY: Precondition passed to the caller. @@ -65,6 +66,7 @@ impl Alignment { /// Returns the alignment as a [`NonZeroUsize`] #[unstable(feature = "ptr_alignment_type", issue = "102070")] + #[rustc_const_unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] pub const fn as_usize(self) -> usize { self.0 as usize From c158b7b7d03039027774b2aabcdb066c371b5d36 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Thu, 22 Sep 2022 11:50:51 -0700 Subject: [PATCH 04/11] Derive Eq/PartialEq instead of manually implementing it --- library/core/src/ptr/alignment.rs | 38 +++++++++++++++++++------------ 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index d0df316c77014..bdebf8baabe48 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -9,7 +9,7 @@ use crate::{cmp, fmt, hash, mem, num}; /// Note that particularly large alignments, while representable in this type, /// are likely not to be supported by actual allocators and linkers. #[unstable(feature = "ptr_alignment_type", issue = "102070")] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Eq, PartialEq)] #[repr(transparent)] pub struct Alignment(AlignmentEnum); @@ -17,7 +17,26 @@ pub struct Alignment(AlignmentEnum); const _: () = assert!(mem::size_of::() == mem::size_of::()); const _: () = assert!(mem::align_of::() == mem::align_of::()); +fn _alignment_can_be_structurally_matched(a: Alignment) -> bool { + matches!(a, Alignment::MIN) +} + impl Alignment { + /// The smallest possible alignment, 1. + /// + /// All addresses are always aligned at least this much. + /// + /// # Examples + /// + /// ``` + /// #![feature(ptr_alignment_type)] + /// use std::ptr::Alignment; + /// + /// assert_eq!(Alignment::MIN.as_usize(), 1); + /// ``` + #[unstable(feature = "ptr_alignment_type", issue = "102070")] + pub const MIN: Self = Self(AlignmentEnum::_Align1Shl0); + /// Returns the alignment for a type. /// /// This provides the same numerical value as [`mem::align_of`], @@ -127,17 +146,6 @@ impl TryFrom for Alignment { } } -#[unstable(feature = "ptr_alignment_type", issue = "102070")] -impl cmp::Eq for Alignment {} - -#[unstable(feature = "ptr_alignment_type", issue = "102070")] -impl cmp::PartialEq for Alignment { - #[inline] - fn eq(&self, other: &Self) -> bool { - self.as_nonzero() == other.as_nonzero() - } -} - #[unstable(feature = "ptr_alignment_type", issue = "102070")] impl cmp::Ord for Alignment { #[inline] @@ -169,7 +177,7 @@ type AlignmentEnum = AlignmentEnum32; #[cfg(target_pointer_width = "64")] type AlignmentEnum = AlignmentEnum64; -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Eq, PartialEq)] #[repr(u16)] enum AlignmentEnum16 { _Align1Shl0 = 1 << 0, @@ -190,7 +198,7 @@ enum AlignmentEnum16 { _Align1Shl15 = 1 << 15, } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Eq, PartialEq)] #[repr(u32)] enum AlignmentEnum32 { _Align1Shl0 = 1 << 0, @@ -227,7 +235,7 @@ enum AlignmentEnum32 { _Align1Shl31 = 1 << 31, } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Eq, PartialEq)] #[repr(u64)] enum AlignmentEnum64 { _Align1Shl0 = 1 << 0, From 468acca108e65101b802821bded17149dc1d86c9 Mon Sep 17 00:00:00 2001 From: Roland Strasser Date: Sat, 8 Oct 2022 01:30:13 +0200 Subject: [PATCH 05/11] rustdoc: remove hover gap in file picker --- src/librustdoc/html/static/css/rustdoc.css | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index e29abbec69c2d..ce980a5d9ed47 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1500,10 +1500,26 @@ details.dir-entry { padding-left: 4px; } +details.dir-entry > summary::after { + content: " ►"; + position: absolute; + left: -15px; + top: 0px; + font-size: 80%; + padding: 2px 0px; + /* set width to cover gap between arrow and text */ + width: 25px; +} + +details[open].dir-entry > summary::after { + content: " ▼"; +} + details.dir-entry > summary { margin: 0 0 0 13px; - list-style-position: outside; + list-style: none; cursor: pointer; + position: relative; } details.dir-entry div.folders, details.dir-entry div.files { From be1c7aad723126b2ea65543b4ceed54167b841a2 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 8 Oct 2022 14:39:25 -0700 Subject: [PATCH 06/11] Show let-else suggestion on stable. --- compiler/rustc_mir_build/src/thir/pattern/check_match.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 8fca94119c211..ec709a1db513e 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -491,7 +491,7 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> { ], Applicability::HasPlaceholders, ); - if !bindings.is_empty() && cx.tcx.sess.is_nightly_build() { + if !bindings.is_empty() { err.span_suggestion_verbose( semi_span.shrink_to_lo(), &format!( From 70f3c79c50669f99c3f14cbbba2ce03a196cd1d1 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 9 Oct 2022 07:09:57 +0000 Subject: [PATCH 07/11] ImplItemKind::TyAlias => ImplItemKind::Type --- compiler/rustc_ast_lowering/src/item.rs | 4 ++-- compiler/rustc_hir/src/hir.rs | 2 +- compiler/rustc_hir/src/intravisit.rs | 2 +- compiler/rustc_hir_analysis/src/check/check.rs | 2 +- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 2 +- compiler/rustc_hir_analysis/src/collect.rs | 2 +- compiler/rustc_hir_analysis/src/collect/generics_of.rs | 2 +- compiler/rustc_hir_analysis/src/collect/type_of.rs | 2 +- compiler/rustc_hir_analysis/src/hir_wf_check.rs | 2 +- compiler/rustc_hir_pretty/src/lib.rs | 2 +- compiler/rustc_incremental/src/persist/dirty_clean.rs | 2 +- compiler/rustc_infer/src/infer/error_reporting/mod.rs | 2 +- compiler/rustc_middle/src/hir/map/mod.rs | 4 ++-- compiler/rustc_passes/src/check_attr.rs | 2 +- compiler/rustc_passes/src/hir_stats.rs | 2 +- compiler/rustc_passes/src/reachable.rs | 4 ++-- compiler/rustc_privacy/src/lib.rs | 6 +++--- compiler/rustc_resolve/src/late/lifetimes.rs | 2 +- compiler/rustc_save_analysis/src/dump_visitor.rs | 2 +- .../rustc_trait_selection/src/traits/error_reporting/mod.rs | 2 +- compiler/rustc_trait_selection/src/traits/wf.rs | 2 +- compiler/rustc_ty_utils/src/ty.rs | 2 +- src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/tools/clippy/clippy_lints/src/missing_inline.rs | 2 +- src/tools/clippy/clippy_lints/src/types/mod.rs | 2 +- src/tools/clippy/clippy_utils/src/check_proc_macro.rs | 2 +- 27 files changed, 32 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 9a46444d82398..347e735fadfbd 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -908,11 +908,11 @@ impl<'hir> LoweringContext<'_, 'hir> { |this| match ty { None => { let ty = this.arena.alloc(this.ty(i.span, hir::TyKind::Err)); - hir::ImplItemKind::TyAlias(ty) + hir::ImplItemKind::Type(ty) } Some(ty) => { let ty = this.lower_ty(ty, &ImplTraitContext::TypeAliasesOpaqueTy); - hir::ImplItemKind::TyAlias(ty) + hir::ImplItemKind::Type(ty) } }, ) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 922ce738dbb15..098f9d5154976 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -2315,7 +2315,7 @@ pub enum ImplItemKind<'hir> { /// An associated function implementation with the given signature and body. Fn(FnSig<'hir>, BodyId), /// An associated type. - TyAlias(&'hir Ty<'hir>), + Type(&'hir Ty<'hir>), } // The name of the associated type for `Fn` return types. diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index 8777a54ba09b4..f3bde099b134f 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -979,7 +979,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt impl_item.hir_id(), ); } - ImplItemKind::TyAlias(ref ty) => { + ImplItemKind::Type(ref ty) => { visitor.visit_id(impl_item.hir_id()); visitor.visit_ty(ty); } diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 824144aeac004..8f232e493f15f 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -1067,7 +1067,7 @@ fn check_impl_items_against_trait<'tcx>( opt_trait_span, ); } - hir::ImplItemKind::TyAlias(impl_ty) => { + hir::ImplItemKind::Type(impl_ty) => { let opt_trait_span = tcx.hir().span_if_local(ty_trait_item.def_id); compare_ty_impl( tcx, diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index d607f9014200e..8721ca0143932 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -839,7 +839,7 @@ fn check_impl_item(tcx: TyCtxt<'_>, impl_item: &hir::ImplItem<'_>) { let (method_sig, span) = match impl_item.kind { hir::ImplItemKind::Fn(ref sig, _) => (Some(sig), impl_item.span), // Constrain binding and overflow error spans to `` in `type foo = `. - hir::ImplItemKind::TyAlias(ty) if ty.span != DUMMY_SP => (None, ty.span), + hir::ImplItemKind::Type(ty) if ty.span != DUMMY_SP => (None, ty.span), _ => (None, impl_item.span), }; diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index ab4b861b6cb60..6976c5a0edbdd 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -738,7 +738,7 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { hir::ImplItemKind::Fn(..) => { tcx.ensure().fn_sig(def_id); } - hir::ImplItemKind::TyAlias(_) => { + hir::ImplItemKind::Type(_) => { // Account for `type T = _;` let mut visitor = HirPlaceholderCollector::default(); visitor.visit_impl_item(impl_item); diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index 7ffacbecf5f02..707fd6c75278d 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -213,7 +213,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics { Node::TraitItem(item) if matches!(item.kind, TraitItemKind::Type(..)) => { (None, Defaults::Deny) } - Node::ImplItem(item) if matches!(item.kind, ImplItemKind::TyAlias(..)) => { + Node::ImplItem(item) if matches!(item.kind, ImplItemKind::Type(..)) => { (None, Defaults::Deny) } diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index f8a62c8491076..a3c142dbbb696 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -284,7 +284,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { icx.to_ty(ty) } } - ImplItemKind::TyAlias(ty) => { + ImplItemKind::Type(ty) => { if tcx.impl_trait_ref(tcx.hir().get_parent_item(hir_id)).is_none() { check_feature_inherent_assoc_ty(tcx, item.span); } diff --git a/compiler/rustc_hir_analysis/src/hir_wf_check.rs b/compiler/rustc_hir_analysis/src/hir_wf_check.rs index 7b080dc2942e0..7e7cc95bf3611 100644 --- a/compiler/rustc_hir_analysis/src/hir_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/hir_wf_check.rs @@ -119,7 +119,7 @@ fn diagnostic_hir_wf_check<'tcx>( let ty = match loc { WellFormedLoc::Ty(_) => match hir.get(hir_id) { hir::Node::ImplItem(item) => match item.kind { - hir::ImplItemKind::TyAlias(ty) => Some(ty), + hir::ImplItemKind::Type(ty) => Some(ty), hir::ImplItemKind::Const(ty, _) => Some(ty), ref item => bug!("Unexpected ImplItem {:?}", item), }, diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 35a58296e370e..729139adc2de8 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -887,7 +887,7 @@ impl<'a> State<'a> { self.end(); // need to close a box self.ann.nested(self, Nested::Body(body)); } - hir::ImplItemKind::TyAlias(ty) => { + hir::ImplItemKind::Type(ty) => { self.print_associated_type(ii.ident, ii.generics, None, Some(ty)); } } diff --git a/compiler/rustc_incremental/src/persist/dirty_clean.rs b/compiler/rustc_incremental/src/persist/dirty_clean.rs index 09163e4f25f3c..9c19f16a496bf 100644 --- a/compiler/rustc_incremental/src/persist/dirty_clean.rs +++ b/compiler/rustc_incremental/src/persist/dirty_clean.rs @@ -302,7 +302,7 @@ impl<'tcx> DirtyCleanVisitor<'tcx> { HirNode::ImplItem(item) => match item.kind { ImplItemKind::Fn(..) => ("Node::ImplItem", LABELS_FN_IN_IMPL), ImplItemKind::Const(..) => ("NodeImplConst", LABELS_CONST_IN_IMPL), - ImplItemKind::TyAlias(..) => ("NodeImplType", LABELS_CONST_IN_IMPL), + ImplItemKind::Type(..) => ("NodeImplType", LABELS_CONST_IN_IMPL), }, _ => self.tcx.sess.span_fatal( attr.span, diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 9d56764d48970..edbbf5ec39e30 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2570,7 +2570,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { for h in self.tcx.hir().parent_iter(param.hir_id) { break 'origin match h.1 { Node::ImplItem(hir::ImplItem { - kind: hir::ImplItemKind::TyAlias(..), + kind: hir::ImplItemKind::Type(..), generics, .. }) diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index b78c3f85596c0..302f12a6f7d44 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -241,7 +241,7 @@ impl<'hir> Map<'hir> { Node::ImplItem(item) => match item.kind { ImplItemKind::Const(..) => DefKind::AssocConst, ImplItemKind::Fn(..) => DefKind::AssocFn, - ImplItemKind::TyAlias(..) => DefKind::AssocTy, + ImplItemKind::Type(..) => DefKind::AssocTy, }, Node::Variant(_) => DefKind::Variant, Node::Ctor(variant_data) => { @@ -1244,7 +1244,7 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String { format!("assoc const {} in {}{}", ii.ident, path_str(), id_str) } ImplItemKind::Fn(..) => format!("method {} in {}{}", ii.ident, path_str(), id_str), - ImplItemKind::TyAlias(_) => { + ImplItemKind::Type(_) => { format!("assoc type {} in {}{}", ii.ident, path_str(), id_str) } }, diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 87433538512b9..5455d063c13a9 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -49,7 +49,7 @@ pub(crate) fn target_from_impl_item<'tcx>( Target::Method(MethodKind::Inherent) } } - hir::ImplItemKind::TyAlias(..) => Target::AssocTy, + hir::ImplItemKind::Type(..) => Target::AssocTy, } } diff --git a/compiler/rustc_passes/src/hir_stats.rs b/compiler/rustc_passes/src/hir_stats.rs index 0be2fc0534467..b413d78b38df9 100644 --- a/compiler/rustc_passes/src/hir_stats.rs +++ b/compiler/rustc_passes/src/hir_stats.rs @@ -391,7 +391,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) { record_variants!( (self, ii, ii.kind, Id::Node(ii.hir_id()), hir, ImplItem, ImplItemKind), - [Const, Fn, TyAlias] + [Const, Fn, Type] ); hir_visit::walk_impl_item(self, ii) } diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 16055641aca9f..0f2879c1eff2b 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -155,7 +155,7 @@ impl<'tcx> ReachableContext<'tcx> { let impl_did = self.tcx.hir().get_parent_item(hir_id); method_might_be_inlined(self.tcx, impl_item, impl_did.def_id) } - hir::ImplItemKind::TyAlias(_) => false, + hir::ImplItemKind::Type(_) => false, }, Some(_) => false, None => false, // This will happen for default methods. @@ -271,7 +271,7 @@ impl<'tcx> ReachableContext<'tcx> { self.visit_nested_body(body) } } - hir::ImplItemKind::TyAlias(_) => {} + hir::ImplItemKind::Type(_) => {} }, Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure(&hir::Closure { body, .. }), diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 841e3ebb2a13b..0983c3148f2ff 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -1574,7 +1574,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..) => { self.access_levels.is_reachable(impl_item_ref.id.def_id.def_id) } - hir::ImplItemKind::TyAlias(_) => false, + hir::ImplItemKind::Type(_) => false, } }); @@ -1596,7 +1596,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { { intravisit::walk_impl_item(self, impl_item) } - hir::ImplItemKind::TyAlias(..) => { + hir::ImplItemKind::Type(..) => { intravisit::walk_impl_item(self, impl_item) } _ => {} @@ -1622,7 +1622,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { // Those in 3. are warned with this call. for impl_item_ref in impl_.items { let impl_item = self.tcx.hir().impl_item(impl_item_ref.id); - if let hir::ImplItemKind::TyAlias(ty) = impl_item.kind { + if let hir::ImplItemKind::Type(ty) = impl_item.kind { self.visit_ty(ty); } } diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index 0c29ff364dcdf..8fa6160d4367f 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -898,7 +898,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { Fn(..) => self.visit_early_late(impl_item.hir_id(), &impl_item.generics, |this| { intravisit::walk_impl_item(this, impl_item) }), - TyAlias(ref ty) => { + Type(ref ty) => { let generics = &impl_item.generics; let lifetimes: FxIndexMap = generics .params diff --git a/compiler/rustc_save_analysis/src/dump_visitor.rs b/compiler/rustc_save_analysis/src/dump_visitor.rs index ecb09f0c4b70d..23d06d8e5163b 100644 --- a/compiler/rustc_save_analysis/src/dump_visitor.rs +++ b/compiler/rustc_save_analysis/src/dump_visitor.rs @@ -1069,7 +1069,7 @@ impl<'tcx> DumpVisitor<'tcx> { impl_item.span, ); } - hir::ImplItemKind::TyAlias(ref ty) => { + hir::ImplItemKind::Type(ref ty) => { // FIXME: uses of the assoc type should ideally point to this // 'def' and the name here should be a ref to the def in the // trait. diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 4398d71a89d42..d0c816946d412 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1639,7 +1639,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { .. }) | hir::Node::ImplItem(hir::ImplItem { - kind: hir::ImplItemKind::TyAlias(ty), + kind: hir::ImplItemKind::Type(ty), .. }), ) => Some((ty.span, format!("type mismatch resolving `{}`", predicate))), diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 5f901d6995e4b..2ef66b716f6fa 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -224,7 +224,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( }; let fix_span = |impl_item_ref: &hir::ImplItemRef| match tcx.hir().impl_item(impl_item_ref.id).kind { - hir::ImplItemKind::Const(ty, _) | hir::ImplItemKind::TyAlias(ty) => ty.span, + hir::ImplItemKind::Const(ty, _) | hir::ImplItemKind::Type(ty) => ty.span, _ => impl_item_ref.span, }; diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index f7db39dfec3b8..30efbf6617598 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -161,7 +161,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { }) => hir::Constness::Const, hir::Node::ImplItem(hir::ImplItem { - kind: hir::ImplItemKind::TyAlias(..) | hir::ImplItemKind::Fn(..), + kind: hir::ImplItemKind::Type(..) | hir::ImplItemKind::Fn(..), .. }) => { let parent_hir_id = tcx.hir().get_parent_node(hir_id); diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 7893429f26f80..432d318907fa0 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -410,7 +410,7 @@ pub(crate) fn build_impl( let assoc_kind = match item.kind { hir::ImplItemKind::Const(..) => ty::AssocKind::Const, hir::ImplItemKind::Fn(..) => ty::AssocKind::Fn, - hir::ImplItemKind::TyAlias(..) => ty::AssocKind::Type, + hir::ImplItemKind::Type(..) => ty::AssocKind::Type, }; let trait_item = tcx .associated_items(associated_trait.def_id) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c61175ecebf36..0aaa519ed027e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1066,7 +1066,7 @@ pub(crate) fn clean_impl_item<'tcx>( let defaultness = cx.tcx.impl_defaultness(impl_.def_id); MethodItem(m, Some(defaultness)) } - hir::ImplItemKind::TyAlias(hir_ty) => { + hir::ImplItemKind::Type(hir_ty) => { let type_ = clean_ty(hir_ty, cx); let generics = clean_generics(impl_.generics, cx); let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, hir_ty), cx, None); diff --git a/src/tools/clippy/clippy_lints/src/missing_inline.rs b/src/tools/clippy/clippy_lints/src/missing_inline.rs index 9d5764ac09260..ef6d1da552bfc 100644 --- a/src/tools/clippy/clippy_lints/src/missing_inline.rs +++ b/src/tools/clippy/clippy_lints/src/missing_inline.rs @@ -148,7 +148,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { let desc = match impl_item.kind { hir::ImplItemKind::Fn(..) => "a method", - hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return, + hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(_) => return, }; let assoc_item = cx.tcx.associated_item(impl_item.def_id); diff --git a/src/tools/clippy/clippy_lints/src/types/mod.rs b/src/tools/clippy/clippy_lints/src/types/mod.rs index aca55817c5250..33eee2a03784d 100644 --- a/src/tools/clippy/clippy_lints/src/types/mod.rs +++ b/src/tools/clippy/clippy_lints/src/types/mod.rs @@ -372,7 +372,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { // Methods are covered by check_fn. // Type aliases are ignored because oftentimes it's impossible to // make type alias declaration in trait simpler, see #1013 - ImplItemKind::Fn(..) | ImplItemKind::TyAlias(..) => (), + ImplItemKind::Fn(..) | ImplItemKind::Type(..) => (), } } diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index 7a8d4e8068ed6..c6bf98b7b8bbd 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -220,7 +220,7 @@ fn trait_item_search_pat(item: &TraitItem<'_>) -> (Pat, Pat) { fn impl_item_search_pat(item: &ImplItem<'_>) -> (Pat, Pat) { let (start_pat, end_pat) = match &item.kind { ImplItemKind::Const(..) => (Pat::Str("const"), Pat::Str(";")), - ImplItemKind::TyAlias(..) => (Pat::Str("type"), Pat::Str(";")), + ImplItemKind::Type(..) => (Pat::Str("type"), Pat::Str(";")), ImplItemKind::Fn(sig, ..) => (fn_header_search_pat(sig.header), Pat::Str("")), }; if item.vis_span.is_empty() { From 7dedb9192dde9fa58dcf29bf3af0859451f87194 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 9 Oct 2022 07:52:15 +0000 Subject: [PATCH 08/11] Don't use unnormalized type in Ty::fn_sig --- src/librustdoc/clean/mod.rs | 9 ++++----- src/test/rustdoc/normalize-assoc-item.rs | 13 +++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 279e762d597a0..713ce390f42dd 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1582,12 +1582,12 @@ fn normalize<'tcx>(cx: &mut DocContext<'tcx>, ty: Ty<'_>) -> Option> { } pub(crate) fn clean_middle_ty<'tcx>( - this: Ty<'tcx>, + ty: Ty<'tcx>, cx: &mut DocContext<'tcx>, def_id: Option, ) -> Type { - trace!("cleaning type: {:?}", this); - let ty = normalize(cx, this).unwrap_or(this); + trace!("cleaning type: {:?}", ty); + let ty = normalize(cx, ty).unwrap_or(ty); match *ty.kind() { ty::Never => Primitive(PrimitiveType::Never), ty::Bool => Primitive(PrimitiveType::Bool), @@ -1610,7 +1610,6 @@ pub(crate) fn clean_middle_ty<'tcx>( type_: Box::new(clean_middle_ty(ty, cx, None)), }, ty::FnDef(..) | ty::FnPtr(_) => { - let ty = cx.tcx.lift(this).expect("FnPtr lift failed"); let sig = ty.fn_sig(cx.tcx); let decl = clean_fn_decl_from_did_and_sig(cx, None, sig); BareFunction(Box::new(BareFunctionDecl { @@ -1644,7 +1643,7 @@ pub(crate) fn clean_middle_ty<'tcx>( let did = obj .principal_def_id() .or_else(|| dids.next()) - .unwrap_or_else(|| panic!("found trait object `{:?}` with no traits?", this)); + .unwrap_or_else(|| panic!("found trait object `{:?}` with no traits?", ty)); let substs = match obj.principal() { Some(principal) => principal.skip_binder().substs, // marker traits have no substs. diff --git a/src/test/rustdoc/normalize-assoc-item.rs b/src/test/rustdoc/normalize-assoc-item.rs index ad1a868ee32b8..db56f68526b3f 100644 --- a/src/test/rustdoc/normalize-assoc-item.rs +++ b/src/test/rustdoc/normalize-assoc-item.rs @@ -11,11 +11,24 @@ impl Trait for usize { type X = isize; } +impl Trait for () { + type X = fn() -> i32; +} + +impl Trait for isize { + type X = <() as Trait>::X; +} + // @has 'normalize_assoc_item/fn.f.html' '//pre[@class="rust fn"]' 'pub fn f() -> isize' pub fn f() -> ::X { 0 } +// @has 'normalize_assoc_item/fn.f2.html' '//pre[@class="rust fn"]' 'pub fn f2() -> fn() -> i32' +pub fn f2() -> ::X { + todo!() +} + pub struct S { // @has 'normalize_assoc_item/struct.S.html' '//span[@id="structfield.box_me_up"]' 'box_me_up: Box' pub box_me_up: ::X, From 7fdce6498adf1bc337f6ab259af4aa9201dbc4a5 Mon Sep 17 00:00:00 2001 From: Roland Strasser Date: Sat, 8 Oct 2022 15:26:06 +0200 Subject: [PATCH 09/11] rustdoc: fix file picker marker renders twice on ios --- src/librustdoc/html/static/css/rustdoc.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index ce980a5d9ed47..1f8088b7ee528 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1515,6 +1515,11 @@ details[open].dir-entry > summary::after { content: " ▼"; } +details.dir-entry > summary::-webkit-details-marker, +details.dir-entry > summary::marker { + display: none; +} + details.dir-entry > summary { margin: 0 0 0 13px; list-style: none; From 9a4d4d5e6b0d68fbacc41e42fc8cb4bde3c2aea7 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 9 Oct 2022 09:07:03 +0000 Subject: [PATCH 10/11] Remove unnecessary lift calls from rustdoc --- src/librustdoc/clean/mod.rs | 19 +++++-------------- src/librustdoc/clean/utils.rs | 8 ++++---- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 279e762d597a0..11e49a56f5fcf 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -22,7 +22,7 @@ use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData}; use rustc_middle::middle::resolve_lifetime as rl; use rustc_middle::ty::fold::TypeFolder; use rustc_middle::ty::InternalSubsts; -use rustc_middle::ty::{self, AdtKind, DefIdTree, EarlyBinder, Lift, Ty, TyCtxt}; +use rustc_middle::ty::{self, AdtKind, DefIdTree, EarlyBinder, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_span::hygiene::{AstPass, MacroKind}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; @@ -176,8 +176,6 @@ fn clean_poly_trait_ref_with_bindings<'tcx>( poly_trait_ref: ty::PolyTraitRef<'tcx>, bindings: ThinVec, ) -> GenericBound { - let poly_trait_ref = poly_trait_ref.lift_to_tcx(cx.tcx).unwrap(); - // collect any late bound regions let late_bound_regions: Vec<_> = cx .tcx @@ -417,8 +415,7 @@ fn clean_projection<'tcx>( cx: &mut DocContext<'tcx>, def_id: Option, ) -> Type { - let lifted = ty.lift_to_tcx(cx.tcx).unwrap(); - let trait_ = clean_trait_ref_with_bindings(cx, lifted.trait_ref(cx.tcx), ThinVec::new()); + let trait_ = clean_trait_ref_with_bindings(cx, ty.trait_ref(cx.tcx), ThinVec::new()); let self_type = clean_middle_ty(ty.self_ty(), cx, None); let self_def_id = if let Some(def_id) = def_id { cx.tcx.opt_parent(def_id).or(Some(def_id)) @@ -1552,7 +1549,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T } /// Returns `None` if the type could not be normalized -fn normalize<'tcx>(cx: &mut DocContext<'tcx>, ty: Ty<'_>) -> Option> { +fn normalize<'tcx>(cx: &mut DocContext<'tcx>, ty: Ty<'tcx>) -> Option> { // HACK: low-churn fix for #79459 while we wait for a trait normalization fix if !cx.tcx.sess.opts.unstable_opts.normalize_docs { return None; @@ -1563,11 +1560,10 @@ fn normalize<'tcx>(cx: &mut DocContext<'tcx>, ty: Ty<'_>) -> Option> { use rustc_middle::traits::ObligationCause; // Try to normalize `::T` to a type - let lifted = ty.lift_to_tcx(cx.tcx).unwrap(); let infcx = cx.tcx.infer_ctxt().build(); let normalized = infcx .at(&ObligationCause::dummy(), cx.param_env) - .normalize(lifted) + .normalize(ty) .map(|resolved| infcx.resolve_vars_if_possible(resolved.value)); match normalized { Ok(normalized_value) => { @@ -1597,8 +1593,7 @@ pub(crate) fn clean_middle_ty<'tcx>( ty::Float(float_ty) => Primitive(float_ty.into()), ty::Str => Primitive(PrimitiveType::Str), ty::Slice(ty) => Slice(Box::new(clean_middle_ty(ty, cx, None))), - ty::Array(ty, n) => { - let mut n = cx.tcx.lift(n).expect("array lift failed"); + ty::Array(ty, mut n) => { n = n.eval(cx.tcx, ty::ParamEnv::reveal_all()); let n = print_const(cx, n); Array(Box::new(clean_middle_ty(ty, cx, None)), n) @@ -1610,7 +1605,6 @@ pub(crate) fn clean_middle_ty<'tcx>( type_: Box::new(clean_middle_ty(ty, cx, None)), }, ty::FnDef(..) | ty::FnPtr(_) => { - let ty = cx.tcx.lift(this).expect("FnPtr lift failed"); let sig = ty.fn_sig(cx.tcx); let decl = clean_fn_decl_from_did_and_sig(cx, None, sig); BareFunction(Box::new(BareFunctionDecl { @@ -1668,8 +1662,6 @@ pub(crate) fn clean_middle_ty<'tcx>( .map(|pb| TypeBinding { assoc: projection_to_path_segment( pb.skip_binder() - .lift_to_tcx(cx.tcx) - .unwrap() // HACK(compiler-errors): Doesn't actually matter what self // type we put here, because we're only using the GAT's substs. .with_self_ty(cx.tcx, cx.tcx.types.self_param) @@ -1702,7 +1694,6 @@ pub(crate) fn clean_middle_ty<'tcx>( ty::Opaque(def_id, substs) => { // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`, // by looking up the bounds associated with the def_id. - let substs = cx.tcx.lift(substs).expect("Opaque lift failed"); let bounds = cx .tcx .explicit_item_bounds(def_id) diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 6b844710514a0..4572a712258ab 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -304,9 +304,9 @@ fn format_integer_with_underscore_sep(num: &str) -> String { .collect() } -fn print_const_with_custom_print_scalar( - tcx: TyCtxt<'_>, - ct: mir::ConstantKind<'_>, +fn print_const_with_custom_print_scalar<'tcx>( + tcx: TyCtxt<'tcx>, + ct: mir::ConstantKind<'tcx>, underscores_and_type: bool, ) -> String { // Use a slightly different format for integer types which always shows the actual value. @@ -320,7 +320,7 @@ fn print_const_with_custom_print_scalar( } } (mir::ConstantKind::Val(ConstValue::Scalar(int), _), ty::Int(i)) => { - let ty = tcx.lift(ct.ty()).unwrap(); + let ty = ct.ty(); let size = tcx.layout_of(ty::ParamEnv::empty().and(ty)).unwrap().size; let data = int.assert_bits(size); let sign_extended_data = size.sign_extend(data) as i128; From d47d3907037c7d7adb3e4f86f898ec42b1a7cd3a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 9 Oct 2022 12:16:02 +0200 Subject: [PATCH 11/11] remove cfg(bootstrap) from Miri --- src/tools/miri/cargo-miri/src/main.rs | 1 - src/tools/miri/src/lib.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/src/tools/miri/cargo-miri/src/main.rs b/src/tools/miri/cargo-miri/src/main.rs index c43bf0bfab11b..9b5fa7ae8736e 100644 --- a/src/tools/miri/cargo-miri/src/main.rs +++ b/src/tools/miri/cargo-miri/src/main.rs @@ -1,4 +1,3 @@ -#![cfg_attr(bootstrap, feature(let_else))] #![allow(clippy::useless_format, clippy::derive_partial_eq_without_eq, rustc::internal)] #[macro_use] diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs index 461f6e4c0f6a0..e21dca7adc1b4 100644 --- a/src/tools/miri/src/lib.rs +++ b/src/tools/miri/src/lib.rs @@ -10,7 +10,6 @@ #![feature(is_some_and)] #![feature(nonzero_ops)] #![feature(local_key_cell_methods)] -#![cfg_attr(bootstrap, feature(let_else))] // Configure clippy and other lints #![allow( clippy::collapsible_else_if,