Skip to content

Commit 9c56d9d

Browse files
committed
Auto merge of rust-lang#102482 - notriddle:rollup-fjm618g, r=notriddle
Rollup of 7 pull requests Successful merges: - rust-lang#102214 (Fix span of byte-escaped left format args brace) - rust-lang#102426 (Don't export `__wasm_init_memory` on WebAssembly.) - rust-lang#102437 (rustdoc: cut margin-top from first header in docblock) - rust-lang#102442 (rustdoc: remove bad CSS font-weight on `.impl`, `.method`, etc) - rust-lang#102447 (rustdoc: add method spacing to trait methods) - rust-lang#102468 (tidy: make rustc dependency error less confusing) - rust-lang#102476 (Split out the error reporting logic into a separate function) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9f1a21a + 9807570 commit 9c56d9d

File tree

12 files changed

+243
-175
lines changed

12 files changed

+243
-175
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

-6
Original file line numberDiff line numberDiff line change
@@ -1180,18 +1180,12 @@ impl<'a> WasmLd<'a> {
11801180
// sharing memory and instantiating the module multiple times. As a
11811181
// result if it were exported then we'd just have no sharing.
11821182
//
1183-
// * `--export=__wasm_init_memory` - when using `--passive-segments` the
1184-
// linker will synthesize this function, and so we need to make sure
1185-
// that our usage of `--export` below won't accidentally cause this
1186-
// function to get deleted.
1187-
//
11881183
// * `--export=*tls*` - when `#[thread_local]` symbols are used these
11891184
// symbols are how the TLS segments are initialized and configured.
11901185
if sess.target_features.contains(&sym::atomics) {
11911186
cmd.arg("--shared-memory");
11921187
cmd.arg("--max-memory=1073741824");
11931188
cmd.arg("--import-memory");
1194-
cmd.arg("--export=__wasm_init_memory");
11951189
cmd.arg("--export=__wasm_init_tls");
11961190
cmd.arg("--export=__tls_size");
11971191
cmd.arg("--export=__tls_align");

compiler/rustc_hir_analysis/src/check/callee.rs

+140-134
Original file line numberDiff line numberDiff line change
@@ -394,140 +394,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
394394
}
395395
ty::FnPtr(sig) => (sig, None),
396396
_ => {
397-
let mut unit_variant = None;
398-
if let hir::ExprKind::Path(qpath) = &callee_expr.kind
399-
&& let Res::Def(def::DefKind::Ctor(kind, def::CtorKind::Const), _)
400-
= self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id)
401-
// Only suggest removing parens if there are no arguments
402-
&& arg_exprs.is_empty()
403-
{
404-
let descr = match kind {
405-
def::CtorOf::Struct => "struct",
406-
def::CtorOf::Variant => "enum variant",
407-
};
408-
let removal_span =
409-
callee_expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
410-
unit_variant =
411-
Some((removal_span, descr, rustc_hir_pretty::qpath_to_string(qpath)));
412-
}
413-
414-
let callee_ty = self.resolve_vars_if_possible(callee_ty);
415-
let mut err = type_error_struct!(
416-
self.tcx.sess,
417-
callee_expr.span,
418-
callee_ty,
419-
E0618,
420-
"expected function, found {}",
421-
match &unit_variant {
422-
Some((_, kind, path)) => format!("{kind} `{path}`"),
423-
None => format!("`{callee_ty}`"),
424-
}
425-
);
426-
427-
self.identify_bad_closure_def_and_call(
428-
&mut err,
429-
call_expr.hir_id,
430-
&callee_expr.kind,
431-
callee_expr.span,
432-
);
433-
434-
if let Some((removal_span, kind, path)) = &unit_variant {
435-
err.span_suggestion_verbose(
436-
*removal_span,
437-
&format!(
438-
"`{path}` is a unit {kind}, and does not take parentheses to be constructed",
439-
),
440-
"",
441-
Applicability::MachineApplicable,
442-
);
443-
}
444-
445-
let mut inner_callee_path = None;
446-
let def = match callee_expr.kind {
447-
hir::ExprKind::Path(ref qpath) => {
448-
self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id)
449-
}
450-
hir::ExprKind::Call(ref inner_callee, _) => {
451-
// If the call spans more than one line and the callee kind is
452-
// itself another `ExprCall`, that's a clue that we might just be
453-
// missing a semicolon (Issue #51055)
454-
let call_is_multiline =
455-
self.tcx.sess.source_map().is_multiline(call_expr.span);
456-
if call_is_multiline {
457-
err.span_suggestion(
458-
callee_expr.span.shrink_to_hi(),
459-
"consider using a semicolon here",
460-
";",
461-
Applicability::MaybeIncorrect,
462-
);
463-
}
464-
if let hir::ExprKind::Path(ref inner_qpath) = inner_callee.kind {
465-
inner_callee_path = Some(inner_qpath);
466-
self.typeck_results.borrow().qpath_res(inner_qpath, inner_callee.hir_id)
467-
} else {
468-
Res::Err
469-
}
470-
}
471-
_ => Res::Err,
472-
};
473-
474-
if !self.maybe_suggest_bad_array_definition(&mut err, call_expr, callee_expr) {
475-
if let Some((maybe_def, output_ty, _)) = self.extract_callable_info(callee_expr, callee_ty)
476-
&& !self.type_is_sized_modulo_regions(self.param_env, output_ty, callee_expr.span)
477-
{
478-
let descr = match maybe_def {
479-
DefIdOrName::DefId(def_id) => self.tcx.def_kind(def_id).descr(def_id),
480-
DefIdOrName::Name(name) => name,
481-
};
482-
err.span_label(
483-
callee_expr.span,
484-
format!("this {descr} returns an unsized value `{output_ty}`, so it cannot be called")
485-
);
486-
if let DefIdOrName::DefId(def_id) = maybe_def
487-
&& let Some(def_span) = self.tcx.hir().span_if_local(def_id)
488-
{
489-
err.span_label(def_span, "the callable type is defined here");
490-
}
491-
} else {
492-
err.span_label(call_expr.span, "call expression requires function");
493-
}
494-
}
495-
496-
if let Some(span) = self.tcx.hir().res_span(def) {
497-
let callee_ty = callee_ty.to_string();
498-
let label = match (unit_variant, inner_callee_path) {
499-
(Some((_, kind, path)), _) => Some(format!("{kind} `{path}` defined here")),
500-
(_, Some(hir::QPath::Resolved(_, path))) => self
501-
.tcx
502-
.sess
503-
.source_map()
504-
.span_to_snippet(path.span)
505-
.ok()
506-
.map(|p| format!("`{p}` defined here returns `{callee_ty}`")),
507-
_ => {
508-
match def {
509-
// Emit a different diagnostic for local variables, as they are not
510-
// type definitions themselves, but rather variables *of* that type.
511-
Res::Local(hir_id) => Some(format!(
512-
"`{}` has type `{}`",
513-
self.tcx.hir().name(hir_id),
514-
callee_ty
515-
)),
516-
Res::Def(kind, def_id) if kind.ns() == Some(Namespace::ValueNS) => {
517-
Some(format!(
518-
"`{}` defined here",
519-
self.tcx.def_path_str(def_id),
520-
))
521-
}
522-
_ => Some(format!("`{callee_ty}` defined here")),
523-
}
524-
}
525-
};
526-
if let Some(label) = label {
527-
err.span_label(span, label);
528-
}
529-
}
530-
err.emit();
397+
self.report_invalid_callee(call_expr, callee_expr, callee_ty, arg_exprs);
531398

