Skip to content

mutable linear types are modified when I don't think they are (except when in function calls?) [documentation needed, or real bug??] #15269

@killerswan

Description

@killerswan

From here, again: https://github.com/killerswan/ovid/blob/ad2efdabb2eb834ca7a50cbda5806ccd033d6283/CSVProvider.rs

In this, cx is a &mut ExtCtxt, which @brson said was a linear type. There's something special in how these are handled in function arguments, apparently, which allows cx to be used twice here with quote_item! only when the first is inside a function call. Why? What is going on?

If this isn't a bug, do we have it documented somewhere? :D

ovid $ 
ovid $ git diff
diff --git a/CSVProvider.rs b/CSVProvider.rs
index 4fa650f..a19192e 100644
--- a/CSVProvider.rs
+++ b/CSVProvider.rs
@@ -156,16 +156,11 @@ fn provide_csv_given_labels(cx: &mut ExtCtxt, sp: Span, tts: &[Toke
  */


-   fn define_my_csv(cx0: &mut ExtCtxt) -> Option<Gc<syntax::ast::Item>> {
       let item1: Option<Gc<syntax::ast::Item>>  = quote_item!(cx0,
          pub struct MyCSV {
             pub data: Vec<(String)>,
          }
       );
-      return item1;
-   }
-
-   let item1 = define_my_csv(cx);  // Why is this necessary?

    let item2: Option<Gc<syntax::ast::Item>>  = quote_item!(cx,
       impl MyCSV {
ovid $ ./build.sh 
CSVProvider.rs:159:63: 159:66 error: unresolved name `cx0`. Did you mean `cx`?
CSVProvider.rs:159       let item1: Option<Gc<syntax::ast::Item>>  = quote_item!(cx0,
                                                                                 ^~~
note: in expansion of quote_item!
CSVProvider.rs:159:51: 163:9 note: expansion site
error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions