Skip to content

Commit

Permalink
Use ErrorGuaranteed more
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Dec 15, 2024
1 parent 0f82cff commit 8c8e8d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use rustc_ast::visit::{
use rustc_ast::*;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_errors::codes::*;
use rustc_errors::{Applicability, DiagArgValue, IntoDiagArg, StashKey, Suggestions};
use rustc_errors::{
Applicability, DiagArgValue, ErrorGuaranteed, IntoDiagArg, StashKey, Suggestions,
};
use rustc_hir::def::Namespace::{self, *};
use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, NonMacroAttrKind, PartialRes, PerNS};
use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId};
Expand Down Expand Up @@ -264,7 +266,7 @@ impl RibKind<'_> {
#[derive(Debug)]
pub(crate) struct Rib<'ra, R = Res> {
pub bindings: IdentMap<R>,
pub patterns_with_skipped_bindings: FxHashMap<DefId, Vec<(Span, bool /* recovered error */)>>,
pub patterns_with_skipped_bindings: FxHashMap<DefId, Vec<(Span, Result<(), ErrorGuaranteed>)>>,
pub kind: RibKind<'ra>,
}

Expand Down Expand Up @@ -3841,7 +3843,10 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
.patterns_with_skipped_bindings
.entry(def_id)
.or_default()
.push((pat.span, matches!(rest, ast::PatFieldsRest::Recovered(_))));
.push((pat.span, match rest {
ast::PatFieldsRest::Recovered(guar) => Err(*guar),
_ => Ok(()),
}));
}
}
ast::PatFieldsRest::None => {}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
if let Some(fields) = self.r.field_idents(*def_id) {
for field in fields {
if field.name == segment.ident.name {
if spans.iter().all(|(_, was_recovered)| *was_recovered) {
if spans.iter().all(|(_, had_error)| had_error.is_err()) {
// This resolution error will likely be fixed by fixing a
// syntax error in a pattern, so it is irrelevant to the user.
let multispan: MultiSpan =
Expand All @@ -1148,15 +1148,15 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
}
let mut multispan: MultiSpan = spans
.iter()
.filter(|(_, was_recovered)| !was_recovered)
.filter(|(_, had_error)| had_error.is_ok())
.map(|(sp, _)| *sp)
.collect::<Vec<_>>()
.into();
let def_span = self.r.def_span(*def_id);
let ty = self.r.tcx.item_name(*def_id);
multispan.push_span_label(def_span, String::new());
multispan.push_span_label(field.span, "defined here".to_string());
for (span, _) in spans.iter().filter(|(_, r)| !r) {
for (span, _) in spans.iter().filter(|(_, had_err)| had_err.is_ok()) {
multispan.push_span_label(
*span,
format!(
Expand Down

0 comments on commit 8c8e8d3

Please sign in to comment.