Skip to content

Commit

Permalink
derive: highlight value, not key
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski committed Jul 30, 2024
1 parent 08674bd commit 5e98580
Show file tree
Hide file tree
Showing 37 changed files with 306 additions and 209 deletions.
8 changes: 4 additions & 4 deletions rinja_derive/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl TemplateArgs {

if ident == "path" {
source_or_path(ident, value, &mut args.source, Source::Path)?;
args.ext_span = Some(ident.span());
args.ext_span = Some(value.span());
} else if ident == "source" {
source_or_path(ident, value, &mut args.source, |s| Source::Source(s.into()))?;
} else if ident == "block" {
Expand Down Expand Up @@ -395,12 +395,12 @@ impl TemplateArgs {
set_template_str_attr(ident, value, &mut args.escaping)?;
} else if ident == "ext" {
set_template_str_attr(ident, value, &mut args.ext)?;
args.ext_span = Some(ident.span());
args.ext_span = Some(value.span());
} else if ident == "syntax" {
set_template_str_attr(ident, value, &mut args.syntax)?;
} else if ident == "config" {
set_template_str_attr(ident, value, &mut args.config)?;
args.config_span = Some(ident.span())
args.config_span = Some(value.span())
} else if ident == "whitespace" {
set_template_str_attr(ident, value, &mut args.whitespace)?;
} else {
Expand Down Expand Up @@ -439,7 +439,7 @@ fn source_or_path(
Some(name.span()),
))
} else if let syn::Lit::Str(s) = &value.lit {
*dest = Some((ctor(s.value()), Some(name.span())));
*dest = Some((ctor(s.value()), Some(value.span())));
Ok(())
} else {
Err(CompileError::no_file_info(
Expand Down
24 changes: 12 additions & 12 deletions testing/tests/ui/as-primitive-type.stderr
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
error: `as` operator expects the name of a primitive type on its right-hand side
--> <source attribute>:1:8
"as 4567 }}"
--> tests/ui/as-primitive-type.rs:4:12
--> tests/ui/as-primitive-type.rs:4:21
|
4 | #[template(source = r#"{{ 1234 as 4567 }}"#, ext = "html")]
| ^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^

error: `as` operator expects the name of a primitive type on its right-hand side
--> <source attribute>:1:8
"as ? }}"
--> tests/ui/as-primitive-type.rs:8:12
--> tests/ui/as-primitive-type.rs:8:21
|
8 | #[template(source = r#"{{ 1234 as ? }}"#, ext = "html")]
| ^^^^^^
| ^^^^^^^^^^^^^^^^^^^^

error: `as` operator expects the name of a primitive type on its right-hand side, found `u1234`
--> <source attribute>:1:8
"as u1234 }}"
--> tests/ui/as-primitive-type.rs:12:12
--> tests/ui/as-primitive-type.rs:12:21
|
12 | #[template(source = r#"{{ 1234 as u1234 }}"#, ext = "html")]
| ^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: `as` operator expects the name of a primitive type on its right-hand side, found `core`
--> <source attribute>:1:8
"as core::primitive::u32 }}"
--> tests/ui/as-primitive-type.rs:16:12
--> tests/ui/as-primitive-type.rs:16:21
|
16 | #[template(source = r#"{{ 1234 as core::primitive::u32 }}"#, ext = "html")]
| ^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: `as` operator expects the name of a primitive type on its right-hand side, found `int32_t`
--> <source attribute>:1:8
"as int32_t }}"
--> tests/ui/as-primitive-type.rs:20:12
--> tests/ui/as-primitive-type.rs:20:21
|
20 | #[template(source = r#"{{ 1234 as int32_t }}"#, ext = "html")]
| ^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: `as` operator expects the name of a primitive type on its right-hand side, found `int32_t`
--> <source attribute>:1:35
"as int32_t }}"
--> tests/ui/as-primitive-type.rs:24:12
--> tests/ui/as-primitive-type.rs:24:21
|
24 | #[template(source = r#"{{ (1234 + 4 * 12 / 45675445 - 13) as int32_t }}"#, ext = "html")]
| ^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15 changes: 11 additions & 4 deletions testing/tests/ui/block_in_filter_block.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
error: cannot have a block inside a filter block
--> BlockInFilter.html:7:10
" block title %}New title{% endblock %}\n a b\n {% endfilter %}\n{%- endblock body %}\n"
--> tests/ui/block_in_filter_block.rs:5:5
|
5 | source = r#"{% extends "html-base.html" %}
| ^^^^^^
--> tests/ui/block_in_filter_block.rs:5:14
|
5 | source = r#"{% extends "html-base.html" %}
| ______________^
6 | |
7 | | {%- block body -%}
8 | | <h1>Metadata</h1>
... |
14 | | {%- endblock body %}
15 | | "#,
| |__^
34 changes: 25 additions & 9 deletions testing/tests/ui/blocks_below_top_level.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
error: `extends` blocks are not allowed below top level
--> MyTemplate1.txt:3:2
" extends \"bla.txt\" %}\n{% endblock %}\n"
--> tests/ui/blocks_below_top_level.rs:4:12
--> tests/ui/blocks_below_top_level.rs:4:21
|
4 | #[template(source = r#"
| ^^^^^^
4 | #[template(source = r#"
| _____________________^
5 | | {% block bla %}
6 | | {% extends "bla.txt" %}
7 | | {% endblock %}
8 | | "#, ext = "txt")]
| |__^

error: `macro` blocks are not allowed below top level
--> MyTemplate2.txt:3:2
" macro bla() %}\n{% endmacro %}\n{% endblock %}\n"
--> tests/ui/blocks_below_top_level.rs:12:12
--> tests/ui/blocks_below_top_level.rs:12:21
|
12 | #[template(source = r#"
| ^^^^^^
12 | #[template(source = r#"
| _____________________^
13 | | {% block bla %}
14 | | {% macro bla() %}
15 | | {% endmacro %}
16 | | {% endblock %}
17 | | "#, ext = "txt")]
| |__^

error: `import` blocks are not allowed below top level
--> MyTemplate3.txt:3:2
" import \"bla.txt\" as blue %}\n{% endblock %}\n"
--> tests/ui/blocks_below_top_level.rs:21:12
--> tests/ui/blocks_below_top_level.rs:21:21
|
21 | #[template(source = r#"
| ^^^^^^
21 | #[template(source = r#"
| _____________________^
22 | | {% block bla %}
23 | | {% import "bla.txt" as blue %}
24 | | {% endblock %}
25 | | "#, ext = "txt")]
| |__^
4 changes: 2 additions & 2 deletions testing/tests/ui/break_outside_of_loop.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: you can only `break` inside a `for` loop
--> <source attribute>:1:9
"break%}, have a parsing error!"
--> tests/ui/break_outside_of_loop.rs:5:5
--> tests/ui/break_outside_of_loop.rs:5:14
|
5 | source = "Have a {%break%}, have a parsing error!",
| ^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16 changes: 8 additions & 8 deletions testing/tests/ui/broken-config.stderr
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
error: `$WORKSPACE/target/tests/trybuild/rinja_testing/no-such-config.toml` does not exist
--> tests/ui/broken-config.rs:4:38
--> tests/ui/broken-config.rs:4:47
|
4 | #[template(source = "", ext = "txt", config = "no-such-config.toml")]
| ^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^

error: unable to read $WORKSPACE/target/tests/trybuild/rinja_testing/folder-config.toml: Is a directory (os error 21)
--> tests/ui/broken-config.rs:8:38
--> tests/ui/broken-config.rs:8:47
|
8 | #[template(source = "", ext = "txt", config = "folder-config.toml")]
| ^^^^^^
| ^^^^^^^^^^^^^^^^^^^^

error: a delimiter may not be the prefix of another delimiter: "<<<" vs "<<<<"
--> testing/delim-clash.toml
--> tests/ui/broken-config.rs:12:38
--> tests/ui/broken-config.rs:12:47
|
12 | #[template(source = "", ext = "txt", config = "delim-clash.toml")]
| ^^^^^^
| ^^^^^^^^^^^^^^^^^^

error: delimiters must be at least two characters long: "<"
--> testing/delim-too-short.toml
--> tests/ui/broken-config.rs:16:38
--> tests/ui/broken-config.rs:16:47
|
16 | #[template(source = "", ext = "txt", config = "delim-too-short.toml")]
| ^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^
32 changes: 16 additions & 16 deletions testing/tests/ui/char_literal.stderr
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
error: invalid character
--> testing/templates/char-literals/char-literal-1.txt:1:11
"'\\a' %}"
--> tests/ui/char_literal.rs:4:12
--> tests/ui/char_literal.rs:4:19
|
4 | #[template(path = "char-literals/char-literal-1.txt")]
| ^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: invalid character
--> testing/templates/char-literals/char-literal-2.txt:1:11
"'\\x' %}"
--> tests/ui/char_literal.rs:8:12
--> tests/ui/char_literal.rs:8:19
|
8 | #[template(path = "char-literals/char-literal-2.txt")]
| ^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: invalid character
--> testing/templates/char-literals/char-literal-3.txt:1:11
"'\\x1' %}"
--> tests/ui/char_literal.rs:12:12
--> tests/ui/char_literal.rs:12:19
|
12 | #[template(path = "char-literals/char-literal-3.txt")]
| ^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: must be a character in the range [\x00-\x7f]
--> testing/templates/char-literals/char-literal-4.txt:1:11
"'\\x80' %}"
--> tests/ui/char_literal.rs:16:12
--> tests/ui/char_literal.rs:16:19
|
16 | #[template(path = "char-literals/char-literal-4.txt")]
| ^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: invalid character
--> testing/templates/char-literals/char-literal-5.txt:1:11
"'\\u' %}"
--> tests/ui/char_literal.rs:20:12
--> tests/ui/char_literal.rs:20:19
|
20 | #[template(path = "char-literals/char-literal-5.txt")]
| ^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: invalid character
--> testing/templates/char-literals/char-literal-6.txt:1:11
"'\\u{}' %}"
--> tests/ui/char_literal.rs:24:12
--> tests/ui/char_literal.rs:24:19
|
24 | #[template(path = "char-literals/char-literal-6.txt")]
| ^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: unicode escape must be at most 10FFFF
--> testing/templates/char-literals/char-literal-7.txt:1:11
"'\\u{110000}' %}"
--> tests/ui/char_literal.rs:28:12
--> tests/ui/char_literal.rs:28:19
|
28 | #[template(path = "char-literals/char-literal-7.txt")]
| ^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: invalid character
--> <source attribute>:1:11
"'aaa' %}"
--> tests/ui/char_literal.rs:32:12
--> tests/ui/char_literal.rs:32:21
|
32 | #[template(source = "{% let s = 'aaa' %}", ext = "html")]
| ^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^
4 changes: 2 additions & 2 deletions testing/tests/ui/cycle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: cyclic dependency in graph [
"\"$WORKSPACE/target/tests/trybuild/rinja_testing/templates/cycle2.html/" --> \"$WORKSPACE/target/tests/trybuild/rinja_testing/templates/cycle1.html/"",
"\"$WORKSPACE/target/tests/trybuild/rinja_testing/templates/cycle1.html/" --> \"$WORKSPACE/target/tests/trybuild/rinja_testing/templates/cycle1.html/"",
]
--> tests/ui/cycle.rs:4:12
--> tests/ui/cycle.rs:4:19
|
4 | #[template(path = "cycle2.html")]
| ^^^^
| ^^^^^^^^^^^^^
4 changes: 2 additions & 2 deletions testing/tests/ui/cycle2.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: cyclic dependency in graph [
"\"$WORKSPACE/target/tests/trybuild/rinja_testing/templates/cycle1.html/" --> \"$WORKSPACE/target/tests/trybuild/rinja_testing/templates/cycle1.html/"",
]
--> tests/ui/cycle2.rs:4:12
--> tests/ui/cycle2.rs:4:19
|
4 | #[template(path = "cycle1.html")]
| ^^^^
| ^^^^^^^^^^^^^
12 changes: 6 additions & 6 deletions testing/tests/ui/error_file_path.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
error: failed to parse template source
--> testing/templates/invalid_syntax.html:1:14
"}"
--> tests/ui/error_file_path.rs:4:12
--> tests/ui/error_file_path.rs:4:19
|
4 | #[template(path = "invalid_syntax.html")]
| ^^^^
| ^^^^^^^^^^^^^^^^^^^^^

error: failed to parse template source
--> testing/templates/invalid_syntax.html:1:14
"}"
--> tests/ui/error_file_path.rs:8:12
--> tests/ui/error_file_path.rs:8:19
|
8 | #[template(path = "include_invalid_syntax.html")]
| ^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: failed to parse template source
--> testing/templates/invalid_syntax.html:1:14
"}"
--> tests/ui/error_file_path.rs:12:12
--> tests/ui/error_file_path.rs:12:21
|
12 | #[template(source = r#"{% extends "include_invalid_syntax.html" %}"#, ext = "txt")]
| ^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Loading

0 comments on commit 5e98580

Please sign in to comment.