Skip to content

Commit 4e0b644

Browse files
Fix newly detected subdiagnostics using variables from parent
1 parent e58ddb5 commit 4e0b644

9 files changed

Lines changed: 12 additions & 38 deletions

File tree

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ fn build_error_for_const_call<'tcx>(
265265
}
266266
}
267267
CallKind::FnCall { fn_trait_id, self_ty } => {
268+
let kind = ccx.const_kind();
268269
let note = match self_ty.kind() {
269270
FnDef(def_id, ..) => {
270271
let span = tcx.def_span(*def_id);
@@ -274,8 +275,8 @@ fn build_error_for_const_call<'tcx>(
274275

275276
Some(errors::NonConstClosureNote::FnDef { span })
276277
}
277-
FnPtr(..) => Some(errors::NonConstClosureNote::FnPtr),
278-
Closure(..) => Some(errors::NonConstClosureNote::Closure),
278+
FnPtr(..) => Some(errors::NonConstClosureNote::FnPtr { kind }),
279+
Closure(..) => Some(errors::NonConstClosureNote::Closure { kind }),
279280
_ => None,
280281
};
281282

compiler/rustc_const_eval/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ pub enum NonConstClosureNote {
533533
*[other] {""}
534534
}s"#
535535
)]
536-
FnPtr,
536+
FnPtr { kind: ConstContext },
537537
#[note(
538538
r#"closures need an RFC before allowed to be called in {$kind ->
539539
[const] constant
@@ -542,7 +542,7 @@ pub enum NonConstClosureNote {
542542
*[other] {""}
543543
}s"#
544544
)]
545-
Closure,
545+
Closure { kind: ConstContext },
546546
}
547547

548548
#[derive(Subdiagnostic)]

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2242,10 +2242,10 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
22422242
EXPLICIT_OUTLIVES_REQUIREMENTS,
22432243
lint_spans.clone(),
22442244
BuiltinExplicitOutlives {
2245-
count: bound_count,
22462245
suggestion: BuiltinExplicitOutlivesSuggestion {
22472246
spans: lint_spans,
22482247
applicability,
2248+
count: bound_count,
22492249
},
22502250
},
22512251
);

compiler/rustc_lint/src/lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,6 @@ pub(crate) struct BuiltinKeywordIdents {
493493
#[derive(Diagnostic)]
494494
#[diag("outlives requirements can be inferred")]
495495
pub(crate) struct BuiltinExplicitOutlives {
496-
pub count: usize,
497496
#[subdiagnostic]
498497
pub suggestion: BuiltinExplicitOutlivesSuggestion,
499498
}
@@ -510,6 +509,7 @@ pub(crate) struct BuiltinExplicitOutlivesSuggestion {
510509
pub spans: Vec<Span>,
511510
#[applicability]
512511
pub applicability: Applicability,
512+
pub count: usize,
513513
}
514514

515515
#[derive(Diagnostic)]

compiler/rustc_parse/src/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ pub(crate) enum MatchArmBodyWithoutBracesSugg {
11791179
left: Span,
11801180
#[suggestion_part(code = " }}")]
11811181
right: Span,
1182+
num_statements: usize,
11821183
},
11831184
#[suggestion(
11841185
"replace `;` with `,` to end a `match` arm expression",

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3207,6 +3207,7 @@ impl<'a> Parser<'a> {
32073207
errors::MatchArmBodyWithoutBracesSugg::AddBraces {
32083208
left: span.shrink_to_lo(),
32093209
right: span.shrink_to_hi(),
3210+
num_statements: stmts.len(),
32103211
}
32113212
} else {
32123213
errors::MatchArmBodyWithoutBracesSugg::UseComma { semicolon: semi_sp }

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-tidy-filelength
12
use std::ops::ControlFlow;
23

34
use itertools::Itertools as _;
@@ -579,6 +580,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
579580
errs::GenericParamsFromOuterItemInnerItem {
580581
span: *span,
581582
descr: kind.descr().to_string(),
583+
is_self,
582584
}
583585
}),
584586
};

compiler/rustc_resolve/src/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub(crate) struct GenericParamsFromOuterItemInnerItem {
5252
#[primary_span]
5353
pub(crate) span: Span,
5454
pub(crate) descr: String,
55+
pub(crate) is_self: bool,
5556
}
5657

5758
#[derive(Subdiagnostic)]

compiler/rustc_trait_selection/src/errors.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,38 +1227,6 @@ impl Subdiagnostic for DynTraitConstraintSuggestion {
12271227
}
12281228
}
12291229

1230-
#[derive(Diagnostic)]
1231-
#[diag("{$has_param_name ->
1232-
[true] `{$param_name}`
1233-
*[false] `fn` parameter
1234-
} has {$lifetime_kind ->
1235-
[true] lifetime `{$lifetime}`
1236-
*[false] an anonymous lifetime `'_`
1237-
} but calling `{$assoc_item}` introduces an implicit `'static` lifetime requirement", code = E0772)]
1238-
pub struct ButCallingIntroduces {
1239-
#[label(
1240-
"{$has_lifetime ->
1241-
[true] lifetime `{$lifetime}`
1242-
*[false] an anonymous lifetime `'_`
1243-
}"
1244-
)]
1245-
pub param_ty_span: Span,
1246-
#[primary_span]
1247-
#[label("...is used and required to live as long as `'static` here because of an implicit lifetime bound on the {$has_impl_path ->
1248-
[true] `impl` of `{$impl_path}`
1249-
*[false] inherent `impl`
1250-
}")]
1251-
pub cause_span: Span,
1252-
1253-
pub has_param_name: bool,
1254-
pub param_name: String,
1255-
pub has_lifetime: bool,
1256-
pub lifetime: String,
1257-
pub assoc_item: Symbol,
1258-
pub has_impl_path: bool,
1259-
pub impl_path: String,
1260-
}
1261-
12621230
pub struct ReqIntroducedLocations {
12631231
pub span: MultiSpan,
12641232
pub spans: Vec<Span>,

0 commit comments

Comments
 (0)