diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-04-29 13:16:26 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-04-29 14:19:36 +0100 |
commit | eb2c6124c46d0b3d58630c80af007ed092adc1ea (patch) | |
tree | 2abecea3993a36362857f6e450a4781232a5dfca /gcc/rust | |
parent | f189f5bbab73b5d04faee4f4d2198f023c9e1522 (diff) | |
download | gcc-eb2c6124c46d0b3d58630c80af007ed092adc1ea.zip gcc-eb2c6124c46d0b3d58630c80af007ed092adc1ea.tar.gz gcc-eb2c6124c46d0b3d58630c80af007ed092adc1ea.tar.bz2 |
Improve error messages of unexpected arguments
When we get GenericBindings such as ::<A=...> this is not allowed
int this context. We can also improve the unexpected number of argument
errors to print the number of expected vs received arguments.
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index b75c139..c8f5f19 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -211,16 +211,32 @@ SubstitutionParamMapping::override_context () SubstitutionArgumentMappings SubstitutionRef::get_mappings_from_generic_args (HIR::GenericArgs &args) { - if (args.get_type_args ().size () != substitutions.size ()) + if (args.get_binding_args ().size () > 0) { rust_error_at (args.get_locus (), - "Invalid number of generic arguments to generic type"); + "associated type bindings are not allowed here"); return SubstitutionArgumentMappings::error (); } - std::vector<SubstitutionArg> mappings; + if (args.get_type_args ().size () > substitutions.size ()) + { + rust_error_at ( + args.get_locus (), + "generic item takes at most %lu type arguments but %lu were supplied", + substitutions.size (), args.get_type_args ().size ()); + return SubstitutionArgumentMappings::error (); + } - // FIXME does not support binding yet + if (args.get_type_args ().size () < substitutions.size ()) + { + rust_error_at ( + args.get_locus (), + "generic item takes at least %lu type arguments but %lu were supplied", + substitutions.size (), args.get_type_args ().size ()); + return SubstitutionArgumentMappings::error (); + } + + std::vector<SubstitutionArg> mappings; for (auto &arg : args.get_type_args ()) { BaseType *resolved = Resolver::TypeCheckType::Resolve (arg.get ()); |