Skip to content

WIP: Silence type error #103838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ pub enum StashKey {
/// When an invalid lifetime e.g. `'2` should be reinterpreted
/// as a char literal in the parser
LifetimeIsChar,
RangeLit,
}

fn default_track_diagnostic(_: &Diagnostic) {}
Expand Down
21 changes: 17 additions & 4 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,9 +1613,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.demand_coerce_diag(&field.expr, ty, field_type, None, AllowTwoPhase::No);

if let Some(mut diag) = diag {
if idx == ast_fields.len() - 1 && remaining_fields.is_empty() {
self.suggest_fru_from_range(field, variant, substs, &mut diag);
if idx == ast_fields.len() - 1 {
if remaining_fields.is_empty() {
self.suggest_fru_from_range(field, variant, substs, &mut diag);
} else {
diag.clone().stash(diag.sort_span, StashKey::RangeLit);
}
}

diag.emit();
}
}
Expand Down Expand Up @@ -1844,7 +1849,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
err.span_label(span, format!("missing {remaining_fields_names}{truncated_fields_error}"));

if let Some(last) = ast_fields.last() {
if let Some(last) = ast_fields.last()
&& self.suggest_fru_from_range(last, variant, substs, &mut err) {
// unstash and cancel
let un = self.tcx.sess.diagnostic().steal_diagnostic(span, StashKey::RangeLit).unwrap();
un.cancel();
self.suggest_fru_from_range(last, variant, substs, &mut err);
}

Expand All @@ -1859,7 +1868,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
variant: &ty::VariantDef,
substs: SubstsRef<'tcx>,
err: &mut Diagnostic,
) {
) -> bool {
// I don't use 'is_range_literal' because only double-sided, half-open ranges count.
if let ExprKind::Struct(
QPath::LangItem(LangItem::Range, ..),
Expand Down Expand Up @@ -1887,7 +1896,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
",",
Applicability::MaybeIncorrect,
);

return true;
}

return false;
}

/// Report an error for a struct field expression when there are invisible fields.
Expand Down