Skip to content

Commit 741f8c9

Browse files
authored
Rollup merge of #105078 - TaKO8Ki:fix-105011, r=nnethercote
Fix `expr_to_spanned_string` ICE Fixes #105011
2 parents d6c4de0 + 02eaecc commit 741f8c9

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

compiler/rustc_expand/src/base.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_errors::{
1616
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
1717
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics};
1818
use rustc_parse::{self, parser, MACRO_ARGUMENTS};
19+
use rustc_session::errors::report_lit_error;
1920
use rustc_session::{parse::ParseSess, Limit, Session};
2021
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
2122
use rustc_span::edition::Edition;
@@ -1245,7 +1246,10 @@ pub fn expr_to_spanned_string<'a>(
12451246
Some((err, true))
12461247
}
12471248
Ok(ast::LitKind::Err) => None,
1248-
Err(_) => None,
1249+
Err(err) => {
1250+
report_lit_error(&cx.sess.parse_sess, err, token_lit, expr.span);
1251+
None
1252+
}
12491253
_ => Some((cx.struct_span_err(expr.span, err_msg), false)),
12501254
},
12511255
ast::ExprKind::Err => None,

compiler/rustc_session/src/errors.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ pub enum UnleashedFeatureHelp {
197197

198198
#[derive(Diagnostic)]
199199
#[diag(session_invalid_literal_suffix)]
200-
pub(crate) struct InvalidLiteralSuffix {
200+
pub(crate) struct InvalidLiteralSuffix<'a> {
201201
#[primary_span]
202202
#[label]
203203
pub span: Span,
204204
// FIXME(#100717)
205-
pub kind: String,
205+
pub kind: &'a str,
206206
pub suffix: Symbol,
207207
}
208208

@@ -311,11 +311,7 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span:
311311
LitError::LexerError => {}
312312
LitError::InvalidSuffix => {
313313
if let Some(suffix) = suffix {
314-
sess.emit_err(InvalidLiteralSuffix {
315-
span,
316-
kind: format!("{}", kind.descr()),
317-
suffix,
318-
});
314+
sess.emit_err(InvalidLiteralSuffix { span, kind: kind.descr(), suffix });
319315
}
320316
}
321317
LitError::InvalidIntSuffix => {

src/test/ui/macros/issue-105011.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!(""y); //~ ERROR suffixes on string literals are invalid
3+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: suffixes on string literals are invalid
2+
--> $DIR/issue-105011.rs:2:14
3+
|
4+
LL | println!(""y);
5+
| ^^^ invalid suffix `y`
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)