mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 12:36:35 +03:00
Rollup merge of #150188 - yotamofek:pr/dogfood-strip-circumfix, r=Kivooeo
Dogfood `strip_circumfix` cc rust-lang/rust#147946 Truth be told, I expected to find more places where this can be used in the compiler. Seems cargo, clippy and rustfmt can use this much more frequently, but I'll have to wait (I think?) for the next two-way sync to be able to dogfood it in those repos.
This commit is contained in:
@@ -251,9 +251,7 @@ pub fn new(libname: &'a str, verbatim: bool) -> Self {
|
||||
// if it looks like the user has provided a complete filename rather just the bare lib name,
|
||||
// then provide a note that they might want to try trimming the name
|
||||
let suggested_name = if !verbatim {
|
||||
if let Some(libname) = libname.strip_prefix("lib")
|
||||
&& let Some(libname) = libname.strip_suffix(".a")
|
||||
{
|
||||
if let Some(libname) = libname.strip_circumfix("lib", ".a") {
|
||||
// this is a unix style filename so trim prefix & suffix
|
||||
Some(libname)
|
||||
} else if let Some(libname) = libname.strip_suffix(".lib") {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#![feature(never_type)]
|
||||
#![feature(proc_macro_internals)]
|
||||
#![feature(result_option_map_or_default)]
|
||||
#![feature(strip_circumfix)]
|
||||
#![feature(trusted_len)]
|
||||
// tidy-alphabetical-end
|
||||
|
||||
|
||||
@@ -1758,8 +1758,7 @@ pub fn type_error_additional_suggestions(
|
||||
// specify a byte literal
|
||||
(ty::Uint(ty::UintTy::U8), ty::Char) => {
|
||||
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
|
||||
&& let Some(code) =
|
||||
code.strip_prefix('\'').and_then(|s| s.strip_suffix('\''))
|
||||
&& let Some(code) = code.strip_circumfix('\'', '\'')
|
||||
// forbid all Unicode escapes
|
||||
&& !code.starts_with("\\u")
|
||||
// forbids literal Unicode characters beyond ASCII
|
||||
@@ -1776,7 +1775,7 @@ pub fn type_error_additional_suggestions(
|
||||
// specify a character literal (issue #92479)
|
||||
(ty::Char, ty::Ref(_, r, _)) if r.is_str() => {
|
||||
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
|
||||
&& let Some(code) = code.strip_prefix('"').and_then(|s| s.strip_suffix('"'))
|
||||
&& let Some(code) = code.strip_circumfix('"', '"')
|
||||
&& code.chars().count() == 1
|
||||
{
|
||||
suggestions.push(TypeErrorAdditionalDiags::MeantCharLiteral {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#![feature(iter_intersperse)]
|
||||
#![feature(iterator_try_reduce)]
|
||||
#![feature(never_type)]
|
||||
#![feature(strip_circumfix)]
|
||||
#![feature(try_blocks)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![feature(yeet_expr)]
|
||||
|
||||
Reference in New Issue
Block a user