- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
bootstrap: emit hint if a config key is used in the wrong section #146611
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
bootstrap: emit hint if a config key is used in the wrong section #146611
Conversation
| This PR modifies  If appropriate, please update  | 
e85f09f    to
    2593762      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation is so hacky I don't even want to look at it 😆 But since this is just a best effort hint, and doesn't affect the rest of the codebase, I'm fine with it. Left one nit. Thank you!
| } | ||
|  | ||
| fn find_correct_section_for_field(field_name: &str) -> Vec<&'static str> { | ||
| let sections = ["<top level>", "build", "install", "llvm", "gcc", "rust", "dist"]; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually have a field named build, so for that this heuristic wouldn't work, but that's not so important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code could easily be generalized to detect when a section name is also valid as a key in a given section, but the problem is I have no idea what a good diagnostic to print in that case would be.
| alright, made the code more robust with an enum, and also made keys like  
 | 
2593762    to
    fed721c      
    Compare
  
    | Some manual testing: [rust]
full-bootstrap = true # hint: try moving `full-bootstrap` to the `build` section => awesome hint! really magical[rust]
build.full-bootstrap = true # hint: `build` would be valid in section `build`, or at top level => a bit confusing, as it doesn't mention full-bootstrap`, which is the more important part[build]
build.full-bootstrap = true # ERROR: Failed to parse '/projects/personal/rust/rust/bootstrap.toml': invalid type: map, expected a string for key `build.build` # I wonder why this wasn't causing this error in the original issue that motivated this PR? | 
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
| unfortunately for the last two there's not much that can be easily done without majorly increasing complexity, as the error we get from the  | 
fed721c    to
    9c42379      
    Compare
  
    | Yeah, agreed! Thank you. @bors r+ rollup | 
Rollup of 5 pull requests Successful merges: - #146442 (Display ?Sized, const, and lifetime parameters in trait item suggestions across a crate boundary) - #146474 (Improve `core::ascii` coverage) - #146605 (Bump rustfix 0.8.1 -> 0.8.7) - #146611 (bootstrap: emit hint if a config key is used in the wrong section) - #146618 (Do not run ui test if options specific to LLVM are used when another codegen backend is used) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #146611 - lolbinarycat:bootstrap-toml-wrong-section-diagnostic, r=Kobzol bootstrap: emit hint if a config key is used in the wrong section based on discussion on #146591 now, if the user puts `build.download-rustc` in `bootstrap.toml`, they'll get a diagnostic: ``hint: try moving `download-rustc` to the `rust` section`` and if they nest things too much (`rust.rust.download-rustc`): ``hint: section name `rust` used as a key within a section`` if they specify a top-level key within a section (`rust.profile`): ``hint: try using `profile` as a top level key`` r? `@Kobzol`
based on discussion on #146591
now, if the user puts
build.download-rustcinbootstrap.toml, they'll get a diagnostic:hint: try moving `download-rustc` to the `rust` sectionand if they nest things too much (
rust.rust.download-rustc):hint: section name `rust` used as a key within a sectionif they specify a top-level key within a section (
rust.profile):hint: try using `profile` as a top level keyr? @Kobzol