Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[E0308] mismatch types on both sides of assignment Operator #2494

Merged
merged 1 commit into from
Aug 2, 2023
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
3 changes: 2 additions & 1 deletion gcc/rust/typecheck/rust-unify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ UnifyRules::emit_type_mismatch () const
rich_location r (line_table, locus);
r.add_range (lhs.get_locus ());
r.add_range (rhs.get_locus ());
rust_error_at (r, "expected %<%s%> got %<%s%>",
rust_error_at (r, ErrorCode::E0308,
"mismatched types, expected %qs but got %qs",
expected->get_name ().c_str (), expr->get_name ().c_str ());
}

Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/arrays1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main() {
let xs: [i32; 5] = [1, 2, 3, 4, 5];
let a: bool = xs[0]; // { dg-error "expected .bool. got .i32." }
let a: bool = xs[0]; // { dg-error "mismatched types, expected .bool. but got .i32." }
}
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/bad_type1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
let logical: bool = 123; // { dg-error "expected .bool. got .<integer>." }
let logical: bool = 123; // { dg-error "mismatched types, expected .bool. but got .<integer>." }
}
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/bad_type2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {

let mut x;
x = 1;
x = true; // { dg-error "expected .<integer>. got .bool." }
x = true; // { dg-error "mismatched types, expected .<integer>. but got .bool." }

let call_test = test(1);
}
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/const_generics_6.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
struct Foo<const N: usize>;
struct Bar<const N: usize = { 15i32 }>; // { dg-error "expected .usize. got .i32." }
struct Bar<const N: usize = { 15i32 }>; // { dg-error "mismatched types, expected .usize. but got .i32." }
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/deadcode_err1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fn foo() -> i32 {

let mut a = 1; // { dg-warning "unreachable statement" }
a = 1.1; // { dg-warning "unreachable statement" }
// { dg-error "expected .<integer>. got .<float>." "" { target *-*-* } .-1 }
// { dg-error "mismatched types, expected .<integer>. but got .<float>." "" { target *-*-* } .-1 }
}

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions gcc/testsuite/rust/compile/deadcode_err2.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
fn foo() -> i32 {
return 1;
return 1.5; // { dg-error "expected .i32. got .<float>." }
return 1.5; // { dg-error "mismatched types, expected .i32. but got .<float>." }
// { dg-warning "unreachable statement" "" { target *-*-* } .-1 }
}

