Skip to content

Commit c5ecc15

Browse files
committed
Auto merge of #91962 - matthiaskrgr:rollup-2g082jw, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #91880 (fix clippy::single_char_pattern perf findings) - #91885 (Remove `in_band_lifetimes` from `rustc_codegen_ssa`) - #91898 (Make `TyS::is_suggestable` check for non-suggestable types structually) - #91915 (Add another regression test for unnormalized fn args with Self) - #91916 (Fix a bunch of typos) - #91918 (Constify `bool::then{,_some}`) - #91920 (Use `tcx.def_path_hash` in `ExistentialPredicate.stable_cmp`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3ee016a + 990cf5b commit c5ecc15

File tree

92 files changed

+283
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+283
-210
lines changed

Diff for: compiler/rustc_codegen_ssa/src/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2226,8 +2226,8 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
22262226
continue;
22272227
}
22282228

2229-
let canonical = f.replace("-", "_");
2230-
let canonical_name = name.replace("-", "_");
2229+
let canonical = f.replace('-', "_");
2230+
let canonical_name = name.replace('-', "_");
22312231

22322232
let is_rust_object =
22332233
canonical.starts_with(&canonical_name) && looks_like_rust_object_file(&f);

Diff for: compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b
154154
tcx.reachable_non_generics(def_id.krate).contains_key(&def_id)
155155
}
156156

