Skip to content

Commit de5228e

Browse files
authored
Rollup merge of #114058 - chenyukang:yukang-fix-113981-crate-arg, r=fmease,oli-obk
Add help for crate arg when crate name is invalid Fixes #113981
2 parents b7a1ff2 + e0c479e commit de5228e

File tree

6 files changed

+31
-3
lines changed

6 files changed

+31
-3
lines changed

compiler/rustc_session/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ session_int_literal_too_large = integer literal is too large
4545
.note = value exceeds limit of `{$limit}`
4646
4747
session_invalid_character_in_create_name = invalid character `{$character}` in crate name: `{$crate_name}`
48+
session_invalid_character_in_create_name_help = you can either pass `--crate-name` on the command line or add `#![crate_name="…"]` to set the crate name
4849
4950
session_invalid_float_literal_suffix = invalid suffix `{$suffix}` for float literal
5051
.label = invalid suffix `{$suffix}`

compiler/rustc_session/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ pub struct InvalidCharacterInCrateName {
199199
pub span: Option<Span>,
200200
pub character: char,
201201
pub crate_name: Symbol,
202+
#[subdiagnostic]
203+
pub crate_name_help: Option<InvalidCrateNameHelp>,
204+
}
205+
206+
#[derive(Subdiagnostic)]
207+
pub enum InvalidCrateNameHelp {
208+
#[help(session_invalid_character_in_create_name_help)]
209+
AddCrateName,
202210
}
203211

204212
#[derive(Subdiagnostic)]

compiler/rustc_session/src/output.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use crate::config::{CrateType, Input, OutFileName, OutputFilenames, OutputType};
33
use crate::errors::{
44
CrateNameDoesNotMatch, CrateNameEmpty, CrateNameInvalid, FileIsNotWriteable,
5-
InvalidCharacterInCrateName,
5+
InvalidCharacterInCrateName, InvalidCrateNameHelp,
66
};
77
use crate::Session;
88
use rustc_ast::{self as ast, attr};
@@ -101,7 +101,16 @@ pub fn validate_crate_name(sess: &Session, s: Symbol, sp: Option<Span>) {
101101
continue;
102102
}
103103
err_count += 1;
104-
sess.emit_err(InvalidCharacterInCrateName { span: sp, character: c, crate_name: s });
104+
sess.emit_err(InvalidCharacterInCrateName {
105+
span: sp,
106+
character: c,
107+
crate_name: s,
108+
crate_name_help: if sp.is_none() {
109+
Some(InvalidCrateNameHelp::AddCrateName)
110+
} else {
111+
None
112+
},
113+
});
105114
}
106115
}
107116

src/tools/tidy/src/ui_tests.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ pub fn check(path: &Path, bad: &mut bool) {
116116
// must strip all of them.
117117
let testname =
118118
file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0;
119-
if !file_path.with_file_name(testname).with_extension("rs").exists() {
119+
if !file_path.with_file_name(testname).with_extension("rs").exists()
120+
&& !testname.contains("ignore-tidy")
121+
{
120122
tidy_error!(bad, "Stray file with UI testing output: {:?}", file_path);
121123
}
122124

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// issue: 113981
2+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: invalid character `'.'` in crate name: `need_crate_arg_ignore_tidy.x`
2+
|
3+
= help: you can either pass `--crate-name` on the command line or add `#![crate_name="…"]` to set the crate name
4+
5+
error: aborting due to previous error
6+

0 commit comments

Comments
 (0)