Skip to content

Commit 78a891d

Browse files
committed
Auto merge of rust-lang#101485 - GuillaumeGomez:rollup-68p9di4, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - rust-lang#101357 (Include enum path in variant suggestion) - rust-lang#101434 (Update `SessionDiagnostic::into_diagnostic` to take `Handler` instead of `ParseSess`) - rust-lang#101445 (Suggest introducing an explicit lifetime if it does not exist) - rust-lang#101457 (Recover from using `;` as separator between fields) - rust-lang#101462 (Rustdoc-Json: Store Variant Fields as their own item.) - rust-lang#101471 (Report number of delayed bugs properly with `-Ztreat-err-as-bug`) - rust-lang#101473 (Add more size assertions for MIR types.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 380addd + f21b612 commit 78a891d

File tree

89 files changed

+707
-384
lines changed

Some content is hidden

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

89 files changed

+707
-384
lines changed

compiler/rustc_attr/src/builtin.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) {
6363
sess.emit_err(session_diagnostics::MultipleStabilityLevels { span });
6464
}
6565
AttrError::UnsupportedLiteral(reason, is_bytestr) => {
66-
sess.emit_err(session_diagnostics::UnsupportedLiteral { span, reason, is_bytestr });
66+
sess.emit_err(session_diagnostics::UnsupportedLiteral {
67+
span,
68+
reason,
69+
is_bytestr,
70+
start_point_span: sess.source_map().start_point(span),
71+
});
6772
}
6873
}
6974
}

compiler/rustc_attr/src/session_diagnostics.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use std::num::IntErrorKind;
22

33
use rustc_ast as ast;
4-
use rustc_errors::{error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed};
4+
use rustc_errors::{
5+
error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler,
6+
};
57
use rustc_macros::SessionDiagnostic;
6-
use rustc_session::{parse::ParseSess, SessionDiagnostic};
8+
use rustc_session::SessionDiagnostic;
79
use rustc_span::{Span, Symbol};
810

911
use crate::UnsupportedLiteralReason;
@@ -49,9 +51,9 @@ pub(crate) struct UnknownMetaItem<'a> {
4951

