@@ -630,6 +630,19 @@ impl GetOptsOptions {
630630 options. emit_mode = Some ( emit_mode_from_emit_str ( emit_str) ?) ;
631631 }
632632
633+ if options. inline_config . contains_key ( "emit_mode" ) {
634+ if options. check {
635+ return Err ( format_err ! (
636+ "Invalid to use `--config=emit_mode=<mode>` and `--check`"
637+ ) ) ;
638+ }
639+ if options. emit_mode . is_some ( ) {
640+ return Err ( format_err ! (
641+ "Invalid to use `--config=emit_mode=<mode>` and `--emit`"
642+ ) ) ;
643+ }
644+ }
645+
633646 if let Some ( ref edition_str) = matches. opt_str ( "edition" ) {
634647 options. edition = Some ( edition_from_edition_str ( edition_str) ?) ;
635648 }
@@ -826,6 +839,37 @@ mod test {
826839 assert_eq ! ( config. style_edition( ) , StyleEdition :: Edition2024 ) ;
827840 }
828841
842+ #[ test]
843+ fn emit_mode_from_inline_config_is_rejected ( ) {
844+ // Regression for #6999.
845+ let emit_modes = [
846+ "Files" ,
847+ "Stdout" ,
848+ "Coverage" ,
849+ "Checkstyle" ,
850+ "Json" ,
851+ "ModifiedLines" ,
852+ "Diff" ,
853+ ] ;
854+ for mode in emit_modes {
855+ let config = format ! ( "emit_mode={mode}" ) ;
856+
857+ let matches = make_opts ( ) . parse ( [ "--check" , "--config" , & config] ) . unwrap ( ) ;
858+ assert ! (
859+ GetOptsOptions :: from_matches( & matches) . is_err( ) ,
860+ "`--check` with `--config={config}` should be rejected"
861+ ) ;
862+
863+ let matches = make_opts ( )
864+ . parse ( [ "--emit" , "stdout" , "--config" , & config] )
865+ . unwrap ( ) ;
866+ assert ! (
867+ GetOptsOptions :: from_matches( & matches) . is_err( ) ,
868+ "`--emit` with `--config={config}` should be rejected"
869+ ) ;
870+ }
871+ }
872+
829873 #[ nightly_only_test]
830874 #[ test]
831875 fn version_config_file_sets_style_edition_override_correctly ( ) {
0 commit comments