Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Prev Previous commit
Next Next commit
Store indices of generic args instead of spans, as the actual entries…
… are unused, just the number of entries is checked.

The indices will be used in a follow-up commit
  • Loading branch information
oli-obk committed Jun 3, 2024
commit 24af952ef7bf02501bf7a991c1c2feb110c77a7f
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
pub(crate) fn complain_about_missing_assoc_tys(
&self,
associated_types: FxIndexMap<Span, FxIndexSet<DefId>>,
potential_assoc_types: Vec<Span>,
potential_assoc_types: Vec<usize>,
trait_bounds: &[hir::PolyTraitRef<'_>],
) {
if associated_types.values().all(|v| v.is_empty()) {
Expand Down
15 changes: 2 additions & 13 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,9 @@ pub(crate) fn check_generic_arg_count(
return Ok(());
}

if provided_args > max_expected_args {
invalid_args.extend(
gen_args.args[max_expected_args..provided_args].iter().map(|arg| arg.span()),
);
};
invalid_args.extend(min_expected_args..provided_args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this not give a backwards range (i.e. 2..1) if you have a fn foo<'a: 'a, 'b: 'b> and you call it foo::<'static>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but that's the prev behaviour. I just merged the two loops


let gen_args_info = if provided_args > min_expected_args {
invalid_args.extend(
gen_args.args[min_expected_args..provided_args].iter().map(|arg| arg.span()),
);
let num_redundant_args = provided_args - min_expected_args;
GenericArgsInfo::ExcessLifetimes { num_redundant_args }
} else {
Expand Down Expand Up @@ -538,11 +531,7 @@ pub(crate) fn check_generic_arg_count(
let num_default_params = expected_max - expected_min;

let gen_args_info = if provided > expected_max {
invalid_args.extend(
gen_args.args[args_offset + expected_max..args_offset + provided]
.iter()
.map(|arg| arg.span()),
);
invalid_args.extend((expected_max..provided).map(|i| i + args_offset));
let num_redundant_args = provided - expected_max;

// Provide extra note if synthetic arguments like `impl Trait` are specified.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ pub(crate) enum GenericArgPosition {
#[derive(Clone, Debug)]
pub struct GenericArgCountMismatch {
pub reported: ErrorGuaranteed,
/// A list of spans of arguments provided that were not valid.
pub invalid_args: Vec<Span>,
/// A list of indices of arguments provided that were not valid.
pub invalid_args: Vec<usize>,
}

/// Decorates the result of a generic argument count mismatch
Expand Down