Skip to content

Commit 31b2046

Browse files
committed
WIP: Silence type error
See rust-lang#96871
1 parent 4596f4f commit 31b2046

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

compiler/rustc_errors/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ pub enum StashKey {
466466
/// When an invalid lifetime e.g. `'2` should be reinterpreted
467467
/// as a char literal in the parser
468468
LifetimeIsChar,
469+
RangeLit,
469470
}
470471

471472
fn default_track_diagnostic(_: &Diagnostic) {}

compiler/rustc_hir_typeck/src/expr.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1613,9 +1613,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16131613
self.demand_coerce_diag(&field.expr, ty, field_type, None, AllowTwoPhase::No);
16141614

16151615
if let Some(mut diag) = diag {
1616-
if idx == ast_fields.len() - 1 && remaining_fields.is_empty() {
1617-
self.suggest_fru_from_range(field, variant, substs, &mut diag);
1616+
if idx == ast_fields.len() - 1 {
1617+
if remaining_fields.is_empty() {
1618+
self.suggest_fru_from_range(field, variant, substs, &mut diag);
1619+
} else {
1620+
diag.stash(diag.sort_span, StashKey::RangeLit)
1621+
}
16181622
}
1623+
16191624
diag.emit();
16201625
}
16211626
}
@@ -1807,7 +1812,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18071812
variant: &'tcx ty::VariantDef,
18081813
ast_fields: &'tcx [hir::ExprField<'tcx>],
18091814
substs: SubstsRef<'tcx>,
1810-
) {
1815+
) -> bool {
18111816
let len = remaining_fields.len();
18121817

18131818
let mut displayable_field_names: Vec<&str> =
@@ -1844,7 +1849,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18441849
);
18451850
err.span_label(span, format!("missing {remaining_fields_names}{truncated_fields_error}"));
18461851

1847-
if let Some(last) = ast_fields.last() {
1852+
if let Some(last) = ast_fields.last() && self.suggest_fru_from_range() {
1853+
// unstash and cancel
1854+
let un = self.tcx.sess.diagnostic().steal_diagnostic(span, StashKey::RangeLit).unwrap();
1855+
un.cancel();
18481856
self.suggest_fru_from_range(last, variant, substs, &mut err);
18491857
}
18501858

0 commit comments

Comments
 (0)