From d2402e3f0d91ef286b3f797ccf09cdeff382f68c Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Tue, 12 Dec 2023 10:20:06 +0800 Subject: [PATCH 1/7] Add xcoff support --- library/std/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index f666b18887c..ef5647f6c10 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -30,7 +30,7 @@ rustc-demangle = { version = "0.1.21", features = ['rustc-dep-of-std'] } [target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies] miniz_oxide = { version = "0.7.0", optional = true, default-features = false } addr2line = { version = "0.21.0", optional = true, default-features = false } -object = { version = "0.32.0", default-features = false, optional = true, features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] } +object = { version = "0.32.0", default-features = false, optional = true, features = ['read_core', 'elf', 'macho', 'pe', 'xcoff', 'unaligned', 'archive'] } [dev-dependencies] rand = { version = "0.8.5", default-features = false, features = ["alloc"] } From e4808afe8eb97567b6ba457337fbdd321336251e Mon Sep 17 00:00:00 2001 From: okaneco <47607823+okaneco@users.noreply.github.com> Date: Fri, 1 Dec 2023 18:58:20 -0500 Subject: [PATCH 2/7] Add ASCII whitespace trimming functions to `&str` Add `trim_ascii_start`, `trim_ascii_end`, and `trim_ascii` functions to `&str` for trimming ASCII whitespace under the `byte_slice_trim_ascii` feature gate. Add `inline` to `[u8]` `trim_ascii` functions --- library/core/src/slice/ascii.rs | 3 ++ library/core/src/str/mod.rs | 79 +++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/library/core/src/slice/ascii.rs b/library/core/src/slice/ascii.rs index 4cfccd2e3ce..ce04a9f4089 100644 --- a/library/core/src/slice/ascii.rs +++ b/library/core/src/slice/ascii.rs @@ -125,6 +125,7 @@ pub fn escape_ascii(&self) -> EscapeAscii<'_> { /// assert_eq!(b"".trim_ascii_start(), b""); /// ``` #[unstable(feature = "byte_slice_trim_ascii", issue = "94035")] + #[inline] pub const fn trim_ascii_start(&self) -> &[u8] { let mut bytes = self; // Note: A pattern matching based approach (instead of indexing) allows @@ -154,6 +155,7 @@ pub const fn trim_ascii_start(&self) -> &[u8] { /// assert_eq!(b"".trim_ascii_end(), b""); /// ``` #[unstable(feature = "byte_slice_trim_ascii", issue = "94035")] + #[inline] pub const fn trim_ascii_end(&self) -> &[u8] { let mut bytes = self; // Note: A pattern matching based approach (instead of indexing) allows @@ -184,6 +186,7 @@ pub const fn trim_ascii_end(&self) -> &[u8] { /// assert_eq!(b"".trim_ascii(), b""); /// ``` #[unstable(feature = "byte_slice_trim_ascii", issue = "94035")] + #[inline] pub const fn trim_ascii(&self) -> &[u8] { self.trim_ascii_start().trim_ascii_end() } diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 27178328be5..a22c46edce2 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -2423,6 +2423,85 @@ pub fn make_ascii_lowercase(&mut self) { me.make_ascii_lowercase() } + /// Returns a string slice with leading ASCII whitespace removed. + /// + /// 'Whitespace' refers to the definition used by + /// [`u8::is_ascii_whitespace`]. + /// + /// [`u8::is_ascii_whitespace`]: u8::is_ascii_whitespace + /// + /// # Examples + /// + /// ``` + /// #![feature(byte_slice_trim_ascii)] + /// + /// assert_eq!(" \t \u{3000}hello world\n".trim_ascii_start(), "\u{3000}hello world\n"); + /// assert_eq!(" ".trim_ascii_start(), ""); + /// assert_eq!("".trim_ascii_start(), ""); + /// ``` + #[unstable(feature = "byte_slice_trim_ascii", issue = "94035")] + #[must_use = "this returns the trimmed string as a new slice, \ + without modifying the original"] + #[inline] + pub const fn trim_ascii_start(&self) -> &str { + // SAFETY: Removing ASCII characters from a `&str` does not invalidate + // UTF-8. + unsafe { core::str::from_utf8_unchecked(self.as_bytes().trim_ascii_start()) } + } + + /// Returns a string slice with trailing ASCII whitespace removed. + /// + /// 'Whitespace' refers to the definition used by + /// [`u8::is_ascii_whitespace`]. + /// + /// [`u8::is_ascii_whitespace`]: u8::is_ascii_whitespace + /// + /// # Examples + /// + /// ``` + /// #![feature(byte_slice_trim_ascii)] + /// + /// assert_eq!("\r hello world\u{3000}\n ".trim_ascii_end(), "\r hello world\u{3000}"); + /// assert_eq!(" ".trim_ascii_end(), ""); + /// assert_eq!("".trim_ascii_end(), ""); + /// ``` + #[unstable(feature = "byte_slice_trim_ascii", issue = "94035")] + #[must_use = "this returns the trimmed string as a new slice, \ + without modifying the original"] + #[inline] + pub const fn trim_ascii_end(&self) -> &str { + // SAFETY: Removing ASCII characters from a `&str` does not invalidate + // UTF-8. + unsafe { core::str::from_utf8_unchecked(self.as_bytes().trim_ascii_end()) } + } + + /// Returns a string slice with leading and trailing ASCII whitespace + /// removed. + /// + /// 'Whitespace' refers to the definition used by + /// [`u8::is_ascii_whitespace`]. + /// + /// [`u8::is_ascii_whitespace`]: u8::is_ascii_whitespace + /// + /// # Examples + /// + /// ``` + /// #![feature(byte_slice_trim_ascii)] + /// + /// assert_eq!("\r hello world\n ".trim_ascii(), "hello world"); + /// assert_eq!(" ".trim_ascii(), ""); + /// assert_eq!("".trim_ascii(), ""); + /// ``` + #[unstable(feature = "byte_slice_trim_ascii", issue = "94035")] + #[must_use = "this returns the trimmed string as a new slice, \ + without modifying the original"] + #[inline] + pub const fn trim_ascii(&self) -> &str { + // SAFETY: Removing ASCII characters from a `&str` does not invalidate + // UTF-8. + unsafe { core::str::from_utf8_unchecked(self.as_bytes().trim_ascii()) } + } + /// Return an iterator that escapes each char in `self` with [`char::escape_debug`]. /// /// Note: only extended grapheme codepoints that begin the string will be From 9f64023096eb23e1e937052a8ad75f6c4c88762b Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Wed, 13 Dec 2023 10:15:27 +0800 Subject: [PATCH 3/7] Use different cfg for AIX --- library/std/Cargo.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index ef5647f6c10..fe66788b564 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -30,7 +30,12 @@ rustc-demangle = { version = "0.1.21", features = ['rustc-dep-of-std'] } [target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies] miniz_oxide = { version = "0.7.0", optional = true, default-features = false } addr2line = { version = "0.21.0", optional = true, default-features = false } -object = { version = "0.32.0", default-features = false, optional = true, features = ['read_core', 'elf', 'macho', 'pe', 'xcoff', 'unaligned', 'archive'] } + +[target.'cfg(all(not(target_os = "aix"), not(all(windows, target_env = "msvc", not(target_vendor = "uwp")))))'.dependencies] +object = { version = "0.32.0", default-features = false, optional = true, features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] } + +[target.'cfg(target_os = "aix")'.dependencies] +object = { version = "0.32.0", default-features = false, optional = true, features = ['read_core', 'xcoff', 'unaligned', 'archive'] } [dev-dependencies] rand = { version = "0.8.5", default-features = false, features = ["alloc"] } From 4845665f6a1b4c2614b7984c79d8a6a4241fa978 Mon Sep 17 00:00:00 2001 From: jyn Date: Fri, 15 Dec 2023 13:15:40 -0500 Subject: [PATCH 4/7] use `if cfg` instead of `#[cfg]` this pr is specifically for waffle because i love it <3 --- compiler/rustc_errors/src/emitter.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 379883a0c18..ec37240e394 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2677,10 +2677,7 @@ fn from_stderr(color: ColorConfig) -> Destination { /// On Windows, BRIGHT_BLUE is hard to read on black. Use cyan instead. /// /// See #36178. -#[cfg(windows)] -const BRIGHT_BLUE: Color = Color::Cyan; -#[cfg(not(windows))] -const BRIGHT_BLUE: Color = Color::Blue; +const BRIGHT_BLUE: Color = if cfg!(windows) { Color::Cyan } else { Color::Blue }; impl Style { fn color_spec(&self, lvl: Level) -> ColorSpec { From 74d81d15b400590b39b9f3ab08f45eaf557aca17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Fri, 15 Dec 2023 23:19:51 +0100 Subject: [PATCH 5/7] NFC: do not clone types that are copy --- compiler/rustc_codegen_llvm/src/builder.rs | 2 +- compiler/rustc_middle/src/infer/canonical.rs | 4 ++-- compiler/rustc_middle/src/ty/consts.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_pattern_analysis/src/constructor.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index f4b9296dbbd..8f60175a603 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -353,7 +353,7 @@ fn checked_binop( let new_kind = match ty.kind() { Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.pointer_width)), Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.pointer_width)), - t @ (Uint(_) | Int(_)) => t.clone(), + t @ (Uint(_) | Int(_)) => *t, _ => panic!("tried to get overflow intrinsic for op applied to non-int type"), }; diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index 59593ae1c63..e544c2a26e8 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -341,13 +341,13 @@ pub fn get_or_insert( Entry::Occupied(e) => { let (canonical, var_values) = e.get(); state.var_values.extend_from_slice(var_values); - canonical.clone() + *canonical } Entry::Vacant(e) => { let canonical = canonicalize_op(tcx, key, state); let OriginalQueryValues { var_values, universe_map } = state; assert_eq!(universe_map.len(), 1); - e.insert((canonical.clone(), tcx.arena.alloc_slice(var_values))); + e.insert((canonical, tcx.arena.alloc_slice(var_values))); canonical } } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index a3fa568114f..2d3ee33489e 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -59,7 +59,7 @@ pub fn ty(self) -> Ty<'tcx> { #[inline] pub fn kind(self) -> ConstKind<'tcx> { - self.0.kind.clone() + self.0.kind } #[inline] diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index a09a5115386..febab23ea35 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -473,7 +473,7 @@ impl<'tcx> IntoKind for Ty<'tcx> { type Kind = TyKind<'tcx>; fn kind(self) -> TyKind<'tcx> { - self.kind().clone() + *self.kind() } } diff --git a/compiler/rustc_pattern_analysis/src/constructor.rs b/compiler/rustc_pattern_analysis/src/constructor.rs index 3bca7894a29..6486ad8b483 100644 --- a/compiler/rustc_pattern_analysis/src/constructor.rs +++ b/compiler/rustc_pattern_analysis/src/constructor.rs @@ -923,7 +923,7 @@ pub(crate) fn split<'a, 'tcx>( } ConstructorSet::Integers { range_1, range_2 } => { let seen_ranges: Vec<_> = - seen.iter().map(|ctor| ctor.as_int_range().unwrap().clone()).collect(); + seen.iter().map(|ctor| *ctor.as_int_range().unwrap()).collect(); for (seen, splitted_range) in range_1.split(seen_ranges.iter().cloned()) { match seen { Presence::Unseen => missing.push(IntRange(splitted_range)), From 8479945c087906a26d045625ac2da4f6383c6c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Fri, 15 Dec 2023 23:56:24 +0100 Subject: [PATCH 6/7] NFC don't convert types to identical types --- compiler/rustc_ast_lowering/src/expr.rs | 4 +--- compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs | 2 +- .../src/debuginfo/metadata/enums/mod.rs | 2 +- compiler/rustc_data_structures/src/sorted_map.rs | 2 +- compiler/rustc_hir/src/hir.rs | 10 ++++------ .../src/collect/resolve_bound_vars.rs | 2 +- compiler/rustc_hir_typeck/src/errors.rs | 6 +++--- compiler/rustc_hir_typeck/src/method/probe.rs | 4 ++-- compiler/rustc_infer/src/infer/outlives/verify.rs | 7 +------ compiler/rustc_infer/src/infer/relate/combine.rs | 2 +- compiler/rustc_mir_dataflow/src/value_analysis.rs | 6 +----- .../rustc_mir_transform/src/dataflow_const_prop.rs | 2 +- compiler/rustc_parse/src/parser/item.rs | 2 +- compiler/rustc_parse/src/validate_attr.rs | 2 +- compiler/rustc_resolve/src/rustdoc.rs | 3 +-- compiler/rustc_session/src/config.rs | 2 +- compiler/rustc_smir/src/rustc_smir/context.rs | 1 - .../rustc_trait_selection/src/traits/object_safety.rs | 2 +- compiler/rustc_trait_selection/src/traits/util.rs | 5 ++--- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/html/markdown.rs | 2 +- src/librustdoc/lint.rs | 4 ++-- src/librustdoc/passes/check_custom_code_classes.rs | 2 +- src/librustdoc/visit_ast.rs | 9 +++++---- 24 files changed, 35 insertions(+), 50 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 0bbdcb7f09e..11b5131b8d7 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -1260,9 +1260,7 @@ fn is_ordinary(lower_ctx: &mut LoweringContext<'_, '_>, lhs: &Expr) -> bool { ); // `a = lhs1; b = lhs2;`. - let stmts = self - .arena - .alloc_from_iter(std::iter::once(destructure_let).chain(assignments.into_iter())); + let stmts = self.arena.alloc_from_iter(std::iter::once(destructure_let).chain(assignments)); // Wrap everything in a block. hir::ExprKind::Block(self.block_all(whole_span, stmts, None), None) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 30c2d633840..883f82caa80 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -607,7 +607,7 @@ fn alloc_new_file_metadata<'ll>( if let Ok(rel_path) = abs_path.strip_prefix(working_directory) { ( - working_directory.to_string_lossy().into(), + working_directory.to_string_lossy(), rel_path.to_string_lossy().into_owned(), ) } else { diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs index 02a1072df6d..eef8dbb33b4 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -396,7 +396,7 @@ pub fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>( }) .collect(); - state_specific_fields.into_iter().chain(common_fields.into_iter()).collect() + state_specific_fields.into_iter().chain(common_fields).collect() }, |cx| build_generic_type_param_di_nodes(cx, coroutine_type_and_layout.ty), ) diff --git a/compiler/rustc_data_structures/src/sorted_map.rs b/compiler/rustc_data_structures/src/sorted_map.rs index 60b343afbed..ed2e558bffa 100644 --- a/compiler/rustc_data_structures/src/sorted_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map.rs @@ -198,7 +198,7 @@ pub fn insert_presorted(&mut self, elements: Vec<(K, V)>) { if index == self.data.len() || elements.last().unwrap().0 < self.data[index].0 { // We can copy the whole range without having to mix with // existing elements. - self.data.splice(index..index, elements.into_iter()); + self.data.splice(index..index, elements); return; } diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 5c252c3f9f2..06bdb6bf3e0 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1560,7 +1560,7 @@ pub fn precedence(&self) -> ExprPrecedence { ExprKind::Call(..) => ExprPrecedence::Call, ExprKind::MethodCall(..) => ExprPrecedence::MethodCall, ExprKind::Tup(_) => ExprPrecedence::Tup, - ExprKind::Binary(op, ..) => ExprPrecedence::Binary(op.node.into()), + ExprKind::Binary(op, ..) => ExprPrecedence::Binary(op.node), ExprKind::Unary(..) => ExprPrecedence::Unary, ExprKind::Lit(_) => ExprPrecedence::Lit, ExprKind::Type(..) | ExprKind::Cast(..) => ExprPrecedence::Cast, @@ -1700,11 +1700,9 @@ pub fn can_have_side_effects(&self) -> bool { // them being used only for its side-effects. base.can_have_side_effects() } - ExprKind::Struct(_, fields, init) => fields - .iter() - .map(|field| field.expr) - .chain(init.into_iter()) - .any(|e| e.can_have_side_effects()), + ExprKind::Struct(_, fields, init) => { + fields.iter().map(|field| field.expr).chain(init).any(|e| e.can_have_side_effects()) + } ExprKind::Array(args) | ExprKind::Tup(args) diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index 5769fc5fe64..2c574918e56 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -350,7 +350,7 @@ fn poly_trait_ref_binder_info(&mut self) -> (Vec, BinderS // Nested poly trait refs have the binders concatenated let mut full_binders = self.map.late_bound_vars.entry(*hir_id).or_default().clone(); - full_binders.extend(supertrait_bound_vars.into_iter()); + full_binders.extend(supertrait_bound_vars); break (full_binders, BinderScopeType::Concatenating); } } diff --git a/compiler/rustc_hir_typeck/src/errors.rs b/compiler/rustc_hir_typeck/src/errors.rs index 74aec897f95..ff03cf16a27 100644 --- a/compiler/rustc_hir_typeck/src/errors.rs +++ b/compiler/rustc_hir_typeck/src/errors.rs @@ -573,13 +573,13 @@ fn add_to_diagnostic_with(self, diag: &mut rustc_errors::Diagnostic, f: F) { match self { CastUnknownPointerSub::To(span) => { - let msg = f(diag, crate::fluent_generated::hir_typeck_label_to.into()); + let msg = f(diag, crate::fluent_generated::hir_typeck_label_to); diag.span_label(span, msg); - let msg = f(diag, crate::fluent_generated::hir_typeck_note.into()); + let msg = f(diag, crate::fluent_generated::hir_typeck_note); diag.note(msg); } CastUnknownPointerSub::From(span) => { - let msg = f(diag, crate::fluent_generated::hir_typeck_label_from.into()); + let msg = f(diag, crate::fluent_generated::hir_typeck_label_from); diag.span_label(span, msg); } } diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 4243bce377f..a0178957558 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1548,9 +1548,9 @@ fn consider_probe( ); let candidate_obligations = impl_obligations - .chain(norm_obligations.into_iter()) + .chain(norm_obligations) .chain(ref_obligations.iter().cloned()) - .chain(normalization_obligations.into_iter()); + .chain(normalization_obligations); // Evaluate those obligations to see if they might possibly hold. for o in candidate_obligations { diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index ce619ae8a0d..bb578a482e4 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -130,12 +130,7 @@ pub fn alias_bound( // see the extensive comment in projection_must_outlive let recursive_bound = { let mut components = smallvec![]; - compute_alias_components_recursive( - self.tcx, - alias_ty_as_ty.into(), - &mut components, - visited, - ); + compute_alias_components_recursive(self.tcx, alias_ty_as_ty, &mut components, visited); self.bound_from_components(&components, visited) }; diff --git a/compiler/rustc_infer/src/infer/relate/combine.rs b/compiler/rustc_infer/src/infer/relate/combine.rs index 043a916679e..dfaca3458d6 100644 --- a/compiler/rustc_infer/src/infer/relate/combine.rs +++ b/compiler/rustc_infer/src/infer/relate/combine.rs @@ -552,7 +552,7 @@ pub fn instantiate( } pub fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>) { - self.obligations.extend(obligations.into_iter()); + self.obligations.extend(obligations); } pub fn register_predicates(&mut self, obligations: impl IntoIterator>) { diff --git a/compiler/rustc_mir_dataflow/src/value_analysis.rs b/compiler/rustc_mir_dataflow/src/value_analysis.rs index 071024a0fa3..2802f5491be 100644 --- a/compiler/rustc_mir_dataflow/src/value_analysis.rs +++ b/compiler/rustc_mir_dataflow/src/value_analysis.rs @@ -956,11 +956,7 @@ fn for_each_aliasing_place( // The local is not tracked at all, so it does not alias anything. return; }; - let elems = place - .projection - .iter() - .map(|&elem| elem.try_into()) - .chain(tail_elem.map(Ok).into_iter()); + let elems = place.projection.iter().map(|&elem| elem.try_into()).chain(tail_elem.map(Ok)); for elem in elems { // A field aliases the parent place. if let Some(vi) = self.places[index].value_index { diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 146cc33e8c6..ad12bce9b02 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -496,7 +496,7 @@ fn eval_operand( FlatSet::Elem(scalar) => { let ty = op.ty(self.local_decls, self.tcx); self.tcx.layout_of(self.param_env.and(ty)).map_or(FlatSet::Top, |layout| { - FlatSet::Elem(ImmTy::from_scalar(scalar.into(), layout)) + FlatSet::Elem(ImmTy::from_scalar(scalar, layout)) }) } FlatSet::Bottom => FlatSet::Bottom, diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 89919247e82..fd7dad36c9d 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -923,7 +923,7 @@ fn parse_type_alias(&mut self, defaultness: Defaultness) -> PResult<'a, ItemInfo ); let where_predicates_split = before_where_clause.predicates.len(); let mut predicates = before_where_clause.predicates; - predicates.extend(after_where_clause.predicates.into_iter()); + predicates.extend(after_where_clause.predicates); let where_clause = WhereClause { has_where_token: before_where_clause.has_where_token || after_where_clause.has_where_token, diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs index 81055431f64..d10c8c92257 100644 --- a/compiler/rustc_parse/src/validate_attr.rs +++ b/compiler/rustc_parse/src/validate_attr.rs @@ -215,7 +215,7 @@ fn emit_malformed_attribute( } else { "the following are the possible correct uses" }, - suggestions.into_iter(), + suggestions, Applicability::HasPlaceholders, ) .emit(); diff --git a/compiler/rustc_resolve/src/rustdoc.rs b/compiler/rustc_resolve/src/rustdoc.rs index f95c0acd750..4ff4ccf5e98 100644 --- a/compiler/rustc_resolve/src/rustdoc.rs +++ b/compiler/rustc_resolve/src/rustdoc.rs @@ -407,8 +407,7 @@ fn parse_links<'md>(doc: &'md str) -> Vec> { doc, main_body_opts(), Some(&mut broken_link_callback), - ) - .into_iter(); + ); let mut links = Vec::new(); while let Some(event) = event_iter.next() { diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index d46a309df55..20d18fa4b83 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1579,7 +1579,7 @@ macro_rules! ins { pub fn build_configuration(sess: &Session, mut user_cfg: Cfg) -> Cfg { // Combine the configuration requested by the session (command line) with // some default and generated configuration items. - user_cfg.extend(default_configuration(sess).into_iter()); + user_cfg.extend(default_configuration(sess)); user_cfg } diff --git a/compiler/rustc_smir/src/rustc_smir/context.rs b/compiler/rustc_smir/src/rustc_smir/context.rs index 70313cc021e..3a8289f38bd 100644 --- a/compiler/rustc_smir/src/rustc_smir/context.rs +++ b/compiler/rustc_smir/src/rustc_smir/context.rs @@ -158,7 +158,6 @@ fn find_crates(&self, name: &str) -> Vec { let crate_name = tables.tcx.crate_name(*crate_num).to_string(); (name == crate_name).then(|| smir_crate(tables.tcx, *crate_num)) }) - .into_iter() .flatten() .collect(); crates diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index fbde7455145..5e154cb71da 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -345,7 +345,7 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool { // Search for a predicate like `Self : Sized` amongst the trait bounds. let predicates = tcx.predicates_of(def_id); let predicates = predicates.instantiate_identity(tcx).predicates; - elaborate(tcx, predicates.into_iter()).any(|pred| match pred.kind().skip_binder() { + elaborate(tcx, predicates).any(|pred| match pred.kind().skip_binder() { ty::ClauseKind::Trait(ref trait_pred) => { trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0) } diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index 98da3bc2fe9..575010ff46d 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -220,9 +220,8 @@ pub fn impl_subject_and_oblig<'a, 'tcx>( selcx.infcx.at(&ObligationCause::dummy(), param_env).normalize(predicates); let impl_obligations = super::predicates_for_generics(cause, param_env, predicates); - let impl_obligations = impl_obligations - .chain(normalization_obligations1.into_iter()) - .chain(normalization_obligations2.into_iter()); + let impl_obligations = + impl_obligations.chain(normalization_obligations1).chain(normalization_obligations2); (subject, impl_obligations) } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6631c427270..b112ba65e8f 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -743,7 +743,7 @@ pub(crate) fn clean_generics<'tcx>( .into_iter() .map(|(lifetime, bounds)| WherePredicate::RegionPredicate { lifetime, bounds }), ) - .chain(eq_predicates.into_iter()) + .chain(eq_predicates) .collect(), } } diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index dbd78ea0dc9..89bba5ebbab 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -1383,7 +1383,7 @@ fn parse( }; if custom_code_classes_in_docs { - call(&mut TagIterator::new(string, extra).into_iter()) + call(&mut TagIterator::new(string, extra)) } else { call(&mut tokens(string)) } diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs index d45040e348a..267f1cb0b72 100644 --- a/src/librustdoc/lint.rs +++ b/src/librustdoc/lint.rs @@ -33,7 +33,7 @@ pub(crate) fn init_lints( let lints = || { lint::builtin::HardwiredLints::get_lints() .into_iter() - .chain(rustc_lint::SoftLints::get_lints().into_iter()) + .chain(rustc_lint::SoftLints::get_lints()) }; let lint_opts = lints() @@ -46,7 +46,7 @@ pub(crate) fn init_lints( filter_call(lint) } }) - .chain(lint_opts.into_iter()) + .chain(lint_opts) .collect::>(); let lint_caps = lints() diff --git a/src/librustdoc/passes/check_custom_code_classes.rs b/src/librustdoc/passes/check_custom_code_classes.rs index 6266d3ff51d..f246e2962fe 100644 --- a/src/librustdoc/passes/check_custom_code_classes.rs +++ b/src/librustdoc/passes/check_custom_code_classes.rs @@ -48,7 +48,7 @@ struct TestsWithCustomClasses { impl crate::doctest::Tester for TestsWithCustomClasses { fn add_test(&mut self, _: String, config: LangString, _: usize) { - self.custom_classes_found.extend(config.added_classes.into_iter()); + self.custom_classes_found.extend(config.added_classes); } } diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index bbc7e5b48d1..42ff1210f23 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -168,10 +168,11 @@ pub(crate) fn visit(mut self) -> Module<'tcx> { }) .collect::>() }) - .chain( - [Cfg::Cfg(sym::test, None), Cfg::Cfg(sym::doc, None), Cfg::Cfg(sym::doctest, None)] - .into_iter(), - ) + .chain([ + Cfg::Cfg(sym::test, None), + Cfg::Cfg(sym::doc, None), + Cfg::Cfg(sym::doctest, None), + ]) .collect(); self.cx.cache.exact_paths = self.exact_paths; From 108bec67232520a124100a928a3ddf1d72d7dc60 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 15 Dec 2023 16:17:55 +0000 Subject: [PATCH 7/7] Simplify lint decorator derive too --- compiler/rustc_errors/src/diagnostic.rs | 5 +- compiler/rustc_lint/src/lints.rs | 56 ++++--------------- .../src/diagnostics/diagnostic.rs | 4 +- compiler/rustc_mir_transform/src/errors.rs | 20 +------ 4 files changed, 17 insertions(+), 68 deletions(-) diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 4fb63d67e78..403e0ec7950 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -91,10 +91,7 @@ fn add_to_diagnostic_with(self, diag: &mut Diagnostic, f: F) #[rustc_diagnostic_item = "DecorateLint"] pub trait DecorateLint<'a, G: EmissionGuarantee> { /// Decorate and emit a lint. - fn decorate_lint<'b>( - self, - diag: &'b mut DiagnosticBuilder<'a, G>, - ) -> &'b mut DiagnosticBuilder<'a, G>; + fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, G>); fn msg(&self) -> DiagnosticMessage; } diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index d0b895f7354..ca6408bdf3d 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -134,12 +134,8 @@ pub struct BuiltinMissingDebugImpl<'a> { // Needed for def_path_str impl<'a> DecorateLint<'a, ()> for BuiltinMissingDebugImpl<'_> { - fn decorate_lint<'b>( - self, - diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, - ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { + fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) { diag.set_arg("debug", self.tcx.def_path_str(self.def_id)); - diag } fn msg(&self) -> DiagnosticMessage { @@ -243,17 +239,13 @@ pub struct BuiltinUngatedAsyncFnTrackCaller<'a> { } impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> { - fn decorate_lint<'b>( - self, - diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, - ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { + fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) { diag.span_label(self.label, fluent::lint_label); rustc_session::parse::add_feature_diagnostics( diag, self.parse_sess, sym::async_fn_track_caller, ); - diag } fn msg(&self) -> DiagnosticMessage { @@ -433,10 +425,7 @@ pub struct BuiltinUnpermittedTypeInit<'a> { } impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> { - fn decorate_lint<'b>( - self, - diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, - ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { + fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) { diag.set_arg("ty", self.ty); diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label); if let InhabitedPredicate::True = self.ty.inhabited_predicate(self.tcx) { @@ -447,7 +436,6 @@ fn decorate_lint<'b>( ); } self.sub.add_to_diagnostic(diag); - diag } fn msg(&self) -> rustc_errors::DiagnosticMessage { @@ -1159,10 +1147,7 @@ pub struct NonFmtPanicUnused { // Used because of two suggestions based on one Option impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused { - fn decorate_lint<'b>( - self, - diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, - ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { + fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) { diag.set_arg("count", self.count); diag.note(fluent::lint_note); if let Some(span) = self.suggestion { @@ -1179,7 +1164,6 @@ fn decorate_lint<'b>( Applicability::MachineApplicable, ); } - diag } fn msg(&self) -> rustc_errors::DiagnosticMessage { @@ -1358,12 +1342,9 @@ pub struct DropTraitConstraintsDiag<'a> { // Needed for def_path_str impl<'a> DecorateLint<'a, ()> for DropTraitConstraintsDiag<'_> { - fn decorate_lint<'b>( - self, - diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, - ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { + fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) { diag.set_arg("predicate", self.predicate); - diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id)) + diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id)); } fn msg(&self) -> rustc_errors::DiagnosticMessage { @@ -1378,11 +1359,8 @@ pub struct DropGlue<'a> { // Needed for def_path_str impl<'a> DecorateLint<'a, ()> for DropGlue<'_> { - fn decorate_lint<'b>( - self, - diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, - ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { - diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id)) + fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) { + diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id)); } fn msg(&self) -> rustc_errors::DiagnosticMessage { @@ -1655,10 +1633,7 @@ pub struct ImproperCTypes<'a> { // Used because of the complexity of Option, DiagnosticMessage, and Option impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> { - fn decorate_lint<'b>( - self, - diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, - ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { + fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) { diag.set_arg("ty", self.ty); diag.set_arg("desc", self.desc); diag.span_label(self.label, fluent::lint_label); @@ -1669,7 +1644,6 @@ fn decorate_lint<'b>( if let Some(note) = self.span_note { diag.span_note(note, fluent::lint_note); } - diag } fn msg(&self) -> rustc_errors::DiagnosticMessage { @@ -1802,10 +1776,7 @@ pub enum UnusedDefSuggestion { // Needed because of def_path_str impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> { - fn decorate_lint<'b>( - self, - diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, - ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { + fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) { diag.set_arg("pre", self.pre); diag.set_arg("post", self.post); diag.set_arg("def", self.cx.tcx.def_path_str(self.def_id)); @@ -1816,7 +1787,6 @@ fn decorate_lint<'b>( if let Some(sugg) = self.suggestion { diag.subdiagnostic(sugg); } - diag } fn msg(&self) -> rustc_errors::DiagnosticMessage { @@ -1889,15 +1859,11 @@ pub struct AsyncFnInTraitDiag { } impl<'a> DecorateLint<'a, ()> for AsyncFnInTraitDiag { - fn decorate_lint<'b>( - self, - diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, - ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { + fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) { diag.note(fluent::lint_note); if let Some(sugg) = self.sugg { diag.multipart_suggestion(fluent::lint_suggestion, sugg, Applicability::MaybeIncorrect); } - diag } fn msg(&self) -> rustc_errors::DiagnosticMessage { diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic.rs b/compiler/rustc_macros/src/diagnostics/diagnostic.rs index 31ad9cdb216..cd61544f69d 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic.rs @@ -175,9 +175,9 @@ pub(crate) fn into_tokens(self) -> TokenStream { fn decorate_lint<'__b>( self, #diag: &'__b mut rustc_errors::DiagnosticBuilder<'__a, ()> - ) -> &'__b mut rustc_errors::DiagnosticBuilder<'__a, ()> { + ) { use rustc_errors::IntoDiagnosticArg; - #implementation + #implementation; } fn msg(&self) -> rustc_errors::DiagnosticMessage { diff --git a/compiler/rustc_mir_transform/src/errors.rs b/compiler/rustc_mir_transform/src/errors.rs index dbf27ea60f8..928db471298 100644 --- a/compiler/rustc_mir_transform/src/errors.rs +++ b/compiler/rustc_mir_transform/src/errors.rs @@ -180,10 +180,7 @@ pub(crate) struct UnsafeOpInUnsafeFn { impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn { #[track_caller] - fn decorate_lint<'b>( - self, - diag: &'b mut DiagnosticBuilder<'a, ()>, - ) -> &'b mut DiagnosticBuilder<'a, ()> { + fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) { let handler = diag.handler().expect("lint should not yet be emitted"); let desc = handler.eagerly_translate_to_string(self.details.label(), [].into_iter()); diag.set_arg("details", desc); @@ -198,8 +195,6 @@ fn decorate_lint<'b>( Applicability::MaybeIncorrect, ); } - - diag } fn msg(&self) -> DiagnosticMessage { @@ -213,10 +208,7 @@ pub(crate) enum AssertLint

{ } impl<'a, P: std::fmt::Debug> DecorateLint<'a, ()> for AssertLint

{ - fn decorate_lint<'b>( - self, - diag: &'b mut DiagnosticBuilder<'a, ()>, - ) -> &'b mut DiagnosticBuilder<'a, ()> { + fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) { let span = self.span(); let assert_kind = self.panic(); let message = assert_kind.diagnostic_message(); @@ -224,8 +216,6 @@ fn decorate_lint<'b>( diag.set_arg(name, value); }); diag.span_label(span, message); - - diag } fn msg(&self) -> DiagnosticMessage { @@ -284,10 +274,7 @@ pub(crate) struct MustNotSupend<'tcx, 'a> { // Needed for def_path_str impl<'a> DecorateLint<'a, ()> for MustNotSupend<'_, '_> { - fn decorate_lint<'b>( - self, - diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, - ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { + fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>) { diag.span_label(self.yield_sp, fluent::_subdiag::label); if let Some(reason) = self.reason { diag.subdiagnostic(reason); @@ -296,7 +283,6 @@ fn decorate_lint<'b>( diag.set_arg("pre", self.pre); diag.set_arg("def_path", self.tcx.def_path_str(self.def_id)); diag.set_arg("post", self.post); - diag } fn msg(&self) -> rustc_errors::DiagnosticMessage {