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

Stabilize 'attr_literals' feature. #53044

Merged
merged 1 commit into from
Aug 24, 2018

Conversation

SergioBenitez
Copy link
Contributor

@SergioBenitez SergioBenitez commented Aug 3, 2018

RFC Issue: rust-lang/rfcs#1559
Tracking Issue: #34981

Reference PR: rust-lang/reference#388.

@rust-highfive
Copy link
Collaborator

r? @michaelwoerister

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 3, 2018
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading https://files.pythonhosted.org/packages/2a/a2/dba13566ff2819757280c7c92ca225de3bef4ef4892697885156dbe36ac9/awscli-1.15.71-py2.py3-none-any.whl (1.3MB)
    0% |▎                               | 10kB 17.7MB/s eta 0:00:01
    1% |▌                               | 20kB 1.8MB/s eta 0:00:01
    2% |▊                               | 30kB 2.2MB/s eta 0:00:01
    3% |█                               | 40kB 1.9MB/s eta 0:00:01
---
travis_time:start:test_ui
Check compiletest suite=ui mode=ui (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[00:41:51] 
[00:41:51] running 2228 tests
[00:41:54] ...................F................................................................................
[00:42:01] ....................................................................................................
[00:42:03] ....................................................................................................
[00:42:03] ....................................................................................................
[00:42:05] .................................................................................F.F................
[00:42:10] ....................................................................................................
[00:42:13] ....................................................................................................
[00:42:15] ....................................................................................................
[00:42:18] ...........i........................................................................................
[00:42:18] ...........i........................................................................................
[00:42:20] ....................................................................................................
[00:42:22] ....................................................................................................
[00:42:25] ....................................................................................................
[00:42:28] .......................................................................................F............
[00:42:33] ....................................................................................................
[00:42:37] ....................................................................................................
[00:42:40] .....i..............................................................................................
[00:42:40] .....i..............................................................................................
[00:42:43] .........i......................F...................................................................
[00:42:50] ....................................................................................................
[00:42:53] ...............................i....................................................................
[00:42:54] .......................i....
[00:42:54] failures:
[00:42:54] failures:
[00:42:54] 
[00:42:54] ---- [ui] ui/attr-usage-repr.rs stdout ----
[00:42:54] diff of stderr:
[00:42:54] 
[00:42:54] 1 error[E0517]: attribute should be applied to struct, enum or union
[00:42:54] +   --> $DIR/attr-usage-repr.rs:13:8
[00:42:54] 3    |
[00:42:54] 3    |
[00:42:54] 4 LL | #[repr(C)] //~ ERROR: attribute should be applied to struct, enum or union
[00:42:54] 
[00:42:54] 
[00:42:54] 7    | --------- not a struct, enum or union
[00:42:54] 9 error[E0517]: attribute should be applied to enum
[00:42:54] -   --> $DIR/attr-usage-repr.rs:26:8
[00:42:54] +   --> $DIR/attr-usage-repr.rs:25:8
[00:42:54] 11    |
[00:42:54] 11    |
[00:42:54] 12 LL | #[repr(i8)] //~ ERROR: attribute should be applied to enum
[00:42:54] 
[00:42:54] 
[00:42:54] 15    | ---------------------- not an enum
[00:42:54] 17 error[E0517]: attribute should be applied to struct or union
[00:42:54] -   --> $DIR/attr-usage-repr.rs:32:8
[00:42:54] +   --> $DIR/attr-usage-repr.rs:31:8
[00:42:54] 19    |
[00:42:54] 19    |
[00:42:54] 20 LL | #[repr(align(8))] //~ ERROR: attribute should be applied to struct
[00:42:54] 
[00:42:54] 
[00:42:54] 23    | -------------------- not a struct or union
mary":false,"text":[{"text":"struct SInt(f64, f64);","highlight_start":1,"highlight_end":23}],"label":"not an enum","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/attr-usage-repr.rs","byte_start":704,"byte_end":706,"line_start":25,"line_end":25,"column_start":8,"column_end":10,"is_primary":true,"text":[{"text":"#[repr(i8)] //~ ERROR: attribute should be applied to enum","highlight_start":8,"highlight_end":10}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0517]: attribute should be applied to enum\n  --> /checkout/src/test/ui/attr-usage-repr.rs:25:8\n   |\nLL | #[repr(i8)] //~ ERROR: attribute should be applied to enum\n   |        ^^\nLL | struct SInt(f64, f64);\n   | ---------------------- not an enum\n\n"}
[00:42:54] {"message":"attribute should be applied to struct or union","code":{"code":"E0517","explanation":"\nThis error indicates that a `#[repr(..)]` attribute was placed on an\nunsupported item.\n\nExamples of erroneous code:\n\n```compile_fail,E0517\n#[repr(C)]\ntype Foo = u8;\n\n#[repr(packed)]\nenum Foo {Bar, Baz}\n\n#[repr(u8)]\nstruct Foo {bar: bool, baz: bool}\n\n#[repr(C)]\nimpl Foo {\n    // ...\n}\n```\n\n* The `#[repr(C)]` attribute can only be placed on structs and enums.\n* The `#[repr(packed)]` and `#[repr(simd)]` attributes only work on structs.\n* The `#[repr(u8)]`, `#[repr(i16)]`, etc attributes only work on enums.\n\nThese attributes do not work on typedefs, since typedefs are just aliases.\n\nRepresentations like `#[repr(u8)]`, `#[repr(i64)]` are for selecting the\ndiscriminant size for enums with no data fields on any of the variants, e.g.\n`enum Color {Red, Blue, Green}`, effectively setting the size of the enum to\nthe size of the provided type. Such an enum can be cast to a value of the same\ntype as well. In short, `#[repr(u8)]` makes the enum behave like an integer\nwith a constrained set of allowed values.\n\nOnly field-less enums can be cast to numerical primitives, so this attribute\nwill not apply to structs.\n\n`#[repr(packed)]` reduces padding to make the struct size smaller. The\nrepresentation of enums isn't strictly defined in Rust, and this attribute\nwon't work on enums.\n\n`#[repr(simd)]` will give a struct consisting of a homogeneous series of machine\ntypes (i.e. `u8`, `i32`, etc) a representation that permits vectorization via\nSIMD. This doesn't make much sense for enums since they don't consist of a\nsingle list of data.\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/attr-usage-repr.rs","byte_start":881,"byte_end":901,"line_start":32,"line_end":32,"column_start":1,"column_end":21,"is_primary":false,"text":[{"text":"enum EAlign { A, B }","highlight_start":1,"highlight_end":21}],"label":"not a struct or union","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/attr-usage-repr.rs","byte_start":821,"byte_end":829,"line_start":31,"line_end":31,"column_start":8,"column_end":16,"is_primary":true,"text":[{"text":"#[repr(align(8))] //~ ERROR: attribute should be applied to struct","highlight_start":8,"highlight_end":16}],"label":null,"suggested_replacement":null,"suggestion_applirs stdout ----
[00:42:54] 
[00:42:54] 1 error[E0565]: unsupported literal
[00:42:54] -   --> $DIR/E0565.rs:14:8
[00:42:54] +   --> $DIR/E0565.rs:12:8
[00:42:54] +   --> $DIR/E0565.rs:12:8
[00:42:54] 3    |
[00:42:54] 4 LL | #[repr("C")] //~ ERROR E0565
[00:42:54] 
[00:42:54] 
[00:42:54] The actual stderr differed from the expected stderr.
[00:42:54] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/error-codes/E0565/E0565.stderr
[00:42:54] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/error-codes/E0565/E0565.stderr
[00:42:54] To update references, rerun the tests and pass the `--bless` flag
[00:42:54] To only update this specific test, also pass `--test-args error-codes/E0565.rs`
[00:42:54] error: 1 errors occurred comparing output.
[00:42:54] status: exit code: 1
[00:42:54] status: exit code: 1
[00:42:54] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/error-codes/E0565.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/error-codes/E0565/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/error-codes/E0565/auxiliary" "-A" "unused"
[00:42:54] ------------------------------------------
[00:42:54] 
[00:42:54] ------------------------------------------
[00:42:54] stderr:
[00:42:54] stderr:
[00:42:54] ------------------------------------------
[00:42:54] {"message":"unsupported literal","code":{"code":"E0565","explanation":"\nA literal was used in a built-in attribute that doesn't support f of stderr:
[00:42:54] 1 error[E0565]: unsupported literal
[00:42:54] -   --> $DIR/E0565-1.rs:14:14
[00:42:54] +   --> $DIR/E0565-1.rs:12:14
[00:42:54] 3    |
[00:42:54] 3    |
[00:42:54] 4 LL | #[deprecated("since")] //~ ERROR E0565
[00:42:54] 
[00:42:54] 
[00:42:54] The actual stderr differed from the expected stderr.
[00:42:54] The actual stderr differed from the expected stderr.
[00:42:54] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/error-codes/E0565-1/E0565-1.stderr
[00:42:54] To update references, rerun the tests and pass the `--bless` flag
[00:42:54] To only update this specific test, also pass `--test-args error-codes/E0565-1.rs`
[00:42:54] error: 1 errors occurred comparing output.
[00:42:54] status: exit code: 1
[00:42:54] status: exit code: 1
[00:42:54] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/error-codes/E0565-1.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/error-codes/E0565-1/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/error-codes/E0565-1/auxiliary" "-A" "unused"
[00:42:54] ------------------------------------------
[00:42:54] 
[00:42:54] ------------------------------------------
[00:42:54] stderr:
[00:42:54] stderr:
[00:42:54] ------------------------------------------
[00:42:54] {"message":"unsupported literal","code":{"code":"E0565","explanation":"\nA literal was used in a built-in attribute that doesn't ue-43925.rs stdout ----
[00:42:54] 
[00:42:54] 
[00:42:54] 1 error: invalid argument for `cfg(..)`
[00:42:54] +   --> $DIR/issue-43925.rs:11:24
[00:42:54] 3    |
[00:42:54] 3    |
[00:42:54] 4 LL | #[link(name="foo", cfg("rlib"))] //~ ERROR invalid argument for `cfg(..)`
[00:42:54] 
[00:42:54] 
[00:42:54] The actual stderr differed from the expected stderr.
[00:42:54] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/issue-43925/issue-43925.stderr
[00:42:54] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/issue-43925/issue-43925.stderr
[00:42:54] To update references, rerun the tests and pass the `--bless` flag
[00:42:54] To only update this specific test, also pass `--test-args issue-43925.rs`
[00:42:54] error: 1 errors occurred comparing output.
[00:42:54] status: exit code: 1
[00:42:54] status: exit code: 1
[00:42:54] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/issue-43925.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/issue-43925/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/issue-43925/auxiliary" "-A" "unused"
[00:42:54] ------------------------------------------
[00:42:54] 
[00:42:54] ------------------------------------------
[00:42:54] stderr:
[00:42:54] stderr:
[00:42:54] ------------------------------------------
[00:42:54] {"message":"invalid argument for `cfg(..)`","code":null,"level":"error "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/parser/expected-comma-found-token/auxiliary" "-A" "unused"
[00:42:54] ------------------------------------------
[00:42:54] 
[00:42:54] ------------------------------------------
[00:42:54] stderr:
[00:42:54] stderr:
[00:42:54] ------------------------------------------
[00:42:54] {"message":"`main` function not found in crate `expected_comma_found_token`","code":{"code":"E0601","explanation":"\nNo `main` function was found in a binary crate. To fix this error, add a\n`main` function. For example:\n\n```\nfn main() {\n    // Your program will start here.\n    println!(\"Hello world!\");\n}\n```\n\nIf you don't know the basics of Rust, you can go look to the Rust Book to get\nstarted: https://doc.rust-lang.org/book/\n"},"level":"error","spans":[],"children":[{"message":"consider adding a `main` function to `/checkout/src/test/ui/parser/expected-comma-found-token.rs`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0601]: `main` function not found in crate `expected_comma_found_token`\n   |\n   = note: consider adding a `main` function to `/checkout/src/test/ui/parser/expected-comma-found-token.rs`\n\n"}
[00:42:54] {"message":"`#[rustc_on_unimplemented]` requires a value","code":{"code":"E0232","explanation":"\nThe `#[rustc_on_unimplemented]` attribute lets you specify a custom error\nmessage for when a particular trait isn't implemented on a type placed in a\nposition that needs that trait. For example, when the forelease/deps
111708 ./obj/build/x86_64-unknown-linux-gnu/stage1-std
107612 ./src/llvm/test/CodeGen
98948 ./obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends
97872 ./obj/build/x86_64-unknown-linux-gnu/stage0-bootstrap-tools/release

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@SergioBenitez
Copy link
Contributor Author

SergioBenitez commented Aug 4, 2018

Whoops! Forgot to update the UI output.

One of the tests is failing for seemingly unrelated reasons:

[00:42:54] thread '[ui] ui/issue-43925.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3149:9
[00:42:54] 
[00:42:54] ---- [ui] ui/parser/expected-comma-found-token.rs stdout ----
[00:42:54] diff of stderr:
[00:42:54] 
[00:42:54] -	error: expected one of `)` or `,`, found `label`
[00:42:54] -	  --> $DIR/expected-comma-found-token.rs:19:5
[00:42:54] +	error[E0601]: `main` function not found in crate `expected_comma_found_token`
[00:42:54] 3	   |
[00:42:54] -	LL |     message="the message"
[00:42:54] -	   |                          - expected one of `)` or `,` here
[00:42:54] -	LL |     label="the label"
[00:42:54] -	   |     ^^^^^ unexpected token
[00:42:54] +	   = note: consider adding a `main` function to `$DIR/expected-comma-found-token.rs`
[00:42:54] 8	
[00:42:54] -	error: aborting due to previous error
[00:42:54] +	error[E0232]: `#[rustc_on_unimplemented]` requires a value
[00:42:54] +	  --> $DIR/expected-comma-found-token.rs:17:1
[00:42:54] +	   |
[00:42:54] +	LL | / #[rustc_on_unimplemented(
[00:42:54] +	LL | |     message="the message"
[00:42:54] +	LL | |     label="the label"
[00:42:54] +	LL | | )]
[00:42:54] +	   | |__^ value required here
[00:42:54] +	   |
[00:42:54] +	   = note: eg `#[rustc_on_unimplemented = "foo"]`
[00:42:54] 10	
[00:42:54] +	error: aborting due to 2 previous errors
[00:42:54] +	
[00:42:54] +	Some errors occurred: E0232, E0601.
[00:42:54] +	For more information about an error, try `rustc --explain E0232`.
[00:42:54] 11	

This is the path that leads to this error:

let result = if let Some(items) = attr.meta_item_list() {
Self::parse(tcx, trait_def_id, &items, attr.span, true).map(Some)
} else if let Some(value) = attr.value_str() {
Ok(Some(OnUnimplementedDirective {
condition: None,
message: None,
subcommands: vec![],
label: Some(OnUnimplementedFormatString::try_parse(
tcx, trait_def_id, value.as_str(), attr.span)?),
note: None,
}))
} else {
return Err(parse_error(tcx, attr.span,
"`#[rustc_on_unimplemented]` requires a value",
"value required here",
Some(r#"eg `#[rustc_on_unimplemented = "foo"]`"#)));
};
debug!("of_item({:?}/{:?}) = {:?}", trait_def_id, impl_def_id, result);
result
}

For some reason, the else branch is being called as opposed to the first branch, as expected. This implies that the attribute's contents aren't parsing as a meta_item_list(). But this PR makes no changes to any parsing code, nor did it change this test, so I'm quite surprised that this is failing.

Taking a closer look now.

Edit: Figured it out! Looks like the feature gate had some code that inadvertently tried to parses every attribute as a meta-item, emitting an error if parsing fails. This means that the rustc_on_unimplemented attribute code never actually runs for this test. The error isn't coming from the rustc_on_unimplemented attribute but instead the feature gated code. This PR removes this code, and so rustc_on_unimplemented does run, returning the "correct" error message.

One potential issue with removing this inadvertent attribute-checking code is that attributes may have been relying on the behavior. This is not the case, however, as all attributes parse the input themselves. Nonetheless, this is a potentially custom-attribute-breaking change.

Turns out nothing else in the compiler checks that attributes look like meta-items, so I've put this back in with an updated comment.

cc @arielb1
cc @estebank

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:40:31] Rustbook (x86_64-unknown-linux-gnu) - nomicon
[00:40:33] Rustbook (x86_64-unknown-linux-gnu) - rustc
[00:40:33] Cargo Book (x86_64-unknown-linux-gnu) - cargo

Broadcast message from root@travis-job-47e4734d-07c4-4c72-bdd9-58a0ea99c3d0
 (unknown) at 2:14 ...
The system is going down for power off NOW!
[00:40:33] 
[00:40:33] Session terminated, terminating shell... ...terminated.
[00:40:33] make: *** wait: No child processes.  Stop.
[00:40:33] make: *** Waiting for unfinished jobs....
[00:40:33] make: *** wait: No child processes.  Stop.

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 143.
travis_time:start:039392b8
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:49:34] ....................................................................................................
[00:49:37] ....................................................................................................
[00:49:39] ....................................................................................................
[00:49:42] ....................................................................................................
[00:49:45] iiiiiiiii...........................................................................................
[00:49:51] ....................................................................................................
[00:49:55] .....i..............................................................................................
[00:49:58] .........i..........................................................................................
[00:50:01] ....................................................................................................
---
[00:56:23] ...................................................ii.iii...........................................
[00:56:26] ...................................................................................i................
[00:56:29] ...........................i........................................................................
[00:56:33] ....................................................................................................
[00:56:37] ........................................................F..i........................................
[00:56:42] ....................................................................................................
[00:56:45] ....................................................................................................
[00:56:48] ....................................................................................................
[00:56:51] ......................................i.............................................................
[00:56:51] ......................................i.............................................................
[00:56:54] ...........................................................F........................................

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:44:29] ....................................................................................................
[00:44:32] ....................................................................................................
[00:44:34] ....................................................................................................
[00:44:37] ....................................................................................................
[00:44:40] iiiiiiiii...........................................................................................
[00:44:46] ....................................................................................................
[00:44:49] .....i..............................................................................................
[00:44:52] ..........i.........................................................................................
[00:44:55] ....................................................................................................
---
travis_time:start:test_run-pass-fulldeps
Check compiletest suite=run-pass-fulldeps mode=run-pass (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[00:52:55] 
[00:52:55] running 96 tests
[00:54:44] ...............................................................F....test [run-pass] run-pass-fulldeps/myriad-closures.rs has been running for over 60 seconds
[00:56:03] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:498:22
[00:56:03] failures:
[00:56:03] 
[00:56:03] ---- [run-pass] run-pass-fulldeps/proc-macro/derive-b.rs stdout ----
[00:56:03] 
[00:56:03] 
[00:56:03] error: compilation failed!
[00:56:03] status: exit code: 1
[00:56:03] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/run-pass-fulldeps/proc-macro/derive-b.rs" "--target=x86_64-unknown-linux-gnu" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass-fulldeps/proc-macro/derive-b/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass-fulldeps/proc-macro/derive-b/auxiliary"
[00:56:03] ------------------------------------------
[00:56:03] 
[00:56:03] ------------------------------------------
[00:56:03] stderr:
[00:56:03] stderr:
[00:56:03] ------------------------------------------
[00:56:03] error: expected one of `(` or `=`, found `arbitrary`
[00:56:03]    |
[00:56:03]    |
[00:56:03] 1  | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
[00:56:03]    | - expected one of `(` or `=` here
[00:56:03] ...
[00:56:03] 19 | #[cfg_attr(all(), B arbitrary tokens)]
[00:56:03]    |                     ^^^^^^^^^ unexpected token
[00:56:03] error: aborting due to previous error
[00:56:03] 
[00:56:03] 
[00:56:03] ------------------------------------------
---
[00:56:03] test result: FAILED. 95 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
[00:56:03] 
[00:56:03] 
[00:56:03] 
[00:56:03] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/run-pass-fulldeps" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass-fulldeps" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "run-pass" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-5.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checko

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@SergioBenitez
Copy link
Contributor Author

SergioBenitez commented Aug 5, 2018

Rather interestingly, this PR has uncovered several issues and inconsistencies in the codebase when it comes to dealing with attributes and determining whether arbitrary tokens are allowed in them.

In particular, in #40346, attribute syntax was expanded to allow for arbitrary tokens as input. This change was not part of any RFC and was made without either a new RFC or a new feature gate. In #40346 (comment), @jseyfried notes that the change should only take affect when proc_macro is enabled. That is, if proc_macro is not enabled, attributes should continue being restricted to meta-items.

The recently stabilization of proc-macro meant that this syntax was also implicitly stabilized, though strangely, the restriction continued being enforced when the attr_literal feature was enabled. I believe this was likely a mistake, and we should continue enforcing meta-items everywhere, at least until a decision is made.

As such, I've decided to add a new feature, arbitrary_attr_input, that enables arbitrary tokens in attributes. When the feature is enabled, attributes can contain any input.

@petrochenkov
Copy link
Contributor

petrochenkov commented Aug 5, 2018

@SergioBenitez

in #40346, attribute syntax was expanded to allow for arbitrary tokens as input ... jseyfried notes that the change should only take affect when proc_macro is enabled.

This is outdated information, #50120 restricted attribute grammar for proc macro (or rather modern proc macro) attributes.

The "literals in attributes" RFC affects only non-macro attributes that are parsed as so called "meta-items" and have a separate very restricted grammar (ident + literal + list of idents/literals/lists).

As I previously mentioned on the tracking issue, the whole situation is mess, but at least stabilization of arbitrary literals in addition to currently stable string literals will not make it worse, but simultaneous support for arbitrary tokens in meta-items certainly will.

@SergioBenitez
Copy link
Contributor Author

SergioBenitez commented Aug 6, 2018

@petrochenkov I'm not sure what you're proposing, if anything.

The situation is that there are tests that assume that arbitrary tokens are allowed and there are tests that check that arbitrary tokens are not allowed. The only way I can see to make both situations work is to have a feature flag that determines when attributes are checked to be meta-items. Are you proposing that there's another way?

Edit: perhaps you're saying that I should change the check to be:

if attr.from_proc_macro() {
    assert_is_meta_item(&attr);
}

That is, allow arbitrary tokens as inputs to non-proc-macro attributes but disallow them as inputs to proc-macro attributes. Is that right?

@michaelwoerister
Copy link
Member

r? @petrochenkov (I think you've got a better handle on this)

@petrochenkov
Copy link
Contributor

petrochenkov commented Aug 6, 2018

@SergioBenitez
I think I misinterpreted you suggestion about adding new feature(arbitrary_attr_input). It's supposed to just replace the current features.use_extern_macros()-based gating, right?

The situation is that there are tests that assume that arbitrary tokens are allowed and there are tests that check that arbitrary tokens are not allowed.

run-pass-fulldeps/proc-macro/derive-b.rs isn't actually supposed to work (even without the meta-item restriction only delimited token streams are allowed: #[attr(arbitrary tokens)] - OK, #[attr arbitrary tokens] - Not OK), it's good that this PR found it.
But if it continues being feature-gated it can be fixed later.

I'm not sure what you're proposing

Ok, now I'm proposing to keep the patch as is, except for restoring the

        if self.context.features.use_extern_macros() && attr::is_known(attr) {
            return
        }

clause.
Other stuff is not really in scope for this PR.

(I'm working on blockers for stabilization of use_extern_macros right now, so I'll fix the attribute grammar issues as well as a part of that work.)

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 6, 2018
@SergioBenitez
Copy link
Contributor Author

Alright, looks like the CI is happy!

@petrochenkov
Copy link
Contributor

r=me after FCP in #34981 is complete.

@petrochenkov petrochenkov added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 7, 2018
@kennytm kennytm added the S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). label Aug 7, 2018
@cramertj
Copy link
Member

@SergioBenitez Now that FCP has completed, we can merge this once you have a chance to rebase! 😄

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Aug 22, 2018
@rust-highfive

This comment has been minimized.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:46:31] ....................................................................................................
[00:46:34] ....................................................................................................
[00:46:36] ....................................................................................................
[00:46:38] ...................................................................................................i
[00:46:41] ..........F........................................................i................................
[00:46:47] ....................................................................................................
[00:46:49] ..............................................i.....................................................
[00:46:52] ....................................................................................................
[00:46:55] ....................................................................................................
---
[00:47:37] ....................................................................................................
[00:47:41] ................i...................................................................................
[00:47:43] ....................................................................................................
[00:47:46] ....................................................................................................
[00:47:50] .................F...............................i..................................................
[00:47:56] ....................................................................................................
[00:47:59] ....................................................................................................
[00:48:00] i............................................................
[00:48:00] failures:
[00:48:00] failures:
[00:48:00] 
[00:48:00] ---- [ui] ui/gated-attr-literals.rs stdout ----
[00:48:00] 
[00:48:00] error: ui test compiled successfully!
[00:48:00] status: exit code: 0
[00:48:00] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/gated-attr-literals.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/gated-attr-literals/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/gated-attr-literals/auxiliary" "-A" "unused"
[00:48:00] ------------------------------------------
[00:48:00] 
[00:48:00] ------------------------------------------
[00:48:00] stderr:
---
[00:48:00] 1 error: suffixed literals are not allowed in attributes
[00:48:00] -   --> $DIR/suffixed-literal-meta.rs:13:10
[00:48:00] +   --> $DIR/suffixed-literal-meta.rs:11:10
[00:48:00] 3    |
[00:48:00] 4 LL | #[path = 1usize] //~ ERROR: suffixed literals are not allowed in attributes
[00:48:00] 
[00:48:00] 
[00:48:00] 7    = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.).
[00:48:00] 9 error: suffixed literals are not allowed in attributes
[00:48:00] -   --> $DIR/suffixed-literal-meta.rs:14:10
[00:48:00] +   --> $DIR/suffixed-literal-meta.rs:12:10
[00:48:00] 11    |
[00:48:00] 11    |
[00:48:00] 12 LL | #[path = 1u8] //~ ERROR: suffixed literals are not allowed in attributes
[00:48:00] 
[00:48:00] 
[00:48:00] 15    = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.).
[00:48:00] 17 error: suffixed literals are not allowed in attributes
[00:48:00] -   --> $DIR/suffixed-literal-meta.rs:15:10
[00:48:00] +   --> $DIR/suffixed-literal-meta.rs:13:10
[00:48:00] 19    |
[00:48:00] 19    |
[00:48:00] 20 LL | #[path = 1u16] //~ ERROR: suffixed literals are not al-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-5.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "5.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[00:48:00] 
[00:48:00] 
[00:48:00] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:48:00] Build completed unsuccessfully in 0:03:06
[00:48:00] Build completed unsuccessfully in 0:03:06
[00:48:00] Makefile:58: recipe for target 'check' failed
[00:48:00] make: *** [check] Error 1

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@SergioBenitez
Copy link
Contributor Author

@cramertj @petrochenkov All's ready!

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 24, 2018

📌 Commit ed0bd38 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 24, 2018
@bors
Copy link
Contributor

bors commented Aug 24, 2018

⌛ Testing commit ed0bd38 with merge 61b0072...

bors added a commit that referenced this pull request Aug 24, 2018
…nkov

Stabilize 'attr_literals' feature.

RFC Issue: rust-lang/rfcs#1559
Tracking Issue: #34981

Reference PR: rust-lang/reference#388.
@bors
Copy link
Contributor

bors commented Aug 24, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing 61b0072 to master...

@bors bors merged commit ed0bd38 into rust-lang:master Aug 24, 2018
@kennytm kennytm added the relnotes Marks issues that should be documented in the release notes of the next release. label Aug 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants