From c8ab63b30f3f071f9ee9b14150613cd4a9e2c5c8 Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Wed, 30 Mar 2022 10:37:55 -0400 Subject: [PATCH 1/6] Only show associated consts from inherent impls in sidebar --- src/librustdoc/html/render/mod.rs | 1 + src/test/rustdoc/associated-consts.rs | 28 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 93b33b0d60912..0cfe12abcd14a 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1987,6 +1987,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) { let used_links_bor = &mut used_links; let mut assoc_consts = v .iter() + .filter(|i| i.inner_impl().trait_.is_none()) .flat_map(|i| get_associated_constants(i.inner_impl(), used_links_bor)) .collect::>(); if !assoc_consts.is_empty() { diff --git a/src/test/rustdoc/associated-consts.rs b/src/test/rustdoc/associated-consts.rs index da50fb86cd581..9319a073bb792 100644 --- a/src/test/rustdoc/associated-consts.rs +++ b/src/test/rustdoc/associated-consts.rs @@ -9,8 +9,8 @@ pub trait Trait { pub struct Bar; // @has 'foo/struct.Bar.html' -// @has - '//h3[@class="sidebar-title"]' 'Associated Constants' -// @has - '//div[@class="sidebar-elems"]//a' 'FOO' +// @!has - '//h3[@class="sidebar-title"]' 'Associated Constants' +// @!has - '//div[@class="sidebar-elems"]//a' 'FOO' impl Trait for Bar { const FOO: u32 = 1; @@ -22,10 +22,30 @@ pub enum Foo { } // @has 'foo/enum.Foo.html' -// @has - '//h3[@class="sidebar-title"]' 'Associated Constants' -// @has - '//div[@class="sidebar-elems"]//a' 'FOO' +// @!has - '//h3[@class="sidebar-title"]' 'Associated Constants' +// @!has - '//div[@class="sidebar-elems"]//a' 'FOO' impl Trait for Foo { const FOO: u32 = 1; fn foo() {} } + +pub struct Baz; + +// @has 'foo/struct.Baz.html' +// @has - '//h3[@class="sidebar-title"]' 'Associated Constants' +// @has - '//div[@class="sidebar-elems"]//a' 'FOO' +impl Baz { + pub const FOO: u32 = 42; +} + +pub enum Quux { + B, +} + +// @has 'foo/enum.Quux.html' +// @has - '//h3[@class="sidebar-title"]' 'Associated Constants' +// @has - '//div[@class="sidebar-elems"]//a' 'FOO' +impl Quux { + pub const FOO: u32 = 42; +} From 907ba11490e95e2bb649329456eb5ab9a6976f99 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 31 Mar 2022 09:32:30 -0400 Subject: [PATCH 2/6] ptr_metadata test: avoid ptr-to-int transmutes --- library/core/tests/ptr.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 750e7295fb533..6a39ab79f4965 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -490,11 +490,11 @@ fn ptr_metadata() { let vtable_5: DynMetadata = metadata(&Pair(true, 7_u32) as &Pair); unsafe { - let address_1: usize = std::mem::transmute(vtable_1); - let address_2: usize = std::mem::transmute(vtable_2); - let address_3: usize = std::mem::transmute(vtable_3); - let address_4: usize = std::mem::transmute(vtable_4); - let address_5: usize = std::mem::transmute(vtable_5); + let address_1: *const () = std::mem::transmute(vtable_1); + let address_2: *const () = std::mem::transmute(vtable_2); + let address_3: *const () = std::mem::transmute(vtable_3); + let address_4: *const () = std::mem::transmute(vtable_4); + let address_5: *const () = std::mem::transmute(vtable_5); // Different trait => different vtable pointer assert_ne!(address_1, address_2); // Different erased type => different vtable pointer From 487bd8184fbd1c0c1db05ce2109737b86a72f837 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 31 Mar 2022 10:44:29 -0400 Subject: [PATCH 3/6] skip slow int_log tests in Miri --- library/core/tests/num/int_log.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/core/tests/num/int_log.rs b/library/core/tests/num/int_log.rs index 3cd0073ddd8c2..dc3092e1486bc 100644 --- a/library/core/tests/num/int_log.rs +++ b/library/core/tests/num/int_log.rs @@ -22,12 +22,15 @@ fn checked_log() { assert_eq!(0i8.checked_log(4), None); assert_eq!(0i16.checked_log(4), None); + #[cfg(not(miri))] // Miri is too slow for i in i16::MIN..=0 { assert_eq!(i.checked_log(4), None); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=i16::MAX { assert_eq!(i.checked_log(13), Some((i as f32).log(13.0) as u32)); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=u16::MAX { assert_eq!(i.checked_log(13), Some((i as f32).log(13.0) as u32)); } @@ -48,6 +51,7 @@ fn checked_log2() { for i in 1..=u8::MAX { assert_eq!(i.checked_log2(), Some((i as f32).log2() as u32)); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=u16::MAX { // Guard against Android's imprecise f32::log2 implementation. if i != 8192 && i != 32768 { @@ -60,9 +64,11 @@ fn checked_log2() { for i in 1..=i8::MAX { assert_eq!(i.checked_log2(), Some((i as f32).log2() as u32)); } + #[cfg(not(miri))] // Miri is too slow for i in i16::MIN..=0 { assert_eq!(i.checked_log2(), None); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=i16::MAX { // Guard against Android's imprecise f32::log2 implementation. if i != 8192 { @@ -87,15 +93,19 @@ fn checked_log10() { assert_eq!(0i8.checked_log10(), None); assert_eq!(0i16.checked_log10(), None); + #[cfg(not(miri))] // Miri is too slow for i in i16::MIN..=0 { assert_eq!(i.checked_log10(), None); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=i16::MAX { assert_eq!(i.checked_log10(), Some((i as f32).log10() as u32)); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=u16::MAX { assert_eq!(i.checked_log10(), Some((i as f32).log10() as u32)); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=100_000u32 { assert_eq!(i.checked_log10(), Some((i as f32).log10() as u32)); } From 9ab4f732cb52eb07ea64a7f65038973bc4e0156c Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 31 Mar 2022 18:56:40 +0300 Subject: [PATCH 4/6] expand: Do not count metavar declarations on RHS of `macro_rules` They are 0 by definition there. --- compiler/rustc_expand/src/mbe/macro_parser.rs | 18 ++++++------------ compiler/rustc_expand/src/mbe/quoted.rs | 7 ++++--- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 18302ffdb8e10..0086983f3d984 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -263,18 +263,12 @@ crate type NamedParseResult = ParseResult usize { matcher .iter() - .map(|tt| { - match tt { - TokenTree::Delimited(_, delim) => count_metavar_decls(delim.inner_tts()), - TokenTree::MetaVar(..) => 0, - TokenTree::MetaVarDecl(..) => 1, - // RHS meta-variable expressions eventually end-up here. `0` is returned to inform - // that no meta-variable was found, because "meta-variables" != "meta-variable - // expressions". - TokenTree::MetaVarExpr(..) => 0, - TokenTree::Sequence(_, seq) => seq.num_captures, - TokenTree::Token(..) => 0, - } + .map(|tt| match tt { + TokenTree::MetaVarDecl(..) => 1, + TokenTree::Sequence(_, seq) => seq.num_captures, + TokenTree::Delimited(_, delim) => count_metavar_decls(delim.inner_tts()), + TokenTree::Token(..) => 0, + TokenTree::MetaVar(..) | TokenTree::MetaVarExpr(..) => unreachable!(), }) .sum() } diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index d91871c7e57db..48abbd7c18e14 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -1,4 +1,4 @@ -use crate::mbe::macro_parser; +use crate::mbe::macro_parser::count_metavar_decls; use crate::mbe::{Delimited, KleeneOp, KleeneToken, MetaVarExpr, SequenceRepetition, TokenTree}; use rustc_ast::token::{self, Token}; @@ -211,14 +211,15 @@ fn parse_tree( let (separator, kleene) = parse_sep_and_kleene_op(&mut trees, delim_span.entire(), sess); // Count the number of captured "names" (i.e., named metavars) - let name_captures = macro_parser::count_metavar_decls(&sequence); + let num_captures = + if parsing_patterns { count_metavar_decls(&sequence) } else { 0 }; TokenTree::Sequence( delim_span, Lrc::new(SequenceRepetition { tts: sequence, separator, kleene, - num_captures: name_captures, + num_captures, }), ) } From 85bfe2d99d191d385ecb1ac4660692e9de5c4fbe Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 31 Mar 2022 13:10:53 -0400 Subject: [PATCH 5/6] make utf8_char_counts test faster in Miri --- library/alloc/tests/str.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/library/alloc/tests/str.rs b/library/alloc/tests/str.rs index 32396e35696c0..273b39aa45a48 100644 --- a/library/alloc/tests/str.rs +++ b/library/alloc/tests/str.rs @@ -2234,11 +2234,14 @@ fn utf8_chars() { #[test] fn utf8_char_counts() { let strs = [("e", 1), ("é", 1), ("€", 1), ("\u{10000}", 1), ("eé€\u{10000}", 4)]; - let mut reps = - [8, 64, 256, 512, 1024].iter().copied().flat_map(|n| n - 8..=n + 8).collect::>(); + let spread = if cfg!(miri) { 4 } else { 8 }; + let mut reps = [8, 64, 256, 512] + .iter() + .copied() + .flat_map(|n| n - spread..=n + spread) + .collect::>(); if cfg!(not(miri)) { - let big = 1 << 16; - reps.extend(big - 8..=big + 8); + reps.extend([1024, 1 << 16].iter().copied().flat_map(|n| n - spread..=n + spread)); } let counts = if cfg!(miri) { 0..1 } else { 0..8 }; let padding = counts.map(|len| " ".repeat(len)).collect::>(); From e2466821add3873d1feb0cc28f3b31e7cf1629fd Mon Sep 17 00:00:00 2001 From: Autumn Date: Thu, 31 Mar 2022 16:13:19 -0700 Subject: [PATCH 6/6] add notes about alignment-altering reallocs to Allocator docs --- library/core/src/alloc/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 1f1033b0437f8..242725b96bd90 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -173,6 +173,8 @@ pub unsafe trait Allocator { /// * `old_layout` must [*fit*] that block of memory (The `new_layout` argument need not fit it.). /// * `new_layout.size()` must be greater than or equal to `old_layout.size()`. /// + /// Note that `new_layout.align()` need not be the same as `old_layout.align()`. + /// /// [*currently allocated*]: #currently-allocated-memory /// [*fit*]: #memory-fitting /// @@ -234,6 +236,8 @@ pub unsafe trait Allocator { /// * `old_layout` must [*fit*] that block of memory (The `new_layout` argument need not fit it.). /// * `new_layout.size()` must be greater than or equal to `old_layout.size()`. /// + /// Note that `new_layout.align()` need not be the same as `old_layout.align()`. + /// /// [*currently allocated*]: #currently-allocated-memory /// [*fit*]: #memory-fitting /// @@ -296,6 +300,8 @@ pub unsafe trait Allocator { /// * `old_layout` must [*fit*] that block of memory (The `new_layout` argument need not fit it.). /// * `new_layout.size()` must be smaller than or equal to `old_layout.size()`. /// + /// Note that `new_layout.align()` need not be the same as `old_layout.align()`. + /// /// [*currently allocated*]: #currently-allocated-memory /// [*fit*]: #memory-fitting ///