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

ASF GitHub Bot commented on THRIFT-4662:
----------------------------------------

allengeorge commented on a change in pull request #1624: THRIFT-4662: Rust 
const string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r232454772
 
 

 ##########
 File path: compiler/cpp/src/thrift/generate/t_rs_generator.cc
 ##########
 @@ -673,15 +676,22 @@ void t_rs_generator::render_const_value_holder(const 
string& name, t_type* ttype
   f_gen_ << endl;
 }
 
-void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue) {
+void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue, 
bool isowned) {
   if (ttype->is_base_type()) {
     t_base_type* tbase_type = (t_base_type*)ttype;
     switch (tbase_type->get_base()) {
     case t_base_type::TYPE_STRING:
       if (tbase_type->is_binary()) {
-        f_gen_ << "\"" << tvalue->get_string() << "\""<<  
".to_owned().into_bytes()";
+        if (isowned) {
 
 Review comment:
   No - the PR isn't being held up because of const binary. I just didn't have 
time to look at it yet. I usually pull the branch locally and test in a 
container to ensure everything works. For one thing, I'm unsure that
   
   ```
   const FOO: &str = "ladeda";
   ```
   
   works in rust 1.28.
   
   EDIT. Oh, nm - I see it was [enabled in 
1.17](https://rust-lang-nursery.github.io/edition-guide/rust-2018/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.html)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> ------------------------------------------------
>
>                 Key: THRIFT-4662
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4662
>             Project: Thrift
>          Issue Type: Bug
>          Components: Rust - Compiler
>    Affects Versions: 0.11.0
>         Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>            Reporter: J W
>            Assignee: Allen George
>            Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE: &str = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to