Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 428b251

Browse filesBrowse files
committed
debug contract body issue
1 parent 5e56316 commit 428b251
Copy full SHA for 428b251

File tree

Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed

‎compiler/rustc_builtin_macros/src/contracts.rs

Copy file name to clipboardExpand all lines: compiler/rustc_builtin_macros/src/contracts.rs
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ fn expand_requires_tts(
130130
) -> Result<TokenStream, ErrorGuaranteed> {
131131
let feature_span = ecx.with_def_site_ctxt(attr_span);
132132
expand_contract_clause(ecx, attr_span, annotated, |new_tts| {
133+
add_allow_unused_parens(new_tts, attr_span);
133134
new_tts.push_tree(TokenTree::Token(
134135
token::Token::from_ast_ident(Ident::new(kw::ContractRequires, feature_span)),
135136
Spacing::Joint,
@@ -156,10 +157,12 @@ fn expand_ensures_tts(
156157
) -> Result<TokenStream, ErrorGuaranteed> {
157158
let feature_span = ecx.with_def_site_ctxt(attr_span);
158159
expand_contract_clause(ecx, attr_span, annotated, |new_tts| {
160+
add_allow_unused_parens(new_tts, attr_span);
159161
new_tts.push_tree(TokenTree::Token(
160162
token::Token::from_ast_ident(Ident::new(kw::ContractEnsures, feature_span)),
161163
Spacing::Joint,
162164
));
165+
163166
new_tts.push_tree(TokenTree::Delimited(
164167
DelimSpan::from_single(attr_span),
165168
DelimSpacing::new(Spacing::JointHidden, Spacing::JointHidden),
@@ -169,3 +172,34 @@ fn expand_ensures_tts(
169172
Ok(())
170173
})
171174
}
175+
176+
fn add_allow_unused_parens(new_tts: &mut TokenStream, attr_span: Span) {
177+
// push_tree `#[allow(unused_parens)]` to avoid linting on the contract expression
178+
new_tts.push_tree(TokenTree::Token(
179+
token::Token::new(token::TokenKind::Pound, attr_span),
180+
Spacing::Joint,
181+
));
182+
new_tts.push_tree(TokenTree::Delimited(
183+
DelimSpan::from_single(attr_span),
184+
DelimSpacing::new(Spacing::JointHidden, Spacing::JointHidden),
185+
token::Delimiter::Parenthesis,
186+
TokenStream::from_iter(vec![
187+
TokenTree::Token(
188+
token::Token::from_ast_ident(Ident::new(Symbol::intern("allow"), attr_span)),
189+
Spacing::Joint,
190+
),
191+
TokenTree::Delimited(
192+
DelimSpan::from_single(attr_span),
193+
DelimSpacing::new(Spacing::JointHidden, Spacing::JointHidden),
194+
token::Delimiter::Parenthesis,
195+
TokenStream::from_iter(vec![TokenTree::Token(
196+
token::Token::from_ast_ident(Ident::new(
197+
Symbol::intern("unused_parens"),
198+
attr_span,
199+
)),
200+
Spacing::Joint,
201+
)]),
202+
),
203+
]),
204+
));
205+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.