532399
// This is the "default" function signature, used in case of error.
533400
// In that case, we check each argument against "error" in order to
@@ -574,6 +441,145 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
574441
fn_sig.output()
575442
}
576443

444+
fn report_invalid_callee(
445+
&self,
446+
call_expr: &'tcx hir::Expr<'tcx>,
447+
callee_expr: &'tcx hir::Expr<'tcx>,
448+
callee_ty: Ty<'tcx>,
449+
arg_exprs: &'tcx [hir::Expr<'tcx>],
450+
) {
451+
let mut unit_variant = None;
452+
if let hir::ExprKind::Path(qpath) = &callee_expr.kind
453+
&& let Res::Def(def::DefKind::Ctor(kind, def::CtorKind::Const), _)
454+
= self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id)
455+
// Only suggest removing parens if there are no arguments
456+
&& arg_exprs.is_empty()
457+
{
458+
let descr = match kind {
459+
def::CtorOf::Struct => "struct",
460+
def::CtorOf::Variant => "enum variant",
461+
};
462+
let removal_span =
463+
callee_expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
464+
unit_variant =
465+
Some((removal_span, descr, rustc_hir_pretty::qpath_to_string(qpath)));
466+
}
467+
468+
let callee_ty = self.resolve_vars_if_possible(callee_ty);
469+
let mut err = type_error_struct!(
470+
self.tcx.sess,
471+
callee_expr.span,
472+
callee_ty,
473+
E0618,
474+
"expected function, found {}",
475+
match &unit_variant {
476+
Some((_, kind, path)) => format!("{kind} `{path}`"),
477+
None => format!("`{callee_ty}`"),
478+
}
479+
);
480+
481+
self.identify_bad_closure_def_and_call(
482+
&mut err,
483+
call_expr.hir_id,
484+
&callee_expr.kind,
485+
callee_expr.span,
486+
);
487+
488+
if let Some((removal_span, kind, path)) = &unit_variant {
489+
err.span_suggestion_verbose(
490+
*removal_span,
491+
&format!(
492+
"`{path}` is a unit {kind}, and does not take parentheses to be constructed",
493+
),
494+
"",
495+
Applicability::MachineApplicable,
496+
);
497+
}
498+
499+
let mut inner_callee_path = None;
500+
let def = match callee_expr.kind {
501+
hir::ExprKind::Path(ref qpath) => {
502+
self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id)
503+
}
504+
hir::ExprKind::Call(ref inner_callee, _) => {
505+
// If the call spans more than one line and the callee kind is
506+
// itself another `ExprCall`, that's a clue that we might just be
507+
// missing a semicolon (Issue #51055)
508+
let call_is_multiline = self.tcx.sess.source_map().is_multiline(call_expr.span);
509+
if call_is_multiline {
510+
err.span_suggestion(
511+
callee_expr.span.shrink_to_hi(),
512+
"consider using a semicolon here",
513+
";",
514+
Applicability::MaybeIncorrect,
515+
);
516+
}
517+
if let hir::ExprKind::Path(ref inner_qpath) = inner_callee.kind {
518+
inner_callee_path = Some(inner_qpath);
519+
self.typeck_results.borrow().qpath_res(inner_qpath, inner_callee.hir_id)
520+
} else {
521+
Res::Err
522+
}
523+
}
524+
_ => Res::Err,
525+
};
526+
527+
if !self.maybe_suggest_bad_array_definition(&mut err, call_expr, callee_expr) {
528+
if let Some((maybe_def, output_ty, _)) = self.extract_callable_info(callee_expr, callee_ty)
529+
&& !self.type_is_sized_modulo_regions(self.param_env, output_ty, callee_expr.span)
530+
{
531+
let descr = match maybe_def {
532+
DefIdOrName::DefId(def_id) => self.tcx.def_kind(def_id).descr(def_id),
533+
DefIdOrName::Name(name) => name,
534+
};
535+
err.span_label(
536+
callee_expr.span,
537+
format!("this {descr} returns an unsized value `{output_ty}`, so it cannot be called")
538+
);
539+
if let DefIdOrName::DefId(def_id) = maybe_def
540+
&& let Some(def_span) = self.tcx.hir().span_if_local(def_id)
541+
{
542+
err.span_label(def_span, "the callable type is defined here");
543+
}
544+
} else {
545+
err.span_label(call_expr.span, "call expression requires function");
546+
}
547+
}
548+
549+
if let Some(span) = self.tcx.hir().res_span(def) {
550+
let callee_ty = callee_ty.to_string();
551+
let label = match (unit_variant, inner_callee_path) {
552+
(Some((_, kind, path)), _) => Some(format!("{kind} `{path}` defined here")),
553+
(_, Some(hir::QPath::Resolved(_, path))) => self
554+
.tcx
555+
.sess
556+
.source_map()
557+
.span_to_snippet(path.span)
558+
.ok()
559+
.map(|p| format!("`{p}` defined here returns `{callee_ty}`")),
560+
_ => {
561+
match def {
562+
// Emit a different diagnostic for local variables, as they are not
563+
// type definitions themselves, but rather variables *of* that type.
564+
Res::Local(hir_id) => Some(format!(
565+
"`{}` has type `{}`",
566+
self.tcx.hir().name(hir_id),
567+
callee_ty
568+
)),
569+
Res::Def(kind, def_id) if kind.ns() == Some(Namespace::ValueNS) => {
570+
Some(format!("`{}` defined here", self.tcx.def_path_str(def_id),))
571+
}
572+
_ => Some(format!("`{callee_ty}` defined here")),
573+
}
574+
}
575+
};
576+
if let Some(label) = label {
577+
err.span_label(span, label);
578+
}
579+
}
580+
err.emit();
581+
}
582+
577583
fn confirm_deferred_closure_call(
578584
&self,
579585
call_expr: &'tcx hir::Expr<'tcx>,

compiler/rustc_parse_format/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl<'a> Iterator for Parser<'a> {
224224
'{' => {
225225
let curr_last_brace = self.last_opening_brace;
226226
let byte_pos = self.to_span_index(pos);
227-
let lbrace_end = InnerOffset(byte_pos.0 + 1);
227+
let lbrace_end = self.to_span_index(pos + 1);
228228
self.last_opening_brace = Some(byte_pos.to(lbrace_end));
229229
self.cur.next();
230230
if self.consume('{') {

src/librustdoc/html/render/print_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
716716
document(&mut content, cx, m, Some(t), HeadingOffset::H5);
717717
let toggled = !content.is_empty();
718718
if toggled {
719-
write!(w, "<details class=\"rustdoc-toggle\" open><summary>");
719+
write!(w, "<details class=\"rustdoc-toggle method-toggle\" open><summary>");
720720
}
721721
write!(w, "<div id=\"{}\" class=\"method has-srclink\">", id);
722722
render_rightside(w, cx, m, t, RenderMode::Normal);

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ h1, h2, h3, h4 {
138138
.docblock h3, .docblock h4, h5, h6 {
139139
margin: 15px 0 5px 0;
140140
}
141+
.docblock > h2:first-child,
142+
.docblock > h3:first-child,
143+
.docblock > h4:first-child,
144+
.docblock > h5:first-child,
145+
.docblock > h6:first-child {
146+
margin-top: 0;
147+
}
141148
h1.fqn {
142149
margin: 0;
143150
padding: 0;
@@ -187,7 +194,6 @@ h4.code-header {
187194
.impl-items .associatedtype,
188195
.methods .associatedtype {
189196
flex-basis: 100%;
190-
font-weight: 600;
191197
position: relative;
192198
}
193199

@@ -2008,7 +2014,8 @@ in storage.js plus the media query with (min-width: 701px)
20082014

20092015
.method-toggle summary,
20102016
.implementors-toggle summary,
2011-
.impl {
2017+
.impl,
2018+
#implementors-list > .docblock {
20122019
margin-bottom: 0.75em;
20132020
}
20142021

src/test/rustdoc-gui/anchor-navigable.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
88
// We check that ".item-info" is bigger than its content.
99
move-cursor-to: ".impl"
10-
assert-property: (".impl > a.anchor", {"offsetWidth": "9"})
10+
assert-property: (".impl > a.anchor", {"offsetWidth": "8"})
1111
assert-css: (".impl > a.anchor", {"left": "-8px"})

src/test/rustdoc-gui/font-weight.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ goto: file://|DOC_PATH|/test_docs/type.SomeType.html
1313
assert-css: (".top-doc .docblock p", {"font-weight": "400"}, ALL)
1414

1515
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
16-
assert-css: (".impl-items .method", {"font-weight": "600"}, ALL)
16+
assert-css: (".impl-items .method > .code-header", {"font-weight": "600"}, ALL)
1717

1818
goto: file://|DOC_PATH|/lib2/trait.Trait.html
1919

@@ -41,4 +41,4 @@ assert-count: (".methods .associatedtype", 1)
4141
assert-css: (".methods .associatedtype", {"font-weight": "600"})
4242
assert-count: (".methods .constant", 1)
4343
assert-css: (".methods .constant", {"font-weight": "600"})
44-
assert-css: (".methods .method", {"font-weight": "600"})
44+
assert-css: (".methods .method > .code-header", {"font-weight": "600"})

src/test/rustdoc-gui/src-font-size.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
55
show-text: true
66
// Check the impl headers.
7-
assert-css: (".impl.has-srclink .srclink", {"font-size": "16px"}, ALL)
8-
assert-css: (".impl.has-srclink .code-header", {"font-size": "18px"}, ALL)
7+
assert-css: (".impl.has-srclink .srclink", {"font-size": "16px", "font-weight": 400}, ALL)
8+
assert-css: (".impl.has-srclink .code-header", {"font-size": "18px", "font-weight": 600}, ALL)
99
// Check the impl items.
10-
assert-css: (".impl-items .has-srclink .srclink", {"font-size": "16px"}, ALL)
11-
assert-css: (".impl-items .has-srclink .code-header", {"font-size": "16px"}, ALL)
10+
assert-css: (".impl-items .has-srclink .srclink", {"font-size": "16px", "font-weight": 400}, ALL)
11+
assert-css: (".impl-items .has-srclink .code-header", {"font-size": "16px", "font-weight": 600}, ALL)

0 commit comments

Comments
 (0)