Skip to content

Commit fa93e28

Browse files
committed
gccrs: Remove bad assertion in name resolution
This was a handy debug assertion but only works for valid rust code. This needs to handle the case where the type is not resolved which is a valid case. Fixes #2423 gcc/rust/ChangeLog: * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): remove assertions gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 can't handle this * rust/compile/issue-2423.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
1 parent 5434de6 commit fa93e28

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

gcc/rust/resolve/rust-ast-resolve-item.cc

+24-6
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,14 @@ ResolveItem::visit (AST::InherentImpl &impl_block)
582582
// Setup paths
583583
CanonicalPath self_cpath = CanonicalPath::create_empty ();
584584
bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_type (), self_cpath);
585-
rust_assert (ok);
585+
if (!ok)
586+
{
587+
resolver->get_name_scope ().pop ();
588+
resolver->get_type_scope ().pop ();
589+
resolver->get_label_scope ().pop ();
590+
return;
591+
}
592+
586593
rust_debug ("AST::InherentImpl resolve Self: {%s}",
587594
self_cpath.get ().c_str ());
588595

@@ -671,20 +678,31 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
671678
return;
672679
}
673680

674-
bool ok;
675681
// setup paths
676682
CanonicalPath canonical_trait_type = CanonicalPath::create_empty ();
677-
ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (),
678-
canonical_trait_type);
679-
rust_assert (ok);
683+
bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (),
684+
canonical_trait_type);
685+
if (!ok)
686+
{
687+
resolver->get_name_scope ().pop ();
688+
resolver->get_type_scope ().pop ();
689+
resolver->get_label_scope ().pop ();
690+
return;
691+
}
680692

681693
rust_debug ("AST::TraitImpl resolve trait type: {%s}",
682694
canonical_trait_type.get ().c_str ());
683695

684696
CanonicalPath canonical_impl_type = CanonicalPath::create_empty ();
685697
ok = ResolveTypeToCanonicalPath::go (impl_block.get_type (),
686698
canonical_impl_type);
687-
rust_assert (ok);
699+
if (!ok)
700+
{
701+
resolver->get_name_scope ().pop ();
702+
resolver->get_type_scope ().pop ();
703+
resolver->get_label_scope ().pop ();
704+
return;
705+
}
688706

689707
rust_debug ("AST::TraitImpl resolve self: {%s}",
690708
canonical_impl_type.get ().c_str ());
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
impl NonExistant {
2+
// { dg-error "failed to resolve" "" { target *-*-* } .-1 }
3+
fn test() {}
4+
}
5+
6+
impl NotFound for NonExistant {
7+
// { dg-error "failed to resolve" "" { target *-*-* } .-1 }
8+
fn test() {}
9+
}
10+
11+
trait A {}
12+
13+
impl A for NotFound {}
14+
// { dg-error "failed to resolve" "" { target *-*-* } .-1 }

gcc/testsuite/rust/compile/nr2/exclude

+1
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,5 @@ issue-1773.rs
206206
issue-2905-1.rs
207207
issue-2905-2.rs
208208
issue-2907.rs
209+
issue-2423.rs
209210
# please don't delete the trailing newline

0 commit comments

Comments
 (0)