Comments (7)
Sorry about the slow reply. The rule gets effectively inserted as a sub-module of the crate that you're operating on, so you should I think be able to refer to types the same way as you would in a sub-module.
from rerast.
Hmm that doesn't seem to be working.
Using an exported path:
error[E0432]: unresolved import `crate::Location`
--> tests/__rerast_rules.rs:1:5
|
1 | use crate::Location;
| ^^^^^^^^^^^^^^^ no `Location` in the root
Using absolute paths relative to the crate:
error[E0433]: failed to resolve: unresolved import
--> tests/__rerast_rules.rs:1:12
|
1 | use crate::data::prelude::Location;
| ^^^^
| |
| unresolved import
| help: a similar path exists: `rcc::data`
Using absolute paths:
error[E0433]: failed to resolve: use of undeclared type or module `rcc`
--> src/__rerast_rules.rs:1:5
|
1 | use rcc::data::prelude::Location;
| ^^^ use of undeclared type or module `rcc`
from rerast.
I just tried with src/lib.rs containing:
pub mod data {
pub mod prelude {
pub struct Location {}
impl Location {
pub fn foo(&self) -> i32 { 41 }
pub fn bar(&self) -> i32 { 42 }
}
}
}
pub struct Location2 {}
impl Location2 {
pub fn foo(&self) -> i32 { 41 }
pub fn bar(&self) -> i32 { 42 }
}
#[cfg(test)]
mod tests {
use crate::data::prelude::Location;
use crate::Location2;
#[test]
fn it_works() {
let l = Location {};
assert_eq!(l.foo(), 42);
let l2 = Location2 {};
assert_eq!(l2.foo(), 42);
}
}
Then ran:
cargo +nightly rerast -p 'l1: crate::data::prelude::Location' -s 'l1.foo()' -r 'l1.bar()' --diff
This produced:
--- src/lib.rs
+++ src/lib.rs
@@ -24,7 +24,7 @@
#[test]
fn it_works() {
let l = Location {};
- assert_eq!(l.foo(), 42);
+ assert_eq!(l.bar(), 42);
let l2 = Location2 {};
assert_eq!(l2.foo(), 42);
from rerast.
That's really strange, your example doesn't work on my machine:
error[E0433]: failed to resolve: unresolved import
--> src/__rerast_rules.rs:1:24
|
1 | pub fn rule(l1: crate::data::prelude::Location){replace!(l1.foo() => l1.bar());}
| ^^^^
| |
| unresolved import
| help: a similar path exists: `import_test::data`
This is with 0.1.74.
from rerast.
Oh I found the problem! If I remove src/bin.rs
it works. Rerast must be trying to fix both, but the import paths are different depending on which it tries to change.
from rerast.
As a workaround, I can use --file src/lib.rs
and it will only try to fix the library, not the binary.
from rerast.
Ah, thanks for debugging what was going on there. That makes sense. Not sure what the best fix is there. Perhaps Rerast could be smart enough to swap between crate:: and the name of the crate depending on which context it's in.
from rerast.
Related Issues (20)
- Build errors on installation HOT 2
- Rewrite discards expression for variable HOT 2
- build failure with rustc 1.32.0-nightly (f4a421ee3 2018-12-13) HOT 1
- Documentation examples of the replace_type and replace_trait_ref. HOT 1
- replace_type macro fails on rust edition 2018. HOT 1
- Build fails on 1.35-nightly HOT 2
- dot async example HOT 2
- Rerast requires `rustup` HOT 4
- try! example panics when fixing docs.rs HOT 5
- Better error messages HOT 1
- Allow running when not in root directory HOT 2
- Build failure with latest nightly: ExprKind::AddrOf variant changed HOT 5
- Example of modifying a function definition? HOT 1
- Specifying type () in placeholders generates bad syntax HOT 2
- Replacing try macro in 2018 edition HOT 3
- Running cargo rerast in workspaces fails HOT 5
- can't compile on latest nightly HOT 2
- Matching of string literals HOT 2
- Transform attribute values
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rerast.