Skip to content

Commit 5e1d329

Browse files
committed
Auto merge of #109824 - GuillaumeGomez:rollup-i5r4uts, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - #109104 (rustdoc: Fix invalid suggestions on ambiguous intra doc links v2) - #109443 (Move `doc(primitive)` future incompat warning to `invalid_doc_attributes`) - #109680 (Fix subslice capture in closure) - #109798 (fluent_messages macro: don't emit the OS error in a note) - #109805 (Source map cleanups) - #109818 (rustdoc: Add GUI test for jump to collapsed item) - #109820 (rustdoc-search: update docs for comma in `?` help popover) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7402519 + 083c128 commit 5e1d329

File tree

83 files changed

+1024
-410
lines changed

Some content is hidden

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

83 files changed

+1024
-410
lines changed

compiler/rustc_expand/src/proc_macro.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl base::BangProcMacro for BangProcMacro {
5454
) -> Result<TokenStream, ErrorGuaranteed> {
5555
let _timer =
5656
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
57-
recorder.record_arg_with_span(ecx.expansion_descr(), span);
57+
recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span);
5858
});
5959

6060
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
@@ -85,7 +85,7 @@ impl base::AttrProcMacro for AttrProcMacro {
8585
) -> Result<TokenStream, ErrorGuaranteed> {
8686
let _timer =
8787
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
88-
recorder.record_arg_with_span(ecx.expansion_descr(), span);
88+
recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span);
8989
});
9090

9191
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
@@ -134,7 +134,11 @@ impl MultiItemModifier for DeriveProcMacro {
134134
let stream = {
135135
let _timer =
136136
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
137-
recorder.record_arg_with_span(ecx.expansion_descr(), span);
137+
recorder.record_arg_with_span(
138+
ecx.sess.source_map(),
139+
ecx.expansion_descr(),
140+
span,
141+
);
138142
});
139143
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
140144
let strategy = exec_strategy(ecx);

compiler/rustc_feature/src/active.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ declare_features! (
225225
(active, rustc_allow_const_fn_unstable, "1.49.0", Some(69399), None),
226226
/// Allows using compiler's own crates.
227227
(active, rustc_private, "1.0.0", Some(27812), None),
228-
/// Allows using internal rustdoc features like `doc(primitive)` or `doc(keyword)`.
228+
/// Allows using internal rustdoc features like `doc(keyword)`.
229229
(active, rustdoc_internals, "1.58.0", Some(90418), None),
230230
/// Allows using the `rustdoc::missing_doc_code_examples` lint
231231
(active, rustdoc_missing_doc_code_examples, "1.31.0", Some(101730), None),

compiler/rustc_feature/src/builtin_attrs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
778778
definition of a trait, it's currently in experimental form and should be changed before \
779779
being exposed outside of the std"
780780
),
781+
rustc_attr!(
782+
rustc_doc_primitive, Normal, template!(NameValueStr: "primitive name"), ErrorFollowing,
783+
r#"`rustc_doc_primitive` is a rustc internal attribute"#,
784+
),
781785

782786
// ==========================================================================
783787
// Internal attributes, Testing:

compiler/rustc_hir_typeck/src/upvar.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1893,14 +1893,13 @@ fn restrict_capture_precision(
18931893

18941894
for (i, proj) in place.projections.iter().enumerate() {
18951895
match proj.kind {
1896-
ProjectionKind::Index => {
1897-
// Arrays are completely captured, so we drop Index projections
1896+
ProjectionKind::Index | ProjectionKind::Subslice => {
1897+
// Arrays are completely captured, so we drop Index and Subslice projections
18981898
truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, i);
18991899
return (place, curr_mode);
19001900
}
19011901
ProjectionKind::Deref => {}
19021902
ProjectionKind::Field(..) => {} // ignore
1903-
ProjectionKind::Subslice => {} // We never capture this
19041903
}
19051904
}
19061905

compiler/rustc_interface/src/interface.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
292292
override_queries: config.override_queries,
293293
};
294294

