Skip to content

Commit f2824da

Browse files
committed
Auto merge of #145970 - GuillaumeGomez:rollup-pr11qds, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - #142472 (Add new `doc(attribute = "...")` attribute) - #145368 (CFI: Make `lto` and `linker-plugin-lto` work the same for `compiler_builtins`) - #145853 (Improve error messages around invalid literals in attribute arguments) - #145920 (bootstrap: Explicitly mark the end of a failed test's captured output) - #145937 (add doc-hidden to exports in attribute prelude) - #145965 (Move exporting of profiler and sanitizer symbols to the LLVM backend) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 35d55b3 + a60b96a commit f2824da

File tree

53 files changed

+514
-194
lines changed

Some content is hidden

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

53 files changed

+514
-194
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
188188
notable_trait => doc_notable_trait
189189
}
190190
"meant for internal use only" {
191+
attribute => rustdoc_internals
191192
keyword => rustdoc_internals
192193
fake_variadic => rustdoc_internals
193194
search_unbox => rustdoc_internals
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
// parsing
21
// templates
2+
#[doc(hidden)]
33
pub(super) use rustc_feature::{AttributeTemplate, template};
44
// data structures
5+
#[doc(hidden)]
56
pub(super) use rustc_hir::attrs::AttributeKind;
7+
#[doc(hidden)]
68
pub(super) use rustc_hir::lints::AttributeLintKind;
9+
#[doc(hidden)]
710
pub(super) use rustc_hir::{MethodKind, Target};
11+
#[doc(hidden)]
812
pub(super) use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym};
13+
#[doc(hidden)]
914
pub(super) use thin_vec::ThinVec;
1015

16+
#[doc(hidden)]
1117
pub(super) use crate::attributes::{
1218
AcceptMapping, AttributeOrder, AttributeParser, CombineAttributeParser, ConvertFn,
1319
NoArgsAttributeParser, OnDuplicate, SingleAttributeParser,
1420
};
1521
// contexts
22+
#[doc(hidden)]
1623
pub(super) use crate::context::{AcceptContext, FinalizeContext, Stage};
24+
#[doc(hidden)]
1725
pub(super) use crate::parser::*;
1826
// target checking
27+
#[doc(hidden)]
1928
pub(super) use crate::target_checking::Policy::{Allow, Error, Warn};
29+
#[doc(hidden)]
2030
pub(super) use crate::target_checking::{ALL_TARGETS, AllowedTargets};

compiler/rustc_attr_parsing/src/parser.rs

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use rustc_ast::token::{self, Delimiter, MetaVarKind};
1010
use rustc_ast::tokenstream::TokenStream;
1111
use rustc_ast::{AttrArgs, DelimArgs, Expr, ExprKind, LitKind, MetaItemLit, NormalAttr, Path};
1212
use rustc_ast_pretty::pprust;
13-
use rustc_errors::PResult;
13+
use rustc_errors::{Diag, PResult};
1414
use rustc_hir::{self as hir, AttrPath};
1515
use rustc_parse::exp;
1616
use rustc_parse::parser::{Parser, PathStyle, token_descr};
17-
use rustc_session::errors::report_lit_error;
17+
use rustc_session::errors::{create_lit_error, report_lit_error};
1818
use rustc_session::parse::ParseSess;
1919
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, sym};
2020
use thin_vec::ThinVec;
@@ -379,22 +379,23 @@ struct MetaItemListParserContext<'a, 'sess> {
379379

380380
impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
381381
fn parse_unsuffixed_meta_item_lit(&mut self) -> PResult<'sess, MetaItemLit> {
382-
let uninterpolated_span = self.parser.token_uninterpolated_span();
383-
let Some(token_lit) = self.parser.eat_token_lit() else {
384-
return self.parser.handle_missing_lit(Parser::mk_meta_item_lit_char);
385-
};
382+
let Some(token_lit) = self.parser.eat_token_lit() else { return Err(self.expected_lit()) };
383+
self.unsuffixed_meta_item_from_lit(token_lit)
384+
}
386385

