Dogfood trim_{suffix|prefix} in compiler

This commit is contained in:
Yotam Ofek 2025-11-01 22:20:42 +02:00
parent 73e6c9ebd9
commit d28dcc7e79
11 changed files with 16 additions and 13 deletions

View file

@ -451,7 +451,7 @@ fn report_inline_asm(
llvm::DiagnosticLevel::Warning => Level::Warning,
llvm::DiagnosticLevel::Note | llvm::DiagnosticLevel::Remark => Level::Note,
};
let msg = msg.strip_prefix("error: ").unwrap_or(&msg).to_string();
let msg = msg.trim_prefix("error: ").to_string();
cgcx.diag_emitter.inline_asm_error(span, msg, level, source);
}

View file

@ -17,6 +17,7 @@
#![feature(macro_derive)]
#![feature(rustdoc_internals)]
#![feature(slice_as_array)]
#![feature(trim_prefix_suffix)]
#![feature(try_blocks)]
// tidy-alphabetical-end

View file

@ -13,6 +13,7 @@
#![feature(panic_backtrace_config)]
#![feature(panic_update_hook)]
#![feature(rustdoc_internals)]
#![feature(trim_prefix_suffix)]
#![feature(try_blocks)]
// tidy-alphabetical-end
@ -466,7 +467,7 @@ pub enum Compilation {
fn handle_explain(early_dcx: &EarlyDiagCtxt, registry: Registry, code: &str, color: ColorConfig) {
// Allow "E0123" or "0123" form.
let upper_cased_code = code.to_ascii_uppercase();
if let Ok(code) = upper_cased_code.strip_prefix('E').unwrap_or(&upper_cased_code).parse::<u32>()
if let Ok(code) = upper_cased_code.trim_prefix('E').parse::<u32>()
&& code <= ErrCode::MAX_AS_U32
&& let Ok(description) = registry.try_find_description(ErrCode::from_u32(code))
{
@ -1263,7 +1264,7 @@ fn warn_on_confusing_output_filename_flag(
if let Some(name) = matches.opt_str("o")
&& let Some(suspect) = args.iter().find(|arg| arg.starts_with("-o") && *arg != "-o")
{
let filename = suspect.strip_prefix("-").unwrap_or(suspect);
let filename = suspect.trim_prefix("-");
let optgroups = config::rustc_optgroups();
let fake_args = ["optimize", "o0", "o1", "o2", "o3", "ofast", "og", "os", "oz"];

View file

@ -7,6 +7,7 @@
#![feature(iter_intersperse)]
#![feature(iter_order_by)]
#![feature(never_type)]
#![feature(trim_prefix_suffix)]
// tidy-alphabetical-end
mod _match;

View file

@ -2551,7 +2551,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// If this is a floating point literal that ends with '.',
// get rid of it to stop this from becoming a member access.
let snippet = snippet.strip_suffix('.').unwrap_or(&snippet);
let snippet = snippet.trim_suffix('.');
err.span_suggestion(
lit.span,
format!(

View file

@ -2608,7 +2608,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
let (span, text) = match path.segments.first() {
Some(seg) if let Some(name) = seg.ident.as_str().strip_prefix("let") => {
// a special case for #117894
let name = name.strip_prefix('_').unwrap_or(name);
let name = name.trim_prefix('_');
(ident_span, format!("let {name}"))
}
_ => (ident_span.shrink_to_lo(), "let ".to_string()),

View file

@ -22,6 +22,7 @@
#![feature(ptr_as_ref_unchecked)]
#![feature(rustc_attrs)]
#![feature(rustdoc_internals)]
#![feature(trim_prefix_suffix)]
#![recursion_limit = "256"]
// tidy-alphabetical-end

View file

@ -400,10 +400,10 @@ fn preprocess_link(link: &str) -> Box<str> {
let link = link.split('#').next().unwrap();
let link = link.trim();
let link = link.rsplit('@').next().unwrap();
let link = link.strip_suffix("()").unwrap_or(link);
let link = link.strip_suffix("{}").unwrap_or(link);
let link = link.strip_suffix("[]").unwrap_or(link);
let link = if link != "!" { link.strip_suffix('!').unwrap_or(link) } else { link };
let link = link.trim_suffix("()");
let link = link.trim_suffix("{}");
let link = link.trim_suffix("[]");
let link = if link != "!" { link.trim_suffix('!') } else { link };
let link = link.trim();
strip_generics_from_path(link).unwrap_or_else(|_| link.into())
}

View file

@ -264,9 +264,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
</pre>\
</div>",
added_classes = added_classes.join(" "),
text = Escape(
original_text.strip_suffix('\n').unwrap_or(&original_text)
),
text = Escape(original_text.trim_suffix('\n')),
)
.into(),
));

View file

@ -185,7 +185,7 @@ impl SourceCollector<'_, '_> {
};
// Remove the utf-8 BOM if any
let contents = contents.strip_prefix('\u{feff}').unwrap_or(&contents);
let contents = contents.trim_prefix('\u{feff}');
let shared = &self.cx.shared;
// Create the intermediate directories

View file

@ -17,6 +17,7 @@
#![feature(iter_order_by)]
#![feature(rustc_private)]
#![feature(test)]
#![feature(trim_prefix_suffix)]
#![warn(rustc::internal)]
// tidy-alphabetical-end