Skip to content
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

Code compiles with escape=html, but not with escape=none. #132

Closed
SolidTux opened this issue Oct 18, 2018 · 4 comments
Closed

Code compiles with escape=html, but not with escape=none. #132

SolidTux opened this issue Oct 18, 2018 · 4 comments

Comments

@SolidTux
Copy link

SolidTux commented Oct 18, 2018

I want to use a template for WebGL inside a html document, so I need to disable the html escaping for it to work. But when switching to escape=none, the borrow checker complains, because &{ self.name } is used instead of &self.name.

The struct is defined as:

#[derive(Template)]
#[template(path = "webgl.html", escape = "none", print = "code")]
pub struct WebGlDemo {
    pub name: String,
    pub shader: StandaloneShader,
}
#[derive(Template)]
#[template(path = "standalone.glsl")]
pub struct StandaloneShader(pub ShaderContent);
pub struct ShaderContent;

And I get the following errors:

error[E0507]: cannot move out of borrowed content
 --> src\webgl.rs:5:10
  |
5 | #[derive(Template)]
  |          ^^^^^^^^ cannot move out of borrowed content

error[E0507]: cannot move out of `self.name` which is behind a `&` reference
 --> src\webgl.rs:5:10
  |
5 | #[derive(Template)]
  |          ^^^^^^^^
  |          |
  |          cannot move out of `self.name` which is behind a `&` reference
  |          `self` is a `&` reference, so the data it refers to cannot be moved
  |          help: consider changing this to be a mutable reference: `&mut self`

error[E0507]: cannot move out of `self.shader` which is behind a `&` reference
 --> src\webgl.rs:5:10
  |
5 | #[derive(Template)]
  |          ^^^^^^^^
  |          |
  |          cannot move out of `self.shader` which is behind a `&` reference
  |          `self` is a `&` reference, so the data it refers to cannot be moved
  |          help: consider changing this to be a mutable reference: `&mut self`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0507`.

Here is the generated code with html escaping and here without escaping.

Edit:

I forgot to mention the versions I use:

  • askama: 0.7.2
  • cargo: 1.31.0-nightly (5dbac9888 2018-10-08)
  • rustc: 1.31.0-nightly (1dceaddfb 2018-10-17)

I also use the edition = "2018" option.

@djc
Copy link
Owner

djc commented Oct 18, 2018

Thanks for the very complete bug report! I'll do some digging. Inferring the types right is one of the hardest parts of Askama and interesting cases keep popping up... One of these days I'll see if I can come up with a more robust strategy.

@djc
Copy link
Owner

djc commented Oct 19, 2018

Can you try the branch from #133 and see if it solves your issue? Also, if you could write up a PR with a reduced version of the failing case, that would help a lot.

@SolidTux
Copy link
Author

Yes, this works. Do you mean a PR with a test case added like #134?

@lukehsiao
Copy link

@djc Using the branch from #133 also fixed the issue I mentioned in #107 for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants