discord-mods-bot icon indicating copy to clipboard operation
discord-mods-bot copied to clipboard

Add ?clippy command

Open technetos opened this issue 4 years ago • 6 comments

play.rust-lang.org supports running code through clippy. Add this support to the bot so users can run code from discord through clippy.

technetos avatar Dec 26 '20 21:12 technetos

Are the other playground feature (Rusfmt, Miri, Expand macros) desirable as separate commands as well?

kangalio avatar Jan 29 '21 15:01 kangalio

So, expand macros would be awesome. The rest im not convinced are worth doing.

technetos avatar Jan 29 '21 20:01 technetos

A question For regular code execution we have two variants to dictate how the code should be sent to the playground: ?eval and ?play. How should this be handled with the new ?clippy/?expand command?

Some ideas

  1. ?clippyeval and ?expandeval variant
  2. Automatically detect eval vs play mode by checking for the presence of "fn main" in the code
  3. Don't support eval-like execution at all

1 is a bit clunky but functioning, 2 is a bit magic but pleasant to use, 3 is unfortunate because for ?clippy and for example for testing custom macros with ?expand, eval-like functionality would be very convenient. I think I personally prefer 2

Another question Should the bot automatically run rustfmt on the macro-expanded code? Macro-expanded code is notoriously ugly; see this expanded hello world program:

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
fn main() {
    {
        ::std::io::_print(::core::fmt::Arguments::new_v1(&["Hello world\n"],
                                                         &match () {
                                                              () => [],
                                                          }));
    };
}

To avoid the second network request wait (playground is kinda sluggish), rustfmt could be executed locally I think. The computation expense is negligible, though I haven't checked if rustfmt has code execution vulnerabilities or anything like that-

kangalio avatar Feb 01 '21 02:02 kangalio

?clippy should run its own request and have nothing to do with ?play or ?eval. It's a totally separate operation.

Re formatting expansions, I would say sure, but we would need to look to make sure local code execution isn't a problem.

khionu avatar Feb 01 '21 03:02 khionu

?clippy should run its own request and have nothing to do with ?play or ?eval. It's a totally separate operation.

I understand that. I was merely making a comparison to ?play/?eval, asking if the clippy and expand commands should have a similar distinction of evaluation vs plain executing.

Re formatting expansions, I would say sure, but we would need to look to make sure local code execution isn't a problem.

Yeah, as said above, I have the same concerns.

kangalio avatar Feb 01 '21 03:02 kangalio

... if the clippy and expand commands should have a similar distinction of evaluation vs plain executing.

The distinction between play and eval could be removed, but it would require preprocessing that was not worth investing in for the initial iteration of the functionality. The distinction exists strictly for the sake of output handling. There is no variation in how to handle output of clippy or expand.

khionu avatar Feb 01 '21 14:02 khionu