Skip to content

Commit d0442e2

Browse files
committed
Auto merge of #155011 - JonathanBrouwer:rollup-9GJWM3g, r=JonathanBrouwer
Rollup of 6 pull requests Successful merges: - #154912 (Remove `BuiltinLintDiag`) - #154598 (test `#[naked]` with `#[link_section = "..."]` on windows) - #154719 (Hexagon inline asm: add reg_pair, vreg, vreg_pair, and qreg register classes) - #154057 (Parenthesize block-like expressions in index base of pretty printer) - #154893 (make `expected_literal` positive) - #155002 (Clarify that `core::range` ranges do not have special syntax)
2 parents 9004856 + efa9224 commit d0442e2

38 files changed

Lines changed: 978 additions & 320 deletions

File tree

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,15 @@ impl<'a> State<'a> {
235235
// In order to call a named field, needs parens: `(self.fun)()`
236236
// But not for an unnamed field: `self.0()`
237237
ast::ExprKind::Field(_, name) => !name.is_numeric(),
238-
_ => func_fixup.precedence(func) < ExprPrecedence::Unambiguous,
238+
// Block-like expressions (block, match, if, loop, ...) never
239+
// parse as the callee of a call, regardless of context: the
240+
// closing brace ends the expression and `(args)` becomes a
241+
// separate tuple. Parenthesize them so the call survives a
242+
// pretty-print round trip.
243+
_ => {
244+
func_fixup.precedence(func) < ExprPrecedence::Unambiguous
245+
|| classify::expr_is_complete(func)
246+
}
239247
};
240248

241249
self.print_expr_cond_paren(func, needs_paren, func_fixup);
@@ -677,7 +685,8 @@ impl<'a> State<'a> {
677685
let expr_fixup = fixup.leftmost_subexpression_with_operator(true);
678686
self.print_expr_cond_paren(
679687
expr,
680-
expr_fixup.precedence(expr) < ExprPrecedence::Unambiguous,
688+
expr_fixup.precedence(expr) < ExprPrecedence::Unambiguous
689+
|| classify::expr_is_complete(expr),
681690
expr_fixup,
682691
);
683692
self.word("[");

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecatedParser {
8383
ArgParser::List(list) => {
8484
for param in list.mixed() {
8585
let Some(param) = param.meta_item() else {
86-
cx.adcx().unexpected_literal(param.span());
86+
cx.adcx().expected_not_literal(param.span());
8787
return None;
8888
};
8989

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<S: Stage> CombineAttributeParser<S> for LinkParser {
9393
let mut import_name_type = None;
9494
for item in items.mixed() {
9595
let Some(item) = item.meta_item() else {
96-
cx.adcx().unexpected_literal(item.span());
96+
cx.adcx().expected_not_literal(item.span());
9797
continue;
9898
};
9999

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl<S: Stage> SingleAttributeParser<S> for CollapseDebugInfoParser {
185185
return None;
186186
};
187187
let Some(mi) = single.meta_item() else {
188-
cx.adcx().unexpected_literal(single.span());
188+
cx.adcx().expected_not_literal(single.span());
189189
return None;
190190
};
191191
if let Err(err) = mi.args().no_args() {

compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn parse_derive_like<S: Stage>(
7878
return None;
7979
};
8080
let Some(trait_attr) = trait_attr.meta_item() else {
81-
cx.adcx().unexpected_literal(trait_attr.span());
81+
cx.adcx().expected_not_literal(trait_attr.span());
8282
return None;
8383
};
8484
let Some(trait_ident) = trait_attr.path().word() else {
@@ -98,7 +98,7 @@ fn parse_derive_like<S: Stage>(
9898
let mut attributes = ThinVec::new();
9999
if let Some(attrs) = items.next() {
100100
let Some(attr_list) = attrs.meta_item() else {
101-
cx.adcx().unexpected_literal(attrs.span());
101+
cx.adcx().expected_not_literal(attrs.span());
102102
return None;
103103
};
104104
if !attr_list.path().word_is(sym::attributes) {

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ impl<S: Stage> CombineAttributeParser<S> for RustcLayoutParser {
744744
let mut result = Vec::new();
745745
for item in items.mixed() {
746746
let Some(arg) = item.meta_item() else {
747-
cx.adcx().unexpected_literal(item.span());
747+
cx.adcx().expected_not_literal(item.span());
748748
continue;
749749
};
750750
let Some(ident) = arg.ident() else {

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ pub(crate) fn parse_stability<S: Stage>(
319319
for param in list.mixed() {
320320
let param_span = param.span();
321321
let Some(param) = param.meta_item() else {
322-
cx.adcx().unexpected_literal(param.span());
322+
cx.adcx().expected_not_literal(param.span());
323323
return None;
324324
};
325325

@@ -390,7 +390,7 @@ pub(crate) fn parse_unstability<S: Stage>(
390390

391391
for param in list.mixed() {
392392
let Some(param) = param.meta_item() else {
393-
cx.adcx().unexpected_literal(param.span());
393+
cx.adcx().expected_not_literal(param.span());
394394
return None;
395395
};
396396

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<S: Stage> SingleAttributeParser<S> for TestRunnerParser {
220220
};
221221

222222
let Some(meta) = single.meta_item() else {
223-
cx.adcx().unexpected_literal(single.span());
223+
cx.adcx().expected_not_literal(single.span());
224224
return None;
225225
};
226226

compiler/rustc_attr_parsing/src/attributes/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcSkipDuringMethodDispatchParser
2929
}
3030
for arg in args.mixed() {
3131
let Some(arg) = arg.meta_item() else {
32-
cx.adcx().unexpected_literal(arg.span());
32+
cx.adcx().expected_not_literal(arg.span());
3333
continue;
3434
};
3535
if let Err(span) = arg.args().no_args() {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ where
747747

748748
/// An error that should be emitted when a [`MetaItemOrLitParser`](crate::parser::MetaItemOrLitParser)
749749
/// was expected *not* to be a literal, but instead a meta item.
750-
pub(crate) fn unexpected_literal(&mut self, span: Span) -> ErrorGuaranteed {
751-
self.emit_parse_error(span, AttributeParseErrorReason::UnexpectedLiteral)
750+
pub(crate) fn expected_not_literal(&mut self, span: Span) -> ErrorGuaranteed {
751+
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedNotLiteral)
752752
}
753753

754754
pub(crate) fn expected_single_argument(&mut self, span: Span) -> ErrorGuaranteed {

0 commit comments

Comments
 (0)