Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions gcc/rust/hir/rust-ast-lower-item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,15 @@ ASTLoweringItem::visit (AST::InherentImpl &impl_block)

if (t.has_type ())
{
// see https://github.com/rust-lang/rust/issues/36887
rust_error_at (
rich_location rich_locus (line_table, t.get_locus ());
rich_locus.add_fixit_replace (
t.get_locus (),
"defaults for type parameters are not allowed here");
"for more information, see issue #36887 "
"<https://github.com/rust-lang/rust/issues/36887>");
rust_error_at (rich_locus,
"defaults for type parameters are only "
"allowed in %<struct%>, %<enum%>, %<type%>, "
"or %<trait%> definitions");
}
}
break;
Expand Down Expand Up @@ -645,10 +650,15 @@ ASTLoweringItem::visit (AST::TraitImpl &impl_block)

if (t.has_type ())
{
// see https://github.com/rust-lang/rust/issues/36887
rust_error_at (
t.get_locus (),
"defaults for type parameters are not allowed here");
rich_location rich_locus (line_table, t.get_locus ());
rich_locus.add_fixit_replace (
t.get_locus (), "for more information, see issue #36887 "
"<https://github.com/rust-lang/rust/"
"issues/36887>");
rust_error_at (rich_locus,
"defaults for type parameters are only "
"allowed in %<struct%>, %<enum%>, %<type%>, "
"or %<trait%> definitions");
Comment on lines +653 to +661
Copy link
Member

Choose a reason for hiding this comment

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

nice, it looks good! in a different PR, could you factor these lines in a separate function? this way we can modify the error message without changing it in two places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@philberty left this issue to me to decide, whether to create a separate class for refactoring these errors.

But that seems excessive. What do you think, @CohenArthur? Should I create a separate class or add a refactor function when we encounter these cases?

Copy link
Member

Choose a reason for hiding this comment

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

A separate class or a separate function is a good idea. I like both :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay :)

}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/generics10.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct Foo<A, B>(A, B);

impl<X = i32> Foo<X, f32> { // { dg-error "defaults for type parameters are not allowed here" }
impl<X = i32> Foo<X, f32> { // { dg-error "defaults for type parameters are only allowed in .struct., .enum., .type., or .trait. definitions" }
fn new(a: X, b: f32) -> Self {
Self(a, b)
}
Expand Down