diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index edc9c5a9130a6..e8689b638e6bc 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -796,9 +796,15 @@ impl SyntaxExtension { /// | external | no | if-ext | if-ext | yes | /// | yes | yes | yes | yes | yes | fn get_collapse_debuginfo(sess: &Session, attrs: &[ast::Attribute], is_local: bool) -> bool { - let collapse_debuginfo_attr = attr::find_by_name(attrs, sym::collapse_debuginfo) + let mut collapse_debuginfo_attr = attr::find_by_name(attrs, sym::collapse_debuginfo) .map(|v| Self::collapse_debuginfo_by_name(sess, v)) .unwrap_or(CollapseMacroDebuginfo::Unspecified); + if collapse_debuginfo_attr == CollapseMacroDebuginfo::Unspecified + && attr::contains_name(attrs, sym::rustc_builtin_macro) + { + collapse_debuginfo_attr = CollapseMacroDebuginfo::Yes; + } + let flag = sess.opts.unstable_opts.collapse_macro_debuginfo; let attr = collapse_debuginfo_attr; let ext = !is_local; diff --git a/tests/debuginfo/collapse-debuginfo-builtin.rs b/tests/debuginfo/collapse-debuginfo-builtin.rs new file mode 100644 index 0000000000000..e63f28477a3b1 --- /dev/null +++ b/tests/debuginfo/collapse-debuginfo-builtin.rs @@ -0,0 +1,32 @@ +// ignore-lldb +#![feature(collapse_debuginfo)] + +use std::fmt; + +// Test that builtin macro debug info is collapsed. +// Debug info for format_args must be #format_arg_external, not #format_arg_internal. +// Because format_args is a builtin macro. +// compile-flags:-g + +// === GDB TESTS =================================================================================== + +// gdb-command:run +// gdb-command:next 2 +// gdb-command:frame +// gdb-check:[...]#format_arg_external[...] +// gdb-command:continue + +fn main() { + let ret = 0; // #break + let w = "world".to_string(); + let s = fmt::format( + format_args!( // #format_arg_external + "hello {}", w // #format_arg_internal + ) + ); // #format_callsite + println!( + "{}", + s + ); // #println_callsite + std::process::exit(ret); +}