Skip to content

Commit a422946

Browse files
authored
Unrolled build for rust-lang#120342
Rollup merge of rust-lang#120342 - oli-obk:track_errors6, r=nnethercote Remove various `has_errors` or `err_count` uses follow up to rust-lang#119895 r? `@nnethercote` since you recently did something similar. There are so many more of these, but I wanted to get a PR out instead of growing the commit list indefinitely. The commits all work on their own and can be reviewed commit by commit.
2 parents 5ad7454 + 054e1e3 commit a422946

File tree

9 files changed

+186
-193
lines changed

9 files changed

+186
-193
lines changed

compiler/rustc_builtin_macros/src/format.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ fn parse_args<'a>(ecx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<
139139
_ => {
140140
let expr = p.parse_expr()?;
141141
if !args.named_args().is_empty() {
142-
ecx.dcx().emit_err(errors::PositionalAfterNamed {
142+
return Err(ecx.dcx().create_err(errors::PositionalAfterNamed {
143143
span: expr.span,
144144
args: args
145145
.named_args()
146146
.iter()
147147
.filter_map(|a| a.kind.ident().map(|ident| (a, ident)))
148148
.map(|(arg, n)| n.span.to(arg.expr.span))
149149
.collect(),
150-
});
150+
}));
151151
}
152152
args.add(FormatArgument { kind: FormatArgumentKind::Normal, expr });
153153
}
@@ -313,6 +313,8 @@ fn make_format_args(
313313
}
314314
use ArgRef::*;
315315

316+
let mut unnamed_arg_after_named_arg = false;
317+
316318
let mut lookup_arg = |arg: ArgRef<'_>,
317319
span: Option<Span>,
318320
used_as: PositionUsedAs,
@@ -352,6 +354,7 @@ fn make_format_args(
352354
// For the moment capturing variables from format strings expanded from macros is
353355
// disabled (see RFC #2795)
354356
ecx.dcx().emit_err(errors::FormatNoArgNamed { span, name });
357+
unnamed_arg_after_named_arg = true;
355358
DummyResult::raw_expr(span, true)
356359
};
357360
Ok(args.add(FormatArgument { kind: FormatArgumentKind::Captured(ident), expr }))
@@ -510,7 +513,8 @@ fn make_format_args(
510513
})
511514
.collect::<Vec<_>>();
512515

