You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Allen George (Jira)" <ji...@apache.org> on 2020/03/29 15:19:00 UTC

[jira] [Comment Edited] (THRIFT-5071) Rust: rust tutorial can not be compiled with rust edition 2018

    [ https://issues.apache.org/jira/browse/THRIFT-5071?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17070383#comment-17070383 ] 

Allen George edited comment on THRIFT-5071 at 3/29/20, 3:18 PM:
----------------------------------------------------------------

[frowns]

If I understand correctly, there are two problems:

# under {{edition = "2018"}} the rules for generating relative paths have changed. It used to be that you didn't have to specify a root for a relative path. Now one *has* to use {{self}},{{super}} or {{crate}}
# one can't place thrift files that are dependent on each other in an arbitrary directory structure, because the generated {{use ...}} declarations assume that all thrift files are in the same location

For the first situation, we can indeed solve it by adding {{crate}} to the {{use}} declaration; for example: {{use crate::MODULE_NAME}}, assuming that all generated files are in one level.

For the second situation, I *think* the problem is as follows. Consider:

{noformat}
root
+- common.thrift
+- dir1
    +- dependent_1_on_common.thrift
    +- ...
+- dir2
    +- dependent_2_on_common.thrift
    +- ...
{noformat}

The problem here is that the generated {{dependent_1_on_common.rs}} and {{dependent_2_on_common.rs}} all would have declarations like:

{noformat}

// Autogenerated by Thrift Compiler (0.14.0)
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING

#![allow(unused_imports)]
#![allow(unused_extern_crates)]
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments, type_complexity))]
#![cfg_attr(rustfmt, rustfmt_skip)]

use crate::common; <---- PROBLEMATIC LINE

...

{noformat}

that would obviously break because their location in the rust/filesystem module hierarchy is not reflected in the thrift-generated code. Assuming the compiler has the information, I *think* this would be solved by including the Thrift namespace of the *dependent* file in the generated {{use}} expressions in the *dependee*.

At any rate, this should be two tickets that are dealt with separately, and I'll create a separate ticket around the directory-structure issue.


was (Author: allengeorge):
[frowns]

If I understand correctly, there are two problems:

# under {{edition = "2018"}} the rules for generating relative paths have changed. It used to be that you didn't have to specify a root for a relative path. Now one *has* to use {{self}},{{super}} or {{crate}}
# one can't place thrift files that are dependent on each other in an arbitrary directory structure, because the generated {{use ...}} declarations assume that all thrift files are in the same location

For the first situation, we can indeed solve it by adding {{crate}} to the {{use}} declaration; for example: {{use crate::MODULE_NAME}}, assuming that all generated files are in one level.

For the second situation, I *think* the problem is as follows. Consider:

{{noformat}}
root
+- common.thrift
+- dir1
    +- dependent_1_on_common.thrift
    +- ...
+- dir2
    +- dependent_2_on_common.thrift
    +- ...
{{noformat}}

The problem here is that the generated {{dependent_1_on_common.rs}} and {{dependent_2_on_common.rs}} all would have declarations like:

{{noformat}}

// Autogenerated by Thrift Compiler (0.14.0)
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING

#![allow(unused_imports)]
#![allow(unused_extern_crates)]
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments, type_complexity))]
#![cfg_attr(rustfmt, rustfmt_skip)]

use crate::common; <---- PROBLEMATIC LINE

...

{{noformat}}

that would obviously break because their location in the rust/filesystem module hierarchy is not reflected in the thrift-generated code. Assuming the compiler has the information, I *think* this would be solved by including the Thrift namespace of the *dependent* file in the generated {{use}} expressions in the *dependee*.

At any rate, this should be two tickets that are dealt with separately, and I'll create a separate ticket around the directory-structure issue.

> Rust: rust tutorial can not be compiled with rust edition 2018
> --------------------------------------------------------------
>
>                 Key: THRIFT-5071
>                 URL: https://issues.apache.org/jira/browse/THRIFT-5071
>             Project: Thrift
>          Issue Type: Bug
>          Components: Rust - Compiler, Tutorial
>    Affects Versions: 0.13.0
>         Environment: cargo 1.40.0 (bc8e4c8be 2019-11-22)
> rustc 1.40.0 (73528e339 2019-12-16)
>            Reporter: fan liwen
>            Assignee: Allen George
>            Priority: Major
>
> The rust compiler is broken for rust edition 2018. If we change the tutorial cargo (tutorial/rs/Cargo.toml) to edition = "2018", the following error would occur:
> {code:java}
> // code placeholder
> error[E0432]: unresolved import `shared`
>   --> src/tutorial.rs:30:5
>    |
> 30 | use shared;
>    |     ^^^^^^ no `shared` external crateerror: aborting due to previous error
> {code}
>  The compiler might need to generate *use crate::shared* instead. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)