295-
rustc_span::with_source_map(compiler.sess.parse_sess.clone_source_map(), move || {
295+
rustc_span::set_source_map(compiler.sess.parse_sess.clone_source_map(), move || {
296296
let r = {
297297
let _sess_abort_error = OnDrop(|| {
298298
compiler.sess.finish_diagnostics(registry);

compiler/rustc_macros/src/diagnostics/fluent.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use proc_macro2::TokenStream;
1515
use quote::quote;
1616
use std::{
1717
collections::{HashMap, HashSet},
18-
fs::File,
19-
io::Read,
18+
fs::read_to_string,
2019
path::{Path, PathBuf},
2120
};
2221
use syn::{parse_macro_input, Ident, LitStr};
@@ -95,22 +94,18 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
9594

9695
// As this macro also outputs an `include_str!` for this file, the macro will always be
9796
// re-executed when the file changes.
98-
let mut resource_file = match File::open(absolute_ftl_path) {
99-
Ok(resource_file) => resource_file,
97+
let resource_contents = match read_to_string(absolute_ftl_path) {
98+
Ok(resource_contents) => resource_contents,
10099
Err(e) => {
101-
Diagnostic::spanned(resource_span, Level::Error, "could not open Fluent resource")
102-
.note(e.to_string())
103-
.emit();
100+
Diagnostic::spanned(
101+
resource_span,
102+
Level::Error,
103+
format!("could not open Fluent resource: {}", e.to_string()),
104+
)
105+
.emit();
104106
return failed(&crate_name);
105107
}
106108
};
107-
let mut resource_contents = String::new();
108-
if let Err(e) = resource_file.read_to_string(&mut resource_contents) {
109-
Diagnostic::spanned(resource_span, Level::Error, "could not read Fluent resource")
110-
.note(e.to_string())
111-
.emit();
112-
return failed(&crate_name);
113-
}
114109
let mut bad = false;
115110
for esc in ["\\n", "\\\"", "\\'"] {
116111
for _ in resource_contents.matches(esc) {

compiler/rustc_passes/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ passes_doc_test_unknown =
148148
passes_doc_test_takes_list =
149149
`#[doc(test(...)]` takes a list of attributes
150150
151-
passes_doc_primitive =
152-
`doc(primitive)` should never have been stable
153-
154151
passes_doc_cfg_hide_takes_list =
155152
`#[doc(cfg_hide(...)]` takes a list of attributes
156153

compiler/rustc_passes/src/check_attr.rs

-11
Original file line numberDiff line numberDiff line change
@@ -1109,17 +1109,6 @@ impl CheckAttrVisitor<'_> {
11091109
}
11101110
}
11111111

1112-
sym::primitive => {
1113-
if !self.tcx.features().rustdoc_internals {
1114-
self.tcx.emit_spanned_lint(
1115-
INVALID_DOC_ATTRIBUTES,
1116-
hir_id,
1117-
i_meta.span,
1118-
errors::DocPrimitive,
1119-
);
1120-
}
1121-
}
1122-
11231112
_ => {
11241113
let path = rustc_ast_pretty::pprust::path_to_string(&i_meta.path);
11251114
if i_meta.has_name(sym::spotlight) {

compiler/rustc_passes/src/errors.rs

-4
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,6 @@ pub struct DocTestTakesList;
288288
#[diag(passes_doc_cfg_hide_takes_list)]
289289
pub struct DocCfgHideTakesList;
290290

291-
#[derive(LintDiagnostic)]
292-
#[diag(passes_doc_primitive)]
293-
pub struct DocPrimitive;
294-
295291
#[derive(LintDiagnostic)]
296292
#[diag(passes_doc_test_unknown_any)]
297293
pub struct DocTestUnknownAny {

compiler/rustc_resolve/src/rustdoc.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,14 @@ pub fn inner_docs(attrs: &[ast::Attribute]) -> bool {
339339
attrs.iter().find(|a| a.doc_str().is_some()).map_or(true, |a| a.style == ast::AttrStyle::Inner)
340340
}
341341

342-
/// Has `#[doc(primitive)]` or `#[doc(keyword)]`.
342+
/// Has `#[rustc_doc_primitive]` or `#[doc(keyword)]`.
343343
pub fn has_primitive_or_keyword_docs(attrs: &[ast::Attribute]) -> bool {
344344
for attr in attrs {
345-
if attr.has_name(sym::doc) && let Some(items) = attr.meta_item_list() {
345+
if attr.has_name(sym::rustc_doc_primitive) {
346+
return true;
347+
} else if attr.has_name(sym::doc) && let Some(items) = attr.meta_item_list() {
346348
for item in items {
347-
if item.has_name(sym::primitive) || item.has_name(sym::keyword) {
349+
if item.has_name(sym::keyword) {
348350
return true;
349351
}
350352
}

compiler/rustc_span/src/lib.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ pub struct SessionGlobals {
8787
symbol_interner: symbol::Interner,
8888
span_interner: Lock<span_encoding::SpanInterner>,
8989
hygiene_data: Lock<hygiene::HygieneData>,
90+
91+
/// A reference to the source map in the `Session`. It's an `Option`
92+
/// because it can't be initialized until `Session` is created, which
93+
/// happens after `SessionGlobals`. `set_source_map` does the
94+
/// initialization.
95+
///
96+
/// This field should only be used in places where the `Session` is truly
97+
/// not available, such as `<Span as Debug>::fmt`.
9098
source_map: Lock<Option<Lrc<SourceMap>>>,
9199
}
92100

@@ -1013,16 +1021,9 @@ impl<D: Decoder> Decodable<D> for Span {
10131021
}
10141022
}
10151023

1016-
/// Calls the provided closure, using the provided `SourceMap` to format
1017-
/// any spans that are debug-printed during the closure's execution.
1018-
///
1019-
/// Normally, the global `TyCtxt` is used to retrieve the `SourceMap`
1020-
/// (see `rustc_interface::callbacks::span_debug1`). However, some parts
1021-
/// of the compiler (e.g. `rustc_parse`) may debug-print `Span`s before
1022-
/// a `TyCtxt` is available. In this case, we fall back to
1023-
/// the `SourceMap` provided to this function. If that is not available,
1024-
/// we fall back to printing the raw `Span` field values.
1025-
pub fn with_source_map<T, F: FnOnce() -> T>(source_map: Lrc<SourceMap>, f: F) -> T {
1024+
/// Insert `source_map` into the session globals for the duration of the
1025+
/// closure's execution.
1026+
pub fn set_source_map<T, F: FnOnce() -> T>(source_map: Lrc<SourceMap>, f: F) -> T {
10261027
with_session_globals(|session_globals| {
10271028
*session_globals.source_map.borrow_mut() = Some(source_map);
10281029
});
@@ -1041,6 +1042,8 @@ pub fn with_source_map<T, F: FnOnce() -> T>(source_map: Lrc<SourceMap>, f: F) ->
10411042

10421043
impl fmt::Debug for Span {
10431044
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1045+
// Use the global `SourceMap` to print the span. If that's not
1046+
// available, fall back to printing the raw values.
10441047
with_session_globals(|session_globals| {
10451048
if let Some(source_map) = &*session_globals.source_map.borrow() {
10461049
write!(f, "{} ({:?})", source_map.span_to_diagnostic_string(*self), self.ctxt())

compiler/rustc_span/src/profiling.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::source_map::SourceMap;
2+
13
use std::borrow::Borrow;
24

35
use rustc_data_structures::profiling::EventArgRecorder;
@@ -11,25 +13,17 @@ pub trait SpannedEventArgRecorder {
1113
///
1214
/// Note: when self-profiling with costly event arguments, at least one argument
1315
/// needs to be recorded. A panic will be triggered if that doesn't happen.
14-
fn record_arg_with_span<A>(&mut self, event_arg: A, span: crate::Span)
16+
fn record_arg_with_span<A>(&mut self, source_map: &SourceMap, event_arg: A, span: crate::Span)
1517
where
1618
A: Borrow<str> + Into<String>;
1719
}
1820

1921
impl SpannedEventArgRecorder for EventArgRecorder<'_> {
20-
fn record_arg_with_span<A>(&mut self, event_arg: A, span: crate::Span)
22+
fn record_arg_with_span<A>(&mut self, source_map: &SourceMap, event_arg: A, span: crate::Span)
2123
where
2224
A: Borrow<str> + Into<String>,
2325
{
2426
self.record_arg(event_arg);
25-
26-
let span_arg = crate::with_session_globals(|session_globals| {
27-
if let Some(source_map) = &*session_globals.source_map.borrow() {
28-
source_map.span_to_embeddable_string(span)
29-
} else {
30-
format!("{span:?}")
31-
}
32-
});
33-
self.record_arg(span_arg);
27+
self.record_arg(source_map.span_to_embeddable_string(span));
3428
}
3529
}

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,7 @@ symbols! {
12471247
rustc_diagnostic_macros,
12481248
rustc_dirty,
12491249
rustc_do_not_const_check,
1250+
rustc_doc_primitive,
12501251
rustc_dummy,
12511252
rustc_dump_env_program_clauses,
12521253
rustc_dump_program_clauses,

0 commit comments

Comments
 (0)