Skip to content

Commit c7b8f17

Browse files
committed
gccrs: [E0308] mismatch types on assignment
This errorcode emits when there are mismatch types between lhs & rhs of assignment operator & refactored message. gcc/rust/ChangeLog: * typecheck/rust-unify.cc (UnifyRules::emit_type_mismatch): refactored & called error function. gcc/testsuite/ChangeLog: * rust/compile/mismatched-types.rs: New test from rustc. Signed-off-by: Muhammad Mahad <[email protected]>
1 parent d20a2c2 commit c7b8f17

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

gcc/rust/typecheck/rust-unify.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ UnifyRules::emit_type_mismatch () const
122122
rich_location r (line_table, locus);
123123
r.add_range (lhs.get_locus ());
124124
r.add_range (rhs.get_locus ());
125-
rust_error_at (r, "expected %<%s%> got %<%s%>",
125+
rust_error_at (r, ErrorCode::E0308,
126+
"mismatched types, expected %qs but got %qs",
126127
expected->get_name ().c_str (), expr->get_name ().c_str ());
127128
}
128129

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// ErrorCode::E0308
2+
#![allow(unused)]
3+
fn main() {
4+
fn plus_one(x: i32) -> i32 {
5+
x + 1
6+
}
7+
plus_one("Not a number"); // { dg-error "mismatched types, expected .i32. but got .&str." }
8+
let x: f32 = "Not a float"; // { dg-error "mismatched types, expected .f32. but got .&str." }
9+
}

0 commit comments

Comments
 (0)