Skip to content

Commit 9fad685

Browse files
committed
Auto merge of rust-lang#118579 - matthiaskrgr:rollup-22kn8sa, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - rust-lang#117869 ([rustdoc] Add highlighting for comments in items declaration) - rust-lang#118525 (coverage: Skip spans that can't be un-expanded back to the function body) - rust-lang#118574 (rustc_session: Address all `rustc::potential_query_instability` lints) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d12dc74 + caeaf31 commit 9fad685

21 files changed

+174
-43
lines changed

compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ fn bcb_to_initial_coverage_spans<'a, 'tcx>(
6363

6464
let statement_spans = data.statements.iter().filter_map(move |statement| {
6565
let expn_span = filtered_statement_span(statement)?;
66-
let span = function_source_span(expn_span, body_span);
66+
let span = unexpand_into_body_span(expn_span, body_span)?;
6767

6868
Some(CoverageSpan::new(span, expn_span, bcb, is_closure(statement)))
6969
});
7070

7171
let terminator_span = Some(data.terminator()).into_iter().filter_map(move |terminator| {
7272
let expn_span = filtered_terminator_span(terminator)?;
73-
let span = function_source_span(expn_span, body_span);
73+
let span = unexpand_into_body_span(expn_span, body_span)?;
7474

7575
Some(CoverageSpan::new(span, expn_span, bcb, false))
7676
});
@@ -180,14 +180,16 @@ fn filtered_terminator_span(terminator: &Terminator<'_>) -> Option<Span> {
180180
/// Returns an extrapolated span (pre-expansion[^1]) corresponding to a range
181181
/// within the function's body source. This span is guaranteed to be contained
182182
/// within, or equal to, the `body_span`. If the extrapolated span is not
183-
/// contained within the `body_span`, the `body_span` is returned.
183+
/// contained within the `body_span`, `None` is returned.
184184
///
185185
/// [^1]Expansions result from Rust syntax including macros, syntactic sugar,
186186
/// etc.).
187187
#[inline]
188-
fn function_source_span(span: Span, body_span: Span) -> Span {
188+
fn unexpand_into_body_span(span: Span, body_span: Span) -> Option<Span> {
189189
use rustc_span::source_map::original_sp;
190190

191+
// FIXME(#118525): Consider switching from `original_sp` to `Span::find_ancestor_inside`,
192+
// which is similar but gives slightly different results in some edge cases.
191193
let original_span = original_sp(span, body_span).with_ctxt(body_span.ctxt());
192-
if body_span.contains(original_span) { original_span } else { body_span }
194+
body_span.contains(original_span).then_some(original_span)
193195
}

compiler/rustc_session/src/code_stats.rs

+4
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ impl CodeStats {
132132

133133
pub fn print_type_sizes(&self) {
134134
let type_sizes = self.type_sizes.borrow();
135+
// We will soon sort, so the initial order does not matter.
136+
#[allow(rustc::potential_query_instability)]
135137
let mut sorted: Vec<_> = type_sizes.iter().collect();
136138

137139
// Primary sort: large-to-small.
@@ -227,6 +229,8 @@ impl CodeStats {
227229
}
228230

229231
pub fn print_vtable_sizes(&self, crate_name: Symbol) {
232+
// We will soon sort, so the initial order does not matter.
233+
#[allow(rustc::potential_query_instability)]
230234
let mut infos =
231235
std::mem::take(&mut *self.vtable_sizes.lock()).into_values().collect::<Vec<_>>();
232236

compiler/rustc_session/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#![feature(map_many_mut)]
77
#![feature(iter_intersperse)]
88
#![recursion_limit = "256"]
9-
#![allow(rustc::potential_query_instability)]
109
#![deny(rustc::untranslatable_diagnostic)]
1110
#![deny(rustc::diagnostic_outside_of_impl)]
1211
#![allow(internal_features)]

compiler/rustc_session/src/parse.rs

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ impl GatedSpans {
5151
/// Prepend the given set of `spans` onto the set in `self`.
5252
pub fn merge(&self, mut spans: FxHashMap<Symbol, Vec<Span>>) {
5353
let mut inner = self.spans.borrow_mut();
54+
// The entries will be moved to another map so the drain order does not
55+
// matter.
56+
#[allow(rustc::potential_query_instability)]
5457
for (gate, mut gate_spans) in inner.drain() {
5558
spans.entry(gate).or_default().append(&mut gate_spans);
5659
}

src/librustdoc/html/render/print_item.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>(
15091509
matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..)))
15101510
})
15111511
{
1512-
return f.write_str("/* private fields */");
1512+
return f.write_str("<span class=\"comment\">/* private fields */</span>");
15131513
}
15141514

15151515
for (i, ty) in s.iter().enumerate() {
@@ -1666,7 +1666,7 @@ fn render_enum_fields(
16661666
}
16671667

16681668
if variants_stripped && !is_non_exhaustive {
1669-
w.write_str(" // some variants omitted\n");
1669+
w.write_str(" <span class=\"comment\">// some variants omitted</span>\n");
16701670
}
16711671
if toggle {
16721672
toggle_close(&mut w);
@@ -1811,15 +1811,21 @@ fn item_proc_macro(
18111811
let name = it.name.expect("proc-macros always have names");
18121812
match m.kind {
18131813
MacroKind::Bang => {
1814-
write!(buffer, "{name}!() {{ /* proc-macro */ }}").unwrap();
1814+
write!(buffer, "{name}!() {{ <span class=\"comment\">/* proc-macro */</span> }}")
1815+
.unwrap();
18151816
}
18161817
MacroKind::Attr => {
18171818
write!(buffer, "#[{name}]").unwrap();
18181819
}
18191820
MacroKind::Derive => {
18201821
write!(buffer, "#[derive({name})]").unwrap();
18211822
if !m.helpers.is_empty() {
1822-
buffer.write_str("\n{\n // Attributes available to this derive:\n").unwrap();
1823+
buffer
1824+
.write_str(
1825+
"\n{\n \
1826+
<span class=\"comment\">// Attributes available to this derive:</span>\n",
1827+
)
1828+
.unwrap();
18231829
for attr in &m.helpers {
18241830
writeln!(buffer, " #[{attr}]").unwrap();
18251831
}
@@ -2181,7 +2187,7 @@ fn render_union<'a, 'cx: 'a>(
21812187
}
21822188

21832189
if it.has_stripped_entries().unwrap() {
2184-
write!(f, " /* private fields */\n")?;
2190+
write!(f, " <span class=\"comment\">/* private fields */</span>\n")?;
21852191
}
21862192
if toggle {
21872193
toggle_close(&mut f);
@@ -2267,11 +2273,11 @@ fn render_struct_fields(
22672273

22682274
if has_visible_fields {
22692275
if has_stripped_entries {
2270-
write!(w, "\n{tab} /* private fields */");
2276+
write!(w, "\n{tab} <span class=\"comment\">/* private fields */</span>");
22712277
}
22722278
write!(w, "\n{tab}");
22732279
} else if has_stripped_entries {
2274-
write!(w, " /* private fields */ ");
2280+
write!(w, " <span class=\"comment\">/* private fields */</span> ");
22752281
}
22762282
if toggle {
22772283
toggle_close(&mut w);
@@ -2285,7 +2291,7 @@ fn render_struct_fields(
22852291
matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..)))
22862292
})
22872293
{
2288-
write!(w, "/* private fields */");
2294+
write!(w, "<span class=\"comment\">/* private fields */</span>");
22892295
} else {
22902296
for (i, field) in fields.iter().enumerate() {
22912297
if i > 0 {

tests/coverage/async.cov-map

+6-6
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,28 @@ Number of file 0 mappings: 6
7474
= ((c0 + c1) - c1)
7575

7676
Function name: async::executor::block_on::VTABLE::{closure#0}
77-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 72, 11, 00, 33]
77+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 72, 11, 00, 31]
7878
Number of files: 1
7979
- file 0 => global file 1
8080
Number of expressions: 0
8181
Number of file 0 mappings: 1
82-
- Code(Counter(0)) at (prev + 114, 17) to (start + 0, 51)
82+
- Code(Counter(0)) at (prev + 114, 17) to (start + 0, 49)
8383

8484
Function name: async::executor::block_on::VTABLE::{closure#1}
85-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 73, 11, 00, 33]
85+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 73, 11, 00, 31]
8686
Number of files: 1
8787
- file 0 => global file 1
8888
Number of expressions: 0
8989
Number of file 0 mappings: 1
90-
- Code(Counter(0)) at (prev + 115, 17) to (start + 0, 51)
90+
- Code(Counter(0)) at (prev + 115, 17) to (start + 0, 49)
9191

9292
Function name: async::executor::block_on::VTABLE::{closure#2}
93-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 74, 11, 00, 33]
93+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 74, 11, 00, 31]
9494
Number of files: 1
9595
- file 0 => global file 1
9696
Number of expressions: 0
9797
Number of file 0 mappings: 1
98-
- Code(Counter(0)) at (prev + 116, 17) to (start + 0, 51)
98+
- Code(Counter(0)) at (prev + 116, 17) to (start + 0, 49)
9999

100100
Function name: async::executor::block_on::VTABLE::{closure#3}
101101
Raw bytes (9): 0x[01, 01, 00, 01, 01, 75, 11, 00, 13]

tests/coverage/async2.cov-map

+6-6
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,28 @@ Number of file 0 mappings: 6
7878
= ((c0 + c1) - c1)
7979

8080
Function name: async2::executor::block_on::VTABLE::{closure#0}
81-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2b, 11, 00, 33]
81+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2b, 11, 00, 31]
8282
Number of files: 1
8383
- file 0 => global file 1
8484
Number of expressions: 0
8585
Number of file 0 mappings: 1
86-
- Code(Counter(0)) at (prev + 43, 17) to (start + 0, 51)
86+
- Code(Counter(0)) at (prev + 43, 17) to (start + 0, 49)
8787

8888
Function name: async2::executor::block_on::VTABLE::{closure#1}
89-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2c, 11, 00, 33]
89+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2c, 11, 00, 31]
9090
Number of files: 1
9191
- file 0 => global file 1
9292
Number of expressions: 0
9393
Number of file 0 mappings: 1
94-
- Code(Counter(0)) at (prev + 44, 17) to (start + 0, 51)
94+
- Code(Counter(0)) at (prev + 44, 17) to (start + 0, 49)
9595

9696
Function name: async2::executor::block_on::VTABLE::{closure#2}
97-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2d, 11, 00, 33]
97+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2d, 11, 00, 31]
9898
Number of files: 1
9999
- file 0 => global file 1
100100
Number of expressions: 0
101101
Number of file 0 mappings: 1
102-
- Code(Counter(0)) at (prev + 45, 17) to (start + 0, 51)
102+
- Code(Counter(0)) at (prev + 45, 17) to (start + 0, 49)
103103

104104
Function name: async2::executor::block_on::VTABLE::{closure#3}
105105
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2e, 11, 00, 13]

tests/coverage/inline.cov-map

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ Number of file 0 mappings: 5
1515
= ((c0 + c1) - c1)
1616

1717
Function name: inline::error
18-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 31, 01, 02, 02]
18+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 31, 01, 01, 14]
1919
Number of files: 1
2020
- file 0 => global file 1
2121
Number of expressions: 0
2222
Number of file 0 mappings: 1
23-
- Code(Counter(0)) at (prev + 49, 1) to (start + 2, 2)
23+
- Code(Counter(0)) at (prev + 49, 1) to (start + 1, 20)
2424

2525
Function name: inline::length::<char>
2626
Raw bytes (9): 0x[01, 01, 00, 01, 01, 1e, 01, 02, 02]

tests/coverage/inline.coverage

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@
5050
LL| |#[inline(always)]
5151
LL| 0|fn error() {
5252
LL| 0| panic!("error");
53-
LL| 0|}
53+
LL| |}
5454

tests/coverage/unreachable.cov-map

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
Function name: unreachable::UNREACHABLE_CLOSURE::{closure#0}
2-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0f, 27, 00, 49]
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0f, 27, 00, 47]
33
Number of files: 1
44
- file 0 => global file 1
55
Number of expressions: 0
66
Number of file 0 mappings: 1
7-
- Code(Counter(0)) at (prev + 15, 39) to (start + 0, 73)
7+
- Code(Counter(0)) at (prev + 15, 39) to (start + 0, 71)
88

99
Function name: unreachable::unreachable_function
10-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 11, 01, 02, 02]
10+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 11, 01, 01, 25]
1111
Number of files: 1
1212
- file 0 => global file 1
1313
Number of expressions: 0
1414
Number of file 0 mappings: 1
15-
- Code(Counter(0)) at (prev + 17, 1) to (start + 2, 2)
15+
- Code(Counter(0)) at (prev + 17, 1) to (start + 1, 37)
1616

