diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index cfbb9541ecd2d..549829e74baca 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -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); } diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index 982d5cd3ac418..c8ad8f0c10d0d 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -17,6 +17,7 @@ #![feature(macro_derive)] #![feature(rustdoc_internals)] #![feature(slice_as_array)] +#![feature(trim_prefix_suffix)] #![feature(try_blocks)] // tidy-alphabetical-end diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index c926a7c742a0a..b12af04c4e300 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -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::() + if let Ok(code) = upper_cased_code.trim_prefix('E').parse::() && 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"]; diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 99a9566c74cef..b4264e9993313 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -7,6 +7,7 @@ #![feature(iter_intersperse)] #![feature(iter_order_by)] #![feature(never_type)] +#![feature(trim_prefix_suffix)] // tidy-alphabetical-end mod _match; diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 8e9c6eb046aed..7d6982cb024c3 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -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!( diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 57f81ebf0d81e..1d00a6b81fabc 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -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()), diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index f6a4f59cb339a..04f3c22d29456 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -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 diff --git a/compiler/rustc_resolve/src/rustdoc.rs b/compiler/rustc_resolve/src/rustdoc.rs index 970d16313584e..872770def1775 100644 --- a/compiler/rustc_resolve/src/rustdoc.rs +++ b/compiler/rustc_resolve/src/rustdoc.rs @@ -400,10 +400,10 @@ fn preprocess_link(link: &str) -> Box { 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()) } diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 752cd2e610a54..a4d377432c914 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -264,9 +264,7 @@ impl<'a, I: Iterator>> Iterator for CodeBlocks<'_, 'a, I> { \ ", added_classes = added_classes.join(" "), - text = Escape( - original_text.strip_suffix('\n').unwrap_or(&original_text) - ), + text = Escape(original_text.trim_suffix('\n')), ) .into(), )); diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index c79f63fbc2032..f04f94432b808 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -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 diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 6c280c0736b18..897369efb0fb4 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -17,6 +17,7 @@ #![feature(iter_order_by)] #![feature(rustc_private)] #![feature(test)] +#![feature(trim_prefix_suffix)] #![warn(rustc::internal)] // tidy-alphabetical-end