From 4369a787300c22110ae5ea8d520870fd8bc975a0 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 19 Dec 2023 16:16:02 +0100 Subject: [PATCH 01/29] Add triagebot mentions entry for simd intrinsics --- triagebot.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/triagebot.toml b/triagebot.toml index e4b104cdb8677..8dcfb38e097b5 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -492,6 +492,13 @@ cc = ["@Nadrieril"] message = "Some changes might have occurred in exhaustiveness checking" cc = ["@Nadrieril"] +[mentions."library/core/src/intrinsics/simd.rs"] +message = """ +Some changes occurred to the platform-builtins intrinsics. Make sure all +codegen backends as well as portable-simd get adapted for the changes. +""" +cc = ["@antoyo", "@GuillaumeGomez", "@bjorn3", "@calebzulawski", "@programmerjake"] + [mentions."library/portable-simd"] message = """ Portable SIMD is developed in its own repository. If possible, consider \ From adb6e1b69bfba1e57ba5606797848199733e0f96 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 26 Dec 2023 12:42:40 +0100 Subject: [PATCH 02/29] Update triagebot.toml --- triagebot.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/triagebot.toml b/triagebot.toml index 8dcfb38e097b5..6acc698ec1b1c 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -494,8 +494,8 @@ cc = ["@Nadrieril"] [mentions."library/core/src/intrinsics/simd.rs"] message = """ -Some changes occurred to the platform-builtins intrinsics. Make sure all -codegen backends as well as portable-simd get adapted for the changes. +Some changes occurred to the platform-builtins intrinsics. Make sure the +LLVM backend as well as portable-simd gets adapted for the changes. """ cc = ["@antoyo", "@GuillaumeGomez", "@bjorn3", "@calebzulawski", "@programmerjake"] From bdf7404b43d683accd29c20c880c51c85ceaaccd Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 26 Jan 2024 14:46:17 +0100 Subject: [PATCH 03/29] Update codegen test for LLVM 18 --- tests/codegen/pow_of_two.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/codegen/pow_of_two.rs b/tests/codegen/pow_of_two.rs index a8c0550e33263..372360dfd12c7 100644 --- a/tests/codegen/pow_of_two.rs +++ b/tests/codegen/pow_of_two.rs @@ -4,7 +4,7 @@ #[no_mangle] pub fn a(exp: u32) -> u64 { // CHECK: %{{[^ ]+}} = icmp ugt i32 %exp, 64 - // CHECK: %{{[^ ]+}} = zext i32 %exp to i64 + // CHECK: %{{[^ ]+}} = zext{{( nneg)?}} i32 %exp to i64 // CHECK: %{{[^ ]+}} = shl nuw i64 {{[^ ]+}}, %{{[^ ]+}} // CHECK: ret i64 %{{[^ ]+}} 2u64.pow(exp) @@ -14,7 +14,7 @@ pub fn a(exp: u32) -> u64 { #[no_mangle] pub fn b(exp: u32) -> i64 { // CHECK: %{{[^ ]+}} = icmp ugt i32 %exp, 64 - // CHECK: %{{[^ ]+}} = zext i32 %exp to i64 + // CHECK: %{{[^ ]+}} = zext{{( nneg)?}} i32 %exp to i64 // CHECK: %{{[^ ]+}} = shl nuw i64 {{[^ ]+}}, %{{[^ ]+}} // CHECK: ret i64 %{{[^ ]+}} 2i64.pow(exp) From bdfb9172c187e5f3527c3a4aba3741badc279515 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 26 Jan 2024 17:54:41 +0100 Subject: [PATCH 04/29] interpret/memory: fix safety comment for large array memset optimization --- compiler/rustc_const_eval/src/interpret/memory.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 3afd14eb57435..38ad8cbf3a691 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -396,7 +396,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { /// to the allocation it points to. Supports both shared and mutable references, as the actual /// checking is offloaded to a helper closure. /// - /// If this returns `None`, the size is 0; it can however return `Some` even for size 0. + /// Returns `None` if and only if the size is 0. fn check_and_deref_ptr( &self, ptr: Pointer>, @@ -1214,10 +1214,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let size_in_bytes = size.bytes_usize(); // For particularly large arrays (where this is perf-sensitive) it's common that // we're writing a single byte repeatedly. So, optimize that case to a memset. - if size_in_bytes == 1 && num_copies >= 1 { - // SAFETY: `src_bytes` would be read from anyway by copies below (num_copies >= 1). - // Since size_in_bytes = 1, then the `init.no_bytes_init()` check above guarantees - // that this read at type `u8` is OK -- it must be an initialized byte. + if size_in_bytes == 1 { + debug_assert!(num_copies >= 1); // we already handled the zero-sized cases above. + // SAFETY: `src_bytes` would be read from anyway by `copy` below (num_copies >= 1). let value = *src_bytes; dest_bytes.write_bytes(value, (size * num_copies).bytes_usize()); } else if src_alloc_id == dest_alloc_id { From 3691ab8e7adc91f877ded39faba826f5c9f8a5a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 26 Jan 2024 20:07:37 +0000 Subject: [PATCH 05/29] Use only one label for multiple unsatisfied bounds on type (astconv) --- .../rustc_hir_analysis/src/astconv/errors.rs | 39 +++++++++++++------ ...nsatisfied-bounds-in-multiple-impls.stderr | 5 +-- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs index bfe88df4e1a55..b2d5d3885d938 100644 --- a/compiler/rustc_hir_analysis/src/astconv/errors.rs +++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs @@ -461,22 +461,24 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { return err.emit(); } - let mut bound_spans = Vec::new(); + let mut bound_spans: FxHashMap> = Default::default(); let mut bound_span_label = |self_ty: Ty<'_>, obligation: &str, quiet: &str| { - let msg = format!( - "doesn't satisfy `{}`", - if obligation.len() > 50 { quiet } else { obligation } - ); + let msg = format!("`{}`", if obligation.len() > 50 { quiet } else { obligation }); match &self_ty.kind() { // Point at the type that couldn't satisfy the bound. - ty::Adt(def, _) => bound_spans.push((tcx.def_span(def.did()), msg)), + ty::Adt(def, _) => { + bound_spans.entry(tcx.def_span(def.did())).or_default().push(msg) + } // Point at the trait object that couldn't satisfy the bound. ty::Dynamic(preds, _, _) => { for pred in preds.iter() { match pred.skip_binder() { ty::ExistentialPredicate::Trait(tr) => { - bound_spans.push((tcx.def_span(tr.def_id), msg.clone())) + bound_spans + .entry(tcx.def_span(tr.def_id)) + .or_default() + .push(msg.clone()); } ty::ExistentialPredicate::Projection(_) | ty::ExistentialPredicate::AutoTrait(_) => {} @@ -485,7 +487,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } // Point at the closure that couldn't satisfy the bound. ty::Closure(def_id, _) => { - bound_spans.push((tcx.def_span(*def_id), format!("doesn't satisfy `{quiet}`"))) + bound_spans + .entry(tcx.def_span(*def_id)) + .or_default() + .push(format!("`{quiet}`")); } _ => {} } @@ -554,12 +559,24 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { format!("associated type cannot be referenced on `{self_ty}` due to unsatisfied trait bounds") ); - bound_spans.sort(); - bound_spans.dedup(); - for (span, msg) in bound_spans { + let mut bound_spans: Vec<(Span, Vec)> = bound_spans + .into_iter() + .map(|(span, mut bounds)| { + bounds.sort(); + bounds.dedup(); + (span, bounds) + }) + .collect(); + bound_spans.sort_by_key(|(span, _)| *span); + for (span, bounds) in bound_spans { if !tcx.sess.source_map().is_span_accessible(span) { continue; } + let msg = match &bounds[..] { + [bound] => format!("doesn't satisfy {bound}"), + [bounds @ .., last] => format!("doesn't satisfy {} or {last}", bounds.join(", ")), + [] => unreachable!(), + }; err.span_label(span, msg); } add_def_label(&mut err); diff --git a/tests/ui/associated-inherent-types/not-found-unsatisfied-bounds-in-multiple-impls.stderr b/tests/ui/associated-inherent-types/not-found-unsatisfied-bounds-in-multiple-impls.stderr index 650b5946064c2..1613af6b8b152 100644 --- a/tests/ui/associated-inherent-types/not-found-unsatisfied-bounds-in-multiple-impls.stderr +++ b/tests/ui/associated-inherent-types/not-found-unsatisfied-bounds-in-multiple-impls.stderr @@ -4,10 +4,7 @@ error: the associated type `X` exists for `S`, but its LL | struct S(A, B); | -------------- associated item `X` not found for this struct LL | struct Featureless; - | ------------------ - | | - | doesn't satisfy `Featureless: One` - | doesn't satisfy `Featureless: Two` + | ------------------ doesn't satisfy `Featureless: One` or `Featureless: Two` ... LL | let _: S::::X; | ^ associated type cannot be referenced on `S` due to unsatisfied trait bounds From 757b726f8689c508dbd3979ea6b547a74d6481b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 26 Jan 2024 20:34:29 +0000 Subject: [PATCH 06/29] Use only one label for multiple unsatisfied bounds on type (typeck) --- .../rustc_hir_typeck/src/method/suggest.rs | 48 ++++++++++++++----- .../box/unit/unique-object-noncopyable.stderr | 15 ++---- tests/ui/box/unit/unique-pinned-nocopy.stderr | 12 ++--- .../deriving-with-repr-packed-2.stderr | 5 +- tests/ui/derives/issue-91550.stderr | 25 ++-------- ...gat-bound-during-assoc-ty-selection.stderr | 3 -- ...method-unsatisfied-assoc-type-predicate.rs | 3 +- ...od-unsatisfied-assoc-type-predicate.stderr | 5 +- .../ui/iterators/vec-on-unimplemented.stderr | 3 -- .../ui/mismatched_types/issue-36053-2.stderr | 6 +-- .../derive-trait-for-method-call.stderr | 16 +------ .../mut-borrow-needed-by-trait.stderr | 3 -- .../ui/suggestions/suggest-change-mut.stderr | 3 -- tests/ui/traits/track-obligations.stderr | 5 +- tests/ui/typeck/derive-sugg-arg-arity.stderr | 3 +- tests/ui/typeck/issue-31173.stderr | 6 --- 16 files changed, 56 insertions(+), 105 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 0b8a25eedafad..d7a0565895d3e 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -9,7 +9,7 @@ use crate::Expectation; use crate::FnCtxt; use rustc_ast::ast::Mutability; use rustc_attr::parse_confusables; -use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; +use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_data_structures::unord::UnordSet; use rustc_errors::StashKey; use rustc_errors::{ @@ -547,7 +547,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); } - let mut bound_spans = vec![]; + let mut bound_spans: FxHashMap> = Default::default(); let mut restrict_type_params = false; let mut unsatisfied_bounds = false; if item_name.name == sym::count && self.is_slice_ty(rcvr_ty, span) { @@ -642,19 +642,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { false }; let mut bound_span_label = |self_ty: Ty<'_>, obligation: &str, quiet: &str| { - let msg = format!( - "doesn't satisfy `{}`", - if obligation.len() > 50 { quiet } else { obligation } - ); + let msg = format!("`{}`", if obligation.len() > 50 { quiet } else { obligation }); match &self_ty.kind() { // Point at the type that couldn't satisfy the bound. - ty::Adt(def, _) => bound_spans.push((self.tcx.def_span(def.did()), msg)), + ty::Adt(def, _) => { + bound_spans.entry(tcx.def_span(def.did())).or_default().push(msg) + } // Point at the trait object that couldn't satisfy the bound. ty::Dynamic(preds, _, _) => { for pred in preds.iter() { match pred.skip_binder() { ty::ExistentialPredicate::Trait(tr) => { - bound_spans.push((self.tcx.def_span(tr.def_id), msg.clone())) + bound_spans + .entry(tcx.def_span(tr.def_id)) + .or_default() + .push(msg.clone()); } ty::ExistentialPredicate::Projection(_) | ty::ExistentialPredicate::AutoTrait(_) => {} @@ -662,8 +664,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } // Point at the closure that couldn't satisfy the bound. - ty::Closure(def_id, _) => bound_spans - .push((tcx.def_span(*def_id), format!("doesn't satisfy `{quiet}`"))), + ty::Closure(def_id, _) => { + bound_spans + .entry(tcx.def_span(*def_id)) + .or_default() + .push(format!("`{quiet}`")); + } _ => {} } }; @@ -1170,9 +1176,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.suggest_unwrapping_inner_self(&mut err, source, rcvr_ty, item_name); - bound_spans.sort(); - bound_spans.dedup(); - for (span, msg) in bound_spans.into_iter() { + #[allow(rustc::potential_query_instability)] // We immediately sort the resulting Vec. + let mut bound_spans: Vec<(Span, Vec)> = bound_spans + .into_iter() + .map(|(span, mut bounds)| { + bounds.sort(); + bounds.dedup(); + (span, bounds) + }) + .collect(); + bound_spans.sort_by_key(|(span, _)| *span); + for (span, bounds) in bound_spans { + if !tcx.sess.source_map().is_span_accessible(span) { + continue; + } + let msg = match &bounds[..] { + [bound] => format!("doesn't satisfy {bound}"), + [bounds @ .., last] => format!("doesn't satisfy {} or {last}", bounds.join(", ")), + [] => unreachable!(), + }; err.span_label(span, msg); } diff --git a/tests/ui/box/unit/unique-object-noncopyable.stderr b/tests/ui/box/unit/unique-object-noncopyable.stderr index 1b98d09ccddb0..49547872d1a7b 100644 --- a/tests/ui/box/unit/unique-object-noncopyable.stderr +++ b/tests/ui/box/unit/unique-object-noncopyable.stderr @@ -1,18 +1,11 @@ error[E0599]: the method `clone` exists for struct `Box`, but its trait bounds were not satisfied --> $DIR/unique-object-noncopyable.rs:24:16 | -LL | trait Foo { - | --------- - | | - | doesn't satisfy `dyn Foo: Clone` - | doesn't satisfy `dyn Foo: Sized` +LL | trait Foo { + | --------- doesn't satisfy `dyn Foo: Clone` or `dyn Foo: Sized` ... -LL | let _z = y.clone(); - | ^^^^^ method cannot be called on `Box` due to unsatisfied trait bounds - --> $SRC_DIR/alloc/src/boxed.rs:LL:COL - ::: $SRC_DIR/alloc/src/boxed.rs:LL:COL - | - = note: doesn't satisfy `Box: Clone` +LL | let _z = y.clone(); + | ^^^^^ method cannot be called on `Box` due to unsatisfied trait bounds | = note: the following trait bounds were not satisfied: `dyn Foo: Sized` diff --git a/tests/ui/box/unit/unique-pinned-nocopy.stderr b/tests/ui/box/unit/unique-pinned-nocopy.stderr index d662a2d6d0512..d2bf72249c451 100644 --- a/tests/ui/box/unit/unique-pinned-nocopy.stderr +++ b/tests/ui/box/unit/unique-pinned-nocopy.stderr @@ -1,15 +1,11 @@ error[E0599]: the method `clone` exists for struct `Box`, but its trait bounds were not satisfied --> $DIR/unique-pinned-nocopy.rs:12:16 | -LL | struct R { - | -------- doesn't satisfy `R: Clone` +LL | struct R { + | -------- doesn't satisfy `R: Clone` ... -LL | let _j = i.clone(); - | ^^^^^ method cannot be called on `Box` due to unsatisfied trait bounds - --> $SRC_DIR/alloc/src/boxed.rs:LL:COL - ::: $SRC_DIR/alloc/src/boxed.rs:LL:COL - | - = note: doesn't satisfy `Box: Clone` +LL | let _j = i.clone(); + | ^^^^^ method cannot be called on `Box` due to unsatisfied trait bounds | = note: the following trait bounds were not satisfied: `R: Clone` diff --git a/tests/ui/derives/deriving-with-repr-packed-2.stderr b/tests/ui/derives/deriving-with-repr-packed-2.stderr index 0eaca7e236098..172dd80fe1d09 100644 --- a/tests/ui/derives/deriving-with-repr-packed-2.stderr +++ b/tests/ui/derives/deriving-with-repr-packed-2.stderr @@ -8,10 +8,7 @@ LL | pub struct Foo(T, T, T); | doesn't satisfy `Foo: Clone` LL | LL | struct NonCopy; - | -------------- - | | - | doesn't satisfy `NonCopy: Clone` - | doesn't satisfy `NonCopy: Copy` + | -------------- doesn't satisfy `NonCopy: Clone` or `NonCopy: Copy` ... LL | _ = x.clone(); | ^^^^^ method cannot be called on `Foo` due to unsatisfied trait bounds diff --git a/tests/ui/derives/issue-91550.stderr b/tests/ui/derives/issue-91550.stderr index 1324b80b5fcdb..9e17189671827 100644 --- a/tests/ui/derives/issue-91550.stderr +++ b/tests/ui/derives/issue-91550.stderr @@ -2,11 +2,7 @@ error[E0599]: the method `insert` exists for struct `HashSet`, but its tr --> $DIR/issue-91550.rs:8:8 | LL | struct Value(u32); - | ------------ - | | - | doesn't satisfy `Value: Eq` - | doesn't satisfy `Value: Hash` - | doesn't satisfy `Value: PartialEq` + | ------------ doesn't satisfy `Value: Eq`, `Value: Hash` or `Value: PartialEq` ... LL | hs.insert(Value(0)); | ^^^^^^ @@ -26,10 +22,7 @@ error[E0599]: the method `use_eq` exists for struct `Object`, but its --> $DIR/issue-91550.rs:26:9 | LL | pub struct NoDerives; - | -------------------- - | | - | doesn't satisfy `NoDerives: Eq` - | doesn't satisfy `NoDerives: PartialEq` + | -------------------- doesn't satisfy `NoDerives: Eq` or `NoDerives: PartialEq` LL | LL | struct Object(T); | ---------------- method `use_eq` not found for this struct @@ -57,12 +50,7 @@ error[E0599]: the method `use_ord` exists for struct `Object`, but it --> $DIR/issue-91550.rs:27:9 | LL | pub struct NoDerives; - | -------------------- - | | - | doesn't satisfy `NoDerives: Eq` - | doesn't satisfy `NoDerives: Ord` - | doesn't satisfy `NoDerives: PartialEq` - | doesn't satisfy `NoDerives: PartialOrd` + | -------------------- doesn't satisfy `NoDerives: Eq`, `NoDerives: Ord`, `NoDerives: PartialEq` or `NoDerives: PartialOrd` LL | LL | struct Object(T); | ---------------- method `use_ord` not found for this struct @@ -94,12 +82,7 @@ error[E0599]: the method `use_ord_and_partial_ord` exists for struct `Object $DIR/issue-91550.rs:28:9 | LL | pub struct NoDerives; - | -------------------- - | | - | doesn't satisfy `NoDerives: Eq` - | doesn't satisfy `NoDerives: Ord` - | doesn't satisfy `NoDerives: PartialEq` - | doesn't satisfy `NoDerives: PartialOrd` + | -------------------- doesn't satisfy `NoDerives: Eq`, `NoDerives: Ord`, `NoDerives: PartialEq` or `NoDerives: PartialOrd` LL | LL | struct Object(T); | ---------------- method `use_ord_and_partial_ord` not found for this struct diff --git a/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr b/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr index 3a973d356dc98..2ce10ce9c1cc0 100644 --- a/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr +++ b/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr @@ -26,9 +26,6 @@ LL | enum Node { ... LL | let mut list = RcNode::::new(); | ^^^ doesn't have a size known at compile-time - --> $SRC_DIR/core/src/ops/deref.rs:LL:COL - | - = note: doesn't satisfy `_: Sized` | note: trait bound `Node: Sized` was not satisfied --> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:4:18 diff --git a/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.rs b/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.rs index 83655341d6a24..1f9e4f24b161c 100644 --- a/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.rs +++ b/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.rs @@ -17,8 +17,7 @@ impl = i32>> M for T {} struct S; //~^ NOTE method `f` not found for this -//~| NOTE doesn't satisfy `::Y = i32` -//~| NOTE doesn't satisfy `S: M` +//~| NOTE doesn't satisfy `::Y = i32` or `S: M` impl X for S { type Y = bool; diff --git a/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.stderr b/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.stderr index 7ca0b2912a68a..489b2772ad8c3 100644 --- a/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.stderr +++ b/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.stderr @@ -1,12 +1,11 @@ error[E0599]: the method `f` exists for struct `S`, but its trait bounds were not satisfied - --> $DIR/method-unsatisfied-assoc-type-predicate.rs:28:7 + --> $DIR/method-unsatisfied-assoc-type-predicate.rs:27:7 | LL | struct S; | -------- | | | method `f` not found for this struct - | doesn't satisfy `::Y = i32` - | doesn't satisfy `S: M` + | doesn't satisfy `::Y = i32` or `S: M` ... LL | a.f(); | ^ method cannot be called on `S` due to unsatisfied trait bounds diff --git a/tests/ui/iterators/vec-on-unimplemented.stderr b/tests/ui/iterators/vec-on-unimplemented.stderr index e2a80dbffdeaa..29b19d5e3b45b 100644 --- a/tests/ui/iterators/vec-on-unimplemented.stderr +++ b/tests/ui/iterators/vec-on-unimplemented.stderr @@ -3,9 +3,6 @@ error[E0599]: `Vec` is not an iterator | LL | vec![true, false].map(|v| !v).collect::>(); | ^^^ `Vec` is not an iterator; try calling `.into_iter()` or `.iter()` - --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL - | - = note: doesn't satisfy `Vec: Iterator` | = note: the following trait bounds were not satisfied: `Vec: Iterator` diff --git a/tests/ui/mismatched_types/issue-36053-2.stderr b/tests/ui/mismatched_types/issue-36053-2.stderr index 292525daa3d6b..6d23319ca7e64 100644 --- a/tests/ui/mismatched_types/issue-36053-2.stderr +++ b/tests/ui/mismatched_types/issue-36053-2.stderr @@ -21,11 +21,7 @@ error[E0599]: the method `count` exists for struct `Filter>, {cl LL | once::<&str>("str").fuse().filter(|a: &str| true).count(); | --------- ^^^^^ method cannot be called due to unsatisfied trait bounds | | - | doesn't satisfy `<_ as FnOnce<(&&str,)>>::Output = bool` - | doesn't satisfy `_: FnMut<(&&str,)>` - --> $SRC_DIR/core/src/iter/adapters/filter.rs:LL:COL - | - = note: doesn't satisfy `_: Iterator` + | doesn't satisfy `<_ as FnOnce<(&&str,)>>::Output = bool` or `_: FnMut<(&&str,)>` | = note: the following trait bounds were not satisfied: `<{closure@$DIR/issue-36053-2.rs:7:39: 7:48} as FnOnce<(&&str,)>>::Output = bool` diff --git a/tests/ui/suggestions/derive-trait-for-method-call.stderr b/tests/ui/suggestions/derive-trait-for-method-call.stderr index e2db0da74f022..9d6d29ec74eec 100644 --- a/tests/ui/suggestions/derive-trait-for-method-call.stderr +++ b/tests/ui/suggestions/derive-trait-for-method-call.stderr @@ -2,10 +2,7 @@ error[E0599]: the method `test` exists for struct `Foo`, but it --> $DIR/derive-trait-for-method-call.rs:28:15 | LL | enum Enum { - | --------- - | | - | doesn't satisfy `Enum: Clone` - | doesn't satisfy `Enum: Default` + | --------- doesn't satisfy `Enum: Clone` or `Enum: Default` ... LL | enum CloneEnum { | -------------- doesn't satisfy `CloneEnum: Default` @@ -40,10 +37,7 @@ error[E0599]: the method `test` exists for struct `Foo`, bu --> $DIR/derive-trait-for-method-call.rs:34:15 | LL | struct Struct { - | ------------- - | | - | doesn't satisfy `Struct: Clone` - | doesn't satisfy `Struct: Default` + | ------------- doesn't satisfy `Struct: Clone` or `Struct: Default` ... LL | struct CloneStruct { | ------------------ doesn't satisfy `CloneStruct: Default` @@ -85,12 +79,6 @@ LL | struct Foo (X, Y); ... LL | let y = x.test(); | ^^^^ method cannot be called on `Foo, Instant>` due to unsatisfied trait bounds - --> $SRC_DIR/std/src/time.rs:LL:COL - | - = note: doesn't satisfy `Instant: Default` - --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL - | - = note: doesn't satisfy `Vec: Clone` | note: the following trait bounds were not satisfied: `Instant: Default` diff --git a/tests/ui/suggestions/mut-borrow-needed-by-trait.stderr b/tests/ui/suggestions/mut-borrow-needed-by-trait.stderr index 94710f4503f56..09a9b1d3b3482 100644 --- a/tests/ui/suggestions/mut-borrow-needed-by-trait.stderr +++ b/tests/ui/suggestions/mut-borrow-needed-by-trait.stderr @@ -25,9 +25,6 @@ error[E0599]: the method `write_fmt` exists for struct `BufWriter<&dyn Write>`, | LL | writeln!(fp, "hello world").unwrap(); | ---------^^---------------- method cannot be called on `BufWriter<&dyn Write>` due to unsatisfied trait bounds - --> $SRC_DIR/std/src/io/buffered/bufwriter.rs:LL:COL - | - = note: doesn't satisfy `BufWriter<&dyn std::io::Write>: std::io::Write` | note: must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method --> $DIR/mut-borrow-needed-by-trait.rs:21:14 diff --git a/tests/ui/suggestions/suggest-change-mut.stderr b/tests/ui/suggestions/suggest-change-mut.stderr index d194afeaf931d..216d1e810fd72 100644 --- a/tests/ui/suggestions/suggest-change-mut.stderr +++ b/tests/ui/suggestions/suggest-change-mut.stderr @@ -27,9 +27,6 @@ error[E0599]: the method `read_until` exists for struct `BufReader<&T>`, but its | LL | stream_reader.read_until(b'\n', &mut buffer).expect("Reading into buffer failed"); | ^^^^^^^^^^ method cannot be called on `BufReader<&T>` due to unsatisfied trait bounds - --> $SRC_DIR/std/src/io/buffered/bufreader.rs:LL:COL - | - = note: doesn't satisfy `BufReader<&T>: BufRead` | = note: the following trait bounds were not satisfied: `&T: std::io::Read` diff --git a/tests/ui/traits/track-obligations.stderr b/tests/ui/traits/track-obligations.stderr index 89477475970f4..822fc91e43fea 100644 --- a/tests/ui/traits/track-obligations.stderr +++ b/tests/ui/traits/track-obligations.stderr @@ -2,10 +2,7 @@ error[E0599]: the method `check` exists for struct `Client<()>`, but its trait b --> $DIR/track-obligations.rs:83:16 | LL | struct ALayer(C); - | ---------------- - | | - | doesn't satisfy `<_ as Layer<()>>::Service = as ParticularServiceLayer<()>>::Service` - | doesn't satisfy `ALayer<()>: ParticularServiceLayer<()>` + | ---------------- doesn't satisfy `<_ as Layer<()>>::Service = as ParticularServiceLayer<()>>::Service` or `ALayer<()>: ParticularServiceLayer<()>` ... LL | struct Client(C); | ---------------- method `check` not found for this struct diff --git a/tests/ui/typeck/derive-sugg-arg-arity.stderr b/tests/ui/typeck/derive-sugg-arg-arity.stderr index 41b16a772ca95..46421ba942c57 100644 --- a/tests/ui/typeck/derive-sugg-arg-arity.stderr +++ b/tests/ui/typeck/derive-sugg-arg-arity.stderr @@ -5,8 +5,7 @@ LL | pub struct A; | ------------ | | | function or associated item `partial_cmp` not found for this struct - | doesn't satisfy `A: Iterator` - | doesn't satisfy `A: PartialOrd<_>` + | doesn't satisfy `A: Iterator` or `A: PartialOrd<_>` ... LL | _ => match A::partial_cmp() {}, | ^^^^^^^^^^^ function or associated item cannot be called on `A` due to unsatisfied trait bounds diff --git a/tests/ui/typeck/issue-31173.stderr b/tests/ui/typeck/issue-31173.stderr index d65c4306a5f28..0983147a5f0c5 100644 --- a/tests/ui/typeck/issue-31173.stderr +++ b/tests/ui/typeck/issue-31173.stderr @@ -35,12 +35,6 @@ LL | | .collect(); | | -^^^^^^^ method cannot be called due to unsatisfied trait bounds | |_________| | - --> $SRC_DIR/core/src/iter/adapters/take_while.rs:LL:COL - | - = note: doesn't satisfy `<_ as Iterator>::Item = &_` - --> $SRC_DIR/core/src/iter/adapters/cloned.rs:LL:COL - | - = note: doesn't satisfy `_: Iterator` | = note: the following trait bounds were not satisfied: `, {closure@$DIR/issue-31173.rs:7:21: 7:25}> as Iterator>::Item = &_` From 7df4a09fc4e236f854273202e124747d47246ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 26 Jan 2024 20:44:43 +0000 Subject: [PATCH 07/29] Use single label for method not found due to unmet bound --- .../rustc_hir_typeck/src/method/suggest.rs | 35 ++++++++++++------- .../derives/derive-assoc-type-not-impl.stderr | 5 +-- .../deriving-with-repr-packed-2.stderr | 5 +-- ...gat-bound-during-assoc-ty-selection.stderr | 5 +-- ...method-unsatisfied-assoc-type-predicate.rs | 3 +- ...od-unsatisfied-assoc-type-predicate.stderr | 7 ++-- .../trait-bounds/issue-30786.stderr | 10 ++---- tests/ui/methods/method-call-err-msg.stderr | 5 +-- ...pecialization-trait-not-implemented.stderr | 5 +-- ...impl-derived-implicit-sized-bound-2.stderr | 5 +-- .../impl-derived-implicit-sized-bound.stderr | 5 +-- tests/ui/typeck/derive-sugg-arg-arity.stderr | 5 +-- tests/ui/union/union-derive-clone.stderr | 5 +-- 13 files changed, 37 insertions(+), 63 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index d7a0565895d3e..0499a46dbb826 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -459,22 +459,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); } - let ty_span = match rcvr_ty.kind() { + let mut ty_span = match rcvr_ty.kind() { ty::Param(param_type) => { Some(param_type.span_from_generics(self.tcx, self.body_id.to_def_id())) } ty::Adt(def, _) if def.did().is_local() => Some(tcx.def_span(def.did())), _ => None, }; - if let Some(span) = ty_span { - err.span_label( - span, - format!( - "{item_kind} `{item_name}` not found for this {}", - rcvr_ty.prefix_string(self.tcx) - ), - ); - } if let SelfSource::MethodCall(rcvr_expr) = source { self.suggest_fn_call(&mut err, rcvr_expr, rcvr_ty, |output_ty| { @@ -1190,13 +1181,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if !tcx.sess.source_map().is_span_accessible(span) { continue; } + let pre = if Some(span) == ty_span { + ty_span.take(); + format!( + "{item_kind} `{item_name}` not found for this {} because it ", + rcvr_ty.prefix_string(self.tcx) + ) + } else { + String::new() + }; let msg = match &bounds[..] { - [bound] => format!("doesn't satisfy {bound}"), - [bounds @ .., last] => format!("doesn't satisfy {} or {last}", bounds.join(", ")), + [bound] => format!("{pre}doesn't satisfy {bound}"), + [bounds @ .., last] => { + format!("{pre}doesn't satisfy {} or {last}", bounds.join(", ")) + } [] => unreachable!(), }; err.span_label(span, msg); } + if let Some(span) = ty_span { + err.span_label( + span, + format!( + "{item_kind} `{item_name}` not found for this {}", + rcvr_ty.prefix_string(self.tcx) + ), + ); + } if rcvr_ty.is_numeric() && rcvr_ty.is_fresh() || restrict_type_params { } else { diff --git a/tests/ui/derives/derive-assoc-type-not-impl.stderr b/tests/ui/derives/derive-assoc-type-not-impl.stderr index 6cbcb455f87e9..61268ffc7f852 100644 --- a/tests/ui/derives/derive-assoc-type-not-impl.stderr +++ b/tests/ui/derives/derive-assoc-type-not-impl.stderr @@ -2,10 +2,7 @@ error[E0599]: the method `clone` exists for struct `Bar`, but its trai --> $DIR/derive-assoc-type-not-impl.rs:18:30 | LL | struct Bar { - | ------------------ - | | - | method `clone` not found for this struct - | doesn't satisfy `Bar: Clone` + | ------------------ method `clone` not found for this struct because it doesn't satisfy `Bar: Clone` ... LL | struct NotClone; | --------------- doesn't satisfy `NotClone: Clone` diff --git a/tests/ui/derives/deriving-with-repr-packed-2.stderr b/tests/ui/derives/deriving-with-repr-packed-2.stderr index 172dd80fe1d09..96f51a4e7a2b4 100644 --- a/tests/ui/derives/deriving-with-repr-packed-2.stderr +++ b/tests/ui/derives/deriving-with-repr-packed-2.stderr @@ -2,10 +2,7 @@ error[E0599]: the method `clone` exists for struct `Foo`, but its trait --> $DIR/deriving-with-repr-packed-2.rs:18:11 | LL | pub struct Foo(T, T, T); - | ----------------- - | | - | method `clone` not found for this struct - | doesn't satisfy `Foo: Clone` + | ----------------- method `clone` not found for this struct because it doesn't satisfy `Foo: Clone` LL | LL | struct NonCopy; | -------------- doesn't satisfy `NonCopy: Clone` or `NonCopy: Copy` diff --git a/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr b/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr index 2ce10ce9c1cc0..7813370ae63f8 100644 --- a/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr +++ b/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr @@ -19,10 +19,7 @@ error[E0599]: the size for values of type `Node` cannot be known --> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:31:35 | LL | enum Node { - | ------------------------------ - | | - | variant or associated item `new` not found for this enum - | doesn't satisfy `Node: Sized` + | ------------------------------ variant or associated item `new` not found for this enum because it doesn't satisfy `Node: Sized` ... LL | let mut list = RcNode::::new(); | ^^^ doesn't have a size known at compile-time diff --git a/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.rs b/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.rs index 1f9e4f24b161c..add4d58f86a0d 100644 --- a/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.rs +++ b/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.rs @@ -16,8 +16,7 @@ impl = i32>> M for T {} //~| NOTE struct S; -//~^ NOTE method `f` not found for this -//~| NOTE doesn't satisfy `::Y = i32` or `S: M` +//~^ NOTE method `f` not found for this struct because it doesn't satisfy `::Y = i32` or `S: M` impl X for S { type Y = bool; diff --git a/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.stderr b/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.stderr index 489b2772ad8c3..1dd463f996ce6 100644 --- a/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.stderr +++ b/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.stderr @@ -1,11 +1,8 @@ error[E0599]: the method `f` exists for struct `S`, but its trait bounds were not satisfied - --> $DIR/method-unsatisfied-assoc-type-predicate.rs:27:7 + --> $DIR/method-unsatisfied-assoc-type-predicate.rs:26:7 | LL | struct S; - | -------- - | | - | method `f` not found for this struct - | doesn't satisfy `::Y = i32` or `S: M` + | -------- method `f` not found for this struct because it doesn't satisfy `::Y = i32` or `S: M` ... LL | a.f(); | ^ method cannot be called on `S` due to unsatisfied trait bounds diff --git a/tests/ui/higher-ranked/trait-bounds/issue-30786.stderr b/tests/ui/higher-ranked/trait-bounds/issue-30786.stderr index 4f9ceb577c0be..73870703cfbac 100644 --- a/tests/ui/higher-ranked/trait-bounds/issue-30786.stderr +++ b/tests/ui/higher-ranked/trait-bounds/issue-30786.stderr @@ -2,10 +2,7 @@ error[E0599]: the method `filterx` exists for struct `Map $DIR/issue-30786.rs:120:22 | LL | pub struct Map { - | -------------------- - | | - | method `filterx` not found for this struct - | doesn't satisfy `_: StreamExt` + | -------------------- method `filterx` not found for this struct because it doesn't satisfy `_: StreamExt` ... LL | let filter = map.filterx(|x: &_| true); | ^^^^^^^ method cannot be called on `Map` due to unsatisfied trait bounds @@ -23,10 +20,7 @@ error[E0599]: the method `countx` exists for struct `Filter $DIR/issue-30786.rs:132:24 | LL | pub struct Filter { - | ----------------------- - | | - | method `countx` not found for this struct - | doesn't satisfy `_: StreamExt` + | ----------------------- method `countx` not found for this struct because it doesn't satisfy `_: StreamExt` ... LL | let count = filter.countx(); | ^^^^^^ method cannot be called due to unsatisfied trait bounds diff --git a/tests/ui/methods/method-call-err-msg.stderr b/tests/ui/methods/method-call-err-msg.stderr index bd51378cf1a50..f431085745405 100644 --- a/tests/ui/methods/method-call-err-msg.stderr +++ b/tests/ui/methods/method-call-err-msg.stderr @@ -49,10 +49,7 @@ error[E0599]: `Foo` is not an iterator --> $DIR/method-call-err-msg.rs:19:7 | LL | pub struct Foo; - | -------------- - | | - | method `take` not found for this struct - | doesn't satisfy `Foo: Iterator` + | -------------- method `take` not found for this struct because it doesn't satisfy `Foo: Iterator` ... LL | / y.zero() LL | | .take() diff --git a/tests/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr b/tests/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr index 75c91e4806f77..e9b0845ccf707 100644 --- a/tests/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr +++ b/tests/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr @@ -12,10 +12,7 @@ error[E0599]: the method `foo_one` exists for struct `MyStruct`, but its trait b --> $DIR/specialization-trait-not-implemented.rs:22:29 | LL | struct MyStruct; - | --------------- - | | - | method `foo_one` not found for this struct - | doesn't satisfy `MyStruct: Foo` + | --------------- method `foo_one` not found for this struct because it doesn't satisfy `MyStruct: Foo` ... LL | println!("{}", MyStruct.foo_one()); | ^^^^^^^ method cannot be called on `MyStruct` due to unsatisfied trait bounds diff --git a/tests/ui/trait-bounds/impl-derived-implicit-sized-bound-2.stderr b/tests/ui/trait-bounds/impl-derived-implicit-sized-bound-2.stderr index 84c2ab68da958..397e80197b952 100644 --- a/tests/ui/trait-bounds/impl-derived-implicit-sized-bound-2.stderr +++ b/tests/ui/trait-bounds/impl-derived-implicit-sized-bound-2.stderr @@ -2,10 +2,7 @@ error[E0599]: the method `get` exists for struct `Victim<'_, Self>`, but its tra --> $DIR/impl-derived-implicit-sized-bound-2.rs:28:19 | LL | struct Victim<'a, T: Perpetrator + ?Sized> { - | ------------------------------------------ - | | - | method `get` not found for this struct - | doesn't satisfy `Victim<'_, Self>: VictimTrait` + | ------------------------------------------ method `get` not found for this struct because it doesn't satisfy `Victim<'_, Self>: VictimTrait` ... LL | self.getter().get(); | ^^^ method cannot be called on `Victim<'_, Self>` due to unsatisfied trait bounds diff --git a/tests/ui/trait-bounds/impl-derived-implicit-sized-bound.stderr b/tests/ui/trait-bounds/impl-derived-implicit-sized-bound.stderr index c597ad0b572ee..abcd915c699c4 100644 --- a/tests/ui/trait-bounds/impl-derived-implicit-sized-bound.stderr +++ b/tests/ui/trait-bounds/impl-derived-implicit-sized-bound.stderr @@ -2,10 +2,7 @@ error[E0599]: the method `get` exists for struct `Victim<'_, Self>`, but its tra --> $DIR/impl-derived-implicit-sized-bound.rs:31:19 | LL | struct Victim<'a, T: Perpetrator + ?Sized> - | ------------------------------------------ - | | - | method `get` not found for this struct - | doesn't satisfy `Victim<'_, Self>: VictimTrait` + | ------------------------------------------ method `get` not found for this struct because it doesn't satisfy `Victim<'_, Self>: VictimTrait` ... LL | self.getter().get(); | ^^^ method cannot be called on `Victim<'_, Self>` due to unsatisfied trait bounds diff --git a/tests/ui/typeck/derive-sugg-arg-arity.stderr b/tests/ui/typeck/derive-sugg-arg-arity.stderr index 46421ba942c57..382b324c4cc50 100644 --- a/tests/ui/typeck/derive-sugg-arg-arity.stderr +++ b/tests/ui/typeck/derive-sugg-arg-arity.stderr @@ -2,10 +2,7 @@ error[E0599]: the function or associated item `partial_cmp` exists for struct `A --> $DIR/derive-sugg-arg-arity.rs:5:23 | LL | pub struct A; - | ------------ - | | - | function or associated item `partial_cmp` not found for this struct - | doesn't satisfy `A: Iterator` or `A: PartialOrd<_>` + | ------------ function or associated item `partial_cmp` not found for this struct because it doesn't satisfy `A: Iterator` or `A: PartialOrd<_>` ... LL | _ => match A::partial_cmp() {}, | ^^^^^^^^^^^ function or associated item cannot be called on `A` due to unsatisfied trait bounds diff --git a/tests/ui/union/union-derive-clone.stderr b/tests/ui/union/union-derive-clone.stderr index 39f1e32e6eb71..a2b81f0dba1c3 100644 --- a/tests/ui/union/union-derive-clone.stderr +++ b/tests/ui/union/union-derive-clone.stderr @@ -17,10 +17,7 @@ error[E0599]: the method `clone` exists for union `U5`, but its tra --> $DIR/union-derive-clone.rs:35:15 | LL | union U5 { - | ----------- - | | - | method `clone` not found for this union - | doesn't satisfy `U5: Clone` + | ----------- method `clone` not found for this union because it doesn't satisfy `U5: Clone` ... LL | struct CloneNoCopy; | ------------------ doesn't satisfy `CloneNoCopy: Copy` From cda898b0d9a34e4a3615e879fcd4fb2da3fcead5 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sat, 27 Jan 2024 14:55:15 +0100 Subject: [PATCH 08/29] Remove unnecessary unit returns in query declarations For consistency with normal functions. --- compiler/rustc_middle/src/query/mod.rs | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 1122f571fff8a..b383a6f5e52c8 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -109,7 +109,7 @@ pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsure, TyCtxtEnsureWithValue // as they will raise an fatal error on query cycles instead. rustc_queries! { /// This exists purely for testing the interactions between span_delayed_bug and incremental. - query trigger_span_delayed_bug(key: DefId) -> () { + query trigger_span_delayed_bug(key: DefId) { desc { "triggering a span delayed bug for testing incremental" } } @@ -119,7 +119,7 @@ rustc_queries! { desc { "compute registered tools for crate" } } - query early_lint_checks(_: ()) -> () { + query early_lint_checks(_: ()) { desc { "perform lints prior to macro expansion" } } @@ -299,7 +299,7 @@ rustc_queries! { /// name. This is useful for cases were not all linting code from rustc /// was called. With the default `None` all registered lints will also /// be checked for expectation fulfillment. - query check_expectations(key: Option) -> () { + query check_expectations(key: Option) { eval_always desc { "checking lint expectations (RFC 2383)" } } @@ -906,39 +906,39 @@ rustc_queries! { } /// Performs lint checking for the module. - query lint_mod(key: LocalModDefId) -> () { + query lint_mod(key: LocalModDefId) { desc { |tcx| "linting {}", describe_as_module(key, tcx) } } - query check_unused_traits(_: ()) -> () { + query check_unused_traits(_: ()) { desc { "checking unused trait imports in crate" } } /// Checks the attributes in the module. - query check_mod_attrs(key: LocalModDefId) -> () { + query check_mod_attrs(key: LocalModDefId) { desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) } } /// Checks for uses of unstable APIs in the module. - query check_mod_unstable_api_usage(key: LocalModDefId) -> () { + query check_mod_unstable_api_usage(key: LocalModDefId) { desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) } } /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`). - query check_mod_const_bodies(key: LocalModDefId) -> () { + query check_mod_const_bodies(key: LocalModDefId) { desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) } } /// Checks the loops in the module. - query check_mod_loops(key: LocalModDefId) -> () { + query check_mod_loops(key: LocalModDefId) { desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) } } - query check_mod_naked_functions(key: LocalModDefId) -> () { + query check_mod_naked_functions(key: LocalModDefId) { desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) } } - query check_mod_privacy(key: LocalModDefId) -> () { + query check_mod_privacy(key: LocalModDefId) { desc { |tcx| "checking privacy in {}", describe_as_module(key.to_local_def_id(), tcx) } } @@ -958,7 +958,7 @@ rustc_queries! { desc { "finding live symbols in crate" } } - query check_mod_deathness(key: LocalModDefId) -> () { + query check_mod_deathness(key: LocalModDefId) { desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) } } @@ -972,7 +972,7 @@ rustc_queries! { ensure_forwards_result_if_red } - query collect_mod_item_types(key: LocalModDefId) -> () { + query collect_mod_item_types(key: LocalModDefId) { desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) } } @@ -1121,7 +1121,7 @@ rustc_queries! { eval_always desc { "checking effective visibilities" } } - query check_private_in_public(_: ()) -> () { + query check_private_in_public(_: ()) { eval_always desc { "checking for private elements in public interfaces" } } From 2251e9abee68f1f8ad7b80938b2e36a96f7768c1 Mon Sep 17 00:00:00 2001 From: Kornel Date: Mon, 15 Jan 2024 11:28:13 +0000 Subject: [PATCH 09/29] Reject infinitely-sized reads from io::Repeat Related to #117925 --- library/std/src/io/util.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/std/src/io/util.rs b/library/std/src/io/util.rs index 6bc8f181c905f..a04bc4811460b 100644 --- a/library/std/src/io/util.rs +++ b/library/std/src/io/util.rs @@ -204,6 +204,16 @@ impl Read for Repeat { Ok(()) } + /// This function is not supported by `io::Repeat`, because there's no end of its data + fn read_to_end(&mut self, _: &mut Vec) -> io::Result { + Err(io::Error::from(io::ErrorKind::OutOfMemory)) + } + + /// This function is not supported by `io::Repeat`, because there's no end of its data + fn read_to_string(&mut self, _: &mut String) -> io::Result { + Err(io::Error::from(io::ErrorKind::OutOfMemory)) + } + #[inline] fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { let mut nwritten = 0; From 5d8c1780fae725ce02a1c4619809347e55af67eb Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 27 Jan 2024 00:50:31 +0000 Subject: [PATCH 10/29] Make the coroutine def id of an async closure the child of the closure def id --- compiler/rustc_resolve/src/def_collector.rs | 18 ++++++++++++------ .../ui/async-await/async-closures/def-path.rs | 14 ++++++++++++++ .../async-await/async-closures/def-path.stderr | 17 +++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 tests/ui/async-await/async-closures/def-path.rs create mode 100644 tests/ui/async-await/async-closures/def-path.stderr diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index b77102c085c59..42ace9bb22fa9 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -289,12 +289,18 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> { // we must create two defs. let closure_def = self.create_def(expr.id, kw::Empty, DefKind::Closure, expr.span); match closure.coroutine_kind { - Some(coroutine_kind) => self.create_def( - coroutine_kind.closure_id(), - kw::Empty, - DefKind::Closure, - expr.span, - ), + Some(coroutine_kind) => { + self.with_parent(closure_def, |this| { + let coroutine_def = this.create_def( + coroutine_kind.closure_id(), + kw::Empty, + DefKind::Closure, + expr.span, + ); + this.with_parent(coroutine_def, |this| visit::walk_expr(this, expr)); + }); + return; + } None => closure_def, } } diff --git a/tests/ui/async-await/async-closures/def-path.rs b/tests/ui/async-await/async-closures/def-path.rs new file mode 100644 index 0000000000000..2883a1715b0ac --- /dev/null +++ b/tests/ui/async-await/async-closures/def-path.rs @@ -0,0 +1,14 @@ +// compile-flags: -Zverbose-internals +// edition:2021 + +#![feature(async_closure)] + +fn main() { + let x = async || {}; + //~^ NOTE the expected `async` closure body + let () = x(); + //~^ ERROR mismatched types + //~| NOTE this expression has type `{static main::{closure#0}::{closure#0} upvar_tys= + //~| NOTE expected `async` closure body, found `()` + //~| NOTE expected `async` closure body `{static main::{closure#0}::{closure#0} +} diff --git a/tests/ui/async-await/async-closures/def-path.stderr b/tests/ui/async-await/async-closures/def-path.stderr new file mode 100644 index 0000000000000..4b37e50aac459 --- /dev/null +++ b/tests/ui/async-await/async-closures/def-path.stderr @@ -0,0 +1,17 @@ +error[E0308]: mismatched types + --> $DIR/def-path.rs:9:9 + | +LL | let x = async || {}; + | -- the expected `async` closure body +LL | +LL | let () = x(); + | ^^ --- this expression has type `{static main::{closure#0}::{closure#0} upvar_tys=?7t witness=?8t}` + | | + | expected `async` closure body, found `()` + | + = note: expected `async` closure body `{static main::{closure#0}::{closure#0} upvar_tys=?7t witness=?8t}` + found unit type `()` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. From 76689539eec27faae941f5419983a0ebad93aad7 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sat, 20 Jan 2024 11:33:00 +0300 Subject: [PATCH 11/29] add more unit tests Signed-off-by: onur-ozkan --- src/bootstrap/src/tests/change_tracker.rs | 10 +++++ src/bootstrap/src/tests/helpers.rs | 48 ++++++++++++++++++++++- src/bootstrap/src/utils/change_tracker.rs | 4 ++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/bootstrap/src/tests/change_tracker.rs diff --git a/src/bootstrap/src/tests/change_tracker.rs b/src/bootstrap/src/tests/change_tracker.rs new file mode 100644 index 0000000000000..d2bfc07d1727b --- /dev/null +++ b/src/bootstrap/src/tests/change_tracker.rs @@ -0,0 +1,10 @@ +use crate::{find_recent_config_change_ids, CONFIG_CHANGE_HISTORY}; + +#[test] +fn test_find_recent_config_change_ids() { + // If change-id is greater than the most recent one, result should be empty. + assert!(find_recent_config_change_ids(usize::MAX).is_empty()); + + // There is no change-id equal to or less than 0, result should include the entire change history. + assert_eq!(find_recent_config_change_ids(0).len(), CONFIG_CHANGE_HISTORY.len()); +} diff --git a/src/bootstrap/src/tests/helpers.rs b/src/bootstrap/src/tests/helpers.rs index 2d626fad417d7..9cfaa3eb67b5c 100644 --- a/src/bootstrap/src/tests/helpers.rs +++ b/src/bootstrap/src/tests/helpers.rs @@ -1,5 +1,14 @@ -use crate::utils::helpers::{check_cfg_arg, extract_beta_rev, hex_encode, make}; -use std::path::PathBuf; +use crate::{ + utils::helpers::{ + check_cfg_arg, extract_beta_rev, hex_encode, make, program_out_of_date, symlink_dir, + }, + Config, +}; +use std::{ + fs::{self, remove_file, File}, + io::Write, + path::PathBuf, +}; #[test] fn test_make() { @@ -70,3 +79,38 @@ fn test_check_cfg_arg() { "--check-cfg=cfg(target_os,values(\"nixos\",\"nix2\"))" ); } + +#[test] +fn test_program_out_of_date() { + let config = Config::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]); + let tempfile = config.tempdir().join(".tmp-stamp-file"); + File::create(&tempfile).unwrap().write_all(b"dummy value").unwrap(); + assert!(tempfile.exists()); + + // up-to-date + assert!(!program_out_of_date(&tempfile, "dummy value")); + // out-of-date + assert!(program_out_of_date(&tempfile, "")); + + remove_file(tempfile).unwrap(); +} + +#[test] +fn test_symlink_dir() { + let config = Config::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]); + let tempdir = config.tempdir().join(".tmp-dir"); + let link_path = config.tempdir().join(".tmp-link"); + + fs::create_dir_all(&tempdir).unwrap(); + symlink_dir(&config, &tempdir, &link_path).unwrap(); + + let link_source = fs::read_link(&link_path).unwrap(); + assert_eq!(link_source, tempdir); + + fs::remove_dir(tempdir).unwrap(); + + #[cfg(windows)] + fs::remove_dir(link_path).unwrap(); + #[cfg(not(windows))] + fs::remove_file(link_path).unwrap(); +} diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index 327b4674acfdb..26d36ab52aba2 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -2,6 +2,10 @@ //! with the goal of keeping developers synchronized with important modifications in //! the bootstrap. +#[cfg(test)] +#[path = "../tests/change_tracker.rs"] +mod tests; + #[derive(Clone, Debug)] pub struct ChangeInfo { /// Represents the ID of PR caused major change on bootstrap. From d6a974d09643200377af60f6cfcf8cfad913721d Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sun, 21 Jan 2024 10:47:12 +0300 Subject: [PATCH 12/29] bootstrap: update test modules Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/setup.rs | 1 - .../src/{tests/setup.rs => core/build_steps/setup/tests.rs} | 0 src/bootstrap/src/core/builder.rs | 1 - .../src/{tests/builder.rs => core/builder/tests.rs} | 0 src/bootstrap/src/core/config/config.rs | 6 +----- src/bootstrap/src/core/config/mod.rs | 2 ++ src/bootstrap/src/{tests/config.rs => core/config/tests.rs} | 2 +- src/bootstrap/src/utils/change_tracker.rs | 1 - .../change_tracker.rs => utils/change_tracker/tests.rs} | 0 src/bootstrap/src/utils/helpers.rs | 1 - .../src/{tests/helpers.rs => utils/helpers/tests.rs} | 0 11 files changed, 4 insertions(+), 10 deletions(-) rename src/bootstrap/src/{tests/setup.rs => core/build_steps/setup/tests.rs} (100%) rename src/bootstrap/src/{tests/builder.rs => core/builder/tests.rs} (100%) rename src/bootstrap/src/{tests/config.rs => core/config/tests.rs} (99%) rename src/bootstrap/src/{tests/change_tracker.rs => utils/change_tracker/tests.rs} (100%) rename src/bootstrap/src/{tests/helpers.rs => utils/helpers/tests.rs} (100%) diff --git a/src/bootstrap/src/core/build_steps/setup.rs b/src/bootstrap/src/core/build_steps/setup.rs index 9c897ae1bb784..8e3c9e2be8b85 100644 --- a/src/bootstrap/src/core/build_steps/setup.rs +++ b/src/bootstrap/src/core/build_steps/setup.rs @@ -14,7 +14,6 @@ use std::str::FromStr; use std::{fmt, fs, io}; #[cfg(test)] -#[path = "../../tests/setup.rs"] mod tests; #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] diff --git a/src/bootstrap/src/tests/setup.rs b/src/bootstrap/src/core/build_steps/setup/tests.rs similarity index 100% rename from src/bootstrap/src/tests/setup.rs rename to src/bootstrap/src/core/build_steps/setup/tests.rs diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 4e20babc55a68..a6b51f6ec63cf 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -32,7 +32,6 @@ use clap::ValueEnum; use once_cell::sync::Lazy; #[cfg(test)] -#[path = "../tests/builder.rs"] mod tests; pub struct Builder<'a> { diff --git a/src/bootstrap/src/tests/builder.rs b/src/bootstrap/src/core/builder/tests.rs similarity index 100% rename from src/bootstrap/src/tests/builder.rs rename to src/bootstrap/src/core/builder/tests.rs diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index fcdd742e69c22..c0dd1e1208484 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -3,10 +3,6 @@ //! This module implements parsing `config.toml` configuration files to tweak //! how the build runs. -#[cfg(test)] -#[path = "../../tests/config.rs"] -mod tests; - use std::cell::{Cell, RefCell}; use std::cmp; use std::collections::{HashMap, HashSet}; @@ -1203,7 +1199,7 @@ impl Config { Self::parse_inner(args, get_toml) } - fn parse_inner(args: &[String], get_toml: impl Fn(&Path) -> TomlConfig) -> Config { + pub(crate) fn parse_inner(args: &[String], get_toml: impl Fn(&Path) -> TomlConfig) -> Config { let mut flags = Flags::parse(&args); let mut config = Config::default_opts(); diff --git a/src/bootstrap/src/core/config/mod.rs b/src/bootstrap/src/core/config/mod.rs index 9c6861826d605..99412848abbb7 100644 --- a/src/bootstrap/src/core/config/mod.rs +++ b/src/bootstrap/src/core/config/mod.rs @@ -1,4 +1,6 @@ pub(crate) mod config; pub(crate) mod flags; +#[cfg(test)] +mod tests; pub use config::*; diff --git a/src/bootstrap/src/tests/config.rs b/src/bootstrap/src/core/config/tests.rs similarity index 99% rename from src/bootstrap/src/tests/config.rs rename to src/bootstrap/src/core/config/tests.rs index c65067f8e8f76..201d11571c48a 100644 --- a/src/bootstrap/src/tests/config.rs +++ b/src/bootstrap/src/core/config/tests.rs @@ -1,4 +1,4 @@ -use super::{Config, Flags}; +use super::{flags::Flags, Config}; use crate::core::config::{LldMode, TomlConfig}; use clap::CommandFactory; diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index 26d36ab52aba2..0d5e2600b73a9 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -3,7 +3,6 @@ //! the bootstrap. #[cfg(test)] -#[path = "../tests/change_tracker.rs"] mod tests; #[derive(Clone, Debug)] diff --git a/src/bootstrap/src/tests/change_tracker.rs b/src/bootstrap/src/utils/change_tracker/tests.rs similarity index 100% rename from src/bootstrap/src/tests/change_tracker.rs rename to src/bootstrap/src/utils/change_tracker/tests.rs diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index 0c917c3d57933..d1f713af91709 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -21,7 +21,6 @@ use crate::LldMode; pub use crate::utils::dylib::{dylib_path, dylib_path_var}; #[cfg(test)] -#[path = "../tests/helpers.rs"] mod tests; /// A helper macro to `unwrap` a result except also print out details like: diff --git a/src/bootstrap/src/tests/helpers.rs b/src/bootstrap/src/utils/helpers/tests.rs similarity index 100% rename from src/bootstrap/src/tests/helpers.rs rename to src/bootstrap/src/utils/helpers/tests.rs From b85b2a783b813def53b2a7f0c9b53fed119e2338 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 28 Jan 2024 11:24:27 -0800 Subject: [PATCH 13/29] std: Update documentation of seek_write on Windows Currently the documentation of `FileExt::seek_write` on Windows indicates that writes beyond the end of the file leave intermediate bytes uninitialized. This commentary dates back to the original inclusion of these functions in #35704 (wow blast from the past!). At the time the functionality here was implemented using `WriteFile`, but nowadays the `NtWriteFile` method is used instead. The documentation for `NtWriteFile` explicitly states: > If Length and ByteOffset specify a write operation past the current > end-of-file mark, NtWriteFile automatically extends the file and updates > the end-of-file mark; any bytes that are not explicitly written between > such old and new end-of-file marks are defined to be zero. This commentary has had a downstream impact in the `system-interface` crate where it tries to handle this by explicitly writing zeros, but I don't believe that's necessary any more. I'm sending a PR upstream here to avoid future confusion and codify that zeros are written in the intermediate bytes matching what Windows currently provides. --- library/std/src/os/windows/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/os/windows/fs.rs b/library/std/src/os/windows/fs.rs index 1b013d1c154c9..e9d7a13e9d5b2 100644 --- a/library/std/src/os/windows/fs.rs +++ b/library/std/src/os/windows/fs.rs @@ -59,7 +59,7 @@ pub trait FileExt { /// function, it is set to the end of the write. /// /// When writing beyond the end of the file, the file is appropriately - /// extended and the intermediate bytes are left uninitialized. + /// extended and the intermediate bytes are set to zero. /// /// Note that similar to `File::write`, it is not an error to return a /// short write. When returning from such a short write, the file pointer From 5bda589ff333dc324963bc653ce9e13bb176e6a5 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 29 Jan 2024 09:28:10 +1100 Subject: [PATCH 14/29] Tweak comment and naming for `recover_unclosed_char`. Because it can be used for a lifetime or a label. --- compiler/rustc_parse/src/parser/expr.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index b789b65797bad..ad26a930829e1 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1737,16 +1737,16 @@ impl<'a> Parser<'a> { Ok(expr) } - /// Emit an error when a char is parsed as a lifetime because of a missing quote. + /// Emit an error when a char is parsed as a lifetime or label because of a missing quote. pub(super) fn recover_unclosed_char( &self, - lifetime: Ident, + ident: Ident, mk_lit_char: impl FnOnce(Symbol, Span) -> L, err: impl FnOnce(&Self) -> DiagnosticBuilder<'a>, ) -> L { - if let Some(diag) = self.dcx().steal_diagnostic(lifetime.span, StashKey::LifetimeIsChar) { + if let Some(diag) = self.dcx().steal_diagnostic(ident.span, StashKey::LifetimeIsChar) { diag.with_span_suggestion_verbose( - lifetime.span.shrink_to_hi(), + ident.span.shrink_to_hi(), "add `'` to close the char literal", "'", Applicability::MaybeIncorrect, @@ -1755,15 +1755,15 @@ impl<'a> Parser<'a> { } else { err(self) .with_span_suggestion_verbose( - lifetime.span.shrink_to_hi(), + ident.span.shrink_to_hi(), "add `'` to close the char literal", "'", Applicability::MaybeIncorrect, ) .emit(); } - let name = lifetime.without_first_quote().name; - mk_lit_char(name, lifetime.span) + let name = ident.without_first_quote().name; + mk_lit_char(name, ident.span) } /// Recover on the syntax `do catch { ... }` suggesting `try { ... }` instead. From 306612ea60850249e0ad9e7a14fb1ce75fcd944e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 29 Jan 2024 09:47:02 +1100 Subject: [PATCH 15/29] Be more careful about interpreting a label/lifetime as a mistyped char literal. Currently the parser will interpret any label/lifetime in certain positions as a mistyped char literal, on the assumption that the trailing single quote was accidentally omitted. This is reasonable for a something like 'a (because 'a' would be valid) but not reasonable for a something like 'abc (because 'abc' is not valid). This commit restricts this behaviour only to labels/lifetimes that would be valid char literals, via the new `could_be_unclosed_char_literal` function. The commit also augments the `label-is-actually-char.rs` test in a couple of ways: - Adds testing of labels/lifetimes with identifiers longer than one char, e.g. 'abc. - Adds a new match with simpler patterns, because the `recover_unclosed_char` call in `parse_pat_with_range_pat` was not being exercised (in this test or any other ui tests). Fixes #120397, an assertion failure, which was caused by this behaviour in the parser interacting with some new stricter char literal checking added in #120329. --- compiler/rustc_parse/src/parser/expr.rs | 17 ++++- compiler/rustc_parse/src/parser/pat.rs | 4 +- tests/ui/parser/label-is-actually-char.rs | 41 +++++++++-- tests/ui/parser/label-is-actually-char.stderr | 73 +++++++++++++++---- 4 files changed, 112 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index ad26a930829e1..583f6f2ae5f4b 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -28,6 +28,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::{ AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, PResult, StashKey, }; +use rustc_lexer::unescape::unescape_char; use rustc_macros::Subdiagnostic; use rustc_session::errors::{report_lit_error, ExprParenthesesNeeded}; use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP; @@ -1652,6 +1653,7 @@ impl<'a> Parser<'a> { && self.may_recover() && (matches!(self.token.kind, token::CloseDelim(_) | token::Comma) || self.token.is_punct()) + && could_be_unclosed_char_literal(label_.ident) { let (lit, _) = self.recover_unclosed_char(label_.ident, Parser::mk_token_lit_char, |self_| { @@ -1744,6 +1746,7 @@ impl<'a> Parser<'a> { mk_lit_char: impl FnOnce(Symbol, Span) -> L, err: impl FnOnce(&Self) -> DiagnosticBuilder<'a>, ) -> L { + assert!(could_be_unclosed_char_literal(ident)); if let Some(diag) = self.dcx().steal_diagnostic(ident.span, StashKey::LifetimeIsChar) { diag.with_span_suggestion_verbose( ident.span.shrink_to_hi(), @@ -2034,8 +2037,11 @@ impl<'a> Parser<'a> { let msg = format!("unexpected token: {}", super::token_descr(&token)); self_.dcx().struct_span_err(token.span, msg) }; - // On an error path, eagerly consider a lifetime to be an unclosed character lit - if self.token.is_lifetime() { + // On an error path, eagerly consider a lifetime to be an unclosed character lit, if that + // makes sense. + if let Some(ident) = self.token.lifetime() + && could_be_unclosed_char_literal(ident) + { let lt = self.expect_lifetime(); Ok(self.recover_unclosed_char(lt.ident, mk_lit_char, err)) } else { @@ -3763,6 +3769,13 @@ impl<'a> Parser<'a> { } } +/// Could this lifetime/label be an unclosed char literal? For example, `'a` +/// could be, but `'abc` could not. +pub(crate) fn could_be_unclosed_char_literal(ident: Ident) -> bool { + ident.name.as_str().starts_with('\'') + && unescape_char(ident.without_first_quote().name.as_str()).is_ok() +} + /// Used to forbid `let` expressions in certain syntactic locations. #[derive(Clone, Copy, Subdiagnostic)] pub(crate) enum ForbiddenLetReason { diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 7918e03750ce3..55144c6165012 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -10,6 +10,7 @@ use crate::errors::{ UnexpectedParenInRangePatSugg, UnexpectedVertVertBeforeFunctionParam, UnexpectedVertVertInPattern, }; +use crate::parser::expr::could_be_unclosed_char_literal; use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole}; use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor}; use rustc_ast::ptr::P; @@ -443,11 +444,12 @@ impl<'a> Parser<'a> { } else { PatKind::Path(qself, path) } - } else if matches!(self.token.kind, token::Lifetime(_)) + } else if let token::Lifetime(lt) = self.token.kind // In pattern position, we're totally fine with using "next token isn't colon" // as a heuristic. We could probably just always try to recover if it's a lifetime, // because we never have `'a: label {}` in a pattern position anyways, but it does // keep us from suggesting something like `let 'a: Ty = ..` => `let 'a': Ty = ..` + && could_be_unclosed_char_literal(Ident::with_dummy_span(lt)) && !self.look_ahead(1, |token| matches!(token.kind, token::Colon)) { // Recover a `'a` as a `'a'` literal diff --git a/tests/ui/parser/label-is-actually-char.rs b/tests/ui/parser/label-is-actually-char.rs index 183da603da434..74df898d1910a 100644 --- a/tests/ui/parser/label-is-actually-char.rs +++ b/tests/ui/parser/label-is-actually-char.rs @@ -1,16 +1,43 @@ +// Note: it's ok to interpret 'a as 'a', but but not ok to interpret 'abc as +// 'abc' because 'abc' is not a valid char literal. + fn main() { let c = 'a; //~^ ERROR expected `while`, `for`, `loop` or `{` after a label //~| HELP add `'` to close the char literal - match c { + + let c = 'abc; + //~^ ERROR expected `while`, `for`, `loop` or `{` after a label + //~| ERROR expected expression, found `;` +} + +fn f() { + match 'a' { 'a'..='b => {} //~^ ERROR unexpected token: `'b` //~| HELP add `'` to close the char literal - _ => {} + 'c'..='def => {} + //~^ ERROR unexpected token: `'def` } - let x = ['a, 'b]; - //~^ ERROR expected `while`, `for`, `loop` or `{` after a label - //~| ERROR expected `while`, `for`, `loop` or `{` after a label - //~| HELP add `'` to close the char literal - //~| HELP add `'` to close the char literal +} + +fn g() { + match 'g' { + 'g => {} + //~^ ERROR expected pattern, found `=>` + //~| HELP add `'` to close the char literal + 'hij => {} + //~^ ERROR expected pattern, found `'hij` + _ => {} + } +} + +fn h() { + let x = ['a, 'b, 'cde]; + //~^ ERROR expected `while`, `for`, `loop` or `{` after a label + //~| HELP add `'` to close the char literal + //~| ERROR expected `while`, `for`, `loop` or `{` after a label + //~| HELP add `'` to close the char literal + //~| ERROR expected `while`, `for`, `loop` or `{` after a label + //~| ERROR expected expression, found `]` } diff --git a/tests/ui/parser/label-is-actually-char.stderr b/tests/ui/parser/label-is-actually-char.stderr index 28c8d2ada3adb..10a7e1803b532 100644 --- a/tests/ui/parser/label-is-actually-char.stderr +++ b/tests/ui/parser/label-is-actually-char.stderr @@ -1,5 +1,5 @@ error: expected `while`, `for`, `loop` or `{` after a label - --> $DIR/label-is-actually-char.rs:2:15 + --> $DIR/label-is-actually-char.rs:5:15 | LL | let c = 'a; | ^ expected `while`, `for`, `loop` or `{` after a label @@ -9,8 +9,20 @@ help: add `'` to close the char literal LL | let c = 'a'; | + +error: expected `while`, `for`, `loop` or `{` after a label + --> $DIR/label-is-actually-char.rs:9:17 + | +LL | let c = 'abc; + | ^ expected `while`, `for`, `loop` or `{` after a label + +error: expected expression, found `;` + --> $DIR/label-is-actually-char.rs:9:17 + | +LL | let c = 'abc; + | ^ expected expression + error: unexpected token: `'b` - --> $DIR/label-is-actually-char.rs:6:15 + --> $DIR/label-is-actually-char.rs:16:15 | LL | 'a'..='b => {} | ^^ @@ -20,27 +32,62 @@ help: add `'` to close the char literal LL | 'a'..='b' => {} | + +error: unexpected token: `'def` + --> $DIR/label-is-actually-char.rs:19:15 + | +LL | 'c'..='def => {} + | ^^^^ + +error: expected pattern, found `=>` + --> $DIR/label-is-actually-char.rs:26:11 + | +LL | 'g => {} + | ^^ expected pattern + | +help: add `'` to close the char literal + | +LL | 'g' => {} + | + + +error: expected pattern, found `'hij` + --> $DIR/label-is-actually-char.rs:29:8 + | +LL | 'hij => {} + | ^^^^ expected pattern + error: expected `while`, `for`, `loop` or `{` after a label - --> $DIR/label-is-actually-char.rs:11:16 + --> $DIR/label-is-actually-char.rs:36:15 | -LL | let x = ['a, 'b]; - | ^ expected `while`, `for`, `loop` or `{` after a label +LL | let x = ['a, 'b, 'cde]; + | ^ expected `while`, `for`, `loop` or `{` after a label | help: add `'` to close the char literal | -LL | let x = ['a', 'b]; - | + +LL | let x = ['a', 'b, 'cde]; + | + error: expected `while`, `for`, `loop` or `{` after a label - --> $DIR/label-is-actually-char.rs:11:20 + --> $DIR/label-is-actually-char.rs:36:19 | -LL | let x = ['a, 'b]; - | ^ expected `while`, `for`, `loop` or `{` after a label +LL | let x = ['a, 'b, 'cde]; + | ^ expected `while`, `for`, `loop` or `{` after a label | help: add `'` to close the char literal | -LL | let x = ['a, 'b']; - | + +LL | let x = ['a, 'b', 'cde]; + | + + +error: expected `while`, `for`, `loop` or `{` after a label + --> $DIR/label-is-actually-char.rs:36:25 + | +LL | let x = ['a, 'b, 'cde]; + | ^ expected `while`, `for`, `loop` or `{` after a label + +error: expected expression, found `]` + --> $DIR/label-is-actually-char.rs:36:25 + | +LL | let x = ['a, 'b, 'cde]; + | ^ expected expression -error: aborting due to 4 previous errors +error: aborting due to 11 previous errors From 3cde0e8fb603f696e895fb4cb817fcd44df827f8 Mon Sep 17 00:00:00 2001 From: Marek 'seqre' Grzelak Date: Fri, 26 Jan 2024 18:41:45 -0600 Subject: [PATCH 16/29] Add instructions of how to use pre-vendored 'rustc-src' --- src/bootstrap/bootstrap.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 83fdcddecf27a..0d604c0d3e5e0 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -1034,7 +1034,16 @@ def check_vendored_status(self): eprint('ERROR: vendoring required, but vendor directory does not exist.') eprint(' Run `cargo vendor {}` to initialize the ' 'vendor directory.'.format(sync_dirs)) - eprint('Alternatively, use the pre-vendored `rustc-src` dist component.') + eprint(' Alternatively, use the pre-vendored `rustc-src` dist component.') + eprint(' To get a stable/beta/nightly version, download it from: ') + eprint(' ' + 'https://forge.rust-lang.org/infra/other-installation-methods.html#source-code') + eprint(' To get a specific commit version, download it using the below URL,') + eprint(' replacing with a specific commit checksum: ') + eprint(' ' + 'https://ci-artifacts.rust-lang.org/rustc-builds//rustc-nightly-src.tar.xz') + eprint(' Once you have the source downloaded, place the vendor directory') + eprint(' from the archive in the root of the rust project.') raise Exception("{} not found".format(vendor_dir)) if not os.path.exists(cargo_dir): From b4e1c569fe1d332fae69a1c04139116adfbf1a7c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 27 Jan 2024 14:08:29 +0100 Subject: [PATCH 17/29] raw pointer metadata API: data address -> data pointer --- library/core/src/ptr/const_ptr.rs | 2 +- library/core/src/ptr/metadata.rs | 16 ++++++++-------- library/core/src/ptr/mut_ptr.rs | 2 +- library/core/src/ptr/non_null.rs | 8 ++++---- ...ed_mut_range.PreCodegen.after.panic-abort.mir | 4 ++-- ...d_mut_range.PreCodegen.after.panic-unwind.mir | 4 ++-- tests/ui/union/issue-81199.rs | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 5ce9ddeb676a6..f3ceadee24c2f 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -285,7 +285,7 @@ impl *const T { self.with_addr(f(self.addr())) } - /// Decompose a (possibly wide) pointer into its address and metadata components. + /// Decompose a (possibly wide) pointer into its data pointer and metadata components. /// /// The pointer can be later reconstructed with [`from_raw_parts`]. #[unstable(feature = "ptr_metadata", issue = "81513")] diff --git a/library/core/src/ptr/metadata.rs b/library/core/src/ptr/metadata.rs index 040aa06978748..a6a390db043b6 100644 --- a/library/core/src/ptr/metadata.rs +++ b/library/core/src/ptr/metadata.rs @@ -39,13 +39,13 @@ use crate::hash::{Hash, Hasher}; /// /// # Usage /// -/// Raw pointers can be decomposed into the data address and metadata components +/// Raw pointers can be decomposed into the data pointer and metadata components /// with their [`to_raw_parts`] method. /// /// Alternatively, metadata alone can be extracted with the [`metadata`] function. /// A reference can be passed to [`metadata`] and implicitly coerced. /// -/// A (possibly-wide) pointer can be put back together from its address and metadata +/// A (possibly-wide) pointer can be put back together from its data pointer and metadata /// with [`from_raw_parts`] or [`from_raw_parts_mut`]. /// /// [`to_raw_parts`]: *const::to_raw_parts @@ -98,7 +98,7 @@ pub const fn metadata(ptr: *const T) -> ::Metadata { unsafe { PtrRepr { const_ptr: ptr }.components.metadata } } -/// Forms a (possibly-wide) raw pointer from a data address and metadata. +/// Forms a (possibly-wide) raw pointer from a data pointer and metadata. /// /// This function is safe but the returned pointer is not necessarily safe to dereference. /// For slices, see the documentation of [`slice::from_raw_parts`] for safety requirements. @@ -109,13 +109,13 @@ pub const fn metadata(ptr: *const T) -> ::Metadata { #[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")] #[inline] pub const fn from_raw_parts( - data_address: *const (), + data_pointer: *const (), metadata: ::Metadata, ) -> *const T { // SAFETY: Accessing the value from the `PtrRepr` union is safe since *const T // and PtrComponents have the same memory layouts. Only std can make this // guarantee. - unsafe { PtrRepr { components: PtrComponents { data_address, metadata } }.const_ptr } + unsafe { PtrRepr { components: PtrComponents { data_pointer, metadata } }.const_ptr } } /// Performs the same functionality as [`from_raw_parts`], except that a @@ -126,13 +126,13 @@ pub const fn from_raw_parts( #[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")] #[inline] pub const fn from_raw_parts_mut( - data_address: *mut (), + data_pointer: *mut (), metadata: ::Metadata, ) -> *mut T { // SAFETY: Accessing the value from the `PtrRepr` union is safe since *const T // and PtrComponents have the same memory layouts. Only std can make this // guarantee. - unsafe { PtrRepr { components: PtrComponents { data_address, metadata } }.mut_ptr } + unsafe { PtrRepr { components: PtrComponents { data_pointer, metadata } }.mut_ptr } } #[repr(C)] @@ -144,7 +144,7 @@ union PtrRepr { #[repr(C)] struct PtrComponents { - data_address: *const (), + data_pointer: *const (), metadata: ::Metadata, } diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 3e5678a7d9172..3e47c4f440a44 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -292,7 +292,7 @@ impl *mut T { self.with_addr(f(self.addr())) } - /// Decompose a (possibly wide) pointer into its address and metadata components. + /// Decompose a (possibly wide) pointer into its data pointer and metadata components. /// /// The pointer can be later reconstructed with [`from_raw_parts_mut`]. #[unstable(feature = "ptr_metadata", issue = "81513")] diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 427a9f3f49456..d18082c3048f1 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -259,16 +259,16 @@ impl NonNull { #[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")] #[inline] pub const fn from_raw_parts( - data_address: NonNull<()>, + data_pointer: NonNull<()>, metadata: ::Metadata, ) -> NonNull { - // SAFETY: The result of `ptr::from::raw_parts_mut` is non-null because `data_address` is. + // SAFETY: The result of `ptr::from::raw_parts_mut` is non-null because `data_pointer` is. unsafe { - NonNull::new_unchecked(super::from_raw_parts_mut(data_address.as_ptr(), metadata)) + NonNull::new_unchecked(super::from_raw_parts_mut(data_pointer.as_ptr(), metadata)) } } - /// Decompose a (possibly wide) pointer into its address and metadata components. + /// Decompose a (possibly wide) pointer into its data pointer and metadata components. /// /// The pointer can be later reconstructed with [`NonNull::from_raw_parts`]. #[unstable(feature = "ptr_metadata", issue = "81513")] diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir index 36329f8fc6845..dc37c1b4cbf9f 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir @@ -42,7 +42,7 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> debug self => _8; } scope 15 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { - debug data_address => _9; + debug data_pointer => _9; debug metadata => _6; let mut _10: *const (); let mut _11: std::ptr::metadata::PtrComponents<[u32]>; @@ -90,7 +90,7 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageLive(_11); StorageLive(_10); _10 = _9 as *const () (PointerCoercion(MutToConstPointer)); - _11 = std::ptr::metadata::PtrComponents::<[u32]> { data_address: move _10, metadata: _6 }; + _11 = std::ptr::metadata::PtrComponents::<[u32]> { data_pointer: move _10, metadata: _6 }; StorageDead(_10); _12 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _11 }; StorageDead(_11); diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir index 36329f8fc6845..dc37c1b4cbf9f 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir @@ -42,7 +42,7 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> debug self => _8; } scope 15 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { - debug data_address => _9; + debug data_pointer => _9; debug metadata => _6; let mut _10: *const (); let mut _11: std::ptr::metadata::PtrComponents<[u32]>; @@ -90,7 +90,7 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageLive(_11); StorageLive(_10); _10 = _9 as *const () (PointerCoercion(MutToConstPointer)); - _11 = std::ptr::metadata::PtrComponents::<[u32]> { data_address: move _10, metadata: _6 }; + _11 = std::ptr::metadata::PtrComponents::<[u32]> { data_pointer: move _10, metadata: _6 }; StorageDead(_10); _12 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _11 }; StorageDead(_11); diff --git a/tests/ui/union/issue-81199.rs b/tests/ui/union/issue-81199.rs index b8b0d9d33e791..2083ee15d87bd 100644 --- a/tests/ui/union/issue-81199.rs +++ b/tests/ui/union/issue-81199.rs @@ -9,7 +9,7 @@ union PtrRepr { #[repr(C)] struct PtrComponents { - data_address: *const (), + data_pointer: *const (), metadata: ::Metadata, } From 1b17d8e1a03315dc9196c69fcfbcc2af165b175f Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Mon, 29 Jan 2024 10:02:59 +0000 Subject: [PATCH 18/29] Add matthewjasper to some review groups --- triagebot.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/triagebot.toml b/triagebot.toml index e57dd158374f8..34b795f49fb17 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -717,6 +717,7 @@ arena = [ mir = [ "@davidtwco", "@oli-obk", + "@matthewjasper" ] mir-opt = [ "@oli-obk", @@ -733,6 +734,7 @@ types = [ borrowck = [ "@davidtwco", "@pnkfelix", + "@matthewjasper" ] ast_lowering = [ "@compiler-errors", @@ -776,6 +778,7 @@ project-stable-mir = [ "/compiler/rustc_data_structures/src/stable_hasher.rs" = ["compiler", "incremental"] "/compiler/rustc_hir_analysis" = ["compiler", "types"] "/compiler/rustc_incremental" = ["compiler", "incremental"] +"/compiler/rustc_borrowck" = ["compiler", "borrowck"] "/compiler/rustc_lexer" = ["compiler", "lexer"] "/compiler/rustc_llvm" = ["@cuviper"] "/compiler/rustc_codegen_llvm/src/debuginfo" = ["compiler", "debuginfo"] @@ -785,6 +788,7 @@ project-stable-mir = [ "/compiler/rustc_const_eval/src/interpret" = ["compiler", "mir"] "/compiler/rustc_const_eval/src/transform" = ["compiler", "mir-opt"] "/compiler/rustc_mir_build/src/build" = ["compiler", "mir"] +"/compiler/rustc_mir_transform" = ["compiler", "mir", "mir-opt"] "/compiler/rustc_smir" = ["project-stable-mir"] "/compiler/rustc_parse" = ["compiler", "parser"] "/compiler/rustc_parse/src/lexer" = ["compiler", "lexer"] From 1bdeeef0d59f5539d045b65865f8b0ec7d76eed0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 28 Jan 2024 11:42:32 +0100 Subject: [PATCH 19/29] Update pulldown-cmark version to 0.9.5 --- Cargo.lock | 6 +++--- compiler/rustc_resolve/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09eb0d98efc90..3af93251fddd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3005,11 +3005,11 @@ dependencies = [ [[package]] name = "pulldown-cmark" -version = "0.9.3" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998" +checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "memchr", "unicase", ] diff --git a/compiler/rustc_resolve/Cargo.toml b/compiler/rustc_resolve/Cargo.toml index a1a353ce0574e..b6ae54010c242 100644 --- a/compiler/rustc_resolve/Cargo.toml +++ b/compiler/rustc_resolve/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start bitflags = "2.4.1" -pulldown-cmark = { version = "0.9.3", default-features = false } +pulldown-cmark = { version = "0.9.6", default-features = false } rustc_arena = { path = "../rustc_arena" } rustc_ast = { path = "../rustc_ast" } rustc_ast_pretty = { path = "../rustc_ast_pretty" } From 1e60cc9bd9b35c1aa63e941fad0c0326db82e366 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 28 Jan 2024 11:42:50 +0100 Subject: [PATCH 20/29] Add regression test for #100638 --- ...otnote-definition-without-blank-line-100638.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/rustdoc/footnote-definition-without-blank-line-100638.rs diff --git a/tests/rustdoc/footnote-definition-without-blank-line-100638.rs b/tests/rustdoc/footnote-definition-without-blank-line-100638.rs new file mode 100644 index 0000000000000..b6f62c3bcba57 --- /dev/null +++ b/tests/rustdoc/footnote-definition-without-blank-line-100638.rs @@ -0,0 +1,15 @@ +#![crate_name = "foo"] + +//! Reference to footnotes A[^1], B[^2] and C[^3]. +//! +//! [^1]: Footnote A. +//! [^2]: Footnote B. +//! [^3]: Footnote C. + +// @has 'foo/index.html' +// @has - '//*[@class="docblock"]/*[@class="footnotes"]/ol/li[@id="fn1"]/p' 'Footnote A' +// @has - '//li[@id="fn1"]/p/a/@href' '#fnref1' +// @has - '//*[@class="docblock"]/*[@class="footnotes"]/ol/li[@id="fn2"]/p' 'Footnote B' +// @has - '//li[@id="fn2"]/p/a/@href' '#fnref2' +// @has - '//*[@class="docblock"]/*[@class="footnotes"]/ol/li[@id="fn3"]/p' 'Footnote C' +// @has - '//li[@id="fn3"]/p/a/@href' '#fnref3' From 503342f51c26b8c5efcf3f3c97818c232d988c41 Mon Sep 17 00:00:00 2001 From: rustbot <47979223+rustbot@users.noreply.github.com> Date: Mon, 29 Jan 2024 12:00:29 -0500 Subject: [PATCH 21/29] Update books --- src/doc/edition-guide | 2 +- src/doc/embedded-book | 2 +- src/doc/reference | 2 +- src/doc/rust-by-example | 2 +- src/doc/rustc-dev-guide | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/doc/edition-guide b/src/doc/edition-guide index bbffb074e16be..baafacc6d8701 160000 --- a/src/doc/edition-guide +++ b/src/doc/edition-guide @@ -1 +1 @@ -Subproject commit bbffb074e16bef89772818b400b6c76a65eac126 +Subproject commit baafacc6d8701269dab1e1e333f3547fb54b5a59 diff --git a/src/doc/embedded-book b/src/doc/embedded-book index 3f9df2b9885c6..2e95fc2fd31d6 160000 --- a/src/doc/embedded-book +++ b/src/doc/embedded-book @@ -1 +1 @@ -Subproject commit 3f9df2b9885c6741365da2e12ed6662cd0e827d6 +Subproject commit 2e95fc2fd31d669947e993aa07ef10dc9828bee7 diff --git a/src/doc/reference b/src/doc/reference index 8c77e8be9da1a..a0b119535e774 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 8c77e8be9da1a9c70545556218d563c8d061f1fd +Subproject commit a0b119535e7740f68494c4f0582f7ad008b00ccd diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index ddf5cb0e6ee54..179256a445d61 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit ddf5cb0e6ee54ba2dd84c8ca3e1314120014e20d +Subproject commit 179256a445d6144f5f371fdefb993f48f33978b0 diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide index 4af29d1a7f64f..ec287e3327776 160000 --- a/src/doc/rustc-dev-guide +++ b/src/doc/rustc-dev-guide @@ -1 +1 @@ -Subproject commit 4af29d1a7f64f88a36539662c6a84fe1fbe6cde1 +Subproject commit ec287e332777627185be4798ad22599ffe7b84aa From 32a0afe30c26044a62d098910464989258f0bc2e Mon Sep 17 00:00:00 2001 From: Chad Norvell Date: Mon, 22 Jan 2024 20:42:27 +0000 Subject: [PATCH 22/29] rustdoc: Prevent JS injection from localStorage --- src/librustdoc/html/static/js/storage.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/js/storage.js b/src/librustdoc/html/static/js/storage.js index ac9c6f377b82a..bda7b3c647e7e 100644 --- a/src/librustdoc/html/static/js/storage.js +++ b/src/librustdoc/html/static/js/storage.js @@ -101,6 +101,14 @@ const getVar = (function getVar(name) { }); function switchTheme(newThemeName, saveTheme) { + const themeNames = getVar("themes").split(",").filter(t => t); + themeNames.push(...builtinThemes); + + // Ensure that the new theme name is among the defined themes + if (themeNames.indexOf(newThemeName) === -1) { + return; + } + // If this new value comes from a system setting or from the previously // saved theme, no need to save it. if (saveTheme) { @@ -115,7 +123,7 @@ function switchTheme(newThemeName, saveTheme) { window.currentTheme = null; } } else { - const newHref = getVar("root-path") + newThemeName + + const newHref = getVar("root-path") + encodeURIComponent(newThemeName) + getVar("resource-suffix") + ".css"; if (!window.currentTheme) { // If we're in the middle of loading, document.write blocks From ed5562987969ab063367418d6847ac4a224b51e7 Mon Sep 17 00:00:00 2001 From: Marek 'seqre' Grzelak Date: Sat, 27 Jan 2024 22:59:40 -0600 Subject: [PATCH 23/29] Move multiple UI issue tests to subdirectories Issue tests numbered 1920, 3668, 5997, 23302, 32122, 40510, 57741, 71676, and 76077 were moved to relevant better-named subdirectories. ISSUES_ENTRY_LIMIT was adjusted to match new number of files and FIXME note was expanded. --- src/tools/tidy/src/ui_tests.rs | 7 +++++-- .../auxiliary/issue-1920.rs | 0 .../issues/{ => issue-1920-absolute-paths}/issue-1920-1.rs | 0 .../{ => issue-1920-absolute-paths}/issue-1920-1.stderr | 0 .../issues/{ => issue-1920-absolute-paths}/issue-1920-2.rs | 0 .../{ => issue-1920-absolute-paths}/issue-1920-2.stderr | 0 .../issues/{ => issue-1920-absolute-paths}/issue-1920-3.rs | 0 .../{ => issue-1920-absolute-paths}/issue-1920-3.stderr | 0 .../issue-23302-1.rs | 0 .../issue-23302-1.stderr | 0 .../issue-23302-2.rs | 0 .../issue-23302-2.stderr | 0 .../issue-23302-3.rs | 0 .../issue-23302-3.stderr | 0 .../issue-32122-1.fixed | 0 .../issue-32122-1.rs | 0 .../issue-32122-1.stderr | 0 .../issue-32122-2.fixed | 0 .../issue-32122-2.rs | 0 .../issue-32122-2.stderr | 0 .../issue-3668-2.fixed | 0 .../issue-3668-2.rs | 0 .../issue-3668-2.stderr | 0 .../issue-3668.rs | 0 .../issue-3668.stderr | 0 .../issue-40510-1.migrate.stderr | 0 .../issue-40510-1.rs | 0 .../issue-40510-1.stderr | 0 .../issue-40510-2.rs | 0 .../issue-40510-3.migrate.stderr | 0 .../issue-40510-3.rs | 0 .../issue-40510-3.stderr | 0 .../issue-40510-4.rs | 0 .../issue-57741-1.rs | 0 .../issue-57741-1.stderr | 0 .../issue-57741.fixed | 0 .../issue-57741.rs | 0 .../issue-57741.stderr | 0 .../issue-5997-enum.rs | 0 .../issue-5997-enum.stderr | 0 .../issue-5997-struct.rs | 0 .../issue-5997-struct.stderr | 0 .../{ => issue-5997-outer-generic-parameter}/issue-5997.rs | 0 .../{ => issue-71676-suggest-deref}/issue-71676-1.fixed | 0 .../{ => issue-71676-suggest-deref}/issue-71676-1.rs | 0 .../{ => issue-71676-suggest-deref}/issue-71676-1.stderr | 0 .../{ => issue-71676-suggest-deref}/issue-71676-2.rs | 0 .../{ => issue-71676-suggest-deref}/issue-71676-2.stderr | 0 .../issue-76077-1.fixed | 0 .../issue-76077-1.rs | 0 .../issue-76077-1.stderr | 0 .../issue-76077.rs | 0 .../issue-76077.stderr | 0 53 files changed, 5 insertions(+), 2 deletions(-) rename tests/ui/issues/{ => issue-1920-absolute-paths}/auxiliary/issue-1920.rs (100%) rename tests/ui/issues/{ => issue-1920-absolute-paths}/issue-1920-1.rs (100%) rename tests/ui/issues/{ => issue-1920-absolute-paths}/issue-1920-1.stderr (100%) rename tests/ui/issues/{ => issue-1920-absolute-paths}/issue-1920-2.rs (100%) rename tests/ui/issues/{ => issue-1920-absolute-paths}/issue-1920-2.stderr (100%) rename tests/ui/issues/{ => issue-1920-absolute-paths}/issue-1920-3.rs (100%) rename tests/ui/issues/{ => issue-1920-absolute-paths}/issue-1920-3.stderr (100%) rename tests/ui/issues/{ => issue-23302-enum-infinite-recursion}/issue-23302-1.rs (100%) rename tests/ui/issues/{ => issue-23302-enum-infinite-recursion}/issue-23302-1.stderr (100%) rename tests/ui/issues/{ => issue-23302-enum-infinite-recursion}/issue-23302-2.rs (100%) rename tests/ui/issues/{ => issue-23302-enum-infinite-recursion}/issue-23302-2.stderr (100%) rename tests/ui/issues/{ => issue-23302-enum-infinite-recursion}/issue-23302-3.rs (100%) rename tests/ui/issues/{ => issue-23302-enum-infinite-recursion}/issue-23302-3.stderr (100%) rename tests/ui/issues/{ => issue-32122-deref-coercions-composition}/issue-32122-1.fixed (100%) rename tests/ui/issues/{ => issue-32122-deref-coercions-composition}/issue-32122-1.rs (100%) rename tests/ui/issues/{ => issue-32122-deref-coercions-composition}/issue-32122-1.stderr (100%) rename tests/ui/issues/{ => issue-32122-deref-coercions-composition}/issue-32122-2.fixed (100%) rename tests/ui/issues/{ => issue-32122-deref-coercions-composition}/issue-32122-2.rs (100%) rename tests/ui/issues/{ => issue-32122-deref-coercions-composition}/issue-32122-2.stderr (100%) rename tests/ui/issues/{ => issue-3668-non-constant-value-in-constant}/issue-3668-2.fixed (100%) rename tests/ui/issues/{ => issue-3668-non-constant-value-in-constant}/issue-3668-2.rs (100%) rename tests/ui/issues/{ => issue-3668-non-constant-value-in-constant}/issue-3668-2.stderr (100%) rename tests/ui/issues/{ => issue-3668-non-constant-value-in-constant}/issue-3668.rs (100%) rename tests/ui/issues/{ => issue-3668-non-constant-value-in-constant}/issue-3668.stderr (100%) rename tests/ui/issues/{ => issue-40510-captured-variable-return}/issue-40510-1.migrate.stderr (100%) rename tests/ui/issues/{ => issue-40510-captured-variable-return}/issue-40510-1.rs (100%) rename tests/ui/issues/{ => issue-40510-captured-variable-return}/issue-40510-1.stderr (100%) rename tests/ui/issues/{ => issue-40510-captured-variable-return}/issue-40510-2.rs (100%) rename tests/ui/issues/{ => issue-40510-captured-variable-return}/issue-40510-3.migrate.stderr (100%) rename tests/ui/issues/{ => issue-40510-captured-variable-return}/issue-40510-3.rs (100%) rename tests/ui/issues/{ => issue-40510-captured-variable-return}/issue-40510-3.stderr (100%) rename tests/ui/issues/{ => issue-40510-captured-variable-return}/issue-40510-4.rs (100%) rename tests/ui/issues/{ => issue-57741-dereference-boxed-value}/issue-57741-1.rs (100%) rename tests/ui/issues/{ => issue-57741-dereference-boxed-value}/issue-57741-1.stderr (100%) rename tests/ui/issues/{ => issue-57741-dereference-boxed-value}/issue-57741.fixed (100%) rename tests/ui/issues/{ => issue-57741-dereference-boxed-value}/issue-57741.rs (100%) rename tests/ui/issues/{ => issue-57741-dereference-boxed-value}/issue-57741.stderr (100%) rename tests/ui/issues/{ => issue-5997-outer-generic-parameter}/issue-5997-enum.rs (100%) rename tests/ui/issues/{ => issue-5997-outer-generic-parameter}/issue-5997-enum.stderr (100%) rename tests/ui/issues/{ => issue-5997-outer-generic-parameter}/issue-5997-struct.rs (100%) rename tests/ui/issues/{ => issue-5997-outer-generic-parameter}/issue-5997-struct.stderr (100%) rename tests/ui/issues/{ => issue-5997-outer-generic-parameter}/issue-5997.rs (100%) rename tests/ui/issues/{ => issue-71676-suggest-deref}/issue-71676-1.fixed (100%) rename tests/ui/issues/{ => issue-71676-suggest-deref}/issue-71676-1.rs (100%) rename tests/ui/issues/{ => issue-71676-suggest-deref}/issue-71676-1.stderr (100%) rename tests/ui/issues/{ => issue-71676-suggest-deref}/issue-71676-2.rs (100%) rename tests/ui/issues/{ => issue-71676-suggest-deref}/issue-71676-2.stderr (100%) rename tests/ui/issues/{ => issue-76077-inaccesible-private-fields}/issue-76077-1.fixed (100%) rename tests/ui/issues/{ => issue-76077-inaccesible-private-fields}/issue-76077-1.rs (100%) rename tests/ui/issues/{ => issue-76077-inaccesible-private-fields}/issue-76077-1.stderr (100%) rename tests/ui/issues/{ => issue-76077-inaccesible-private-fields}/issue-76077.rs (100%) rename tests/ui/issues/{ => issue-76077-inaccesible-private-fields}/issue-76077.stderr (100%) diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 85553d2e3384a..451276b5ac157 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -8,9 +8,12 @@ use std::ffi::OsStr; use std::fs; use std::path::{Path, PathBuf}; +// FIXME: GitHub's UI truncates file lists that exceed 1000 entries, so these +// should all be 1000 or lower. Limits significantly smaller than 1000 are also +// desirable, because large numbers of files are unwieldy in general. See issue +// #73494. const ENTRY_LIMIT: usize = 900; -// FIXME: The following limits should be reduced eventually. -const ISSUES_ENTRY_LIMIT: usize = 1849; +const ISSUES_ENTRY_LIMIT: usize = 1807; const ROOT_ENTRY_LIMIT: usize = 870; const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[ diff --git a/tests/ui/issues/auxiliary/issue-1920.rs b/tests/ui/issues/issue-1920-absolute-paths/auxiliary/issue-1920.rs similarity index 100% rename from tests/ui/issues/auxiliary/issue-1920.rs rename to tests/ui/issues/issue-1920-absolute-paths/auxiliary/issue-1920.rs diff --git a/tests/ui/issues/issue-1920-1.rs b/tests/ui/issues/issue-1920-absolute-paths/issue-1920-1.rs similarity index 100% rename from tests/ui/issues/issue-1920-1.rs rename to tests/ui/issues/issue-1920-absolute-paths/issue-1920-1.rs diff --git a/tests/ui/issues/issue-1920-1.stderr b/tests/ui/issues/issue-1920-absolute-paths/issue-1920-1.stderr similarity index 100% rename from tests/ui/issues/issue-1920-1.stderr rename to tests/ui/issues/issue-1920-absolute-paths/issue-1920-1.stderr diff --git a/tests/ui/issues/issue-1920-2.rs b/tests/ui/issues/issue-1920-absolute-paths/issue-1920-2.rs similarity index 100% rename from tests/ui/issues/issue-1920-2.rs rename to tests/ui/issues/issue-1920-absolute-paths/issue-1920-2.rs diff --git a/tests/ui/issues/issue-1920-2.stderr b/tests/ui/issues/issue-1920-absolute-paths/issue-1920-2.stderr similarity index 100% rename from tests/ui/issues/issue-1920-2.stderr rename to tests/ui/issues/issue-1920-absolute-paths/issue-1920-2.stderr diff --git a/tests/ui/issues/issue-1920-3.rs b/tests/ui/issues/issue-1920-absolute-paths/issue-1920-3.rs similarity index 100% rename from tests/ui/issues/issue-1920-3.rs rename to tests/ui/issues/issue-1920-absolute-paths/issue-1920-3.rs diff --git a/tests/ui/issues/issue-1920-3.stderr b/tests/ui/issues/issue-1920-absolute-paths/issue-1920-3.stderr similarity index 100% rename from tests/ui/issues/issue-1920-3.stderr rename to tests/ui/issues/issue-1920-absolute-paths/issue-1920-3.stderr diff --git a/tests/ui/issues/issue-23302-1.rs b/tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-1.rs similarity index 100% rename from tests/ui/issues/issue-23302-1.rs rename to tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-1.rs diff --git a/tests/ui/issues/issue-23302-1.stderr b/tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-1.stderr similarity index 100% rename from tests/ui/issues/issue-23302-1.stderr rename to tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-1.stderr diff --git a/tests/ui/issues/issue-23302-2.rs b/tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-2.rs similarity index 100% rename from tests/ui/issues/issue-23302-2.rs rename to tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-2.rs diff --git a/tests/ui/issues/issue-23302-2.stderr b/tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-2.stderr similarity index 100% rename from tests/ui/issues/issue-23302-2.stderr rename to tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-2.stderr diff --git a/tests/ui/issues/issue-23302-3.rs b/tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-3.rs similarity index 100% rename from tests/ui/issues/issue-23302-3.rs rename to tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-3.rs diff --git a/tests/ui/issues/issue-23302-3.stderr b/tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-3.stderr similarity index 100% rename from tests/ui/issues/issue-23302-3.stderr rename to tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-3.stderr diff --git a/tests/ui/issues/issue-32122-1.fixed b/tests/ui/issues/issue-32122-deref-coercions-composition/issue-32122-1.fixed similarity index 100% rename from tests/ui/issues/issue-32122-1.fixed rename to tests/ui/issues/issue-32122-deref-coercions-composition/issue-32122-1.fixed diff --git a/tests/ui/issues/issue-32122-1.rs b/tests/ui/issues/issue-32122-deref-coercions-composition/issue-32122-1.rs similarity index 100% rename from tests/ui/issues/issue-32122-1.rs rename to tests/ui/issues/issue-32122-deref-coercions-composition/issue-32122-1.rs diff --git a/tests/ui/issues/issue-32122-1.stderr b/tests/ui/issues/issue-32122-deref-coercions-composition/issue-32122-1.stderr similarity index 100% rename from tests/ui/issues/issue-32122-1.stderr rename to tests/ui/issues/issue-32122-deref-coercions-composition/issue-32122-1.stderr diff --git a/tests/ui/issues/issue-32122-2.fixed b/tests/ui/issues/issue-32122-deref-coercions-composition/issue-32122-2.fixed similarity index 100% rename from tests/ui/issues/issue-32122-2.fixed rename to tests/ui/issues/issue-32122-deref-coercions-composition/issue-32122-2.fixed diff --git a/tests/ui/issues/issue-32122-2.rs b/tests/ui/issues/issue-32122-deref-coercions-composition/issue-32122-2.rs similarity index 100% rename from tests/ui/issues/issue-32122-2.rs rename to tests/ui/issues/issue-32122-deref-coercions-composition/issue-32122-2.rs diff --git a/tests/ui/issues/issue-32122-2.stderr b/tests/ui/issues/issue-32122-deref-coercions-composition/issue-32122-2.stderr similarity index 100% rename from tests/ui/issues/issue-32122-2.stderr rename to tests/ui/issues/issue-32122-deref-coercions-composition/issue-32122-2.stderr diff --git a/tests/ui/issues/issue-3668-2.fixed b/tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668-2.fixed similarity index 100% rename from tests/ui/issues/issue-3668-2.fixed rename to tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668-2.fixed diff --git a/tests/ui/issues/issue-3668-2.rs b/tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668-2.rs similarity index 100% rename from tests/ui/issues/issue-3668-2.rs rename to tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668-2.rs diff --git a/tests/ui/issues/issue-3668-2.stderr b/tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668-2.stderr similarity index 100% rename from tests/ui/issues/issue-3668-2.stderr rename to tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668-2.stderr diff --git a/tests/ui/issues/issue-3668.rs b/tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668.rs similarity index 100% rename from tests/ui/issues/issue-3668.rs rename to tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668.rs diff --git a/tests/ui/issues/issue-3668.stderr b/tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668.stderr similarity index 100% rename from tests/ui/issues/issue-3668.stderr rename to tests/ui/issues/issue-3668-non-constant-value-in-constant/issue-3668.stderr diff --git a/tests/ui/issues/issue-40510-1.migrate.stderr b/tests/ui/issues/issue-40510-captured-variable-return/issue-40510-1.migrate.stderr similarity index 100% rename from tests/ui/issues/issue-40510-1.migrate.stderr rename to tests/ui/issues/issue-40510-captured-variable-return/issue-40510-1.migrate.stderr diff --git a/tests/ui/issues/issue-40510-1.rs b/tests/ui/issues/issue-40510-captured-variable-return/issue-40510-1.rs similarity index 100% rename from tests/ui/issues/issue-40510-1.rs rename to tests/ui/issues/issue-40510-captured-variable-return/issue-40510-1.rs diff --git a/tests/ui/issues/issue-40510-1.stderr b/tests/ui/issues/issue-40510-captured-variable-return/issue-40510-1.stderr similarity index 100% rename from tests/ui/issues/issue-40510-1.stderr rename to tests/ui/issues/issue-40510-captured-variable-return/issue-40510-1.stderr diff --git a/tests/ui/issues/issue-40510-2.rs b/tests/ui/issues/issue-40510-captured-variable-return/issue-40510-2.rs similarity index 100% rename from tests/ui/issues/issue-40510-2.rs rename to tests/ui/issues/issue-40510-captured-variable-return/issue-40510-2.rs diff --git a/tests/ui/issues/issue-40510-3.migrate.stderr b/tests/ui/issues/issue-40510-captured-variable-return/issue-40510-3.migrate.stderr similarity index 100% rename from tests/ui/issues/issue-40510-3.migrate.stderr rename to tests/ui/issues/issue-40510-captured-variable-return/issue-40510-3.migrate.stderr diff --git a/tests/ui/issues/issue-40510-3.rs b/tests/ui/issues/issue-40510-captured-variable-return/issue-40510-3.rs similarity index 100% rename from tests/ui/issues/issue-40510-3.rs rename to tests/ui/issues/issue-40510-captured-variable-return/issue-40510-3.rs diff --git a/tests/ui/issues/issue-40510-3.stderr b/tests/ui/issues/issue-40510-captured-variable-return/issue-40510-3.stderr similarity index 100% rename from tests/ui/issues/issue-40510-3.stderr rename to tests/ui/issues/issue-40510-captured-variable-return/issue-40510-3.stderr diff --git a/tests/ui/issues/issue-40510-4.rs b/tests/ui/issues/issue-40510-captured-variable-return/issue-40510-4.rs similarity index 100% rename from tests/ui/issues/issue-40510-4.rs rename to tests/ui/issues/issue-40510-captured-variable-return/issue-40510-4.rs diff --git a/tests/ui/issues/issue-57741-1.rs b/tests/ui/issues/issue-57741-dereference-boxed-value/issue-57741-1.rs similarity index 100% rename from tests/ui/issues/issue-57741-1.rs rename to tests/ui/issues/issue-57741-dereference-boxed-value/issue-57741-1.rs diff --git a/tests/ui/issues/issue-57741-1.stderr b/tests/ui/issues/issue-57741-dereference-boxed-value/issue-57741-1.stderr similarity index 100% rename from tests/ui/issues/issue-57741-1.stderr rename to tests/ui/issues/issue-57741-dereference-boxed-value/issue-57741-1.stderr diff --git a/tests/ui/issues/issue-57741.fixed b/tests/ui/issues/issue-57741-dereference-boxed-value/issue-57741.fixed similarity index 100% rename from tests/ui/issues/issue-57741.fixed rename to tests/ui/issues/issue-57741-dereference-boxed-value/issue-57741.fixed diff --git a/tests/ui/issues/issue-57741.rs b/tests/ui/issues/issue-57741-dereference-boxed-value/issue-57741.rs similarity index 100% rename from tests/ui/issues/issue-57741.rs rename to tests/ui/issues/issue-57741-dereference-boxed-value/issue-57741.rs diff --git a/tests/ui/issues/issue-57741.stderr b/tests/ui/issues/issue-57741-dereference-boxed-value/issue-57741.stderr similarity index 100% rename from tests/ui/issues/issue-57741.stderr rename to tests/ui/issues/issue-57741-dereference-boxed-value/issue-57741.stderr diff --git a/tests/ui/issues/issue-5997-enum.rs b/tests/ui/issues/issue-5997-outer-generic-parameter/issue-5997-enum.rs similarity index 100% rename from tests/ui/issues/issue-5997-enum.rs rename to tests/ui/issues/issue-5997-outer-generic-parameter/issue-5997-enum.rs diff --git a/tests/ui/issues/issue-5997-enum.stderr b/tests/ui/issues/issue-5997-outer-generic-parameter/issue-5997-enum.stderr similarity index 100% rename from tests/ui/issues/issue-5997-enum.stderr rename to tests/ui/issues/issue-5997-outer-generic-parameter/issue-5997-enum.stderr diff --git a/tests/ui/issues/issue-5997-struct.rs b/tests/ui/issues/issue-5997-outer-generic-parameter/issue-5997-struct.rs similarity index 100% rename from tests/ui/issues/issue-5997-struct.rs rename to tests/ui/issues/issue-5997-outer-generic-parameter/issue-5997-struct.rs diff --git a/tests/ui/issues/issue-5997-struct.stderr b/tests/ui/issues/issue-5997-outer-generic-parameter/issue-5997-struct.stderr similarity index 100% rename from tests/ui/issues/issue-5997-struct.stderr rename to tests/ui/issues/issue-5997-outer-generic-parameter/issue-5997-struct.stderr diff --git a/tests/ui/issues/issue-5997.rs b/tests/ui/issues/issue-5997-outer-generic-parameter/issue-5997.rs similarity index 100% rename from tests/ui/issues/issue-5997.rs rename to tests/ui/issues/issue-5997-outer-generic-parameter/issue-5997.rs diff --git a/tests/ui/issues/issue-71676-1.fixed b/tests/ui/issues/issue-71676-suggest-deref/issue-71676-1.fixed similarity index 100% rename from tests/ui/issues/issue-71676-1.fixed rename to tests/ui/issues/issue-71676-suggest-deref/issue-71676-1.fixed diff --git a/tests/ui/issues/issue-71676-1.rs b/tests/ui/issues/issue-71676-suggest-deref/issue-71676-1.rs similarity index 100% rename from tests/ui/issues/issue-71676-1.rs rename to tests/ui/issues/issue-71676-suggest-deref/issue-71676-1.rs diff --git a/tests/ui/issues/issue-71676-1.stderr b/tests/ui/issues/issue-71676-suggest-deref/issue-71676-1.stderr similarity index 100% rename from tests/ui/issues/issue-71676-1.stderr rename to tests/ui/issues/issue-71676-suggest-deref/issue-71676-1.stderr diff --git a/tests/ui/issues/issue-71676-2.rs b/tests/ui/issues/issue-71676-suggest-deref/issue-71676-2.rs similarity index 100% rename from tests/ui/issues/issue-71676-2.rs rename to tests/ui/issues/issue-71676-suggest-deref/issue-71676-2.rs diff --git a/tests/ui/issues/issue-71676-2.stderr b/tests/ui/issues/issue-71676-suggest-deref/issue-71676-2.stderr similarity index 100% rename from tests/ui/issues/issue-71676-2.stderr rename to tests/ui/issues/issue-71676-suggest-deref/issue-71676-2.stderr diff --git a/tests/ui/issues/issue-76077-1.fixed b/tests/ui/issues/issue-76077-inaccesible-private-fields/issue-76077-1.fixed similarity index 100% rename from tests/ui/issues/issue-76077-1.fixed rename to tests/ui/issues/issue-76077-inaccesible-private-fields/issue-76077-1.fixed diff --git a/tests/ui/issues/issue-76077-1.rs b/tests/ui/issues/issue-76077-inaccesible-private-fields/issue-76077-1.rs similarity index 100% rename from tests/ui/issues/issue-76077-1.rs rename to tests/ui/issues/issue-76077-inaccesible-private-fields/issue-76077-1.rs diff --git a/tests/ui/issues/issue-76077-1.stderr b/tests/ui/issues/issue-76077-inaccesible-private-fields/issue-76077-1.stderr similarity index 100% rename from tests/ui/issues/issue-76077-1.stderr rename to tests/ui/issues/issue-76077-inaccesible-private-fields/issue-76077-1.stderr diff --git a/tests/ui/issues/issue-76077.rs b/tests/ui/issues/issue-76077-inaccesible-private-fields/issue-76077.rs similarity index 100% rename from tests/ui/issues/issue-76077.rs rename to tests/ui/issues/issue-76077-inaccesible-private-fields/issue-76077.rs diff --git a/tests/ui/issues/issue-76077.stderr b/tests/ui/issues/issue-76077-inaccesible-private-fields/issue-76077.stderr similarity index 100% rename from tests/ui/issues/issue-76077.stderr rename to tests/ui/issues/issue-76077-inaccesible-private-fields/issue-76077.stderr From fc964fb439473c84a47444f89e5cf4c570b98f46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 29 Jan 2024 23:33:02 +0000 Subject: [PATCH 24/29] review comments --- .../rustc_hir_analysis/src/astconv/errors.rs | 25 ++++++----------- .../rustc_hir_typeck/src/method/suggest.rs | 28 +++++++------------ 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs index b2d5d3885d938..fa7d9799dbd2e 100644 --- a/compiler/rustc_hir_analysis/src/astconv/errors.rs +++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs @@ -6,6 +6,7 @@ use crate::errors::{ use crate::fluent_generated as fluent; use crate::traits::error_reporting::report_object_safety_error; use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; +use rustc_data_structures::sorted_map::SortedMap; use rustc_data_structures::unord::UnordMap; use rustc_errors::{pluralize, struct_span_code_err, Applicability, Diagnostic, ErrorGuaranteed}; use rustc_hir as hir; @@ -461,14 +462,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { return err.emit(); } - let mut bound_spans: FxHashMap> = Default::default(); + let mut bound_spans: SortedMap> = Default::default(); let mut bound_span_label = |self_ty: Ty<'_>, obligation: &str, quiet: &str| { let msg = format!("`{}`", if obligation.len() > 50 { quiet } else { obligation }); match &self_ty.kind() { // Point at the type that couldn't satisfy the bound. ty::Adt(def, _) => { - bound_spans.entry(tcx.def_span(def.did())).or_default().push(msg) + bound_spans.get_mut_or_insert_default(tcx.def_span(def.did())).push(msg) } // Point at the trait object that couldn't satisfy the bound. ty::Dynamic(preds, _, _) => { @@ -476,8 +477,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { match pred.skip_binder() { ty::ExistentialPredicate::Trait(tr) => { bound_spans - .entry(tcx.def_span(tr.def_id)) - .or_default() + .get_mut_or_insert_default(tcx.def_span(tr.def_id)) .push(msg.clone()); } ty::ExistentialPredicate::Projection(_) @@ -488,8 +488,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // Point at the closure that couldn't satisfy the bound. ty::Closure(def_id, _) => { bound_spans - .entry(tcx.def_span(*def_id)) - .or_default() + .get_mut_or_insert_default(tcx.def_span(*def_id)) .push(format!("`{quiet}`")); } _ => {} @@ -559,21 +558,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { format!("associated type cannot be referenced on `{self_ty}` due to unsatisfied trait bounds") ); - let mut bound_spans: Vec<(Span, Vec)> = bound_spans - .into_iter() - .map(|(span, mut bounds)| { - bounds.sort(); - bounds.dedup(); - (span, bounds) - }) - .collect(); - bound_spans.sort_by_key(|(span, _)| *span); - for (span, bounds) in bound_spans { + for (span, mut bounds) in bound_spans { if !tcx.sess.source_map().is_span_accessible(span) { continue; } + bounds.sort(); + bounds.dedup(); let msg = match &bounds[..] { [bound] => format!("doesn't satisfy {bound}"), + bounds if bounds.len() > 4 => format!("doesn't satisfy {} bounds", bounds.len()), [bounds @ .., last] => format!("doesn't satisfy {} or {last}", bounds.join(", ")), [] => unreachable!(), }; diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 0499a46dbb826..677d224065195 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -9,7 +9,8 @@ use crate::Expectation; use crate::FnCtxt; use rustc_ast::ast::Mutability; use rustc_attr::parse_confusables; -use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; +use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; +use rustc_data_structures::sorted_map::SortedMap; use rustc_data_structures::unord::UnordSet; use rustc_errors::StashKey; use rustc_errors::{ @@ -538,7 +539,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); } - let mut bound_spans: FxHashMap> = Default::default(); + let mut bound_spans: SortedMap> = Default::default(); let mut restrict_type_params = false; let mut unsatisfied_bounds = false; if item_name.name == sym::count && self.is_slice_ty(rcvr_ty, span) { @@ -637,7 +638,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match &self_ty.kind() { // Point at the type that couldn't satisfy the bound. ty::Adt(def, _) => { - bound_spans.entry(tcx.def_span(def.did())).or_default().push(msg) + bound_spans.get_mut_or_insert_default(tcx.def_span(def.did())).push(msg) } // Point at the trait object that couldn't satisfy the bound. ty::Dynamic(preds, _, _) => { @@ -645,8 +646,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match pred.skip_binder() { ty::ExistentialPredicate::Trait(tr) => { bound_spans - .entry(tcx.def_span(tr.def_id)) - .or_default() + .get_mut_or_insert_default(tcx.def_span(tr.def_id)) .push(msg.clone()); } ty::ExistentialPredicate::Projection(_) @@ -657,8 +657,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Point at the closure that couldn't satisfy the bound. ty::Closure(def_id, _) => { bound_spans - .entry(tcx.def_span(*def_id)) - .or_default() + .get_mut_or_insert_default(tcx.def_span(*def_id)) .push(format!("`{quiet}`")); } _ => {} @@ -1167,20 +1166,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.suggest_unwrapping_inner_self(&mut err, source, rcvr_ty, item_name); - #[allow(rustc::potential_query_instability)] // We immediately sort the resulting Vec. - let mut bound_spans: Vec<(Span, Vec)> = bound_spans - .into_iter() - .map(|(span, mut bounds)| { - bounds.sort(); - bounds.dedup(); - (span, bounds) - }) - .collect(); - bound_spans.sort_by_key(|(span, _)| *span); - for (span, bounds) in bound_spans { + for (span, mut bounds) in bound_spans { if !tcx.sess.source_map().is_span_accessible(span) { continue; } + bounds.sort(); + bounds.dedup(); let pre = if Some(span) == ty_span { ty_span.take(); format!( @@ -1192,6 +1183,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let msg = match &bounds[..] { [bound] => format!("{pre}doesn't satisfy {bound}"), + bounds if bounds.len() > 4 => format!("doesn't satisfy {} bounds", bounds.len()), [bounds @ .., last] => { format!("{pre}doesn't satisfy {} or {last}", bounds.join(", ")) } From 5350edb9e8f4e194a2cad9a41b81d97a8ed52fab Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 30 Jan 2024 15:27:16 +1100 Subject: [PATCH 25/29] Remove the lifetime from `DiagnosticArgValue`. Because it's almost always static. This makes `impl IntoDiagnosticArg for DiagnosticArgValue` trivial, which is nice. There are a few diagnostics constructed in `compiler/rustc_mir_build/src/check_unsafety.rs` and `compiler/rustc_mir_transform/src/errors.rs` that now need symbols converted to `String` with `to_string` instead of `&str` with `as_str`, but that' no big deal, and worth it for the simplifications elsewhere. --- .../src/diagnostics/region_name.rs | 2 +- compiler/rustc_codegen_gcc/src/errors.rs | 2 +- .../src/assert_module_sources.rs | 2 +- compiler/rustc_codegen_ssa/src/back/write.rs | 4 +- compiler/rustc_codegen_ssa/src/errors.rs | 4 +- .../rustc_const_eval/src/const_eval/error.rs | 2 +- compiler/rustc_const_eval/src/errors.rs | 2 +- compiler/rustc_errors/src/diagnostic.rs | 32 ++++------ compiler/rustc_errors/src/diagnostic_impls.rs | 60 +++++++++---------- compiler/rustc_errors/src/translation.rs | 6 +- compiler/rustc_hir_typeck/src/errors.rs | 2 +- compiler/rustc_infer/src/errors/mod.rs | 2 +- .../src/errors/note_and_explain.rs | 4 +- .../src/infer/error_reporting/mod.rs | 2 +- .../infer/error_reporting/need_type_info.rs | 2 +- .../nice_region_error/placeholder_error.rs | 2 +- compiler/rustc_metadata/src/locator.rs | 2 +- compiler/rustc_middle/src/error.rs | 7 +-- .../rustc_middle/src/mir/interpret/error.rs | 11 ++-- compiler/rustc_middle/src/mir/terminator.rs | 2 +- compiler/rustc_middle/src/thir.rs | 2 +- compiler/rustc_middle/src/ty/consts/int.rs | 2 +- compiler/rustc_middle/src/ty/consts/kind.rs | 2 +- compiler/rustc_middle/src/ty/diagnostics.rs | 2 +- compiler/rustc_middle/src/ty/generic_args.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 4 +- compiler/rustc_middle/src/ty/print/pretty.rs | 4 +- compiler/rustc_middle/src/ty/sty.rs | 8 +-- .../rustc_mir_build/src/check_unsafety.rs | 21 +++++-- compiler/rustc_mir_build/src/errors.rs | 12 ++-- .../rustc_mir_transform/src/const_prop.rs | 2 +- compiler/rustc_mir_transform/src/errors.rs | 4 +- compiler/rustc_passes/src/check_attr.rs | 2 +- compiler/rustc_resolve/src/late.rs | 2 +- compiler/rustc_session/src/config.rs | 2 +- compiler/rustc_session/src/session.rs | 2 +- src/tools/miri/src/diagnostics.rs | 2 +- 38 files changed, 113 insertions(+), 116 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 4cb49362863fc..15e1066e983a9 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -188,7 +188,7 @@ impl Display for RegionName { } impl rustc_errors::IntoDiagnosticArg for RegionName { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/compiler/rustc_codegen_gcc/src/errors.rs b/compiler/rustc_codegen_gcc/src/errors.rs index e9283b1989453..cc0fbe46dcc11 100644 --- a/compiler/rustc_codegen_gcc/src/errors.rs +++ b/compiler/rustc_codegen_gcc/src/errors.rs @@ -35,7 +35,7 @@ pub(crate) enum PossibleFeature<'a> { struct ExitCode(Option); impl IntoDiagnosticArg for ExitCode { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { let ExitCode(exit_code) = self; match exit_code { Some(t) => t.into_diagnostic_arg(), diff --git a/compiler/rustc_codegen_ssa/src/assert_module_sources.rs b/compiler/rustc_codegen_ssa/src/assert_module_sources.rs index a1daadce958eb..ad5a74b04e447 100644 --- a/compiler/rustc_codegen_ssa/src/assert_module_sources.rs +++ b/compiler/rustc_codegen_ssa/src/assert_module_sources.rs @@ -206,7 +206,7 @@ impl fmt::Display for CguReuse { } impl IntoDiagnosticArg for CguReuse { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Owned(self.to_string())) } } diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index b13d566b40b3b..affd386361c09 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -999,7 +999,7 @@ type DiagnosticArgName<'source> = Cow<'source, str>; struct Diagnostic { msgs: Vec<(DiagnosticMessage, Style)>, - args: FxHashMap, rustc_errors::DiagnosticArgValue<'static>>, + args: FxHashMap, rustc_errors::DiagnosticArgValue>, code: Option, lvl: Level, } @@ -1811,7 +1811,7 @@ impl Translate for SharedEmitter { impl Emitter for SharedEmitter { fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) { - let args: FxHashMap, rustc_errors::DiagnosticArgValue<'_>> = + let args: FxHashMap, rustc_errors::DiagnosticArgValue> = diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect(); drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic { msgs: diag.messages.clone(), diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index ef291ead190cc..06ea5b9e8f4ab 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -147,7 +147,7 @@ impl<'a> CopyPath<'a> { struct DebugArgPath<'a>(pub &'a Path); impl IntoDiagnosticArg for DebugArgPath<'_> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.0))) } } @@ -974,7 +974,7 @@ pub enum ExpectedPointerMutability { } impl IntoDiagnosticArg for ExpectedPointerMutability { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { match self { ExpectedPointerMutability::Mut => DiagnosticArgValue::Str(Cow::Borrowed("*mut")), ExpectedPointerMutability::Not => DiagnosticArgValue::Str(Cow::Borrowed("*_")), diff --git a/compiler/rustc_const_eval/src/const_eval/error.rs b/compiler/rustc_const_eval/src/const_eval/error.rs index e8d0430c9d955..dabf78ef90e5f 100644 --- a/compiler/rustc_const_eval/src/const_eval/error.rs +++ b/compiler/rustc_const_eval/src/const_eval/error.rs @@ -34,7 +34,7 @@ impl MachineStopType for ConstEvalErrKind { } fn add_args( self: Box, - adder: &mut dyn FnMut(std::borrow::Cow<'static, str>, DiagnosticArgValue<'static>), + adder: &mut dyn FnMut(std::borrow::Cow<'static, str>, DiagnosticArgValue), ) { use ConstEvalErrKind::*; match *self { diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index 9e27c19e94cd9..4d2b1ba3eec89 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -906,7 +906,7 @@ impl ReportErrorExt for ResourceExhaustionInfo { } impl rustc_errors::IntoDiagnosticArg for InternKind { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Borrowed(match self { InternKind::Static(Mutability::Not) => "static", InternKind::Static(Mutability::Mut) => "static_mut", diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 8a32e29ddc9dc..b3a4e1c5843dd 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -24,7 +24,7 @@ pub struct SuggestionsDisabled; /// `DiagnosticArg` are converted to `FluentArgs` (consuming the collection) at the start of /// diagnostic emission. pub type DiagnosticArg<'iter, 'source> = - (&'iter DiagnosticArgName<'source>, &'iter DiagnosticArgValue<'source>); + (&'iter DiagnosticArgName<'source>, &'iter DiagnosticArgValue); /// Name of a diagnostic argument. pub type DiagnosticArgName<'source> = Cow<'source, str>; @@ -32,10 +32,10 @@ pub type DiagnosticArgName<'source> = Cow<'source, str>; /// Simplified version of `FluentValue` that can implement `Encodable` and `Decodable`. Converted /// to a `FluentValue` by the emitter to be used in diagnostic translation. #[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)] -pub enum DiagnosticArgValue<'source> { - Str(Cow<'source, str>), +pub enum DiagnosticArgValue { + Str(Cow<'static, str>), Number(i128), - StrListSepByAnd(Vec>), + StrListSepByAnd(Vec>), } /// Converts a value of a type into a `DiagnosticArg` (typically a field of an `IntoDiagnostic` @@ -43,23 +43,17 @@ pub enum DiagnosticArgValue<'source> { /// being converted rather than on `DiagnosticArgValue`, which enables types from other `rustc_*` /// crates to implement this. pub trait IntoDiagnosticArg { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>; + fn into_diagnostic_arg(self) -> DiagnosticArgValue; } -impl<'source> IntoDiagnosticArg for DiagnosticArgValue<'source> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { - match self { - DiagnosticArgValue::Str(s) => DiagnosticArgValue::Str(Cow::Owned(s.into_owned())), - DiagnosticArgValue::Number(n) => DiagnosticArgValue::Number(n), - DiagnosticArgValue::StrListSepByAnd(l) => DiagnosticArgValue::StrListSepByAnd( - l.into_iter().map(|s| Cow::Owned(s.into_owned())).collect(), - ), - } +impl IntoDiagnosticArg for DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { + self } } -impl<'source> Into> for DiagnosticArgValue<'source> { - fn into(self) -> FluentValue<'source> { +impl Into> for DiagnosticArgValue { + fn into(self) -> FluentValue<'static> { match self { DiagnosticArgValue::Str(s) => From::from(s), DiagnosticArgValue::Number(n) => From::from(n), @@ -109,7 +103,7 @@ pub struct Diagnostic { pub span: MultiSpan, pub children: Vec, pub suggestions: Result, SuggestionsDisabled>, - args: FxHashMap, DiagnosticArgValue<'static>>, + args: FxHashMap, DiagnosticArgValue>, /// This is not used for highlighting or rendering any error message. Rather, it can be used /// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of @@ -931,7 +925,7 @@ impl Diagnostic { pub fn replace_args( &mut self, - args: FxHashMap, DiagnosticArgValue<'static>>, + args: FxHashMap, DiagnosticArgValue>, ) { self.args = args; } @@ -990,7 +984,7 @@ impl Diagnostic { ) -> ( &Level, &[(DiagnosticMessage, Style)], - Vec<(&Cow<'static, str>, &DiagnosticArgValue<'static>)>, + Vec<(&Cow<'static, str>, &DiagnosticArgValue)>, &Option, &Option, &MultiSpan, diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index df3fd4af4b436..faab3fc663a82 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -23,7 +23,7 @@ use std::process::ExitStatus; pub struct DiagnosticArgFromDisplay<'a>(pub &'a dyn fmt::Display); impl IntoDiagnosticArg for DiagnosticArgFromDisplay<'_> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { self.0.to_string().into_diagnostic_arg() } } @@ -41,7 +41,7 @@ impl<'a, T: fmt::Display> From<&'a T> for DiagnosticArgFromDisplay<'a> { } impl<'a, T: Clone + IntoDiagnosticArg> IntoDiagnosticArg for &'a T { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { self.clone().into_diagnostic_arg() } } @@ -50,7 +50,7 @@ macro_rules! into_diagnostic_arg_using_display { ($( $ty:ty ),+ $(,)?) => { $( impl IntoDiagnosticArg for $ty { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { self.to_string().into_diagnostic_arg() } } @@ -62,7 +62,7 @@ macro_rules! into_diagnostic_arg_for_number { ($( $ty:ty ),+ $(,)?) => { $( impl IntoDiagnosticArg for $ty { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { // HACK: `FluentNumber` the underline backing struct represent // numbers using a f64 which can't represent all the i128 numbers // So in order to be able to use fluent selectors and still @@ -99,7 +99,7 @@ into_diagnostic_arg_using_display!( into_diagnostic_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize); impl IntoDiagnosticArg for bool { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { if self { DiagnosticArgValue::Str(Cow::Borrowed("true")) } else { @@ -109,13 +109,13 @@ impl IntoDiagnosticArg for bool { } impl IntoDiagnosticArg for char { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Owned(format!("{self:?}"))) } } impl IntoDiagnosticArg for Vec { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::StrListSepByAnd( self.into_iter().map(|c| Cow::Owned(format!("{c:?}"))).collect(), ) @@ -123,49 +123,49 @@ impl IntoDiagnosticArg for Vec { } impl IntoDiagnosticArg for Symbol { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { self.to_ident_string().into_diagnostic_arg() } } impl<'a> IntoDiagnosticArg for &'a str { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { self.to_string().into_diagnostic_arg() } } impl IntoDiagnosticArg for String { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Owned(self)) } } impl<'a> IntoDiagnosticArg for Cow<'a, str> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Owned(self.into_owned())) } } impl<'a> IntoDiagnosticArg for &'a Path { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Owned(self.display().to_string())) } } impl IntoDiagnosticArg for PathBuf { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Owned(self.display().to_string())) } } impl IntoDiagnosticArg for PanicStrategy { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Owned(self.desc().to_string())) } } impl IntoDiagnosticArg for hir::ConstContext { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Borrowed(match self { hir::ConstContext::ConstFn => "const_fn", hir::ConstContext::Static(_) => "static", @@ -175,49 +175,49 @@ impl IntoDiagnosticArg for hir::ConstContext { } impl IntoDiagnosticArg for ast::Expr { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Owned(pprust::expr_to_string(&self))) } } impl IntoDiagnosticArg for ast::Path { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Owned(pprust::path_to_string(&self))) } } impl IntoDiagnosticArg for ast::token::Token { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(pprust::token_to_string(&self)) } } impl IntoDiagnosticArg for ast::token::TokenKind { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(pprust::token_kind_to_string(&self)) } } impl IntoDiagnosticArg for type_ir::FloatTy { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Borrowed(self.name_str())) } } impl IntoDiagnosticArg for std::ffi::CString { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned())) } } impl IntoDiagnosticArg for rustc_data_structures::small_c_str::SmallCStr { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned())) } } impl IntoDiagnosticArg for ast::Visibility { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { let s = pprust::vis_to_string(&self); let s = s.trim_end().to_string(); DiagnosticArgValue::Str(Cow::Owned(s)) @@ -225,7 +225,7 @@ impl IntoDiagnosticArg for ast::Visibility { } impl IntoDiagnosticArg for rustc_lint_defs::Level { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Borrowed(self.to_cmd_flag())) } } @@ -240,7 +240,7 @@ impl From> for DiagnosticSymbolList { } impl IntoDiagnosticArg for DiagnosticSymbolList { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::StrListSepByAnd( self.0.into_iter().map(|sym| Cow::Owned(format!("`{sym}`"))).collect(), ) @@ -248,7 +248,7 @@ impl IntoDiagnosticArg for DiagnosticSymbolList { } impl IntoDiagnosticArg for hir::def::Res { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Borrowed(self.descr())) } } @@ -334,13 +334,13 @@ pub struct DelayedAtWithoutNewline { } impl IntoDiagnosticArg for DiagnosticLocation { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::from(self.to_string())) } } impl IntoDiagnosticArg for Backtrace { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::from(self.to_string())) } } @@ -353,7 +353,7 @@ pub struct InvalidFlushedDelayedDiagnosticLevel { pub level: Level, } impl IntoDiagnosticArg for Level { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::from(self.to_string())) } } @@ -368,7 +368,7 @@ pub struct IndicateAnonymousLifetime { } impl IntoDiagnosticArg for type_ir::ClosureKind { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(self.as_str().into()) } } diff --git a/compiler/rustc_errors/src/translation.rs b/compiler/rustc_errors/src/translation.rs index ed35eb1b6c4ad..af927bf9629a1 100644 --- a/compiler/rustc_errors/src/translation.rs +++ b/compiler/rustc_errors/src/translation.rs @@ -12,9 +12,9 @@ use std::error::Report; /// /// Typically performed once for each diagnostic at the start of `emit_diagnostic` and then /// passed around as a reference thereafter. -pub fn to_fluent_args<'iter, 'arg: 'iter>( - iter: impl Iterator>, -) -> FluentArgs<'arg> { +pub fn to_fluent_args<'iter>( + iter: impl Iterator>, +) -> FluentArgs<'static> { let mut args = if let Some(size) = iter.size_hint().1 { FluentArgs::with_capacity(size) } else { diff --git a/compiler/rustc_hir_typeck/src/errors.rs b/compiler/rustc_hir_typeck/src/errors.rs index b75cf4b4e8bca..0695af15b16f8 100644 --- a/compiler/rustc_hir_typeck/src/errors.rs +++ b/compiler/rustc_hir_typeck/src/errors.rs @@ -43,7 +43,7 @@ pub enum ReturnLikeStatementKind { } impl IntoDiagnosticArg for ReturnLikeStatementKind { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { let kind = match self { Self::Return => "return", Self::Become => "become", diff --git a/compiler/rustc_infer/src/errors/mod.rs b/compiler/rustc_infer/src/errors/mod.rs index 4e9f573091b09..0a128218c9229 100644 --- a/compiler/rustc_infer/src/errors/mod.rs +++ b/compiler/rustc_infer/src/errors/mod.rs @@ -534,7 +534,7 @@ pub enum TyOrSig<'tcx> { } impl IntoDiagnosticArg for TyOrSig<'_> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { match self { TyOrSig::Ty(ty) => ty.into_diagnostic_arg(), TyOrSig::ClosureSig(sig) => sig.into_diagnostic_arg(), diff --git a/compiler/rustc_infer/src/errors/note_and_explain.rs b/compiler/rustc_infer/src/errors/note_and_explain.rs index 8e45cc6d80e92..331e3633e908d 100644 --- a/compiler/rustc_infer/src/errors/note_and_explain.rs +++ b/compiler/rustc_infer/src/errors/note_and_explain.rs @@ -108,7 +108,7 @@ pub enum SuffixKind { } impl IntoDiagnosticArg for PrefixKind { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { let kind = match self { Self::Empty => "empty", Self::RefValidFor => "ref_valid_for", @@ -130,7 +130,7 @@ impl IntoDiagnosticArg for PrefixKind { } impl IntoDiagnosticArg for SuffixKind { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { let kind = match self { Self::Empty => "empty", Self::Continues => "continues", diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index e19177fccefd8..db01b5bd70719 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2914,7 +2914,7 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> { pub struct ObligationCauseAsDiagArg<'tcx>(pub ObligationCause<'tcx>); impl IntoDiagnosticArg for ObligationCauseAsDiagArg<'_> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { use crate::traits::ObligationCauseCode::*; let kind = match self.0.code() { CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => "method_compat", diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index cf1e042c529a4..7287fc26053fe 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -134,7 +134,7 @@ impl InferenceDiagnosticsParentData { } impl IntoDiagnosticArg for UnderspecifiedArgKind { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { let kind = match self { Self::Type { .. } => "type", Self::Const { is_parameter: true } => "const_with_param", diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs index e1a83c86318e9..b3b83c8ab957f 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -30,7 +30,7 @@ impl<'tcx, T> IntoDiagnosticArg for Highlighted<'tcx, T> where T: for<'a> Print<'tcx, FmtPrinter<'a, 'tcx>>, { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { rustc_errors::DiagnosticArgValue::Str(self.to_string().into()) } } diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 2376d95334155..1ab965e28769f 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -291,7 +291,7 @@ impl fmt::Display for CrateFlavor { } impl IntoDiagnosticArg for CrateFlavor { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { match self { CrateFlavor::Rlib => DiagnosticArgValue::Str(Cow::Borrowed("rlib")), CrateFlavor::Rmeta => DiagnosticArgValue::Str(Cow::Borrowed("rmeta")), diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs index e0436b38c4be6..211da80020297 100644 --- a/compiler/rustc_middle/src/error.rs +++ b/compiler/rustc_middle/src/error.rs @@ -95,17 +95,14 @@ pub(super) struct ConstNotUsedTraitAlias { pub struct CustomSubdiagnostic<'a> { pub msg: fn() -> DiagnosticMessage, - pub add_args: - Box, DiagnosticArgValue<'static>)) + 'a>, + pub add_args: Box, DiagnosticArgValue)) + 'a>, } impl<'a> CustomSubdiagnostic<'a> { pub fn label(x: fn() -> DiagnosticMessage) -> Self { Self::label_and_then(x, |_| {}) } - pub fn label_and_then< - F: FnOnce(&mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue<'static>)) + 'a, - >( + pub fn label_and_then, DiagnosticArgValue)) + 'a>( msg: fn() -> DiagnosticMessage, f: F, ) -> Self { diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index 7a1df4954514a..95574aee499f2 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -233,7 +233,7 @@ pub enum InvalidMetaKind { } impl IntoDiagnosticArg for InvalidMetaKind { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Borrowed(match self { InvalidMetaKind::SliceTooBig => "slice_too_big", InvalidMetaKind::TooBig => "too_big", @@ -267,7 +267,7 @@ pub struct Misalignment { macro_rules! impl_into_diagnostic_arg_through_debug { ($($ty:ty),*$(,)?) => {$( impl IntoDiagnosticArg for $ty { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Owned(format!("{self:?}"))) } } @@ -367,7 +367,7 @@ pub enum PointerKind { } impl IntoDiagnosticArg for PointerKind { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str( match self { Self::Ref => "ref", @@ -485,10 +485,7 @@ pub trait MachineStopType: Any + fmt::Debug + Send { fn diagnostic_message(&self) -> DiagnosticMessage; /// Add diagnostic arguments by passing name and value pairs to `adder`, which are passed to /// fluent for formatting the translated diagnostic message. - fn add_args( - self: Box, - adder: &mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue<'static>), - ); + fn add_args(self: Box, adder: &mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue)); } impl dyn MachineStopType { diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index fdbbf468ecea2..0fe33e441f430 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -292,7 +292,7 @@ impl AssertKind { } } - pub fn add_args(self, adder: &mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue<'static>)) + pub fn add_args(self, adder: &mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue)) where O: fmt::Debug, { diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index b4b8387c262b9..0fed4ccc62a83 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -674,7 +674,7 @@ impl<'tcx> Pat<'tcx> { } impl<'tcx> IntoDiagnosticArg for Pat<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { format!("{self}").into_diagnostic_arg() } } diff --git a/compiler/rustc_middle/src/ty/consts/int.rs b/compiler/rustc_middle/src/ty/consts/int.rs index 310cf113b11b6..f7c33960fdd83 100644 --- a/compiler/rustc_middle/src/ty/consts/int.rs +++ b/compiler/rustc_middle/src/ty/consts/int.rs @@ -117,7 +117,7 @@ impl std::fmt::Debug for ConstInt { impl IntoDiagnosticArg for ConstInt { // FIXME this simply uses the Debug impl, but we could probably do better by converting both // to an inherent method that returns `Cow`. - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(format!("{self:?}").into()) } } diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs index 16e7b16a0bf8c..603d7f46aabe0 100644 --- a/compiler/rustc_middle/src/ty/consts/kind.rs +++ b/compiler/rustc_middle/src/ty/consts/kind.rs @@ -15,7 +15,7 @@ pub struct UnevaluatedConst<'tcx> { } impl rustc_errors::IntoDiagnosticArg for UnevaluatedConst<'_> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { format!("{self:?}").into_diagnostic_arg() } } diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index c1e2479defd0a..8678f388298c2 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -20,7 +20,7 @@ use rustc_span::{BytePos, Span}; use rustc_type_ir::TyKind::*; impl<'tcx> IntoDiagnosticArg for Ty<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/compiler/rustc_middle/src/ty/generic_args.rs b/compiler/rustc_middle/src/ty/generic_args.rs index 5a4b86eeffd76..69ad6810c6fe0 100644 --- a/compiler/rustc_middle/src/ty/generic_args.rs +++ b/compiler/rustc_middle/src/ty/generic_args.rs @@ -56,7 +56,7 @@ unsafe impl<'tcx> Sync for GenericArg<'tcx> where } impl<'tcx> IntoDiagnosticArg for GenericArg<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 25473f52c039e..f07a4ac29e961 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -269,7 +269,7 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> { } impl<'tcx> IntoDiagnosticArg for LayoutError<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index dac60ae58a0ca..dabd50a32b95c 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -583,13 +583,13 @@ impl<'tcx> Predicate<'tcx> { } impl rustc_errors::IntoDiagnosticArg for Predicate<'_> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { rustc_errors::DiagnosticArgValue::Str(std::borrow::Cow::Owned(self.to_string())) } } impl rustc_errors::IntoDiagnosticArg for Clause<'_> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { rustc_errors::DiagnosticArgValue::Str(std::borrow::Cow::Owned(self.to_string())) } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 73052be30ae3d..bac5068a69b86 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2632,7 +2632,7 @@ where pub struct TraitRefPrintOnlyTraitPath<'tcx>(ty::TraitRef<'tcx>); impl<'tcx> rustc_errors::IntoDiagnosticArg for TraitRefPrintOnlyTraitPath<'tcx> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { self.to_string().into_diagnostic_arg() } } @@ -2649,7 +2649,7 @@ impl<'tcx> fmt::Debug for TraitRefPrintOnlyTraitPath<'tcx> { pub struct TraitRefPrintSugared<'tcx>(ty::TraitRef<'tcx>); impl<'tcx> rustc_errors::IntoDiagnosticArg for TraitRefPrintSugared<'tcx> { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index b089f4a9e78b9..43a6281481fa4 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -862,7 +862,7 @@ impl<'tcx> PolyTraitRef<'tcx> { } impl<'tcx> IntoDiagnosticArg for TraitRef<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { self.to_string().into_diagnostic_arg() } } @@ -908,7 +908,7 @@ impl<'tcx> ExistentialTraitRef<'tcx> { } impl<'tcx> IntoDiagnosticArg for ExistentialTraitRef<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { self.to_string().into_diagnostic_arg() } } @@ -1149,7 +1149,7 @@ impl<'tcx, T> IntoDiagnosticArg for Binder<'tcx, T> where T: IntoDiagnosticArg, { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { self.value.into_diagnostic_arg() } } @@ -1359,7 +1359,7 @@ impl<'tcx> FnSig<'tcx> { } impl<'tcx> IntoDiagnosticArg for FnSig<'tcx> { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index ac147afaab313..226df08ff8f68 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -698,12 +698,15 @@ impl UnsafeOpKind { span, function: &with_no_trimmed_paths!(tcx.def_path_str(*function)), missing_target_features: DiagnosticArgValue::StrListSepByAnd( - missing.iter().map(|feature| Cow::from(feature.as_str())).collect(), + missing.iter().map(|feature| Cow::from(feature.to_string())).collect(), ), missing_target_features_count: missing.len(), note: if build_enabled.is_empty() { None } else { Some(()) }, build_target_features: DiagnosticArgValue::StrListSepByAnd( - build_enabled.iter().map(|feature| Cow::from(feature.as_str())).collect(), + build_enabled + .iter() + .map(|feature| Cow::from(feature.to_string())) + .collect(), ), build_target_features_count: build_enabled.len(), unsafe_not_inherited_note, @@ -860,12 +863,15 @@ impl UnsafeOpKind { dcx.emit_err(CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed { span, missing_target_features: DiagnosticArgValue::StrListSepByAnd( - missing.iter().map(|feature| Cow::from(feature.as_str())).collect(), + missing.iter().map(|feature| Cow::from(feature.to_string())).collect(), ), missing_target_features_count: missing.len(), note: if build_enabled.is_empty() { None } else { Some(()) }, build_target_features: DiagnosticArgValue::StrListSepByAnd( - build_enabled.iter().map(|feature| Cow::from(feature.as_str())).collect(), + build_enabled + .iter() + .map(|feature| Cow::from(feature.to_string())) + .collect(), ), build_target_features_count: build_enabled.len(), unsafe_not_inherited_note, @@ -876,12 +882,15 @@ impl UnsafeOpKind { dcx.emit_err(CallToFunctionWithRequiresUnsafe { span, missing_target_features: DiagnosticArgValue::StrListSepByAnd( - missing.iter().map(|feature| Cow::from(feature.as_str())).collect(), + missing.iter().map(|feature| Cow::from(feature.to_string())).collect(), ), missing_target_features_count: missing.len(), note: if build_enabled.is_empty() { None } else { Some(()) }, build_target_features: DiagnosticArgValue::StrListSepByAnd( - build_enabled.iter().map(|feature| Cow::from(feature.as_str())).collect(), + build_enabled + .iter() + .map(|feature| Cow::from(feature.to_string())) + .collect(), ), build_target_features_count: build_enabled.len(), unsafe_not_inherited_note, diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index 6929c8040c503..147001cabb0f3 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -127,11 +127,11 @@ pub struct UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe<'a> { #[label] pub span: Span, pub function: &'a str, - pub missing_target_features: DiagnosticArgValue<'a>, + pub missing_target_features: DiagnosticArgValue, pub missing_target_features_count: usize, #[note] pub note: Option<()>, - pub build_target_features: DiagnosticArgValue<'a>, + pub build_target_features: DiagnosticArgValue, pub build_target_features_count: usize, #[subdiagnostic] pub unsafe_not_inherited_note: Option, @@ -379,11 +379,11 @@ pub struct CallToFunctionWithRequiresUnsafe<'a> { #[label] pub span: Span, pub function: &'a str, - pub missing_target_features: DiagnosticArgValue<'a>, + pub missing_target_features: DiagnosticArgValue, pub missing_target_features_count: usize, #[note] pub note: Option<()>, - pub build_target_features: DiagnosticArgValue<'a>, + pub build_target_features: DiagnosticArgValue, pub build_target_features_count: usize, #[subdiagnostic] pub unsafe_not_inherited_note: Option, @@ -397,11 +397,11 @@ pub struct CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed<'a> { #[label] pub span: Span, pub function: &'a str, - pub missing_target_features: DiagnosticArgValue<'a>, + pub missing_target_features: DiagnosticArgValue, pub missing_target_features_count: usize, #[note] pub note: Option<()>, - pub build_target_features: DiagnosticArgValue<'a>, + pub build_target_features: DiagnosticArgValue, pub build_target_features_count: usize, #[subdiagnostic] pub unsafe_not_inherited_note: Option, diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 8b9e507c8c746..c49f92f4f859f 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -34,7 +34,7 @@ pub(crate) macro throw_machine_stop_str($($tt:tt)*) {{ fn add_args( self: Box, - _: &mut dyn FnMut(std::borrow::Cow<'static, str>, rustc_errors::DiagnosticArgValue<'static>), + _: &mut dyn FnMut(std::borrow::Cow<'static, str>, rustc_errors::DiagnosticArgValue), ) {} } throw_machine_stop!(Zst) diff --git a/compiler/rustc_mir_transform/src/errors.rs b/compiler/rustc_mir_transform/src/errors.rs index 4ef3d47d6a6f5..30de40e226c33 100644 --- a/compiler/rustc_mir_transform/src/errors.rs +++ b/compiler/rustc_mir_transform/src/errors.rs @@ -125,7 +125,7 @@ impl RequiresUnsafeDetail { diag.arg( "missing_target_features", DiagnosticArgValue::StrListSepByAnd( - missing.iter().map(|feature| Cow::from(feature.as_str())).collect(), + missing.iter().map(|feature| Cow::from(feature.to_string())).collect(), ), ); diag.arg("missing_target_features_count", missing.len()); @@ -136,7 +136,7 @@ impl RequiresUnsafeDetail { DiagnosticArgValue::StrListSepByAnd( build_enabled .iter() - .map(|feature| Cow::from(feature.as_str())) + .map(|feature| Cow::from(feature.to_string())) .collect(), ), ); diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 9d9741bbe8947..8f27d01794cc6 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -78,7 +78,7 @@ pub(crate) enum ProcMacroKind { } impl IntoDiagnosticArg for ProcMacroKind { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { match self { ProcMacroKind::Attribute => "attribute proc macro", ProcMacroKind::Derive => "derive proc macro", diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 0743ff0386402..9788fcb3c7d36 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -90,7 +90,7 @@ impl PatternSource { } impl IntoDiagnosticArg for PatternSource { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { DiagnosticArgValue::Str(Cow::Borrowed(self.descr())) } } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 2ec1a726cef1f..d35f951e2aea3 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -3092,7 +3092,7 @@ impl fmt::Display for CrateType { } impl IntoDiagnosticArg for CrateType { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 7cd76ad729388..3a0ae74dd9215 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -111,7 +111,7 @@ impl Mul for Limit { } impl rustc_errors::IntoDiagnosticArg for Limit { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue { self.to_string().into_diagnostic_arg() } } diff --git a/src/tools/miri/src/diagnostics.rs b/src/tools/miri/src/diagnostics.rs index bf3284df5967a..92c58d48dc757 100644 --- a/src/tools/miri/src/diagnostics.rs +++ b/src/tools/miri/src/diagnostics.rs @@ -104,7 +104,7 @@ impl MachineStopType for TerminationInfo { self: Box, _: &mut dyn FnMut( std::borrow::Cow<'static, str>, - rustc_errors::DiagnosticArgValue<'static>, + rustc_errors::DiagnosticArgValue, ), ) { } From 45dc19785df0cd23af30498d3e1221e5e78142dc Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 30 Jan 2024 15:44:37 +1100 Subject: [PATCH 26/29] Remove lifetimes from some diagnostics. Because the `&'a str` fields can be trivially converted to `String` without causing any extra allocations. --- .../rustc_mir_build/src/check_unsafety.rs | 12 +++++----- compiler/rustc_mir_build/src/errors.rs | 24 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 226df08ff8f68..422549755d1e1 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -605,7 +605,7 @@ impl UnsafeOpKind { span, UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafe { span, - function: &with_no_trimmed_paths!(tcx.def_path_str(*did)), + function: with_no_trimmed_paths!(tcx.def_path_str(*did)), unsafe_not_inherited_note, }, ), @@ -696,7 +696,7 @@ impl UnsafeOpKind { span, UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe { span, - function: &with_no_trimmed_paths!(tcx.def_path_str(*function)), + function: with_no_trimmed_paths!(tcx.def_path_str(*function)), missing_target_features: DiagnosticArgValue::StrListSepByAnd( missing.iter().map(|feature| Cow::from(feature.to_string())).collect(), ), @@ -750,14 +750,14 @@ impl UnsafeOpKind { dcx.emit_err(CallToUnsafeFunctionRequiresUnsafeUnsafeOpInUnsafeFnAllowed { span, unsafe_not_inherited_note, - function: &tcx.def_path_str(*did), + function: tcx.def_path_str(*did), }); } CallToUnsafeFunction(Some(did)) => { dcx.emit_err(CallToUnsafeFunctionRequiresUnsafe { span, unsafe_not_inherited_note, - function: &tcx.def_path_str(*did), + function: tcx.def_path_str(*did), }); } CallToUnsafeFunction(None) if unsafe_op_in_unsafe_fn_allowed => { @@ -875,7 +875,7 @@ impl UnsafeOpKind { ), build_target_features_count: build_enabled.len(), unsafe_not_inherited_note, - function: &tcx.def_path_str(*function), + function: tcx.def_path_str(*function), }); } CallToFunctionWith { function, missing, build_enabled } => { @@ -894,7 +894,7 @@ impl UnsafeOpKind { ), build_target_features_count: build_enabled.len(), unsafe_not_inherited_note, - function: &tcx.def_path_str(*function), + function: tcx.def_path_str(*function), }); } } diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index 147001cabb0f3..3c1ba26a50309 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -23,10 +23,10 @@ pub struct UnconditionalRecursion { #[derive(LintDiagnostic)] #[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_unsafe_fn_requires_unsafe)] #[note] -pub struct UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafe<'a> { +pub struct UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafe { #[label] pub span: Span, - pub function: &'a str, + pub function: String, #[subdiagnostic] pub unsafe_not_inherited_note: Option, } @@ -123,10 +123,10 @@ pub struct UnsafeOpInUnsafeFnBorrowOfLayoutConstrainedFieldRequiresUnsafe { #[derive(LintDiagnostic)] #[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_fn_with_requires_unsafe)] #[help] -pub struct UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe<'a> { +pub struct UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe { #[label] pub span: Span, - pub function: &'a str, + pub function: String, pub missing_target_features: DiagnosticArgValue, pub missing_target_features_count: usize, #[note] @@ -140,11 +140,11 @@ pub struct UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe<'a> { #[derive(Diagnostic)] #[diag(mir_build_call_to_unsafe_fn_requires_unsafe, code = E0133)] #[note] -pub struct CallToUnsafeFunctionRequiresUnsafe<'a> { +pub struct CallToUnsafeFunctionRequiresUnsafe { #[primary_span] #[label] pub span: Span, - pub function: &'a str, + pub function: String, #[subdiagnostic] pub unsafe_not_inherited_note: Option, } @@ -163,11 +163,11 @@ pub struct CallToUnsafeFunctionRequiresUnsafeNameless { #[derive(Diagnostic)] #[diag(mir_build_call_to_unsafe_fn_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = E0133)] #[note] -pub struct CallToUnsafeFunctionRequiresUnsafeUnsafeOpInUnsafeFnAllowed<'a> { +pub struct CallToUnsafeFunctionRequiresUnsafeUnsafeOpInUnsafeFnAllowed { #[primary_span] #[label] pub span: Span, - pub function: &'a str, + pub function: String, #[subdiagnostic] pub unsafe_not_inherited_note: Option, } @@ -374,11 +374,11 @@ pub struct BorrowOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed #[derive(Diagnostic)] #[diag(mir_build_call_to_fn_with_requires_unsafe, code = E0133)] #[help] -pub struct CallToFunctionWithRequiresUnsafe<'a> { +pub struct CallToFunctionWithRequiresUnsafe { #[primary_span] #[label] pub span: Span, - pub function: &'a str, + pub function: String, pub missing_target_features: DiagnosticArgValue, pub missing_target_features_count: usize, #[note] @@ -392,11 +392,11 @@ pub struct CallToFunctionWithRequiresUnsafe<'a> { #[derive(Diagnostic)] #[diag(mir_build_call_to_fn_with_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = E0133)] #[help] -pub struct CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed<'a> { +pub struct CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed { #[primary_span] #[label] pub span: Span, - pub function: &'a str, + pub function: String, pub missing_target_features: DiagnosticArgValue, pub missing_target_features_count: usize, #[note] From 06aa381adbd5bac561c57dc6fc0390da8ec45b69 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 30 Jan 2024 15:52:20 +1100 Subject: [PATCH 27/29] Remove `DiagnosticArgName` from `rustc_codegen_ssa`. It's identical to the one in `rustc_errors`; use that instead. Also remove some `rustc_errors::` qualifiers. --- compiler/rustc_codegen_ssa/src/back/write.rs | 17 +++++++++-------- compiler/rustc_errors/src/lib.rs | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index affd386361c09..562359a6b3976 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -14,8 +14,11 @@ use rustc_data_structures::memmap::Mmap; use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard}; use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::Emitter; -use rustc_errors::{translation::Translate, DiagCtxt, FatalError, Level}; -use rustc_errors::{DiagnosticBuilder, DiagnosticMessage, ErrCode, Style}; +use rustc_errors::translation::Translate; +use rustc_errors::{ + DiagCtxt, DiagnosticArgName, DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage, ErrCode, + FatalError, FluentBundle, Level, Style, +}; use rustc_fs_util::link_or_copy; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc_incremental::{ @@ -995,11 +998,9 @@ pub(crate) enum Message { /// process another codegen unit. pub struct CguMessage; -type DiagnosticArgName<'source> = Cow<'source, str>; - struct Diagnostic { msgs: Vec<(DiagnosticMessage, Style)>, - args: FxHashMap, rustc_errors::DiagnosticArgValue>, + args: FxHashMap, DiagnosticArgValue>, code: Option, lvl: Level, } @@ -1800,18 +1801,18 @@ impl SharedEmitter { } impl Translate for SharedEmitter { - fn fluent_bundle(&self) -> Option<&Lrc> { + fn fluent_bundle(&self) -> Option<&Lrc> { None } - fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle { + fn fallback_fluent_bundle(&self) -> &FluentBundle { panic!("shared emitter attempted to translate a diagnostic"); } } impl Emitter for SharedEmitter { fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) { - let args: FxHashMap, rustc_errors::DiagnosticArgValue> = + let args: FxHashMap, DiagnosticArgValue> = diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect(); drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic { msgs: diag.messages.clone(), diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 6d9208341a5c0..295112c7c3c42 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -33,8 +33,8 @@ extern crate self as rustc_errors; pub use codes::*; pub use diagnostic::{ - AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgValue, - DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic, + AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgName, + DiagnosticArgValue, DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic, }; pub use diagnostic_builder::{ BugAbort, DiagnosticBuilder, EmissionGuarantee, FatalAbort, IntoDiagnostic, From f0426b77fc1f4bc170ababce990c88565310eb26 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 30 Jan 2024 16:04:03 +1100 Subject: [PATCH 28/29] Remove the lifetime from `DiagnosticArgName`. Because it's always 'static. --- compiler/rustc_codegen_ssa/src/back/write.rs | 2 +- compiler/rustc_errors/src/diagnostic.rs | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 562359a6b3976..06edb79453727 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -1000,7 +1000,7 @@ pub struct CguMessage; struct Diagnostic { msgs: Vec<(DiagnosticMessage, Style)>, - args: FxHashMap, DiagnosticArgValue>, + args: FxHashMap, code: Option, lvl: Level, } diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index b3a4e1c5843dd..0ce20fda27ff5 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -23,11 +23,10 @@ pub struct SuggestionsDisabled; /// Simplified version of `FluentArg` that can implement `Encodable` and `Decodable`. Collection of /// `DiagnosticArg` are converted to `FluentArgs` (consuming the collection) at the start of /// diagnostic emission. -pub type DiagnosticArg<'iter, 'source> = - (&'iter DiagnosticArgName<'source>, &'iter DiagnosticArgValue); +pub type DiagnosticArg<'iter, 'source> = (&'iter DiagnosticArgName, &'iter DiagnosticArgValue); /// Name of a diagnostic argument. -pub type DiagnosticArgName<'source> = Cow<'source, str>; +pub type DiagnosticArgName = Cow<'static, str>; /// Simplified version of `FluentValue` that can implement `Encodable` and `Decodable`. Converted /// to a `FluentValue` by the emitter to be used in diagnostic translation. @@ -103,7 +102,7 @@ pub struct Diagnostic { pub span: MultiSpan, pub children: Vec, pub suggestions: Result, SuggestionsDisabled>, - args: FxHashMap, DiagnosticArgValue>, + args: FxHashMap, /// This is not used for highlighting or rendering any error message. Rather, it can be used /// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of @@ -923,10 +922,7 @@ impl Diagnostic { self } - pub fn replace_args( - &mut self, - args: FxHashMap, DiagnosticArgValue>, - ) { + pub fn replace_args(&mut self, args: FxHashMap) { self.args = args; } From 514a5d8d556a6e28f586551c31ad0e9c83224caf Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 30 Jan 2024 16:06:18 +1100 Subject: [PATCH 29/29] Remove the second lifetime from `DiagnosticArg`. Because it's always static. I'm surprised the compiler allowed this unused lifetime without any complaint. --- compiler/rustc_errors/src/diagnostic.rs | 4 ++-- compiler/rustc_errors/src/lib.rs | 4 ++-- compiler/rustc_errors/src/translation.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 0ce20fda27ff5..bf1ab37a1cf48 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -23,7 +23,7 @@ pub struct SuggestionsDisabled; /// Simplified version of `FluentArg` that can implement `Encodable` and `Decodable`. Collection of /// `DiagnosticArg` are converted to `FluentArgs` (consuming the collection) at the start of /// diagnostic emission. -pub type DiagnosticArg<'iter, 'source> = (&'iter DiagnosticArgName, &'iter DiagnosticArgValue); +pub type DiagnosticArg<'iter> = (&'iter DiagnosticArgName, &'iter DiagnosticArgValue); /// Name of a diagnostic argument. pub type DiagnosticArgName = Cow<'static, str>; @@ -909,7 +909,7 @@ impl Diagnostic { // Exact iteration order of diagnostic arguments shouldn't make a difference to output because // they're only used in interpolation. #[allow(rustc::potential_query_instability)] - pub fn args(&self) -> impl Iterator> { + pub fn args(&self) -> impl Iterator> { self.args.iter() } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 295112c7c3c42..9090adea1562d 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -628,7 +628,7 @@ impl DiagCtxt { pub fn eagerly_translate<'a>( &self, message: DiagnosticMessage, - args: impl Iterator>, + args: impl Iterator>, ) -> SubdiagnosticMessage { SubdiagnosticMessage::Eager(Cow::from(self.eagerly_translate_to_string(message, args))) } @@ -637,7 +637,7 @@ impl DiagCtxt { pub fn eagerly_translate_to_string<'a>( &self, message: DiagnosticMessage, - args: impl Iterator>, + args: impl Iterator>, ) -> String { let inner = self.inner.borrow(); let args = crate::translation::to_fluent_args(args); diff --git a/compiler/rustc_errors/src/translation.rs b/compiler/rustc_errors/src/translation.rs index af927bf9629a1..5bdac367d55e7 100644 --- a/compiler/rustc_errors/src/translation.rs +++ b/compiler/rustc_errors/src/translation.rs @@ -13,7 +13,7 @@ use std::error::Report; /// Typically performed once for each diagnostic at the start of `emit_diagnostic` and then /// passed around as a reference thereafter. pub fn to_fluent_args<'iter>( - iter: impl Iterator>, + iter: impl Iterator>, ) -> FluentArgs<'static> { let mut args = if let Some(size) = iter.size_hint().1 { FluentArgs::with_capacity(size)