386+
fn unsuffixed_meta_item_from_lit(
387+
&mut self,
388+
token_lit: token::Lit,
389+
) -> PResult<'sess, MetaItemLit> {
387390
let lit = match MetaItemLit::from_token_lit(token_lit, self.parser.prev_token.span) {
388391
Ok(lit) => lit,
389392
Err(err) => {
390-
let guar =
391-
report_lit_error(&self.parser.psess, err, token_lit, uninterpolated_span);
392-
// Pack possible quotes and prefixes from the original literal into
393-
// the error literal's symbol so they can be pretty-printed faithfully.
394-
let suffixless_lit = token::Lit::new(token_lit.kind, token_lit.symbol, None);
395-
let symbol = Symbol::intern(&suffixless_lit.to_string());
396-
let token_lit = token::Lit::new(token::Err(guar), symbol, token_lit.suffix);
397-
MetaItemLit::from_token_lit(token_lit, uninterpolated_span).unwrap()
393+
return Err(create_lit_error(
394+
&self.parser.psess,
395+
err,
396+
token_lit,
397+
self.parser.prev_token_uninterpolated_span(),
398+
));
398399
}
399400
};
400401

@@ -448,16 +449,28 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
448449
}
449450

450451
fn parse_meta_item_inner(&mut self) -> PResult<'sess, MetaItemOrLitParser<'static>> {
451-
match self.parse_unsuffixed_meta_item_lit() {
452-
Ok(lit) => return Ok(MetaItemOrLitParser::Lit(lit)),
453-
Err(err) => err.cancel(), // we provide a better error below
454-
}
455-
456-
match self.parse_attr_item() {
457-
Ok(mi) => return Ok(MetaItemOrLitParser::MetaItemParser(mi)),
458-
Err(err) => err.cancel(), // we provide a better error below
452+
if let Some(token_lit) = self.parser.eat_token_lit() {
453+
// If a literal token is parsed, we commit to parsing a MetaItemLit for better errors
454+
Ok(MetaItemOrLitParser::Lit(self.unsuffixed_meta_item_from_lit(token_lit)?))
455+
} else {
456+
let prev_pros = self.parser.approx_token_stream_pos();
457+
match self.parse_attr_item() {
458+
Ok(item) => Ok(MetaItemOrLitParser::MetaItemParser(item)),
459+
Err(err) => {
460+
// If `parse_attr_item` made any progress, it likely has a more precise error we should prefer
461+
// If it didn't make progress we use the `expected_lit` from below
462+
if self.parser.approx_token_stream_pos() != prev_pros {
463+
Err(err)
464+
} else {
465+
err.cancel();
466+
Err(self.expected_lit())
467+
}
468+
}
469+
}
459470
}
471+
}
460472

473+
fn expected_lit(&mut self) -> Diag<'sess> {
461474
let mut err = InvalidMetaItem {
462475
span: self.parser.token.span,
463476
descr: token_descr(&self.parser.token),
@@ -492,7 +505,7 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
492505
self.parser.bump();
493506
}
494507

495-
Err(self.parser.dcx().create_err(err))
508+
self.parser.dcx().create_err(err)
496509
}
497510

