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

Add possibility to request compiler's JSON output #257

Open
panicbit opened this issue Feb 8, 2018 · 3 comments
Open

Add possibility to request compiler's JSON output #257

panicbit opened this issue Feb 8, 2018 · 3 comments
Labels
enhancement Something new the playground could do

Comments

@panicbit
Copy link
Contributor

panicbit commented Feb 8, 2018

With the JSON output it would be possible to reorder / tweak messages if needed.
E.g. my IRC bot could use it to prefer showing error messages instead of warnings.

@shepmaster shepmaster changed the title Add possibilty to request compiler's json output Add possibility to request compiler's JSON output Feb 8, 2018
@shepmaster shepmaster added the enhancement Something new the playground could do label Feb 8, 2018
@shepmaster
Copy link
Member

Do you know how stable the output of the JSON format is? It might be better for the playground itself to use it, instead of scraping the stdout/stderr. Then the next thing would be to figure out how to expose it.

As a heads-up, the /meta/version/ route has no stability guarantees as it's not intended for public use. the /execute route is (unfortunately) stable because so much relies on it. So stable, in fact, that I'd be pretty hesitant to even add fields to it!

@panicbit
Copy link
Contributor Author

panicbit commented Feb 8, 2018

I'm not sure how stable the output format is, but the compiler let's you use it on the stable channel, so I hope it is? 🤞
At any rate, here's what cargo/rustc outputs for the code given in the linked issue (quite verbose IMO):

{
  "message": {
    "children": [
      {
        "children": [],
        "code": null,
        "level": "note",
        "message": "#[warn(dead_code)] on by default",
        "rendered": null,
        "spans": []
      }
    ],
    "code": {
      "code": "dead_code",
      "explanation": null
    },
    "level": "warning",
    "message": "static item is never used: `X`",
    "rendered": null,
    "spans": [
      {
        "byte_end": 40,
        "byte_start": 16,
        "column_end": 29,
        "column_start": 5,
        "expansion": null,
        "file_name": "src/main.rs",
        "is_primary": true,
        "label": null,
        "line_end": 2,
        "line_start": 2,
        "suggested_replacement": null,
        "text": [
          {
            "highlight_end": 29,
            "highlight_start": 5,
            "text": "    static X: u8 = [1,2][4];"
          }
        ]
      }
    ]
  },
  "package_id": "foo 0.1.0 (path+file:///tmp/foo)",
  "reason": "compiler-message",
  "target": {
    "crate_types": [
      "bin"
    ],
    "kind": [
      "bin"
    ],
    "name": "foo",
    "src_path": "/tmp/foo/src/main.rs"
  }
}
{
  "message": {
    "children": [],
    "code": {
      "code": "E0080",
      "explanation": "\nThis error indicates that the compiler was unable to sensibly evaluate an\nconstant expression that had to be evaluated. Attempting to divide by 0\nor causing integer overflow are two ways to induce this error. For example:\n\n```compile_fail,E0080\nenum Enum {\n    X = (1 << 500),\n    Y = (1 / 0)\n}\n```\n\nEnsure that the expressions given can be evaluated as the desired integer type.\nSee the FFI section of the Reference for more information about using a custom\ninteger type:\n\nhttps://doc.rust-lang.org/reference.html#ffi-attributes\n"
    },
    "level": "error",
    "message": "constant evaluation error",
    "rendered": null,
    "spans": [
      {
        "byte_end": 39,
        "byte_start": 31,
        "column_end": 28,
        "column_start": 20,
        "expansion": null,
        "file_name": "src/main.rs",
        "is_primary": true,
        "label": "index out of bounds: the len is 2 but the index is 4",
        "line_end": 2,
        "line_start": 2,
        "suggested_replacement": null,
        "text": [
          {
            "highlight_end": 28,
            "highlight_start": 20,
            "text": "    static X: u8 = [1,2][4];"
          }
        ]
      }
    ]
  },
  "package_id": "foo 0.1.0 (path+file:///tmp/foo)",
  "reason": "compiler-message",
  "target": {
    "crate_types": [
      "bin"
    ],
    "kind": [
      "bin"
    ],
    "name": "foo",
    "src_path": "/tmp/foo/src/main.rs"
  }
}

@panicbit
Copy link
Contributor Author

panicbit commented Feb 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something new the playground could do
Projects
None yet
Development

No branches or pull requests

2 participants