Avoid an Option
that is always Some
This commit is contained in:
parent
61c4b7f1a7
commit
4dec6bbcb3
@ -610,7 +610,7 @@ pub(crate) fn check_generic_arg_count(
|
|||||||
explicit_late_bound,
|
explicit_late_bound,
|
||||||
correct: lifetimes_correct
|
correct: lifetimes_correct
|
||||||
.and(args_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
|
/// A marker denoting that the generic arguments that were
|
||||||
/// provided did not match the respective generic parameters.
|
/// provided did not match the respective generic parameters.
|
||||||
#[derive(Clone, Default, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct GenericArgCountMismatch {
|
pub struct GenericArgCountMismatch {
|
||||||
/// Indicates whether a fatal error was reported (`Some`), or just a lint (`None`).
|
pub reported: ErrorGuaranteed,
|
||||||
pub reported: Option<ErrorGuaranteed>,
|
|
||||||
/// A list of spans of arguments provided that were not valid.
|
/// A list of spans of arguments provided that were not valid.
|
||||||
pub invalid_args: Vec<Span>,
|
pub invalid_args: Vec<Span>,
|
||||||
}
|
}
|
||||||
@ -404,10 +403,8 @@ fn lower_generic_args_of_path(
|
|||||||
self_ty.is_some(),
|
self_ty.is_some(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Err(err) = &arg_count.correct
|
if let Err(err) = &arg_count.correct {
|
||||||
&& let Some(reported) = err.reported
|
self.set_tainted_by_errors(err.reported);
|
||||||
{
|
|
||||||
self.set_tainted_by_errors(reported);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip processing if type has no generic parameters.
|
// Skip processing if type has no generic parameters.
|
||||||
@ -584,13 +581,12 @@ fn inferred_kind(
|
|||||||
&& generics.has_self
|
&& generics.has_self
|
||||||
&& !tcx.has_attr(def_id, sym::const_trait)
|
&& !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,
|
span,
|
||||||
modifier: constness.as_str(),
|
modifier: constness.as_str(),
|
||||||
});
|
});
|
||||||
self.set_tainted_by_errors(e);
|
self.set_tainted_by_errors(reported);
|
||||||
arg_count.correct =
|
arg_count.correct = Err(GenericArgCountMismatch { reported, invalid_args: vec![] });
|
||||||
Err(GenericArgCountMismatch { reported: Some(e), invalid_args: vec![] });
|
|
||||||
}
|
}
|
||||||
let args = lower_generic_args(
|
let args = lower_generic_args(
|
||||||
tcx,
|
tcx,
|
||||||
|
@ -1118,7 +1118,7 @@ pub fn instantiate_value_path(
|
|||||||
// to add defaults. If the user provided *too many* types, that's
|
// to add defaults. If the user provided *too many* types, that's
|
||||||
// a problem.
|
// a problem.
|
||||||
|
|
||||||
let mut infer_args_for_err = FxHashSet::default();
|
let mut infer_args_for_err = None;
|
||||||
|
|
||||||
let mut explicit_late_bound = ExplicitLateBound::No;
|
let mut explicit_late_bound = ExplicitLateBound::No;
|
||||||
for &GenericPathSegment(def_id, index) in &generic_segments {
|
for &GenericPathSegment(def_id, index) in &generic_segments {
|
||||||
@ -1136,9 +1136,12 @@ pub fn instantiate_value_path(
|
|||||||
explicit_late_bound = ExplicitLateBound::Yes;
|
explicit_late_bound = ExplicitLateBound::Yes;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(GenericArgCountMismatch { reported: Some(e), .. }) = arg_count.correct {
|
if let Err(GenericArgCountMismatch { reported, .. }) = arg_count.correct {
|
||||||
infer_args_for_err.insert(index);
|
infer_args_for_err
|
||||||
self.set_tainted_by_errors(e); // See issue #53251.
|
.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 def_id = res.def_id();
|
||||||
|
|
||||||
let arg_count = GenericArgCountResult {
|
let (correct, infer_args_for_err) = match infer_args_for_err {
|
||||||
explicit_late_bound,
|
Some((reported, args)) => {
|
||||||
correct: if infer_args_for_err.is_empty() {
|
(Err(GenericArgCountMismatch { reported, invalid_args: vec![] }), args)
|
||||||
Ok(())
|
}
|
||||||
} else {
|
None => (Ok(()), Default::default()),
|
||||||
Err(GenericArgCountMismatch::default())
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let arg_count = GenericArgCountResult { explicit_late_bound, correct };
|
||||||
|
|
||||||
struct CtorGenericArgsCtxt<'a, 'tcx> {
|
struct CtorGenericArgsCtxt<'a, 'tcx> {
|
||||||
fcx: &'a FnCtxt<'a, 'tcx>,
|
fcx: &'a FnCtxt<'a, 'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
Loading…
Reference in New Issue
Block a user