Use enum for approximate suggestions
This commit is contained in:
parent
f5203d1073
commit
b9c44ebd3f
4 changed files with 29 additions and 15 deletions
|
@ -11,6 +11,7 @@
|
||||||
use CodeSuggestion;
|
use CodeSuggestion;
|
||||||
use SubstitutionPart;
|
use SubstitutionPart;
|
||||||
use Substitution;
|
use Substitution;
|
||||||
|
use SuggestionApproximate;
|
||||||
use Level;
|
use Level;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use syntax_pos::{MultiSpan, Span};
|
use syntax_pos::{MultiSpan, Span};
|
||||||
|
@ -222,7 +223,7 @@ impl Diagnostic {
|
||||||
}],
|
}],
|
||||||
msg: msg.to_owned(),
|
msg: msg.to_owned(),
|
||||||
show_code_when_inline: false,
|
show_code_when_inline: false,
|
||||||
approximate: false,
|
approximate: SuggestionApproximate::Unspecified,
|
||||||
});
|
});
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -253,7 +254,7 @@ impl Diagnostic {
|
||||||
}],
|
}],
|
||||||
msg: msg.to_owned(),
|
msg: msg.to_owned(),
|
||||||
show_code_when_inline: true,
|
show_code_when_inline: true,
|
||||||
approximate: false,
|
approximate: SuggestionApproximate::Unspecified,
|
||||||
});
|
});
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -269,7 +270,7 @@ impl Diagnostic {
|
||||||
}).collect(),
|
}).collect(),
|
||||||
msg: msg.to_owned(),
|
msg: msg.to_owned(),
|
||||||
show_code_when_inline: true,
|
show_code_when_inline: true,
|
||||||
approximate: false,
|
approximate: SuggestionApproximate::Unspecified,
|
||||||
});
|
});
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -277,7 +278,8 @@ impl Diagnostic {
|
||||||
/// This is a suggestion that may contain mistakes or fillers and should
|
/// This is a suggestion that may contain mistakes or fillers and should
|
||||||
/// be read and understood by a human.
|
/// be read and understood by a human.
|
||||||
pub fn span_approximate_suggestion(&mut self, sp: Span, msg: &str,
|
pub fn span_approximate_suggestion(&mut self, sp: Span, msg: &str,
|
||||||
suggestion: String) -> &mut Self {
|
suggestion: String,
|
||||||
|
approximate: SuggestionApproximate) -> &mut Self {
|
||||||
self.suggestions.push(CodeSuggestion {
|
self.suggestions.push(CodeSuggestion {
|
||||||
substitutions: vec![Substitution {
|
substitutions: vec![Substitution {
|
||||||
parts: vec![SubstitutionPart {
|
parts: vec![SubstitutionPart {
|
||||||
|
@ -287,13 +289,14 @@ impl Diagnostic {
|
||||||
}],
|
}],
|
||||||
msg: msg.to_owned(),
|
msg: msg.to_owned(),
|
||||||
show_code_when_inline: true,
|
show_code_when_inline: true,
|
||||||
approximate: true,
|
approximate,
|
||||||
});
|
});
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn span_approximate_suggestions(&mut self, sp: Span, msg: &str,
|
pub fn span_approximate_suggestions(&mut self, sp: Span, msg: &str,
|
||||||
suggestions: Vec<String>) -> &mut Self {
|
suggestions: Vec<String>,
|
||||||
|
approximate: SuggestionApproximate) -> &mut Self {
|
||||||
self.suggestions.push(CodeSuggestion {
|
self.suggestions.push(CodeSuggestion {
|
||||||
substitutions: suggestions.into_iter().map(|snippet| Substitution {
|
substitutions: suggestions.into_iter().map(|snippet| Substitution {
|
||||||
parts: vec![SubstitutionPart {
|
parts: vec![SubstitutionPart {
|
||||||
|
@ -303,7 +306,7 @@ impl Diagnostic {
|
||||||
}).collect(),
|
}).collect(),
|
||||||
msg: msg.to_owned(),
|
msg: msg.to_owned(),
|
||||||
show_code_when_inline: true,
|
show_code_when_inline: true,
|
||||||
approximate: true,
|
approximate,
|
||||||
});
|
});
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
use Diagnostic;
|
use Diagnostic;
|
||||||
use DiagnosticId;
|
use DiagnosticId;
|
||||||
use DiagnosticStyledString;
|
use DiagnosticStyledString;
|
||||||
|
use SuggestionApproximate;
|
||||||
|
|
||||||
use Level;
|
use Level;
|
||||||
use Handler;
|
use Handler;
|
||||||
|
@ -190,12 +191,14 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||||
forward!(pub fn span_approximate_suggestion(&mut self,
|
forward!(pub fn span_approximate_suggestion(&mut self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
suggestion: String)
|
suggestion: String,
|
||||||
|
approximate: SuggestionApproximate)
|
||||||
-> &mut Self);
|
-> &mut Self);
|
||||||
forward!(pub fn span_approximate_suggestions(&mut self,
|
forward!(pub fn span_approximate_suggestions(&mut self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
suggestions: Vec<String>)
|
suggestions: Vec<String>,
|
||||||
|
approximate: SuggestionApproximate)
|
||||||
-> &mut Self);
|
-> &mut Self);
|
||||||
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self);
|
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self);
|
||||||
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
|
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
|
||||||
|
|
|
@ -56,6 +56,14 @@ mod lock;
|
||||||
|
|
||||||
use syntax_pos::{BytePos, Loc, FileLinesResult, FileMap, FileName, MultiSpan, Span, NO_EXPANSION};
|
use syntax_pos::{BytePos, Loc, FileLinesResult, FileMap, FileName, MultiSpan, Span, NO_EXPANSION};
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
|
||||||
|
pub enum SuggestionApproximate {
|
||||||
|
MachineApplicable,
|
||||||
|
HasPlaceholders,
|
||||||
|
MaybeIncorrect,
|
||||||
|
Unspecified
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
|
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
|
||||||
pub struct CodeSuggestion {
|
pub struct CodeSuggestion {
|
||||||
/// Each substitute can have multiple variants due to multiple
|
/// Each substitute can have multiple variants due to multiple
|
||||||
|
@ -87,7 +95,7 @@ pub struct CodeSuggestion {
|
||||||
/// Sometimes we may show suggestions with placeholders,
|
/// Sometimes we may show suggestions with placeholders,
|
||||||
/// which are useful for users but not useful for
|
/// which are useful for users but not useful for
|
||||||
/// tools like rustfix
|
/// tools like rustfix
|
||||||
pub approximate: bool,
|
pub approximate: SuggestionApproximate,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
|
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
|
||||||
|
|
|
@ -23,7 +23,7 @@ use codemap::{CodeMap, FilePathMapping};
|
||||||
use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan};
|
use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan};
|
||||||
use errors::registry::Registry;
|
use errors::registry::Registry;
|
||||||
use errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, CodeMapper};
|
use errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, CodeMapper};
|
||||||
use errors::DiagnosticId;
|
use errors::{DiagnosticId, SuggestionApproximate};
|
||||||
use errors::emitter::{Emitter, EmitterWriter};
|
use errors::emitter::{Emitter, EmitterWriter};
|
||||||
|
|
||||||
use rustc_data_structures::sync::{self, Lrc};
|
use rustc_data_structures::sync::{self, Lrc};
|
||||||
|
@ -138,7 +138,7 @@ struct DiagnosticSpan {
|
||||||
suggested_replacement: Option<String>,
|
suggested_replacement: Option<String>,
|
||||||
/// If the suggestion is approximate
|
/// If the suggestion is approximate
|
||||||
#[rustc_serialize_exclude_null]
|
#[rustc_serialize_exclude_null]
|
||||||
suggestion_approximate: Option<bool>,
|
suggestion_approximate: Option<SuggestionApproximate>,
|
||||||
/// Macro invocations that created the code at this span, if any.
|
/// Macro invocations that created the code at this span, if any.
|
||||||
expansion: Option<Box<DiagnosticSpanMacroExpansion>>,
|
expansion: Option<Box<DiagnosticSpanMacroExpansion>>,
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ impl Diagnostic {
|
||||||
|
|
||||||
impl DiagnosticSpan {
|
impl DiagnosticSpan {
|
||||||
fn from_span_label(span: SpanLabel,
|
fn from_span_label(span: SpanLabel,
|
||||||
suggestion: Option<(&String, bool)>,
|
suggestion: Option<(&String, SuggestionApproximate)>,
|
||||||
je: &JsonEmitter)
|
je: &JsonEmitter)
|
||||||
-> DiagnosticSpan {
|
-> DiagnosticSpan {
|
||||||
Self::from_span_etc(span.span,
|
Self::from_span_etc(span.span,
|
||||||
|
@ -252,7 +252,7 @@ impl DiagnosticSpan {
|
||||||
fn from_span_etc(span: Span,
|
fn from_span_etc(span: Span,
|
||||||
is_primary: bool,
|
is_primary: bool,
|
||||||
label: Option<String>,
|
label: Option<String>,
|
||||||
suggestion: Option<(&String, bool)>,
|
suggestion: Option<(&String, SuggestionApproximate)>,
|
||||||
je: &JsonEmitter)
|
je: &JsonEmitter)
|
||||||
-> DiagnosticSpan {
|
-> DiagnosticSpan {
|
||||||
// obtain the full backtrace from the `macro_backtrace`
|
// obtain the full backtrace from the `macro_backtrace`
|
||||||
|
@ -272,7 +272,7 @@ impl DiagnosticSpan {
|
||||||
fn from_span_full(span: Span,
|
fn from_span_full(span: Span,
|
||||||
is_primary: bool,
|
is_primary: bool,
|
||||||
label: Option<String>,
|
label: Option<String>,
|
||||||
suggestion: Option<(&String, bool)>,
|
suggestion: Option<(&String, SuggestionApproximate)>,
|
||||||
mut backtrace: vec::IntoIter<MacroBacktrace>,
|
mut backtrace: vec::IntoIter<MacroBacktrace>,
|
||||||
je: &JsonEmitter)
|
je: &JsonEmitter)
|
||||||
-> DiagnosticSpan {
|
-> DiagnosticSpan {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue