Skip to content

Commit a37c32e

Browse files
committed
Auto merge of #73246 - Dylan-DPC:rollup-xnm531f, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #72180 (remove extra space from crate-level doctest names) - #73012 (Show `SyntaxContext` in formatted `Span` debug output) - #73097 (Try_run must only be used if toolstate is populated) - #73169 (Handle assembler warnings properly) - #73182 (Track span of function in method calls, and use this in #[track_caller]) - #73207 (Clean up E0648 explanation) - #73230 (Suggest including unused asm arguments in a comment to avoid error) Failed merges: r? @ghost
2 parents 50c0192 + 8650df5 commit a37c32e

File tree

118 files changed

+534
-232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+534
-232
lines changed

src/bootstrap/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ impl Step for Clippy {
553553

554554
builder.add_rustc_lib_path(compiler, &mut cargo);
555555

556-
try_run(builder, &mut cargo.into());
556+
builder.run(&mut cargo.into());
557557
}
558558
}
559559

src/doc/unstable-book/src/library-features/asm.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fn mul(a: u64, b: u64) -> u128 {
201201
);
202202
}
203203
204-
(hi as u128) << 64 + lo as u128
204+
((hi as u128) << 64) + lo as u128
205205
}
206206
```
207207

@@ -382,7 +382,9 @@ The macro will initially be supported only on ARM, AArch64, x86, x86-64 and RISC
382382

383383
The assembler template uses the same syntax as [format strings][format-syntax] (i.e. placeholders are specified by curly braces). The corresponding arguments are accessed in order, by index, or by name. However, implicit named arguments (introduced by [RFC #2795][rfc-2795]) are not supported.
384384

385-
As with format strings, named arguments must appear after positional arguments. Explicit register operands must appear at the end of the operand list, after any named arguments if any. Explicit register operands cannot be used by placeholders in the template string. All other operands must appear at least once in the template string, otherwise a compiler error is generated.
385+
As with format strings, named arguments must appear after positional arguments. Explicit register operands must appear at the end of the operand list, after named arguments if any.
386+
387+
Explicit register operands cannot be used by placeholders in the template string. All other named and positional operands must appear at least once in the template string, otherwise a compiler error is generated.
386388

387389
The exact assembly code syntax is target-specific and opaque to the compiler except for the way operands are substituted into the template string to form the code passed to the assembler.
388390

src/librustc_ast/ast.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,9 @@ pub enum ExprKind {
11741174
/// and the remaining elements are the rest of the arguments.
11751175
/// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as
11761176
/// `ExprKind::MethodCall(PathSegment { foo, [Bar, Baz] }, [x, a, b, c, d])`.
1177-
MethodCall(PathSegment, Vec<P<Expr>>),
1177+
/// This `Span` is the span of the function, without the dot and receiver
1178+
/// (e.g. `foo(a, b)` in `x.foo(a, b)`
1179+
MethodCall(PathSegment, Vec<P<Expr>>, Span),
11781180
/// A tuple (e.g., `(a, b, c, d)`).
11791181
Tup(Vec<P<Expr>>),
11801182
/// A binary operation (e.g., `a + b`, `a * b`).

src/librustc_ast/mut_visit.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1111,11 +1111,12 @@ pub fn noop_visit_expr<T: MutVisitor>(
11111111
vis.visit_expr(f);
11121112
visit_exprs(args, vis);
11131113
}
1114-
ExprKind::MethodCall(PathSegment { ident, id, args }, exprs) => {
1114+
ExprKind::MethodCall(PathSegment { ident, id, args }, exprs, span) => {
11151115
vis.visit_ident(ident);
11161116
vis.visit_id(id);
11171117
visit_opt(args, |args| vis.visit_generic_args(args));
11181118
visit_exprs(exprs, vis);
1119+
vis.visit_span(span);
11191120
}
11201121
ExprKind::Binary(_binop, lhs, rhs) => {
11211122
vis.visit_expr(lhs);

src/librustc_ast/util/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
394394
contains_exterior_struct_lit(&x)
395395
}
396396

397-
ast::ExprKind::MethodCall(.., ref exprs) => {
397+
ast::ExprKind::MethodCall(.., ref exprs, _) => {
398398
// X { y: 1 }.bar(...)
399399
contains_exterior_struct_lit(&exprs[0])
400400
}

src/librustc_ast/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
726726
visitor.visit_expr(callee_expression);
727727
walk_list!(visitor, visit_expr, arguments);
728728
}
729-
ExprKind::MethodCall(ref segment, ref arguments) => {
729+
ExprKind::MethodCall(ref segment, ref arguments, _span) => {
730730
visitor.visit_path_segment(expression.span, segment);
731731
walk_list!(visitor, visit_expr, arguments);
732732
}

src/librustc_ast_lowering/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
3939
let f = self.lower_expr(f);
4040
hir::ExprKind::Call(f, self.lower_exprs(args))
4141
}
42-
ExprKind::MethodCall(ref seg, ref args) => {
42+
ExprKind::MethodCall(ref seg, ref args, span) => {
4343
let hir_seg = self.arena.alloc(self.lower_path_segment(
4444
e.span,
4545
seg,
@@ -50,7 +50,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
5050
None,
5151
));
5252
let args = self.lower_exprs(args);
53-
hir::ExprKind::MethodCall(hir_seg, seg.ident.span, args)
53+
hir::ExprKind::MethodCall(hir_seg, seg.ident.span, args, span)
5454
}
5555
ExprKind::Binary(binop, ref lhs, ref rhs) => {
5656
let binop = self.lower_binop(binop);

src/librustc_ast_pretty/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ impl<'a> State<'a> {
18181818
ast::ExprKind::Call(ref func, ref args) => {
18191819
self.print_expr_call(func, &args[..]);
18201820
}
1821-
ast::ExprKind::MethodCall(ref segment, ref args) => {
1821+
ast::ExprKind::MethodCall(ref segment, ref args, _) => {
18221822
self.print_expr_method_call(segment, &args[..]);
18231823
}
18241824
ast::ExprKind::Binary(op, ref lhs, ref rhs) => {

src/librustc_builtin_macros/asm.rs

+29-18
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
391391
used[*pos] = true;
392392
}
393393

394-
let named_pos: FxHashSet<usize> = args.named_args.values().cloned().collect();
394+
let named_pos: FxHashMap<usize, Symbol> =
395+
args.named_args.iter().map(|(&sym, &idx)| (idx, sym)).collect();
395396
let mut arg_spans = parser.arg_places.iter().map(|span| template_span.from_inner(*span));
396397
let mut template = vec![];
397398
for piece in unverified_pieces {
@@ -405,7 +406,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
405406
let operand_idx = match arg.position {
406407
parse::ArgumentIs(idx) | parse::ArgumentImplicitlyIs(idx) => {
407408
if idx >= args.operands.len()
408-
|| named_pos.contains(&idx)
409+
|| named_pos.contains_key(&idx)
409410
|| args.reg_args.contains(&idx)
410411
{
411412
let msg = format!("invalid reference to argument at index {}", idx);
@@ -426,7 +427,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
426427
};
427428
err.note(&msg);
428429

429-
if named_pos.contains(&idx) {
430+
if named_pos.contains_key(&idx) {
430431
err.span_label(args.operands[idx].1, "named argument");
431432
err.span_note(
432433
args.operands[idx].1,
@@ -480,27 +481,31 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
480481
}
481482
}
482483

483-
let operands = args.operands;
484-
let unused_operands: Vec<_> = used
485-
.into_iter()
486-
.enumerate()
487-
.filter(|&(_, used)| !used)
488-
.map(|(idx, _)| {
489-
if named_pos.contains(&idx) {
490-
// named argument
491-
(operands[idx].1, "named argument never used")
484+
let mut unused_operands = vec![];
485+
let mut help_str = String::new();
486+
for (idx, used) in used.into_iter().enumerate() {
487+
if !used {
488+
let msg = if let Some(sym) = named_pos.get(&idx) {
489+
help_str.push_str(&format!(" {{{}}}", sym));
490+
"named argument never used"
492491
} else {
493-
// positional argument
494-
(operands[idx].1, "argument never used")
495-
}
496-
})
497-
.collect();
492+
help_str.push_str(&format!(" {{{}}}", idx));
493+
"argument never used"
494+
};
495+
unused_operands.push((args.operands[idx].1, msg));
496+
}
497+
}
498498
match unused_operands.len() {
499499
0 => {}
500500
1 => {
501501
let (sp, msg) = unused_operands.into_iter().next().unwrap();
502502
let mut err = ecx.struct_span_err(sp, msg);
503503
err.span_label(sp, msg);
504+
err.help(&format!(
505+
"if this argument is intentionally unused, \
506+
consider using it in an asm comment: `\"/*{} */\"`",
507+
help_str
508+
));
504509
err.emit();
505510
}
506511
_ => {
@@ -511,6 +516,11 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
511516
for (sp, msg) in unused_operands {
512517
err.span_label(sp, msg);
513518
}
519+
err.help(&format!(
520+
"if these arguments are intentionally unused, \
521+
consider using them in an asm comment: `\"/*{} */\"`",
522+
help_str
523+
));
514524
err.emit();
515525
}
516526
}
@@ -521,7 +531,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
521531
parser.line_spans.iter().map(|span| template_span.from_inner(*span)).collect()
522532
};
523533

