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

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

Closed
killerswan opened this issue Jun 30, 2014 · 2 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@killerswan
Copy link
Contributor

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
@killerswan
Copy link
Contributor Author

I need to understand this so I can do some additional things like this, which can't be done in a fn item: https://gist.github.com/killerswan/b4e6d5840c46942bd3be

@steveklabnik steveklabnik added O-macos Operating system: macOS A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) and removed O-macos Operating system: macOS labels Jan 23, 2015
@kmcallister
Copy link
Contributor

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?

&mut T can be "re-borrowed" for function calls. The quote_*! macros used to not do this properly but I fixed that in #16992.

If there's still an issue here, please open a new ticket with a self-contained example.

bors added a commit to rust-lang-ci/rust that referenced this issue Aug 7, 2023
…red-rendering, r=Veykril

internal: Defer structured snippet rendering to allow escaping snippet bits

Since we know exactly where snippets are, we can transparently escape snippet bits to the exact text edits that need it, and not have to do it for anything other text edits.

Also will eventually fix rust-lang#11006 once all assists are migrated. This comes as a side-effect of text edits that don't have snippets get marked as having no insert formatting at all.
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 16, 2023
…textedit, r=Veykril

minor: Allow multiple snippet edits in a `TextDocumentEdit`

Explicitly[^1] allow a single `TextDocumentEdit` to have multiple `SnippetTextEdit`s. This allows things like renaming extracted variables and functions without having to go through a separate rename step. For an example of what this looks like, see the video in [this comment](microsoft/vscode#145374 (comment)).

The behavior described here lines up with [what VSCode does](https://github.com/microsoft/vscode/blob/bdc113ffe148a92d0e1a8ec34b12c44ea0b73f29/src/vscode-dts/vscode.d.ts#L3728-L3731), and presumably what the eventual LSP behavior will be.

[^1]: This was technically the case before rust-lang#15269, a single `TextDocumentEdit` always had multiple edits which were `InsertTextFormat.Snippet` as all of the edits were marked as being snippets, even if there weren't any tab stops or placeholders.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
Projects
None yet
Development

No branches or pull requests

3 participants