498511
fn parse(

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_codegen_ssa::{ModuleCodegen, ModuleKind, looks_like_rust_object_file};
1515
use rustc_data_structures::fx::FxHashMap;
1616
use rustc_data_structures::memmap::Mmap;
1717
use rustc_errors::DiagCtxtHandle;
18+
use rustc_hir::attrs::SanitizerSet;
1819
use rustc_middle::bug;
1920
use rustc_middle::dep_graph::WorkProduct;
2021
use rustc_session::config::{self, Lto};
@@ -42,6 +43,37 @@ fn prepare_lto(
4243
.map(|symbol| CString::new(symbol.to_owned()).unwrap())
4344
.collect::<Vec<CString>>();
4445

46+
if cgcx.regular_module_config.instrument_coverage
47+
|| cgcx.regular_module_config.pgo_gen.enabled()
48+
{
49+
// These are weak symbols that point to the profile version and the
50+
// profile name, which need to be treated as exported so LTO doesn't nix
51+
// them.
52+
const PROFILER_WEAK_SYMBOLS: [&CStr; 2] =
53+
[c"__llvm_profile_raw_version", c"__llvm_profile_filename"];
54+
55+
symbols_below_threshold.extend(PROFILER_WEAK_SYMBOLS.iter().map(|&sym| sym.to_owned()));
56+
}
57+
58+
if cgcx.regular_module_config.sanitizer.contains(SanitizerSet::MEMORY) {
59+
let mut msan_weak_symbols = Vec::new();
60+
61+
// Similar to profiling, preserve weak msan symbol during LTO.
62+
if cgcx.regular_module_config.sanitizer_recover.contains(SanitizerSet::MEMORY) {
63+
msan_weak_symbols.push(c"__msan_keep_going");
64+
}
65+
66+
if cgcx.regular_module_config.sanitizer_memory_track_origins != 0 {
67+
msan_weak_symbols.push(c"__msan_track_origins");
68+
}
69+
70+
symbols_below_threshold.extend(msan_weak_symbols.into_iter().map(|sym| sym.to_owned()));
71+
}
72+
73+
// Preserve LLVM-injected, ASAN-related symbols.
74+
// See also https://github.com/rust-lang/rust/issues/113404.
75+
symbols_below_threshold.push(c"___asan_globals_registered".to_owned());
76+
4577
// __llvm_profile_counter_bias is pulled in at link time by an undefined reference to
4678
// __llvm_profile_runtime, therefore we won't know until link time if this symbol
4779
// should have default visibility.

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, Instance, SymbolNam
1515
use rustc_middle::util::Providers;
1616
use rustc_session::config::{CrateType, OomStrategy};
1717
use rustc_symbol_mangling::mangle_internal_symbol;
18-
use rustc_target::spec::{SanitizerSet, TlsModel};
18+
use rustc_target::spec::TlsModel;
1919
use tracing::debug;
2020

2121
use crate::base::allocator_kind_for_codegen;
@@ -242,53 +242,6 @@ fn exported_non_generic_symbols_provider_local<'tcx>(
242242
}
243243
}
244244

