Skip to content

Commit

Permalink
Rollup merge of rust-lang#105078 - TaKO8Ki:fix-105011, r=nnethercote
Browse files Browse the repository at this point in the history
Fix `expr_to_spanned_string` ICE

Fixes rust-lang#105011
  • Loading branch information
Dylan-DPC committed Dec 1, 2022
2 parents 2377177 + 02eaecc commit 7a7b885
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rustc_errors::{
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics};
use rustc_parse::{self, parser, MACRO_ARGUMENTS};
use rustc_session::errors::report_lit_error;
use rustc_session::{parse::ParseSess, Limit, Session};
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
use rustc_span::edition::Edition;
Expand Down Expand Up @@ -1245,7 +1246,10 @@ pub fn expr_to_spanned_string<'a>(
Some((err, true))
}
Ok(ast::LitKind::Err) => None,
Err(_) => None,
Err(err) => {
report_lit_error(&cx.sess.parse_sess, err, token_lit, expr.span);
None
}
_ => Some((cx.struct_span_err(expr.span, err_msg), false)),
},
ast::ExprKind::Err => None,
Expand Down
10 changes: 3 additions & 7 deletions compiler/rustc_session/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ pub enum UnleashedFeatureHelp {

#[derive(Diagnostic)]
#[diag(session_invalid_literal_suffix)]
pub(crate) struct InvalidLiteralSuffix {
pub(crate) struct InvalidLiteralSuffix<'a> {
#[primary_span]
#[label]
pub span: Span,
// FIXME(#100717)
pub kind: String,
pub kind: &'a str,
pub suffix: Symbol,
}

Expand Down Expand Up @@ -311,11 +311,7 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span:
LitError::LexerError => {}
LitError::InvalidSuffix => {
if let Some(suffix) = suffix {
sess.emit_err(InvalidLiteralSuffix {
span,
kind: format!("{}", kind.descr()),
suffix,
});
sess.emit_err(InvalidLiteralSuffix { span, kind: kind.descr(), suffix });
}
}
LitError::InvalidIntSuffix => {
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/macros/issue-105011.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!(""y); //~ ERROR suffixes on string literals are invalid
}
8 changes: 8 additions & 0 deletions src/test/ui/macros/issue-105011.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: suffixes on string literals are invalid
--> $DIR/issue-105011.rs:2:14
|
LL | println!(""y);
| ^^^ invalid suffix `y`

error: aborting due to previous error

0 comments on commit 7a7b885

Please sign in to comment.