mirror of
https://github.com/rust-lang/rust
synced 2024-11-05 20:45:15 +00:00
Avoid an Option
that is always Some
This commit is contained in:
parent
61c4b7f1a7
commit
4dec6bbcb3
3 changed files with 22 additions and 23 deletions
|
@ -610,7 +610,7 @@ pub(crate) fn check_generic_arg_count(
|
|||
explicit_late_bound,
|
||||
correct: lifetimes_correct
|
||||
.and(args_correct)
|
||||
.map_err(|reported| GenericArgCountMismatch { reported: Some(reported), invalid_args }),
|
||||
.map_err(|reported| GenericArgCountMismatch { reported, invalid_args }),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -215,10 +215,9 @@ pub(crate) enum GenericArgPosition {
|
|||
|
||||
/// A marker denoting that the generic arguments that were
|
||||
/// provided did not match the respective generic parameters.
|
||||
#[derive(Clone, Default, Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GenericArgCountMismatch {
|
||||
/// Indicates whether a fatal error was reported (`Some`), or just a lint (`None`).
|
||||
pub reported: Option<ErrorGuaranteed>,
|
||||
pub reported: ErrorGuaranteed,
|
||||
/// A list of spans of arguments provided that were not valid.
|
||||
pub invalid_args: Vec<Span>,
|
||||
}
|
||||
|
@ -404,10 +403,8 @@ fn lower_generic_args_of_path(
|
|||
self_ty.is_some(),
|
||||
);
|
||||
|
||||
if let Err(err) = &arg_count.correct
|
||||
&& let Some(reported) = err.reported
|
||||
{
|
||||
self.set_tainted_by_errors(reported);
|
||||
if let Err(err) = &arg_count.correct {
|
||||
self.set_tainted_by_errors(err.reported);
|
||||
}
|
||||
|
||||
// Skip processing if type has no generic parameters.
|
||||
|
@ -584,13 +581,12 @@ fn inferred_kind(
|
|||
&& generics.has_self
|
||||
&& !tcx.has_attr(def_id, sym::const_trait)
|
||||
{
|
||||
let e = tcx.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
|
||||
let reported = tcx.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
|
||||
span,
|
||||
modifier: constness.as_str(),
|
||||
});
|
||||
self.set_tainted_by_errors(e);
|
||||
arg_count.correct =
|
||||
Err(GenericArgCountMismatch { reported: Some(e), invalid_args: vec![] });
|
||||
self.set_tainted_by_errors(reported);
|
||||
arg_count.correct = Err(GenericArgCountMismatch { reported, invalid_args: vec![] });
|
||||
}
|
||||
let args = lower_generic_args(
|
||||
tcx,
|
||||
|
|
|
@ -1118,7 +1118,7 @@ pub fn instantiate_value_path(
|
|||
// to add defaults. If the user provided *too many* types, that's
|
||||
// a problem.
|
||||
|
||||
let mut infer_args_for_err = FxHashSet::default();
|
||||
let mut infer_args_for_err = None;
|
||||
|
||||
let mut explicit_late_bound = ExplicitLateBound::No;
|
||||
for &GenericPathSegment(def_id, index) in &generic_segments {
|
||||
|
@ -1136,9 +1136,12 @@ pub fn instantiate_value_path(
|
|||
explicit_late_bound = ExplicitLateBound::Yes;
|
||||
}
|
||||
|
||||
if let Err(GenericArgCountMismatch { reported: Some(e), .. }) = arg_count.correct {
|
||||
infer_args_for_err.insert(index);
|
||||
self.set_tainted_by_errors(e); // See issue #53251.
|
||||
if let Err(GenericArgCountMismatch { reported, .. }) = arg_count.correct {
|
||||
infer_args_for_err
|
||||
.get_or_insert_with(|| (reported, FxHashSet::default()))
|
||||
.1
|
||||
.insert(index);
|
||||
self.set_tainted_by_errors(reported); // See issue #53251.
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1232,15 +1235,15 @@ pub fn instantiate_value_path(
|
|||
};
|
||||
let def_id = res.def_id();
|
||||
|
||||
let arg_count = GenericArgCountResult {
|
||||
explicit_late_bound,
|
||||
correct: if infer_args_for_err.is_empty() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(GenericArgCountMismatch::default())
|
||||
},
|
||||
let (correct, infer_args_for_err) = match infer_args_for_err {
|
||||
Some((reported, args)) => {
|
||||
(Err(GenericArgCountMismatch { reported, invalid_args: vec![] }), args)
|
||||
}
|
||||
None => (Ok(()), Default::default()),
|
||||
};
|
||||
|
||||
let arg_count = GenericArgCountResult { explicit_late_bound, correct };
|
||||
|
||||
struct CtorGenericArgsCtxt<'a, 'tcx> {
|
||||
fcx: &'a FnCtxt<'a, 'tcx>,
|
||||
span: Span,
|
||||
|
|
Loading…
Reference in a new issue