mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Remove SymbolStr
.
By changing `as_str()` to take `&self` instead of `self`, we can just return `&str`. We're still lying about lifetimes, but it's a smaller lie than before, where `SymbolStr` contained a (fake) `&'static str`!
This commit is contained in:
parent
41c48bd390
commit
a89a063ba0
@ -17,7 +17,7 @@ use rustc_semver::RustcVersion;
|
|||||||
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
|
||||||
use rustc_span::source_map::Span;
|
use rustc_span::source_map::Span;
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
use rustc_span::symbol::{Symbol, SymbolStr};
|
use rustc_span::symbol::Symbol;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
|
|
||||||
static UNIX_SYSTEMS: &[&str] = &[
|
static UNIX_SYSTEMS: &[&str] = &[
|
||||||
@ -310,8 +310,8 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
|
|||||||
|| is_word(lint, sym::deprecated)
|
|| is_word(lint, sym::deprecated)
|
||||||
|| is_word(lint, sym!(unreachable_pub))
|
|| is_word(lint, sym!(unreachable_pub))
|
||||||
|| is_word(lint, sym!(unused))
|
|| is_word(lint, sym!(unused))
|
||||||
|| extract_clippy_lint(lint).map_or(false, |s| s == "wildcard_imports")
|
|| extract_clippy_lint(lint).map_or(false, |s| s.as_str() == "wildcard_imports")
|
||||||
|| extract_clippy_lint(lint).map_or(false, |s| s == "enum_glob_use")
|
|| extract_clippy_lint(lint).map_or(false, |s| s.as_str() == "enum_glob_use")
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -370,7 +370,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the lint name if it is clippy lint.
|
/// Returns the lint name if it is clippy lint.
|
||||||
fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<SymbolStr> {
|
fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<Symbol> {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let Some(meta_item) = lint.meta_item();
|
if let Some(meta_item) = lint.meta_item();
|
||||||
if meta_item.path.segments.len() > 1;
|
if meta_item.path.segments.len() > 1;
|
||||||
@ -378,7 +378,7 @@ fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<SymbolStr> {
|
|||||||
if tool_name.name == sym::clippy;
|
if tool_name.name == sym::clippy;
|
||||||
then {
|
then {
|
||||||
let lint_name = meta_item.path.segments.last().unwrap().ident.name;
|
let lint_name = meta_item.path.segments.last().unwrap().ident.name;
|
||||||
return Some(lint_name.as_str());
|
return Some(lint_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
@ -387,7 +387,7 @@ fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<SymbolStr> {
|
|||||||
fn check_clippy_lint_names(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem]) {
|
fn check_clippy_lint_names(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem]) {
|
||||||
for lint in items {
|
for lint in items {
|
||||||
if let Some(lint_name) = extract_clippy_lint(lint) {
|
if let Some(lint_name) = extract_clippy_lint(lint) {
|
||||||
if lint_name == "restriction" && name != sym::allow {
|
if lint_name.as_str() == "restriction" && name != sym::allow {
|
||||||
span_lint_and_help(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
BLANKET_CLIPPY_RESTRICTION_LINTS,
|
BLANKET_CLIPPY_RESTRICTION_LINTS,
|
||||||
|
@ -9,7 +9,7 @@ use rustc_middle::hir::map::Map;
|
|||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_span::symbol::SymbolStr;
|
use rustc_span::symbol::Symbol;
|
||||||
use rustc_span::{sym, Span};
|
use rustc_span::{sym, Span};
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
@ -71,8 +71,8 @@ impl LateLintPass<'_> for MatchStrCaseMismatch {
|
|||||||
visitor.visit_expr(match_expr);
|
visitor.visit_expr(match_expr);
|
||||||
|
|
||||||
if let Some(case_method) = visitor.case_method {
|
if let Some(case_method) = visitor.case_method {
|
||||||
if let Some((bad_case_span, bad_case_str)) = verify_case(&case_method, arms) {
|
if let Some((bad_case_span, bad_case_sym)) = verify_case(&case_method, arms) {
|
||||||
lint(cx, &case_method, bad_case_span, &bad_case_str);
|
lint(cx, &case_method, bad_case_span, bad_case_sym.as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ fn get_case_method(segment_ident_str: &str) -> Option<CaseMethod> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<(Span, SymbolStr)> {
|
fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<(Span, Symbol)> {
|
||||||
let case_check = match case_method {
|
let case_check = match case_method {
|
||||||
CaseMethod::LowerCase => |input: &str| -> bool { input.chars().all(|c| c.to_lowercase().next() == Some(c)) },
|
CaseMethod::LowerCase => |input: &str| -> bool { input.chars().all(|c| c.to_lowercase().next() == Some(c)) },
|
||||||
CaseMethod::AsciiLowerCase => |input: &str| -> bool { !input.chars().any(|c| c.is_ascii_uppercase()) },
|
CaseMethod::AsciiLowerCase => |input: &str| -> bool { !input.chars().any(|c| c.is_ascii_uppercase()) },
|
||||||
@ -144,7 +144,7 @@ fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<(
|
|||||||
let input = symbol.as_str();
|
let input = symbol.as_str();
|
||||||
if !case_check(&input);
|
if !case_check(&input);
|
||||||
then {
|
then {
|
||||||
return Some((lit.span, input));
|
return Some((lit.span, symbol));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ use rustc_middle::lint::in_external_macro;
|
|||||||
use rustc_middle::ty::{self, TraitRef, Ty, TyS};
|
use rustc_middle::ty::{self, TraitRef, Ty, TyS};
|
||||||
use rustc_semver::RustcVersion;
|
use rustc_semver::RustcVersion;
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
use rustc_span::symbol::SymbolStr;
|
use rustc_span::symbol::Symbol;
|
||||||
use rustc_span::{sym, Span};
|
use rustc_span::{sym, Span};
|
||||||
use rustc_typeck::hir_ty_to_ty;
|
use rustc_typeck::hir_ty_to_ty;
|
||||||
|
|
||||||
@ -1968,21 +1968,21 @@ impl_lint_pass!(Methods => [
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
/// Extracts a method call name, args, and `Span` of the method name.
|
/// Extracts a method call name, args, and `Span` of the method name.
|
||||||
fn method_call<'tcx>(recv: &'tcx hir::Expr<'tcx>) -> Option<(SymbolStr, &'tcx [hir::Expr<'tcx>], Span)> {
|
fn method_call<'tcx>(recv: &'tcx hir::Expr<'tcx>) -> Option<(Symbol, &'tcx [hir::Expr<'tcx>], Span)> {
|
||||||
if let ExprKind::MethodCall(path, span, args, _) = recv.kind {
|
if let ExprKind::MethodCall(path, span, args, _) = recv.kind {
|
||||||
if !args.iter().any(|e| e.span.from_expansion()) {
|
if !args.iter().any(|e| e.span.from_expansion()) {
|
||||||
return Some((path.ident.name.as_str(), args, span));
|
return Some((path.ident.name, args, span));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as `method_call` but the `SymbolStr` is dereferenced into a temporary `&str`
|
/// Same as `method_call` but the `Symbol` is dereferenced into a temporary `&str`
|
||||||
macro_rules! method_call {
|
macro_rules! method_call {
|
||||||
($expr:expr) => {
|
($expr:expr) => {
|
||||||
method_call($expr)
|
method_call($expr)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|&(ref name, args, span)| (&**name, args, span))
|
.map(|&(ref name, args, span)| (name.as_str(), args, span))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,6 +407,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
|
|||||||
// Don't lint things expanded by #[derive(...)], etc or `await` desugaring
|
// Don't lint things expanded by #[derive(...)], etc or `await` desugaring
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let sym;
|
||||||
let binding = match expr.kind {
|
let binding = match expr.kind {
|
||||||
ExprKind::Path(ref qpath) if !matches!(qpath, hir::QPath::LangItem(..)) => {
|
ExprKind::Path(ref qpath) if !matches!(qpath, hir::QPath::LangItem(..)) => {
|
||||||
let binding = last_path_segment(qpath).ident.as_str();
|
let binding = last_path_segment(qpath).ident.as_str();
|
||||||
@ -423,7 +424,8 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ExprKind::Field(_, ident) => {
|
ExprKind::Field(_, ident) => {
|
||||||
let name = ident.as_str();
|
sym = ident.name;
|
||||||
|
let name = sym.as_str();
|
||||||
if name.starts_with('_') && !name.starts_with("__") {
|
if name.starts_with('_') && !name.starts_with("__") {
|
||||||
Some(name)
|
Some(name)
|
||||||
} else {
|
} else {
|
||||||
|
@ -48,7 +48,7 @@ impl LateLintPass<'_> for MultipleCrateVersions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let metadata = unwrap_cargo_metadata!(cx, MULTIPLE_CRATE_VERSIONS, true);
|
let metadata = unwrap_cargo_metadata!(cx, MULTIPLE_CRATE_VERSIONS, true);
|
||||||
let local_name = cx.tcx.crate_name(LOCAL_CRATE).as_str();
|
let local_name = cx.tcx.crate_name(LOCAL_CRATE);
|
||||||
let mut packages = metadata.packages;
|
let mut packages = metadata.packages;
|
||||||
packages.sort_by(|a, b| a.name.cmp(&b.name));
|
packages.sort_by(|a, b| a.name.cmp(&b.name));
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ impl LateLintPass<'_> for MultipleCrateVersions {
|
|||||||
if let Some(resolve) = &metadata.resolve;
|
if let Some(resolve) = &metadata.resolve;
|
||||||
if let Some(local_id) = packages
|
if let Some(local_id) = packages
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|p| if p.name == *local_name { Some(&p.id) } else { None });
|
.find_map(|p| if p.name == local_name.as_str() { Some(&p.id) } else { None });
|
||||||
then {
|
then {
|
||||||
for (name, group) in &packages.iter().group_by(|p| p.name.clone()) {
|
for (name, group) in &packages.iter().group_by(|p| p.name.clone()) {
|
||||||
let group: Vec<&Package> = group.collect();
|
let group: Vec<&Package> = group.collect();
|
||||||
|
@ -319,8 +319,8 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
|||||||
if let ExprKind::Path(qpath) = &callee.kind;
|
if let ExprKind::Path(qpath) = &callee.kind;
|
||||||
let res = self.typeck_results.qpath_res(qpath, callee.hir_id);
|
let res = self.typeck_results.qpath_res(qpath, callee.hir_id);
|
||||||
if let Some(def_id) = res.opt_def_id();
|
if let Some(def_id) = res.opt_def_id();
|
||||||
let def_path: Vec<_> = self.lcx.get_def_path(def_id).into_iter().map(Symbol::as_str).collect();
|
let def_path = self.lcx.get_def_path(def_id);
|
||||||
let def_path: Vec<&str> = def_path.iter().take(4).map(|s| &**s).collect();
|
let def_path: Vec<&str> = def_path.iter().take(4).map(|s| s.as_str()).collect();
|
||||||
if let ["core", "num", int_impl, "max_value"] = *def_path;
|
if let ["core", "num", int_impl, "max_value"] = *def_path;
|
||||||
then {
|
then {
|
||||||
let value = match int_impl {
|
let value = match int_impl {
|
||||||
|
Loading…
Reference in New Issue
Block a user