]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #91962 - matthiaskrgr:rollup-2g082jw, r=matthiaskrgr
authorbors <bors@rust-lang.org>
Wed, 15 Dec 2021 12:41:42 +0000 (12:41 +0000)
committerbors <bors@rust-lang.org>
Wed, 15 Dec 2021 12:41:42 +0000 (12:41 +0000)
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

92 files changed:
compiler/rustc_codegen_ssa/src/back/link.rs
compiler/rustc_codegen_ssa/src/back/symbol_export.rs
compiler/rustc_codegen_ssa/src/base.rs
compiler/rustc_codegen_ssa/src/coverageinfo/map.rs
compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
compiler/rustc_codegen_ssa/src/lib.rs
compiler/rustc_codegen_ssa/src/mir/analyze.rs
compiler/rustc_codegen_ssa/src/mir/operand.rs
compiler/rustc_codegen_ssa/src/traits/type_.rs
compiler/rustc_driver/src/lib.rs
compiler/rustc_graphviz/src/lib.rs
compiler/rustc_interface/src/passes.rs
compiler/rustc_middle/src/lint.rs
compiler/rustc_middle/src/mir/generic_graphviz.rs
compiler/rustc_middle/src/mir/spanview.rs
compiler/rustc_middle/src/ty/diagnostics.rs
compiler/rustc_middle/src/ty/sty.rs
compiler/rustc_mir_transform/src/coverage/debug.rs
compiler/rustc_mir_transform/src/coverage/spans.rs
compiler/rustc_parse/src/parser/diagnostics.rs
compiler/rustc_save_analysis/src/lib.rs
compiler/rustc_session/src/config.rs
compiler/rustc_session/src/options.rs
compiler/rustc_session/src/output.rs
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
library/alloc/tests/boxed.rs
library/alloc/tests/str.rs
library/core/src/alloc/layout.rs
library/core/src/bool.rs
library/core/src/cell.rs
library/core/src/iter/adapters/zip.rs
library/core/src/iter/range.rs
library/core/src/num/dec2flt/number.rs
library/core/src/num/fmt.rs
library/core/src/slice/iter.rs
library/core/src/slice/rotate.rs
library/core/src/str/iter.rs
library/core/tests/array.rs
library/core/tests/bool.rs
library/core/tests/lib.rs
library/panic_unwind/src/emcc.rs
library/std/src/fs/tests.rs
library/std/src/io/mod.rs
library/std/src/io/stdio.rs
library/std/src/net/ip/tests.rs
library/std/src/panicking.rs
library/std/src/sys/itron/thread.rs
library/std/src/sys/unix/kernel_copy.rs
library/std/src/sys/unix/process/process_fuchsia.rs
library/std/src/sys/unix/weak.rs
library/std/src/sys/wasm/alloc.rs
library/std/src/sys/wasm/atomics/mutex.rs
library/std/src/sys/windows/stdio.rs
library/std/src/sys/windows/thread_parker.rs
library/std/src/sys_common/thread_parker/generic.rs
library/std/src/thread/local.rs
library/std/src/time.rs
src/librustdoc/html/render/cache.rs
src/librustdoc/html/render/mod.rs
src/librustdoc/passes/collect_intra_doc_links.rs
src/librustdoc/theme.rs
src/test/ui/associated-types/defaults-in-other-trait-items.rs
src/test/ui/associated-types/defaults-in-other-trait-items.stderr
src/test/ui/destructuring-assignment/default-match-bindings-forbidden.stderr
src/test/ui/destructuring-assignment/tuple_destructure_fail.stderr
src/test/ui/fn/implied-bounds-unnorm-associated-type-3.rs [new file with mode: 0644]
src/test/ui/fn/implied-bounds-unnorm-associated-type-3.stderr [new file with mode: 0644]
src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.stderr
src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.stderr
src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.stderr
src/test/ui/half-open-range-patterns/pat-tuple-5.stderr
src/test/ui/issues/issue-11844.stderr
src/test/ui/issues/issue-12552.stderr
src/test/ui/issues/issue-13466.stderr
src/test/ui/issues/issue-3680.stderr
src/test/ui/issues/issue-66706.stderr
src/test/ui/issues/issue-72574-1.stderr
src/test/ui/mismatched_types/E0409.stderr
src/test/ui/mut/mut-pattern-mismatched.stderr
src/test/ui/never_type/diverging-tuple-parts-39485.stderr
src/test/ui/or-patterns/already-bound-name.stderr
src/test/ui/or-patterns/inconsistent-modes.stderr
src/test/ui/pattern/issue-74702.stderr
src/test/ui/pattern/pat-tuple-overfield.stderr
src/test/ui/return/return-type.stderr
src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr
src/test/ui/slightly-nice-generic-literal-messages.stderr
src/test/ui/structs/structure-constructor-type-mismatch.stderr
src/test/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.stderr
src/test/ui/typeck/issue-91334.stderr
src/test/ui/typeck/return_type_containing_closure.rs [new file with mode: 0644]
src/test/ui/typeck/return_type_containing_closure.stderr [new file with mode: 0644]

index bf45810de7708d0fc99d87213eef6ad58a60adb0..e29c109f12d599149760c86bb07eaf94a6fdd463 100644 (file)
@@ -2226,8 +2226,8 @@ fn add_static_crate<'a, B: ArchiveBuilder<'a>>(
                     continue;
                 }
 
-                let canonical = f.replace("-", "_");
-                let canonical_name = name.replace("-", "_");
+                let canonical = f.replace('-', "_");
+                let canonical_name = name.replace('-', "_");
 
                 let is_rust_object =
                     canonical.starts_with(&canonical_name) && looks_like_rust_object_file(&f);
index f80f9965f4d8acd0c651fb0a74dbf867abafa8ad..baafa74b13146b9e5c9254791112df97ac6575d9 100644 (file)
@@ -154,7 +154,7 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b
     tcx.reachable_non_generics(def_id.krate).contains_key(&def_id)
 }
 
-fn exported_symbols_provider_local(
+fn exported_symbols_provider_local<'tcx>(
     tcx: TyCtxt<'tcx>,
     cnum: CrateNum,
 ) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
