Auto merge of #119211 - rust-lang:pa-master-1.77, r=Mark-Simulacrum
Bump stage0 to 1.76 beta r? `@Mark-Simulacrum`
This commit is contained in:
commit
495203bf61
27 changed files with 455 additions and 885 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#![cfg_attr(all(doc, not(bootstrap)), allow(internal_features))]
|
||||
#![cfg_attr(all(doc, not(bootstrap)), feature(rustdoc_internals))]
|
||||
#![cfg_attr(all(doc, not(bootstrap)), doc(rust_logo))]
|
||||
#![cfg_attr(doc, allow(internal_features))]
|
||||
#![cfg_attr(doc, feature(rustdoc_internals))]
|
||||
#![cfg_attr(doc, doc(rust_logo))]
|
||||
#![feature(rustc_private)]
|
||||
// Note: please avoid adding other feature gates where possible
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#![feature(rustdoc_internals)]
|
||||
#![doc(rust_logo)]
|
||||
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
||||
#![cfg_attr(bootstrap, feature(c_str_literals))]
|
||||
#![feature(exact_size_is_empty)]
|
||||
#![feature(extern_types)]
|
||||
#![feature(hash_raw_entry)]
|
||||
|
|
|
|||
|
|
@ -81,150 +81,6 @@
|
|||
/// E::A,
|
||||
/// }
|
||||
/// ```
|
||||
#[cfg(bootstrap)]
|
||||
#[macro_export]
|
||||
macro_rules! impl_tag {
|
||||
(
|
||||
impl Tag for $Self:ty;
|
||||
$(
|
||||
$($path:ident)::* $( { $( $fields:tt )* })?,
|
||||
)*
|
||||
) => {
|
||||
// Safety:
|
||||
// `bits_for_tags` is called on the same `${index()}`-es as
|
||||
// `into_usize` returns, thus `BITS` constant is correct.
|
||||
unsafe impl $crate::tagged_ptr::Tag for $Self {
|
||||
const BITS: u32 = $crate::tagged_ptr::bits_for_tags(&[
|
||||
$(
|
||||
${index()},
|
||||
$( ${ignore(path)} )*
|
||||
)*
|
||||
]);
|
||||
|
||||
#[inline]
|
||||
fn into_usize(self) -> usize {
|
||||
// This forbids use of repeating patterns (`Enum::V`&`Enum::V`, etc)
|
||||
// (or at least it should, see <https://github.com/rust-lang/rust/issues/110613>)
|
||||
#[forbid(unreachable_patterns)]
|
||||
match self {
|
||||
// `match` is doing heavy lifting here, by requiring exhaustiveness
|
||||
$(
|
||||
$($path)::* $( { $( $fields )* } )? => ${index()},
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn from_usize(tag: usize) -> Self {
|
||||
match tag {
|
||||
$(
|
||||
${index()} => $($path)::* $( { $( $fields )* } )?,
|
||||
)*
|
||||
|
||||
// Safety:
|
||||
// `into_usize` only returns `${index()}` of the same
|
||||
// repetition as we are filtering above, thus if this is
|
||||
// reached, the safety contract of this function was
|
||||
// already breached.
|
||||
_ => unsafe {
|
||||
debug_assert!(
|
||||
false,
|
||||
"invalid tag: {tag}\
|
||||
(this is a bug in the caller of `from_usize`)"
|
||||
);
|
||||
std::hint::unreachable_unchecked()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Implements [`Tag`] for a given type.
|
||||
///
|
||||
/// You can use `impl_tag` on structs and enums.
|
||||
/// You need to specify the type and all its possible values,
|
||||
/// which can only be paths with optional fields.
|
||||
///
|
||||
/// [`Tag`]: crate::tagged_ptr::Tag
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(macro_metavar_expr)]
|
||||
/// use rustc_data_structures::{impl_tag, tagged_ptr::Tag};
|
||||
///
|
||||
/// #[derive(Copy, Clone, PartialEq, Debug)]
|
||||
/// enum SomeTag {
|
||||
/// A,
|
||||
/// B,
|
||||
/// X { v: bool },
|
||||
/// Y(bool, bool),
|
||||
/// }
|
||||
///
|
||||
/// impl_tag! {
|
||||
/// // The type for which the `Tag` will be implemented
|
||||
/// impl Tag for SomeTag;
|
||||
/// // You need to specify all possible tag values:
|
||||
/// SomeTag::A, // 0
|
||||
/// SomeTag::B, // 1
|
||||
/// // For variants with fields, you need to specify the fields:
|
||||
/// SomeTag::X { v: true }, // 2
|
||||
/// SomeTag::X { v: false }, // 3
|
||||
/// // For tuple variants use named syntax:
|
||||
/// SomeTag::Y { 0: true, 1: true }, // 4
|
||||
/// SomeTag::Y { 0: false, 1: true }, // 5
|
||||
/// SomeTag::Y { 0: true, 1: false }, // 6
|
||||
/// SomeTag::Y { 0: false, 1: false }, // 7
|
||||
/// }
|
||||
///
|
||||
/// // Tag values are assigned in order:
|
||||
/// assert_eq!(SomeTag::A.into_usize(), 0);
|
||||
/// assert_eq!(SomeTag::X { v: false }.into_usize(), 3);
|
||||
/// assert_eq!(SomeTag::Y(false, true).into_usize(), 5);
|
||||
///
|
||||
/// assert_eq!(unsafe { SomeTag::from_usize(1) }, SomeTag::B);
|
||||
/// assert_eq!(unsafe { SomeTag::from_usize(2) }, SomeTag::X { v: true });
|
||||
/// assert_eq!(unsafe { SomeTag::from_usize(7) }, SomeTag::Y(false, false));
|
||||
/// ```
|
||||
///
|
||||
/// Structs are supported:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(macro_metavar_expr)]
|
||||
/// # use rustc_data_structures::impl_tag;
|
||||
/// #[derive(Copy, Clone)]
|
||||
/// struct Flags { a: bool, b: bool }
|
||||
///
|
||||
/// impl_tag! {
|
||||
/// impl Tag for Flags;
|
||||
/// Flags { a: true, b: true },
|
||||
/// Flags { a: false, b: true },
|
||||
/// Flags { a: true, b: false },
|
||||
/// Flags { a: false, b: false },
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Not specifying all values results in a compile error:
|
||||
///
|
||||
/// ```compile_fail,E0004
|
||||
/// #![feature(macro_metavar_expr)]
|
||||
/// # use rustc_data_structures::impl_tag;
|
||||
/// #[derive(Copy, Clone)]
|
||||
/// enum E {
|
||||
/// A,
|
||||
/// B,
|
||||
/// }
|
||||
///
|
||||
/// impl_tag! {
|
||||
/// impl Tag for E;
|
||||
/// E::A,
|
||||
/// }
|
||||
/// ```
|
||||
#[cfg(not(bootstrap))]
|
||||
#[macro_export]
|
||||
macro_rules! impl_tag {
|
||||
(
|
||||
|
|
|
|||
|
|
@ -41,132 +41,6 @@ use std::path::PathBuf;
|
|||
use std::rc::Rc;
|
||||
use std::{iter, mem};
|
||||
|
||||
#[cfg(bootstrap)]
|
||||
macro_rules! ast_fragments {
|
||||
(
|
||||
$($Kind:ident($AstTy:ty) {
|
||||
$kind_name:expr;
|
||||
$(one fn $mut_visit_ast:ident; fn $visit_ast:ident;)?
|
||||
$(many fn $flat_map_ast_elt:ident; fn $visit_ast_elt:ident($($args:tt)*);)?
|
||||
fn $make_ast:ident;
|
||||
})*
|
||||
) => {
|
||||
/// A fragment of AST that can be produced by a single macro expansion.
|
||||
/// Can also serve as an input and intermediate result for macro expansion operations.
|
||||
pub enum AstFragment {
|
||||
OptExpr(Option<P<ast::Expr>>),
|
||||
MethodReceiverExpr(P<ast::Expr>),
|
||||
$($Kind($AstTy),)*
|
||||
}
|
||||
|
||||
/// "Discriminant" of an AST fragment.
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub enum AstFragmentKind {
|
||||
OptExpr,
|
||||
MethodReceiverExpr,
|
||||
$($Kind,)*
|
||||
}
|
||||
|
||||
impl AstFragmentKind {
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
AstFragmentKind::OptExpr => "expression",
|
||||
AstFragmentKind::MethodReceiverExpr => "expression",
|
||||
$(AstFragmentKind::$Kind => $kind_name,)*
|
||||
}
|
||||
}
|
||||
|
||||
fn make_from<'a>(self, result: Box<dyn MacResult + 'a>) -> Option<AstFragment> {
|
||||
match self {
|
||||
AstFragmentKind::OptExpr =>
|
||||
result.make_expr().map(Some).map(AstFragment::OptExpr),
|
||||
AstFragmentKind::MethodReceiverExpr =>
|
||||
result.make_expr().map(AstFragment::MethodReceiverExpr),
|
||||
$(AstFragmentKind::$Kind => result.$make_ast().map(AstFragment::$Kind),)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AstFragment {
|
||||
pub fn add_placeholders(&mut self, placeholders: &[NodeId]) {
|
||||
if placeholders.is_empty() {
|
||||
return;
|
||||
}
|
||||
match self {
|
||||
$($(AstFragment::$Kind(ast) => ast.extend(placeholders.iter().flat_map(|id| {
|
||||
${ignore(flat_map_ast_elt)}
|
||||
placeholder(AstFragmentKind::$Kind, *id, None).$make_ast()
|
||||
})),)?)*
|
||||
_ => panic!("unexpected AST fragment kind")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_opt_expr(self) -> Option<P<ast::Expr>> {
|
||||
match self {
|
||||
AstFragment::OptExpr(expr) => expr,
|
||||
_ => panic!("AstFragment::make_* called on the wrong kind of fragment"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_method_receiver_expr(self) -> P<ast::Expr> {
|
||||
match self {
|
||||
AstFragment::MethodReceiverExpr(expr) => expr,
|
||||
_ => panic!("AstFragment::make_* called on the wrong kind of fragment"),
|
||||
}
|
||||
}
|
||||
|
||||
$(pub fn $make_ast(self) -> $AstTy {
|
||||
match self {
|
||||
AstFragment::$Kind(ast) => ast,
|
||||
_ => panic!("AstFragment::make_* called on the wrong kind of fragment"),
|
||||
}
|
||||
})*
|
||||
|
||||
fn make_ast<T: InvocationCollectorNode>(self) -> T::OutputTy {
|
||||
T::fragment_to_output(self)
|
||||
}
|
||||
|
||||
pub fn mut_visit_with<F: MutVisitor>(&mut self, vis: &mut F) {
|
||||
match self {
|
||||
AstFragment::OptExpr(opt_expr) => {
|
||||
visit_clobber(opt_expr, |opt_expr| {
|
||||
if let Some(expr) = opt_expr {
|
||||
vis.filter_map_expr(expr)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
}
|
||||
AstFragment::MethodReceiverExpr(expr) => vis.visit_method_receiver_expr(expr),
|
||||
$($(AstFragment::$Kind(ast) => vis.$mut_visit_ast(ast),)?)*
|
||||
$($(AstFragment::$Kind(ast) =>
|
||||
ast.flat_map_in_place(|ast| vis.$flat_map_ast_elt(ast)),)?)*
|
||||
}
|
||||
}
|
||||
|
||||
pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) {
|
||||
match self {
|
||||
AstFragment::OptExpr(Some(expr)) => visitor.visit_expr(expr),
|
||||
AstFragment::OptExpr(None) => {}
|
||||
AstFragment::MethodReceiverExpr(expr) => visitor.visit_method_receiver_expr(expr),
|
||||
$($(AstFragment::$Kind(ast) => visitor.$visit_ast(ast),)?)*
|
||||
$($(AstFragment::$Kind(ast) => for ast_elt in &ast[..] {
|
||||
visitor.$visit_ast_elt(ast_elt, $($args)*);
|
||||
})?)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> MacResult for crate::mbe::macro_rules::ParserAnyMacro<'a> {
|
||||
$(fn $make_ast(self: Box<crate::mbe::macro_rules::ParserAnyMacro<'a>>)
|
||||
-> Option<$AstTy> {
|
||||
Some(self.make(AstFragmentKind::$Kind).$make_ast())
|
||||
})*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(bootstrap))]
|
||||
macro_rules! ast_fragments {
|
||||
(
|
||||
$($Kind:ident($AstTy:ty) {
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ declare_features! (
|
|||
/// Allows empty structs and enum variants with braces.
|
||||
(accepted, braced_empty_structs, "1.8.0", Some(29720)),
|
||||
/// Allows `c"foo"` literals.
|
||||
(accepted, c_str_literals, "CURRENT_RUSTC_VERSION", Some(105723)),
|
||||
(accepted, c_str_literals, "1.76.0", Some(105723)),
|
||||
/// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`.
|
||||
(accepted, cfg_attr_multi, "1.33.0", Some(54881)),
|
||||
/// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests.
|
||||
|
|
@ -341,7 +341,7 @@ declare_features! (
|
|||
(accepted, track_caller, "1.46.0", Some(47809)),
|
||||
/// Allows dyn upcasting trait objects via supertraits.
|
||||
/// Dyn upcasting is casting, e.g., `dyn Foo -> dyn Bar` where `Foo: Bar`.
|
||||
(accepted, trait_upcasting, "CURRENT_RUSTC_VERSION", Some(65991)),
|
||||
(accepted, trait_upcasting, "1.76.0", Some(65991)),
|
||||
/// Allows #[repr(transparent)] on univariant enums (RFC 2645).
|
||||
(accepted, transparent_enums, "1.42.0", Some(60405)),
|
||||
/// Allows indexing tuples.
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ declare_features! (
|
|||
/// Allows using the `#[register_attr]` attribute.
|
||||
(removed, register_attr, "1.65.0", Some(66080),
|
||||
Some("removed in favor of `#![register_tool]`")),
|
||||
(removed, rust_2018_preview, "CURRENT_RUSTC_VERSION", None,
|
||||
(removed, rust_2018_preview, "1.76.0", None,
|
||||
Some("2018 Edition preview is no longer relevant")),
|
||||
/// Allows using the macros:
|
||||
/// + `__diagnostic_used`
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ declare_features! (
|
|||
/// Allows using `#[lang = ".."]` attribute for linking items to special compiler logic.
|
||||
(internal, lang_items, "1.0.0", None),
|
||||
/// Changes `impl Trait` to capture all lifetimes in scope.
|
||||
(unstable, lifetime_capture_rules_2024, "CURRENT_RUSTC_VERSION", None),
|
||||
(unstable, lifetime_capture_rules_2024, "1.76.0", None),
|
||||
/// Allows `#[link(..., cfg(..))]`; perma-unstable per #37406
|
||||
(unstable, link_cfg, "1.14.0", None),
|
||||
/// Allows the `multiple_supertrait_upcastable` lint.
|
||||
|
|
@ -470,7 +470,7 @@ declare_features! (
|
|||
/// Allows using `#[repr(align(...))]` on function items
|
||||
(unstable, fn_align, "1.53.0", Some(82232)),
|
||||
/// Support delegating implementation of functions to other already implemented functions.
|
||||
(incomplete, fn_delegation, "CURRENT_RUSTC_VERSION", Some(118212)),
|
||||
(incomplete, fn_delegation, "1.76.0", Some(118212)),
|
||||
/// Allows defining gen blocks and `gen fn`.
|
||||
(unstable, gen_blocks, "1.75.0", Some(117078)),
|
||||
/// Infer generic args for both consts and types.
|
||||
|
|
@ -507,7 +507,7 @@ declare_features! (
|
|||
(unstable, let_chains, "1.37.0", Some(53667)),
|
||||
/// Allows using `#[link(kind = "link-arg", name = "...")]`
|
||||
/// to pass custom arguments to the linker.
|
||||
(unstable, link_arg_attribute, "CURRENT_RUSTC_VERSION", Some(99427)),
|
||||
(unstable, link_arg_attribute, "1.76.0", Some(99427)),
|
||||
/// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.
|
||||
(unstable, lint_reasons, "1.31.0", Some(54503)),
|
||||
/// Give access to additional metadata about declarative macro meta-variables.
|
||||
|
|
@ -529,7 +529,7 @@ declare_features! (
|
|||
/// Allow negative trait implementations.
|
||||
(unstable, negative_impls, "1.44.0", Some(68318)),
|
||||
/// Allows the `!` pattern.
|
||||
(incomplete, never_patterns, "CURRENT_RUSTC_VERSION", Some(118155)),
|
||||
(incomplete, never_patterns, "1.76.0", Some(118155)),
|
||||
/// Allows the `!` type. Does not imply 'exhaustive_patterns' (below) any more.
|
||||
(unstable, never_type, "1.13.0", Some(35121)),
|
||||
/// Allows diverging expressions to fall back to `!` rather than `()`.
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@
|
|||
#![feature(min_specialization)]
|
||||
#![feature(never_type)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![cfg_attr(bootstrap, feature(trait_upcasting))]
|
||||
#![recursion_limit = "256"]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@
|
|||
#![feature(associated_type_bounds)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(control_flow_enum)]
|
||||
#![cfg_attr(bootstrap, feature(trait_upcasting))]
|
||||
#![feature(trusted_step)]
|
||||
#![feature(try_blocks)]
|
||||
#![feature(try_reserve_kind)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue