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
This commit is contained in:
commit
de5228e489
6 changed files with 31 additions and 3 deletions
|
@ -45,6 +45,7 @@ session_int_literal_too_large = integer literal is too large
|
||||||
.note = value exceeds limit of `{$limit}`
|
.note = value exceeds limit of `{$limit}`
|
||||||
|
|
||||||
session_invalid_character_in_create_name = invalid character `{$character}` in crate name: `{$crate_name}`
|
session_invalid_character_in_create_name = invalid character `{$character}` in crate name: `{$crate_name}`
|
||||||
|
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
|
||||||
|
|
||||||
session_invalid_float_literal_suffix = invalid suffix `{$suffix}` for float literal
|
session_invalid_float_literal_suffix = invalid suffix `{$suffix}` for float literal
|
||||||
.label = invalid suffix `{$suffix}`
|
.label = invalid suffix `{$suffix}`
|
||||||
|
|
|
@ -199,6 +199,14 @@ pub struct InvalidCharacterInCrateName {
|
||||||
pub span: Option<Span>,
|
pub span: Option<Span>,
|
||||||
pub character: char,
|
pub character: char,
|
||||||
pub crate_name: Symbol,
|
pub crate_name: Symbol,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub crate_name_help: Option<InvalidCrateNameHelp>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
pub enum InvalidCrateNameHelp {
|
||||||
|
#[help(session_invalid_character_in_create_name_help)]
|
||||||
|
AddCrateName,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
use crate::config::{CrateType, Input, OutFileName, OutputFilenames, OutputType};
|
use crate::config::{CrateType, Input, OutFileName, OutputFilenames, OutputType};
|
||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
CrateNameDoesNotMatch, CrateNameEmpty, CrateNameInvalid, FileIsNotWriteable,
|
CrateNameDoesNotMatch, CrateNameEmpty, CrateNameInvalid, FileIsNotWriteable,
|
||||||
InvalidCharacterInCrateName,
|
InvalidCharacterInCrateName, InvalidCrateNameHelp,
|
||||||
};
|
};
|
||||||
use crate::Session;
|
use crate::Session;
|
||||||
use rustc_ast::{self as ast, attr};
|
use rustc_ast::{self as ast, attr};
|
||||||
|
@ -101,7 +101,16 @@ pub fn validate_crate_name(sess: &Session, s: Symbol, sp: Option<Span>) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
err_count += 1;
|
err_count += 1;
|
||||||
sess.emit_err(InvalidCharacterInCrateName { span: sp, character: c, crate_name: s });
|
sess.emit_err(InvalidCharacterInCrateName {
|
||||||
|
span: sp,
|
||||||
|
character: c,
|
||||||
|
crate_name: s,
|
||||||
|
crate_name_help: if sp.is_none() {
|
||||||
|
Some(InvalidCrateNameHelp::AddCrateName)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,9 @@ pub fn check(path: &Path, bad: &mut bool) {
|
||||||
// must strip all of them.
|
// must strip all of them.
|
||||||
let testname =
|
let testname =
|
||||||
file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0;
|
file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0;
|
||||||
if !file_path.with_file_name(testname).with_extension("rs").exists() {
|
if !file_path.with_file_name(testname).with_extension("rs").exists()
|
||||||
|
&& !testname.contains("ignore-tidy")
|
||||||
|
{
|
||||||
tidy_error!(bad, "Stray file with UI testing output: {:?}", file_path);
|
tidy_error!(bad, "Stray file with UI testing output: {:?}", file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
tests/ui/command/need-crate-arg-ignore-tidy.x.rs
Normal file
2
tests/ui/command/need-crate-arg-ignore-tidy.x.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
// issue: 113981
|
||||||
|
pub fn main() {}
|
6
tests/ui/command/need-crate-arg-ignore-tidy.x.stderr
Normal file
6
tests/ui/command/need-crate-arg-ignore-tidy.x.stderr
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
error: invalid character `'.'` in crate name: `need_crate_arg_ignore_tidy.x`
|
||||||
|
|
|
||||||
|
= help: you can either pass `--crate-name` on the command line or add `#![crate_name="…"]` to set the crate name
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Reference in a new issue