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

Improve logging of capture analysis #78213

Closed
wants to merge 6 commits into from

Conversation

roxelo
Copy link
Member

@roxelo roxelo commented Oct 22, 2020

This PR aims to improve the logging of capture analysis by reducing the verbosity of the logs.

For instance, consider the following test case: src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.rs

Previously, the logs would have outputted the following to stdout:

For closure=DefId(0:4 ~ simple_struct_min_capture[317d]::main::{closure#0}): Using new-style capture analysis
For closure=DefId(0:4 ~ simple_struct_min_capture[317d]::main::{closure#0}): capture information: {
    Place {
        base_ty: Point,
        base: Upvar(
            UpvarId(HirId { owner: DefId(0:3 ~ simple_struct_min_capture[317d]::main), local_id: 1 };`p`;DefId(0:4 ~ simple_struct_min_capture[317d]::main::{closure#0})),
        ),
        projections: [
            Projection {
                ty: i32,
                kind: Field(
                    0,
                    0,
                ),
            },
        ],
    }: CaptureInfo {
        expr_id: Some(
            HirId {
                owner: DefId(0:3 ~ simple_struct_min_capture[317d]::main),
                local_id: 15,
            },
        ),
        capture_kind: ByRef(
            UpvarBorrow(MutBorrow, '_#34r),
        ),
    },
    Place {
        base_ty: Point,
        base: Upvar(
            UpvarId(HirId { owner: DefId(0:3 ~ simple_struct_min_capture[317d]::main), local_id: 1 };`p`;DefId(0:4 ~ simple_struct_min_capture[317d]::main::{closure#0})),
        ),
        projections: [],
    }: CaptureInfo {
        expr_id: Some(
            HirId {
                owner: DefId(0:3 ~ simple_struct_min_capture[317d]::main),
                local_id: 35,
            },
        ),
        capture_kind: ByRef(
            UpvarBorrow(ImmBorrow, '_#35r),
        ),
    },
}

and the following to stderr:

error[E0658]: attributes on expressions are experimental
  --> $DIR/simple-struct-min-capture.rs:25:17
   |
LL |     let mut c = #[rustc_capture_analysis]
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
   = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
  --> $DIR/simple-struct-min-capture.rs:3:12
   |
LL | #![feature(capture_disjoint_fields)]
   |            ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(incomplete_features)]` on by default
   = note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information

error: aborting due to previous error; 1 warning emitted

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

After the changes, the following is being outputted to stderr:

error[E0658]: attributes on expressions are experimental
  --> src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.rs:25:17
   |
25 |     let mut c = #[rustc_capture_analysis]
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
   = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.rs:3:12
  |
3 | #![feature(capture_disjoint_fields)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information

For closure=DefId(0:4 ~ simple_struct_min_capture[317d]::main::{closure#0}): Using new-style capture analysis
error: Capturing p[(0, 0)] -> MutBorrow
  --> src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.rs:28:9
   |
28 |         p.x += 10;
   |         ^^^

error: Capturing p[] -> ImmBorrow
  --> src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.rs:29:26
   |
29 |         println!("{:?}", p);
   |                          ^

error: aborting due to 3 previous errors; 1 warning emitted

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

Closes rust-lang/project-rfc-2229#19

arora-aman and others added 6 commits October 16, 2020 22:46
Co-authored-by: Archer Zhang <archer.xn@gmail.com>
Signed-off-by: Aman Arora <me@aman-arora.com>
Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
Co-authored-by: Jenny Wills <wills.jenniferg@gmail.com>
@rust-highfive
Copy link
Collaborator

r? @davidtwco

(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 Oct 22, 2020
@roxelo roxelo closed this Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve logging of capture analysis
4 participants