fn bar() -> i32 {
return 1.5; // { dg-error "expected .i32. got .<float>." }
return 1.5; // { dg-error "mismatched types, expected .i32. but got .<float>." }
return 1;
// { dg-warning "unreachable statement" "" { target *-*-* } .-1 }
}
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/func1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn test(x: i32) -> bool {
return x + 1; // { dg-error "expected .bool. got .i32." }
return x + 1; // { dg-error "mismatched types, expected .bool. but got .i32." }
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/func3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ fn test(a: i32, b: i32) -> i32 {

fn main() {
let a = test(1, true);
// { dg-error "expected .i32. got .bool." "" { target *-*-* } .-1 }
// { dg-error "mismatched types, expected .i32. but got .bool." "" { target *-*-* } .-1 }
}
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/func4.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn func() -> i32 { // { dg-error "expected .i32. got ...." }
fn func() -> i32 { // { dg-error "mismatched types, expected .i32. but got ...." }
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/func5.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn func() -> i32 {
return; // { dg-error "expected .i32. got ...." }
return; // { dg-error "mismatched types, expected .i32. but got ...." }
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/generics1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// { dg-error "expected .i32. got .i8." "" { target *-*-* } 0 }
// { dg-error "mismatched types, expected .i32. but got .i8." "" { target *-*-* } 0 }

#[lang = "sized"]
pub trait Sized {}
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/generics2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// { dg-error "expected .i32. got .i8." "" { target *-*-* } 0 }
// { dg-error "mismatched types, expected .i32. but got .i8." "" { target *-*-* } 0 }

#[lang = "sized"]
pub trait Sized {}
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/generics3.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// { dg-error "expected .i32. got .i8." "" { target *-*-* } 0 }
// { dg-error "mismatched types, expected .i32. but got .i8." "" { target *-*-* } 0 }
#[lang = "sized"]
pub trait Sized {}

Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/implicit_returns_err1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn test(x: i32) -> i32 {
if x > 1 { // { dg-error "expected .... got .<integer>." }
if x > 1 { // { dg-error "mismatched types, expected .... but got .<integer>." }
1
} else {
2
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/implicit_returns_err2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn test(x: i32) -> i32 {
// { dg-error "expected .i32. got .bool." "" { target *-*-* } .-1 }
// { dg-error "mismatched types, expected .i32. but got .bool." "" { target *-*-* } .-1 }
return 1;
// { dg-warning "unreachable expression" "" { target *-*-* } .+1 }
true
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/implicit_returns_err3.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn test(x: i32) -> i32 { // { dg-error "expected .i32. got ...." }
fn test(x: i32) -> i32 { // { dg-error "mismatched types, expected .i32. but got ...." }
if x > 1 {
1
}
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/implicit_returns_err4.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn test(x: bool) -> bool {
// { dg-error "expected .bool. got ...." "" { target *-*-*} .-1 }
// { dg-error "mismatched types, expected .bool. but got ...." "" { target *-*-*} .-1 }
return x;
// { dg-warning "unreachable expression" "" { target *-*-* } .+1 }
()
Expand Down
4 changes: 2 additions & 2 deletions gcc/testsuite/rust/compile/issue-1152.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn test() {
let f = [0; -4_isize];
// { dg-error "expected .usize. got .isize." "" { target *-*-* } .-1 }
// { dg-error "mismatched types, expected .usize. but got .isize." "" { target *-*-* } .-1 }
let f = [0_usize; -1_isize];
// { dg-error "expected .usize. got .isize." "" { target *-*-* } .-1 }
// { dg-error "mismatched types, expected .usize. but got .isize." "" { target *-*-* } .-1 }
}
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/issue-2477.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const FOO: u32 = return 0;
// { dg-error "return statement outside of function body" "" { target *-*-* } .-1 }
// { dg-error "expected .u32. got" "" { target *-*-* } .-2 }
// { dg-error "mismatched types, expected .u32. but got" "" { target *-*-* } .-2 }
9 changes: 9 additions & 0 deletions gcc/testsuite/rust/compile/mismatched-types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// ErrorCode::E0308
#![allow(unused)]
fn main() {
fn plus_one(x: i32) -> i32 {
x + 1
}
plus_one("Not a number"); // { dg-error "mismatched types, expected .i32. but got .& str." }
let x: f32 = "Not a float"; // { dg-error "mismatched types, expected .f32. but got .& str." }
}
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/reference1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ fn main() {
let a = &123;
let b: &mut i32 = a;
// { dg-error "mismatched mutability" "" { target *-*-* } .-1 }
// { dg-error "expected .&mut i32. got .& i32." "" { target *-*-* } .-2 }
// { dg-error "mismatched types, expected .&mut i32. but got .& i32." "" { target *-*-* } .-2 }
}
4 changes: 2 additions & 2 deletions gcc/testsuite/rust/compile/stmt_with_block_err1.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
fn test(x: i32) -> i32 {
if x > 1 { // { dg-error "expected .... got .<integer>." }
if x > 1 { // { dg-error "mismatched types, expected .... but got .<integer>." }
1
} else {
2
}

{ // { dg-error "expected .... got .<integer>." }
{ // { dg-error "mismatched types, expected .... but got .<integer>." }
3
}

Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/traits1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub trait Sized {}

trait Foo {
fn Bar() -> i32 {}
// { dg-error "expected .i32. got .()." "" { target *-*-* } .-1 }
// { dg-error "mismatched types, expected .i32. but got .()." "" { target *-*-* } .-1 }
}

struct Baz;
Expand Down
4 changes: 2 additions & 2 deletions gcc/testsuite/rust/compile/traits2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ pub trait Sized {}

trait Foo {
fn Bar() -> i32 {}
// { dg-error "expected .i32. got .()." "" { target *-*-* } .-1 }
// { dg-error "mismatched types, expected .i32. but got .()." "" { target *-*-* } .-1 }
}

struct Baz;

impl Foo for Baz {
fn Bar() {}
// { dg-error "expected" "" { target *-*-* } .-1 }
// { dg-error "mismatched types, expected" "" { target *-*-* } .-1 }
// { dg-error "method .Bar. has an incompatible type for trait .Foo." "" { target *-*-* } .-2 }
}

Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/tuple_mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {

// The lhs and rhs sizes don't match, but we still resolve 'a' to be bool, we don't
// error out immediately once we notice the size mismatch.
fn foo() -> i32 { // { dg-error "expected .i32. got .bool." }
fn foo() -> i32 { // { dg-error "mismatched types, expected .i32. but got .bool." }
let (a, _) = (true, 2, 3); // { dg-error "expected a tuple with 3 elements, found one with 2 elements" }
a
}
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/tuple_struct3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ struct Foo(i32, i32, bool);

fn main() {
let c = Foo(1, 2f32, true);
// { dg-error "expected .i32. got .f32." "" { target *-*-* } .-1 }
// { dg-error "mismatched types, expected .i32. but got .f32." "" { target *-*-* } .-1 }
}
Loading