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

Move some ast_util functions into methods #30105

Merged
merged 1 commit into from
Dec 15, 2015
Merged

Conversation

faineance
Copy link
Contributor

Issue: #30058
Updated for:

  • Stmt
  • BinOp_
  • UnOp
  • UintTy, IntTy and FloatTy
  • Lit
  • Generics

A possible inconsistancy?
The Stmt methods are on the spanned varient:

pub type Stmt = Spanned<Stmt_>;

impl Stmt {
    pub fn id(s: &Stmt) -> Option<NodeId> {
        match s.node {
          StmtDecl(_, id) => Some(id),
          StmtExpr(_, id) => Some(id),
          StmtSemi(_, id) => Some(id),
          StmtMac(..) => None,
      }
  }
}

Whilst the methods for BinOp are on the non spanned version.

impl BinOp_ {
    pub fn to_string(op: BinOp_) -> &'static str { ... }
    pub fn lazy(b: BinOp_) -> bool { ... }

    pub fn is_shift(b: BinOp_) -> bool { ... }
    pub fn is_comparison(b: BinOp_) -> bool { ... }
    /// Returns `true` if the binary operator takes its arguments by value
    pub fn is_by_value(b: BinOp_) -> bool { ... }

}
pub type BinOp = Spanned<BinOp_>;

r? @Manishearth

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton
Copy link
Member

There's been some discussion about the stability of libsyntax recently, so I'm going to move this over in review:

r? @nrc

@rust-highfive rust-highfive assigned nrc and unassigned alexcrichton Nov 29, 2015
/// A statement
pub type Stmt = Spanned<Stmt_>;

impl Stmt {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be on the unspanned version. s.node is a Stmt_

@Manishearth Manishearth assigned Manishearth and nrc and unassigned nrc and Manishearth Nov 30, 2015
@Manishearth
Copy link
Member

Good start! However, all your impls should take self (except Generics::empty)-- that was the purpose behind this refactoring -- to convert ast_util::some_function(thing) into thing.some_function()

@faineance
Copy link
Contributor Author

Fixed. Are these considered breaking changes?

@Manishearth
Copy link
Member

It's a breaking change for a public, but unstable API. One that isn't used much outside of rustc

@faineance
Copy link
Contributor Author

@nrc Should this be merged?

@bors
Copy link
Contributor

bors commented Dec 4, 2015

☔ The latest upstream changes (presumably #29850) made this pull request unmergeable. Please resolve the merge conflicts.

@@ -1 +1 @@
Subproject commit 3564439515985dc1cc0d77057ed00901635a80ad
Subproject commit cde1ed3196ba9b39bcf028e06e08a8722113a5cb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a mistake

@nrc
Copy link
Member

nrc commented Dec 6, 2015

Could you squash the commits please and add a [breaking-change] comment to the commit message?

This seems somewhat borderline as to whether it should land or not. I think it is OK - ast_util stuff shouldn't be used by too many syntax extensions. Note that the corresponding changes to the HIR versions are totally OK.

There's a bunch of minor things to be addressed, but r+ with them fixed.

@nrc
Copy link
Member

nrc commented Dec 6, 2015

Oh, and with tests passing :-)

@faineance
Copy link
Contributor Author

Will do, thanks very much for the feedback.

@faineance faineance force-pushed the master branch 2 times, most recently from 536b2a7 to 0ca7bc5 Compare December 13, 2015 13:09
@faineance faineance force-pushed the master branch 2 times, most recently from 46461af to 3fc0dba Compare December 14, 2015 20:58
@faineance
Copy link
Contributor Author

Good to go?

@nrc
Copy link
Member

nrc commented Dec 14, 2015

@bors: r+

@bors
Copy link
Contributor

bors commented Dec 14, 2015

📌 Commit ec8ea22 has been approved by nrc

@bors
Copy link
Contributor

bors commented Dec 15, 2015

⌛ Testing commit ec8ea22 with merge 8f031bf...

bors added a commit that referenced this pull request Dec 15, 2015
Issue: #30058
Updated for:
 - Stmt
 - BinOp_
 - UnOp
 - UintTy, IntTy and FloatTy
 - Lit
 - Generics

A possible inconsistancy?
The `Stmt` methods are on the spanned varient:
```rust
pub type Stmt = Spanned<Stmt_>;

impl Stmt {
    pub fn id(s: &Stmt) -> Option<NodeId> {
        match s.node {
          StmtDecl(_, id) => Some(id),
          StmtExpr(_, id) => Some(id),
          StmtSemi(_, id) => Some(id),
          StmtMac(..) => None,
      }
  }
}
```
Whilst the methods for BinOp are on the non spanned version.
````rust
impl BinOp_ {
    pub fn to_string(op: BinOp_) -> &'static str { ... }
    pub fn lazy(b: BinOp_) -> bool { ... }

    pub fn is_shift(b: BinOp_) -> bool { ... }
    pub fn is_comparison(b: BinOp_) -> bool { ... }
    /// Returns `true` if the binary operator takes its arguments by value
    pub fn is_by_value(b: BinOp_) -> bool { ... }

}
pub type BinOp = Spanned<BinOp_>;
````
r? @Manishearth
@bors bors merged commit ec8ea22 into rust-lang:master Dec 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants