[COMMITTED 085/146] gccrs: lang-item: Add Sync trait

2025-03-22 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Add Sync marker trait.
* util/rust-lang-item.cc: Likewise.
---
 gcc/rust/util/rust-lang-item.cc | 1 +
 gcc/rust/util/rust-lang-item.h  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc
index 5ddffaa59d4..216202af926 100644
--- a/gcc/rust/util/rust-lang-item.cc
+++ b/gcc/rust/util/rust-lang-item.cc
@@ -62,6 +62,7 @@ const BiMap 
Rust::LangItem::lang_items = {{
   {"copy", Kind::COPY},
   {"clone", Kind::CLONE},
   {"sized", Kind::SIZED},
+  {"sync", Kind::SYNC},
   {"slice_alloc", Kind::SLICE_ALLOC},
   {"slice_u8_alloc", Kind::SLICE_U8_ALLOC},
   {"str_alloc", Kind::STR_ALLOC},
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 92c70bbddf4..66d26d03907 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -82,6 +82,7 @@ public:
 COPY,
 CLONE,
 SIZED,
+SYNC,
 
 // https://github.com/Rust-GCC/gccrs/issues/1896
 // 
https://github.com/rust-lang/rust/commit/afbecc0f68c4dcfc4878ba5bcb1ac942544a1bdc
-- 
2.45.2



[COMMITTED 044/146] gccrs: Handle type path segments during late resolution 2.0

2025-03-22 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Call DefaultResolver::visit when visiting
TypePath.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery 
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 2 ++
 gcc/testsuite/rust/compile/nr2/exclude  | 2 --
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index 850f96aef89..3af8496288d 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -263,6 +263,8 @@ Late::visit (AST::TypePath &type)
   Definition (resolved->get_node_id ()));
   else
 rust_unreachable ();
+
+  DefaultResolver::visit (type);
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 2e956960dad..3dbebc703c4 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -42,7 +42,6 @@ generics3.rs
 generics4.rs
 generics5.rs
 generics6.rs
-generics7.rs
 generics8.rs
 generics9.rs
 if_let_expr.rs
@@ -83,7 +82,6 @@ issue-2165.rs
 issue-2166.rs
 issue-2190-1.rs
 issue-2190-2.rs
-issue-2195.rs
 issue-2238.rs
 issue-2304.rs
 issue-2330.rs
-- 
2.45.2



[COMMITTED 104/146] gccrs: nr2.0: Resolve Self inside impl blocks

2025-03-22 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert a definition for Self when visiting
InherentImpl and TraitImpl instances.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Add visitors for InherentImpl and TraitImpl.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery 
---
 .../rust-toplevel-name-resolver-2.0.cc| 26 +++
 .../resolve/rust-toplevel-name-resolver-2.0.h |  2 ++
 gcc/testsuite/rust/compile/nr2/exclude|  3 ---
 3 files changed, 28 insertions(+), 3 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 4aca709263c..4c6664f104b 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -103,6 +103,32 @@ TopLevel::visit (AST::Trait &trait)
   DefaultResolver::visit (trait);
 }
 
