-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
proc-macro param attrs dropping first attrs in impl fns #64682
Comments
Ping @Centril |
I'm rather busy this week and I can only take a look into it in this weekend |
triage: P-high. Leaving nominated in hopes to find someone to look into it, since @c410-f3r won't have time for next few days. |
assigning to @Centril |
Investigation thus far: I don't think the problem is in pretty printing but somewhere else. #![deny(unused_variables)]
struct Foo;
fn _f0(#[allow(unused_variables)] p0: u8) {}
impl Foo {
fn _f1(#[allow(unused_variables)] p1: u8) {}
fn _f2(&self, #[allow(unused_variables)] p2: u8) {}
} results in: error: unused variable: `p1`
--> src/lib.rs:8:39
|
8 | fn _f1(#[allow(unused_variables)] p1: u8) {}
| ^^ help: consider prefixing with an underscore: `_p1`
|
note: lint level defined here
--> src/lib.rs:1:9
|
1 | #![deny(unused_variables)]
| ^^^^^^^^^^^^^^^^
pub struct S;
impl S {
fn _f1(#[allow(lint)] p1: u8) {}
} results in: error[E0658]: attributes on function parameters are unstable
--> src/lib.rs:4:12
|
4 | fn _f1(#[allow(lint)] p1: u8) {}
| ^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/60406 on stable. But the problem does appear at least in AST validation: pub struct S;
impl S {
fn _f2(
/// abc <-- compiles but it should be rejected!
_p1: u8
) {}
} Actually, it turns out the problem is in the parser, and we have a bug that allows: trait T {
fn _f2(#[foo]) {}
} |
syntax: fix dropping of attribute on first param of non-method assocated fn Fixes rust-lang#64682. The general idea is that we bake parsing of `self` into `parse_param_general` and then we just use standard list parsing. Overall, this simplifies the parsing and makes it more consistent. r? @petrochenkov cc @c410-f3r
syntax: fix dropping of attribute on first param of non-method assocated fn Fixes rust-lang#64682. The general idea is that we bake parsing of `self` into `parse_param_general` and then we just use standard list parsing. Overall, this simplifies the parsing and makes it more consistent. r? @petrochenkov cc @c410-f3r
Fuse parsing of `self` into `parse_param_general`.
Fuse parsing of `self` into `parse_param_general`.
I have been able to reproduce #64282.
If an
fn
inside animpl
has a param attr on the first parameter, no matter how many, they are not visible in theTokenStream
.Repro repo: https://github.com/bbqsrc/params-attribute-example
Source:
Printed output:
As you can see,
hello
andhello2
are missing their attrs on thea
param. The addition ofself
however gives bothself
and thea
param their attrs. Weird.The text was updated successfully, but these errors were encountered: