From a4bff741d0bd128dc92a7e36c96af91461bd3611 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 21 Nov 2021 19:09:14 -0800 Subject: [PATCH 01/16] Test not never Currently fails to build: error[E0600]: cannot apply unary operator `!` to type `!` --> library/core/tests/ops.rs:239:8 | 239 | if !return () {} | ^^^^^^^^^^ cannot apply unary operator `!` --- library/core/tests/ops.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/core/tests/ops.rs b/library/core/tests/ops.rs index aa79dbac8f39d..0c81cba35b3df 100644 --- a/library/core/tests/ops.rs +++ b/library/core/tests/ops.rs @@ -232,3 +232,9 @@ fn deref_on_ref() { let y = deref(&mut x); assert_eq!(y, 4); } + +#[test] +#[allow(unreachable_code)] +fn test_not_never() { + if !return () {} +} From 9e834785787961646fd3951757b48d87f1afe6ef Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 21 Nov 2021 19:06:35 -0800 Subject: [PATCH 02/16] impl Not for ! --- library/core/src/ops/bit.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/library/core/src/ops/bit.rs b/library/core/src/ops/bit.rs index 255f6cb7933a2..d9ce84541cf9f 100644 --- a/library/core/src/ops/bit.rs +++ b/library/core/src/ops/bit.rs @@ -68,6 +68,17 @@ macro_rules! not_impl { not_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } +#[stable(feature = "not_never", since = "1.58.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "90080")] +impl const Not for ! { + type Output = !; + + #[inline] + fn not(self) -> ! { + match self {} + } +} + /// The bitwise AND operator `&`. /// /// Note that `Rhs` is `Self` by default, but this is not mandatory. From 881e093f6d3c68caaad64fa28a5def6d308c52cd Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 21 Nov 2021 19:30:17 -0800 Subject: [PATCH 03/16] Replace ! with * in ui test of unary expr reachability --- src/test/ui/reachable/expr_unary.rs | 4 ++-- src/test/ui/reachable/expr_unary.stderr | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/ui/reachable/expr_unary.rs b/src/test/ui/reachable/expr_unary.rs index e229d22ebc798..190c7447dccbe 100644 --- a/src/test/ui/reachable/expr_unary.rs +++ b/src/test/ui/reachable/expr_unary.rs @@ -5,8 +5,8 @@ #![deny(unreachable_code)] fn foo() { - let x: ! = ! { return; }; //~ ERROR unreachable - //~| ERROR cannot apply unary operator `!` to type `!` + let x: ! = * { return; }; //~ ERROR unreachable + //~| ERROR type `!` cannot be dereferenced } fn main() { } diff --git a/src/test/ui/reachable/expr_unary.stderr b/src/test/ui/reachable/expr_unary.stderr index 063d841c25e39..0a763087c6f13 100644 --- a/src/test/ui/reachable/expr_unary.stderr +++ b/src/test/ui/reachable/expr_unary.stderr @@ -1,13 +1,13 @@ -error[E0600]: cannot apply unary operator `!` to type `!` +error[E0614]: type `!` cannot be dereferenced --> $DIR/expr_unary.rs:8:16 | -LL | let x: ! = ! { return; }; - | ^^^^^^^^^^^^^ cannot apply unary operator `!` +LL | let x: ! = * { return; }; + | ^^^^^^^^^^^^^ error: unreachable expression --> $DIR/expr_unary.rs:8:16 | -LL | let x: ! = ! { return; }; +LL | let x: ! = * { return; }; | ^^^^------^^^ | | | | | any code following this expression is unreachable @@ -21,4 +21,4 @@ LL | #![deny(unreachable_code)] error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0600`. +For more information about this error, try `rustc --explain E0614`. From ef472f1dc93ee4c953e296e7316ead7f3de4c09f Mon Sep 17 00:00:00 2001 From: bdbai Date: Mon, 13 Dec 2021 21:41:21 +0800 Subject: [PATCH 04/16] Stabilize arc_new_cyclic --- library/alloc/src/rc.rs | 39 +++++++++++++++++++++++----------- library/alloc/src/sync.rs | 44 +++++++++++++++++++++++++++------------ 2 files changed, 58 insertions(+), 25 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 33bee4324fd38..b92fbac36d92e 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -374,32 +374,47 @@ impl Rc { } } - /// Constructs a new `Rc` using a weak reference to itself. Attempting - /// to upgrade the weak reference before this function returns will result - /// in a `None` value. However, the weak reference may be cloned freely and - /// stored for use at a later time. + /// Constructs a new `Rc` using a closure `data_fn` that has access to a + /// weak reference to the constructing `Rc`. + /// + /// Generally, a structure circularly referencing itself, either directly or + /// indirectly, should not hold a strong reference to prevent a memory leak. + /// In `data_fn`, initialization of `T` can make use of the weak reference + /// by cloning and storing it inside `T` for use at a later time. + /// + /// Since the new `Rc` is not fully-constructed until `Rc::new_cyclic` + /// returns, calling [`upgrade`] on the weak reference inside `data_fn` will + /// fail and result in a `None` value. + /// + /// # Panics + /// If `data_fn` panics, the panic is propagated to the caller, and the + /// temporary [`Weak`] is dropped normally. /// /// # Examples /// /// ``` - /// #![feature(arc_new_cyclic)] /// #![allow(dead_code)] /// use std::rc::{Rc, Weak}; /// /// struct Gadget { - /// self_weak: Weak, - /// // ... more fields + /// me: Weak, /// } + /// /// impl Gadget { - /// pub fn new() -> Rc { - /// Rc::new_cyclic(|self_weak| { - /// Gadget { self_weak: self_weak.clone(), /* ... */ } - /// }) + /// /// Construct a reference counted Gadget. + /// fn new() -> Rc { + /// Rc::new_cyclic(|me| Gadget { me: me.clone() }) + /// } + /// + /// /// Return a reference counted pointer to Self. + /// fn me(&self) -> Rc { + /// self.me.upgrade().unwrap() /// } /// } /// ``` + /// [`upgrade`]: Weak::upgrade #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "arc_new_cyclic", issue = "75861")] + #[stable(feature = "arc_new_cyclic", since = "1.59.0")] pub fn new_cyclic(data_fn: impl FnOnce(&Weak) -> T) -> Rc { // Construct the inner in the "uninitialized" state with a single // weak reference. diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 7c065f37d1fa8..4deec0146e472 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -351,29 +351,47 @@ impl Arc { unsafe { Self::from_inner(Box::leak(x).into()) } } - /// Constructs a new `Arc` using a weak reference to itself. Attempting - /// to upgrade the weak reference before this function returns will result - /// in a `None` value. However, the weak reference may be cloned freely and - /// stored for use at a later time. + /// Constructs a new `Arc` using a closure `data_fn` that has access to + /// a weak reference to the constructing `Arc`. /// - /// # Examples + /// Generally, a structure circularly referencing itself, either directly or + /// indirectly, should not hold a strong reference to prevent a memory leak. + /// In `data_fn`, initialization of `T` can make use of the weak reference + /// by cloning and storing it inside `T` for use at a later time. + /// + /// Since the new `Arc` is not fully-constructed until + /// `Arc::new_cyclic` returns, calling [`upgrade`] on the weak + /// reference inside `data_fn` will fail and result in a `None` value. + /// + /// # Panics + /// If `data_fn` panics, the panic is propagated to the caller, and the + /// temporary [`Weak`] is dropped normally. + /// + /// # Example /// ``` - /// #![feature(arc_new_cyclic)] /// #![allow(dead_code)] - /// /// use std::sync::{Arc, Weak}; /// - /// struct Foo { - /// me: Weak, + /// struct Gadget { + /// me: Weak, /// } /// - /// let foo = Arc::new_cyclic(|me| Foo { - /// me: me.clone(), - /// }); + /// impl Gadget { + /// /// Construct a reference counted Gadget. + /// fn new() -> Arc { + /// Arc::new_cyclic(|me| Gadget { me: me.clone() }) + /// } + /// + /// /// Return a reference counted pointer to Self. + /// fn me(&self) -> Arc { + /// self.me.upgrade().unwrap() + /// } + /// } /// ``` + /// [`upgrade`]: Weak::upgrade #[cfg(not(no_global_oom_handling))] #[inline] - #[unstable(feature = "arc_new_cyclic", issue = "75861")] + #[stable(feature = "arc_new_cyclic", since = "1.59.0")] pub fn new_cyclic(data_fn: impl FnOnce(&Weak) -> T) -> Arc { // Construct the inner in the "uninitialized" state with a single // weak reference. From ce31cbc7a35131d0386f03982d7cac8786f574f4 Mon Sep 17 00:00:00 2001 From: bdbai Date: Thu, 30 Dec 2021 21:55:18 +0800 Subject: [PATCH 05/16] use generic params for arc_new_cyclic --- library/alloc/src/rc.rs | 5 ++++- library/alloc/src/sync.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index b92fbac36d92e..e373be5bb6e2d 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -415,7 +415,10 @@ impl Rc { /// [`upgrade`]: Weak::upgrade #[cfg(not(no_global_oom_handling))] #[stable(feature = "arc_new_cyclic", since = "1.59.0")] - pub fn new_cyclic(data_fn: impl FnOnce(&Weak) -> T) -> Rc { + pub fn new_cyclic(data_fn: F) -> Rc + where + F: FnOnce(&Weak) -> T, + { // Construct the inner in the "uninitialized" state with a single // weak reference. let uninit_ptr: NonNull<_> = Box::leak(box RcBox { diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 4deec0146e472..aba45f36c1532 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -392,7 +392,10 @@ impl Arc { #[cfg(not(no_global_oom_handling))] #[inline] #[stable(feature = "arc_new_cyclic", since = "1.59.0")] - pub fn new_cyclic(data_fn: impl FnOnce(&Weak) -> T) -> Arc { + pub fn new_cyclic(data_fn: F) -> Arc + where + F: FnOnce(&Weak) -> T, + { // Construct the inner in the "uninitialized" state with a single // weak reference. let uninit_ptr: NonNull<_> = Box::leak(box ArcInner { From 91d80863e9bcdc4ac7bccef1492c4552af262dfb Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 13 Jan 2022 18:13:54 +0100 Subject: [PATCH 06/16] [debuginfo] Fix and unify handling of fat pointers in debuginfo. --- .../src/debuginfo/metadata.rs | 353 +++++++++--------- .../rustc_codegen_llvm/src/debuginfo/utils.rs | 59 ++- compiler/rustc_codegen_llvm/src/lib.rs | 1 + src/test/debuginfo/unsized.rs | 40 +- 4 files changed, 273 insertions(+), 180 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 3d5fd2f354e55..d29e28f4a74f2 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -10,6 +10,8 @@ use super::CrateDebugContext; use crate::abi; use crate::common::CodegenCx; +use crate::debuginfo::utils::fat_pointer_kind; +use crate::debuginfo::utils::FatPtrKind; use crate::llvm; use crate::llvm::debuginfo::{ DIArray, DICompositeType, DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType, @@ -376,22 +378,24 @@ macro_rules! return_if_metadata_created_in_meantime { }; } -fn fixed_vec_metadata<'ll, 'tcx>( +/// Creates debuginfo for a fixed size array (e.g. `[u64; 123]`). +/// For slices (that is, "arrays" of unknown size) use [slice_type_metadata]. +fn fixed_size_array_metadata<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, unique_type_id: UniqueTypeId, - array_or_slice_type: Ty<'tcx>, - element_type: Ty<'tcx>, + array_type: Ty<'tcx>, ) -> MetadataCreationResult<'ll> { + let ty::Array(element_type, len) = array_type.kind() else { + bug!("fixed_size_array_metadata() called with non-ty::Array type `{:?}`", array_type) + }; + let element_type_metadata = type_metadata(cx, element_type); return_if_metadata_created_in_meantime!(cx, unique_type_id); - let (size, align) = cx.size_and_align_of(array_or_slice_type); + let (size, align) = cx.size_and_align_of(array_type); - let upper_bound = match array_or_slice_type.kind() { - ty::Array(_, len) => len.eval_usize(cx.tcx, ty::ParamEnv::reveal_all()) as c_longlong, - _ => -1, - }; + let upper_bound = len.eval_usize(cx.tcx, ty::ParamEnv::reveal_all()) as c_longlong; let subrange = unsafe { Some(llvm::LLVMRustDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound)) }; @@ -410,55 +414,111 @@ fn fixed_vec_metadata<'ll, 'tcx>( MetadataCreationResult::new(metadata, false) } -fn vec_slice_metadata<'ll, 'tcx>( +/// Creates debuginfo for built-in pointer-like things: +/// +/// - ty::Ref +/// - ty::RawPtr +/// - ty::Adt in the case it's Box +/// +/// At some point we might want to remove the special handling of Box +/// and treat it the same as other smart pointers (like Rc, Arc, ...). +fn pointer_or_reference_metadata<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, - slice_ptr_type: Ty<'tcx>, - element_type: Ty<'tcx>, + ptr_type: Ty<'tcx>, + pointee_type: Ty<'tcx>, unique_type_id: UniqueTypeId, ) -> MetadataCreationResult<'ll> { - let data_ptr_type = cx.tcx.mk_imm_ptr(element_type); - - let data_ptr_metadata = type_metadata(cx, data_ptr_type); + let pointee_type_metadata = type_metadata(cx, pointee_type); return_if_metadata_created_in_meantime!(cx, unique_type_id); - let slice_type_name = compute_debuginfo_type_name(cx.tcx, slice_ptr_type, true); - - let (pointer_size, pointer_align) = cx.size_and_align_of(data_ptr_type); - let (usize_size, usize_align) = cx.size_and_align_of(cx.tcx.types.usize); - - let member_descriptions = vec![ - MemberDescription { - name: "data_ptr".to_owned(), - type_metadata: data_ptr_metadata, - offset: Size::ZERO, - size: pointer_size, - align: pointer_align, - flags: DIFlags::FlagZero, - discriminant: None, - source_info: None, - }, - MemberDescription { - name: "length".to_owned(), - type_metadata: type_metadata(cx, cx.tcx.types.usize), - offset: pointer_size, - size: usize_size, - align: usize_align, - flags: DIFlags::FlagZero, - discriminant: None, - source_info: None, - }, - ]; + let (thin_pointer_size, thin_pointer_align) = + cx.size_and_align_of(cx.tcx.mk_imm_ptr(cx.tcx.types.unit)); + let ptr_type_debuginfo_name = compute_debuginfo_type_name(cx.tcx, ptr_type, true); - let metadata = composite_type_metadata( - cx, - slice_ptr_type, - &slice_type_name, - unique_type_id, - member_descriptions, - NO_SCOPE_METADATA, - ); - MetadataCreationResult::new(metadata, false) + let pointer_type_metadata = match fat_pointer_kind(cx, pointee_type) { + None => { + // This is a thin pointer. Create a regular pointer type and give it the correct name. + debug_assert_eq!( + (thin_pointer_size, thin_pointer_align), + cx.size_and_align_of(ptr_type) + ); + + unsafe { + llvm::LLVMRustDIBuilderCreatePointerType( + DIB(cx), + pointee_type_metadata, + thin_pointer_size.bits(), + thin_pointer_align.bits() as u32, + 0, // Ignore DWARF address space. + ptr_type_debuginfo_name.as_ptr().cast(), + ptr_type_debuginfo_name.len(), + ) + } + } + Some(fat_pointer_kind) => { + let layout = cx.layout_of(ptr_type); + + let addr_field = layout.field(cx, abi::FAT_PTR_ADDR); + let extra_field = layout.field(cx, abi::FAT_PTR_EXTRA); + + let (addr_field_name, extra_field_name) = match fat_pointer_kind { + FatPtrKind::Dyn => ("pointer", "vtable"), + FatPtrKind::Slice => ("data_ptr", "length"), + }; + + debug_assert_eq!(abi::FAT_PTR_ADDR, 0); + debug_assert_eq!(abi::FAT_PTR_EXTRA, 1); + + // The data pointer type is a regular, thin pointer, regardless of whether this is a slice + // or a trait object. + let data_ptr_type_metadata = unsafe { + llvm::LLVMRustDIBuilderCreatePointerType( + DIB(cx), + pointee_type_metadata, + addr_field.size.bits(), + addr_field.align.abi.bits() as u32, + 0, // Ignore DWARF address space. + std::ptr::null(), + 0, + ) + }; + + let member_descriptions = vec![ + MemberDescription { + name: addr_field_name.into(), + type_metadata: data_ptr_type_metadata, + offset: layout.fields.offset(abi::FAT_PTR_ADDR), + size: addr_field.size, + align: addr_field.align.abi, + flags: DIFlags::FlagArtificial, + discriminant: None, + source_info: None, + }, + MemberDescription { + name: extra_field_name.into(), + type_metadata: type_metadata(cx, extra_field.ty), + offset: layout.fields.offset(abi::FAT_PTR_EXTRA), + size: extra_field.size, + align: extra_field.align.abi, + flags: DIFlags::FlagArtificial, + discriminant: None, + source_info: None, + }, + ]; + + composite_type_metadata( + cx, + ptr_type, + &ptr_type_debuginfo_name, + unique_type_id, + member_descriptions, + NO_SCOPE_METADATA, + ) + } + }; + + MetadataCreationResult { metadata: pointer_type_metadata, already_stored_in_typemap: false } } fn subroutine_type_metadata<'ll, 'tcx>( @@ -495,83 +555,57 @@ fn subroutine_type_metadata<'ll, 'tcx>( ) } -// FIXME(1563): This is all a bit of a hack because 'trait pointer' is an ill- -// defined concept. For the case of an actual trait pointer (i.e., `Box`, -// `&Trait`), `trait_object_type` should be the whole thing (e.g, `Box`) and -// `trait_type` should be the actual trait (e.g., `Trait`). Where the trait is part -// of a DST struct, there is no `trait_object_type` and the results of this -// function will be a little bit weird. -fn trait_pointer_metadata<'ll, 'tcx>( +// Create debuginfo for `dyn SomeTrait` types. Currently these are empty structs +// we with the correct type name (e.g. "dyn SomeTrait + Sync"). +fn dyn_type_metadata<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, - trait_type: Ty<'tcx>, - trait_object_type: Option>, + dyn_type: Ty<'tcx>, unique_type_id: UniqueTypeId, ) -> &'ll DIType { - // The implementation provided here is a stub. It makes sure that the trait - // type is assigned the correct name, size, namespace, and source location. - // However, it does not describe the trait's methods. - - let (containing_scope, trait_type_name) = match trait_object_type { - Some(trait_object_type) => match trait_object_type.kind() { - ty::Adt(def, _) => ( - Some(get_namespace_for_item(cx, def.did)), - compute_debuginfo_type_name(cx.tcx, trait_object_type, false), - ), - ty::RawPtr(_) | ty::Ref(..) => { - (NO_SCOPE_METADATA, compute_debuginfo_type_name(cx.tcx, trait_object_type, true)) - } - _ => { - bug!( - "debuginfo: unexpected trait-object type in \ - trait_pointer_metadata(): {:?}", - trait_object_type - ); - } - }, + if let ty::Dynamic(..) = dyn_type.kind() { + let type_name = compute_debuginfo_type_name(cx.tcx, dyn_type, true); + composite_type_metadata(cx, dyn_type, &type_name, unique_type_id, vec![], NO_SCOPE_METADATA) + } else { + bug!("Only ty::Dynamic is valid for dyn_type_metadata(). Found {:?} instead.", dyn_type) + } +} - // No object type, use the trait type directly (no scope here since the type - // will be wrapped in the dyn$ synthetic type). - None => (NO_SCOPE_METADATA, compute_debuginfo_type_name(cx.tcx, trait_type, true)), +// Create debuginfo for `[T]` and `str`. These are unsized. +// +// Note: We currently emit just emit the debuginfo for the element type here +// (i.e. `T` for slices and `u8` for `str`), so that we end up with +// `*const T` for the `data_ptr` field of the corresponding fat-pointer +// debuginfo of `&[T]`. +// +// It would be preferable and more accurate if we emitted a DIArray of T +// without an upper bound instead. That is, LLVM already supports emitting +// debuginfo of arrays of unknown size. But GDB currently seems to end up +// in an infinite loop when confronted with such a type. +// +// As a side effect of the current encoding every instance of a type like +// `struct Foo { unsized_field: [u8] }` will look like +// `struct Foo { unsized_field: u8 }` in debuginfo. If the length of the +// slice is zero, then accessing `unsized_field` in the debugger would +// result in an out-of-bounds access. +fn slice_type_metadata<'ll, 'tcx>( + cx: &CodegenCx<'ll, 'tcx>, + slice_type: Ty<'tcx>, + unique_type_id: UniqueTypeId, +) -> MetadataCreationResult<'ll> { + let element_type = match slice_type.kind() { + ty::Slice(element_type) => element_type, + ty::Str => cx.tcx.types.u8, + _ => { + bug!( + "Only ty::Slice is valid for slice_type_metadata(). Found {:?} instead.", + slice_type + ) + } }; - let layout = cx.layout_of(cx.tcx.mk_mut_ptr(trait_type)); - - assert_eq!(abi::FAT_PTR_ADDR, 0); - assert_eq!(abi::FAT_PTR_EXTRA, 1); - - let data_ptr_field = layout.field(cx, 0); - let vtable_field = layout.field(cx, 1); - let member_descriptions = vec![ - MemberDescription { - name: "pointer".to_owned(), - type_metadata: type_metadata(cx, cx.tcx.mk_mut_ptr(cx.tcx.types.u8)), - offset: layout.fields.offset(0), - size: data_ptr_field.size, - align: data_ptr_field.align.abi, - flags: DIFlags::FlagArtificial, - discriminant: None, - source_info: None, - }, - MemberDescription { - name: "vtable".to_owned(), - type_metadata: type_metadata(cx, vtable_field.ty), - offset: layout.fields.offset(1), - size: vtable_field.size, - align: vtable_field.align.abi, - flags: DIFlags::FlagArtificial, - discriminant: None, - source_info: None, - }, - ]; - - composite_type_metadata( - cx, - trait_object_type.unwrap_or(trait_type), - &trait_type_name, - unique_type_id, - member_descriptions, - containing_scope, - ) + let element_type_metadata = type_metadata(cx, element_type); + return_if_metadata_created_in_meantime!(cx, unique_type_id); + MetadataCreationResult { metadata: element_type_metadata, already_stored_in_typemap: false } } pub fn type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType { @@ -610,26 +644,6 @@ pub fn type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll debug!("type_metadata: {:?}", t); - let ptr_metadata = |ty: Ty<'tcx>| match *ty.kind() { - ty::Slice(typ) => Ok(vec_slice_metadata(cx, t, typ, unique_type_id)), - ty::Str => Ok(vec_slice_metadata(cx, t, cx.tcx.types.u8, unique_type_id)), - ty::Dynamic(..) => Ok(MetadataCreationResult::new( - trait_pointer_metadata(cx, ty, Some(t), unique_type_id), - false, - )), - _ => { - let pointee_metadata = type_metadata(cx, ty); - - if let Some(metadata) = - debug_context(cx).type_map.borrow().find_metadata_for_unique_id(unique_type_id) - { - return Err(metadata); - } - - Ok(MetadataCreationResult::new(pointer_type_metadata(cx, t, pointee_metadata), false)) - } - }; - let MetadataCreationResult { metadata, already_stored_in_typemap } = match *t.kind() { ty::Never | ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) => { MetadataCreationResult::new(basic_type_metadata(cx, t), false) @@ -637,22 +651,20 @@ pub fn type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll ty::Tuple(elements) if elements.is_empty() => { MetadataCreationResult::new(basic_type_metadata(cx, t), false) } - ty::Array(typ, _) | ty::Slice(typ) => fixed_vec_metadata(cx, unique_type_id, t, typ), - ty::Str => fixed_vec_metadata(cx, unique_type_id, t, cx.tcx.types.i8), + ty::Array(..) => fixed_size_array_metadata(cx, unique_type_id, t), + ty::Slice(_) | ty::Str => slice_type_metadata(cx, t, unique_type_id), ty::Dynamic(..) => { - MetadataCreationResult::new(trait_pointer_metadata(cx, t, None, unique_type_id), false) + MetadataCreationResult::new(dyn_type_metadata(cx, t, unique_type_id), false) } ty::Foreign(..) => { MetadataCreationResult::new(foreign_type_metadata(cx, t, unique_type_id), false) } - ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::Ref(_, ty, _) => match ptr_metadata(ty) { - Ok(res) => res, - Err(metadata) => return metadata, - }, - ty::Adt(def, _) if def.is_box() => match ptr_metadata(t.boxed_ty()) { - Ok(res) => res, - Err(metadata) => return metadata, - }, + ty::RawPtr(ty::TypeAndMut { ty: pointee_type, .. }) | ty::Ref(_, pointee_type, _) => { + pointer_or_reference_metadata(cx, t, pointee_type, unique_type_id) + } + ty::Adt(def, _) if def.is_box() => { + pointer_or_reference_metadata(cx, t, t.boxed_ty(), unique_type_id) + } ty::FnDef(..) | ty::FnPtr(_) => { if let Some(metadata) = debug_context(cx).type_map.borrow().find_metadata_for_unique_id(unique_type_id) @@ -694,7 +706,22 @@ pub fn type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll type_map.borrow_mut().remove_type(t); // This is actually a function pointer, so wrap it in pointer DI. - MetadataCreationResult::new(pointer_type_metadata(cx, t, fn_metadata), false) + let (pointer_size, pointer_align) = + cx.size_and_align_of(cx.tcx.mk_imm_ptr(cx.tcx.mk_unit())); + let name = compute_debuginfo_type_name(cx.tcx, t, false); + let md = unsafe { + llvm::LLVMRustDIBuilderCreatePointerType( + DIB(cx), + fn_metadata, + pointer_size.bits(), + pointer_align.bits() as u32, + 0, // Ignore DWARF address space. + name.as_ptr().cast(), + name.len(), + ) + }; + + MetadataCreationResult::new(md, false) } ty::Closure(def_id, substs) => { let upvar_tys: Vec<_> = substs.as_closure().upvar_tys().collect(); @@ -959,26 +986,6 @@ fn foreign_type_metadata<'ll, 'tcx>( create_struct_stub(cx, t, &name, unique_type_id, NO_SCOPE_METADATA, DIFlags::FlagZero) } -fn pointer_type_metadata<'ll, 'tcx>( - cx: &CodegenCx<'ll, 'tcx>, - pointer_type: Ty<'tcx>, - pointee_type_metadata: &'ll DIType, -) -> &'ll DIType { - let (pointer_size, pointer_align) = cx.size_and_align_of(pointer_type); - let name = compute_debuginfo_type_name(cx.tcx, pointer_type, false); - unsafe { - llvm::LLVMRustDIBuilderCreatePointerType( - DIB(cx), - pointee_type_metadata, - pointer_size.bits(), - pointer_align.bits() as u32, - 0, // Ignore DWARF address space. - name.as_ptr().cast(), - name.len(), - ) - } -} - fn param_type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType { debug!("param_type_metadata: {:?}", t); let name = format!("{:?}", t); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs b/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs index 953b6765a4894..6dd0d58efe328 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs @@ -4,7 +4,9 @@ use super::namespace::item_namespace; use super::CrateDebugContext; use rustc_hir::def_id::DefId; -use rustc_middle::ty::DefIdTree; +use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::{self, DefIdTree, Ty}; +use rustc_target::abi::VariantIdx; use crate::common::CodegenCx; use crate::llvm; @@ -46,3 +48,58 @@ pub fn DIB<'a, 'll>(cx: &'a CodegenCx<'ll, '_>) -> &'a DIBuilder<'ll> { pub fn get_namespace_for_item<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope { item_namespace(cx, cx.tcx.parent(def_id).expect("get_namespace_for_item: missing parent?")) } + +#[derive(Debug, PartialEq, Eq)] +pub(crate) enum FatPtrKind { + Slice, + Dyn, +} + +/// Determines if `pointee_ty` is slice-like or trait-object-like, i.e. +/// if the second field of the fat pointer is a length or a vtable-pointer. +/// If `pointee_ty` does not require a fat pointer (because it is Sized) then +/// the function returns `None`. +pub(crate) fn fat_pointer_kind<'ll, 'tcx>( + cx: &CodegenCx<'ll, 'tcx>, + pointee_ty: Ty<'tcx>, +) -> Option { + let layout = cx.layout_of(pointee_ty); + + if !layout.is_unsized() { + return None; + } + + match *pointee_ty.kind() { + ty::Str | ty::Slice(_) => Some(FatPtrKind::Slice), + ty::Dynamic(..) => Some(FatPtrKind::Dyn), + ty::Adt(adt_def, _) => { + assert!(adt_def.is_struct()); + assert!(adt_def.variants.len() == 1); + let variant = &adt_def.variants[VariantIdx::from_usize(0)]; + assert!(!variant.fields.is_empty()); + let last_field_index = variant.fields.len() - 1; + + debug_assert!( + (0..last_field_index) + .all(|field_index| { !layout.field(cx, field_index).is_unsized() }) + ); + + let unsized_field = layout.field(cx, last_field_index); + assert!(unsized_field.is_unsized()); + fat_pointer_kind(cx, unsized_field.ty) + } + ty::Foreign(_) => { + // Assert that pointers to foreign types really are thin: + debug_assert_eq!( + cx.size_of(cx.tcx.mk_imm_ptr(pointee_ty)), + cx.size_of(cx.tcx.mk_imm_ptr(cx.tcx.types.u8)) + ); + None + } + _ => { + // For all other pointee types we should already have returned None + // at the beginning of the function. + panic!("fat_pointer_kind() - Encountered unexpected `pointee_ty`: {:?}", pointee_ty) + } + } +} diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index cea4595fbbfed..1dac9c3478d7e 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -9,6 +9,7 @@ #![feature(crate_visibility_modifier)] #![feature(extern_types)] #![feature(nll)] +#![feature(let_else)] #![recursion_limit = "256"] use back::write::{create_informational_target_machine, create_target_machine}; diff --git a/src/test/debuginfo/unsized.rs b/src/test/debuginfo/unsized.rs index c27fe61dc8b47..1d1f3c0c76ece 100644 --- a/src/test/debuginfo/unsized.rs +++ b/src/test/debuginfo/unsized.rs @@ -4,13 +4,36 @@ // gdb-command:run -// gdb-command:print *a -// gdbg-check:$1 = {value = [...] "abc"} -// gdbr-check:$1 = unsized::Foo<[u8]> {value: [...]} +// gdb-command:print a +// gdbg-check:$1 = {data_ptr: [...], length: 4} +// gdbr-check:$1 = &unsized::Foo<[u8]> {data_ptr: [...], length: 4} -// gdb-command:print *b -// gdbg-check:$2 = {value = {value = [...] "abc"}} -// gdbr-check:$2 = unsized::Foo> {value: unsized::Foo<[u8]> {value: [...]}} +// gdb-command:print b +// gdbg-check:$2 = {data_ptr: [...], length: 4} +// gdbr-check:$2 = &unsized::Foo> {data_ptr: [...], length: 4} + +// gdb-command:print c +// gdbg-check:$3 = {pointer: [...], vtable: [...]} +// gdbr-check:$3 = &unsized::Foo {pointer: [...], vtable: [...]} + + +// === CDB TESTS =================================================================================== + +// cdb-command: g +// cdb-command:dx a +// cdb-check:a [Type: ref$ > >] +// cdb-check: [+0x000] data_ptr : 0x[...] [Type: unsized::Foo > *] +// cdb-check: [+0x008] length : 0x4 [Type: unsigned __int64] + +// cdb-command:dx b +// cdb-check:b [Type: ref$ > > >] +// cdb-check: [+0x000] data_ptr : 0x[...] [Type: unsized::Foo > > *] +// cdb-check: [+0x008] length : 0x4 [Type: unsigned __int64] + +// cdb-command:dx c +// cdb-check:c [Type: ref$ > >] +// cdb-check: [+0x000] pointer : 0x[...] [Type: unsized::Foo > *] +// cdb-check: [+0x008] vtable : 0x[...] [Type: unsigned __int64 (*)[3]] #![feature(omit_gdb_pretty_printer_section)] @@ -26,8 +49,13 @@ fn main() { value: *b"abc\0" } }; + + // We expect `a`, `b`, and `c` to all be fat pointers. + // `a` and `b` should be slice-like and thus have a `data_ptr` and `length` field. + // `c` should be trait-object-like and thus have a `pointer` and `vtable` field. let a: &Foo<[u8]> = &foo.value; let b: &Foo> = &foo; + let c: &Foo = &Foo { value: 7i32 }; zzz(); // #break } From 756a70cdae7ac53551cb5d9648443044785f74b9 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Mon, 17 Jan 2022 17:31:13 +0100 Subject: [PATCH 07/16] Fix vec-slices debuginfo test for GDB. --- src/test/debuginfo/vec-slices.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/test/debuginfo/vec-slices.rs b/src/test/debuginfo/vec-slices.rs index e109b1bf2aeae..3525e8d83b8e2 100644 --- a/src/test/debuginfo/vec-slices.rs +++ b/src/test/debuginfo/vec-slices.rs @@ -1,5 +1,4 @@ // ignore-windows -// ignore-gdb // Test temporarily ignored due to debuginfo tests being disabled, see PR 47155 // min-lldb-version: 310 // compile-flags:-g @@ -13,21 +12,21 @@ // gdb-command:print singleton.length // gdb-check:$2 = 1 // gdbg-command:print *((i64[1]*)(singleton.data_ptr)) -// gdbr-command:print *(singleton.data_ptr as &[i64; 1]) +// gdbr-command:print *(singleton.data_ptr as *const [i64; 1]) // gdbg-check:$3 = {1} // gdbr-check:$3 = [1] // gdb-command:print multiple.length // gdb-check:$4 = 4 // gdbg-command:print *((i64[4]*)(multiple.data_ptr)) -// gdbr-command:print *(multiple.data_ptr as &[i64; 4]) +// gdbr-command:print *(multiple.data_ptr as *const [i64; 4]) // gdbg-check:$5 = {2, 3, 4, 5} // gdbr-check:$5 = [2, 3, 4, 5] // gdb-command:print slice_of_slice.length // gdb-check:$6 = 2 // gdbg-command:print *((i64[2]*)(slice_of_slice.data_ptr)) -// gdbr-command:print *(slice_of_slice.data_ptr as &[i64; 2]) +// gdbr-command:print *(slice_of_slice.data_ptr as *const [i64; 2]) // gdbg-check:$7 = {3, 4} // gdbr-check:$7 = [3, 4] @@ -53,16 +52,16 @@ // gdbr-command:print MUT_VECT_SLICE.length // gdb-check:$14 = 2 // gdbg-command:print *((i64[2]*)('vec_slices::MUT_VECT_SLICE'.data_ptr)) -// gdbr-command:print *(MUT_VECT_SLICE.data_ptr as &[i64; 2]) +// gdbr-command:print *(MUT_VECT_SLICE.data_ptr as *const [i64; 2]) // gdbg-check:$15 = {64, 65} // gdbr-check:$15 = [64, 65] -//gdb-command:print mut_slice.length -//gdb-check:$16 = 5 -//gdbg-command:print *((i64[5]*)(mut_slice.data_ptr)) -//gdbr-command:print *(mut_slice.data_ptr as &[i64; 5]) -//gdbg-check:$17 = {1, 2, 3, 4, 5} -//gdbr-check:$17 = [1, 2, 3, 4, 5] +// gdb-command:print mut_slice.length +// gdb-check:$16 = 5 +// gdbg-command:print *((i64[5]*)(mut_slice.data_ptr)) +// gdbr-command:print *(mut_slice.data_ptr as *const [i64; 5]) +// gdbg-check:$17 = {1, 2, 3, 4, 5} +// gdbr-check:$17 = [1, 2, 3, 4, 5] // === LLDB TESTS ================================================================================== From 7356e28abbd56ff600dff1d34553b5bebcfc8767 Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Thu, 20 Jan 2022 04:09:46 +0000 Subject: [PATCH 08/16] Tweak `expr.await` desugaring `Span` Fix #93074 --- compiler/rustc_ast_lowering/src/expr.rs | 20 +++++++++---------- .../proper-span-for-type-error.fixed | 11 ++++++++++ .../async-await/proper-span-for-type-error.rs | 11 ++++++++++ .../proper-span-for-type-error.stderr | 16 +++++++++++++++ 4 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 src/test/ui/async-await/proper-span-for-type-error.fixed create mode 100644 src/test/ui/async-await/proper-span-for-type-error.rs create mode 100644 src/test/ui/async-await/proper-span-for-type-error.stderr diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 6c172d59f837b..9c3945efe502d 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -630,18 +630,18 @@ impl<'hir> LoweringContext<'_, 'hir> { /// } /// } /// ``` - fn lower_expr_await(&mut self, await_span: Span, expr: &Expr) -> hir::ExprKind<'hir> { - let dot_await_span = expr.span.shrink_to_hi().to(await_span); + fn lower_expr_await(&mut self, dot_await_span: Span, expr: &Expr) -> hir::ExprKind<'hir> { + let full_span = expr.span.to(dot_await_span); match self.generator_kind { Some(hir::GeneratorKind::Async(_)) => {} Some(hir::GeneratorKind::Gen) | None => { let mut err = struct_span_err!( self.sess, - await_span, + dot_await_span, E0728, "`await` is only allowed inside `async` functions and blocks" ); - err.span_label(await_span, "only allowed inside `async` functions and blocks"); + err.span_label(dot_await_span, "only allowed inside `async` functions and blocks"); if let Some(item_sp) = self.current_item { err.span_label(item_sp, "this is not `async`"); } @@ -651,7 +651,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let span = self.mark_span_with_reason(DesugaringKind::Await, dot_await_span, None); let gen_future_span = self.mark_span_with_reason( DesugaringKind::Await, - await_span, + full_span, self.allow_gen_future.clone(), ); let expr = self.lower_expr_mut(expr); @@ -704,9 +704,9 @@ impl<'hir> LoweringContext<'_, 'hir> { let loop_hir_id = self.lower_node_id(loop_node_id); let ready_arm = { let x_ident = Ident::with_dummy_span(sym::result); - let (x_pat, x_pat_hid) = self.pat_ident(span, x_ident); - let x_expr = self.expr_ident(span, x_ident, x_pat_hid); - let ready_field = self.single_pat_field(span, x_pat); + let (x_pat, x_pat_hid) = self.pat_ident(gen_future_span, x_ident); + let x_expr = self.expr_ident(gen_future_span, x_ident, x_pat_hid); + let ready_field = self.single_pat_field(gen_future_span, x_pat); let ready_pat = self.pat_lang_item_variant( span, hir::LangItem::PollReady, @@ -716,7 +716,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let break_x = self.with_loop_scope(loop_node_id, move |this| { let expr_break = hir::ExprKind::Break(this.lower_loop_destination(None), Some(x_expr)); - this.arena.alloc(this.expr(span, expr_break, ThinVec::new())) + this.arena.alloc(this.expr(gen_future_span, expr_break, ThinVec::new())) }); self.arm(ready_pat, break_x) }; @@ -788,7 +788,7 @@ impl<'hir> LoweringContext<'_, 'hir> { // `match ::std::future::IntoFuture::into_future() { ... }` let into_future_span = self.mark_span_with_reason( DesugaringKind::Await, - await_span, + dot_await_span, self.allow_into_future.clone(), ); let into_future_expr = self.expr_call_lang_item_fn( diff --git a/src/test/ui/async-await/proper-span-for-type-error.fixed b/src/test/ui/async-await/proper-span-for-type-error.fixed new file mode 100644 index 0000000000000..1f1e1184dcc02 --- /dev/null +++ b/src/test/ui/async-await/proper-span-for-type-error.fixed @@ -0,0 +1,11 @@ +// edition:2021 +// run-rustfix +#![allow(dead_code)] + +async fn a() {} + +async fn foo() -> Result<(), i32> { + Ok(a().await) //~ ERROR mismatched types +} + +fn main() {} diff --git a/src/test/ui/async-await/proper-span-for-type-error.rs b/src/test/ui/async-await/proper-span-for-type-error.rs new file mode 100644 index 0000000000000..00ccde1bf9962 --- /dev/null +++ b/src/test/ui/async-await/proper-span-for-type-error.rs @@ -0,0 +1,11 @@ +// edition:2021 +// run-rustfix +#![allow(dead_code)] + +async fn a() {} + +async fn foo() -> Result<(), i32> { + a().await //~ ERROR mismatched types +} + +fn main() {} diff --git a/src/test/ui/async-await/proper-span-for-type-error.stderr b/src/test/ui/async-await/proper-span-for-type-error.stderr new file mode 100644 index 0000000000000..611dc0407bf96 --- /dev/null +++ b/src/test/ui/async-await/proper-span-for-type-error.stderr @@ -0,0 +1,16 @@ +error[E0308]: mismatched types + --> $DIR/proper-span-for-type-error.rs:8:5 + | +LL | a().await + | ^^^^^^^^^ expected enum `Result`, found `()` + | + = note: expected enum `Result<(), i32>` + found unit type `()` +help: try wrapping the expression in `Ok` + | +LL | Ok(a().await) + | +++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From 3136c5f752837ce48d2e6cf1cc643929d294cfe0 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 19 Jan 2022 23:30:42 -0800 Subject: [PATCH 09/16] Update stabilization version of impl Not for ! --- library/core/src/ops/bit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/ops/bit.rs b/library/core/src/ops/bit.rs index d9ce84541cf9f..7c664226fc256 100644 --- a/library/core/src/ops/bit.rs +++ b/library/core/src/ops/bit.rs @@ -68,7 +68,7 @@ macro_rules! not_impl { not_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } -#[stable(feature = "not_never", since = "1.58.0")] +#[stable(feature = "not_never", since = "1.60.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const Not for ! { type Output = !; From 89f677815aae1ca3f75bde7757b69a42877edf7f Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 21 Jan 2022 10:35:18 +0100 Subject: [PATCH 10/16] [debuginfo] Fix and unify handling of fat pointers in debuginfo: address review comments. --- .../src/debuginfo/metadata.rs | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index d29e28f4a74f2..f64c823975aae 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -555,8 +555,8 @@ fn subroutine_type_metadata<'ll, 'tcx>( ) } -// Create debuginfo for `dyn SomeTrait` types. Currently these are empty structs -// we with the correct type name (e.g. "dyn SomeTrait + Sync"). +/// Create debuginfo for `dyn SomeTrait` types. Currently these are empty structs +/// we with the correct type name (e.g. "dyn SomeTrait + Sync"). fn dyn_type_metadata<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, dyn_type: Ty<'tcx>, @@ -570,23 +570,23 @@ fn dyn_type_metadata<'ll, 'tcx>( } } -// Create debuginfo for `[T]` and `str`. These are unsized. -// -// Note: We currently emit just emit the debuginfo for the element type here -// (i.e. `T` for slices and `u8` for `str`), so that we end up with -// `*const T` for the `data_ptr` field of the corresponding fat-pointer -// debuginfo of `&[T]`. -// -// It would be preferable and more accurate if we emitted a DIArray of T -// without an upper bound instead. That is, LLVM already supports emitting -// debuginfo of arrays of unknown size. But GDB currently seems to end up -// in an infinite loop when confronted with such a type. -// -// As a side effect of the current encoding every instance of a type like -// `struct Foo { unsized_field: [u8] }` will look like -// `struct Foo { unsized_field: u8 }` in debuginfo. If the length of the -// slice is zero, then accessing `unsized_field` in the debugger would -// result in an out-of-bounds access. +/// Create debuginfo for `[T]` and `str`. These are unsized. +/// +/// Note: We currently emit just emit the debuginfo for the element type here +/// (i.e. `T` for slices and `u8` for `str`), so that we end up with +/// `*const T` for the `data_ptr` field of the corresponding fat-pointer +/// debuginfo of `&[T]`. +/// +/// It would be preferable and more accurate if we emitted a DIArray of T +/// without an upper bound instead. That is, LLVM already supports emitting +/// debuginfo of arrays of unknown size. But GDB currently seems to end up +/// in an infinite loop when confronted with such a type. +/// +/// As a side effect of the current encoding every instance of a type like +/// `struct Foo { unsized_field: [u8] }` will look like +/// `struct Foo { unsized_field: u8 }` in debuginfo. If the length of the +/// slice is zero, then accessing `unsized_field` in the debugger would +/// result in an out-of-bounds access. fn slice_type_metadata<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, slice_type: Ty<'tcx>, From f0525da1242cc50297e7fa97f3ba148c2734bea8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 20 Jan 2022 14:18:59 +0100 Subject: [PATCH 11/16] Unify search input and buttons size --- src/librustdoc/html/static/css/rustdoc.css | 83 +++++-------------- src/librustdoc/html/static/css/themes/ayu.css | 12 +-- .../html/static/css/themes/dark.css | 11 +-- .../html/static/css/themes/light.css | 13 +-- src/librustdoc/html/templates/page.html | 20 ++--- 5 files changed, 33 insertions(+), 106 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index bdd8aa430b2d1..d9fa257085633 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -873,11 +873,11 @@ h2.small-section-header > .anchor { .search-container { position: relative; - max-width: 960px; + display: flex; + height: 34px; } -.search-container > div { - display: inline-flex; - width: calc(100% - 63px); +.search-container > * { + height: 100%; } .search-results-title { display: inline; @@ -908,10 +908,8 @@ h2.small-section-header > .anchor { background-position: calc(100% - 1px) 56%; background-image: /* AUTOREPLACE: */url("down-arrow.svg"); } -.search-container > .top-button { - position: absolute; - right: 0; - top: 10px; +.search-container { + margin-top: 4px; } .search-input { /* Override Normalize.css: it has a rule that sets @@ -924,23 +922,14 @@ h2.small-section-header > .anchor { -moz-box-sizing: border-box !important; box-sizing: border-box !important; outline: none; - border: none; - border-radius: 1px; - margin-top: 5px; - padding: 10px 16px; + border: 1px solid; + border-radius: 2px; + padding: 5px 8px; font-size: 1.0625rem; transition: border-color 300ms ease; - transition: border-radius 300ms ease-in-out; - transition: box-shadow 300ms ease-in-out; width: 100%; } -.search-input:focus { - border-radius: 2px; - border: 0; - outline: 0; -} - .search-results { display: none; padding-bottom: 2em; @@ -1414,8 +1403,8 @@ pre.rust { .theme-picker { position: absolute; - left: -34px; - top: 9px; + left: -38px; + top: 4px; } .theme-picker button { @@ -1423,34 +1412,27 @@ pre.rust { } #settings-menu, #help-button { - position: absolute; - top: 10px; -} - -#settings-menu { - right: 0; + margin-left: 4px; outline: none; } +#theme-picker, #copy-path { + height: 34px; +} #theme-picker, #settings-menu, #help-button, #copy-path { - padding: 4px; - /* Rare exception to specifying font sizes in rem. Since these are acting - as icons, it's okay to specify their sizes in pixels. */ - font-size: 16px; - width: 27px; - height: 29px; + padding: 5px; + width: 33px; border: 1px solid; - border-radius: 3px; + border-radius: 2px; cursor: pointer; } #help-button { - right: 30px; font-family: "Fira Sans", Arial, sans-serif; text-align: center; /* Rare exception to specifying font sizes in rem. Since this is acting as an icon, it's okay to specify their sizes in pixels. */ - font-size: 16px; + font-size: 20px; padding-top: 2px; } @@ -1887,10 +1869,6 @@ details.rustdoc-toggle[open] > summary.hideme::after { display: none !important; } - .theme-picker { - z-index: 1; - } - .notable-traits { position: absolute; left: -22px; @@ -1977,10 +1955,6 @@ details.rustdoc-toggle[open] > summary.hideme::after { width: 100%; } - .search-container > div { - width: calc(100% - 32px); - } - /* Display an alternating layout on tablets and phones */ .search-results > a { border-bottom: 1px solid #aaa9; @@ -2025,30 +1999,11 @@ details.rustdoc-toggle[open] > summary.hideme::after { width: 50%; } - .search-container > div { - display: block; - width: calc(100% - 37px); - } - #crate-search { border-radius: 4px; border: 0; } - #theme-picker, #settings-menu { - padding: 5px; - width: 31px; - height: 31px; - } - - #theme-picker { - margin-top: -2px; - } - - #settings-menu { - top: 7px; - } - .docblock { margin-left: 12px; } diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index 69097b81b9f1c..b217d0e27f3fc 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -233,22 +233,14 @@ details.undocumented > summary::before { filter: invert(100%); } -#crate-search { - color: #c5c5c5; +#crate-search, .search-input { background-color: #141920; - box-shadow: 0 0 0 1px #424c57,0 0 0 2px transparent; border-color: #424c57; + color: #c5c5c5; } .search-input { color: #ffffff; - background-color: #141920; - box-shadow: 0 0 0 1px #424c57,0 0 0 2px transparent; - transition: box-shadow 150ms ease-in-out; -} - -#crate-search+.search-input:focus { - box-shadow: 0 0 0 1px #148099,0 0 0 2px transparent; } .module-item .stab, diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index 39165b2fc058f..ead1e08386e8f 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -194,27 +194,20 @@ details.undocumented > summary::before { filter: invert(100%); } -#crate-search { +#crate-search, .search-input { color: #111; background-color: #f0f0f0; border-color: #000; - box-shadow: 0 0 0 1px #000, 0 0 0 2px transparent; } .search-input { - color: #111; - background-color: #f0f0f0; - box-shadow: 0 0 0 1px #000, 0 0 0 2px transparent; + border-color: #e0e0e0; } .search-input:focus { border-color: #008dfd; } -#crate-search + .search-input:focus { - box-shadow: 0 0 8px 4px #078dd8; -} - .module-item .stab, .import-item .stab { color: #ddd; diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index 448c9ac603c82..cd77b80cd385f 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -186,27 +186,16 @@ details.undocumented > summary::before { color: #999; } -#crate-search { +#crate-search, .search-input { color: #555; background-color: white; border-color: #e0e0e0; - box-shadow: 0 0 0 1px #e0e0e0, 0 0 0 2px transparent; -} - -.search-input { - color: #555; - background-color: white; - box-shadow: 0 0 0 1px #e0e0e0, 0 0 0 2px transparent; } .search-input:focus { border-color: #66afe9; } -#crate-search + .search-input:focus { - box-shadow: 0 0 8px #078dd8; -} - .module-item .stab, .import-item .stab { color: #000; diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index 1322b854b7fc7..3325515bef606 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -110,25 +110,23 @@