1- // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2- // file at the top-level directory of this distribution and at
3- // http://rust-lang.org/COPYRIGHT.
4- //
5- // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6- // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7- // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8- // option. This file may not be copied, modified, or distributed
9- // except according to those terms.
10-
111//! Conversion of raw rustc-emitted JSON messages into LSP diagnostics.
122//!
133//! Data definitions for diagnostics can be found in the Rust compiler for:
14- //! 1. Internal diagnostics at src/librustc_errors/diagnostic.rs.
15- //! 2. Emitted JSON format at src/libsyntax/json.rs.
4+ //! 1. Internal diagnostics at ` src/librustc_errors/diagnostic.rs` .
5+ //! 2. Emitted JSON format at ` src/libsyntax/json.rs` .
166
177use std:: collections:: HashMap ;
188use std:: iter;
@@ -98,7 +88,8 @@ pub fn parse_diagnostics(
9888
9989 let mut diagnostics = HashMap :: new ( ) ;
10090
101- // If the client doesn't support related information, emit separate diagnostics for secondary spans
91+ // If the client doesn't support related information, emit separate diagnostics for
92+ // secondary spans.
10293 let diagnostic_spans = if related_information_support { & primaries } else { & message. spans } ;
10394
10495 for ( path, diagnostic) in diagnostic_spans. iter ( ) . map ( |span| {
@@ -131,8 +122,8 @@ pub fn parse_diagnostics(
131122
132123 let rls_span = {
133124 let mut span = span;
134- // if span points to a macro, search through the expansions
135- // for a more useful source location
125+ // If span points to a macro, search through the expansions
126+ // for a more useful source location.
136127 while span. file_name . ends_with ( " macros>" ) && span. expansion . is_some ( ) {
137128 span = & span. expansion . as_ref ( ) . unwrap ( ) . span ;
138129 }
@@ -244,8 +235,8 @@ fn make_suggestions<'a>(
244235 . collect ( ) ;
245236
246237 // Suggestions are displayed at primary span, so if the change is somewhere
247- // else, be sure to specify that
248- // TODO: In theory this can even point to different files - does that happen in practice?
238+ // else, be sure to specify that.
239+ // TODO: In theory this can even point to different files -- does that happen in practice?
249240 for suggestion in & mut suggestions {
250241 if !suggestion. range . is_within ( & primary_range) {
251242 let line = suggestion. range . start . line + 1 ; // as 1-based
@@ -275,7 +266,7 @@ fn label_suggestion(span: &DiagnosticSpan, label: &str) -> Option<Suggestion> {
275266
276267trait IsWithin {
277268 /// Returns whether `other` is considered within `self`
278- /// note : a thing should be 'within' itself
269+ /// NOTE : a thing should be 'within' itself.
279270 fn is_within ( & self , other : & Self ) -> bool ;
280271}
281272
@@ -304,9 +295,9 @@ impl IsWithin for Range {
304295 }
305296}
306297
307- /// Tests for formatted messages from the compilers json output
308- /// run cargo with `--message-format=json` to generate the json for new tests and add .json
309- /// message files to ' $FIXTURES_DIR/compiler_message/'
298+ /// Tests for formatted messages from the compiler's JSON output.
299+ /// Runs cargo with `--message-format=json` to generate the JSON for new tests and add JSON
300+ /// message files to the ` $FIXTURES_DIR/compiler_message/` directory.
310301#[ cfg( test) ]
311302mod diagnostic_message_test {
312303 use super :: * ;
@@ -332,7 +323,7 @@ mod diagnostic_message_test {
332323
333324 pub ( super ) trait FileDiagnosticTestExt {
334325 fn single_file_results ( & self ) -> & Vec < ( Diagnostic , Vec < Suggestion > ) > ;
335- /// Returns (primary message, secondary messages)
326+ /// Returns ` (primary message, secondary messages)`.
336327 fn to_messages ( & self ) -> Vec < ( String , Vec < String > ) > ;
337328 fn to_primary_messages ( & self ) -> Vec < String > ;
338329 fn to_secondary_messages ( & self ) -> Vec < String > ;
@@ -419,7 +410,7 @@ mod diagnostic_message_test {
419410 assert_eq ! ( messages[ 0 ] . 1 , vec![ "consider giving `v` a type" , "cannot infer type for `T`" ] ) ;
420411
421412 // Check if we don't emit related information if it's not supported and
422- // if secondary spans are emitted as separate diagnostics
413+ // if secondary spans are emitted as separate diagnostics.
423414 let messages = parse_compiler_message (
424415 & read_fixture ( "compiler_message/type-annotations-needed.json" ) ,
425416 false ,
@@ -477,7 +468,7 @@ mod diagnostic_message_test {
477468 cannot borrow mutably",
478469 ) ;
479470
480- // note: consider message becomes a suggestion
471+ // NOTE: ' consider' message becomes a suggestion.
481472 assert_eq ! (
482473 messages[ 0 ] . 1 ,
483474 vec![ "consider changing this to `mut string`" , "cannot borrow mutably" , ]
@@ -675,7 +666,7 @@ help: consider borrowing here: `&string`"#,
675666 }
676667}
677668
678- /// Tests for creating suggestions from the compilers json output
669+ /// Tests for creating suggestions from the compilers JSON output.
679670#[ cfg( test) ]
680671mod diagnostic_suggestion_test {
681672 use self :: diagnostic_message_test:: * ;
0 commit comments