513-
if !unused.is_empty() {
516+
let has_unused = !unused.is_empty();
517+
if has_unused {
514518
// If there's a lot of unused arguments,
515519
// let's check if this format arguments looks like another syntax (printf / shell).
516520
let detect_foreign_fmt = unused.len() > args.explicit_args().len() / 2;
@@ -529,7 +533,7 @@ fn make_format_args(
529533

530534
// Only check for unused named argument names if there are no other errors to avoid causing
531535
// too much noise in output errors, such as when a named argument is entirely unused.
532-
if invalid_refs.is_empty() && ecx.dcx().has_errors().is_none() {
536+
if invalid_refs.is_empty() && !has_unused && !unnamed_arg_after_named_arg {
533537
for &(index, span, used_as) in &numeric_refences_to_named_arg {
534538
let (position_sp_to_replace, position_sp_for_msg) = match used_as {
535539
Placeholder(pspan) => (span, pspan),

compiler/rustc_expand/src/mbe/macro_rules.rs

+24-15
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ pub fn compile_declarative_macro(
485485
)
486486
.pop()
487487
.unwrap();
488-
valid &= check_lhs_nt_follows(sess, def, &tt);
488+
// We don't handle errors here, the driver will abort
489+
// after parsing/expansion. we can report every error in every macro this way.
490+
valid &= check_lhs_nt_follows(sess, def, &tt).is_ok();
489491
return tt;
490492
}
491493
sess.dcx().span_bug(def.span, "wrong-structured lhs")
@@ -589,18 +591,19 @@ pub fn compile_declarative_macro(
589591
(mk_syn_ext(expander), rule_spans)
590592
}
591593

592-
fn check_lhs_nt_follows(sess: &Session, def: &ast::Item, lhs: &mbe::TokenTree) -> bool {
594+
fn check_lhs_nt_follows(
595+
sess: &Session,
596+
def: &ast::Item,
597+
lhs: &mbe::TokenTree,
598+
) -> Result<(), ErrorGuaranteed> {
593599
// lhs is going to be like TokenTree::Delimited(...), where the
594600
// entire lhs is those tts. Or, it can be a "bare sequence", not wrapped in parens.
595601
if let mbe::TokenTree::Delimited(.., delimited) = lhs {
596602
check_matcher(sess, def, &delimited.tts)
597603
} else {
598604
let msg = "invalid macro matcher; matchers must be contained in balanced delimiters";
599-
sess.dcx().span_err(lhs.span(), msg);
600-
false
605+
Err(sess.dcx().span_err(lhs.span(), msg))
601606
}
602-
// we don't abort on errors on rejection, the driver will do that for us
603-
// after parsing/expansion. we can report every error in every macro this way.
604607
}
605608

606609
fn is_empty_token_tree(sess: &Session, seq: &mbe::SequenceRepetition) -> bool {
@@ -675,12 +678,15 @@ fn check_rhs(sess: &Session, rhs: &mbe::TokenTree) -> bool {
675678
false
676679
}
677680

678-
fn check_matcher(sess: &Session, def: &ast::Item, matcher: &[mbe::TokenTree]) -> bool {
681+
fn check_matcher(
682+
sess: &Session,
683+
def: &ast::Item,
684+
matcher: &[mbe::TokenTree],
685+
) -> Result<(), ErrorGuaranteed> {
679686
let first_sets = FirstSets::new(matcher);
680687
let empty_suffix = TokenSet::empty();
681-
let err = sess.dcx().err_count();
682-
check_matcher_core(sess, def, &first_sets, matcher, &empty_suffix);
683-
err == sess.dcx().err_count()
688+
check_matcher_core(sess, def, &first_sets, matcher, &empty_suffix)?;
689+
Ok(())
684690
}
685691

686692
fn has_compile_error_macro(rhs: &mbe::TokenTree) -> bool {
@@ -1020,11 +1026,13 @@ fn check_matcher_core<'tt>(
10201026
first_sets: &FirstSets<'tt>,
10211027
matcher: &'tt [mbe::TokenTree],
10221028
follow: &TokenSet<'tt>,
1023-
) -> TokenSet<'tt> {
1029+
) -> Result<TokenSet<'tt>, ErrorGuaranteed> {
10241030
use mbe::TokenTree;
10251031

10261032
let mut last = TokenSet::empty();
10271033

1034+
let mut errored = Ok(());
1035+
10281036
// 2. For each token and suffix [T, SUFFIX] in M:
10291037
// ensure that T can be followed by SUFFIX, and if SUFFIX may be empty,
10301038
// then ensure T can also be followed by any element of FOLLOW.
@@ -1068,7 +1076,7 @@ fn check_matcher_core<'tt>(
10681076
token::CloseDelim(d.delim),
10691077
span.close,
10701078
));
1071-
check_matcher_core(sess, def, first_sets, &d.tts, &my_suffix);
1079+
check_matcher_core(sess, def, first_sets, &d.tts, &my_suffix)?;
10721080
// don't track non NT tokens
10731081
last.replace_with_irrelevant();
10741082

@@ -1100,7 +1108,7 @@ fn check_matcher_core<'tt>(
11001108
// At this point, `suffix_first` is built, and
11011109
// `my_suffix` is some TokenSet that we can use
11021110
// for checking the interior of `seq_rep`.
1103-
let next = check_matcher_core(sess, def, first_sets, &seq_rep.tts, my_suffix);
1111+
let next = check_matcher_core(sess, def, first_sets, &seq_rep.tts, my_suffix)?;
11041112
if next.maybe_empty {
11051113
last.add_all(&next);
11061114
} else {
@@ -1206,14 +1214,15 @@ fn check_matcher_core<'tt>(
12061214
));
12071215
}
12081216
}
1209-
err.emit();
1217+
errored = Err(err.emit());
12101218
}
12111219
}
12121220
}
12131221
}
12141222
}
12151223
}
1216-
last
1224+
errored?;
1225+
Ok(last)
12171226
}
12181227

12191228
fn token_can_be_followed_by_any(tok: &mbe::TokenTree) -> bool {

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
426426
.map(|vars| self.resolve_vars_if_possible(vars)),
427427
);
428428

429-
self.report_arg_errors(
429+
self.set_tainted_by_errors(self.report_arg_errors(
430430
compatibility_diagonal,
431431
formal_and_expected_inputs,
432432
provided_args,
@@ -435,7 +435,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
435435
fn_def_id,
436436
call_span,
437437
call_expr,
438-
);
438+
));
439439
}
440440
}
441441

