Skip to content

Commit 104131c

Browse files
committed
Use Result instead of bool throughout
1 parent dff64eb commit 104131c

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/librustc_typeck/astconv.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
317317
}
318318

319319
// Prohibit explicit lifetime arguments if late-bound lifetime parameters are present.
320-
let mut reported_late_bound_region_err = false;
320+
let mut explicit_lifetimes = Ok(());
321321
if !infer_lifetimes {
322322
if let Some(span_late) = def.has_late_bound_regions {
323-
reported_late_bound_region_err = true;
323+
explicit_lifetimes = Err(GenericArgCountMismatch);
324324
let msg = "cannot specify lifetime arguments explicitly \
325325
if late bound lifetime parameters are present";
326326
let note = "the late bound lifetime parameter is introduced here";
@@ -354,7 +354,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
354354
// For kinds without defaults (e.g.., lifetimes), `required == permitted`.
355355
// For other kinds (i.e., types), `permitted` may be greater than `required`.
356356
if required <= provided && provided <= permitted {
357-
return false;
357+
return Ok(());
358358
}
359359

360360
// Unfortunately lifetime and type parameter mismatches are typically styled
@@ -405,49 +405,49 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
405405
}
406406
err.emit();
407407

408-
true
408+
Err(GenericArgCountMismatch)
409409
};
410410

411-
let mut arg_count_mismatch = reported_late_bound_region_err;
411+
let mut arg_count_correct = explicit_lifetimes;
412412
let mut unexpected_spans = vec![];
413413

414-
if !reported_late_bound_region_err
414+
if arg_count_correct.is_ok()
415415
&& (!infer_lifetimes || arg_counts.lifetimes > param_counts.lifetimes)
416416
{
417-
arg_count_mismatch |= check_kind_count(
417+
arg_count_correct = arg_count_correct.and(check_kind_count(
418418
"lifetime",
419419
param_counts.lifetimes,
420420
param_counts.lifetimes,
421421
arg_counts.lifetimes,
422422
0,
423423
&mut unexpected_spans,
424-
);
424+
));
425425
}
426426
// FIXME(const_generics:defaults)
427427
if !infer_args || arg_counts.consts > param_counts.consts {
428-
arg_count_mismatch |= check_kind_count(
428+
arg_count_correct = arg_count_correct.and(check_kind_count(
429429
"const",
430430
param_counts.consts,
431431
param_counts.consts,
432432
arg_counts.consts,
433433
arg_counts.lifetimes + arg_counts.types,
434434
&mut unexpected_spans,
435-
);
435+
));
436436
}
437437
// Note that type errors are currently be emitted *after* const errors.
438438
if !infer_args || arg_counts.types > param_counts.types - defaults.types - has_self as usize
439439
{
440-
arg_count_mismatch |= check_kind_count(
440+
arg_count_correct = arg_count_correct.and(check_kind_count(
441441
"type",
442442
param_counts.types - defaults.types - has_self as usize,
443443
param_counts.types - has_self as usize,
444444
arg_counts.types,
445445
arg_counts.lifetimes,
446446
&mut unexpected_spans,
447-
);
447+
));
448448
}
449449

450-
(if arg_count_mismatch { Err(GenericArgCountMismatch) } else { Ok(()) }, unexpected_spans)
450+
(arg_count_correct, unexpected_spans)
451451
}
452452

453453
/// Report an error that a generic argument did not match the generic parameter that was

0 commit comments

Comments
 (0)