5052
// Manual implementation to be able to format `expected` items correctly.
5153
impl<'a> SessionDiagnostic<'a> for UnknownMetaItem<'_> {
52-
fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
54+
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
5355
let expected = self.expected.iter().map(|name| format!("`{}`", name)).collect::<Vec<_>>();
54-
let mut diag = sess.span_diagnostic.struct_span_err_with_code(
56+
let mut diag = handler.struct_span_err_with_code(
5557
self.span,
5658
fluent::attr::unknown_meta_item,
5759
error_code!(E0541),
@@ -204,11 +206,12 @@ pub(crate) struct UnsupportedLiteral {
204206
pub span: Span,
205207
pub reason: UnsupportedLiteralReason,
206208
pub is_bytestr: bool,
209+
pub start_point_span: Span,
207210
}
208211

209212
impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral {
210-
fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
211-
let mut diag = sess.span_diagnostic.struct_span_err_with_code(
213+
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
214+
let mut diag = handler.struct_span_err_with_code(
212215
self.span,
213216
match self.reason {
214217
UnsupportedLiteralReason::Generic => fluent::attr::unsupported_literal_generic,
@@ -224,7 +227,7 @@ impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral {
224227
);
225228
if self.is_bytestr {
226229
diag.span_suggestion(
227-
sess.source_map().start_point(self.span),
230+
self.start_point_span,
228231
fluent::attr::unsupported_literal_suggestion,
229232
"",
230233
Applicability::MaybeIncorrect,

compiler/rustc_errors/src/lib.rs

+22-17
Original file line numberDiff line numberDiff line change
@@ -1250,14 +1250,14 @@ impl HandlerInner {
12501250

12511251
fn treat_err_as_bug(&self) -> bool {
12521252
self.flags.treat_err_as_bug.map_or(false, |c| {
1253-
self.err_count()
1254-
+ self.lint_err_count
1255-
+ self.delayed_span_bugs.len()
1256-
+ self.delayed_good_path_bugs.len()
1257-
>= c.get()
1253+
self.err_count() + self.lint_err_count + self.delayed_bug_count() >= c.get()
12581254
})
12591255
}
12601256

1257+
fn delayed_bug_count(&self) -> usize {
1258+
self.delayed_span_bugs.len() + self.delayed_good_path_bugs.len()
1259+
}
1260+
12611261
fn print_error_count(&mut self, registry: &Registry) {
12621262
self.emit_stashed_diagnostics();
12631263

@@ -1412,12 +1412,7 @@ impl HandlerInner {
14121412
// incrementing `err_count` by one, so we need to +1 the comparing.
14131413
// FIXME: Would be nice to increment err_count in a more coherent way.
14141414
if self.flags.treat_err_as_bug.map_or(false, |c| {
1415-
self.err_count()
1416-
+ self.lint_err_count
1417-
+ self.delayed_span_bugs.len()
1418-
+ self.delayed_good_path_bugs.len()
1419-
+ 1
1420-
>= c.get()
1415+
self.err_count() + self.lint_err_count + self.delayed_bug_count() + 1 >= c.get()
14211416
}) {
14221417
// FIXME: don't abort here if report_delayed_bugs is off
14231418
self.span_bug(sp, msg);
@@ -1518,14 +1513,24 @@ impl HandlerInner {
15181513
if self.treat_err_as_bug() {
15191514
match (
15201515
self.err_count() + self.lint_err_count,
1516+
self.delayed_bug_count(),
15211517
self.flags.treat_err_as_bug.map(|c| c.get()).unwrap_or(0),
15221518
) {
1523-
(1, 1) => panic!("aborting due to `-Z treat-err-as-bug=1`"),
1524-
(0 | 1, _) => {}
1525-
(count, as_bug) => panic!(
1526-
"aborting after {} errors due to `-Z treat-err-as-bug={}`",
1527-
count, as_bug,
1528-
),
1519+
(1, 0, 1) => panic!("aborting due to `-Z treat-err-as-bug=1`"),
1520+
(0, 1, 1) => panic!("aborting due delayed bug with `-Z treat-err-as-bug=1`"),
1521+
(count, delayed_count, as_bug) => {
1522+
if delayed_count > 0 {
1523+
panic!(
1524+
"aborting after {} errors and {} delayed bugs due to `-Z treat-err-as-bug={}`",
1525+
count, delayed_count, as_bug,
1526+
)
1527+
} else {
1528+
panic!(
1529+
"aborting after {} errors due to `-Z treat-err-as-bug={}`",
1530+
count, as_bug,
1531+
)
1532+
}
1533+
}
15291534
}
15301535
}
15311536
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -2395,19 +2395,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
23952395
type_param_span: Option<(Span, bool)>,
23962396
bound_kind: GenericKind<'tcx>,
23972397
sub: S,
2398+
add_lt_sugg: Option<(Span, String)>,
23982399
) {
23992400
let msg = "consider adding an explicit lifetime bound";
24002401
if let Some((sp, has_lifetimes)) = type_param_span {
24012402
let suggestion =
24022403
if has_lifetimes { format!(" + {}", sub) } else { format!(": {}", sub) };
2403-
err.span_suggestion_verbose(
2404-
sp,
2405-
&format!("{}...", msg),
2406-
suggestion,
2404+
let mut suggestions = vec![(sp, suggestion)];
2405+
if let Some(add_lt_sugg) = add_lt_sugg {
2406+
suggestions.push(add_lt_sugg);
2407+
}
2408+
err.multipart_suggestion_verbose(
2409+
format!("{msg}..."),
2410+
suggestions,
24072411
Applicability::MaybeIncorrect, // Issue #41966
24082412
);
24092413
} else {
2410-
let consider = format!("{} `{}: {}`...", msg, bound_kind, sub,);
2414+
let consider = format!("{} `{}: {}`...", msg, bound_kind, sub);
24112415
err.help(&consider);
24122416
}
24132417
}
@@ -2423,7 +2427,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
24232427
};
24242428
let mut sugg =
24252429
vec![(sp, suggestion), (span.shrink_to_hi(), format!(" + {}", new_lt))];
2426-
if let Some(lt) = add_lt_sugg {
2430+
if let Some(lt) = add_lt_sugg.clone() {
24272431
sugg.push(lt);
24282432
sugg.rotate_right(1);
24292433
}
@@ -2529,7 +2533,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
25292533
// for the bound is not suitable for suggestions when `-Zverbose` is set because it
25302534
// uses `Debug` output, so we handle it specially here so that suggestions are
25312535
// always correct.
2532-
binding_suggestion(&mut err, type_param_span, bound_kind, name);
2536+
binding_suggestion(&mut err, type_param_span, bound_kind, name, None);
25332537
err
25342538
}
25352539

@@ -2542,7 +2546,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
25422546
"{} may not live long enough",
25432547
labeled_user_string
25442548
);
2545-
binding_suggestion(&mut err, type_param_span, bound_kind, "'static");
2549+
binding_suggestion(&mut err, type_param_span, bound_kind, "'static", None);
25462550
err
25472551
}
25482552

@@ -2576,7 +2580,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
25762580
new_binding_suggestion(&mut err, type_param_span);
25772581
}
25782582
_ => {
2579-
binding_suggestion(&mut err, type_param_span, bound_kind, new_lt);
2583+
binding_suggestion(
2584+
&mut err,
2585+
type_param_span,
2586+
bound_kind,
2587+
new_lt,
2588+
add_lt_sugg,
2589+
);
25802590
}
25812591
}
25822592
}

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
341341
multi_suggestions,
342342
bad_label,
343343
}
344-
.into_diagnostic(&self.tcx.sess.parse_sess),
344+
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
345345
TypeAnnotationNeeded::E0283 => AmbigousImpl {
346346
span,
347347
source_kind,
@@ -351,7 +351,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
351351
multi_suggestions,
352352
bad_label,
353353
}
354-
.into_diagnostic(&self.tcx.sess.parse_sess),
354+
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
355355
TypeAnnotationNeeded::E0284 => AmbigousReturn {
356356
span,
357357
source_kind,
@@ -361,7 +361,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
361361
multi_suggestions,
362362
bad_label,
363363
}
364-
.into_diagnostic(&self.tcx.sess.parse_sess),
364+
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
365365
}
366366
}
367367

@@ -537,7 +537,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
537537
multi_suggestions,
538538
bad_label: None,
539539
}
540-
.into_diagnostic(&self.tcx.sess.parse_sess),
540+
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
541541
TypeAnnotationNeeded::E0283 => AmbigousImpl {
542542
span,
543543
source_kind,
@@ -547,7 +547,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
547547
multi_suggestions,
548548
bad_label: None,
549549
}
550-
.into_diagnostic(&self.tcx.sess.parse_sess),
550+
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
551551
TypeAnnotationNeeded::E0284 => AmbigousReturn {
552552
span,
553553
source_kind,
@@ -557,7 +557,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
557557
multi_suggestions,
558558
bad_label: None,
559559
}
560-
.into_diagnostic(&self.tcx.sess.parse_sess),
560+
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
561561
}
562562
}
563563

@@ -575,7 +575,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
575575
span,
576576
generator_kind: GeneratorKindAsDiagArg(kind),
577577
}
578-
.into_diagnostic(&self.tcx.sess.parse_sess)
578+
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
579579
}
580580
}
581581