245-
if tcx.sess.instrument_coverage() || tcx.sess.opts.cg.profile_generate.enabled() {
246-
// These are weak symbols that point to the profile version and the
247-
// profile name, which need to be treated as exported so LTO doesn't nix
248-
// them.
249-
const PROFILER_WEAK_SYMBOLS: [&str; 2] =
250-
["__llvm_profile_raw_version", "__llvm_profile_filename"];
251-
252-
symbols.extend(PROFILER_WEAK_SYMBOLS.iter().map(|sym| {
253-
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
254-
(
255-
exported_symbol,
256-
SymbolExportInfo {
257-
level: SymbolExportLevel::C,
258-
kind: SymbolExportKind::Data,
259-
used: false,
260-
rustc_std_internal_symbol: false,
261-
},
262-
)
263-
}));
264-
}
265-
266-
if tcx.sess.opts.unstable_opts.sanitizer.contains(SanitizerSet::MEMORY) {
267-
let mut msan_weak_symbols = Vec::new();
268-
269-
// Similar to profiling, preserve weak msan symbol during LTO.
270-
if tcx.sess.opts.unstable_opts.sanitizer_recover.contains(SanitizerSet::MEMORY) {
271-
msan_weak_symbols.push("__msan_keep_going");
272-
}
273-
274-
if tcx.sess.opts.unstable_opts.sanitizer_memory_track_origins != 0 {
275-
msan_weak_symbols.push("__msan_track_origins");
276-
}
277-
278-
symbols.extend(msan_weak_symbols.into_iter().map(|sym| {
279-
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
280-
(
281-
exported_symbol,
282-
SymbolExportInfo {
283-
level: SymbolExportLevel::C,
284-
kind: SymbolExportKind::Data,
285-
used: false,
286-
rustc_std_internal_symbol: false,
287-
},
288-
)
289-
}));
290-
}
291-
292245
// Sort so we get a stable incr. comp. hash.
293246
symbols.sort_by_cached_key(|s| s.0.symbol_name_for_local_instance(tcx));
294247

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,12 @@ impl ModuleConfig {
138138

139139
let emit_obj = if !should_emit_obj {
140140
EmitObj::None
141-
} else if sess.target.obj_is_bitcode
142-
|| (sess.opts.cg.linker_plugin_lto.enabled() && !no_builtins)
143-
{
141+
} else if sess.target.obj_is_bitcode || sess.opts.cg.linker_plugin_lto.enabled() {
144142
// This case is selected if the target uses objects as bitcode, or
145143
// if linker plugin LTO is enabled. In the linker plugin LTO case
146144
// the assumption is that the final link-step will read the bitcode
147145
// and convert it to object code. This may be done by either the
148146
// native linker or rustc itself.
149-
//
150-
// Note, however, that the linker-plugin-lto requested here is
151-
// explicitly ignored for `#![no_builtins]` crates. These crates are
152-
// specifically ignored by rustc's LTO passes and wouldn't work if
153-
// loaded into the linker. These crates define symbols that LLVM
154-
// lowers intrinsics to, and these symbol dependencies aren't known
155-
// until after codegen. As a result any crate marked
156-
// `#![no_builtins]` is assumed to not participate in LTO and
157-
// instead goes on to generate object code.
158147
EmitObj::Bitcode
159148
} else if need_bitcode_in_object(tcx) {
160149
EmitObj::ObjectCode(BitcodeSection::Full)

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,12 +1226,6 @@ extern "C" void LLVMRustPrintPasses() {
12261226
extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols,
12271227
size_t Len) {
12281228
auto PreserveFunctions = [=](const GlobalValue &GV) {
1229-
// Preserve LLVM-injected, ASAN-related symbols.
1230-
// See also https://github.com/rust-lang/rust/issues/113404.
1231-
if (GV.getName() == "___asan_globals_registered") {
1232-
return true;
1233-
}
1234-
12351229
// Preserve symbols exported from Rust modules.
12361230
for (size_t I = 0; I < Len; I++) {
12371231
if (GV.getName() == Symbols[I]) {

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,7 @@ impl<'a> Parser<'a> {
20772077
(token::Lit { symbol: name, suffix: None, kind: token::Char }, span)
20782078
}
20792079

2080-
pub fn mk_meta_item_lit_char(name: Symbol, span: Span) -> MetaItemLit {
2080+
fn mk_meta_item_lit_char(name: Symbol, span: Span) -> MetaItemLit {
20812081
ast::MetaItemLit {
20822082
symbol: name,
20832083
suffix: None,
@@ -2086,7 +2086,7 @@ impl<'a> Parser<'a> {
20862086
}
20872087
}
20882088

2089-
pub fn handle_missing_lit<L>(
2089+
fn handle_missing_lit<L>(
20902090
&mut self,
20912091
mk_lit_char: impl FnOnce(Symbol, Span) -> L,
20922092
) -> PResult<'a, L> {

compiler/rustc_passes/messages.ftl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ passes_doc_alias_start_end =
145145
passes_doc_attr_not_crate_level =
146146
`#![doc({$attr_name} = "...")]` isn't allowed as a crate-level attribute
147147
148+
passes_doc_attribute_not_attribute =
149+
nonexistent builtin attribute `{$attribute}` used in `#[doc(attribute = "...")]`
150+
.help = only existing builtin attributes are allowed in core/std
151+
148152
passes_doc_cfg_hide_takes_list =
149153
`#[doc(cfg_hide(...))]` takes a list of attributes
150154
@@ -173,16 +177,16 @@ passes_doc_inline_only_use =
173177
passes_doc_invalid =
174178
invalid `doc` attribute
175179
176-
passes_doc_keyword_empty_mod =
177-
`#[doc(keyword = "...")]` should be used on empty modules
180+
passes_doc_keyword_attribute_empty_mod =
181+
`#[doc({$attr_name} = "...")]` should be used on empty modules
182+
183+
passes_doc_keyword_attribute_not_mod =
184+
`#[doc({$attr_name} = "...")]` should be used on modules
178185
179186
passes_doc_keyword_not_keyword =
180187
nonexistent keyword `{$keyword}` used in `#[doc(keyword = "...")]`
181188
.help = only existing keywords are allowed in core/std
182189
183-
passes_doc_keyword_not_mod =
184-
`#[doc(keyword = "...")]` should be used on modules
185-
186190
passes_doc_keyword_only_impl =
187191
`#[doc(keyword = "...")]` should be used on impl blocks
188192

0 commit comments

Comments
 (0)