pub message: String,
pub span: MultiSpan,
pub render_span: Option<RenderSpan>,
+ pub list: Vec<String>,
}
impl Diagnostic {
self
}
+ pub fn help_with_list(&mut self , msg: &str, list: Vec<String>) -> &mut Self {
+ self.sub_with_list(Level::Help, msg, MultiSpan::new(), None, list);
+ self
+ }
+
pub fn span_help<S: Into<MultiSpan>>(&mut self,
sp: S,
msg: &str)
message: &str,
span: MultiSpan,
render_span: Option<RenderSpan>) {
+ self.sub_with_list(level, message, span, render_span, vec![]);
+ }
+
+ /// Convenience function for internal use, clients should use one of the
+ /// public methods above.
+ fn sub_with_list(&mut self,
+ level: Level,
+ message: &str,
+ span: MultiSpan,
+ render_span: Option<RenderSpan>,
+ list: Vec<String>) {
let sub = SubDiagnostic {
level: level,
message: message.to_owned(),
span: span,
render_span: render_span,
+ list: list,
};
self.children.push(sub);
}
forward!(pub fn warn(&mut self, msg: &str) -> &mut Self);
forward!(pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self);
forward!(pub fn help(&mut self , msg: &str) -> &mut Self);
+ forward!(pub fn help_with_list(&mut self , msg: &str, list: Vec<String>) -> &mut Self);
forward!(pub fn span_help<S: Into<MultiSpan>>(&mut self,
sp: S,
msg: &str)
.to_string(),
span: MultiSpan::new(),
render_span: None,
+ list: vec![],
});
}
}
}
},
None => {
+ let msg = if child.list.len() == 0 {
+ child.message.to_owned()
+ } else {
+ format!("{}\n{}",
+ &child.message,
+ &child.list.iter().map(|item| {
+ format!("{} - {}",
+ (0..max_line_num_len)
+ .map(|_| " ")
+ .collect::<String>(),
+ item)
+ }).collect::<Vec<String>>()
+ .join("\n"))
+ };
match self.emit_message_default(&child.span,
- &child.message,
+ &msg,
&None,
&child.level,
max_line_num_len,
true) {
Err(e) => panic!("failed to emit error: {}", e),
- _ => ()
+ _ => (),
}
}
}
ast::DUMMY_NODE_ID);
let mut err = self.report_mismatched_types(&cause, expected, expr_ty, e);
if suggestions.len() > 0 {
- err.help(&format!("here are some functions which \
- might fulfill your needs:\n - {}",
- self.get_best_match(&suggestions)));
+ err.help_with_list("here are some functions which might fulfill your needs:",
+ self.get_best_match(&suggestions));
};
err.emit();
}
})
}
- fn display_suggested_methods(&self, methods: &[AssociatedItem]) -> String {
+ fn display_suggested_methods(&self, methods: &[AssociatedItem]) -> Vec<String> {
methods.iter()
.take(5)
.map(|method| self.format_method_suggestion(&*method))
.collect::<Vec<String>>()
- .join("\n - ")
}
- fn get_best_match(&self, methods: &[AssociatedItem]) -> String {
+ fn get_best_match(&self, methods: &[AssociatedItem]) -> Vec<String> {
let no_argument_methods: Vec<_> =
methods.iter()
.filter(|ref x| self.has_no_input_arg(&*x))
= note: expected type `()`
= note: found type `std::result::Result<bool, std::io::Error>`
= help: here are some functions which might fulfill your needs:
- - .unwrap()
- - .unwrap_err()
- - .unwrap_or_default()
+ - .unwrap()
+ - .unwrap_err()
+ - .unwrap_or_default()
error: aborting due to previous error
= note: expected type `usize`
= note: found type `std::string::String`
= help: here are some functions which might fulfill your needs:
- - .capacity()
- - .len()
+ - .capacity()
+ - .len()
error[E0308]: mismatched types
--> $DIR/coerce-suggestions.rs:23:19
= note: expected type `&str`
= note: found type `std::string::String`
= help: here are some functions which might fulfill your needs:
- - .as_str()
- - .trim()
- - .trim_left()
- - .trim_right()
+ - .as_str()
+ - .trim()
+ - .trim_left()
+ - .trim_right()
error[E0308]: mismatched types
--> $DIR/coerce-suggestions.rs:30:10