1717
Function name: unreachable::unreachable_intrinsic
18-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 16, 01, 02, 02]
18+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 16, 01, 01, 2c]
1919
Number of files: 1
2020
- file 0 => global file 1
2121
Number of expressions: 0
2222
Number of file 0 mappings: 1
23-
- Code(Counter(0)) at (prev + 22, 1) to (start + 2, 2)
23+
- Code(Counter(0)) at (prev + 22, 1) to (start + 1, 44)
2424

tests/coverage/unreachable.coverage

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
LL| |
1717
LL| 0|fn unreachable_function() {
1818
LL| 0| unsafe { unreachable_unchecked() }
19-
LL| 0|}
19+
LL| |}
2020
LL| |
2121
LL| |// Use an intrinsic to more reliably trigger unreachable-propagation.
2222
LL| 0|fn unreachable_intrinsic() {
2323
LL| 0| unsafe { std::intrinsics::unreachable() }
24-
LL| 0|}
24+
LL| |}
2525
LL| |
2626
LL| |#[coverage(off)]
2727
LL| |fn main() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// This test checks that comments in item declarations are highlighted.
2+
go-to: "file://" + |DOC_PATH| + "/test_docs/private/enum.Enum.html"
3+
show-text: true
4+
5+
define-function: (
6+
"check-item-decl-comment",
7+
(theme, url, comment_color),
8+
block {
9+
go-to: |url|
10+
set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}
11+
reload:
12+
assert-css: (".item-decl .comment", {"color": |comment_color|}, ALL)
13+
}
14+
)
15+
16+
define-function: (
17+
"check-items-for-theme",
18+
(theme, comment_color),
19+
block {
20+
call-function: ("check-item-decl-comment", {
21+
"theme": |theme|,
22+
"url": "file://" + |DOC_PATH| + "/test_docs/private/enum.Enum.html",
23+
"comment_color": |comment_color|,
24+
})
25+
call-function: ("check-item-decl-comment", {
26+
"theme": |theme|,
27+
"url": "file://" + |DOC_PATH| + "/test_docs/private/struct.Struct.html",
28+
"comment_color": |comment_color|,
29+
})
30+
call-function: ("check-item-decl-comment", {
31+
"theme": |theme|,
32+
"url": "file://" + |DOC_PATH| + "/test_docs/private/struct.Tuple.html",
33+
"comment_color": |comment_color|,
34+
})
35+
call-function: ("check-item-decl-comment", {
36+
"theme": |theme|,
37+
"url": "file://" + |DOC_PATH| + "/test_docs/private/union.Union.html",
38+
"comment_color": |comment_color|,
39+
})
40+
call-function: ("check-item-decl-comment", {
41+
"theme": |theme|,
42+
"url": "file://" + |DOC_PATH| + "/proc_macro_test/macro.make_answer.html",
43+
"comment_color": |comment_color|,
44+
})
45+
call-function: ("check-item-decl-comment", {
46+
"theme": |theme|,
47+
"url": "file://" + |DOC_PATH| + "/proc_macro_test/derive.HelperAttr.html",
48+
"comment_color": |comment_color|,
49+
})
50+
}
51+
)
52+
53+
call-function: (
54+
"check-items-for-theme",
55+
{
56+
"theme": "ayu",
57+
"comment_color": "#788797",
58+
}
59+
)
60+
call-function: (
61+
"check-items-for-theme",
62+
{
63+
"theme": "dark",
64+
"comment_color": "#8d8d8b",
65+
}
66+
)
67+
call-function: (
68+
"check-items-for-theme",
69+
{
70+
"theme": "light",
71+
"comment_color": "#8e908c",
72+
}
73+
)

