mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-15 05:26:47 +00:00
add rustc_macro_edition_2021
This commit is contained in:
parent
c4b38a5967
commit
7c085f7ffd
@ -191,6 +191,7 @@ pub enum AttributeKind {
|
||||
},
|
||||
MacroTransparency(Transparency),
|
||||
Repr(ThinVec<(ReprAttr, Span)>),
|
||||
RustcMacroEdition2021,
|
||||
Stability {
|
||||
stability: Stability,
|
||||
/// Span of the `#[stable(...)]` or `#[unstable(...)]` attribute
|
||||
|
@ -182,21 +182,18 @@ macro_rules! find_attr {
|
||||
}};
|
||||
|
||||
($attributes_list: expr, $pattern: pat $(if $guard: expr)? => $e: expr) => {{
|
||||
fn check_attribute_iterator<'a>(_: &'_ impl IntoIterator<Item = &'a rustc_hir::Attribute>) {}
|
||||
check_attribute_iterator(&$attributes_list);
|
||||
|
||||
let find_attribute = |iter| {
|
||||
'done: {
|
||||
for i in $attributes_list {
|
||||
let i: &rustc_hir::Attribute = i;
|
||||
match i {
|
||||
rustc_hir::Attribute::Parsed($pattern) $(if $guard)? => {
|
||||
return Some($e);
|
||||
break 'done Some($e);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
};
|
||||
find_attribute($attributes_list)
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ pub(crate) mod cfg;
|
||||
pub(crate) mod confusables;
|
||||
pub(crate) mod deprecation;
|
||||
pub(crate) mod repr;
|
||||
pub(crate) mod rustc;
|
||||
pub(crate) mod stability;
|
||||
pub(crate) mod transparency;
|
||||
pub(crate) mod util;
|
||||
|
19
compiler/rustc_attr_parsing/src/attributes/rustc.rs
Normal file
19
compiler/rustc_attr_parsing/src/attributes/rustc.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use rustc_attr_data_structures::AttributeKind;
|
||||
use rustc_span::sym;
|
||||
|
||||
use super::{AcceptContext, SingleAttributeParser};
|
||||
use crate::parser::ArgParser;
|
||||
|
||||
pub(crate) struct RustcMacroEdition2021Parser;
|
||||
|
||||
// FIXME(jdonszelmann): make these proper diagnostics
|
||||
impl SingleAttributeParser for RustcMacroEdition2021Parser {
|
||||
const PATH: &'static [rustc_span::Symbol] = &[sym::rustc_macro_edition_2021];
|
||||
|
||||
fn on_duplicate(_cx: &crate::context::AcceptContext<'_>, _first_span: rustc_span::Span) {}
|
||||
|
||||
fn convert(_cx: &AcceptContext<'_>, args: &ArgParser<'_>) -> Option<AttributeKind> {
|
||||
assert!(args.no_args());
|
||||
Some(AttributeKind::RustcMacroEdition2021)
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInterna
|
||||
use crate::attributes::confusables::ConfusablesParser;
|
||||
use crate::attributes::deprecation::DeprecationParser;
|
||||
use crate::attributes::repr::ReprParser;
|
||||
use crate::attributes::rustc::RustcMacroEdition2021Parser;
|
||||
use crate::attributes::stability::{
|
||||
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
|
||||
};
|
||||
@ -76,6 +77,7 @@ attribute_groups!(
|
||||
// tidy-alphabetical-start
|
||||
Single<ConstStabilityIndirectParser>,
|
||||
Single<DeprecationParser>,
|
||||
Single<RustcMacroEdition2021Parser>,
|
||||
Single<TransparencyParser>,
|
||||
// tidy-alphabetical-end
|
||||
];
|
||||
|
@ -661,6 +661,14 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
||||
"`rustc_never_type_options` is used to experiment with never type fallback and work on \
|
||||
never type stabilization, and will never be stable"
|
||||
),
|
||||
rustc_attr!(
|
||||
rustc_macro_edition_2021,
|
||||
Normal,
|
||||
template!(Word),
|
||||
ErrorFollowing,
|
||||
EncodeCrossCrate::No,
|
||||
"makes spans in this macro edition 2021"
|
||||
),
|
||||
|
||||
// ==========================================================================
|
||||
// Internal attributes: Runtime related:
|
||||
|
@ -8,7 +8,7 @@ use std::sync::Arc;
|
||||
use rustc_ast::expand::StrippedCfgItem;
|
||||
use rustc_ast::{self as ast, Crate, NodeId, attr};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_attr_parsing::StabilityLevel;
|
||||
use rustc_attr_parsing::{AttributeKind, StabilityLevel, find_attr};
|
||||
use rustc_data_structures::intern::Interned;
|
||||
use rustc_errors::{Applicability, StashKey};
|
||||
use rustc_expand::base::{
|
||||
@ -1125,6 +1125,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
edition,
|
||||
);
|
||||
|
||||
if find_attr!(attrs.iter(), AttributeKind::RustcMacroEdition2021 {}) {
|
||||
ext.edition = Edition::Edition2021;
|
||||
}
|
||||
|
||||
if let Some(builtin_name) = ext.builtin_name {
|
||||
// The macro was marked with `#[rustc_builtin_macro]`.
|
||||
if let Some(builtin_macro) = self.builtin_macros.get_mut(&builtin_name) {
|
||||
|
@ -1793,6 +1793,7 @@ symbols! {
|
||||
rustc_lint_opt_ty,
|
||||
rustc_lint_query_instability,
|
||||
rustc_lint_untracked_query_information,
|
||||
rustc_macro_edition_2021,
|
||||
rustc_macro_transparency,
|
||||
rustc_main,
|
||||
rustc_mir,
|
||||
|
@ -1943,6 +1943,7 @@ unsafe impl<T: ?Sized> PinCoerceUnsized for *mut T {}
|
||||
#[stable(feature = "pin_macro", since = "1.68.0")]
|
||||
#[rustc_macro_transparency = "semitransparent"]
|
||||
#[allow_internal_unstable(unsafe_pin_internals)]
|
||||
#[cfg_attr(not(bootstrap), rustc_macro_edition_2021)]
|
||||
pub macro pin($value:expr $(,)?) {
|
||||
// This is `Pin::new_unchecked(&mut { $value })`, so, for starters, let's
|
||||
// review such a hypothetical macro (that any user-code could define):
|
||||
|
@ -81,3 +81,16 @@ mod pin_coerce_unsized {
|
||||
arg
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spans_2021() {
|
||||
// Check that we accept a Rust 2024 $expr.
|
||||
std::pin::pin!(const { 1 });
|
||||
|
||||
// Check that temporary lifetimes work as in Rust 2021.
|
||||
match std::pin::pin!(foo(&mut 0)) {
|
||||
_f => {}
|
||||
}
|
||||
}
|
||||
|
||||
async fn foo(_: &mut usize) {}
|
||||
|
Loading…
Reference in New Issue
Block a user