- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
          Update SessionDiagnostic::into_diagnostic to take Handler instead of ParseSess
          #101434
        
          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
          
     Merged
      
      
            bors
  merged 7 commits into
  rust-lang:master
from
JhonnyBillM:replace-session-for-handler-in-into-diagnostic
  
      
      
   
  Sep 6, 2022 
      
    
                
     Merged
            
            
  
    Update SessionDiagnostic::into_diagnostic to take Handler instead of ParseSess
  
  #101434
              
                    bors
  merged 7 commits into
  rust-lang:master
from
JhonnyBillM:replace-session-for-handler-in-into-diagnostic
  
      
      
   
  Sep 6, 2022 
              
            Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    | 
 cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki Some changes occurred in need_type_info.rs cc @lcnr | 
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
Suggested by the team in this Zulip Topic https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20SessionDiagnostic.20on.20Handler Handler already has almost all the capabilities of ParseSess when it comes to diagnostic emission, in this migration we only needed to add the ability to access source_map from the emitter in order to get a Snippet and the start_point. Not sure if this is the best way to address this gap
64df415    to
    d14b3af      
    Compare
  
    
              
                    davidtwco
  
              
              approved these changes
              
                  
                    Sep 6, 2022 
                  
              
              
            
            
| @bors r+ | 
    
  bors 
      added a commit
        to rust-lang-ci/rust
      that referenced
      this pull request
    
      Sep 6, 2022 
    
    
      
  
    
      
    
  
…llaumeGomez Rollup of 7 pull requests Successful merges: - rust-lang#101357 (Include enum path in variant suggestion) - rust-lang#101434 (Update `SessionDiagnostic::into_diagnostic` to take `Handler` instead of `ParseSess`) - rust-lang#101445 (Suggest introducing an explicit lifetime if it does not exist) - rust-lang#101457 (Recover from using `;` as separator between fields) - rust-lang#101462 (Rustdoc-Json: Store Variant Fields as their own item.) - rust-lang#101471 (Report number of delayed bugs properly with `-Ztreat-err-as-bug`) - rust-lang#101473 (Add more size assertions for MIR types.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
      
        
      
      
  
    5 tasks
  
    
  bors 
      added a commit
        to rust-lang-ci/rust
      that referenced
      this pull request
    
      Sep 21, 2022 
    
    
      
  
    
      
    
  
…agnostic-handler-refactor, r=davidtwco Move and rename `SessionDiagnostic` & `SessionSubdiagnostic` traits and macros After PR rust-lang#101434, we want to: - [x] Move `SessionDiagnostic` to `rustc_errors`. - [x] Add `emit_` methods that accept `impl SessionDiagnostic` to `Handler`. - [x] _(optional)_ Rename trait `SessionDiagnostic` to `DiagnosticHandler`. - [x] _(optional)_ Rename macro `SessionDiagnostic` to `DiagnosticHandler`. - [x] Update Rustc Dev Guide and Docs to reflect these changes. rust-lang/rustc-dev-guide#1460 Now I am having build issues getting the compiler to build when trying to rename the macro. <details> <summary>See diagnostics errors and context when building.</summary> ``` error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls --> compiler/rustc_attr/src/session_diagnostics.rs:13:10 | 13 | #[derive(DiagnosticHandler)] | ^^^^^^^^^^^^^^^^^ in this derive macro expansion | ::: /Users/jhonny/.cargo/registry/src/github.com-1ecc6299db9ec823/synstructure-0.12.6/src/macros.rs:94:9 | 94 | / pub fn $derives( 95 | | i: $crate::macros::TokenStream 96 | | ) -> $crate::macros::TokenStream { | |________________________________________- in this expansion of `#[derive(DiagnosticHandler)]` | note: the lint level is defined here --> compiler/rustc_attr/src/lib.rs:10:9 | 10 | #![deny(rustc::diagnostic_outside_of_impl)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` And also this one: ``` error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls --> compiler/rustc_attr/src/session_diagnostics.rs:213:32 | 213 | let mut diag = handler.struct_span_err_with_code( | ^^^^^^^^^^^^^^^^^^^^^^^^^ ``` > **Note** > Can't find where this message is coming from, because you can see in [this experimental branch](https://github.com/JhonnyBillM/rust/tree/experimental/trying-to-rename-session-diagnostic-macro) that I updated all errors and diags to say: > error: diagnostics should only be created in **`DiagnosticHandler`**/`AddSubdiagnostic` impls > and not: > error: diagnostics should only be created in **`SessionDiagnostic`**/`AddSubdiagnostic` impls </details> I tried building the compiler in different ways (playing with the stages etc), but nothing worked. ## Question **Do we need to build or do something different when renaming a macro and identifiers?** For context, see experimental commit JhonnyBillM@f2193a9 where the macro and symbols are renamed, but it doesn't compile.
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      Labels
      
    A-query-system
  Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) 
  
    A-translation
  Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic 
  
    S-waiting-on-bors
  Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 
  
    T-compiler
  Relevant to the compiler team, which will review and decide on the PR/issue. 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Suggested by the team in this Zulip Topic.
Handleralready has almost all the capabilities ofParseSesswhen it comes to diagnostic emission, in this migration we only needed to add the ability to accesssource_mapfrom the emitter in order to get aSnippetand thestart_point. Not sure if adding these two methods [span_to_snippet_from_emitterandspan_start_point_from_emitter] is the best way to address this gap.P.S. If this goes in the right direction, then we probably may want to move
SessionDiagnostictorustc_errorsand rename it toDiagnosticHandleror something similar.r? @davidtwco
r? @compiler-errors