diff options
| author | Michael Goulet <michael@errs.io> | 2025-02-10 19:47:00 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-02-10 19:51:26 +0000 |
| commit | 28164e3c047991294a3d4e7afd6b820c0c2f86ee (patch) | |
| tree | 62b5c343f309aea47fe00529bfa97554e5251995 /compiler/rustc_builtin_macros/src/contracts.rs | |
| parent | 8c04e395952022a451138dc4dbead6dd6ae65203 (diff) | |
| download | rust-28164e3c047991294a3d4e7afd6b820c0c2f86ee.tar.gz rust-28164e3c047991294a3d4e7afd6b820c0c2f86ee.zip | |
Stop using span hack for contracts feature gating
Diffstat (limited to 'compiler/rustc_builtin_macros/src/contracts.rs')
| -rw-r--r-- | compiler/rustc_builtin_macros/src/contracts.rs | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/compiler/rustc_builtin_macros/src/contracts.rs b/compiler/rustc_builtin_macros/src/contracts.rs index 85a30f7bdc9..0cba29f2b31 100644 --- a/compiler/rustc_builtin_macros/src/contracts.rs +++ b/compiler/rustc_builtin_macros/src/contracts.rs @@ -4,8 +4,8 @@ use rustc_ast::token; use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree}; use rustc_errors::ErrorGuaranteed; use rustc_expand::base::{AttrProcMacro, ExtCtxt}; -use rustc_span::Span; use rustc_span::symbol::{Ident, Symbol, kw, sym}; +use rustc_span::{DesugaringKind, Span}; pub(crate) struct ExpandRequires; @@ -121,23 +121,19 @@ fn expand_contract_clause( } } - // Record the span as a contract attribute expansion. - // This is used later to stop users from using the extended syntax directly - // which is gated via `contracts_internals`. - ecx.psess().contract_attribute_spans.push(attr_span); - Ok(new_tts) } fn expand_requires_tts( - _ecx: &mut ExtCtxt<'_>, + ecx: &mut ExtCtxt<'_>, attr_span: Span, annotation: TokenStream, annotated: TokenStream, ) -> Result<TokenStream, ErrorGuaranteed> { - expand_contract_clause(_ecx, attr_span, annotated, |new_tts| { + let feature_span = ecx.with_def_site_ctxt(attr_span); + expand_contract_clause(ecx, attr_span, annotated, |new_tts| { new_tts.push_tree(TokenTree::Token( - token::Token::from_ast_ident(Ident::new(kw::ContractRequires, attr_span)), + token::Token::from_ast_ident(Ident::new(kw::ContractRequires, feature_span)), Spacing::Joint, )); new_tts.push_tree(TokenTree::Token( @@ -155,14 +151,15 @@ fn expand_requires_tts( } fn expand_ensures_tts( - _ecx: &mut ExtCtxt<'_>, + ecx: &mut ExtCtxt<'_>, attr_span: Span, annotation: TokenStream, annotated: TokenStream, ) -> Result<TokenStream, ErrorGuaranteed> { - expand_contract_clause(_ecx, attr_span, annotated, |new_tts| { + let feature_span = ecx.with_def_site_ctxt(attr_span); + expand_contract_clause(ecx, attr_span, annotated, |new_tts| { new_tts.push_tree(TokenTree::Token( - token::Token::from_ast_ident(Ident::new(kw::ContractEnsures, attr_span)), + token::Token::from_ast_ident(Ident::new(kw::ContractEnsures, feature_span)), Spacing::Joint, )); new_tts.push_tree(TokenTree::Delimited( |
