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

cannot strip expression in this position - outer attributes not allowed #391

Closed
dkm opened this issue Apr 26, 2021 · 2 comments · Fixed by #1022
Closed

cannot strip expression in this position - outer attributes not allowed #391

dkm opened this issue Apr 26, 2021 · 2 comments · Fixed by #1022
Assignees
Labels

Comments

@dkm
Copy link
Member

dkm commented Apr 26, 2021

Not really sure what is the meaning of the message for :

fn foo (e: &str) -> &str {
    &""
}
slice1.rs:2:6: error: cannot strip expression in this position - outer attributes not allowed

FTR, rustc gives :

warning: unused variable: `e`
 --> .../git/gccrs/gcc/testsuite/rust.test/unsupported/slice1.rs:1:9
  |
1 | fn foo (e: &str) -> &str {
  |         ^ help: if this is intentional, prefix it with an underscore: `_e`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: function is never used: `foo`
 --> .../git/gccrs/gcc/testsuite/rust.test/unsupported/slice1.rs:1:4
  |
1 | fn foo (e: &str) -> &str {
  |    ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 2 warnings emitted
@SimplyTheOther
Copy link
Member

I believe the error results from this:

The string literal given is empty. This is incidentally also the representation of an “invalid literal”, as defined by the is_error method in Literal. This was a typo - it was meant to be an empty char only that is invalid (since you can’t have an empty char).

The LiteralExpr that wraps this Literal into an expression is also marked as “invalid” as a result.

In macro expansion, all expressions (among other things) are recursively checked for being invalid - being invalid is a marker to “strip” them. You obviously can’t strip components of operator expressions as they no longer make sense without operands, and that is why this error occurs - the macro expander finds that the LiteralExpr used as the operand for the BorrowExpr is invalid, but knows it can’t strip it, so it gives this error message.

TL;DR: We need to add a condition stating that the “type” of the literal must also be char to be invalid (as well as being empty).

@dkm
Copy link
Member Author

dkm commented Apr 27, 2021

Thanks for the details! I think I'll have to read a bit more to really understand what you are describing :D

@philberty philberty added the bug label Jan 17, 2022
@philberty philberty added this to the Macro Expansion milestone Jan 17, 2022
CohenArthur added a commit to CohenArthur/gccrs that referenced this issue Mar 14, 2022
This commit fixes the issue reported in Rust-GCC#391, but highlights another
one, which will be reported.
CohenArthur added a commit to CohenArthur/gccrs that referenced this issue Mar 16, 2022
This commit fixes the issue reported in Rust-GCC#391, but highlights another
one, which will be reported.
@bors bors bot closed this as completed in #1022 Mar 17, 2022
@bors bors bot closed this as completed in 3ada3d8 Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants