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

Unknown reference for resolved name Self in impl of Clone for ! #3035

Open
CohenArthur opened this issue May 23, 2024 · 1 comment · May be fixed by #3179
Open

Unknown reference for resolved name Self in impl of Clone for ! #3035

CohenArthur opened this issue May 23, 2024 · 1 comment · May be fixed by #3179

Comments

@CohenArthur
Copy link
Member

I tried this code:

// ---- gccrs additions

#[lang = "sized"]
trait Sized {}

// ---- gccrs additions

#[lang = "clone"]
pub trait Clone: Sized {
    #[stable(feature = "rust1", since = "1.0.0")]
    #[must_use = "cloning is often expensive and is not expected to have side effects"]
    fn clone(&self) -> Self;

    #[inline]
    #[stable(feature = "rust1", since = "1.0.0")]
    fn clone_from(&mut self, source: &Self) {
        *self = source.clone()
    }
}

#[unstable(feature = "never_type", issue = "35121")]
impl Clone for ! {
    #[inline]
    fn clone(&self) -> Self {
        *self
    }
}

I expected to see this happen: no errors

Instead, this happened:

test.rs:24:24: error: unknown reference for resolved name:Self24 |     fn clone(&self) -> Self {
      |                        ^~~~
crab1: internal compiler error: Segmentation fault
0x490e16c crash_signal(int)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/toplev.cc:319
0x23c1eec std::vector<std::pair<unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::size() const
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/stl_vector.h:990
0x23c1df0 std::vector<std::pair<unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::vector(std::vector<std::pair<unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&)
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/stl_vector.h:599
0x23c1dac Rust::Resolver::CanonicalPath::CanonicalPath(Rust::Resolver::CanonicalPath const&)
	../../gcc/rust/util/rust-canonical-path.h:49
0x25f73f3 Rust::RustIdent::RustIdent(Rust::Resolver::CanonicalPath const&, unsigned int)
	../../gcc/rust/util/rust-identifier.h:33
0x26a302e Rust::Resolver::TypeCheckImplItem::visit(Rust::HIR::Function&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/typecheck/rust-hir-type-check-implitem.cc:467
0x24d953c Rust::HIR::Function::accept_vis(Rust::HIR::HIRImplVisitor&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/tree/rust-hir.cc:5011
0x26a25d8 Rust::Resolver::TypeCheckImplItem::Resolve(Rust::HIR::ImplBlock*, Rust::HIR::ImplItem*, Rust::TyTy::BaseType*, std::vector<Rust::TyTy::SubstitutionParamMapping, std::allocator<Rust::TyTy::SubstitutionParamMapping> >)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/typecheck/rust-hir-type-check-implitem.cc:337
0x2674394 Rust::Resolver::TypeCheckItem::resolve_impl_item(Rust::HIR::ImplBlock&, Rust::HIR::ImplItem&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/typecheck/rust-hir-type-check-item.cc:497
0x26741da Rust::Resolver::TypeCheckItem::ResolveImplItem(Rust::HIR::ImplBlock&, Rust::HIR::ImplItem&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/typecheck/rust-hir-type-check-item.cc:63
0x26de8c9 Rust::Resolver::query_type(unsigned int, Rust::TyTy::BaseType**)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/typecheck/rust-type-util.cc:82
0x26d613d Rust::Resolver::MethodResolver::select(Rust::TyTy::BaseType&)::$_1::operator()(unsigned int, Rust::HIR::ImplBlock*)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/typecheck/rust-hir-dot-operator.cc:228
0x26d5f09 bool std::__invoke_impl<bool, Rust::Resolver::MethodResolver::select(Rust::TyTy::BaseType&)::$_1&, unsigned int, Rust::HIR::ImplBlock*>(std::__invoke_other, Rust::Resolver::MethodResolver::select(Rust::TyTy::BaseType&)::$_1&, unsigned int&&, Rust::HIR::ImplBlock*&&)
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/invoke.h:61
0x26d5eb4 std::enable_if<is_invocable_r_v<bool, Rust::Resolver::MethodResolver::select(Rust::TyTy::BaseType&)::$_1&, unsigned int, Rust::HIR::ImplBlock*>, bool>::type std::__invoke_r<bool, Rust::Resolver::MethodResolver::select(Rust::TyTy::BaseType&)::$_1&, unsigned int, Rust::HIR::ImplBlock*>(Rust::Resolver::MethodResolver::select(Rust::TyTy::BaseType&)::$_1&, unsigned int&&, Rust::HIR::ImplBlock*&&)
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/invoke.h:114
0x26d5d9c std::_Function_handler<bool (unsigned int, Rust::HIR::ImplBlock*), Rust::Resolver::MethodResolver::select(Rust::TyTy::BaseType&)::$_1>::_M_invoke(std::_Any_data const&, unsigned int&&, Rust::HIR::ImplBlock*&&)
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/std_function.h:290
0x2516576 std::function<bool (unsigned int, Rust::HIR::ImplBlock*)>::operator()(unsigned int, Rust::HIR::ImplBlock*) const
	/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/std_function.h:591
0x250edf1 Rust::Analysis::Mappings::iterate_impl_blocks(std::function<bool (unsigned int, Rust::HIR::ImplBlock*)>)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/util/rust-hir-map.cc:826
0x26d3449 Rust::Resolver::MethodResolver::select(Rust::TyTy::BaseType&)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/typecheck/rust-hir-dot-operator.cc:203
0x26f1844 Rust::Resolver::AutoderefCycle::try_autoderefed(Rust::TyTy::BaseType*)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/typecheck/rust-autoderef.cc:423
0x26f137c Rust::Resolver::AutoderefCycle::cycle(Rust::TyTy::BaseType*)
	/home/arthur/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/typecheck/rust-autoderef.cc:329
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
@philberty
Copy link
Member

I think this is because of the never type

philberty added a commit that referenced this issue Sep 20, 2024
We need to resolve the never type which is its own special AST node so it
doesnt magically get handled like the regular builtin type paths such as
i32.

Fixes #3035

gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-type.cc (ResolveType::visit):
	handle never type
	(ResolveTypeToCanonicalPath::visit): likewise
	* resolve/rust-ast-resolve-type.h: missing never type
	* resolve/rust-name-resolver.cc (Resolver::generate_builtins):
	track never type node_id
	(Resolver::setup_builtin): likewise
	* resolve/rust-name-resolver.h: new never type getter

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: nr2 cant handle this
	* rust/compile/issue-3035.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
@philberty philberty linked a pull request Sep 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants