Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #95539

Closed
wants to merge 10 commits into from
18 changes: 6 additions & 12 deletions compiler/rustc_expand/src/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,18 +263,12 @@ crate type NamedParseResult = ParseResult<FxHashMap<MacroRulesNormalizedIdent, N
pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> 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()
}
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_expand/src/mbe/quoted.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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,
}),
)
}
Expand Down
10 changes: 10 additions & 0 deletions library/core/tests/num/int_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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));
}
Expand Down
10 changes: 5 additions & 5 deletions library/core/tests/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,11 @@ fn ptr_metadata() {
let vtable_5: DynMetadata<dyn Display> =
metadata(&Pair(true, 7_u32) as &Pair<bool, dyn Display>);
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
Expand Down
19 changes: 11 additions & 8 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,17 @@ impl Item {
) -> Item {
trace!("name={:?}, def_id={:?}", name, def_id);

Item {
def_id: def_id.into(),
kind: box kind,
name,
attrs,
visibility: cx.tcx.visibility(def_id).clean(cx),
cfg,
}
// Primitives and Keywords are written in the source code as private modules.
// The modules need to be private so that nobody actually uses them, but the
// keywords and primitives that they are documenting are public.
let visibility = if matches!(&kind, ItemKind::KeywordItem(..) | ItemKind::PrimitiveItem(..))
{
Visibility::Public
} else {
cx.tcx.visibility(def_id).clean(cx)
};

Item { def_id: def_id.into(), kind: box kind, name, attrs, visibility, cfg }
}

/// Finds all `doc` attributes as NameValues and returns their corresponding values, joined
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
if !assoc_consts.is_empty() {
Expand Down
28 changes: 24 additions & 4 deletions src/test/rustdoc/associated-consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
1 change: 1 addition & 0 deletions src/test/rustdoc/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// @has foo/index.html '//a/@href' '../foo/index.html'
// @!has foo/foo/index.html
// @!has-dir foo/foo
// @!has foo/index.html '//span' '🔒'
#[doc(keyword = "match")]
/// this is a test!
mod foo{}
Expand Down
21 changes: 21 additions & 0 deletions src/test/rustdoc/primitive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#![crate_name = "foo"]

#![feature(rustdoc_internals)]

// @has foo/index.html '//h2[@id="primitives"]' 'Primitive Types'
// @has foo/index.html '//a[@href="primitive.i32.html"]' 'i32'
// @has foo/index.html '//div[@class="sidebar-elems"]//li/a' 'Primitive Types'
// @has foo/index.html '//div[@class="sidebar-elems"]//li/a/@href' '#primitives'
// @has foo/primitive.i32.html '//a[@class="primitive"]' 'i32'
// @has foo/primitive.i32.html '//span[@class="in-band"]' 'Primitive Type i32'
// @has foo/primitive.i32.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'this is a test!'
// @has foo/index.html '//a/@href' '../foo/index.html'
// @!has foo/index.html '//span' '🔒'
#[doc(primitive = "i32")]
/// this is a test!
mod i32{}

// @has foo/primitive.bool.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'hello'
#[doc(primitive = "bool")]
/// hello
mod bool {}