From: Philip Herron <[email protected]>
Fixes Rust-GCC#4486
gcc/rust/ChangeLog:
* backend/rust-compile-item.cc (CompileItem::visit): check instead of
assert
gcc/testsuite/ChangeLog:
* rust/compile/issue-4486-1.rs: New test.
* rust/compile/issue-4486-2.rs: New test.
Signed-off-by: Philip Herron <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/00f321321159557c5c75317af58d0f0fbeb6a735
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4604
gcc/rust/backend/rust-compile-item.cc | 4 ++-
gcc/testsuite/rust/compile/issue-4486-1.rs | 15 ++++++++
gcc/testsuite/rust/compile/issue-4486-2.rs | 41 ++++++++++++++++++++++
3 files changed, 59 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/rust/compile/issue-4486-1.rs
create mode 100644 gcc/testsuite/rust/compile/issue-4486-2.rs
diff --git a/gcc/rust/backend/rust-compile-item.cc
b/gcc/rust/backend/rust-compile-item.cc
index 4c627ac90..423df15c2 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -180,7 +180,9 @@ CompileItem::visit (HIR::Function &function)
TyTy::TyWithLocation (concrete),
function.get_locus ());
- rust_assert (resolved->is<TyTy::FnType> ());
+ if (!resolved->is<TyTy::FnType> ())
+ return;
+
fntype = resolved->as<TyTy::FnType> ();
}
diff --git a/gcc/testsuite/rust/compile/issue-4486-1.rs
b/gcc/testsuite/rust/compile/issue-4486-1.rs
new file mode 100644
index 000000000..29e30757f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4486-1.rs
@@ -0,0 +1,15 @@
+#![feature(no_core, intrinsics, staged_api, lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+trait Number {
+ fn from<T>(n: T) -> Self;
+}
+
+trait NumConv {}
+
+fn main() {
+ let _: f64 = Number::from(0.0f64); // { dg-error {bounds not satisfied for
f64 .Number. is not satisfied \[E0277\]} }
+}
diff --git a/gcc/testsuite/rust/compile/issue-4486-2.rs
b/gcc/testsuite/rust/compile/issue-4486-2.rs
new file mode 100644
index 000000000..d3232422e
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4486-2.rs
@@ -0,0 +1,41 @@
+#![feature(no_core, intrinsics, staged_api, lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+pub trait Number: NumConv {
+ fn from<T: Number>(n: T) -> Self;
+}
+
+trait NumberExt: Number {
+ fn to_double(&self) -> f64 {
+ self.to_float() * 2.0
+ }
+}
+
+impl<T: Number> NumberExt for T {}
+
+impl Number for f64 {
+ fn from<T: Number + NewTrait>(n: T) -> f64 { // { dg-error {bounds not
satisfied for f64 .NewTrait. is not satisfied \[E0277\]} }
+ n.to_float()
+ }
+}
+
+pub trait NumConv {
+ fn to_float(&self) -> f64;
+}
+
+impl NumConv for f64 {
+ fn to_float(&self) -> f64 {
+ *self
+ }
+}
+
+pub fn main() {
+ let _: f64 = Number::from(0.0f64);
+}
+
+trait NewTrait {
+ type Assoc;
+}
base-commit: 74c259427e971b8f18492974900d1c57cdc99ad5
--
2.54.0