tests/rustdoc-gui/sidebar-source-code.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ assert: "//*[@class='dir-entry' and @open]/*[text()='sub_mod']"
7373
// Only "another_folder" should be "open" in "lib2".
7474
assert: "//*[@class='dir-entry' and not(@open)]/*[text()='another_mod']"
7575
// All other trees should be collapsed.
76-
assert-count: ("//*[@id='src-sidebar']/details[not(text()='lib2') and not(@open)]", 10)
76+
assert-count: ("//*[@id='src-sidebar']/details[not(text()='lib2') and not(@open)]", 11)
7777

7878
// We now switch to mobile mode.
7979
set-window-size: (600, 600)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file is automatically @generated by Cargo.
2+
# It is not intended for manual editing.
3+
version = 3
4+
5+
[[package]]
6+
name = "proc_macro_test"
7+
version = "0.1.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "proc_macro_test"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
path = "lib.rs"
8+
proc-macro = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use proc_macro::TokenStream;
2+
3+
#[proc_macro]
4+
pub fn make_answer(_item: TokenStream) -> TokenStream {
5+
"fn answer() -> u32 { 42 }".parse().unwrap()
6+
}
7+
8+
#[proc_macro_derive(HelperAttr, attributes(helper))]
9+
pub fn derive_helper_attr(_item: TokenStream) -> TokenStream {
10+
TokenStream::new()
11+
}

0 commit comments

Comments
 (0)