aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-context.h4
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.h2
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-stmt.h2
-rw-r--r--gcc/rust/typecheck/rust-tyty-coercion.h38
-rw-r--r--gcc/testsuite/rust/compile/reference1.rs5
-rw-r--r--gcc/testsuite/rust/compile/torture/coercion1.rs11
6 files changed, 41 insertions, 21 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index d822937..efca267 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -537,6 +537,10 @@ public:
Btype *base_compiled_type
= TyTyResolveCompile::compile (ctx, type.get_base ());
translated = ctx->get_backend ()->reference_type (base_compiled_type);
+ if (!type.is_mutable ())
+ {
+ translated = ctx->get_backend ()->immutable_type (translated);
+ }
}
void visit (TyTy::StrType &type) override
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index 0749839..b53cd46 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -348,7 +348,7 @@ public:
auto lhs = TypeCheckExpr::Resolve (expr.get_lhs (), false);
auto rhs = TypeCheckExpr::Resolve (expr.get_rhs (), false);
- auto result = lhs->unify (rhs);
+ auto result = lhs->coerce (rhs);
if (result->get_kind () == TyTy::TypeKind::ERROR)
return;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.h b/gcc/rust/typecheck/rust-hir-type-check-stmt.h
index ba821ca..1b6f47c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-stmt.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.h
@@ -80,7 +80,7 @@ public:
// let x:i32 = 123;
if (specified_ty != nullptr && init_expr_ty != nullptr)
{
- auto unified_ty = specified_ty->unify (init_expr_ty);
+ auto unified_ty = specified_ty->coerce (init_expr_ty);
if (unified_ty->get_kind () == TyTy::TypeKind::ERROR)
return;
diff --git a/gcc/rust/typecheck/rust-tyty-coercion.h b/gcc/rust/typecheck/rust-tyty-coercion.h
index 6695056..5c10b04 100644
--- a/gcc/rust/typecheck/rust-tyty-coercion.h
+++ b/gcc/rust/typecheck/rust-tyty-coercion.h
@@ -93,7 +93,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -104,7 +104,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -115,7 +115,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -126,7 +126,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -137,7 +137,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -148,7 +148,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -159,7 +159,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -170,7 +170,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -181,7 +181,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -192,7 +192,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -203,7 +203,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -214,7 +214,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -225,7 +225,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -236,7 +236,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -247,7 +247,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -258,7 +258,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -269,7 +269,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -280,7 +280,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
@@ -291,7 +291,7 @@ public:
Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
RichLocation r (ref_locus);
r.add_range (base_locus);
- rust_error_at (r, "cannot coerce [%s] with [%s]",
+ rust_error_at (r, "expected [%s] got [%s]",
get_base ()->as_string ().c_str (),
type.as_string ().c_str ());
}
diff --git a/gcc/testsuite/rust/compile/reference1.rs b/gcc/testsuite/rust/compile/reference1.rs
new file mode 100644
index 0000000..3d97926
--- /dev/null
+++ b/gcc/testsuite/rust/compile/reference1.rs
@@ -0,0 +1,5 @@
+fn main() {
+ let a = &123;
+ let b: &mut i32 = a;
+ // { dg-error "expected .&mut i32. got .& i32." "" { target *-*-* } .-1 }
+}
diff --git a/gcc/testsuite/rust/compile/torture/coercion1.rs b/gcc/testsuite/rust/compile/torture/coercion1.rs
new file mode 100644
index 0000000..3bfa938
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/coercion1.rs
@@ -0,0 +1,11 @@
+pub fn main() {
+ let a: &i32 = &123;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ let b: &mut i32 = &mut 123;
+
+ let c: &i32 = &mut 123;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let d: &i32 = b;
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}