157-
fn exported_symbols_provider_local(
157+
fn exported_symbols_provider_local<'tcx>(
158158
tcx: TyCtxt<'tcx>,
159159
cnum: CrateNum,
160160
) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {

Diff for: compiler/rustc_codegen_ssa/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
486486

487487
pub fn codegen_crate<B: ExtraBackendMethods>(
488488
backend: B,
489-
tcx: TyCtxt<'tcx>,
489+
tcx: TyCtxt<'_>,
490490
target_cpu: String,
491491
metadata: EncodedMetadata,
492492
need_metadata_module: bool,

Diff for: compiler/rustc_codegen_ssa/src/coverageinfo/map.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ impl<'tcx> FunctionCoverage<'tcx> {
150150
/// Generate an array of CounterExpressions, and an iterator over all `Counter`s and their
151151
/// associated `Regions` (from which the LLVM-specific `CoverageMapGenerator` will create
152152
/// `CounterMappingRegion`s.
153-
pub fn get_expressions_and_counter_regions<'a>(
154-
&'a self,
155-
) -> (Vec<CounterExpression>, impl Iterator<Item = (Counter, &'a CodeRegion)>) {
153+
pub fn get_expressions_and_counter_regions(
154+
&self,
155+
) -> (Vec<CounterExpression>, impl Iterator<Item = (Counter, &CodeRegion)>) {
156156
assert!(
157157
self.source_hash != 0 || !self.is_used,
158158
"No counters provided the source_hash for used function: {:?}",
@@ -168,7 +168,7 @@ impl<'tcx> FunctionCoverage<'tcx> {
168168
(counter_expressions, counter_regions)
169169
}
170170

171-
fn counter_regions<'a>(&'a self) -> impl Iterator<Item = (Counter, &'a CodeRegion)> {
171+
fn counter_regions(&self) -> impl Iterator<Item = (Counter, &CodeRegion)> {
172172
self.counters.iter_enumerated().filter_map(|(index, entry)| {
173173
// Option::map() will return None to filter out missing counters. This may happen
174174
// if, for example, a MIR-instrumented counter is removed during an optimization.
@@ -177,8 +177,8 @@ impl<'tcx> FunctionCoverage<'tcx> {
177177
}
178178

179179
fn expressions_with_regions(
180-
&'a self,
181-
) -> (Vec<CounterExpression>, impl Iterator<Item = (Counter, &'a CodeRegion)>) {
180+
&self,
181+
) -> (Vec<CounterExpression>, impl Iterator<Item = (Counter, &CodeRegion)>) {
182182
let mut counter_expressions = Vec::with_capacity(self.expressions.len());
183183
let mut expression_regions = Vec::with_capacity(self.expressions.len());
184184
let mut new_indexes = IndexVec::from_elem_n(None, self.expressions.len());
@@ -336,7 +336,7 @@ impl<'tcx> FunctionCoverage<'tcx> {
336336
(counter_expressions, expression_regions.into_iter())
337337
}
338338

339-
fn unreachable_regions<'a>(&'a self) -> impl Iterator<Item = (Counter, &'a CodeRegion)> {
339+
fn unreachable_regions(&self) -> impl Iterator<Item = (Counter, &CodeRegion)> {
340340
self.unreachable_regions.iter().map(|region| (Counter::zero(), region))
341341
}
342342

Diff for: compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ fn push_debuginfo_type_name<'tcx>(
376376
// format (natvis) is able to understand enums and render the active variant correctly in the
377377
// debugger. For more information, look in `src/etc/natvis/intrinsic.natvis` and
378378
// `EnumMemberDescriptionFactor::create_member_descriptions`.
379-
fn msvc_enum_fallback(
379+
fn msvc_enum_fallback<'tcx>(
380380
tcx: TyCtxt<'tcx>,
381381
ty: Ty<'tcx>,
382382
def: &AdtDef,
@@ -496,7 +496,7 @@ pub fn compute_debuginfo_vtable_name<'tcx>(
496496
vtable_name
497497
}
498498

499-
pub fn push_item_name(tcx: TyCtxt<'tcx>, def_id: DefId, qualified: bool, output: &mut String) {
499+
pub fn push_item_name(tcx: TyCtxt<'_>, def_id: DefId, qualified: bool, output: &mut String) {
500500
let def_key = tcx.def_key(def_id);
501501
if qualified {
502502
if let Some(parent) = def_key.parent {
@@ -509,7 +509,7 @@ pub fn push_item_name(tcx: TyCtxt<'tcx>, def_id: DefId, qualified: bool, output:
509509
}
510510

511511
fn push_unqualified_item_name(
512-
tcx: TyCtxt<'tcx>,
512+
tcx: TyCtxt<'_>,
513513
def_id: DefId,
514514
disambiguated_data: DisambiguatedDefPathData,
515515
output: &mut String,

Diff for: compiler/rustc_codegen_ssa/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![feature(bool_to_option)]
33
#![feature(box_patterns)]
44
#![feature(try_blocks)]
5-
#![feature(in_band_lifetimes)]
65
#![feature(let_else)]
76
#![feature(once_cell)]
87
#![feature(nll)]

Diff for: compiler/rustc_codegen_ssa/src/mir/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
7373
locals: IndexVec<mir::Local, LocalKind>,
7474
}
7575

76-
impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
76+
impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
7777
fn assign(&mut self, local: mir::Local, location: Location) {
7878
let kind = &mut self.locals[local];
7979
match *kind {

Diff for: compiler/rustc_codegen_ssa/src/mir/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub struct OperandRef<'tcx, V> {
4747
pub layout: TyAndLayout<'tcx>,
4848
}
4949

50-
impl<V: CodegenObject> fmt::Debug for OperandRef<'tcx, V> {
50+
impl<V: CodegenObject> fmt::Debug for OperandRef<'_, V> {
5151
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5252
write!(f, "OperandRef({:?} @ {:?})", self.val, self.layout)
5353
}

Diff for: compiler/rustc_codegen_ssa/src/traits/type_.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
9797
}
9898
}
9999

100-
impl<T> DerivedTypeMethods<'tcx> for T where Self: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {}
100+
impl<'tcx, T> DerivedTypeMethods<'tcx> for T where Self: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {}
101101

102102
pub trait LayoutTypeMethods<'tcx>: Backend<'tcx> {
103103
fn backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type;
@@ -135,4 +135,4 @@ pub trait ArgAbiMethods<'tcx>: HasCodegen<'tcx> {
135135

136136
pub trait TypeMethods<'tcx>: DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx> {}
137137

138-
impl<T> TypeMethods<'tcx> for T where Self: DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx> {}
138+
impl<'tcx, T> TypeMethods<'tcx> for T where Self: DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx> {}

Diff for: compiler/rustc_driver/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ Available lint options:
872872

873873
let print_lints = |lints: Vec<&Lint>| {
874874
for lint in lints {
875-
let name = lint.name_lower().replace("_", "-");
875+
let name = lint.name_lower().replace('_', "-");
876876
println!(
877877
" {} {:7.7} {}",
878878
padded(&name),
@@ -908,10 +908,10 @@ Available lint options:
908908

909909
let print_lint_groups = |lints: Vec<(&'static str, Vec<LintId>)>| {
910910
for (name, to) in lints {
911-
let name = name.to_lowercase().replace("_", "-");
911+
let name = name.to_lowercase().replace('_', "-");
912912
let desc = to
913913
.into_iter()
914-
.map(|x| x.to_string().replace("_", "-"))
914+
.map(|x| x.to_string().replace('_', "-"))
915915
.collect::<Vec<String>>()
916916
.join(", ");
917917
println!(" {} {}", padded(&name), desc);
@@ -960,7 +960,7 @@ fn print_flag_list<T>(
960960
println!(
961961
" {} {:>width$}=val -- {}",
962962
cmdline_opt,
963-
name.replace("_", "-"),
963+
name.replace('_', "-"),
964964
desc,
965965
width = max_len
966966
);
@@ -1015,7 +1015,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
10151015
.iter()
10161016
.map(|&(name, ..)| ('C', name))
10171017
.chain(DB_OPTIONS.iter().map(|&(name, ..)| ('Z', name)))
1018-
.find(|&(_, name)| *opt == name.replace("_", "-"))
1018+
.find(|&(_, name)| *opt == name.replace('_', "-"))
10191019
.map(|(flag, _)| format!("{}. Did you mean `-{} {}`?", e, flag, opt)),
10201020
_ => None,
10211021
};

Diff for: compiler/rustc_graphviz/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ pub trait Labeller<'a> {
472472
/// Escape tags in such a way that it is suitable for inclusion in a
473473
/// Graphviz HTML label.
474474
pub fn escape_html(s: &str) -> String {
475-
s.replace("&", "&amp;").replace("\"", "&quot;").replace("<", "&lt;").replace(">", "&gt;")
475+
s.replace('&', "&amp;").replace('\"', "&quot;").replace('<', "&lt;").replace('>', "&gt;")
476476
}
477477

478478
impl<'a> LabelText<'a> {

Diff for: compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ fn output_conflicts_with_dir(output_paths: &[PathBuf]) -> Option<PathBuf> {
584584
fn escape_dep_filename(filename: &str) -> String {
585585
// Apparently clang and gcc *only* escape spaces:
586586
// https://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4
587-
filename.replace(" ", "\\ ")
587+
filename.replace(' ', "\\ ")
588588
}
589589

590590
// Makefile comments only need escaping newlines and `\`.

Diff for: compiler/rustc_middle/src/lint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub fn struct_lint_level<'s, 'd>(
295295
Level::Allow => "-A",
296296
Level::ForceWarn => "--force-warn",
297297
};
298-
let hyphen_case_lint_name = name.replace("_", "-");
298+
let hyphen_case_lint_name = name.replace('_', "-");
299299
if lint_flag_val.as_str() == name {
300300
sess.diag_note_once(
301301
&mut err,
@@ -306,7 +306,7 @@ pub fn struct_lint_level<'s, 'd>(
306306
),
307307
);
308308
} else {
309-
let hyphen_case_flag_val = lint_flag_val.as_str().replace("_", "-");
309+
let hyphen_case_flag_val = lint_flag_val.as_str().replace('_', "-");
310310
sess.diag_note_once(
311311
&mut err,
312312
DiagnosticMessageId::from(lint),

Diff for: compiler/rustc_middle/src/mir/generic_graphviz.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<
126126
write!(
127127
w,
128128
r#"<tr><td align="left" balign="left">{}</td></tr>"#,
129-
dot::escape_html(&section).replace("\n", "<br/>")
129+
dot::escape_html(&section).replace('\n', "<br/>")
130130
)?;
131131
}
132132

@@ -147,7 +147,7 @@ impl<
147147
let src = self.node(source);
148148
let trg = self.node(target);
149149
let escaped_edge_label = if let Some(edge_label) = edge_labels.get(index) {
150-
dot::escape_html(edge_label).replace("\n", r#"<br align="left"/>"#)
150+
dot::escape_html(edge_label).replace('\n', r#"<br align="left"/>"#)
151151
} else {
152152
"".to_owned()
153153
};

Diff for: compiler/rustc_middle/src/mir/spanview.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -681,13 +681,13 @@ fn hir_body<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<&'tcx rustc_hir::B
681681
}
682682

683683
fn escape_html(s: &str) -> String {
684-
s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
684+
s.replace('&', "&amp;").replace('<', "&lt;").replace('>', "&gt;")
685685
}
686686

687687
fn escape_attr(s: &str) -> String {
688-
s.replace("&", "&amp;")
689-
.replace("\"", "&quot;")
690-
.replace("'", "&#39;")
691-
.replace("<", "&lt;")
692-
.replace(">", "&gt;")
688+
s.replace('&', "&amp;")
689+
.replace('\"', "&quot;")
690+
.replace('\'', "&#39;")
691+
.replace('<', "&lt;")
692+
.replace('>', "&gt;")
693693
}

Diff for: compiler/rustc_middle/src/ty/diagnostics.rs

+54-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
//! Diagnostics related methods for `TyS`.
22
3+
use crate::ty::subst::{GenericArg, GenericArgKind};
34
use crate::ty::TyKind::*;
4-
use crate::ty::{InferTy, TyCtxt, TyS};
5+
use crate::ty::{
6+
ConstKind, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, InferTy,
7+
ProjectionTy, TyCtxt, TyS, TypeAndMut,
8+
};
9+
510
use rustc_errors::{Applicability, DiagnosticBuilder};
611
use rustc_hir as hir;
712
use rustc_hir::def_id::DefId;
@@ -63,16 +68,55 @@ impl<'tcx> TyS<'tcx> {
6368

6469
/// Whether the type can be safely suggested during error recovery.
6570
pub fn is_suggestable(&self) -> bool {
66-
!matches!(
67-
self.kind(),
71+
fn generic_arg_is_suggestible(arg: GenericArg<'_>) -> bool {
72+
match arg.unpack() {
73+
GenericArgKind::Type(ty) => ty.is_suggestable(),
74+
GenericArgKind::Const(c) => const_is_suggestable(c.val),
75+
_ => true,
76+
}
77+
}
78+
79+
fn const_is_suggestable(kind: ConstKind<'_>) -> bool {
80+
match kind {
81+
ConstKind::Infer(..)
82+
| ConstKind::Bound(..)
83+
| ConstKind::Placeholder(..)
84+
| ConstKind::Error(..) => false,
85+
_ => true,
86+
}
87+
}
88+
89+
// FIXME(compiler-errors): Some types are still not good to suggest,
90+
// specifically references with lifetimes within the function. Not
91+
//sure we have enough information to resolve whether a region is
92+
// temporary, so I'll leave this as a fixme.
93+
94+
match self.kind() {
6895
Opaque(..)
69-
| FnDef(..)
70-
| FnPtr(..)
71-
| Dynamic(..)
72-
| Closure(..)
73-
| Infer(..)
74-
| Projection(..)
75-
)
96+
| FnDef(..)
97+
| Closure(..)
98+
| Infer(..)
99+
| Generator(..)
100+
| GeneratorWitness(..)
101+
| Bound(_, _)
102+
| Placeholder(_)
103+
| Error(_) => false,
104+
Dynamic(dty, _) => dty.iter().all(|pred| match pred.skip_binder() {
105+
ExistentialPredicate::Trait(ExistentialTraitRef { substs, .. }) => {
106+
substs.iter().all(generic_arg_is_suggestible)
107+
}
108+
ExistentialPredicate::Projection(ExistentialProjection { substs, ty, .. }) => {
109+
ty.is_suggestable() && substs.iter().all(generic_arg_is_suggestible)
110+
}
111+
_ => true,
112+
}),
113+
Projection(ProjectionTy { substs: args, .. }) | Adt(_, args) | Tuple(args) => {
114+
args.iter().all(generic_arg_is_suggestible)
115+
}
116+
Slice(ty) | RawPtr(TypeAndMut { ty, .. }) | Ref(_, ty, _) => ty.is_suggestable(),
117+
Array(ty, c) => ty.is_suggestable() && const_is_suggestable(c.val),
118+
_ => true,
119+
}
76120
}
77121
}
78122

Diff for: compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ impl<'tcx> ExistentialPredicate<'tcx> {
787787
tcx.def_path_hash(a.item_def_id).cmp(&tcx.def_path_hash(b.item_def_id))
788788
}
789789
(AutoTrait(ref a), AutoTrait(ref b)) => {
790-
tcx.trait_def(*a).def_path_hash.cmp(&tcx.trait_def(*b).def_path_hash)
790+
tcx.def_path_hash(*a).cmp(&tcx.def_path_hash(*b))
791791
}
792792
(Trait(_), _) => Ordering::Less,
793793
(Projection(_), Trait(_)) => Ordering::Greater,

Diff for: compiler/rustc_mir_transform/src/coverage/debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl DebugOptions {
148148
let mut counter_format = ExpressionFormat::default();
149149

150150
if let Ok(env_debug_options) = std::env::var(RUSTC_COVERAGE_DEBUG_OPTIONS) {
151-
for setting_str in env_debug_options.replace(" ", "").replace("-", "_").split(',') {
151+
for setting_str in env_debug_options.replace(' ', "").replace('-', "_").split(',') {
152152
let (option, value) = match setting_str.split_once('=') {
153153
None => (setting_str, None),
154154
Some((k, v)) => (k, Some(v)),

Diff for: compiler/rustc_mir_transform/src/coverage/spans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl CoverageSpan {
155155
format!(
156156
"{}\n {}",
157157
source_range_no_file(tcx, &self.span),
158-
self.format_coverage_statements(tcx, mir_body).replace("\n", "\n "),
158+
self.format_coverage_statements(tcx, mir_body).replace('\n', "\n "),
159159
)
160160
}
161161

Diff for: compiler/rustc_parse/src/parser/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,7 @@ impl<'a> Parser<'a> {
22362236
err.span_suggestion(
22372237
seq_span,
22382238
"...or a vertical bar to match on multiple alternatives",
2239-
seq_snippet.replace(",", " |"),
2239+
seq_snippet.replace(',', " |"),
22402240
Applicability::MachineApplicable,
22412241
);
22422242
}

Diff for: compiler/rustc_save_analysis/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ fn find_config(supplied: Option<Config>) -> Config {
10361036

10371037
// Helper function to escape quotes in a string
10381038
fn escape(s: String) -> String {
1039-
s.replace("\"", "\"\"")
1039+
s.replace('\"', "\"\"")
10401040
}
10411041

10421042
// Helper function to determine if a span came from a

Diff for: compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ pub fn get_cmd_lint_options(
12131213
if lint_name == "help" {
12141214
describe_lints = true;
12151215
} else {
1216-
lint_opts_with_position.push((arg_pos, lint_name.replace("-", "_"), level));
1216+
lint_opts_with_position.push((arg_pos, lint_name.replace('-', "_"), level));
12171217
}
12181218
}
12191219
}

Diff for: compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ fn build_options<O: Default>(
335335
Some((k, v)) => (k.to_string(), Some(v)),
336336
};
337337

338-
let option_to_lookup = key.replace("-", "_");
338+
let option_to_lookup = key.replace('-', "_");
339339
match descrs.iter().find(|(name, ..)| *name == option_to_lookup) {
340340
Some((_, setter, type_desc, _)) => {
341341
if !setter(&mut op, value) {

0 commit comments

Comments
 (0)