compiler/rustc_lint/src/errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use rustc_errors::{fluent, AddSubdiagnostic, ErrorGuaranteed};
1+
use rustc_errors::{fluent, AddSubdiagnostic, ErrorGuaranteed, Handler};
22
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
3-
use rustc_session::{lint::Level, parse::ParseSess, SessionDiagnostic};
3+
use rustc_session::{lint::Level, SessionDiagnostic};
44
use rustc_span::{Span, Symbol};
55

66
#[derive(SessionDiagnostic)]
@@ -122,9 +122,9 @@ pub struct CheckNameUnknown {
122122
impl SessionDiagnostic<'_> for CheckNameUnknown {
123123
fn into_diagnostic(
124124
self,
125-
sess: &ParseSess,
125+
handler: &Handler,
126126
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
127-
let mut diag = sess.struct_err(fluent::lint::check_name_unknown);
127+
let mut diag = handler.struct_err(fluent::lint::check_name_unknown);
128128
diag.code(rustc_errors::error_code!(E0602));
129129
if let Some(suggestion) = self.suggestion {
130130
diag.help(fluent::lint::help);

compiler/rustc_macros/src/diagnostics/diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
8888
{
8989
fn into_diagnostic(
9090
self,
91-
#sess: &'__session_diagnostic_sess rustc_session::parse::ParseSess
91+
#sess: &'__session_diagnostic_sess rustc_errors::Handler
9292
) -> rustc_errors::DiagnosticBuilder<'__session_diagnostic_sess, G> {
9393
use rustc_errors::IntoDiagnosticArg;
9494
#implementation

compiler/rustc_metadata/src/errors.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,9 @@ pub(crate) struct MultipleCandidates {
424424
impl SessionDiagnostic<'_> for MultipleCandidates {
425425
fn into_diagnostic(
426426
self,
427-
sess: &'_ rustc_session::parse::ParseSess,
427+
handler: &'_ rustc_errors::Handler,
428428
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
429-
let mut diag = sess.struct_err(rustc_errors::fluent::metadata::multiple_candidates);
429+
let mut diag = handler.struct_err(rustc_errors::fluent::metadata::multiple_candidates);
430430
diag.set_arg("crate_name", self.crate_name);
431431
diag.set_arg("flavor", self.flavor);
432432
diag.code(error_code!(E0465));
@@ -540,9 +540,9 @@ pub struct InvalidMetadataFiles {
540540
impl SessionDiagnostic<'_> for InvalidMetadataFiles {
541541
fn into_diagnostic(
542542
self,
543-
sess: &'_ rustc_session::parse::ParseSess,
543+
handler: &'_ rustc_errors::Handler,
544544
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
545-
let mut diag = sess.struct_err(rustc_errors::fluent::metadata::invalid_meta_files);
545+
let mut diag = handler.struct_err(rustc_errors::fluent::metadata::invalid_meta_files);
546546
diag.set_arg("crate_name", self.crate_name);
547547
diag.set_arg("add_info", self.add_info);
548548
diag.code(error_code!(E0786));
@@ -568,9 +568,9 @@ pub struct CannotFindCrate {
568568
impl SessionDiagnostic<'_> for CannotFindCrate {
569569
fn into_diagnostic(
570570
self,
571-
sess: &'_ rustc_session::parse::ParseSess,
571+
handler: &'_ rustc_errors::Handler,
572572
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
573-
let mut diag = sess.struct_err(rustc_errors::fluent::metadata::cannot_find_crate);
573+
let mut diag = handler.struct_err(rustc_errors::fluent::metadata::cannot_find_crate);
574574
diag.set_arg("crate_name", self.crate_name);
575575
diag.set_arg("add_info", self.add_info);
576576
diag.set_arg("locator_triple", self.locator_triple.triple());

compiler/rustc_middle/src/mir/mod.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -839,10 +839,6 @@ pub struct LocalDecl<'tcx> {
839839
pub source_info: SourceInfo,
840840
}
841841

842-
// `LocalDecl` is used a lot. Make sure it doesn't unintentionally get bigger.
843-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
844-
static_assert_size!(LocalDecl<'_>, 56);
845-
846842
/// Extra information about a some locals that's used for diagnostics and for
847843
/// classifying variables into local variables, statics, etc, which is needed e.g.
848844
/// for unsafety checking.
@@ -1317,10 +1313,6 @@ pub struct Statement<'tcx> {
13171313
pub kind: StatementKind<'tcx>,
13181314
}
13191315

1320-
// `Statement` is used a lot. Make sure it doesn't unintentionally get bigger.
1321-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
1322-
static_assert_size!(Statement<'_>, 32);
1323-
13241316
impl Statement<'_> {
13251317
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
13261318
/// invalidating statement indices in `Location`s.
@@ -2900,3 +2892,17 @@ impl Location {
29002892
}
29012893
}
29022894
}
2895+
2896+
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
2897+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
2898+
mod size_asserts {
2899+
use super::*;
2900+
use rustc_data_structures::static_assert_size;
2901+
// These are in alphabetical order, which is easy to maintain.
2902+
static_assert_size!(BasicBlockData<'_>, 144);
2903+
static_assert_size!(LocalDecl<'_>, 56);
2904+
static_assert_size!(Statement<'_>, 32);
2905+
static_assert_size!(StatementKind<'_>, 16);
2906+
static_assert_size!(Terminator<'_>, 112);
2907+
static_assert_size!(TerminatorKind<'_>, 96);
2908+
}

0 commit comments

Comments
 (0)