diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-02-07 12:51:28 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-08-01 16:52:27 +0200 |
commit | 5540afbd0136a6e78710445a89eb4af44fd14292 (patch) | |
tree | 585b6cfc8ed96b1930cc561f6d9380c93695d82c /gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | |
parent | f1b91d0a2bcb74adf7c752592f95f0552afcad77 (diff) | |
download | gcc-5540afbd0136a6e78710445a89eb4af44fd14292.zip gcc-5540afbd0136a6e78710445a89eb4af44fd14292.tar.gz gcc-5540afbd0136a6e78710445a89eb4af44fd14292.tar.bz2 |
gccrs: Reinject Self parameter in new resolver
The old resolver injected a Self generic parameter in order to help the
trait solver. This is clearly sketchy at best and should be fixed in
the future.
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add
Self generic parameter injection and a warning.
* resolve/rust-toplevel-name-resolver-2.0.h: Add function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc')
-rw-r--r-- | gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index f65ec77..80b1426 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -186,6 +186,29 @@ TopLevel::visit (AST::Module &module) Analysis::Mappings::get ()->insert_ast_module (&module); } +void +TopLevel::visit (AST::Trait &trait) +{ + // FIXME: This Self injection is dodgy. It even lead to issues with metadata + // export in the past (#2349). We cannot tell appart injected parameters from + // regular ones. Dumping generic parameters highlights this Self in metadata, + // during debug or proc macro collection. This is clearly a hack. + // + // For now I'll keep it here in the new name resolver even if it should + // probably not be there. We need to find another way to solve this. + // Maybe an additional attribute to Trait ? + // + // From old resolver: + //// we need to inject an implicit self TypeParam here + //// FIXME: which location should be used for Rust::Identifier `Self`? + AST::TypeParam *implicit_self + = new AST::TypeParam ({"Self"}, trait.get_locus ()); + trait.insert_implict_self ( + std::unique_ptr<AST::GenericParam> (implicit_self)); + + DefaultResolver::visit (trait); +} + template <typename PROC_MACRO> static void insert_macros (std::vector<PROC_MACRO> ¯os, NameResolutionContext &ctx) |