Rollup merge of #99342 - TaKO8Ki:avoid-symbol-to-string-conversions, r=compiler-errors
Avoid some `Symbol` to `String` conversions This patch removes some Symbol to String conversions.
This commit is contained in:
commit
6277ac2fb8
18 changed files with 50 additions and 59 deletions
|
@ -23,7 +23,7 @@ use rustc_middle::ty::{
|
||||||
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
|
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
|
||||||
use rustc_span::hygiene::DesugaringKind;
|
use rustc_span::hygiene::DesugaringKind;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::{BytePos, Span};
|
use rustc_span::{BytePos, Span, Symbol};
|
||||||
use rustc_trait_selection::infer::InferCtxtExt;
|
use rustc_trait_selection::infer::InferCtxtExt;
|
||||||
use rustc_trait_selection::traits::TraitEngineExt as _;
|
use rustc_trait_selection::traits::TraitEngineExt as _;
|
||||||
|
|
||||||
|
@ -1227,8 +1227,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
from_closure: false,
|
from_closure: false,
|
||||||
region_name:
|
region_name:
|
||||||
RegionName {
|
RegionName {
|
||||||
source:
|
source: RegionNameSource::AnonRegionFromUpvar(upvar_span, upvar_name),
|
||||||
RegionNameSource::AnonRegionFromUpvar(upvar_span, ref upvar_name),
|
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
span,
|
span,
|
||||||
|
@ -1762,7 +1761,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
borrow_span: Span,
|
borrow_span: Span,
|
||||||
name: &Option<String>,
|
name: &Option<String>,
|
||||||
upvar_span: Span,
|
upvar_span: Span,
|
||||||
upvar_name: &str,
|
upvar_name: Symbol,
|
||||||
escape_span: Span,
|
escape_span: Span,
|
||||||
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
|
||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
|
|
|
@ -12,7 +12,7 @@ use rustc_middle::mir::{
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::adjustment::PointerCast;
|
use rustc_middle::ty::adjustment::PointerCast;
|
||||||
use rustc_middle::ty::{self, RegionVid, TyCtxt};
|
use rustc_middle::ty::{self, RegionVid, TyCtxt};
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::{kw, Symbol};
|
||||||
use rustc_span::{sym, DesugaringKind, Span};
|
use rustc_span::{sym, DesugaringKind, Span};
|
||||||
|
|
||||||
use crate::region_infer::BlameConstraint;
|
use crate::region_infer::BlameConstraint;
|
||||||
|
@ -282,7 +282,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||||
) {
|
) {
|
||||||
if let ConstraintCategory::OpaqueType = category {
|
if let ConstraintCategory::OpaqueType = category {
|
||||||
let suggestable_name =
|
let suggestable_name =
|
||||||
if region_name.was_named() { region_name.to_string() } else { "'_".to_string() };
|
if region_name.was_named() { region_name.name } else { kw::UnderscoreLifetime };
|
||||||
|
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"you can add a bound to the {}to make it last less than `'static` and match `{}`",
|
"you can add a bound to the {}to make it last less than `'static` and match `{}`",
|
||||||
|
|
|
@ -19,8 +19,7 @@ use rustc_middle::ty::subst::InternalSubsts;
|
||||||
use rustc_middle::ty::Region;
|
use rustc_middle::ty::Region;
|
||||||
use rustc_middle::ty::TypeVisitor;
|
use rustc_middle::ty::TypeVisitor;
|
||||||
use rustc_middle::ty::{self, RegionVid, Ty};
|
use rustc_middle::ty::{self, RegionVid, Ty};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::{kw, sym, Ident};
|
||||||
use rustc_span::symbol::Ident;
|
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
use crate::borrowck_errors;
|
use crate::borrowck_errors;
|
||||||
|
@ -758,7 +757,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let lifetime = if f.has_name() { fr_name.to_string() } else { "'_".to_string() };
|
let lifetime = if f.has_name() { fr_name.name } else { kw::UnderscoreLifetime };
|
||||||
|
|
||||||
let arg = match param.param.pat.simple_ident() {
|
let arg = match param.param.pat.simple_ident() {
|
||||||
Some(simple_ident) => format!("argument `{}`", simple_ident),
|
Some(simple_ident) => format!("argument `{}`", simple_ident),
|
||||||
|
@ -770,7 +769,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
self.infcx.tcx,
|
self.infcx.tcx,
|
||||||
diag,
|
diag,
|
||||||
fn_returns,
|
fn_returns,
|
||||||
lifetime,
|
lifetime.to_string(),
|
||||||
Some(arg),
|
Some(arg),
|
||||||
captures,
|
captures,
|
||||||
Some((param.param_ty_span, param.param_ty.to_string())),
|
Some((param.param_ty_span, param.param_ty.to_string())),
|
||||||
|
|
|
@ -34,13 +34,13 @@ pub(crate) enum RegionNameSource {
|
||||||
/// The `'static` region.
|
/// The `'static` region.
|
||||||
Static,
|
Static,
|
||||||
/// The free region corresponding to the environment of a closure.
|
/// The free region corresponding to the environment of a closure.
|
||||||
SynthesizedFreeEnvRegion(Span, String),
|
SynthesizedFreeEnvRegion(Span, &'static str),
|
||||||
/// The region corresponding to an argument.
|
/// The region corresponding to an argument.
|
||||||
AnonRegionFromArgument(RegionNameHighlight),
|
AnonRegionFromArgument(RegionNameHighlight),
|
||||||
/// The region corresponding to a closure upvar.
|
/// The region corresponding to a closure upvar.
|
||||||
AnonRegionFromUpvar(Span, String),
|
AnonRegionFromUpvar(Span, Symbol),
|
||||||
/// The region corresponding to the return type of a closure.
|
/// The region corresponding to the return type of a closure.
|
||||||
AnonRegionFromOutput(RegionNameHighlight, String),
|
AnonRegionFromOutput(RegionNameHighlight, &'static str),
|
||||||
/// The region from a type yielded by a generator.
|
/// The region from a type yielded by a generator.
|
||||||
AnonRegionFromYieldTy(Span, String),
|
AnonRegionFromYieldTy(Span, String),
|
||||||
/// An anonymous region from an async fn.
|
/// An anonymous region from an async fn.
|
||||||
|
@ -110,7 +110,7 @@ impl RegionName {
|
||||||
}
|
}
|
||||||
RegionNameSource::SynthesizedFreeEnvRegion(span, note) => {
|
RegionNameSource::SynthesizedFreeEnvRegion(span, note) => {
|
||||||
diag.span_label(*span, format!("lifetime `{self}` represents this closure's body"));
|
diag.span_label(*span, format!("lifetime `{self}` represents this closure's body"));
|
||||||
diag.note(note);
|
diag.note(*note);
|
||||||
}
|
}
|
||||||
RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::CannotMatchHirTy(
|
RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::CannotMatchHirTy(
|
||||||
span,
|
span,
|
||||||
|
@ -350,10 +350,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
||||||
|
|
||||||
Some(RegionName {
|
Some(RegionName {
|
||||||
name: region_name,
|
name: region_name,
|
||||||
source: RegionNameSource::SynthesizedFreeEnvRegion(
|
source: RegionNameSource::SynthesizedFreeEnvRegion(fn_decl_span, note),
|
||||||
fn_decl_span,
|
|
||||||
note.to_string(),
|
|
||||||
),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,7 +675,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
||||||
|
|
||||||
Some(RegionName {
|
Some(RegionName {
|
||||||
name: region_name,
|
name: region_name,
|
||||||
source: RegionNameSource::AnonRegionFromUpvar(upvar_span, upvar_name.to_string()),
|
source: RegionNameSource::AnonRegionFromUpvar(upvar_span, upvar_name),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -756,7 +753,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
||||||
|
|
||||||
Some(RegionName {
|
Some(RegionName {
|
||||||
name: self.synthesize_region_name(),
|
name: self.synthesize_region_name(),
|
||||||
source: RegionNameSource::AnonRegionFromOutput(highlight, mir_description.to_string()),
|
source: RegionNameSource::AnonRegionFromOutput(highlight, mir_description),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -453,7 +453,7 @@ impl Diagnostic {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn note_trait_signature(&mut self, name: String, signature: String) -> &mut Self {
|
pub fn note_trait_signature(&mut self, name: Symbol, signature: String) -> &mut Self {
|
||||||
self.highlighted_note(vec![
|
self.highlighted_note(vec![
|
||||||
(format!("`{}` from trait: `", name), Style::NoStyle),
|
(format!("`{}` from trait: `", name), Style::NoStyle),
|
||||||
(signature, Style::Highlight),
|
(signature, Style::Highlight),
|
||||||
|
|
|
@ -218,10 +218,9 @@ pub fn default_submod_path<'a>(
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
|
||||||
let mod_name = ident.name.to_string();
|
let default_path_str = format!("{}{}.rs", relative_prefix, ident.name);
|
||||||
let default_path_str = format!("{}{}.rs", relative_prefix, mod_name);
|
|
||||||
let secondary_path_str =
|
let secondary_path_str =
|
||||||
format!("{}{}{}mod.rs", relative_prefix, mod_name, path::MAIN_SEPARATOR);
|
format!("{}{}{}mod.rs", relative_prefix, ident.name, path::MAIN_SEPARATOR);
|
||||||
let default_path = dir_path.join(&default_path_str);
|
let default_path = dir_path.join(&default_path_str);
|
||||||
let secondary_path = dir_path.join(&secondary_path_str);
|
let secondary_path = dir_path.join(&secondary_path_str);
|
||||||
let default_exists = sess.source_map().file_exists(&default_path);
|
let default_exists = sess.source_map().file_exists(&default_path);
|
||||||
|
|
|
@ -138,7 +138,7 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'_, 'tcx>, ns: Namespace) -> FmtPr
|
||||||
if let TypeVariableOriginKind::TypeParameterDefinition(name, _) =
|
if let TypeVariableOriginKind::TypeParameterDefinition(name, _) =
|
||||||
infcx.inner.borrow_mut().type_variables().var_origin(ty_vid).kind
|
infcx.inner.borrow_mut().type_variables().var_origin(ty_vid).kind
|
||||||
{
|
{
|
||||||
Some(name.to_string())
|
Some(name)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'_, 'tcx>, ns: Namespace) -> FmtPr
|
||||||
if let ConstVariableOriginKind::ConstParameterDefinition(name, _) =
|
if let ConstVariableOriginKind::ConstParameterDefinition(name, _) =
|
||||||
infcx.inner.borrow_mut().const_unification_table().probe_value(ct_vid).origin.kind
|
infcx.inner.borrow_mut().const_unification_table().probe_value(ct_vid).origin.kind
|
||||||
{
|
{
|
||||||
return Some(name.to_string());
|
return Some(name);
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -1975,7 +1975,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
min_size = field_end;
|
min_size = field_end;
|
||||||
}
|
}
|
||||||
FieldInfo {
|
FieldInfo {
|
||||||
name: name.to_string(),
|
name,
|
||||||
offset: offset.bytes(),
|
offset: offset.bytes(),
|
||||||
size: field_layout.size.bytes(),
|
size: field_layout.size.bytes(),
|
||||||
align: field_layout.align.abi.bytes(),
|
align: field_layout.align.abi.bytes(),
|
||||||
|
@ -1984,7 +1984,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
VariantInfo {
|
VariantInfo {
|
||||||
name: n.map(|n| n.to_string()),
|
name: n,
|
||||||
kind: if layout.is_unsized() { SizeKind::Min } else { SizeKind::Exact },
|
kind: if layout.is_unsized() { SizeKind::Min } else { SizeKind::Exact },
|
||||||
align: layout.align.abi.bytes(),
|
align: layout.align.abi.bytes(),
|
||||||
size: if min_size.bytes() == 0 { layout.size.bytes() } else { min_size.bytes() },
|
size: if min_size.bytes() == 0 { layout.size.bytes() } else { min_size.bytes() },
|
||||||
|
|
|
@ -1030,11 +1030,11 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ty_infer_name(&self, _: ty::TyVid) -> Option<String> {
|
fn ty_infer_name(&self, _: ty::TyVid) -> Option<Symbol> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn const_infer_name(&self, _: ty::ConstVid<'tcx>) -> Option<String> {
|
fn const_infer_name(&self, _: ty::ConstVid<'tcx>) -> Option<Symbol> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1550,8 +1550,8 @@ pub struct FmtPrinterData<'a, 'tcx> {
|
||||||
|
|
||||||
pub region_highlight_mode: RegionHighlightMode<'tcx>,
|
pub region_highlight_mode: RegionHighlightMode<'tcx>,
|
||||||
|
|
||||||
pub ty_infer_name_resolver: Option<Box<dyn Fn(ty::TyVid) -> Option<String> + 'a>>,
|
pub ty_infer_name_resolver: Option<Box<dyn Fn(ty::TyVid) -> Option<Symbol> + 'a>>,
|
||||||
pub const_infer_name_resolver: Option<Box<dyn Fn(ty::ConstVid<'tcx>) -> Option<String> + 'a>>,
|
pub const_infer_name_resolver: Option<Box<dyn Fn(ty::ConstVid<'tcx>) -> Option<Symbol> + 'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> Deref for FmtPrinter<'a, 'tcx> {
|
impl<'a, 'tcx> Deref for FmtPrinter<'a, 'tcx> {
|
||||||
|
@ -1841,11 +1841,11 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
|
impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||||
fn ty_infer_name(&self, id: ty::TyVid) -> Option<String> {
|
fn ty_infer_name(&self, id: ty::TyVid) -> Option<Symbol> {
|
||||||
self.0.ty_infer_name_resolver.as_ref().and_then(|func| func(id))
|
self.0.ty_infer_name_resolver.as_ref().and_then(|func| func(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn const_infer_name(&self, id: ty::ConstVid<'tcx>) -> Option<String> {
|
fn const_infer_name(&self, id: ty::ConstVid<'tcx>) -> Option<Symbol> {
|
||||||
self.0.const_infer_name_resolver.as_ref().and_then(|func| func(id))
|
self.0.const_infer_name_resolver.as_ref().and_then(|func| func(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_data_structures::sync::Lock;
|
use rustc_data_structures::sync::Lock;
|
||||||
|
use rustc_span::Symbol;
|
||||||
use rustc_target::abi::{Align, Size};
|
use rustc_target::abi::{Align, Size};
|
||||||
use std::cmp::{self, Ordering};
|
use std::cmp::{self, Ordering};
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||||
pub struct VariantInfo {
|
pub struct VariantInfo {
|
||||||
pub name: Option<String>,
|
pub name: Option<Symbol>,
|
||||||
pub kind: SizeKind,
|
pub kind: SizeKind,
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
pub align: u64,
|
pub align: u64,
|
||||||
|
@ -20,7 +21,7 @@ pub enum SizeKind {
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||||
pub struct FieldInfo {
|
pub struct FieldInfo {
|
||||||
pub name: String,
|
pub name: Symbol,
|
||||||
pub offset: u64,
|
pub offset: u64,
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
pub align: u64,
|
pub align: u64,
|
||||||
|
@ -119,7 +120,7 @@ impl CodeStats {
|
||||||
let VariantInfo { ref name, kind: _, align: _, size, ref fields } = *variant_info;
|
let VariantInfo { ref name, kind: _, align: _, size, ref fields } = *variant_info;
|
||||||
let indent = if !struct_like {
|
let indent = if !struct_like {
|
||||||
let name = match name.as_ref() {
|
let name = match name.as_ref() {
|
||||||
Some(name) => name.to_owned(),
|
Some(name) => name.to_string(),
|
||||||
None => i.to_string(),
|
None => i.to_string(),
|
||||||
};
|
};
|
||||||
println!(
|
println!(
|
||||||
|
|
|
@ -2486,7 +2486,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
concrete type's name `{type_name}` instead if you want to \
|
concrete type's name `{type_name}` instead if you want to \
|
||||||
specify its type parameters"
|
specify its type parameters"
|
||||||
),
|
),
|
||||||
type_name.to_string(),
|
type_name,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -544,7 +544,7 @@ fn compare_self_type<'tcx>(
|
||||||
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
|
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
|
||||||
err.span_label(span, format!("trait method declared without `{self_descr}`"));
|
err.span_label(span, format!("trait method declared without `{self_descr}`"));
|
||||||
} else {
|
} else {
|
||||||
err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
|
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
|
||||||
}
|
}
|
||||||
let reported = err.emit();
|
let reported = err.emit();
|
||||||
return Err(reported);
|
return Err(reported);
|
||||||
|
@ -564,7 +564,7 @@ fn compare_self_type<'tcx>(
|
||||||
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
|
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
|
||||||
err.span_label(span, format!("`{self_descr}` used in trait"));
|
err.span_label(span, format!("`{self_descr}` used in trait"));
|
||||||
} else {
|
} else {
|
||||||
err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
|
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
|
||||||
}
|
}
|
||||||
let reported = err.emit();
|
let reported = err.emit();
|
||||||
return Err(reported);
|
return Err(reported);
|
||||||
|
@ -803,7 +803,7 @@ fn compare_number_of_method_arguments<'tcx>(
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
|
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
|
||||||
}
|
}
|
||||||
err.span_label(
|
err.span_label(
|
||||||
impl_span,
|
impl_span,
|
||||||
|
|
|
@ -1856,7 +1856,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let remaining_private_fields_len = remaining_private_fields.len();
|
let remaining_private_fields_len = remaining_private_fields.len();
|
||||||
let names = match &remaining_private_fields
|
let names = match &remaining_private_fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(name, _, _)| name.to_string())
|
.map(|(name, _, _)| name)
|
||||||
.collect::<Vec<_>>()[..]
|
.collect::<Vec<_>>()[..]
|
||||||
{
|
{
|
||||||
_ if remaining_private_fields_len > 6 => String::new(),
|
_ if remaining_private_fields_len > 6 => String::new(),
|
||||||
|
|
|
@ -19,6 +19,7 @@ use rustc_middle::ty::print::with_crate_prefix;
|
||||||
use rustc_middle::ty::ToPolyTraitRef;
|
use rustc_middle::ty::ToPolyTraitRef;
|
||||||
use rustc_middle::ty::{self, DefIdTree, ToPredicate, Ty, TyCtxt, TypeVisitable};
|
use rustc_middle::ty::{self, DefIdTree, ToPredicate, Ty, TyCtxt, TypeVisitable};
|
||||||
use rustc_span::symbol::{kw, sym, Ident};
|
use rustc_span::symbol::{kw, sym, Ident};
|
||||||
|
use rustc_span::Symbol;
|
||||||
use rustc_span::{lev_distance, source_map, ExpnKind, FileName, MacroKind, Span};
|
use rustc_span::{lev_distance, source_map, ExpnKind, FileName, MacroKind, Span};
|
||||||
use rustc_trait_selection::traits::error_reporting::on_unimplemented::InferCtxtExt as _;
|
use rustc_trait_selection::traits::error_reporting::on_unimplemented::InferCtxtExt as _;
|
||||||
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
|
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
|
||||||
|
@ -1548,7 +1549,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
Option<ObligationCause<'tcx>>,
|
Option<ObligationCause<'tcx>>,
|
||||||
)],
|
)],
|
||||||
) {
|
) {
|
||||||
let mut derives = Vec::<(String, Span, String)>::new();
|
let mut derives = Vec::<(String, Span, Symbol)>::new();
|
||||||
let mut traits = Vec::<Span>::new();
|
let mut traits = Vec::<Span>::new();
|
||||||
for (pred, _, _) in unsatisfied_predicates {
|
for (pred, _, _) in unsatisfied_predicates {
|
||||||
let ty::PredicateKind::Trait(trait_pred) = pred.kind().skip_binder() else { continue };
|
let ty::PredicateKind::Trait(trait_pred) = pred.kind().skip_binder() else { continue };
|
||||||
|
@ -1581,12 +1582,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
derives.push((
|
derives.push((
|
||||||
self_name.clone(),
|
self_name.clone(),
|
||||||
self_span,
|
self_span,
|
||||||
parent_diagnostic_name.to_string(),
|
parent_diagnostic_name,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
derives.push((self_name, self_span, diagnostic_name.to_string()));
|
derives.push((self_name, self_span, diagnostic_name));
|
||||||
} else {
|
} else {
|
||||||
traits.push(self.tcx.def_span(trait_pred.def_id()));
|
traits.push(self.tcx.def_span(trait_pred.def_id()));
|
||||||
}
|
}
|
||||||
|
@ -1609,7 +1610,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
derives_grouped.push((self_name, self_span, trait_name));
|
derives_grouped.push((self_name, self_span, trait_name.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let len = traits.len();
|
let len = traits.len();
|
||||||
|
|
|
@ -17,7 +17,7 @@ use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_middle::ty::query::Providers;
|
use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::{self, TyCtxt, TypeVisitable};
|
use rustc_middle::ty::{self, TyCtxt, TypeVisitable};
|
||||||
use rustc_span::Span;
|
use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||||
|
|
||||||
|
@ -123,12 +123,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
|
||||||
ty::GenericParamDefKind::Type { .. } => {
|
ty::GenericParamDefKind::Type { .. } => {
|
||||||
let param_ty = ty::ParamTy::for_def(param);
|
let param_ty = ty::ParamTy::for_def(param);
|
||||||
if !input_parameters.contains(&cgp::Parameter::from(param_ty)) {
|
if !input_parameters.contains(&cgp::Parameter::from(param_ty)) {
|
||||||
report_unused_parameter(
|
report_unused_parameter(tcx, tcx.def_span(param.def_id), "type", param_ty.name);
|
||||||
tcx,
|
|
||||||
tcx.def_span(param.def_id),
|
|
||||||
"type",
|
|
||||||
¶m_ty.to_string(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::GenericParamDefKind::Lifetime => {
|
ty::GenericParamDefKind::Lifetime => {
|
||||||
|
@ -140,7 +135,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
|
||||||
tcx,
|
tcx,
|
||||||
tcx.def_span(param.def_id),
|
tcx.def_span(param.def_id),
|
||||||
"lifetime",
|
"lifetime",
|
||||||
¶m.name.to_string(),
|
param.name,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +146,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
|
||||||
tcx,
|
tcx,
|
||||||
tcx.def_span(param.def_id),
|
tcx.def_span(param.def_id),
|
||||||
"const",
|
"const",
|
||||||
¶m_ct.to_string(),
|
param_ct.name,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,7 +173,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
|
||||||
// used elsewhere are not projected back out.
|
// used elsewhere are not projected back out.
|
||||||
}
|
}
|
||||||
|
|
||||||
fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: &str) {
|
fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: Symbol) {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
tcx.sess,
|
tcx.sess,
|
||||||
span,
|
span,
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat {
|
||||||
then {
|
then {
|
||||||
let is_new_string = match value.kind {
|
let is_new_string = match value.kind {
|
||||||
ExprKind::Binary(..) => true,
|
ExprKind::Binary(..) => true,
|
||||||
ExprKind::MethodCall(path, ..) => path.ident.name.as_str() == "to_string",
|
ExprKind::MethodCall(path, ..) => path.ident.name == sym::to_string,
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
let sugg = if format_args.format_string_span.contains(value.span) {
|
let sugg = if format_args.format_string_span.contains(value.span) {
|
||||||
|
|
|
@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
// Check if item is a method, called to_string and has a parameter 'self'
|
// Check if item is a method, called to_string and has a parameter 'self'
|
||||||
if let ImplItemKind::Fn(ref signature, _) = impl_item.kind;
|
if let ImplItemKind::Fn(ref signature, _) = impl_item.kind;
|
||||||
if impl_item.ident.name.as_str() == "to_string";
|
if impl_item.ident.name == sym::to_string;
|
||||||
let decl = &signature.decl;
|
let decl = &signature.decl;
|
||||||
if decl.implicit_self.has_implicit_self();
|
if decl.implicit_self.has_implicit_self();
|
||||||
if decl.inputs.len() == 1;
|
if decl.inputs.len() == 1;
|
||||||
|
|
|
@ -427,5 +427,5 @@ fn is_cow_into_owned(cx: &LateContext<'_>, method_name: Symbol, method_def_id: D
|
||||||
|
|
||||||
/// Returns true if the named method is `ToString::to_string`.
|
/// Returns true if the named method is `ToString::to_string`.
|
||||||
fn is_to_string(cx: &LateContext<'_>, method_name: Symbol, method_def_id: DefId) -> bool {
|
fn is_to_string(cx: &LateContext<'_>, method_name: Symbol, method_def_id: DefId) -> bool {
|
||||||
method_name.as_str() == "to_string" && is_diag_trait_item(cx, method_def_id, sym::ToString)
|
method_name == sym::to_string && is_diag_trait_item(cx, method_def_id, sym::ToString)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue