mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-07 13:25:45 +00:00
Remove lots of Symbol::as_str()
calls.
In various ways, such as changing functions to take a `Symbol` instead of a `&str`.
This commit is contained in:
parent
f04e866e57
commit
5930081f34
@ -2,7 +2,7 @@ pub use CommentStyle::*;
|
||||
|
||||
use crate::ast;
|
||||
use rustc_span::source_map::SourceMap;
|
||||
use rustc_span::{BytePos, CharPos, FileName, Pos};
|
||||
use rustc_span::{BytePos, CharPos, FileName, Pos, Symbol};
|
||||
|
||||
use log::debug;
|
||||
|
||||
@ -52,7 +52,8 @@ pub fn is_doc_comment(s: &str) -> bool {
|
||||
|| s.starts_with("/*!")
|
||||
}
|
||||
|
||||
pub fn doc_comment_style(comment: &str) -> ast::AttrStyle {
|
||||
pub fn doc_comment_style(comment: Symbol) -> ast::AttrStyle {
|
||||
let comment = &comment.as_str();
|
||||
assert!(is_doc_comment(comment));
|
||||
if comment.starts_with("//!") || comment.starts_with("/*!") {
|
||||
ast::AttrStyle::Inner
|
||||
@ -61,7 +62,9 @@ pub fn doc_comment_style(comment: &str) -> ast::AttrStyle {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn strip_doc_comment_decoration(comment: &str) -> String {
|
||||
pub fn strip_doc_comment_decoration(comment: Symbol) -> String {
|
||||
let comment = &comment.as_str();
|
||||
|
||||
/// remove whitespace-only lines from the start/end of lines
|
||||
fn vertical_trim(lines: Vec<String>) -> Vec<String> {
|
||||
let mut i = 0;
|
||||
|
@ -1,47 +1,58 @@
|
||||
use super::*;
|
||||
use crate::with_default_session_globals;
|
||||
|
||||
#[test]
|
||||
fn test_block_doc_comment_1() {
|
||||
let comment = "/**\n * Test \n ** Test\n * Test\n*/";
|
||||
let stripped = strip_doc_comment_decoration(comment);
|
||||
assert_eq!(stripped, " Test \n* Test\n Test");
|
||||
with_default_session_globals(|| {
|
||||
let comment = "/**\n * Test \n ** Test\n * Test\n*/";
|
||||
let stripped = strip_doc_comment_decoration(Symbol::intern(comment));
|
||||
assert_eq!(stripped, " Test \n* Test\n Test");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_block_doc_comment_2() {
|
||||
let comment = "/**\n * Test\n * Test\n*/";
|
||||
let stripped = strip_doc_comment_decoration(comment);
|
||||
assert_eq!(stripped, " Test\n Test");
|
||||
with_default_session_globals(|| {
|
||||
let comment = "/**\n * Test\n * Test\n*/";
|
||||
let stripped = strip_doc_comment_decoration(Symbol::intern(comment));
|
||||
assert_eq!(stripped, " Test\n Test");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_block_doc_comment_3() {
|
||||
let comment = "/**\n let a: *i32;\n *a = 5;\n*/";
|
||||
let stripped = strip_doc_comment_decoration(comment);
|
||||
assert_eq!(stripped, " let a: *i32;\n *a = 5;");
|
||||
with_default_session_globals(|| {
|
||||
let comment = "/**\n let a: *i32;\n *a = 5;\n*/";
|
||||
let stripped = strip_doc_comment_decoration(Symbol::intern(comment));
|
||||
assert_eq!(stripped, " let a: *i32;\n *a = 5;");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_block_doc_comment_4() {
|
||||
let comment = "/*******************\n test\n *********************/";
|
||||
let stripped = strip_doc_comment_decoration(comment);
|
||||
assert_eq!(stripped, " test");
|
||||
with_default_session_globals(|| {
|
||||
let comment = "/*******************\n test\n *********************/";
|
||||
let stripped = strip_doc_comment_decoration(Symbol::intern(comment));
|
||||
assert_eq!(stripped, " test");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_line_doc_comment() {
|
||||
let stripped = strip_doc_comment_decoration("/// test");
|
||||
assert_eq!(stripped, " test");
|
||||
let stripped = strip_doc_comment_decoration("///! test");
|
||||
assert_eq!(stripped, " test");
|
||||
let stripped = strip_doc_comment_decoration("// test");
|
||||
assert_eq!(stripped, " test");
|
||||
let stripped = strip_doc_comment_decoration("// test");
|
||||
assert_eq!(stripped, " test");
|
||||
let stripped = strip_doc_comment_decoration("///test");
|
||||
assert_eq!(stripped, "test");
|
||||
let stripped = strip_doc_comment_decoration("///!test");
|
||||
assert_eq!(stripped, "test");
|
||||
let stripped = strip_doc_comment_decoration("//test");
|
||||
assert_eq!(stripped, "test");
|
||||
with_default_session_globals(|| {
|
||||
let stripped = strip_doc_comment_decoration(Symbol::intern("/// test"));
|
||||
assert_eq!(stripped, " test");
|
||||
let stripped = strip_doc_comment_decoration(Symbol::intern("///! test"));
|
||||
assert_eq!(stripped, " test");
|
||||
let stripped = strip_doc_comment_decoration(Symbol::intern("// test"));
|
||||
assert_eq!(stripped, " test");
|
||||
let stripped = strip_doc_comment_decoration(Symbol::intern("// test"));
|
||||
assert_eq!(stripped, " test");
|
||||
let stripped = strip_doc_comment_decoration(Symbol::intern("///test"));
|
||||
assert_eq!(stripped, "test");
|
||||
let stripped = strip_doc_comment_decoration(Symbol::intern("///!test"));
|
||||
assert_eq!(stripped, "test");
|
||||
let stripped = strip_doc_comment_decoration(Symbol::intern("//test"));
|
||||
assert_eq!(stripped, "test");
|
||||
})
|
||||
}
|
||||
|
@ -47,12 +47,13 @@ pub fn lev_distance(a: &str, b: &str) -> usize {
|
||||
/// a lower(upper)case letters mismatch.
|
||||
pub fn find_best_match_for_name<'a, T>(
|
||||
iter_names: T,
|
||||
lookup: &str,
|
||||
lookup: Symbol,
|
||||
dist: Option<usize>,
|
||||
) -> Option<Symbol>
|
||||
where
|
||||
T: Iterator<Item = &'a Symbol>,
|
||||
{
|
||||
let lookup = &lookup.as_str();
|
||||
let max_dist = dist.map_or_else(|| cmp::max(lookup.len(), 3) / 3, |d| d);
|
||||
let name_vec: Vec<&Symbol> = iter_names.collect();
|
||||
|
||||
|
@ -25,31 +25,34 @@ fn test_find_best_match_for_name() {
|
||||
with_default_session_globals(|| {
|
||||
let input = vec![Symbol::intern("aaab"), Symbol::intern("aaabc")];
|
||||
assert_eq!(
|
||||
find_best_match_for_name(input.iter(), "aaaa", None),
|
||||
find_best_match_for_name(input.iter(), Symbol::intern("aaaa"), None),
|
||||
Some(Symbol::intern("aaab"))
|
||||
);
|
||||
|
||||
assert_eq!(find_best_match_for_name(input.iter(), "1111111111", None), None);
|
||||
assert_eq!(
|
||||
find_best_match_for_name(input.iter(), Symbol::intern("1111111111"), None),
|
||||
None
|
||||
);
|
||||
|
||||
let input = vec![Symbol::intern("aAAA")];
|
||||
assert_eq!(
|
||||
find_best_match_for_name(input.iter(), "AAAA", None),
|
||||
find_best_match_for_name(input.iter(), Symbol::intern("AAAA"), None),
|
||||
Some(Symbol::intern("aAAA"))
|
||||
);
|
||||
|
||||
let input = vec![Symbol::intern("AAAA")];
|
||||
// Returns None because `lev_distance > max_dist / 3`
|
||||
assert_eq!(find_best_match_for_name(input.iter(), "aaaa", None), None);
|
||||
assert_eq!(find_best_match_for_name(input.iter(), Symbol::intern("aaaa"), None), None);
|
||||
|
||||
let input = vec![Symbol::intern("AAAA")];
|
||||
assert_eq!(
|
||||
find_best_match_for_name(input.iter(), "aaaa", Some(4)),
|
||||
find_best_match_for_name(input.iter(), Symbol::intern("aaaa"), Some(4)),
|
||||
Some(Symbol::intern("AAAA"))
|
||||
);
|
||||
|
||||
let input = vec![Symbol::intern("a_longer_variable_name")];
|
||||
assert_eq!(
|
||||
find_best_match_for_name(input.iter(), "a_variable_longer_name", None),
|
||||
find_best_match_for_name(input.iter(), Symbol::intern("a_variable_longer_name"), None),
|
||||
Some(Symbol::intern("a_longer_variable_name"))
|
||||
);
|
||||
})
|
||||
|
@ -522,6 +522,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
||||
self.word(st)
|
||||
}
|
||||
|
||||
fn print_symbol(&mut self, sym: Symbol, style: ast::StrStyle) {
|
||||
self.print_string(&sym.as_str(), style);
|
||||
}
|
||||
|
||||
fn print_inner_attributes(&mut self, attrs: &[ast::Attribute]) {
|
||||
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, true)
|
||||
}
|
||||
@ -2050,7 +2054,7 @@ impl<'a> State<'a> {
|
||||
let print_reg_or_class = |s: &mut Self, r: &InlineAsmRegOrRegClass| match r
|
||||
{
|
||||
InlineAsmRegOrRegClass::Reg(r) => {
|
||||
s.print_string(&r.as_str(), ast::StrStyle::Cooked)
|
||||
s.print_symbol(*r, ast::StrStyle::Cooked)
|
||||
}
|
||||
InlineAsmRegOrRegClass::RegClass(r) => s.word(r.to_string()),
|
||||
};
|
||||
@ -2144,7 +2148,7 @@ impl<'a> State<'a> {
|
||||
ast::ExprKind::LlvmInlineAsm(ref a) => {
|
||||
self.s.word("llvm_asm!");
|
||||
self.popen();
|
||||
self.print_string(&a.asm.as_str(), a.asm_str_style);
|
||||
self.print_symbol(a.asm, a.asm_str_style);
|
||||
self.word_space(":");
|
||||
|
||||
self.commasep(Inconsistent, &a.outputs, |s, out| {
|
||||
@ -2164,7 +2168,7 @@ impl<'a> State<'a> {
|
||||
self.word_space(":");
|
||||
|
||||
self.commasep(Inconsistent, &a.inputs, |s, &(co, ref o)| {
|
||||
s.print_string(&co.as_str(), ast::StrStyle::Cooked);
|
||||
s.print_symbol(co, ast::StrStyle::Cooked);
|
||||
s.popen();
|
||||
s.print_expr(o);
|
||||
s.pclose();
|
||||
@ -2172,8 +2176,8 @@ impl<'a> State<'a> {
|
||||
self.s.space();
|
||||
self.word_space(":");
|
||||
|
||||
self.commasep(Inconsistent, &a.clobbers, |s, co| {
|
||||
s.print_string(&co.as_str(), ast::StrStyle::Cooked);
|
||||
self.commasep(Inconsistent, &a.clobbers, |s, &co| {
|
||||
s.print_symbol(co, ast::StrStyle::Cooked);
|
||||
});
|
||||
|
||||
let mut options = vec![];
|
||||
|
@ -149,8 +149,8 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
|
||||
}
|
||||
Literal(lit) => tt!(Literal { lit }),
|
||||
DocComment(c) => {
|
||||
let style = comments::doc_comment_style(&c.as_str());
|
||||
let stripped = comments::strip_doc_comment_decoration(&c.as_str());
|
||||
let style = comments::doc_comment_style(c);
|
||||
let stripped = comments::strip_doc_comment_decoration(c);
|
||||
let mut escaped = String::new();
|
||||
for ch in stripped.chars() {
|
||||
escaped.extend(ch.escape_debug());
|
||||
|
@ -1557,7 +1557,7 @@ impl<'a> State<'a> {
|
||||
let i = &a.inner;
|
||||
self.s.word("llvm_asm!");
|
||||
self.popen();
|
||||
self.print_string(&i.asm.as_str(), i.asm_str_style);
|
||||
self.print_symbol(i.asm, i.asm_str_style);
|
||||
self.word_space(":");
|
||||
|
||||
let mut out_idx = 0;
|
||||
@ -1579,8 +1579,8 @@ impl<'a> State<'a> {
|
||||
self.word_space(":");
|
||||
|
||||
let mut in_idx = 0;
|
||||
self.commasep(Inconsistent, &i.inputs, |s, co| {
|
||||
s.print_string(&co.as_str(), ast::StrStyle::Cooked);
|
||||
self.commasep(Inconsistent, &i.inputs, |s, &co| {
|
||||
s.print_symbol(co, ast::StrStyle::Cooked);
|
||||
s.popen();
|
||||
s.print_expr(&a.inputs_exprs[in_idx]);
|
||||
s.pclose();
|
||||
@ -1589,8 +1589,8 @@ impl<'a> State<'a> {
|
||||
self.s.space();
|
||||
self.word_space(":");
|
||||
|
||||
self.commasep(Inconsistent, &i.clobbers, |s, co| {
|
||||
s.print_string(&co.as_str(), ast::StrStyle::Cooked);
|
||||
self.commasep(Inconsistent, &i.clobbers, |s, &co| {
|
||||
s.print_symbol(co, ast::StrStyle::Cooked);
|
||||
});
|
||||
|
||||
let mut options = vec![];
|
||||
|
@ -139,7 +139,7 @@ impl AssertModuleSource<'tcx> {
|
||||
}
|
||||
|
||||
self.tcx.sess.cgu_reuse_tracker.set_expectation(
|
||||
&cgu_name.as_str(),
|
||||
cgu_name,
|
||||
&user_path,
|
||||
attr.span,
|
||||
expected_reuse,
|
||||
|
@ -234,7 +234,7 @@ impl DirtyCleanVisitor<'tcx> {
|
||||
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
|
||||
if item.check_name(LABEL) {
|
||||
let value = expect_associated_value(self.tcx, &item);
|
||||
return Some(self.resolve_labels(&item, &value.as_str()));
|
||||
return Some(self.resolve_labels(&item, value));
|
||||
}
|
||||
}
|
||||
None
|
||||
@ -245,7 +245,7 @@ impl DirtyCleanVisitor<'tcx> {
|
||||
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
|
||||
if item.check_name(EXCEPT) {
|
||||
let value = expect_associated_value(self.tcx, &item);
|
||||
return self.resolve_labels(&item, &value.as_str());
|
||||
return self.resolve_labels(&item, value);
|
||||
}
|
||||
}
|
||||
// if no `label` or `except` is given, only the node's group are asserted
|
||||
@ -347,9 +347,9 @@ impl DirtyCleanVisitor<'tcx> {
|
||||
(name, labels)
|
||||
}
|
||||
|
||||
fn resolve_labels(&self, item: &NestedMetaItem, value: &str) -> Labels {
|
||||
fn resolve_labels(&self, item: &NestedMetaItem, value: Symbol) -> Labels {
|
||||
let mut out = Labels::default();
|
||||
for label in value.split(',') {
|
||||
for label in value.as_str().split(',') {
|
||||
let label = label.trim();
|
||||
if DepNode::has_label_string(label) {
|
||||
if out.contains(label) {
|
||||
|
@ -427,11 +427,8 @@ pub(crate) fn check_attr_crate_type(attrs: &[ast::Attribute], lint_buffer: &mut
|
||||
|
||||
if let ast::MetaItemKind::NameValue(spanned) = a.meta().unwrap().kind {
|
||||
let span = spanned.span;
|
||||
let lev_candidate = find_best_match_for_name(
|
||||
CRATE_TYPES.iter().map(|(k, _)| k),
|
||||
&n.as_str(),
|
||||
None,
|
||||
);
|
||||
let lev_candidate =
|
||||
find_best_match_for_name(CRATE_TYPES.iter().map(|(k, _)| k), n, None);
|
||||
if let Some(candidate) = lev_candidate {
|
||||
lint_buffer.buffer_lint_with_diagnostic(
|
||||
lint::builtin::UNKNOWN_CRATE_TYPES,
|
||||
|
@ -394,8 +394,11 @@ impl LintStore {
|
||||
let symbols =
|
||||
self.by_name.keys().map(|name| Symbol::intern(&name)).collect::<Vec<_>>();
|
||||
|
||||
let suggestion =
|
||||
find_best_match_for_name(symbols.iter(), &lint_name.to_lowercase(), None);
|
||||
let suggestion = find_best_match_for_name(
|
||||
symbols.iter(),
|
||||
Symbol::intern(&lint_name.to_lowercase()),
|
||||
None,
|
||||
);
|
||||
|
||||
CheckLintNameResult::NoLint(suggestion)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
crate fn collect(tcx: TyCtxt<'_>) -> Vec<String> {
|
||||
@ -11,7 +11,7 @@ crate fn collect(tcx: TyCtxt<'_>) -> Vec<String> {
|
||||
for attr in tcx.hir().krate().item.attrs.iter() {
|
||||
if attr.has_name(sym::link_args) {
|
||||
if let Some(linkarg) = attr.value_str() {
|
||||
collector.add_link_args(&linkarg.as_str());
|
||||
collector.add_link_args(linkarg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -36,7 +36,7 @@ impl<'tcx> ItemLikeVisitor<'tcx> for Collector {
|
||||
// First, add all of the custom #[link_args] attributes
|
||||
for m in it.attrs.iter().filter(|a| a.check_name(sym::link_args)) {
|
||||
if let Some(linkarg) = m.value_str() {
|
||||
self.add_link_args(&linkarg.as_str());
|
||||
self.add_link_args(linkarg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -46,7 +46,7 @@ impl<'tcx> ItemLikeVisitor<'tcx> for Collector {
|
||||
}
|
||||
|
||||
impl Collector {
|
||||
fn add_link_args(&mut self, args: &str) {
|
||||
self.args.extend(args.split(' ').filter(|s| !s.is_empty()).map(|s| s.to_string()))
|
||||
fn add_link_args(&mut self, args: Symbol) {
|
||||
self.args.extend(args.as_str().split(' ').filter(|s| !s.is_empty()).map(|s| s.to_string()))
|
||||
}
|
||||
}
|
||||
|
@ -448,8 +448,7 @@ impl CodegenUnitNameBuilder<'tcx> {
|
||||
if self.tcx.sess.opts.debugging_opts.human_readable_cgu_names {
|
||||
cgu_name
|
||||
} else {
|
||||
let cgu_name = &cgu_name.as_str();
|
||||
Symbol::intern(&CodegenUnit::mangle_name(cgu_name))
|
||||
Symbol::intern(&CodegenUnit::mangle_name(&cgu_name.as_str()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
fn mk_doc_comment(&self, s: Symbol) -> ast::Attribute {
|
||||
attr::mk_doc_comment(comments::doc_comment_style(&s.as_str()), s, self.token.span)
|
||||
attr::mk_doc_comment(comments::doc_comment_style(s), s, self.token.span)
|
||||
}
|
||||
|
||||
/// Matches `attribute = # ! [ meta_item ]`.
|
||||
|
@ -213,7 +213,7 @@ impl TokenCursor {
|
||||
tok => return tok,
|
||||
};
|
||||
|
||||
let stripped = strip_doc_comment_decoration(&name.as_str());
|
||||
let stripped = strip_doc_comment_decoration(name);
|
||||
|
||||
// Searches for the occurrences of `"#*` and returns the minimum number of `#`s
|
||||
// required to wrap the text.
|
||||
@ -250,7 +250,7 @@ impl TokenCursor {
|
||||
TokenCursorFrame::new(
|
||||
delim_span,
|
||||
token::NoDelim,
|
||||
&if doc_comment_style(&name.as_str()) == AttrStyle::Inner {
|
||||
&if doc_comment_style(name) == AttrStyle::Inner {
|
||||
[TokenTree::token(token::Pound, sp), TokenTree::token(token::Not, sp), body]
|
||||
.iter()
|
||||
.cloned()
|
||||
|
@ -674,7 +674,7 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
match find_best_match_for_name(
|
||||
suggestions.iter().map(|suggestion| &suggestion.candidate),
|
||||
&ident.as_str(),
|
||||
ident.name,
|
||||
None,
|
||||
) {
|
||||
Some(found) if found != ident.name => {
|
||||
|
@ -1132,7 +1132,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
});
|
||||
|
||||
let lev_suggestion =
|
||||
find_best_match_for_name(names, &ident.as_str(), None).map(|suggestion| {
|
||||
find_best_match_for_name(names, ident.name, None).map(|suggestion| {
|
||||
(
|
||||
vec![(ident.span, suggestion.to_string())],
|
||||
String::from("a similar name exists in the module"),
|
||||
|
@ -760,7 +760,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
self.r.report_error(
|
||||
original_span,
|
||||
ResolutionError::UnreachableLabel {
|
||||
name: &label.name.as_str(),
|
||||
name: label.name,
|
||||
definition_span: ident.span,
|
||||
suggestion,
|
||||
},
|
||||
@ -777,7 +777,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
|
||||
self.r.report_error(
|
||||
original_span,
|
||||
ResolutionError::UndeclaredLabel { name: &label.name.as_str(), suggestion },
|
||||
ResolutionError::UndeclaredLabel { name: label.name, suggestion },
|
||||
);
|
||||
None
|
||||
}
|
||||
@ -1550,7 +1550,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
// `Variant(a, a)`:
|
||||
_ => IdentifierBoundMoreThanOnceInSamePattern,
|
||||
};
|
||||
self.r.report_error(ident.span, error(&ident.as_str()));
|
||||
self.r.report_error(ident.span, error(ident.name));
|
||||
}
|
||||
|
||||
// Record as bound if it's valid:
|
||||
|
@ -765,7 +765,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
|
||||
|
||||
match find_best_match_for_name(
|
||||
names.iter().map(|suggestion| &suggestion.candidate),
|
||||
&name.as_str(),
|
||||
name,
|
||||
None,
|
||||
) {
|
||||
Some(found) if found != name => {
|
||||
@ -1008,7 +1008,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
|
||||
.filter(|(id, _)| id.span.ctxt() == label.span.ctxt())
|
||||
.map(|(id, _)| &id.name);
|
||||
|
||||
find_best_match_for_name(names, &label.as_str(), None).map(|symbol| {
|
||||
find_best_match_for_name(names, label.name, None).map(|symbol| {
|
||||
// Upon finding a similar name, get the ident that it was from - the span
|
||||
// contained within helps make a useful diagnostic. In addition, determine
|
||||
// whether this candidate is within scope.
|
||||
|
@ -193,11 +193,11 @@ enum ResolutionError<'a> {
|
||||
/// Error E0409: variable `{}` is bound in inconsistent ways within the same match arm.
|
||||
VariableBoundWithDifferentMode(Symbol, Span),
|
||||
/// Error E0415: identifier is bound more than once in this parameter list.
|
||||
IdentifierBoundMoreThanOnceInParameterList(&'a str),
|
||||
IdentifierBoundMoreThanOnceInParameterList(Symbol),
|
||||
/// Error E0416: identifier is bound more than once in the same pattern.
|
||||
IdentifierBoundMoreThanOnceInSamePattern(&'a str),
|
||||
IdentifierBoundMoreThanOnceInSamePattern(Symbol),
|
||||
/// Error E0426: use of undeclared label.
|
||||
UndeclaredLabel { name: &'a str, suggestion: Option<LabelSuggestion> },
|
||||
UndeclaredLabel { name: Symbol, suggestion: Option<LabelSuggestion> },
|
||||
/// Error E0429: `self` imports are only allowed within a `{ }` list.
|
||||
SelfImportsOnlyAllowedWithin { root: bool, span_with_rename: Span },
|
||||
/// Error E0430: `self` import can only appear once in the list.
|
||||
@ -211,13 +211,13 @@ enum ResolutionError<'a> {
|
||||
/// Error E0435: attempt to use a non-constant value in a constant.
|
||||
AttemptToUseNonConstantValueInConstant,
|
||||
/// Error E0530: `X` bindings cannot shadow `Y`s.
|
||||
BindingShadowsSomethingUnacceptable(&'a str, Symbol, &'a NameBinding<'a>),
|
||||
BindingShadowsSomethingUnacceptable(&'static str, Symbol, &'a NameBinding<'a>),
|
||||
/// Error E0128: type parameters with a default cannot use forward-declared identifiers.
|
||||
ForwardDeclaredTyParam, // FIXME(const_generics:defaults)
|
||||
/// Error E0735: type parameters with a default cannot use `Self`
|
||||
SelfInTyParamDefault,
|
||||
/// Error E0767: use of unreachable label
|
||||
UnreachableLabel { name: &'a str, definition_span: Span, suggestion: Option<LabelSuggestion> },
|
||||
UnreachableLabel { name: Symbol, definition_span: Span, suggestion: Option<LabelSuggestion> },
|
||||
}
|
||||
|
||||
enum VisResolutionError<'a> {
|
||||
|
@ -824,7 +824,7 @@ impl<'tcx> SaveContext<'tcx> {
|
||||
for attr in attrs {
|
||||
if let Some(val) = attr.doc_str() {
|
||||
if attr.is_doc_comment() {
|
||||
result.push_str(&strip_doc_comment_decoration(&val.as_str()));
|
||||
result.push_str(&strip_doc_comment_decoration(val));
|
||||
} else {
|
||||
result.push_str(&val.as_str());
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
use log::debug;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{Span, Symbol};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
|
||||
@ -67,7 +67,7 @@ impl CguReuseTracker {
|
||||
|
||||
pub fn set_expectation(
|
||||
&self,
|
||||
cgu_name: &str,
|
||||
cgu_name: Symbol,
|
||||
cgu_user_name: &str,
|
||||
error_span: Span,
|
||||
expected_reuse: CguReuse,
|
||||
|
@ -1597,7 +1597,7 @@ impl !Sync for SymbolStr {}
|
||||
|
||||
/// This impl means that if `ss` is a `SymbolStr`:
|
||||
/// - `*ss` is a `str`;
|
||||
/// - `&*ss` is a `&str`;
|
||||
/// - `&*ss` is a `&str` (and `match &*ss { ... }` is a common pattern).
|
||||
/// - `&ss as &str` is a `&str`, which means that `&ss` can be passed to a
|
||||
/// function expecting a `&str`.
|
||||
impl std::ops::Deref for SymbolStr {
|
||||
|
@ -2254,7 +2254,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
.collect();
|
||||
|
||||
if let (Some(suggested_name), true) = (
|
||||
find_best_match_for_name(all_candidate_names.iter(), &assoc_name.as_str(), None),
|
||||
find_best_match_for_name(all_candidate_names.iter(), assoc_name.name, None),
|
||||
assoc_name.span != DUMMY_SP,
|
||||
) {
|
||||
err.span_suggestion(
|
||||
@ -2354,7 +2354,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
let adt_def = qself_ty.ty_adt_def().expect("enum is not an ADT");
|
||||
if let Some(suggested_name) = find_best_match_for_name(
|
||||
adt_def.variants.iter().map(|variant| &variant.ident.name),
|
||||
&assoc_ident.as_str(),
|
||||
assoc_ident.name,
|
||||
None,
|
||||
) {
|
||||
err.span_suggestion(
|
||||
|
@ -1336,7 +1336,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// prevent all specified fields from being suggested
|
||||
let skip_fields = skip_fields.iter().map(|ref x| x.ident.name);
|
||||
if let Some(field_name) =
|
||||
Self::suggest_field_name(variant, &field.ident.as_str(), skip_fields.collect())
|
||||
Self::suggest_field_name(variant, field.ident.name, skip_fields.collect())
|
||||
{
|
||||
err.span_suggestion(
|
||||
field.ident.span,
|
||||
@ -1377,7 +1377,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// Return an hint about the closest match in field names
|
||||
fn suggest_field_name(
|
||||
variant: &'tcx ty::VariantDef,
|
||||
field: &str,
|
||||
field: Symbol,
|
||||
skip: Vec<Symbol>,
|
||||
) -> Option<Symbol> {
|
||||
let names = variant.fields.iter().filter_map(|field| {
|
||||
@ -1621,7 +1621,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
field: Ident,
|
||||
) {
|
||||
if let Some(suggested_field_name) =
|
||||
Self::suggest_field_name(def.non_enum_variant(), &field.as_str(), vec![])
|
||||
Self::suggest_field_name(def.non_enum_variant(), field.name, vec![])
|
||||
{
|
||||
err.span_suggestion(
|
||||
field.span,
|
||||
|
@ -1536,7 +1536,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
} else {
|
||||
let best_name = {
|
||||
let names = applicable_close_candidates.iter().map(|cand| &cand.ident.name);
|
||||
find_best_match_for_name(names, &self.method_name.unwrap().as_str(), None)
|
||||
find_best_match_for_name(names, self.method_name.unwrap().name, None)
|
||||
}
|
||||
.unwrap();
|
||||
Ok(applicable_close_candidates
|
||||
|
@ -729,7 +729,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let adt_def = actual.ty_adt_def().expect("enum is not an ADT");
|
||||
if let Some(suggestion) = lev_distance::find_best_match_for_name(
|
||||
adt_def.variants.iter().map(|s| &s.ident.name),
|
||||
&item_name.as_str(),
|
||||
item_name.name,
|
||||
None,
|
||||
) {
|
||||
err.span_suggestion(
|
||||
|
@ -1216,7 +1216,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
);
|
||||
if plural == "" {
|
||||
let input = unmentioned_fields.iter().map(|field| &field.name);
|
||||
let suggested_name = find_best_match_for_name(input, &ident.as_str(), None);
|
||||
let suggested_name = find_best_match_for_name(input, ident.name, None);
|
||||
if let Some(suggested_name) = suggested_name {
|
||||
err.span_suggestion(
|
||||
ident.span,
|
||||
|
@ -540,7 +540,7 @@ impl Attributes {
|
||||
.filter_map(|attr| {
|
||||
if let Some(value) = attr.doc_str() {
|
||||
let (value, mk_fragment): (_, fn(_, _, _) -> _) = if attr.is_doc_comment() {
|
||||
(strip_doc_comment_decoration(&value.as_str()), DocFragment::SugaredDoc)
|
||||
(strip_doc_comment_decoration(value), DocFragment::SugaredDoc)
|
||||
} else {
|
||||
(value.to_string(), DocFragment::RawDoc)
|
||||
};
|
||||
|
@ -421,7 +421,11 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMet
|
||||
.iter()
|
||||
.map(|l| Symbol::intern(&l.name_lower()))
|
||||
.collect::<Vec<_>>();
|
||||
let sugg = find_best_match_for_name(symbols.iter(), &format!("clippy::{}", name_lower), None);
|
||||
let sugg = find_best_match_for_name(
|
||||
symbols.iter(),
|
||||
Symbol::intern(&format!("clippy::{}", name_lower)),
|
||||
None,
|
||||
);
|
||||
if lint_name.chars().any(char::is_uppercase)
|
||||
&& lint_store.find_lints(&format!("clippy::{}", name_lower)).is_ok()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user