Rollup merge of #125640 - fmease:plz-no-stringify, r=estebank
Don't suggest turning non-char-literal exprs of ty `char` into string literals Fixes #125595. Fixes #125081. r? estebank (#122217) or compiler
This commit is contained in:
commit
01aa2e8511
6 changed files with 66 additions and 11 deletions
|
@ -2102,10 +2102,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
// If a string was expected and the found expression is a character literal,
|
||||
// perhaps the user meant to write `"s"` to specify a string literal.
|
||||
(ty::Ref(_, r, _), ty::Char) if r.is_str() => {
|
||||
suggestions.push(TypeErrorAdditionalDiags::MeantStrLiteral {
|
||||
start: span.with_hi(span.lo() + BytePos(1)),
|
||||
end: span.with_lo(span.hi() - BytePos(1)),
|
||||
})
|
||||
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
|
||||
&& code.starts_with("'")
|
||||
&& code.ends_with("'")
|
||||
{
|
||||
suggestions.push(TypeErrorAdditionalDiags::MeantStrLiteral {
|
||||
start: span.with_hi(span.lo() + BytePos(1)),
|
||||
end: span.with_lo(span.hi() - BytePos(1)),
|
||||
});
|
||||
}
|
||||
}
|
||||
// For code `if Some(..) = expr `, the type mismatch may be expected `bool` but found `()`,
|
||||
// we try to suggest to add the missing `let` for `if let Some(..) = expr`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue