aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-01-25 17:00:21 +0000
committerGitHub <noreply@github.com>2022-01-25 17:00:21 +0000
commit1fc2b540800d25af1c70e90439e8a9077c7d07f8 (patch)
tree88328f8b601a74c4b87fa6409a8284365f3d0071 /gcc
parent5f2973fe0e322380bd5f3f4ea35b657efbf86efa (diff)
parent234816ac9d919505f2ddf2cdf9e83a10de7e3ced (diff)
downloadgcc-1fc2b540800d25af1c70e90439e8a9077c7d07f8.zip
gcc-1fc2b540800d25af1c70e90439e8a9077c7d07f8.tar.gz
gcc-1fc2b540800d25af1c70e90439e8a9077c7d07f8.tar.bz2
Merge #892
892: Remove bad assertion when resolving segments r=philberty a=philberty When resolving segments in a path generics ones can match types in othe impl blocks which will not be compiled yet so this assertion is bad. Fixes #862 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-hir-path-probe.h4
-rw-r--r--gcc/testsuite/rust/compile/torture/issue-862.rs74
2 files changed, 76 insertions, 2 deletions
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h b/gcc/rust/typecheck/rust-hir-path-probe.h
index caacc2a..50d660c 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.h
+++ b/gcc/rust/typecheck/rust-hir-path-probe.h
@@ -280,8 +280,8 @@ protected:
current_impl = impl;
HirId impl_ty_id = impl->get_type ()->get_mappings ().get_hirid ();
TyTy::BaseType *impl_block_ty = nullptr;
- bool ok = context->lookup_type (impl_ty_id, &impl_block_ty);
- rust_assert (ok);
+ if (!context->lookup_type (impl_ty_id, &impl_block_ty))
+ return;
if (!receiver->can_eq (impl_block_ty, false))
return;
diff --git a/gcc/testsuite/rust/compile/torture/issue-862.rs b/gcc/testsuite/rust/compile/torture/issue-862.rs
new file mode 100644
index 0000000..c1a4609
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/issue-862.rs
@@ -0,0 +1,74 @@
+// { dg-additional-options "-w" }
+extern "C" {
+ fn printf(s: *const i8, ...);
+}
+
+#[lang = "deref"]
+pub trait Deref {
+ type Target;
+
+ fn deref(&self) -> &Self::Target;
+}
+
+impl<T> Deref for &T {
+ type Target = T;
+
+ fn deref(&self) -> &T {
+ unsafe {
+ let a = "imm_deref\n\0";
+ let b = a as *const str;
+ let c = b as *const i8;
+
+ printf(c);
+ }
+
+ *self
+ }
+}
+
+impl<T> Deref for &mut T {
+ type Target = T;
+
+ fn deref(&self) -> &T {
+ unsafe {
+ let a = "mut_deref\n\0";
+ let b = a as *const str;
+ let c = b as *const i8;
+
+ printf(c);
+ }
+
+ *self
+ }
+}
+
+struct Foo<T>(T);
+impl<T> Deref for Foo<T> {
+ type Target = T;
+
+ fn deref(&self) -> &Self::Target {
+ unsafe {
+ let a = "foo_deref\n\0";
+ let b = a as *const str;
+ let c = b as *const i8;
+
+ printf(c);
+ }
+
+ &self.0
+ }
+}
+
+struct Bar(i32);
+impl Bar {
+ fn cake(self) -> i32 {
+ self.0 + 1
+ }
+}
+
+pub fn main() {
+ let foo: Foo<Bar> = Foo(Bar(123));
+ let bar: Bar = *foo;
+
+ let cake_result: i32 = foo.cake();
+}