@@ -449,7 +449,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
449449
fn_def_id: Option<DefId>,
450450
call_span: Span,
451451
call_expr: &'tcx hir::Expr<'tcx>,
452-
) {
452+
) -> ErrorGuaranteed {
453453
// Next, let's construct the error
454454
let (error_span, full_call_span, call_name, is_method) = match &call_expr.kind {
455455
hir::ExprKind::Call(
@@ -488,10 +488,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
488488
}
489489

490490
let tcx = self.tcx;
491-
// FIXME: taint after emitting errors and pass through an `ErrorGuaranteed`
492-
self.set_tainted_by_errors(
493-
tcx.dcx().span_delayed_bug(call_span, "no errors reported for args"),
494-
);
495491

496492
// Get the argument span in the context of the call span so that
497493
// suggestions and labels are (more) correct when an arg is a
@@ -698,8 +694,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
698694
Some(mismatch_idx),
699695
is_method,
700696
);
701-
err.emit();
702-
return;
697+
return err.emit();
703698
}
704699
}
705700
}
@@ -723,11 +718,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
723718
if cfg!(debug_assertions) {
724719
span_bug!(error_span, "expected errors from argument matrix");
725720
} else {
726-
tcx.dcx().emit_err(errors::ArgMismatchIndeterminate { span: error_span });
721+
return tcx.dcx().emit_err(errors::ArgMismatchIndeterminate { span: error_span });
727722
}
728-
return;
729723
}
730724

725+
let mut reported = None;
731726
errors.retain(|error| {
732727
let Error::Invalid(provided_idx, expected_idx, Compatibility::Incompatible(Some(e))) =
733728
error
@@ -738,16 +733,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
738733
let trace =
739734
mk_trace(provided_span, formal_and_expected_inputs[*expected_idx], provided_ty);
740735
if !matches!(trace.cause.as_failure_code(*e), FailureCode::Error0308) {
741-
self.err_ctxt().report_and_explain_type_error(trace, *e).emit();
736+
reported = Some(self.err_ctxt().report_and_explain_type_error(trace, *e).emit());
742737
return false;
743738
}
744739
true
745740
});
746741

747742
// We're done if we found errors, but we already emitted them.
748-
if errors.is_empty() {
749-
return;
743+
if let Some(reported) = reported {
744+
assert!(errors.is_empty());
745+
return reported;
750746
}
747+
assert!(!errors.is_empty());
751748

752749
// Okay, now that we've emitted the special errors separately, we
753750
// are only left missing/extra/swapped and mismatched arguments, both
@@ -804,8 +801,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
804801
Some(expected_idx.as_usize()),
805802
is_method,
806803
);
807-
err.emit();
808-
return;
804+
return err.emit();
809805
}
810806

811807
let mut err = if formal_and_expected_inputs.len() == provided_args.len() {
@@ -1253,7 +1249,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12531249
);
12541250
}
12551251

1256-
err.emit();
1252+
err.emit()
12571253
}
12581254

12591255
fn suggest_ptr_null_mut(

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

-13
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ pub struct FnCtxt<'a, 'tcx> {
4545
/// eventually).
4646
pub(super) param_env: ty::ParamEnv<'tcx>,
4747

48-
/// Number of errors that had been reported when we started
49-
/// checking this function. On exit, if we find that *more* errors
50-
/// have been reported, we will skip regionck and other work that
51-
/// expects the types within the function to be consistent.
52-
// FIXME(matthewjasper) This should not exist, and it's not correct
53-
// if type checking is run in parallel.
54-
err_count_on_creation: usize,
55-
5648
/// If `Some`, this stores coercion information for returned
5749
/// expressions. If `None`, this is in a context where return is
5850
/// inappropriate, such as a const expression.
@@ -126,7 +118,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
126118
FnCtxt {
127119
body_id,
128120
param_env,
129-
err_count_on_creation: inh.tcx.dcx().err_count(),
130121
ret_coercion: None,
131122
ret_coercion_span: Cell::new(None),
132123
coroutine_types: None,
@@ -195,10 +186,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
195186
}),
196187
}
197188
}
198-
199-
pub fn errors_reported_since_creation(&self) -> bool {
200-
self.dcx().err_count() > self.err_count_on_creation
201-
}
202189
}
203190

204191
impl<'a, 'tcx> Deref for FnCtxt<'a, 'tcx> {

compiler/rustc_infer/src/infer/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ pub struct InferCtxt<'tcx> {
278278

279279
/// The set of predicates on which errors have been reported, to
280280
/// avoid reporting the same error twice.
281-
pub reported_trait_errors: RefCell<FxIndexMap<Span, Vec<ty::Predicate<'tcx>>>>,
281+
pub reported_trait_errors:
282+
RefCell<FxIndexMap<Span, (Vec<ty::Predicate<'tcx>>, ErrorGuaranteed)>>,
282283

283284
pub reported_signature_mismatch: RefCell<FxHashSet<(Span, Option<Span>)>>,
284285

0 commit comments

Comments
 (0)