Coder Social home page Coder Social logo

Cannot parse disabled pub type about gccrs HOT 3 CLOSED

P-E-P avatar P-E-P commented on July 19, 2024
Cannot parse disabled pub type

from gccrs.

Comments (3)

officialhemant511 avatar officialhemant511 commented on July 19, 2024

i wanna solve this issue

from gccrs.

officialhemant511 avatar officialhemant511 commented on July 19, 2024
  • try this...
  • The issue with the code you provided is that trait items, including associated types like type X, cannot be marked as pub. The pub keyword specifies the item's visibility, but associated types in traits are always public by default. Therefore, you can simply remove the pub keyword from the declaration of type X:

fn main() {}

  • #[cfg(FALSE)]

trait T

[ ] {

type X;

}
i hope it will solve the issue...

from gccrs.

P-E-P avatar P-E-P commented on July 19, 2024

i wanna solve this issue

Sure @officialhemant511 ! I can assign it to you.

* The issue with the code you provided is that trait items, including associated types like type X, cannot be marked as pub. The pub keyword specifies the item's visibility, but associated types in traits are always public by default. Therefore, you can simply remove the pub keyword from the declaration of type X:

The problem here does not lie in the code in this code but rather in the compiler. rustc can compile this code without any error (link to the playground).

It compiles because the line has been disabled thanks to #[cfg(FALSE)]. The step that removes part of the AST with those cfg directives is called "cfg stripping" in gccrs. This step relies on the ast, this means we shall refer to rust syntax reference:

Syntax
AssociatedItem :
OuterAttribute* (
MacroInvocationSemi
| ( Visibility? ( TypeAlias | ConstantItem | Function ) )
)

from https://doc.rust-lang.org/beta/reference/items/associated-items.html, here pub type fall in the type alias category.

Note that from the syntax pov, this visibility modifier is expected even if the language reject it at a later stage with the error 0449.

The error message from gccrs states that it originates from the parsing stage of the compiler. This means the AST has not been finished yet. We should be able to parse this syntax, even if rejected later, so it could be eliminated by the cfg stripper.

To sum up

The parser shall be fixed to accept a visibility modifier. The problem probably is in the member function parse_trait_item in rust-parse-impl.h. The function does not expect pub and falls to the default case label, which s expecting a macro.

This means we should probably modify the TraitIemType ast node to store the visibility and reject the line at a later stage.

Do you still want to me to assign you on the issue ? I hope this didn't break your confidence or anything.

from gccrs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.