index d82aa6915452b42c5d20d6995273667ad78ffa27..1dac528481d8c25690ec96d447295c99c9879b04 100644 (file)
@@ -486,7 +486,7 @@ fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
 
 pub fn codegen_crate<B: ExtraBackendMethods>(
     backend: B,
-    tcx: TyCtxt<'tcx>,
+    tcx: TyCtxt<'_>,
     target_cpu: String,
     metadata: EncodedMetadata,
     need_metadata_module: bool,
index c1dfe1ef85600d63dd9441a1bd2e49094c4af13d..1a6495cb15cf28fe6df5e080f4266a25973a6f5a 100644 (file)
@@ -150,9 +150,9 @@ pub fn source_hash(&self) -> u64 {
     /// Generate an array of CounterExpressions, and an iterator over all `Counter`s and their
     /// associated `Regions` (from which the LLVM-specific `CoverageMapGenerator` will create
     /// `CounterMappingRegion`s.
-    pub fn get_expressions_and_counter_regions<'a>(
-        &'a self,
-    ) -> (Vec<CounterExpression>, impl Iterator<Item = (Counter, &'a CodeRegion)>) {
+    pub fn get_expressions_and_counter_regions(
+        &self,
+    ) -> (Vec<CounterExpression>, impl Iterator<Item = (Counter, &CodeRegion)>) {
         assert!(
             self.source_hash != 0 || !self.is_used,
             "No counters provided the source_hash for used function: {:?}",
@@ -168,7 +168,7 @@ pub fn get_expressions_and_counter_regions<'a>(
         (counter_expressions, counter_regions)
     }
 
-    fn counter_regions<'a>(&'a self) -> impl Iterator<Item = (Counter, &'a CodeRegion)> {
+    fn counter_regions(&self) -> impl Iterator<Item = (Counter, &CodeRegion)> {
         self.counters.iter_enumerated().filter_map(|(index, entry)| {
             // Option::map() will return None to filter out missing counters. This may happen
             // if, for example, a MIR-instrumented counter is removed during an optimization.
@@ -177,8 +177,8 @@ fn counter_regions<'a>(&'a self) -> impl Iterator<Item = (Counter, &'a CodeRegio
     }
 
     fn expressions_with_regions(
-        &'a self,
-    ) -> (Vec<CounterExpression>, impl Iterator<Item = (Counter, &'a CodeRegion)>) {
+        &self,
+    ) -> (Vec<CounterExpression>, impl Iterator<Item = (Counter, &CodeRegion)>) {
         let mut counter_expressions = Vec::with_capacity(self.expressions.len());
         let mut expression_regions = Vec::with_capacity(self.expressions.len());
         let mut new_indexes = IndexVec::from_elem_n(None, self.expressions.len());
@@ -336,7 +336,7 @@ fn expressions_with_regions(
         (counter_expressions, expression_regions.into_iter())
     }
 
-    fn unreachable_regions<'a>(&'a self) -> impl Iterator<Item = (Counter, &'a CodeRegion)> {
+    fn unreachable_regions(&self) -> impl Iterator<Item = (Counter, &CodeRegion)> {
         self.unreachable_regions.iter().map(|region| (Counter::zero(), region))
     }
 
index ab119ae25f5e89d496b69388ce65ab9058b4131b..b03124769a06febbd7631316eb208093c266a819 100644 (file)
@@ -376,7 +376,7 @@ fn push_debuginfo_type_name<'tcx>(
     // format (natvis) is able to understand enums and render the active variant correctly in the
     // debugger. For more information, look in `src/etc/natvis/intrinsic.natvis` and
     // `EnumMemberDescriptionFactor::create_member_descriptions`.
-    fn msvc_enum_fallback(
+    fn msvc_enum_fallback<'tcx>(
         tcx: TyCtxt<'tcx>,
         ty: Ty<'tcx>,
         def: &AdtDef,
@@ -496,7 +496,7 @@ pub fn compute_debuginfo_vtable_name<'tcx>(
     vtable_name
 }
 
-pub fn push_item_name(tcx: TyCtxt<'tcx>, def_id: DefId, qualified: bool, output: &mut String) {
+pub fn push_item_name(tcx: TyCtxt<'_>, def_id: DefId, qualified: bool, output: &mut String) {
     let def_key = tcx.def_key(def_id);
     if qualified {
         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:
 }
 
 fn push_unqualified_item_name(
-    tcx: TyCtxt<'tcx>,
+    tcx: TyCtxt<'_>,
     def_id: DefId,
     disambiguated_data: DisambiguatedDefPathData,
     output: &mut String,
index 4c87d4d896e2ec8129362eb05464504d68108a26..350199f4e98c29ec99701a85e0aa856ee6643074 100644 (file)
@@ -2,7 +2,6 @@
 #![feature(bool_to_option)]
 #![feature(box_patterns)]
 #![feature(try_blocks)]
-#![feature(in_band_lifetimes)]
 #![feature(let_else)]
 #![feature(once_cell)]
 #![feature(nll)]
index 0447c02fdecc4fdc2e9791d374439cc978290899..b1b3f1d6d81b97d3689da5da1ea21f03ed848af8 100644 (file)
@@ -73,7 +73,7 @@ struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
     locals: IndexVec<mir::Local, LocalKind>,
 }
 
-impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
+impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
     fn assign(&mut self, local: mir::Local, location: Location) {
         let kind = &mut self.locals[local];
         match *kind {
index bea55bbc87965a37e12acf89ea8b3e66a0cf754f..0c526ff13f2bae88cdf9df75230f47fc3c60ec4a 100644 (file)
@@ -47,7 +47,7 @@ pub struct OperandRef<'tcx, V> {
     pub layout: TyAndLayout<'tcx>,
 }
 
-impl<V: CodegenObject> fmt::Debug for OperandRef<'tcx, V> {
+impl<V: CodegenObject> fmt::Debug for OperandRef<'_, V> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "OperandRef({:?} @ {:?})", self.val, self.layout)
     }
index b94fb1e10db0198386750c06b657ae5e52a940a8..5d3f07317a37b0ad36dd40be80e578e7985ab644 100644 (file)
@@ -97,7 +97,7 @@ fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
     }
 }
 
-impl<T> DerivedTypeMethods<'tcx> for T where Self: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {}
+impl<'tcx, T> DerivedTypeMethods<'tcx> for T where Self: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {}
 
 pub trait LayoutTypeMethods<'tcx>: Backend<'tcx> {
     fn backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type;
@@ -135,4 +135,4 @@ fn store_arg(
 
 pub trait TypeMethods<'tcx>: DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx> {}
 
-impl<T> TypeMethods<'tcx> for T where Self: DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx> {}
+impl<'tcx, T> TypeMethods<'tcx> for T where Self: DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx> {}
index 6ff94341142fda67563b9f412857a987ab1256f3..12e0b7a4977e1cf88130901ac251958a77951cf0 100644 (file)
@@ -872,7 +872,7 @@ fn sort_lint_groups(
 
     let print_lints = |lints: Vec<&Lint>| {
         for lint in lints {
-            let name = lint.name_lower().replace("_", "-");
+            let name = lint.name_lower().replace('_', "-");
             println!(
                 "    {}  {:7.7}  {}",
                 padded(&name),
@@ -908,10 +908,10 @@ fn sort_lint_groups(
 
     let print_lint_groups = |lints: Vec<(&'static str, Vec<LintId>)>| {
         for (name, to) in lints {
-            let name = name.to_lowercase().replace("_", "-");
+            let name = name.to_lowercase().replace('_', "-");
             let desc = to
                 .into_iter()
-                .map(|x| x.to_string().replace("_", "-"))
+                .map(|x| x.to_string().replace('_', "-"))
                 .collect::<Vec<String>>()
                 .join(", ");
             println!("    {}  {}", padded(&name), desc);
@@ -960,7 +960,7 @@ fn print_flag_list<T>(
         println!(
             "    {} {:>width$}=val -- {}",
             cmdline_opt,
-            name.replace("_", "-"),
+            name.replace('_', "-"),
             desc,
             width = max_len
         );
@@ -1015,7 +1015,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
                 .iter()
                 .map(|&(name, ..)| ('C', name))
                 .chain(DB_OPTIONS.iter().map(|&(name, ..)| ('Z', name)))
-                .find(|&(_, name)| *opt == name.replace("_", "-"))
+                .find(|&(_, name)| *opt == name.replace('_', "-"))
                 .map(|(flag, _)| format!("{}. Did you mean `-{} {}`?", e, flag, opt)),
             _ => None,
         };
index edb8bd503e1d01602a32bcb182e0296a475aeb0a..e318090ebe15aec658917b35b2c4b903589f3a01 100644 (file)
@@ -472,7 +472,7 @@ fn edge_style(&'a self, _e: &Self::Edge) -> Style {
 /// Escape tags in such a way that it is suitable for inclusion in a
 /// Graphviz HTML label.
 pub fn escape_html(s: &str) -> String {
-    s.replace("&", "&amp;").replace("\"", "&quot;").replace("<", "&lt;").replace(">", "&gt;")
+    s.replace('&', "&amp;").replace('\"', "&quot;").replace('<', "&lt;").replace('>', "&gt;")
 }
 
 impl<'a> LabelText<'a> {
index da76f221269fe7a61032d0d41b9b43f22d86fa01..34865900495c753b23201f1b0d84286b951edfce 100644 (file)
@@ -584,7 +584,7 @@ fn output_conflicts_with_dir(output_paths: &[PathBuf]) -> Option<PathBuf> {
 fn escape_dep_filename(filename: &str) -> String {
     // Apparently clang and gcc *only* escape spaces:
     // https://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4
-    filename.replace(" ", "\\ ")
+    filename.replace(' ', "\\ ")
 }
 
 // Makefile comments only need escaping newlines and `\`.
index 881b14278e99ed7186329facf09a70210e997ed0..a6432b301743a292b63ee6aab566dd0e7ec8a114 100644 (file)
@@ -295,7 +295,7 @@ fn struct_lint_level_impl(
                     Level::Allow => "-A",
                     Level::ForceWarn => "--force-warn",
                 };
-                let hyphen_case_lint_name = name.replace("_", "-");
+                let hyphen_case_lint_name = name.replace('_', "-");
                 if lint_flag_val.as_str() == name {
                     sess.diag_note_once(
                         &mut err,
@@ -306,7 +306,7 @@ fn struct_lint_level_impl(
                         ),
                     );
                 } else {
-                    let hyphen_case_flag_val = lint_flag_val.as_str().replace("_", "-");
+                    let hyphen_case_flag_val = lint_flag_val.as_str().replace('_', "-");
                     sess.diag_note_once(
                         &mut err,
                         DiagnosticMessageId::from(lint),
index 21c18b28e258ba2d389099d61a2100d3f1cf43a5..c907680bda14aab6068bd00ff6358223631e1aca 100644 (file)
@@ -126,7 +126,7 @@ pub fn write_node<W>(&self, node: G::Node, dark_mode: bool, w: &mut W) -> io::Re
             write!(
                 w,
                 r#"<tr><td align="left" balign="left">{}</td></tr>"#,
-                dot::escape_html(&section).replace("\n", "<br/>")
+                dot::escape_html(&section).replace('\n', "<br/>")
             )?;
         }
 
@@ -147,7 +147,7 @@ fn write_edges<W>(&self, source: G::Node, w: &mut W) -> io::Result<()>
             let src = self.node(source);
             let trg = self.node(target);
             let escaped_edge_label = if let Some(edge_label) = edge_labels.get(index) {
-                dot::escape_html(edge_label).replace("\n", r#"<br align="left"/>"#)
+                dot::escape_html(edge_label).replace('\n', r#"<br align="left"/>"#)
             } else {
                 "".to_owned()
             };
index 1260c691e7844cfb1fc1447c51d938114233f280..507f9971981b0a5b6270715faeae44b6596ab931 100644 (file)
@@ -681,13 +681,13 @@ fn hir_body<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<&'tcx rustc_hir::B
 }
 
 fn escape_html(s: &str) -> String {
-    s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
+    s.replace('&', "&amp;").replace('<', "&lt;").replace('>', "&gt;")
 }
 
 fn escape_attr(s: &str) -> String {
-    s.replace("&", "&amp;")
-        .replace("\"", "&quot;")
-        .replace("'", "&#39;")
-        .replace("<", "&lt;")
-        .replace(">", "&gt;")
+    s.replace('&', "&amp;")
+        .replace('\"', "&quot;")
+        .replace('\'', "&#39;")
+        .replace('<', "&lt;")
+        .replace('>', "&gt;")
 }
index 1acb3ec57dea6e943533eb0d401f7ea5b4633f8c..ee00f6c62f345005f9257a08de20dc0428b45125 100644 (file)
@@ -1,7 +1,12 @@
 //! Diagnostics related methods for `TyS`.
 
+use crate::ty::subst::{GenericArg, GenericArgKind};
 use crate::ty::TyKind::*;
-use crate::ty::{InferTy, TyCtxt, TyS};
+use crate::ty::{
+    ConstKind, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, InferTy,
+    ProjectionTy, TyCtxt, TyS, TypeAndMut,
+};
+
 use rustc_errors::{Applicability, DiagnosticBuilder};
 use rustc_hir as hir;
 use rustc_hir::def_id::DefId;
@@ -63,16 +68,55 @@ pub fn is_simple_text(&self) -> bool {
 
     /// Whether the type can be safely suggested during error recovery.
     pub fn is_suggestable(&self) -> bool {
-        !matches!(
-            self.kind(),
+        fn generic_arg_is_suggestible(arg: GenericArg<'_>) -> bool {
+            match arg.unpack() {
+                GenericArgKind::Type(ty) => ty.is_suggestable(),
+                GenericArgKind::Const(c) => const_is_suggestable(c.val),
+                _ => true,
+            }
+        }
+
+        fn const_is_suggestable(kind: ConstKind<'_>) -> bool {
+            match kind {
+                ConstKind::Infer(..)
+                | ConstKind::Bound(..)
+                | ConstKind::Placeholder(..)
+                | ConstKind::Error(..) => false,
+                _ => true,
+            }
+        }
+
+        // FIXME(compiler-errors): Some types are still not good to suggest,
+        // specifically references with lifetimes within the function. Not
+        //sure we have enough information to resolve whether a region is
+        // temporary, so I'll leave this as a fixme.
+
+        match self.kind() {
             Opaque(..)
-                | FnDef(..)
-                | FnPtr(..)
-                | Dynamic(..)
-                | Closure(..)
-                | Infer(..)
-                | Projection(..)
-        )
+            | FnDef(..)
+            | Closure(..)
+            | Infer(..)
+            | Generator(..)
+            | GeneratorWitness(..)
+            | Bound(_, _)
+            | Placeholder(_)
+            | Error(_) => false,
+            Dynamic(dty, _) => dty.iter().all(|pred| match pred.skip_binder() {
+                ExistentialPredicate::Trait(ExistentialTraitRef { substs, .. }) => {
+                    substs.iter().all(generic_arg_is_suggestible)
+                }
+                ExistentialPredicate::Projection(ExistentialProjection { substs, ty, .. }) => {
+                    ty.is_suggestable() && substs.iter().all(generic_arg_is_suggestible)
+                }
+                _ => true,
+            }),
+            Projection(ProjectionTy { substs: args, .. }) | Adt(_, args) | Tuple(args) => {
+                args.iter().all(generic_arg_is_suggestible)
+            }
+            Slice(ty) | RawPtr(TypeAndMut { ty, .. }) | Ref(_, ty, _) => ty.is_suggestable(),
+            Array(ty, c) => ty.is_suggestable() && const_is_suggestable(c.val),
+            _ => true,
+        }
     }
 }
 
index a80fe6a3362b4821955cd99c1da7044c8e54b12d..1c525fb55e1b57aec4c2c958d2ed17dde0c164bc 100644 (file)
@@ -787,7 +787,7 @@ pub fn stable_cmp(&self, tcx: TyCtxt<'tcx>, other: &Self) -> Ordering {
                 tcx.def_path_hash(a.item_def_id).cmp(&tcx.def_path_hash(b.item_def_id))
             }
             (AutoTrait(ref a), AutoTrait(ref b)) => {
-                tcx.trait_def(*a).def_path_hash.cmp(&tcx.trait_def(*b).def_path_hash)
+                tcx.def_path_hash(*a).cmp(&tcx.def_path_hash(*b))
             }
             (Trait(_), _) => Ordering::Less,
             (Projection(_), Trait(_)) => Ordering::Greater,
index 588103ca43dd0fdc5e058f747c1f502c5ae74134..c61ee6f7e6cb784f8cb5c002f9ffdf9ba2fe4b40 100644 (file)
@@ -148,7 +148,7 @@ fn from_env() -> Self {
         let mut counter_format = ExpressionFormat::default();
 
         if let Ok(env_debug_options) = std::env::var(RUSTC_COVERAGE_DEBUG_OPTIONS) {
-            for setting_str in env_debug_options.replace(" ", "").replace("-", "_").split(',') {
+            for setting_str in env_debug_options.replace(' ', "").replace('-', "_").split(',') {
                 let (option, value) = match setting_str.split_once('=') {
                     None => (setting_str, None),
                     Some((k, v)) => (k, Some(v)),
index 01e72a6c1588d6393bb9a9d148509baee1a44cd3..b5356a817f7ac5e25dc8c7d05268450172c9334f 100644 (file)
@@ -155,7 +155,7 @@ pub fn format<'tcx>(&self, tcx: TyCtxt<'tcx>, mir_body: &mir::Body<'tcx>) -> Str
         format!(
             "{}\n    {}",
             source_range_no_file(tcx, &self.span),
-            self.format_coverage_statements(tcx, mir_body).replace("\n", "\n    "),
+            self.format_coverage_statements(tcx, mir_body).replace('\n', "\n    "),
         )
     }
 
index 25beed1ecf9c776413e7580c683ebe0197b6406a..9677e7642b88c9c4f522eb51dae3a4ac2b76fd0c 100644 (file)
@@ -2236,7 +2236,7 @@ pub(super) fn incorrect_move_async_order_found(
             err.span_suggestion(
                 seq_span,
                 "...or a vertical bar to match on multiple alternatives",
-                seq_snippet.replace(",", " |"),
+                seq_snippet.replace(',', " |"),
                 Applicability::MachineApplicable,
             );
         }
index c7f8fe3a88a64b1dc4ea99a8456f852f54083995..6f86bafbe458144ed3da5c5b3a5e82ec895e4bc2 100644 (file)
@@ -1036,7 +1036,7 @@ fn find_config(supplied: Option<Config>) -> Config {
 
 // Helper function to escape quotes in a string
 fn escape(s: String) -> String {
-    s.replace("\"", "\"\"")
+    s.replace('\"', "\"\"")
 }
 
 // Helper function to determine if a span came from a
index 5df8a4103b74fd6d696d78d5056433d15dcb508f..50a8f0336728e2276f55aed853bc7cee31562bbb 100644 (file)
@@ -1213,7 +1213,7 @@ pub fn get_cmd_lint_options(
             if lint_name == "help" {
                 describe_lints = true;
             } else {
-                lint_opts_with_position.push((arg_pos, lint_name.replace("-", "_"), level));
+                lint_opts_with_position.push((arg_pos, lint_name.replace('-', "_"), level));
             }
         }
     }
index bd7b1639613eb7963a776fcb38b2e779cf95cb74..dc5f4ee0ece0cd0ccad378fd6ec73dad9ddca585 100644 (file)
@@ -335,7 +335,7 @@ fn build_options<O: Default>(
             Some((k, v)) => (k.to_string(), Some(v)),
         };
 
-        let option_to_lookup = key.replace("-", "_");
+        let option_to_lookup = key.replace('-', "_");
         match descrs.iter().find(|(name, ..)| *name == option_to_lookup) {
             Some((_, setter, type_desc, _)) => {
                 if !setter(&mut op, value) {
index cc1e4bb198a3b4c2c204b0f85ceddbd1e3e3886d..5689b723ad6104c65ec57e2dc2b7721c01bded7e 100644 (file)
@@ -85,7 +85,7 @@ pub fn find_crate_name(sess: &Session, attrs: &[ast::Attribute], input: &Input)
                 );
                 sess.err(&msg);
             } else {
-                return validate(s.replace("-", "_"), None);
+                return validate(s.replace('-', "_"), None);
             }
         }
     }
index 4d17a7140e80b19496efa05a6a59f0b1a68598a9..8624f8c8442e1f3394f1c4bbbfaf955e2cd6234d 100644 (file)
@@ -747,7 +747,7 @@ fn suggest_add_reference_to_arg(
 
                     let msg = format!(
                         "the trait bound `{}: {}` is not satisfied",
-                        orig_ty.to_string(),
+                        orig_ty,
                         old_ref.print_only_trait_path(),
                     );
                     if has_custom_message {
index a38b5c471bf06cc63b546b28fa5e8c1a44836379..bfe66b2687ef4d89644a76df2901784bb35a7f19 100644 (file)
@@ -3,7 +3,7 @@
 use std::ptr::NonNull;
 
 #[test]
-fn unitialized_zero_size_box() {
+fn uninitialized_zero_size_box() {
     assert_eq!(
         &*Box::<()>::new_uninit() as *const _,
         NonNull::<MaybeUninit<()>>::dangling().as_ptr(),
index 1b741f174fb12f605b01984196f60d85a3c7e132..7bd0abbad0192939be8faad7dc1c531be3ec8e72 100644 (file)
@@ -162,7 +162,7 @@ fn test_join_for_different_lengths_with_long_separator() {
 }
 
 #[test]
-fn test_join_isue_80335() {
+fn test_join_issue_80335() {
     use core::{borrow::Borrow, cell::Cell};
 
     struct WeirdBorrow {
index 9df0b5c55191591de62b572cedb21cb866eaf85a..ea639268652c3e7140fb19b595abcfcbded95bf1 100644 (file)
@@ -157,11 +157,11 @@ pub fn for_value<T: ?Sized>(t: &T) -> Self {
     ///
     /// - If `T` is `Sized`, this function is always safe to call.
     /// - If the unsized tail of `T` is:
-    ///     - a [slice], then the length of the slice tail must be an intialized
+    ///     - a [slice], then the length of the slice tail must be an initialized
     ///       integer, and the size of the *entire value*
     ///       (dynamic tail length + statically sized prefix) must fit in `isize`.
     ///     - a [trait object], then the vtable part of the pointer must point
-    ///       to a valid vtable for the type `T` acquired by an unsizing coersion,
+    ///       to a valid vtable for the type `T` acquired by an unsizing coercion,
     ///       and the size of the *entire value*
     ///       (dynamic tail length + statically sized prefix) must fit in `isize`.
     ///     - an (unstable) [extern type], then this function is always safe to
index f14c2a4641627ec4378bad32c91e0b129bd6bbc7..d5119d0b7c3286f70153d9c28a6393fec1f061db 100644 (file)
@@ -14,8 +14,12 @@ impl bool {
     /// assert_eq!(true.then_some(0), Some(0));
     /// ```
     #[unstable(feature = "bool_to_option", issue = "80967")]
+    #[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
     #[inline]
-    pub fn then_some<T>(self, t: T) -> Option<T> {
+    pub const fn then_some<T>(self, t: T) -> Option<T>
+    where
+        T: ~const Drop,
+    {
         if self { Some(t) } else { None }
     }
 
@@ -29,8 +33,13 @@ pub fn then_some<T>(self, t: T) -> Option<T> {
     /// assert_eq!(true.then(|| 0), Some(0));
     /// ```
     #[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
+    #[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
     #[inline]
-    pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
+    pub const fn then<T, F>(self, f: F) -> Option<T>
+    where
+        F: ~const FnOnce() -> T,
+        F: ~const Drop,
+    {
         if self { Some(f()) } else { None }
     }
 }
index 06dc5ecf2ffa610a4f93509ad05e348c2a56b984..bc3f7167fac3a9dd4dae0c4ca02c8c9122586580 100644 (file)
@@ -898,7 +898,7 @@ pub fn try_borrow(&self) -> Result<Ref<'_, T>, BorrowError> {
                 Ok(Ref { value: unsafe { &*self.value.get() }, borrow: b })
             }
             None => Err(BorrowError {
-                // If a borrow occured, then we must already have an outstanding borrow,
+                // If a borrow occurred, then we must already have an outstanding borrow,
                 // so `borrowed_at` will be `Some`
                 #[cfg(feature = "debug_refcell")]
                 location: self.borrowed_at.get().unwrap(),
@@ -983,7 +983,7 @@ pub fn try_borrow_mut(&self) -> Result<RefMut<'_, T>, BorrowMutError> {
                 Ok(RefMut { value: unsafe { &mut *self.value.get() }, borrow: b })
             }
             None => Err(BorrowMutError {
-                // If a borrow occured, then we must already have an outstanding borrow,
+                // If a borrow occurred, then we must already have an outstanding borrow,
                 // so `borrowed_at` will be `Some`
                 #[cfg(feature = "debug_refcell")]
                 location: self.borrowed_at.get().unwrap(),
@@ -1104,7 +1104,7 @@ pub unsafe fn try_borrow_unguarded(&self) -> Result<&T, BorrowError> {
             Ok(unsafe { &*self.value.get() })
         } else {
             Err(BorrowError {
-                // If a borrow occured, then we must already have an outstanding borrow,
+                // If a borrow occurred, then we must already have an outstanding borrow,
                 // so `borrowed_at` will be `Some`
                 #[cfg(feature = "debug_refcell")]
                 location: self.borrowed_at.get().unwrap(),
index e1ee0de3d1fa5bc3cb61b1689a2573699596c45c..f50e71da20f160d83806b9e82e67c3107e0ad1bf 100644 (file)
@@ -516,7 +516,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 /// * It must also be safe to drop `self` after calling `self.__iterator_get_unchecked(idx)`.
 /// * If `T` is a subtype of `Self`, then it must be safe to coerce `self` to `T`.
 //
-// FIXME: Clarify interaction with SourceIter/InPlaceIterable. Calling `SouceIter::as_inner`
+// FIXME: Clarify interaction with SourceIter/InPlaceIterable. Calling `SourceIter::as_inner`
 // after `__iterator_get_unchecked` is supposed to be allowed.
 #[doc(hidden)]
 #[unstable(feature = "trusted_random_access", issue = "none")]
index 06733a1b50b9198cf88c66ae0fb99e7848229523..0ae94c05da6583c11d3df41058fa9eee57050202 100644 (file)
@@ -777,7 +777,7 @@ unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
     usize u8 u16
     isize i8 i16
 
-    // These are incorect per the reasoning above,
+    // These are incorrect per the reasoning above,
     // but removing them would be a breaking change as they were stabilized in Rust 1.0.0.
     // So e.g. `(0..66_000_u32).len()` for example will compile without error or warnings
     // on 16-bit platforms, but continue to give a wrong result.
@@ -805,7 +805,7 @@ unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
     u8
     i8
 
-    // These are incorect per the reasoning above,
+    // These are incorrect per the reasoning above,
     // but removing them would be a breaking change as they were stabilized in Rust 1.26.0.
     // So e.g. `(0..=u16::MAX).len()` for example will compile without error or warnings
     // on 16-bit platforms, but continue to give a wrong result.
index 36432718af40eaed18f60c2a6836a0d2b6f4ac8e..405f7e7b6135daeac7cd0bc8dd85901a9b601042 100644 (file)
@@ -40,7 +40,7 @@ fn is_fast_path<F: RawFloat>(&self) -> bool {
             && !self.many_digits
     }
 
-    /// The fast path algorithmn using machine-sized integers and floats.
+    /// The fast path algorithm using machine-sized integers and floats.
     ///
     /// This is extracted into a separate function so that it can be attempted before constructing
     /// a Decimal. This only works if both the mantissa and the exponent
index 578288bda259545d199e7586609855d232ff997d..ed61197157bf57125815ff337c9cfbf71642ff57 100644 (file)
@@ -1,4 +1,4 @@
-//! Shared utilties used by both float and integer formatting.
+//! Shared utilities used by both float and integer formatting.
 #![doc(hidden)]
 #![unstable(
     feature = "numfmt",
index 11a57558f67d7bfb5a8e3586e53633d3f66ae718..176820efe398ed42adb6a0b77dfd6256d4d98e02 100644 (file)
@@ -221,7 +221,7 @@ pub(super) fn new(slice: &'a mut [T]) -> Self {
         // the length, to also allows for the fast `ptr == end` check.
         //
         // See the `next_unchecked!` and `is_empty!` macros as well as the
-        // `post_inc_start` method for more informations.
+        // `post_inc_start` method for more information.
         unsafe {
             assume(!ptr.is_null());
 
index 7528927ef33b9a57297f8330e323856cd518a5bb..4589c6c0f04a5fe836124c5db70190a0c3c8ce5b 100644 (file)
@@ -104,7 +104,7 @@ pub unsafe fn ptr_rotate<T>(mut left: usize, mut mid: *mut T, mut right: usize)
                 // - overflows cannot happen for `i` since the function's safety contract ask for
                 //   `mid+right-1 = x+left+right` to be valid for writing
                 // - underflows cannot happen because `i` must be bigger or equal to `left` for
-                //   a substraction of `left` to happen.
+                //   a subtraction of `left` to happen.
                 //
                 // So `x+i` is valid for reading and writing if the caller respected the contract
                 tmp = unsafe { x.add(i).replace(tmp) };
@@ -202,7 +202,7 @@ pub unsafe fn ptr_rotate<T>(mut left: usize, mut mid: *mut T, mut right: usize)
             loop {
                 // SAFETY:
                 // `left >= right` so `[mid-right, mid+right)` is valid for reading and writing
-                // Substracting `right` from `mid` each turn is counterbalanced by the addition and
+                // Subtracting `right` from `mid` each turn is counterbalanced by the addition and
                 // check after it.
                 unsafe {
                     ptr::swap_nonoverlapping(mid.sub(right), mid, right);
@@ -218,7 +218,7 @@ pub unsafe fn ptr_rotate<T>(mut left: usize, mut mid: *mut T, mut right: usize)
             loop {
                 // SAFETY: `[mid-left, mid+left)` is valid for reading and writing because
                 // `left < right` so `mid+left < mid+right`.
-                // Adding `left` to `mid` each turn is counterbalanced by the substraction and check
+                // Adding `left` to `mid` each turn is counterbalanced by the subtraction and check
                 // after it.
                 unsafe {
                     ptr::swap_nonoverlapping(mid.sub(left), mid, left);
index 4841044671659add949d8ead7bb65d9ade087318..de6e6d52b362543d455664e25cf0c8bd58818d10 100644 (file)
@@ -748,7 +748,7 @@ fn as_str(&self) -> &'a str {
 }
 
 impl<'a, P: Pattern<'a>> Split<'a, P> {
-    /// Returns remainder of the splitted string
+    /// Returns remainder of the split string
     ///
     /// # Examples
     ///
@@ -769,7 +769,7 @@ pub fn as_str(&self) -> &'a str {
 }
 
 impl<'a, P: Pattern<'a>> RSplit<'a, P> {
-    /// Returns remainder of the splitted string
+    /// Returns remainder of the split string
     ///
     /// # Examples
     ///
@@ -808,7 +808,7 @@ pub fn as_str(&self) -> &'a str {
 }
 
 impl<'a, P: Pattern<'a>> SplitTerminator<'a, P> {
-    /// Returns remainder of the splitted string
+    /// Returns remainder of the split string
     ///
     /// # Examples
     ///
@@ -829,7 +829,7 @@ pub fn as_str(&self) -> &'a str {
 }
 
 impl<'a, P: Pattern<'a>> RSplitTerminator<'a, P> {
-    /// Returns remainder of the splitted string
+    /// Returns remainder of the split string
     ///
     /// # Examples
     ///
@@ -931,7 +931,7 @@ fn as_str(&self) -> &'a str {
 }
 
 impl<'a, P: Pattern<'a>> SplitN<'a, P> {
-    /// Returns remainder of the splitted string
+    /// Returns remainder of the split string
     ///
     /// # Examples
     ///
@@ -952,7 +952,7 @@ pub fn as_str(&self) -> &'a str {
 }
 
 impl<'a, P: Pattern<'a>> RSplitN<'a, P> {
-    /// Returns remainder of the splitted string
+    /// Returns remainder of the split string
     ///
     /// # Examples
     ///
@@ -1236,7 +1236,7 @@ fn next_back(&mut self) -> Option<&'a str> {
 impl FusedIterator for SplitWhitespace<'_> {}
 
 impl<'a> SplitWhitespace<'a> {
-    /// Returns remainder of the splitted string
+    /// Returns remainder of the split string
     ///
     /// # Examples
     ///
@@ -1292,7 +1292,7 @@ fn next_back(&mut self) -> Option<&'a str> {
 impl FusedIterator for SplitAsciiWhitespace<'_> {}
 
 impl<'a> SplitAsciiWhitespace<'a> {
-    /// Returns remainder of the splitted string
+    /// Returns remainder of the split string
     ///
     /// # Examples
     ///
@@ -1360,7 +1360,7 @@ fn next_back(&mut self) -> Option<&'a str> {
 impl<'a, P: Pattern<'a>> FusedIterator for SplitInclusive<'a, P> {}
 
 impl<'a, P: Pattern<'a>> SplitInclusive<'a, P> {
-    /// Returns remainder of the splitted string
+    /// Returns remainder of the split string
     ///
     /// # Examples
     ///
index ceb6720079665048b165a9723ff754eb019ae628..fe4fef749904ea2b9cc41e21c651d53e87b70443 100644 (file)
@@ -259,7 +259,7 @@ fn drop(&mut self) {
 // This test does not work on targets without panic=unwind support.
 // To work around this problem, test is marked is should_panic, so it will
 // be automagically skipped on unsuitable targets, such as
-// wasm32-unknown-unkown.
+// wasm32-unknown-unknown.
 //
 // It means that we use panic for indicating success.
 #[test]
index e40f0482aee3e2f1f87b7d48c4da73e665a8eda6..4819ce911d6186a54a45e42c49aefd68c4ab284d 100644 (file)
@@ -88,4 +88,18 @@ fn test_bool_to_option() {
     assert_eq!(true.then_some(0), Some(0));
     assert_eq!(false.then(|| 0), None);
     assert_eq!(true.then(|| 0), Some(0));
+
+    const fn zero() -> i32 {
+        0
+    }
+
+    const A: Option<i32> = false.then_some(0);
+    const B: Option<i32> = true.then_some(0);
+    const C: Option<i32> = false.then(zero);
+    const D: Option<i32> = true.then(zero);
+
+    assert_eq!(A, None);
+    assert_eq!(B, Some(0));
+    assert_eq!(C, None);
+    assert_eq!(D, Some(0));
 }
index b41d3e09df8765bab78997e6848bd3064eca6d5f..dacb33619f8c3d0bd88ac62299df1467ce623abd 100644 (file)
@@ -8,6 +8,7 @@
 #![feature(cfg_panic)]
 #![feature(cfg_target_has_atomic)]
 #![feature(const_assume)]
+#![feature(const_bool_to_option)]
 #![feature(const_cell_into_inner)]
 #![feature(const_convert)]
 #![feature(const_maybe_uninit_as_mut_ptr)]
index e428f2fdaaa39a6d9db9add819b59ccf50ff7857..12f0fe9c3c3a960c70dc9994479a30e93b938841 100644 (file)
@@ -49,7 +49,7 @@ unsafe impl Sync for TypeInfo {}
 };
 
 struct Exception {
-    // This is necessary because C++ code can capture our execption with
+    // This is necessary because C++ code can capture our exception with
     // std::exception_ptr and rethrow it multiple times, possibly even in
     // another thread.
     caught: AtomicBool,
index 9a8f1e44f1f1cc3b04928d84b4c13361b44117ed..2293fb6b558121c11b7f1f1ce06fb792b902bd75 100644 (file)
@@ -1369,7 +1369,7 @@ fn symlink_hard_link() {
     // "hard_link" should appear as a symlink.
     assert!(check!(fs::symlink_metadata(tmpdir.join("hard_link"))).file_type().is_symlink());
 
-    // We sould be able to open "file" via any of the above names.
+    // We should be able to open "file" via any of the above names.
     let _ = check!(fs::File::open(tmpdir.join("file")));
     assert!(fs::File::open(tmpdir.join("file.renamed")).is_err());
     let _ = check!(fs::File::open(tmpdir.join("symlink")));
index dd182c059b9cba39e6e0f5180d4296699cc1a6be..ecc9e91b6bdb2c106eb565a2788e6a9392b85576 100644 (file)
@@ -362,7 +362,7 @@ pub(crate) fn default_read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>
     let start_len = buf.len();
     let start_cap = buf.capacity();
 
-    let mut initialized = 0; // Extra initalized bytes from previous loop iteration
+    let mut initialized = 0; // Extra initialized bytes from previous loop iteration
     loop {
         if buf.len() == buf.capacity() {
             buf.reserve(32); // buf is full, need more space
@@ -370,7 +370,7 @@ pub(crate) fn default_read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>
 
         let mut read_buf = ReadBuf::uninit(buf.spare_capacity_mut());
 
-        // SAFETY: These bytes were initalized but not filled in the previous loop
+        // SAFETY: These bytes were initialized but not filled in the previous loop
         unsafe {
             read_buf.assume_init(initialized);
         }
index 9888d3a09c48d76d9d94776d72c64b9e2e3f94c0..c072f0cafe47bedd0fa04b2a1fed8757010699e1 100644 (file)
@@ -1179,7 +1179,7 @@ fn print_to<T>(args: fmt::Arguments<'_>, global_s: fn() -> T, label: &str)
             })
         }) == Ok(Some(()))
     {
-        // Succesfully wrote to capture buffer.
+        // Successfully wrote to capture buffer.
         return;
     }
 
index 17581f330266dc7394f8b3c42138becb861816a6..632d4683b41595e0fdb5c8216fb694d709ab96ca 100644 (file)
@@ -749,7 +749,7 @@ fn ipv4_from_constructors() {
 }
 
 #[test]
-fn ipv6_from_contructors() {
+fn ipv6_from_constructors() {
     assert_eq!(Ipv6Addr::LOCALHOST, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
     assert!(Ipv6Addr::LOCALHOST.is_loopback());
     assert_eq!(Ipv6Addr::UNSPECIFIED, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0));
index 6fc6b8daec0a6c76a15100194315271beecfa7ba..87854fe4f297088d09e1081a9a37dd2bb0b78c9d 100644 (file)
@@ -365,7 +365,7 @@ union Data<F, R> {
     // The call to `intrinsics::r#try` is made safe by:
     // - `do_call`, the first argument, can be called with the initial `data_ptr`.
     // - `do_catch`, the second argument, can be called with the `data_ptr` as well.
-    // See their safety preconditions for more informations
+    // See their safety preconditions for more information
     unsafe {
         return if intrinsics::r#try(do_call::<F, R>, data_ptr, do_catch::<F, R>) == 0 {
             Ok(ManuallyDrop::into_inner(data.r))
@@ -398,7 +398,7 @@ unsafe fn cleanup(payload: *mut u8) -> Box<dyn Any + Send + 'static> {
     // expects normal function pointers.
     #[inline]
     fn do_call<F: FnOnce() -> R, R>(data: *mut u8) {
-        // SAFETY: this is the responsibilty of the caller, see above.
+        // SAFETY: this is the responsibility of the caller, see above.
         unsafe {
             let data = data as *mut Data<F, R>;
             let data = &mut (*data);
@@ -420,7 +420,7 @@ fn do_call<F: FnOnce() -> R, R>(data: *mut u8) {
     // expects normal function pointers.
     #[inline]
     fn do_catch<F: FnOnce() -> R, R>(data: *mut u8, payload: *mut u8) {
-        // SAFETY: this is the responsibilty of the caller, see above.
+        // SAFETY: this is the responsibility of the caller, see above.
         //
         // When `__rustc_panic_cleaner` is correctly implemented we can rely
         // on `obj` being the correct thing to pass to `data.p` (after wrapping
index bb9fa54d02ea4174eb596c3df960b4a77540fafd..ebcc9ab26e088c27a42b7711c705dc14b7cf4e32 100644 (file)
@@ -126,7 +126,7 @@ pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
                     // In this case, `inner`'s ownership has been moved to us,
                     // And we are responsible for dropping it. The acquire
                     // ordering is not necessary because the parent thread made
-                    // no memory acccess needing synchronization since the call
+                    // no memory access needing synchronization since the call
                     // to `acre_tsk`.
                     // Safety: See above.
                     let _ = unsafe { Box::from_raw(inner as *const _ as *mut ThreadInner) };
@@ -264,7 +264,7 @@ fn drop(&mut self) {
                 // one will ever join it.
                 // The ownership of `self.inner` is moved to the child thread.
                 // However, the release ordering is not necessary because we
-                // made no memory acccess needing synchronization since the call
+                // made no memory access needing synchronization since the call
                 // to `acre_tsk`.
             }
             LIFECYCLE_FINISHED => {
index 241cf89d3145c6cfcd20dac0b125b31d14cd64b9..e85e4c5d618ced0a1e679f96cf858cefcabfff44 100644 (file)
@@ -104,7 +104,7 @@ fn maybe_fifo(&self) -> bool {
 
     fn potential_sendfile_source(&self) -> bool {
         match self {
-            // procfs erronously shows 0 length on non-empty readable files.
+            // procfs erroneously shows 0 length on non-empty readable files.
             // and if a file is truly empty then a `read` syscall will determine that and skip the write syscall
             // thus there would be benefit from attempting sendfile
             FdMeta::Metadata(meta)
index 507abb27871bf05747ffb0e132c0e99070781909..ce77c210a6220c28ae2e8f22727b2adeab3c6f33 100644 (file)
@@ -284,7 +284,7 @@ pub fn into_raw(&self) -> c_int {
         //
         // The other view would be to say that the caller on Fuchsia ought to know that `into_raw`
         // will give a raw Fuchsia status (whatever that is - I don't know, personally).  That is
-        // not possible here becaause we must return a c_int because that's what Unix (including
+        // not possible here because we must return a c_int because that's what Unix (including
         // SuS and POSIX) say a wait status is, but Fuchsia apparently uses a u64, so it won't
         // necessarily fit.
         //
index 32072affe8af45f20c8862e23f73fe7fa059b5a2..55719b87c7e0687212ba7ba314be24757402390f 100644 (file)
@@ -124,7 +124,7 @@ pub(crate) fn get(&self) -> Option<F> {
         }
     }
 
-    // Cold because it should only happen during first-time initalization.
+    // Cold because it should only happen during first-time initialization.
     #[cold]
     unsafe fn initialize(&self) -> Option<F> {
         assert_eq!(mem::size_of::<F>(), mem::size_of::<usize>());
index 3223e8941024c8a3e468803ad45a82550909e777..6dceb1689a8b7d2c97621f6038a4b076def6ec4f 100644 (file)
@@ -24,7 +24,7 @@
 unsafe impl GlobalAlloc for System {
     #[inline]
     unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
-        // SAFETY: DLMALLOC access is guranteed to be safe because the lock gives us unique and non-reentrant access.
+        // SAFETY: DLMALLOC access is guaranteed to be safe because the lock gives us unique and non-reentrant access.
         // Calling malloc() is safe because preconditions on this function match the trait method preconditions.
         let _lock = lock::lock();
         unsafe { DLMALLOC.malloc(layout.size(), layout.align()) }
@@ -32,7 +32,7 @@ unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
 
     #[inline]
     unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
-        // SAFETY: DLMALLOC access is guranteed to be safe because the lock gives us unique and non-reentrant access.
+        // SAFETY: DLMALLOC access is guaranteed to be safe because the lock gives us unique and non-reentrant access.
         // Calling calloc() is safe because preconditions on this function match the trait method preconditions.
         let _lock = lock::lock();
         unsafe { DLMALLOC.calloc(layout.size(), layout.align()) }
@@ -40,7 +40,7 @@ unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
 
     #[inline]
     unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
-        // SAFETY: DLMALLOC access is guranteed to be safe because the lock gives us unique and non-reentrant access.
+        // SAFETY: DLMALLOC access is guaranteed to be safe because the lock gives us unique and non-reentrant access.
         // Calling free() is safe because preconditions on this function match the trait method preconditions.
         let _lock = lock::lock();
         unsafe { DLMALLOC.free(ptr, layout.size(), layout.align()) }
@@ -48,7 +48,7 @@ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
 
     #[inline]
     unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
-        // SAFETY: DLMALLOC access is guranteed to be safe because the lock gives us unique and non-reentrant access.
+        // SAFETY: DLMALLOC access is guaranteed to be safe because the lock gives us unique and non-reentrant access.
         // Calling realloc() is safe because preconditions on this function match the trait method preconditions.
         let _lock = lock::lock();
         unsafe { DLMALLOC.realloc(ptr, layout.size(), layout.align(), new_size) }
index 5ff0ec052b6f4c0cdc95f4f85942f107d5b47b3f..3a09f0bf9bb4c3488be96f3d2bdb53e5ce931403 100644 (file)
@@ -73,7 +73,7 @@ pub struct ReentrantMutex {
 unsafe impl Send for ReentrantMutex {}
 unsafe impl Sync for ReentrantMutex {}
 
-// Reentrant mutexes are similarly implemented to mutexs above except that
+// Reentrant mutexes are similarly implemented to mutexes above except that
 // instead of "1" meaning unlocked we use the id of a thread to represent
 // whether it has locked a mutex. That way we have an atomic counter which
 // always holds the id of the thread that currently holds the lock (or 0 if the
@@ -96,7 +96,7 @@ pub unsafe fn init(&self) {
     pub unsafe fn lock(&self) {
         let me = thread::my_id();
         while let Err(owner) = self._try_lock(me) {
-            // SAFETY: the caller must gurantee that `self.ptr()` and `owner` are valid i32.
+            // SAFETY: the caller must guarantee that `self.ptr()` and `owner` are valid i32.
             let val = unsafe { wasm32::memory_atomic_wait32(self.ptr(), owner as i32, -1) };
             debug_assert!(val == 0 || val == 1);
         }
@@ -136,7 +136,7 @@ pub unsafe fn unlock(&self) {
         match *self.recursions.get() {
             0 => {
                 self.owner.swap(0, SeqCst);
-                // SAFETY: the caller must gurantee that `self.ptr()` is valid i32.
+                // SAFETY: the caller must guarantee that `self.ptr()` is valid i32.
                 unsafe {
                     wasm32::memory_atomic_notify(self.ptr() as *mut i32, 1);
                 } // wake up one waiter, if any
index a4fe5f67f699a22600520bf22e76ffe4fb7b74fb..eb0925b3fda7d66a87f02c5df563fabd09d2269e 100644 (file)
@@ -124,7 +124,7 @@ fn write(
     //
     // If the data is not valid UTF-8 we write out as many bytes as are valid.
     // If the first byte is invalid it is either first byte of a multi-byte sequence but the
-    // provided byte slice is too short or it is the first byte of an invalide multi-byte sequence.
+    // provided byte slice is too short or it is the first byte of an invalid multi-byte sequence.
     let len = cmp::min(data.len(), MAX_BUFFER_SIZE / 2);
     let utf8 = match str::from_utf8(&data[..len]) {
         Ok(s) => s,
index 4f59d4dd452be9d2149ae17aa816f62500dad47a..5a8011a95880814497c589257df29f11c8c5195e 100644 (file)
@@ -22,7 +22,7 @@
 //
 // Unlike WaitOnAddress, NtWaitForKeyedEvent/NtReleaseKeyedEvent operate on a
 // HANDLE (created with NtCreateKeyedEvent). This means that we can be sure
-// a succesfully awoken park() was awoken by unpark() and not a
+// a successfully awoken park() was awoken by unpark() and not a
 // NtReleaseKeyedEvent call from some other code, as these events are not only
 // matched by the key (address of the parker (state)), but also by this HANDLE.
 // We lazily allocate this handle the first time it is needed.
index 14cfa958e5e534ce7ef371ab194f570a81c6156f..d99e901bb5f83988bb3c55e3d1c442b3edb9286b 100644 (file)
@@ -1,4 +1,4 @@
-//! Parker implementaiton based on a Mutex and Condvar.
+//! Parker implementation based on a Mutex and Condvar.
 
 use crate::sync::atomic::AtomicUsize;
 use crate::sync::atomic::Ordering::SeqCst;
@@ -20,7 +20,7 @@ pub fn new() -> Self {
         Parker { state: AtomicUsize::new(EMPTY), lock: Mutex::new(()), cvar: Condvar::new() }
     }
 
-    // This implementaiton doesn't require `unsafe`, but other implementations
+    // This implementation doesn't require `unsafe`, but other implementations
     // may assume this is only called by the thread that owns the Parker.
     pub unsafe fn park(&self) {
         // If we were previously notified then we consume this notification and
@@ -55,7 +55,7 @@ pub unsafe fn park(&self) {
         }
     }
 
-    // This implementaiton doesn't require `unsafe`, but other implementations
+    // This implementation doesn't require `unsafe`, but other implementations
     // may assume this is only called by the thread that owns the Parker.
     pub unsafe fn park_timeout(&self, dur: Duration) {
         // Like `park` above we have a fast path for an already-notified thread, and
index c03fe116320aa4378a38a4acd7d76fb12714847a..1d2f6e976800b88b67e603630e803adc3a997fd0 100644 (file)
@@ -582,7 +582,7 @@ pub const fn new() -> Key<T> {
             Key { inner: LazyKeyInner::new(), dtor_state: Cell::new(DtorState::Unregistered) }
         }
 
-        // note that this is just a publically-callable function only for the
+        // note that this is just a publicly-callable function only for the
         // const-initialized form of thread locals, basically a way to call the
         // free `register_dtor` function defined elsewhere in libstd.
         pub unsafe fn register_dtor(a: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
@@ -593,7 +593,7 @@ pub unsafe fn register_dtor(a: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
 
         pub unsafe fn get<F: FnOnce() -> T>(&self, init: F) -> Option<&'static T> {
             // SAFETY: See the definitions of `LazyKeyInner::get` and
-            // `try_initialize` for more informations.
+            // `try_initialize` for more information.
             //
             // The caller must ensure no mutable references are ever active to
             // the inner cell or the inner T when this is called.
index a5e3bd0c29030731aaba4e6cfe7aa16c0575d664..86cc93c44537663d08e1591e330c3a696176f3e1 100644 (file)
@@ -273,7 +273,7 @@ pub fn now() -> Instant {
         // While issues have been seen on arm64 platforms the Arm architecture
         // requires that the counter monotonically increases and that it must
         // provide a uniform view of system time (e.g. it must not be possible
-        // for a core to recieve a message from another core with a time stamp
+        // for a core to receive a message from another core with a time stamp
         // and observe time going backwards (ARM DDI 0487G.b D11.1.2). While
         // there have been a few 64bit SoCs that have bugs which cause time to
         // not monoticially increase, these have been fixed in the Linux kernel
index 2f7214e958ea7d2169b64afb03fad5928c0060d1..631eacc9618286120d88c3b020fbcc8f1cf93671 100644 (file)
@@ -184,8 +184,8 @@ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
         })
         .expect("failed serde conversion")
         // All these `replace` calls are because we have to go through JS string for JSON content.
-        .replace(r"\", r"\\")
-        .replace("'", r"\'")
+        .replace(r#"\"#, r"\\")
+        .replace(r#"'"#, r"\'")
         // We need to escape double quotes for the JSON.
         .replace("\\\"", "\\\\\"")
     )
index 166e084012724e18999eb920770880617556c5ad..c67fe1fef40cdd5750bda407d8be5588ce8f2195 100644 (file)
@@ -989,7 +989,7 @@ fn attributes(it: &clean::Item) -> Vec<String> {
         .iter()
         .filter_map(|attr| {
             if ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
-                Some(pprust::attribute_to_string(attr).replace("\n", "").replace("  ", " "))
+                Some(pprust::attribute_to_string(attr).replace('\n', "").replace("  ", " "))
             } else {
                 None
             }
index 4e5812d7f8429e38a5a5f11042f5912b0a5ee0a4..2faf7781807d42a0700d354b430db1f4e8768a6f 100644 (file)
@@ -963,7 +963,7 @@ fn preprocess_link<'a>(
         return None;
     }
 
-    let stripped = ori_link.link.replace("`", "");
+    let stripped = ori_link.link.replace('`', "");
     let mut parts = stripped.split('#');
 
     let link = parts.next().unwrap();
index b8b3f9634e58234d25934fcb59ad248a020c914e..1e9a65e1d2fc498f1072929e8359ce7a9e3fe3cd 100644 (file)
@@ -173,11 +173,11 @@ fn build_rule(v: &[u8], positions: &[usize]) -> String {
             .map(|x| ::std::str::from_utf8(&v[x[0]..x[1]]).unwrap_or(""))
             .collect::<String>()
             .trim()
-            .replace("\n", " ")
-            .replace("/", "")
-            .replace("\t", " ")
-            .replace("{", "")
-            .replace("}", "")
+            .replace('\n', " ")
+            .replace('/', "")
+            .replace('\t', " ")
+            .replace('{', "")
+            .replace('}', "")
             .split(' ')
             .filter(|s| !s.is_empty())
             .collect::<Vec<&str>>()
index 4014f46285d70aeaeebb1ea4430c10868e3926a0..505751969b623168fdc168c8ce5829c194300cdd 100644 (file)
@@ -10,6 +10,7 @@ fn f(p: Self::A) {
         //~^ ERROR mismatched types
         //~| NOTE expected associated type, found `()`
         //~| NOTE expected associated type `<Self as Tr>::A`
+        //~| NOTE this expression has type `<Self as Tr>::A`
     }
 }
 
index 493df30a64daf25f5a54076a8070ee6c5ddd311c..71d421926e702f0b0b3a4786833392ff1f3a9c37 100644 (file)
@@ -5,13 +5,15 @@ LL |     type A = ();
    |     ------------ associated type defaults can't be assumed inside the trait defining them
 ...
 LL |         let () = p;
-   |             ^^ expected associated type, found `()`
+   |             ^^   - this expression has type `<Self as Tr>::A`
+   |             |
+   |             expected associated type, found `()`
    |
    = note: expected associated type `<Self as Tr>::A`
                     found unit type `()`
 
 error[E0308]: mismatched types
-  --> $DIR/defaults-in-other-trait-items.rs:35:25
+  --> $DIR/defaults-in-other-trait-items.rs:36:25
    |
 LL |     type Ty = u8;
    |     ------------- associated type defaults can't be assumed inside the trait defining them
index 3d472bf63094d90db1d3c17e423876b8b0406690..2250f561b54a5998bcd843b7123123f335bdb0a4 100644 (file)
@@ -2,9 +2,7 @@ error[E0308]: mismatched types
   --> $DIR/default-match-bindings-forbidden.rs:4:5
    |
 LL |     (x, y) = &(1, 2);
-   |     ^^^^^^   ------- this expression has type `&({integer}, {integer})`
-   |     |
-   |     expected reference, found tuple
+   |     ^^^^^^ expected reference, found tuple
    |
    = note: expected type `&({integer}, {integer})`
              found tuple `(_, _)`
index 55b08b74af0620a0edd598c7aded9e46d23825f1..184b3ea6da82b6249af572c819aa312706148438 100644 (file)
@@ -10,9 +10,7 @@ error[E0308]: mismatched types
   --> $DIR/tuple_destructure_fail.rs:6:5
    |
 LL |     (a, a, b) = (1, 2);
-   |     ^^^^^^^^^   ------ this expression has type `({integer}, {integer})`
-   |     |
-   |     expected a tuple with 2 elements, found one with 3 elements
+   |     ^^^^^^^^^ expected a tuple with 2 elements, found one with 3 elements
    |
    = note: expected type `({integer}, {integer})`
              found tuple `(_, _, _)`
@@ -29,9 +27,7 @@ error[E0308]: mismatched types
   --> $DIR/tuple_destructure_fail.rs:8:5
    |
 LL |     (_,) = (1, 2);
-   |     ^^^^   ------ this expression has type `({integer}, {integer})`
-   |     |
-   |     expected a tuple with 2 elements, found one with 1 element
+   |     ^^^^ expected a tuple with 2 elements, found one with 1 element
    |
    = note: expected type `({integer}, {integer})`
              found tuple `(_,)`
diff --git a/src/test/ui/fn/implied-bounds-unnorm-associated-type-3.rs b/src/test/ui/fn/implied-bounds-unnorm-associated-type-3.rs
new file mode 100644 (file)
index 0000000..dc25ac0
--- /dev/null
@@ -0,0 +1,25 @@
+// check-fail
+// See issue #91899. If we treat unnormalized args as WF, `Self` can also be a
+// source of unsoundness.
+
+pub trait Yokeable<'a>: 'static {
+    type Output: 'a;
+}
+
+impl<'a, T: 'static + ?Sized> Yokeable<'a> for &'static T {
+    type Output = &'a T;
+}
+
+pub trait ZeroCopyFrom<C: ?Sized>: for<'a> Yokeable<'a> {
+    /// Clone the cart `C` into a [`Yokeable`] struct, which may retain references into `C`.
+    fn zero_copy_from<'b>(cart: &'b C) -> <Self as Yokeable<'b>>::Output;
+}
+
+impl<T> ZeroCopyFrom<[T]> for &'static [T] {
+    fn zero_copy_from<'b>(cart: &'b [T]) -> &'b [T] {
+        //~^ the parameter
+        cart
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/fn/implied-bounds-unnorm-associated-type-3.stderr b/src/test/ui/fn/implied-bounds-unnorm-associated-type-3.stderr
new file mode 100644 (file)
index 0000000..26eecf6
--- /dev/null
@@ -0,0 +1,12 @@
+error[E0310]: the parameter type `T` may not live long enough
+  --> $DIR/implied-bounds-unnorm-associated-type-3.rs:19:5
+   |
+LL |     fn zero_copy_from<'b>(cart: &'b [T]) -> &'b [T] {
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: consider adding an explicit lifetime bound `T: 'static`...
+   = note: ...so that the type `[T]` will meet its required lifetime bounds
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0310`.
index a6f8563a047851e8a0ea337d02ca329895a881d5..241485db49bc9ad35e4353ed47b0f3f79a6809d1 100644 (file)
@@ -1,8 +1,6 @@
 error[E0308]: mismatched types
   --> $DIR/exclusive_range_pattern_syntax_collision.rs:6:13
    |
-LL |     match [5..4, 99..105, 43..44] {
-   |           ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
 LL |         [_, 99.., _] => {},
    |             ^^ expected struct `std::ops::Range`, found integer
    |
index 4e0102c930da82b7ab86b7bac25a73033f2fe8f6..777d029d7dd7b392302af9c8a8114b4c31d61a84 100644 (file)
@@ -7,8 +7,6 @@ LL |         [_, 99..] => {},
 error[E0308]: mismatched types
   --> $DIR/exclusive_range_pattern_syntax_collision2.rs:6:13
    |
-LL |     match [5..4, 99..105, 43..44] {
-   |           ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
 LL |         [_, 99..] => {},
    |             ^^ expected struct `std::ops::Range`, found integer
    |
index 665eef2fcb96c80ea7aff1c1f8ae0dbb3e0b5eb6..6119733a7d84bda8b514709ccc0f4b9271d35c7a 100644 (file)
@@ -1,8 +1,6 @@
 error[E0308]: mismatched types
   --> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:12
    |
-LL |     match [5..4, 99..105, 43..44] {
-   |           ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
 LL |         [..9, 99..100, _] => {},
    |            ^ expected struct `std::ops::Range`, found integer
    |
@@ -12,8 +10,6 @@ LL |         [..9, 99..100, _] => {},
 error[E0308]: mismatched types
   --> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:15
    |
-LL |     match [5..4, 99..105, 43..44] {
-   |           ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
 LL |         [..9, 99..100, _] => {},
    |               ^^  --- this is of type `{integer}`
    |               |
@@ -25,8 +21,6 @@ LL |         [..9, 99..100, _] => {},
 error[E0308]: mismatched types
   --> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:19
    |
-LL |     match [5..4, 99..105, 43..44] {
-   |           ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
 LL |         [..9, 99..100, _] => {},
    |               --  ^^^ expected struct `std::ops::Range`, found integer
    |               |
index 307ad711b74d9f58c988b557ef799556ed6a1482..31ea3a17871a56b9f3deb58c29b224394e38fe24 100644 (file)
@@ -1,8 +1,6 @@
 error[E0308]: mismatched types
   --> $DIR/pat-tuple-5.rs:8:10
    |
-LL |     match (0, 1) {
-   |           ------ this expression has type `({integer}, {integer})`
 LL |         (PAT ..) => {}
    |          ^^^ expected tuple, found `u8`
    |
index 9d7470e7af9aa9c557edc551e87a9647494c9fc7..ecab1074a295f742cacdffb1d71eb4c71899da74 100644 (file)
@@ -1,8 +1,6 @@
 error[E0308]: mismatched types
   --> $DIR/issue-11844.rs:6:9
    |
-LL |     match a {
-   |           - this expression has type `Option<Box<{integer}>>`
 LL |         Ok(a) =>
    |         ^^^^^ expected enum `Option`, found enum `Result`
    |
index 3d8852ca748af6c296119c129b3d520db51ed72b..1ba6852b17c06a4068a18f3ed333828202c721d8 100644 (file)
@@ -1,8 +1,6 @@
 error[E0308]: mismatched types
   --> $DIR/issue-12552.rs:6:5
    |
-LL |   match t {
-   |         - this expression has type `Result<_, {integer}>`
 LL |     Some(k) => match k {
    |     ^^^^^^^ expected enum `Result`, found enum `Option`
    |
@@ -12,9 +10,6 @@ LL |     Some(k) => match k {
 error[E0308]: mismatched types
   --> $DIR/issue-12552.rs:9:5
    |
-LL |   match t {
-   |         - this expression has type `Result<_, {integer}>`
-...
 LL |     None => ()
    |     ^^^^ expected enum `Result`, found enum `Option`
    |
index c78466f4e8ce1c03322bf9e144b57a4f11ea1ded..15ee49a5fdd25f48f17324b976d6bc990b1c1d4f 100644 (file)
@@ -1,8 +1,6 @@
 error[E0308]: mismatched types
   --> $DIR/issue-13466.rs:8:9
    |
-LL |     let _x: usize = match Some(1) {
-   |                           ------- this expression has type `Option<{integer}>`
 LL |         Ok(u) => u,
    |         ^^^^^ expected enum `Option`, found enum `Result`
    |
@@ -12,9 +10,6 @@ LL |         Ok(u) => u,
 error[E0308]: mismatched types
   --> $DIR/issue-13466.rs:14:9
    |
-LL |     let _x: usize = match Some(1) {
-   |                           ------- this expression has type `Option<{integer}>`
-...
 LL |         Err(e) => panic!(e)
    |         ^^^^^^ expected enum `Option`, found enum `Result`
    |
index e8fafa76b919bbc5d5860ac5075b338f1663f121..8dc0dfa2356f4cf6606d8b7d762164b24c615fb6 100644 (file)
@@ -1,8 +1,6 @@
 error[E0308]: mismatched types
   --> $DIR/issue-3680.rs:3:9
    |
-LL |     match None {
-   |           ---- this expression has type `Option<_>`
 LL |         Err(_) => ()
    |         ^^^^^^ expected enum `Option`, found enum `Result`
    |
index f0b93ac91111a88bbcea399c7b418593826d3e50..3e933a0f01b753dc41e7900be31ff7c7694cda37 100644 (file)
@@ -36,7 +36,7 @@ error[E0308]: mismatched types
   --> $DIR/issue-66706.rs:2:5
    |
 LL | fn a() {
-   |        - help: try adding a return type: `-> [{integer}; _]`
+   |        - possibly return type missing here?
 LL |     [0; [|_: _ &_| ()].len()]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[{integer}; _]`
 
@@ -44,7 +44,7 @@ error[E0308]: mismatched types
   --> $DIR/issue-66706.rs:14:5
    |
 LL | fn c() {
-   |        - help: try adding a return type: `-> [{integer}; _]`
+   |        - possibly return type missing here?
 LL |     [0; [|&_: _ &_| {}; 0 ].len()]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[{integer}; _]`
 
@@ -52,7 +52,7 @@ error[E0308]: mismatched types
   --> $DIR/issue-66706.rs:20:5
    |
 LL | fn d() {
-   |        - help: try adding a return type: `-> [{integer}; _]`
+   |        - possibly return type missing here?
 LL |     [0; match [|f @ &ref _| () ] {} ]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[{integer}; _]`
 
index 653869a237d88b5d70def281be3e4aec317cad64..5d3d390a95dedfe0aa94e02cf2d3d6246b6d3ca6 100644 (file)
@@ -21,8 +21,6 @@ LL |         (_a, _x @ ..) => {}
 error[E0308]: mismatched types
   --> $DIR/issue-72574-1.rs:4:9
    |
-LL |     match x {
-   |           - this expression has type `({integer}, {integer}, {integer})`
 LL |         (_a, _x @ ..) => {}
    |         ^^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 2 elements
    |
index ef03b67b1b0b19db03bec5b038bdc717c315cb8b..eb884bcc6226fef462095aeda83c2ca69e0a6e10 100644 (file)
@@ -9,8 +9,6 @@ LL |         (0, ref y) | (y, 0) => {}
 error[E0308]: mismatched types
   --> $DIR/E0409.rs:5:23
    |
-LL |     match x {
-   |           - this expression has type `({integer}, {integer})`
 LL |         (0, ref y) | (y, 0) => {}
    |             -----     ^ expected `&{integer}`, found integer
    |             |
index cad1cef5155d5f1ba54e81808a613ebbaa467129..ccc8ac1278c63576c2ed2d253c653f312e9f8338 100644 (file)
@@ -3,9 +3,6 @@ error[E0308]: mismatched types
    |
 LL |      let &_
    |          ^^ types differ in mutability
-...
-LL |         = foo;
-   |           --- this expression has type `&mut {integer}`
    |
    = note: expected mutable reference `&mut {integer}`
                       found reference `&_`
@@ -15,9 +12,6 @@ error[E0308]: mismatched types
    |
 LL |     let &mut _
    |         ^^^^^^ types differ in mutability
-...
-LL |          = bar;
-   |            --- this expression has type `&{integer}`
    |
    = note:      expected reference `&{integer}`
            found mutable reference `&mut _`
index 32967b376ca9c2b12dae6e9aee6bbbba0d10c90c..e99a38aaaee95834ad6d506f2bd4982a43f7f391 100644 (file)
@@ -1,15 +1,13 @@
 error[E0308]: mismatched types
   --> $DIR/diverging-tuple-parts-39485.rs:8:5
    |
+LL | fn g() {
+   |        - possibly return type missing here?
 LL |     &panic!()
    |     ^^^^^^^^^ expected `()`, found reference
    |
    = note: expected unit type `()`
               found reference `&_`
-help: try adding a return type
-   |
-LL | fn g() -> &_ {
-   |        +++++
 help: consider removing the borrow
    |
 LL -     &panic!()
index 66112165622b95ff35a27d74a4fdf908cf172567..92416a0d5cbf086d739ef3e5df92d4b9cae3d084 100644 (file)
@@ -86,9 +86,8 @@ error[E0308]: mismatched types
   --> $DIR/already-bound-name.rs:30:32
    |
 LL |     let (B(A(a, _) | B(a)) | A(a, A(a, _) | B(a))) = B(B(1));
-   |              -                 ^                     ------- this expression has type `E<E<{integer}>>`
-   |              |                 |
-   |              |                 expected integer, found enum `E`
+   |              -                 ^ expected integer, found enum `E`
+   |              |
    |              first introduced with type `{integer}` here
    |
    = note: expected type `{integer}`
index dae6bb41e74e296b67127be90a874cbcde098403..95e8618808c08e392f294200cf5e43c4fe57e5fa 100644 (file)
@@ -65,9 +65,8 @@ error[E0308]: mismatched types
   --> $DIR/inconsistent-modes.rs:13:32
    |
 LL |     let (Ok((ref a, b)) | Err((ref mut a, ref b))) = Ok((0, &0));
-   |              -----             ^^^^^^^^^             ----------- this expression has type `Result<({integer}, &{integer}), (_, _)>`
-   |              |                 |
-   |              |                 types differ in mutability
+   |              -----             ^^^^^^^^^ types differ in mutability
+   |              |
    |              first introduced with type `&{integer}` here
    |
    = note: expected type `&{integer}`
index f2e2c8f021badac2c2a555395adb7c74c33c7e19..53dcf97f81c6a4d765577e4c39525b9a16948f88 100644 (file)
@@ -22,9 +22,7 @@ error[E0308]: mismatched types
   --> $DIR/issue-74702.rs:2:9
    |
 LL |     let (foo @ ..,) = (0, 0);
-   |         ^^^^^^^^^^^   ------ this expression has type `({integer}, {integer})`
-   |         |
-   |         expected a tuple with 2 elements, found one with 1 element
+   |         ^^^^^^^^^^^ expected a tuple with 2 elements, found one with 1 element
    |
    = note: expected tuple `({integer}, {integer})`
               found tuple `(_,)`
index 1c44f7e5f6f1fa8e1015628fc662c57ffa388a10..64b6e5eec5562565ee52e6ae1dbac996574b0cad 100644 (file)
@@ -150,8 +150,6 @@ LL |         E1::Z0 => {}
 error[E0308]: mismatched types
   --> $DIR/pat-tuple-overfield.rs:19:9
    |
-LL |     match (1, 2, 3) {
-   |           --------- this expression has type `({integer}, {integer}, {integer})`
 LL |         (1, 2, 3, 4) => {}
    |         ^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 4 elements
    |
@@ -161,9 +159,6 @@ LL |         (1, 2, 3, 4) => {}
 error[E0308]: mismatched types
   --> $DIR/pat-tuple-overfield.rs:20:9
    |
-LL |     match (1, 2, 3) {
-   |           --------- this expression has type `({integer}, {integer}, {integer})`
-LL |         (1, 2, 3, 4) => {}
 LL |         (1, 2, .., 3, 4) => {}
    |         ^^^^^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 4 elements
    |
index 5af136e6011238497ff2b145661577b7a4ce979f..f86209a651d139d1f72aeeadfd110d42d69a76b2 100644 (file)
@@ -1,19 +1,15 @@
 error[E0308]: mismatched types
   --> $DIR/return-type.rs:10:5
    |
+LL | fn bar() {
+   |          - possibly return type missing here?
 LL |     foo(4 as usize)
-   |     ^^^^^^^^^^^^^^^ expected `()`, found struct `S`
+   |     ^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;`
+   |     |
+   |     expected `()`, found struct `S`
    |
    = note: expected unit type `()`
                  found struct `S<usize>`
-help: consider using a semicolon here
-   |
-LL |     foo(4 as usize);
-   |                    +
-help: try adding a return type
-   |
-LL | fn bar() -> S<usize> {
-   |          +++++++++++
 
 error: aborting due to previous error
 
index 3fc5cb1b079734ad94d5a8df71daf9248b1fbaec..1433a16d7274a57e4b074a51036f75440ccbd83c 100644 (file)
@@ -644,7 +644,9 @@ error[E0308]: mismatched types
   --> $DIR/disallowed-positions.rs:76:12
    |
 LL |     if let Range { start: F, end } = F..|| true {}
-   |            ^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found struct `std::ops::Range`
+   |            ^^^^^^^^^^^^^^^^^^^^^^^   - this expression has type `fn() -> bool`
+   |            |
+   |            expected fn pointer, found struct `std::ops::Range`
    |
    = note: expected fn pointer `fn() -> bool`
                   found struct `std::ops::Range<_>`
@@ -832,7 +834,9 @@ error[E0308]: mismatched types
   --> $DIR/disallowed-positions.rs:140:15
    |
 LL |     while let Range { start: F, end } = F..|| true {}
-   |               ^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found struct `std::ops::Range`
+   |               ^^^^^^^^^^^^^^^^^^^^^^^   - this expression has type `fn() -> bool`
+   |               |
+   |               expected fn pointer, found struct `std::ops::Range`
    |
    = note: expected fn pointer `fn() -> bool`
                   found struct `std::ops::Range<_>`
index 14f01f0ebdf7386055fcdec842f0ddce5d53b26c..61eabed950423834089b6d0a9dd8289d0200c1eb 100644 (file)
@@ -1,8 +1,6 @@
 error[E0308]: mismatched types
   --> $DIR/slightly-nice-generic-literal-messages.rs:7:9
    |
-LL |     match Foo(1.1, marker::PhantomData) {
-   |           ----------------------------- this expression has type `Foo<{float}, _>`
 LL |         1 => {}
    |         ^ expected struct `Foo`, found integer
    |
index 3d64fc601df988f32052207bbcddca2a85ebed28..98972a121599655cae0f36351dd2aa84dae2c516 100644 (file)
@@ -101,8 +101,6 @@ LL | type PointF = Point<f32>;
 error[E0308]: mismatched types
   --> $DIR/structure-constructor-type-mismatch.rs:54:9
    |
-LL |     match (Point { x: 1, y: 2 }) {
-   |           ---------------------- this expression has type `Point<{integer}>`
 LL |         PointF::<u32> { .. } => {}
    |         ^^^^^^^^^^^^^^^^^^^^ expected integer, found `f32`
    |
@@ -112,8 +110,6 @@ LL |         PointF::<u32> { .. } => {}
 error[E0308]: mismatched types
   --> $DIR/structure-constructor-type-mismatch.rs:59:9
    |
-LL |     match (Point { x: 1, y: 2 }) {
-   |           ---------------------- this expression has type `Point<{integer}>`
 LL |         PointF { .. } => {}
    |         ^^^^^^^^^^^^^ expected integer, found `f32`
    |
@@ -123,8 +119,6 @@ LL |         PointF { .. } => {}
 error[E0308]: mismatched types
   --> $DIR/structure-constructor-type-mismatch.rs:67:9
    |
-LL |     match (Pair { x: 1, y: 2 }) {
-   |           --------------------- this expression has type `Pair<{integer}, {integer}>`
 LL |         PairF::<u32> { .. } => {}
    |         ^^^^^^^^^^^^^^^^^^^ expected integer, found `f32`
    |
index b4d7dfe06be5473afbe510fa2d001b2500922bcb..b92a6f2ec2b485df7c3dd8c1378f6e8f7ba5232a 100644 (file)
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
   --> $DIR/issue-57673-ice-on-deref-of-boxed-trait.rs:5:5
    |
 LL | fn ice(x: Box<dyn Iterator<Item=()>>) {
-   |                                       - possibly return type missing here?
+   |                                       - help: try adding a return type: `-> (dyn Iterator<Item = ()> + 'static)`
 LL |     *x
    |     ^^ expected `()`, found trait object `dyn Iterator`
    |
index 358cc771b7c458e986741377bad39637826e8b4a..0872e83ea2e7e6917eff54dee6d4fb068d782a78 100644 (file)
@@ -40,7 +40,7 @@ error[E0308]: mismatched types
 LL | fn f(){||yield(((){),
    |       -^^^^^^^^^^^^^^^ expected `()`, found generator
    |       |
-   |       help: try adding a return type: `-> [generator@$DIR/issue-91334.rs:10:8: 10:23]`
+   |       possibly return type missing here?
    |
    = note: expected unit type `()`
               found generator `[generator@$DIR/issue-91334.rs:10:8: 10:23]`
diff --git a/src/test/ui/typeck/return_type_containing_closure.rs b/src/test/ui/typeck/return_type_containing_closure.rs
new file mode 100644 (file)
index 0000000..aee9769
--- /dev/null
@@ -0,0 +1,10 @@
+#[allow(unused)]
+fn foo() {
+    //~^ NOTE possibly return type missing here?
+    vec!['a'].iter().map(|c| c)
+    //~^ ERROR mismatched types [E0308]
+    //~| NOTE expected `()`, found struct `Map`
+    //~| NOTE expected unit type `()`
+}
+
+fn main() {}
diff --git a/src/test/ui/typeck/return_type_containing_closure.stderr b/src/test/ui/typeck/return_type_containing_closure.stderr
new file mode 100644 (file)
index 0000000..b08152d
--- /dev/null
@@ -0,0 +1,17 @@
+error[E0308]: mismatched types
+  --> $DIR/return_type_containing_closure.rs:4:5
+   |
+LL | fn foo() {
+   |          - possibly return type missing here?
+LL |
+LL |     vec!['a'].iter().map(|c| c)
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;`
+   |     |
+   |     expected `()`, found struct `Map`
+   |
+   = note: expected unit type `()`
+                 found struct `Map<std::slice::Iter<'_, char>, [closure@$DIR/return_type_containing_closure.rs:4:26: 4:31]>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.