524-
let inline_asm = ast::InlineAsm { template, operands, options: args.options, line_spans };
534+
let inline_asm =
535+
ast::InlineAsm { template, operands: args.operands, options: args.options, line_spans };
525536
P(ast::Expr {
526537
id: ast::DUMMY_NODE_ID,
527538
kind: ast::ExprKind::InlineAsm(P(inline_asm)),

src/librustc_codegen_llvm/back/write.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, Mo
1616
use rustc_codegen_ssa::traits::*;
1717
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
1818
use rustc_data_structures::small_c_str::SmallCStr;
19-
use rustc_errors::{FatalError, Handler};
19+
use rustc_errors::{FatalError, Handler, Level};
2020
use rustc_fs_util::{link_or_copy, path_to_c_string};
2121
use rustc_hir::def_id::LOCAL_CRATE;
2222
use rustc_middle::bug;
@@ -242,6 +242,7 @@ impl<'a> Drop for DiagnosticHandlers<'a> {
242242
fn report_inline_asm(
243243
cgcx: &CodegenContext<LlvmCodegenBackend>,
244244
msg: String,
245+
level: llvm::DiagnosticLevel,
245246
mut cookie: c_uint,
246247
source: Option<(String, Vec<InnerSpan>)>,
247248
) {
@@ -251,7 +252,12 @@ fn report_inline_asm(
251252
if matches!(cgcx.lto, Lto::Fat | Lto::Thin) {
252253
cookie = 0;
253254
}
254-
cgcx.diag_emitter.inline_asm_error(cookie as u32, msg, source);
255+
let level = match level {
256+
llvm::DiagnosticLevel::Error => Level::Error,
257+
llvm::DiagnosticLevel::Warning => Level::Warning,
258+
llvm::DiagnosticLevel::Note | llvm::DiagnosticLevel::Remark => Level::Note,
259+
};
260+
cgcx.diag_emitter.inline_asm_error(cookie as u32, msg, level, source);
255261
}
256262

257263
unsafe extern "C" fn inline_asm_handler(diag: &SMDiagnostic, user: *const c_void, cookie: c_uint) {
@@ -264,6 +270,7 @@ unsafe extern "C" fn inline_asm_handler(diag: &SMDiagnostic, user: *const c_void
264270
// diagnostics.
265271
let mut have_source = false;
266272
let mut buffer = String::new();
273+
let mut level = llvm::DiagnosticLevel::Error;
267274
let mut loc = 0;
268275
let mut ranges = [0; 8];
269276
let mut num_ranges = ranges.len() / 2;
@@ -273,6 +280,7 @@ unsafe extern "C" fn inline_asm_handler(diag: &SMDiagnostic, user: *const c_void
273280
diag,
274281
msg,
275282
buffer,
283+
&mut level,
276284
&mut loc,
277285
ranges.as_mut_ptr(),
278286
&mut num_ranges,
@@ -290,7 +298,7 @@ unsafe extern "C" fn inline_asm_handler(diag: &SMDiagnostic, user: *const c_void
290298
(buffer, spans)
291299
});
292300

293-
report_inline_asm(cgcx, msg, cookie, source);
301+
report_inline_asm(cgcx, msg, level, cookie, source);
294302
}
295303

296304
unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void) {
@@ -301,7 +309,13 @@ unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void
301309

302310
match llvm::diagnostic::Diagnostic::unpack(info) {
303311
llvm::diagnostic::InlineAsm(inline) => {
304-
report_inline_asm(cgcx, llvm::twine_to_string(inline.message), inline.cookie, None);
312+
report_inline_asm(
313+
cgcx,
314+
llvm::twine_to_string(inline.message),
315+
inline.level,
316+
inline.cookie,
317+
None,
318+
);
305319
}
306320

307321
llvm::diagnostic::Optimization(opt) => {

src/librustc_codegen_llvm/llvm/diagnostic.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ impl OptimizationDiagnostic<'ll> {
8888

8989
#[derive(Copy, Clone)]
9090
pub struct InlineAsmDiagnostic<'ll> {
91+
pub level: super::DiagnosticLevel,
9192
pub cookie: c_uint,
9293
pub message: &'ll Twine,
9394
pub instruction: Option<&'ll Value>,
@@ -98,10 +99,17 @@ impl InlineAsmDiagnostic<'ll> {
9899
let mut cookie = 0;
99100
let mut message = None;
100101
let mut instruction = None;
102+
let mut level = super::DiagnosticLevel::Error;
101103

102-
super::LLVMRustUnpackInlineAsmDiagnostic(di, &mut cookie, &mut message, &mut instruction);
104+
super::LLVMRustUnpackInlineAsmDiagnostic(
105+
di,
106+
&mut level,
107+
&mut cookie,
108+
&mut message,
109+
&mut instruction,
110+
);
103111

104-
InlineAsmDiagnostic { cookie, message: message.unwrap(), instruction }
112+
InlineAsmDiagnostic { level, cookie, message: message.unwrap(), instruction }
105113
}
106114
}
107115

src/librustc_codegen_llvm/llvm/ffi.rs

+13
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,17 @@ pub enum DiagnosticKind {
489489
Linker,
490490
}
491491

492+
/// LLVMRustDiagnosticLevel
493+
#[derive(Copy, Clone)]
494+
#[repr(C)]
495+
#[allow(dead_code)] // Variants constructed by C++.
496+
pub enum DiagnosticLevel {
497+
Error,
498+
Warning,
499+
Note,
500+
Remark,
501+
}
502+
492503
/// LLVMRustArchiveKind
493504
#[derive(Copy, Clone)]
494505
#[repr(C)]
@@ -2054,6 +2065,7 @@ extern "C" {
20542065

20552066
pub fn LLVMRustUnpackInlineAsmDiagnostic(
20562067
DI: &'a DiagnosticInfo,
2068+
level_out: &mut DiagnosticLevel,
20572069
cookie_out: &mut c_uint,
20582070
message_out: &mut Option<&'a Twine>,
20592071
instruction_out: &mut Option<&'a Value>,
@@ -2074,6 +2086,7 @@ extern "C" {
20742086
d: &SMDiagnostic,
20752087
message_out: &RustString,
20762088
buffer_out: &RustString,
2089+
level_out: &mut DiagnosticLevel,
20772090
loc_out: &mut c_uint,
20782091
ranges_out: *mut c_uint,
20792092
num_ranges: &mut usize,

src/librustc_codegen_ssa/back/write.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
15511551

15521552
enum SharedEmitterMessage {
15531553
Diagnostic(Diagnostic),
1554-
InlineAsmError(u32, String, Option<(String, Vec<InnerSpan>)>),
1554+
InlineAsmError(u32, String, Level, Option<(String, Vec<InnerSpan>)>),
15551555
AbortIfErrors,
15561556
Fatal(String),
15571557
}
@@ -1576,9 +1576,10 @@ impl SharedEmitter {
15761576
&self,
15771577
cookie: u32,
15781578
msg: String,
1579+
level: Level,
15791580
source: Option<(String, Vec<InnerSpan>)>,
15801581
) {
1581-
drop(self.sender.send(SharedEmitterMessage::InlineAsmError(cookie, msg, source)));
1582+
drop(self.sender.send(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)));
15821583
}
15831584

15841585
pub fn fatal(&self, msg: &str) {
@@ -1631,16 +1632,21 @@ impl SharedEmitterMain {
16311632
}
16321633
handler.emit_diagnostic(&d);
16331634
}
1634-
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, source)) => {
1635+
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
16351636
let msg = msg.strip_prefix("error: ").unwrap_or(&msg);
16361637

1638+
let mut err = match level {
1639+
Level::Error => sess.struct_err(&msg),
1640+
Level::Warning => sess.struct_warn(&msg),
1641+
Level::Note => sess.struct_note_without_error(&msg),
1642+
_ => bug!("Invalid inline asm diagnostic level"),
1643+
};
1644+
16371645
// If the cookie is 0 then we don't have span information.
1638-
let mut err = if cookie == 0 {
1639-
sess.struct_err(&msg)
1640-
} else {
1646+
if cookie != 0 {
16411647
let pos = BytePos::from_u32(cookie);
16421648
let span = Span::with_root_ctxt(pos, pos);
1643-
sess.struct_span_err(span, &msg)
1649+
err.set_span(span);
16441650
};
16451651

16461652
// Point to the generated assembly if it is available.

0 commit comments

Comments
 (0)