Skip to content

Commit 9c9ae85

Browse files
committed
Auto merge of rust-lang#98874 - matthiaskrgr:rollup-0u4hm54, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#98501 (rustc_passes/src/entry.rs: De-duplicate more code with `fn throw_attr_err()`) - rust-lang#98774 (rustdoc: make source sidebar toggle a real button) - rust-lang#98806 (Fix long declaration trailing whitespace) - rust-lang#98823 (Fix rust-call ICE in mir-inliner) - rust-lang#98870 (Add regression test for rust-lang#86784) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents a5c6a48 + c41e208 commit 9c9ae85

File tree

11 files changed

+2714
-32
lines changed

11 files changed

+2714
-32
lines changed

compiler/rustc_mir_transform/src/inline.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,20 @@ impl<'tcx> Inliner<'tcx> {
180180
return Err("failed to normalize return type");
181181
}
182182
if callsite.fn_sig.abi() == Abi::RustCall {
183-
let mut args = args.into_iter();
184-
let _ = args.next(); // Skip `self` argument.
185-
let arg_tuple_ty = args.next().unwrap().ty(&caller_body.local_decls, self.tcx);
186-
assert!(args.next().is_none());
183+
let (arg_tuple, skipped_args) = match &args[..] {
184+
[arg_tuple] => (arg_tuple, 0),
185+
[_, arg_tuple] => (arg_tuple, 1),
186+
_ => bug!("Expected `rust-call` to have 1 or 2 args"),
187+
};
187188

189+
let arg_tuple_ty = arg_tuple.ty(&caller_body.local_decls, self.tcx);
188190
let ty::Tuple(arg_tuple_tys) = arg_tuple_ty.kind() else {
189191
bug!("Closure arguments are not passed as a tuple");
190192
};
191193

192-
for (arg_ty, input) in arg_tuple_tys.iter().zip(callee_body.args_iter().skip(1)) {
194+
for (arg_ty, input) in
195+
arg_tuple_tys.iter().zip(callee_body.args_iter().skip(skipped_args))
196+
{
193197
let input_type = callee_body.local_decls[input].ty;
194198
if !equal_up_to_regions(self.tcx, self.param_env, arg_ty, input_type) {
195199
trace!(?arg_ty, ?input_type);

compiler/rustc_passes/src/entry.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_ast::entry::EntryPointType;
1+
use rustc_ast::{entry::EntryPointType, Attribute};
22
use rustc_errors::struct_span_err;
33
use rustc_hir::def::DefKind;
44
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
@@ -7,9 +7,8 @@ use rustc_middle::ty::query::Providers;
77
use rustc_middle::ty::{DefIdTree, TyCtxt};
88
use rustc_session::config::{CrateType, EntryFnType};
99
use rustc_session::parse::feature_err;
10-
use rustc_session::Session;
1110
use rustc_span::symbol::sym;
12-
use rustc_span::{Span, DUMMY_SP};
11+
use rustc_span::{Span, Symbol, DUMMY_SP};
1312

1413
struct EntryContext<'tcx> {
1514
tcx: TyCtxt<'tcx>,
@@ -72,9 +71,16 @@ fn entry_point_type(ctxt: &EntryContext<'_>, id: ItemId, at_root: bool) -> Entry
7271
}
7372
}
7473

75-
fn throw_attr_err(sess: &Session, span: Span, attr: &str) {
76-
sess.struct_span_err(span, &format!("`{}` attribute can only be used on functions", attr))
77-
.emit();
74+
fn err_if_attr_found(ctxt: &EntryContext<'_>, attrs: &[Attribute], sym: Symbol) {
75+
if let Some(attr) = ctxt.tcx.sess.find_by_name(attrs, sym) {
76+
ctxt.tcx
77+
.sess
78+
.struct_span_err(
79+
attr.span,
80+
&format!("`{}` attribute can only be used on functions", sym.as_str()),
81+
)
82+
.emit();
83+
}
7884
}
7985

8086
fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
@@ -84,12 +90,8 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
8490
EntryPointType::None => (),
8591
_ if !matches!(ctxt.tcx.def_kind(id.def_id), DefKind::Fn) => {
8692
let attrs = ctxt.tcx.hir().attrs(id.hir_id());
87-
if let Some(attr) = ctxt.tcx.sess.find_by_name(attrs, sym::start) {
88-
throw_attr_err(&ctxt.tcx.sess, attr.span, "start");
89-
}
90-
if let Some(attr) = ctxt.tcx.sess.find_by_name(attrs, sym::rustc_main) {
91-
throw_attr_err(&ctxt.tcx.sess, attr.span, "rustc_main");
92-
}
93+
err_if_attr_found(ctxt, attrs, sym::start);
94+
err_if_attr_found(ctxt, attrs, sym::rustc_main);
9395
}
9496
EntryPointType::MainNamed => (),
9597
EntryPointType::OtherMain => {

src/librustdoc/html/format.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1283,10 +1283,6 @@ impl clean::FnDecl {
12831283
let mut args = Buffer::html();
12841284
let mut args_plain = Buffer::new();
12851285
for (i, input) in self.inputs.values.iter().enumerate() {
1286-
if i == 0 {
1287-
args.push_str("<br>");
1288-
}
1289-
12901286
if let Some(selfty) = input.to_self() {
12911287
match selfty {
12921288
clean::SelfValue => {
@@ -1312,8 +1308,7 @@ impl clean::FnDecl {
13121308
}
13131309
} else {
13141310
if i > 0 {
1315-
args.push_str(" <br>");
1316-
args_plain.push_str(" ");
1311+
args.push_str("<br>");
13171312
}
13181313
if input.is_const {
13191314
args.push_str("const ");
@@ -1360,13 +1355,14 @@ impl clean::FnDecl {
13601355
let full_pad = format!("<br>{}", "&nbsp;".repeat(indent + 4));
13611356
let close_pad = format!("<br>{}", "&nbsp;".repeat(indent));
13621357
format!(
1363-
"({args}{close}){arrow}",
1358+
"({pad}{args}{close}){arrow}",
1359+
pad = if self.inputs.values.is_empty() { "" } else { &full_pad },
13641360
args = args.replace("<br>", &full_pad),
13651361
close = close_pad,
13661362
arrow = arrow
13671363
)
13681364
} else {
1369-
format!("({args}){arrow}", args = args.replace("<br>", ""), arrow = arrow)
1365+
format!("({args}){arrow}", args = args.replace("<br>", " "), arrow = arrow)
13701366
};
13711367

13721368
if f.alternate() {

src/librustdoc/html/static/css/rustdoc.css

+19-3
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ nav.sub {
418418
background-color: var(--sidebar-background-color);
419419
}
420420

421-
#sidebar-toggle:hover {
421+
#sidebar-toggle > button:hover, #sidebar-toggle > button:focus {
422422
background-color: var(--sidebar-background-color-hover);
423423
}
424424

@@ -1401,7 +1401,6 @@ pre.rust {
14011401
position: sticky;
14021402
top: 0;
14031403
left: 0;
1404-
cursor: pointer;
14051404
font-weight: bold;
14061405
font-size: 1.25rem;
14071406
border-bottom: 1px solid;
@@ -1422,7 +1421,24 @@ pre.rust {
14221421
border-bottom: 1px solid;
14231422
margin-bottom: 6px;
14241423
}
1425-
1424+
#sidebar-toggle > button {
1425+
background: none;
1426+
color: inherit;
1427+
cursor: pointer;
1428+
text-align: center;
1429+
border: none;
1430+
outline: none;
1431+
position: absolute;
1432+
top: 0;
1433+
bottom: 0;
1434+
left: 0;
1435+
right: 0;
1436+
/* work around button layout strangeness: https://stackoverflow.com/q/7271561 */
1437+
width: 100%;
1438+
/* iOS button gradient: https://stackoverflow.com/q/5438567 */
1439+
-webkit-appearance: none;
1440+
opacity: 1;
1441+
}
14261442
#settings-menu, #help-button {
14271443
margin-left: 4px;
14281444
outline: none;

src/librustdoc/html/static/js/source-script.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
5757
}
5858

5959
function toggleSidebar() {
60-
const child = this.children[0];
60+
const child = this.parentNode.children[0];
6161
if (child.innerText === ">") {
6262
if (window.innerWidth < 701) {
6363
// This is to keep the scroll position on mobile.
@@ -86,15 +86,15 @@ function toggleSidebar() {
8686
function createSidebarToggle() {
8787
const sidebarToggle = document.createElement("div");
8888
sidebarToggle.id = "sidebar-toggle";
89-
sidebarToggle.onclick = toggleSidebar;
9089

91-
const inner = document.createElement("div");
90+
const inner = document.createElement("button");
9291

9392
if (getCurrentValue("source-sidebar-show") === "true") {
9493
inner.innerText = "<";
9594
} else {
9695
inner.innerText = ">";
9796
}
97+
inner.onclick = toggleSidebar;
9898

9999
sidebarToggle.appendChild(inner);
100100
return sidebarToggle;

src/test/rustdoc-gui/sidebar-source-code-display.goml

+27
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ assert-css: (
3030
"#source-sidebar details[open] > .files a.selected",
3131
{"color": "rgb(0, 0, 0)", "background-color": "rgb(255, 255, 255)"},
3232
)
33+
// Without hover or focus.
34+
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(0, 0, 0, 0)"})
35+
// With focus.
36+
focus: "#sidebar-toggle > button"
37+
assert-css: ("#sidebar-toggle > button", {"background-color": "rgb(224, 224, 224)"})
38+
focus: ".search-input"
39+
// With hover.
40+
move-cursor-to: "#sidebar-toggle > button"
41+
assert-css: ("#sidebar-toggle > button", {"background-color": "rgb(224, 224, 224)"})
3342
// Without hover.
3443
assert-css: (
3544
"#source-sidebar details[open] > .files a:not(.selected)",
@@ -76,6 +85,15 @@ assert-css: (
7685
"#source-sidebar details[open] > .files > a.selected",
7786
{"color": "rgb(221, 221, 221)", "background-color": "rgb(51, 51, 51)"},
7887
)
88+
// Without hover or focus.
89+
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(0, 0, 0, 0)"})
90+
// With focus.
91+
focus: "#sidebar-toggle > button"
92+
assert-css: ("#sidebar-toggle > button", {"background-color": "rgb(103, 103, 103)"})
93+
focus: ".search-input"
94+
// With hover.
95+
move-cursor-to: "#sidebar-toggle > button"
96+
assert-css: ("#sidebar-toggle > button", {"background-color": "rgb(103, 103, 103)"})
7997
// Without hover.
8098
assert-css: (
8199
"#source-sidebar details[open] > .files > a:not(.selected)",
@@ -122,6 +140,15 @@ assert-css: (
122140
"#source-sidebar details[open] > .files a.selected",
123141
{"color": "rgb(255, 180, 76)", "background-color": "rgb(20, 25, 31)"},
124142
)
143+
// Without hover or focus.
144+
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(0, 0, 0, 0)"})
145+
// With focus.
146+
focus: "#sidebar-toggle > button"
147+
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(70, 70, 70, 0.33)"})
148+
focus: ".search-input"
149+
// With hover.
150+
move-cursor-to: "#sidebar-toggle > button"
151+
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(70, 70, 70, 0.33)"})
125152
// Without hover.
126153
assert-css: (
127154
"#source-sidebar details[open] > .files a:not(.selected)",

src/test/rustdoc/assoc-types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// @has assoc_types/trait.Index.html
44
pub trait Index<I: ?Sized> {
5-
// @has - '//*[@id="associatedtype.Output"]//h4[@class="code-header"]' 'type Output: ?Sized'
5+
// @has - '//*[@id="associatedtype.Output"]//h4[@class="code-header"]' 'type Output: ?Sized'
66
type Output: ?Sized;
77
// @has - '//*[@id="tymethod.index"]//h4[@class="code-header"]' \
88
// "fn index<'a>(&'a self, index: I) -> &'a Self::Output"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<code>pub trait Write {
2+
fn <a href="#tymethod.poll_write" class="fnname">poll_write</a>(<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cx: &amp;mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;buf: &amp;mut [<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>]<br />&#160;&#160;&#160;&#160;) -&gt; <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt;;
3+
<span class="item-spacer" /> fn <a href="#tymethod.poll_flush" class="fnname">poll_flush</a>(<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cx: &amp;mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;<br />&#160;&#160;&#160;&#160;) -&gt; <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt;;
4+
<span class="item-spacer" /> fn <a href="#tymethod.poll_close" class="fnname">poll_close</a>(<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cx: &amp;mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;<br />&#160;&#160;&#160;&#160;) -&gt; <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt;;
5+
6+
fn <a href="#method.poll_write_vectored" class="fnname">poll_write_vectored</a>(<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cx: &amp;mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;bufs: &amp;[<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>]<br />&#160;&#160;&#160;&#160;) -&gt; <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt; { ... }
7+
}</code>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/98803>.
2+
3+
#![crate_name = "foo"]
4+
5+
pub struct Error;
6+
7+
// @has 'foo/trait.Write.html'
8+
9+
pub trait Write {
10+
// @snapshot 'declaration' - '//*[@class="docblock item-decl"]//code'
11+
fn poll_write(
12+
self: Option<String>,
13+
cx: &mut Option<String>,
14+
buf: &mut [usize]
15+
) -> Option<Result<usize, Error>>;
16+
fn poll_flush(
17+
self: Option<String>,
18+
cx: &mut Option<String>
19+
) -> Option<Result<(), Error>>;
20+
fn poll_close(
21+
self: Option<String>,
22+
cx: &mut Option<String>,
23+
) -> Option<Result<(), Error>>;
24+
25+
fn poll_write_vectored(
26+
self: Option<String>,
27+
cx: &mut Option<String>,
28+
bufs: &[usize]
29+
) -> Option<Result<usize, Error>> {}
30+
}

src/test/ui/abi/rustcall-generic.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
// revisions: normal opt
12
// check-pass
3+
//[opt] compile-flags: -Zmir-opt-level=3
4+
25
#![feature(unboxed_closures)]
36

47
extern "rust-call" fn foo<T>(_: T) {}

0 commit comments

Comments
 (0)