Skip to content

Commit 5b84a49

Browse files
committed
gccrs: add diagnostic for E0229 no associated type arguments allowed here
It seems bounds in qualified paths are not allowed to specify associated type bindings because its going to be associated with the impl block anyway. Fixes #2369 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.h: add flag * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise * typecheck/rust-tyty-bounds.cc: new diagnostic gcc/testsuite/ChangeLog: * rust/compile/issue-2369.rs: New test. Signed-off-by: Philip Herron <[email protected]>
1 parent e9e0310 commit 5b84a49

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

gcc/rust/typecheck/rust-hir-type-check-base.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class TypeCheckBase
4040
TyTy::TypeBoundPredicate get_predicate_from_bound (
4141
HIR::TypePath &path,
4242
tl::optional<std::reference_wrapper<HIR::Type>> associated_self,
43-
BoundPolarity polarity = BoundPolarity::RegularBound);
43+
BoundPolarity polarity = BoundPolarity::RegularBound,
44+
bool is_qualified_type = false);
4445

4546
bool check_for_unconstrained (
4647
const std::vector<TyTy::SubstitutionParamMapping> &params_to_constrain,

gcc/rust/typecheck/rust-hir-type-check-type.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
193193
return;
194194

195195
// get the predicate for the bound
196-
auto specified_bound = get_predicate_from_bound (qual_path_type.get_trait (),
197-
qual_path_type.get_type ());
196+
auto specified_bound
197+
= get_predicate_from_bound (qual_path_type.get_trait (),
198+
qual_path_type.get_type (),
199+
BoundPolarity::RegularBound, true);
198200
if (specified_bound.is_error ())
199201
return;
200202

gcc/rust/typecheck/rust-tyty-bounds.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ TyTy::TypeBoundPredicate
196196
TypeCheckBase::get_predicate_from_bound (
197197
HIR::TypePath &type_path,
198198
tl::optional<std::reference_wrapper<HIR::Type>> associated_self,
199-
BoundPolarity polarity)
199+
BoundPolarity polarity, bool is_qualified_type_path)
200200
{
201201
TyTy::TypeBoundPredicate lookup = TyTy::TypeBoundPredicate::error ();
202202
bool already_resolved
@@ -222,6 +222,21 @@ TypeCheckBase::get_predicate_from_bound (
222222
if (final_generic_seg.has_generic_args ())
223223
{
224224
args = final_generic_seg.get_generic_args ();
225+
if (args.get_binding_args ().size () > 0
226+
&& associated_self.has_value () && is_qualified_type_path)
227+
{
228+
auto &binding_args = args.get_binding_args ();
229+
230+
rich_location r (line_table, args.get_locus ());
231+
for (auto it = binding_args.begin (); it != binding_args.end ();
232+
it++)
233+
{
234+
auto &arg = *it;
235+
r.add_fixit_remove (arg.get_locus ());
236+
}
237+
rust_error_at (r, ErrorCode::E0229,
238+
"associated type bindings are not allowed here");
239+
}
225240
}
226241
}
227242
break;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#[lang = "sized"]
2+
trait Sized {}
3+
4+
fn main() {
5+
pub trait Foo {
6+
type A;
7+
fn boo(&self) -> <Self as Foo>::A;
8+
}
9+
10+
struct Bar;
11+
12+
impl Foo for isize {
13+
type A = usize;
14+
fn boo(&self) -> usize {
15+
42
16+
}
17+
}
18+
19+
fn baz<I>(x: &<I as Foo<A = Bar>>::A) {}
20+
// { dg-error "associated type bindings are not allowed here .E0229." "" { target *-*-* } .-1 }
21+
}

0 commit comments

Comments
 (0)