+void
+TopLevel::visit (AST::InherentImpl &impl)
+{
+  auto inner_fn = [this, &impl] () {
+insert_or_error_out (Identifier ("Self", impl.get_type ().get_locus ()),
+impl.get_type (), Namespace::Types);
+
+AST::DefaultASTVisitor::visit (impl);
+  };
+
+  ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn);
+}
+
+void
+TopLevel::visit (AST::TraitImpl &impl)
+{
+  auto inner_fn = [this, &impl] () {
+insert_or_error_out (Identifier ("Self", impl.get_type ().get_locus ()),
+impl.get_type (), Namespace::Types);
+
+AST::DefaultASTVisitor::visit (impl);
+  };
+
+  ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn);
+}
+
 void
 TopLevel::visit (AST::TraitItemType &trait_item)
 {
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
index 64d2174a7be..fabcb5bf707 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -148,6 +148,8 @@ private:
 
   void visit (AST::Module &module) override;
   void visit (AST::Trait &trait) override;
+  void visit (AST::InherentImpl &impl) override;
+  void visit (AST::TraitImpl &impl) override;
   void visit (AST::TraitItemType &trait_item) override;
   void visit (AST::MacroRulesDefinition ¯o) override;
   void visit (AST::Function &function) override;
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index af7d105debc..9b1ee7ceaf9 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -39,13 +39,11 @@ generics6.rs
 generics9.rs
 if_let_expr.rs
 issue-1019.rs
-issue-1031.rs
 issue-1034.rs
 issue-1129-2.rs
 issue-1130.rs
 issue-1173.rs
 issue-1272.rs
-issue-1289.rs
 issue-1447.rs
 issue-1483.rs
 issue-1725-1.rs
@@ -85,7 +83,6 @@ issue-855.rs
 issue-925.rs
 iterators1.rs
 lookup_err1.rs
-macros/mbe/macro-issue1233.rs
 macros/mbe/macro-issue1400.rs
 macros/mbe/macro13.rs
 macros/mbe/macro15.rs
-- 
2.45.2



Re: [COMMITTED 136/145] gccrs: Fix nightly rustc warnings

2025-03-22 Thread Arthur Cohen
Hi Thomas!

Thanks for testing that commit. I think a partial revert is not
necessary, as I'm currently
working on our milestone to make all Rust code compile with a Rust
1.49 toolchain.

I think pushing a partial revert upstream would just create some
confusion when the
correct version of the code which will fully compile with Rust 1.49
will be on our dev repo
in a few days or weeks. I'm hoping to upstream it on Monday or next
Monday if I cannot
finish it in time.

I feel like holding on on this for a few days would make the process
easier? What do you
think?

Best,

Arthur


On Sat, 22 Mar 2025 at 15:43, Thomas Schwinge  wrote:
>
> Hi!
>
> On 2025-03-17T16:33:34+0100, arthur.co...@embecosm.com wrote:
> > From: Kushal Pal 
> >
> > libgrust/ChangeLog:
> >
> >   * libformat_parser/Cargo.toml:
> >   Used crate-type instead of depricated crate_type.
> >   * libformat_parser/generic_format_parser/src/lib.rs:
> >   Remove dead code.
> >   * libformat_parser/src/lib.rs: Likewise.
> >
> > Signed-off-by: Kushal Pal 
>
> This isn't "dead code" on a Debian "bookworm" system where I'm testing
> with:
>
> $ rustc --version
> rustc 1.63.0
>
> With this commit in place, I get:
>
> [...]
> Making all in libformat_parser
> make[3]: Entering directory '[...]/build-gcc/libgrust/libformat_parser'
> cargo \
>   --config [...]/source-gcc/libgrust/libformat_parser/.cargo/config \
>   build \
> --offline \
> --target-dir . \
> --manifest-path [...]/source-gcc/libgrust/libformat_parser/Cargo.toml 
> \
> # FIXME: Not always '--release', right?
>Compiling generic_format_parser v0.1.0 
> ([...]/source-gcc/libgrust/libformat_parser/generic_format_parser)
> error[E0658]: use of unstable library feature 'is_some_with'
>--> generic_format_parser/src/lib.rs:615:34
> |
> 615 | ...   .is_some_and(is_id_start)
> |^^^
> |
> = note: see issue #93050 
>  for more information
>
> error[E0631]: type mismatch in function arguments
>--> generic_format_parser/src/lib.rs:615:46
> |
> 17  | fn is_id_start(c: char) -> bool {
> | --- found signature of `fn(char) -> _`
> ...
> 615 | .is_some_and(is_id_start)
> |  --- ^^^ expected 
> signature of `for<'r> fn(&'r char) -> _`
> |  |
> |  required by a bound introduced by 
> this call
> |
> note: required by a bound in `Optionis_some_and`
>
> Some errors have detailed explanations: E0631, E0658.
> For more information about an error, try `rustc --explain E0631`.
> error: could not compile `generic_format_parser` due to 2 previous errors
> make[3]: *** [Makefile:431: debug/liblibformat_parser.a] Error 101
> make[3]: Target 'all' not remade because of errors.
> make[3]: Leaving directory '[...]/build-gcc/libgrust/libformat_parser'
> [...]
>
> With this commit reverted, the build again succeeds, with good test
> results.  May I, therefore, push a (partial, I suppose?) 'git revert' of
> this commit?
>
>
> Grüße
>  Thomas
>
>
> > ---
> >  libgrust/libformat_parser/Cargo.toml |  2 +-
> >  .../generic_format_parser/src/lib.rs | 16 
> >  libgrust/libformat_parser/src/lib.rs | 14 --
> >  3 files changed, 1 insertion(+), 31 deletions(-)
> >
> > diff --git a/libgrust/libformat_parser/Cargo.toml 
> > b/libgrust/libformat_parser/Cargo.toml
> > index 3c214915d31..39c017d249b 100644
> > --- a/libgrust/libformat_parser/Cargo.toml
> > +++ b/libgrust/libformat_parser/Cargo.toml
> > @@ -14,7 +14,7 @@ libc = "0.2"
> >  generic_format_parser = { path = "generic_format_parser" }
> >
> >  [lib]
> > -crate_type = ["staticlib", "rlib"]
> > +crate-type = ["staticlib", "rlib"]
> >
> >  [[bin]]
> >  name = "format_parser_test"
> > diff --git a/libgrust/libformat_parser/generic_format_parser/src/lib.rs 
> > b/libgrust/libformat_parser/generic_format_parser/src/lib.rs
> > index e255bf16908..25f6b0ead17 100644
> > --- a/libgrust/libformat_parser/generic_format_parser/src/lib.rs
> > +++ b/libgrust/libformat_parser/generic_format_parser/src/lib.rs
> > @@ -22,22 +22,6 @@ fn is_id_continue(c: char) -> bool {
> >  unicode_xid::UnicodeXID::is_xid_continue(c)
> >  }
> >
> > -// Workaround for Ubuntu 18.04. The default Rust package is 1.65 (and 
> > unlikely to change I assume?), but the
> > -// generic format parser library uses `is_some_and` which was introduced 
> > in 1.70. So this is a reimplementation,
> > -// directly taken from the standard library sources
> > -trait IsSomeAnd {
> > -fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool;
> > -}
> > -
> > -imp

Re: [COMMITTED 136/145] gccrs: Fix nightly rustc warnings

2025-03-22 Thread Thomas Schwinge
Hi!

On 2025-03-17T16:33:34+0100, arthur.co...@embecosm.com wrote:
> From: Kushal Pal 
>
> libgrust/ChangeLog:
>
>   * libformat_parser/Cargo.toml:
>   Used crate-type instead of depricated crate_type.
>   * libformat_parser/generic_format_parser/src/lib.rs:
>   Remove dead code.
>   * libformat_parser/src/lib.rs: Likewise.
>
> Signed-off-by: Kushal Pal 

This isn't "dead code" on a Debian "bookworm" system where I'm testing
with:

$ rustc --version
rustc 1.63.0

With this commit in place, I get:

[...]
Making all in libformat_parser
make[3]: Entering directory '[...]/build-gcc/libgrust/libformat_parser'
cargo \
  --config [...]/source-gcc/libgrust/libformat_parser/.cargo/config \
  build \
--offline \
--target-dir . \
--manifest-path [...]/source-gcc/libgrust/libformat_parser/Cargo.toml \
# FIXME: Not always '--release', right?
   Compiling generic_format_parser v0.1.0 
([...]/source-gcc/libgrust/libformat_parser/generic_format_parser)
error[E0658]: use of unstable library feature 'is_some_with'
   --> generic_format_parser/src/lib.rs:615:34
|
615 | ...   .is_some_and(is_id_start)
|^^^
|
= note: see issue #93050 
 for more information

error[E0631]: type mismatch in function arguments
   --> generic_format_parser/src/lib.rs:615:46
|
17  | fn is_id_start(c: char) -> bool {
| --- found signature of `fn(char) -> _`
...
615 | .is_some_and(is_id_start)
|  --- ^^^ expected 
signature of `for<'r> fn(&'r char) -> _`
|  |
|  required by a bound introduced by 
this call
|
note: required by a bound in `Optionis_some_and`

Some errors have detailed explanations: E0631, E0658.
For more information about an error, try `rustc --explain E0631`.
error: could not compile `generic_format_parser` due to 2 previous errors
make[3]: *** [Makefile:431: debug/liblibformat_parser.a] Error 101
make[3]: Target 'all' not remade because of errors.
make[3]: Leaving directory '[...]/build-gcc/libgrust/libformat_parser'
[...]

With this commit reverted, the build again succeeds, with good test
results.  May I, therefore, push a (partial, I suppose?) 'git revert' of
this commit?


Grüße
 Thomas


> ---
>  libgrust/libformat_parser/Cargo.toml |  2 +-
>  .../generic_format_parser/src/lib.rs | 16 
>  libgrust/libformat_parser/src/lib.rs | 14 --
>  3 files changed, 1 insertion(+), 31 deletions(-)
>
> diff --git a/libgrust/libformat_parser/Cargo.toml 
> b/libgrust/libformat_parser/Cargo.toml
> index 3c214915d31..39c017d249b 100644
> --- a/libgrust/libformat_parser/Cargo.toml
> +++ b/libgrust/libformat_parser/Cargo.toml
> @@ -14,7 +14,7 @@ libc = "0.2"
>  generic_format_parser = { path = "generic_format_parser" }
>  
>  [lib]
> -crate_type = ["staticlib", "rlib"]
> +crate-type = ["staticlib", "rlib"]
>  
>  [[bin]]
>  name = "format_parser_test"
> diff --git a/libgrust/libformat_parser/generic_format_parser/src/lib.rs 
> b/libgrust/libformat_parser/generic_format_parser/src/lib.rs
> index e255bf16908..25f6b0ead17 100644
> --- a/libgrust/libformat_parser/generic_format_parser/src/lib.rs
> +++ b/libgrust/libformat_parser/generic_format_parser/src/lib.rs
> @@ -22,22 +22,6 @@ fn is_id_continue(c: char) -> bool {
>  unicode_xid::UnicodeXID::is_xid_continue(c)
>  }
>  
> -// Workaround for Ubuntu 18.04. The default Rust package is 1.65 (and 
> unlikely to change I assume?), but the
> -// generic format parser library uses `is_some_and` which was introduced in 
> 1.70. So this is a reimplementation,
> -// directly taken from the standard library sources
> -trait IsSomeAnd {
> -fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool;
> -}
> -
> -impl IsSomeAnd for Option {
> -fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool {
> -match self {
> -None => false,
> -Some(x) => f(x),
> -}
> -}
> -}
> -
>  // use rustc_lexer::unescape;
>  pub use Alignment::*;
>  pub use Count::*;
> diff --git a/libgrust/libformat_parser/src/lib.rs 
> b/libgrust/libformat_parser/src/lib.rs
> index 0769577740f..f4670bf9b1f 100644
> --- a/libgrust/libformat_parser/src/lib.rs
> +++ b/libgrust/libformat_parser/src/lib.rs
> @@ -5,16 +5,6 @@
>  
>  use std::ffi::CStr;
>  
> -trait StringLeakExt {
> -fn leak<'a>(self) -> &'a mut str;
> -}
> -
> -impl StringLeakExt for String {
> -fn leak<'a>(self) -> &'a mut str {
> -Box::leak(self.into_boxed_str())
> -}
> -}
> -
>  trait IntoFFI {
>  fn into_ffi(self) -> T;
>  }
> @@ -98,10 +88,6