From 97fbcf6773fa2d00675cbd7ea8dcdac1d6772072 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 19 Sep 2024 17:23:46 -0700 Subject: [PATCH 01/13] Allow reborrowing Pin<&mut Self> --- .../rustc_hir_typeck/src/method/confirm.rs | 9 ++++++ .../src/method/prelude_edition_lints.rs | 32 +++++++++++++++---- compiler/rustc_hir_typeck/src/method/probe.rs | 32 ++++++++++++++----- tests/ui/async-await/pin-reborrow-self.rs | 20 +++++++++--- 4 files changed, 74 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index e3b0fa78eb705..0d11df1133467 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -235,6 +235,15 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { target, }); } + + Some(probe::AutorefOrPtrAdjustment::ReborrowPin(mutbl)) => { + let region = self.next_region_var(infer::Autoref(self.span)); + + adjustments.push(Adjustment { + kind: Adjust::ReborrowPin(region, mutbl), + target, + }); + } None => {} } diff --git a/compiler/rustc_hir_typeck/src/method/prelude_edition_lints.rs b/compiler/rustc_hir_typeck/src/method/prelude_edition_lints.rs index a8b5b6165db06..b20592c85d285 100644 --- a/compiler/rustc_hir_typeck/src/method/prelude_edition_lints.rs +++ b/compiler/rustc_hir_typeck/src/method/prelude_edition_lints.rs @@ -121,16 +121,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { mutbl.ref_prefix_str() } Some(probe::AutorefOrPtrAdjustment::ToConstPtr) | None => "", + Some(probe::AutorefOrPtrAdjustment::ReborrowPin(mutbl)) => match mutbl { + hir::Mutability::Mut => "Pin<&mut ", + hir::Mutability::Not => "Pin<&", + }, }; if let Ok(self_expr) = self.sess().source_map().span_to_snippet(self_expr.span) { - let self_adjusted = if let Some(probe::AutorefOrPtrAdjustment::ToConstPtr) = + let mut self_adjusted = + if let Some(probe::AutorefOrPtrAdjustment::ToConstPtr) = + pick.autoref_or_ptr_adjustment + { + format!("{derefs}{self_expr} as *const _") + } else { + format!("{autoref}{derefs}{self_expr}") + }; + + if let Some(probe::AutorefOrPtrAdjustment::ReborrowPin(_)) = pick.autoref_or_ptr_adjustment { - format!("{derefs}{self_expr} as *const _") - } else { - format!("{autoref}{derefs}{self_expr}") - }; + self_adjusted.push('>'); + } lint.span_suggestion( sp, @@ -400,6 +411,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let autoref = match pick.autoref_or_ptr_adjustment { Some(probe::AutorefOrPtrAdjustment::Autoref { mutbl, .. }) => mutbl.ref_prefix_str(), Some(probe::AutorefOrPtrAdjustment::ToConstPtr) | None => "", + Some(probe::AutorefOrPtrAdjustment::ReborrowPin(mutbl)) => match mutbl { + hir::Mutability::Mut => "Pin<&mut ", + hir::Mutability::Not => "Pin<&", + }, }; let (expr_text, precise) = if let Some(expr_text) = expr @@ -412,7 +427,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ("(..)".to_string(), false) }; - let adjusted_text = if let Some(probe::AutorefOrPtrAdjustment::ToConstPtr) = + let mut adjusted_text = if let Some(probe::AutorefOrPtrAdjustment::ToConstPtr) = pick.autoref_or_ptr_adjustment { format!("{derefs}{expr_text} as *const _") @@ -420,6 +435,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { format!("{autoref}{derefs}{expr_text}") }; + if let Some(probe::AutorefOrPtrAdjustment::ReborrowPin(_)) = pick.autoref_or_ptr_adjustment + { + adjusted_text.push('>'); + } + (adjusted_text, precise) } } diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 3828b40b88570..43481c9704a72 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -136,7 +136,7 @@ enum ProbeResult { /// `mut`), or it has type `*mut T` and we convert it to `*const T`. #[derive(Debug, PartialEq, Copy, Clone)] pub(crate) enum AutorefOrPtrAdjustment { - /// Receiver has type `T`, add `&` or `&mut` (it `T` is `mut`), and maybe also "unsize" it. + /// Receiver has type `T`, add `&` or `&mut` (if `T` is `mut`), and maybe also "unsize" it. /// Unsizing is used to convert a `[T; N]` to `[T]`, which only makes sense when autorefing. Autoref { mutbl: hir::Mutability, @@ -147,6 +147,9 @@ pub(crate) enum AutorefOrPtrAdjustment { }, /// Receiver has type `*mut T`, convert to `*const T` ToConstPtr, + + /// Reborrow a `Pin<&mut T>` or `Pin<&T>`. + ReborrowPin(hir::Mutability), } impl AutorefOrPtrAdjustment { @@ -154,6 +157,7 @@ impl AutorefOrPtrAdjustment { match self { AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => *unsize, AutorefOrPtrAdjustment::ToConstPtr => false, + AutorefOrPtrAdjustment::ReborrowPin(_) => false, } } } @@ -1133,13 +1137,25 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { r.map(|mut pick| { pick.autoderefs = step.autoderefs; - // Insert a `&*` or `&mut *` if this is a reference type: - if let ty::Ref(_, _, mutbl) = *step.self_ty.value.value.kind() { - pick.autoderefs += 1; - pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref { - mutbl, - unsize: pick.autoref_or_ptr_adjustment.is_some_and(|a| a.get_unsize()), - }) + match *step.self_ty.value.value.kind() { + // Insert a `&*` or `&mut *` if this is a reference type: + ty::Ref(_, _, mutbl) => { + pick.autoderefs += 1; + pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref { + mutbl, + unsize: pick.autoref_or_ptr_adjustment.is_some_and(|a| a.get_unsize()), + }) + } + + ty::Adt(def, args) if self.tcx.is_lang_item(def.did(), hir::LangItem::Pin) => { + // make sure this is a pinned reference (and not a `Pin` or something) + if let ty::Ref(_, _, mutbl) = args[0].expect_ty().kind() { + pick.autoref_or_ptr_adjustment = + Some(AutorefOrPtrAdjustment::ReborrowPin(*mutbl)); + } + } + + _ => (), } pick diff --git a/tests/ui/async-await/pin-reborrow-self.rs b/tests/ui/async-await/pin-reborrow-self.rs index b60b6982bb879..ab36ce575e198 100644 --- a/tests/ui/async-await/pin-reborrow-self.rs +++ b/tests/ui/async-await/pin-reborrow-self.rs @@ -1,24 +1,34 @@ //@ check-pass -//@ignore-test - -// Currently ignored due to self reborrowing not being implemented for Pin #![feature(pin_ergonomics)] #![allow(incomplete_features)] use std::pin::Pin; -struct Foo; +pub struct Foo; impl Foo { fn foo(self: Pin<&mut Self>) { } + + fn baz(self: Pin<&Self>) { + } } -fn bar(x: Pin<&mut Foo>) { +pub fn bar(x: Pin<&mut Foo>) { x.foo(); x.foo(); // for this to work we need to automatically reborrow, // as if the user had written `x.as_mut().foo()`. + + Foo::baz(x); + + // FIXME: We should allow downgrading a Pin<&mut T> to Pin<&T> + // x.baz(); +} + +pub fn baaz(x: Pin<&Foo>) { + x.baz(); + x.baz(); } fn main() {} From 3dfb30c70a2a8da87eefa01a56d753d1698866c9 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 19 Sep 2024 19:35:01 -0700 Subject: [PATCH 02/13] Allow reborrowing pinned self methods --- .../rustc_hir_typeck/src/method/confirm.rs | 16 ++++-- compiler/rustc_hir_typeck/src/method/probe.rs | 49 ++++++++++++++++++- compiler/rustc_middle/src/ty/sty.rs | 10 ++++ tests/ui/async-await/pin-reborrow-self.rs | 3 +- .../feature-gate-pin_ergonomics.rs | 8 +++ .../feature-gate-pin_ergonomics.stderr | 47 ++++++++++++++++-- 6 files changed, 123 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 0d11df1133467..f955c62a443c2 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -239,10 +239,18 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { Some(probe::AutorefOrPtrAdjustment::ReborrowPin(mutbl)) => { let region = self.next_region_var(infer::Autoref(self.span)); - adjustments.push(Adjustment { - kind: Adjust::ReborrowPin(region, mutbl), - target, - }); + target = match target.kind() { + ty::Adt(pin, args) if self.tcx.is_lang_item(pin.did(), hir::LangItem::Pin) => { + let inner_ty = match args[0].expect_ty().kind() { + ty::Ref(_, ty, _) => *ty, + _ => bug!("Expected a reference type for argument to Pin"), + }; + Ty::new_pinned_ref(self.tcx, region, inner_ty, mutbl) + } + _ => bug!("Cannot adjust receiver type for reborrowing pin of {target:?}"), + }; + + adjustments.push(Adjustment { kind: Adjust::ReborrowPin(region, mutbl), target }); } None => {} } diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 43481c9704a72..86584860b7925 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1113,6 +1113,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { unstable_candidates.as_deref_mut(), ) }) + .or_else(|| { + self.pick_reborrow_pin_method( + step, + self_ty, + unstable_candidates.as_deref_mut(), + ) + }) }) }) } @@ -1147,7 +1154,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { }) } - ty::Adt(def, args) if self.tcx.is_lang_item(def.did(), hir::LangItem::Pin) => { + ty::Adt(def, args) + if self.tcx.features().pin_ergonomics + && self.tcx.is_lang_item(def.did(), hir::LangItem::Pin) => + { // make sure this is a pinned reference (and not a `Pin` or something) if let ty::Ref(_, _, mutbl) = args[0].expect_ty().kind() { pick.autoref_or_ptr_adjustment = @@ -1186,6 +1196,43 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { }) } + /// Looks for applicable methods if we reborrow a `Pin<&mut T>` as a `Pin<&T>`. + #[instrument(level = "debug", skip(self, step, unstable_candidates))] + fn pick_reborrow_pin_method( + &self, + step: &CandidateStep<'tcx>, + self_ty: Ty<'tcx>, + unstable_candidates: Option<&mut Vec<(Candidate<'tcx>, Symbol)>>, + ) -> Option> { + if !self.tcx.features().pin_ergonomics { + return None; + } + + // make sure self is a Pin<&mut T> + let inner_ty = match self_ty.kind() { + ty::Adt(def, args) if self.tcx.is_lang_item(def.did(), hir::LangItem::Pin) => { + match args[0].expect_ty().kind() { + ty::Ref(_, ty, hir::Mutability::Mut) => *ty, + _ => { + return None; + } + } + } + _ => return None, + }; + + let region = self.tcx.lifetimes.re_erased; + let autopin_ty = Ty::new_pinned_ref(self.tcx, region, inner_ty, hir::Mutability::Not); + self.pick_method(autopin_ty, unstable_candidates).map(|r| { + r.map(|mut pick| { + pick.autoderefs = step.autoderefs; + pick.autoref_or_ptr_adjustment = + Some(AutorefOrPtrAdjustment::ReborrowPin(hir::Mutability::Not)); + pick + }) + }) + } + /// If `self_ty` is `*mut T` then this picks `*const T` methods. The reason why we have a /// special case for this is because going from `*mut T` to `*const T` with autoderefs and /// autorefs would require dereferencing the pointer, which is not safe. diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index db9978a7f5334..fc4fb91728329 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -584,6 +584,16 @@ impl<'tcx> Ty<'tcx> { Ty::new_ref(tcx, r, ty, hir::Mutability::Not) } + pub fn new_pinned_ref( + tcx: TyCtxt<'tcx>, + r: Region<'tcx>, + ty: Ty<'tcx>, + mutbl: ty::Mutability, + ) -> Ty<'tcx> { + let pin = tcx.adt_def(tcx.require_lang_item(LangItem::Pin, None)); + Ty::new_adt(tcx, pin, tcx.mk_args(&[Ty::new_ref(tcx, r, ty, mutbl).into()])) + } + #[inline] pub fn new_ptr(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, mutbl: ty::Mutability) -> Ty<'tcx> { Ty::new(tcx, ty::RawPtr(ty, mutbl)) diff --git a/tests/ui/async-await/pin-reborrow-self.rs b/tests/ui/async-await/pin-reborrow-self.rs index ab36ce575e198..ee617617da069 100644 --- a/tests/ui/async-await/pin-reborrow-self.rs +++ b/tests/ui/async-await/pin-reborrow-self.rs @@ -22,8 +22,7 @@ pub fn bar(x: Pin<&mut Foo>) { Foo::baz(x); - // FIXME: We should allow downgrading a Pin<&mut T> to Pin<&T> - // x.baz(); + x.baz(); } pub fn baaz(x: Pin<&Foo>) { diff --git a/tests/ui/feature-gates/feature-gate-pin_ergonomics.rs b/tests/ui/feature-gates/feature-gate-pin_ergonomics.rs index d694531d53abe..d56a046fd62ee 100644 --- a/tests/ui/feature-gates/feature-gate-pin_ergonomics.rs +++ b/tests/ui/feature-gates/feature-gate-pin_ergonomics.rs @@ -4,12 +4,20 @@ use std::pin::Pin; struct Foo; +impl Foo { + fn foo(self: Pin<&mut Self>) { + } +} + fn foo(_: Pin<&mut Foo>) { } fn bar(mut x: Pin<&mut Foo>) { foo(x); foo(x); //~ ERROR use of moved value: `x` + + x.foo(); //~ ERROR use of moved value: `x` + x.foo(); //~ ERROR use of moved value: `x` } fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-pin_ergonomics.stderr b/tests/ui/feature-gates/feature-gate-pin_ergonomics.stderr index 6c9029d817674..bc49088f3d783 100644 --- a/tests/ui/feature-gates/feature-gate-pin_ergonomics.stderr +++ b/tests/ui/feature-gates/feature-gate-pin_ergonomics.stderr @@ -1,5 +1,5 @@ error[E0382]: use of moved value: `x` - --> $DIR/feature-gate-pin_ergonomics.rs:12:9 + --> $DIR/feature-gate-pin_ergonomics.rs:17:9 | LL | fn bar(mut x: Pin<&mut Foo>) { | ----- move occurs because `x` has type `Pin<&mut Foo>`, which does not implement the `Copy` trait @@ -9,13 +9,54 @@ LL | foo(x); | ^ value used here after move | note: consider changing this parameter type in function `foo` to borrow instead if owning the value isn't necessary - --> $DIR/feature-gate-pin_ergonomics.rs:7:11 + --> $DIR/feature-gate-pin_ergonomics.rs:12:11 | LL | fn foo(_: Pin<&mut Foo>) { | --- ^^^^^^^^^^^^^ this parameter takes ownership of the value | | | in this function -error: aborting due to 1 previous error +error[E0382]: use of moved value: `x` + --> $DIR/feature-gate-pin_ergonomics.rs:19:5 + | +LL | fn bar(mut x: Pin<&mut Foo>) { + | ----- move occurs because `x` has type `Pin<&mut Foo>`, which does not implement the `Copy` trait +LL | foo(x); +LL | foo(x); + | - value moved here +LL | +LL | x.foo(); + | ^ value used here after move + | +note: consider changing this parameter type in function `foo` to borrow instead if owning the value isn't necessary + --> $DIR/feature-gate-pin_ergonomics.rs:12:11 + | +LL | fn foo(_: Pin<&mut Foo>) { + | --- ^^^^^^^^^^^^^ this parameter takes ownership of the value + | | + | in this function + +error[E0382]: use of moved value: `x` + --> $DIR/feature-gate-pin_ergonomics.rs:20:5 + | +LL | fn bar(mut x: Pin<&mut Foo>) { + | ----- move occurs because `x` has type `Pin<&mut Foo>`, which does not implement the `Copy` trait +... +LL | x.foo(); + | ----- `x` moved due to this method call +LL | x.foo(); + | ^ value used here after move + | +note: `Foo::foo` takes ownership of the receiver `self`, which moves `x` + --> $DIR/feature-gate-pin_ergonomics.rs:8:12 + | +LL | fn foo(self: Pin<&mut Self>) { + | ^^^^ +help: consider reborrowing the `Pin` instead of moving it + | +LL | x.as_mut().foo(); + | +++++++++ + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0382`. From 30ff4006e136123645b9fcca511b13652b8a5f98 Mon Sep 17 00:00:00 2001 From: Slanterns Date: Wed, 2 Oct 2024 01:27:11 +0800 Subject: [PATCH 03/13] update `Literal`'s intro --- library/proc_macro/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 5522d556a5975..72b597a8083ba 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -1166,7 +1166,7 @@ impl fmt::Debug for Ident { } } -/// A literal string (`"hello"`), byte string (`b"hello"`), +/// A literal string (`"hello"`), byte string (`b"hello"`), C string (`c"hello"`), /// character (`'a'`), byte character (`b'a'`), an integer or floating point number /// with or without a suffix (`1`, `1u8`, `2.3`, `2.3f32`). /// Boolean literals like `true` and `false` do not belong here, they are `Ident`s. From 9b52fb555835224e085170b67857a250dd6f176b Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Tue, 1 Oct 2024 12:44:10 -0700 Subject: [PATCH 04/13] Split out method receivers in feature gate test --- .../feature-gate-pin_ergonomics.rs | 4 ++- .../feature-gate-pin_ergonomics.stderr | 27 +++---------------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/tests/ui/feature-gates/feature-gate-pin_ergonomics.rs b/tests/ui/feature-gates/feature-gate-pin_ergonomics.rs index d56a046fd62ee..3382504af9d61 100644 --- a/tests/ui/feature-gates/feature-gate-pin_ergonomics.rs +++ b/tests/ui/feature-gates/feature-gate-pin_ergonomics.rs @@ -15,8 +15,10 @@ fn foo(_: Pin<&mut Foo>) { fn bar(mut x: Pin<&mut Foo>) { foo(x); foo(x); //~ ERROR use of moved value: `x` +} - x.foo(); //~ ERROR use of moved value: `x` +fn baz(mut x: Pin<&mut Foo>) { + x.foo(); x.foo(); //~ ERROR use of moved value: `x` } diff --git a/tests/ui/feature-gates/feature-gate-pin_ergonomics.stderr b/tests/ui/feature-gates/feature-gate-pin_ergonomics.stderr index bc49088f3d783..430b78662414a 100644 --- a/tests/ui/feature-gates/feature-gate-pin_ergonomics.stderr +++ b/tests/ui/feature-gates/feature-gate-pin_ergonomics.stderr @@ -17,31 +17,10 @@ LL | fn foo(_: Pin<&mut Foo>) { | in this function error[E0382]: use of moved value: `x` - --> $DIR/feature-gate-pin_ergonomics.rs:19:5 + --> $DIR/feature-gate-pin_ergonomics.rs:22:5 | -LL | fn bar(mut x: Pin<&mut Foo>) { - | ----- move occurs because `x` has type `Pin<&mut Foo>`, which does not implement the `Copy` trait -LL | foo(x); -LL | foo(x); - | - value moved here -LL | -LL | x.foo(); - | ^ value used here after move - | -note: consider changing this parameter type in function `foo` to borrow instead if owning the value isn't necessary - --> $DIR/feature-gate-pin_ergonomics.rs:12:11 - | -LL | fn foo(_: Pin<&mut Foo>) { - | --- ^^^^^^^^^^^^^ this parameter takes ownership of the value - | | - | in this function - -error[E0382]: use of moved value: `x` - --> $DIR/feature-gate-pin_ergonomics.rs:20:5 - | -LL | fn bar(mut x: Pin<&mut Foo>) { +LL | fn baz(mut x: Pin<&mut Foo>) { | ----- move occurs because `x` has type `Pin<&mut Foo>`, which does not implement the `Copy` trait -... LL | x.foo(); | ----- `x` moved due to this method call LL | x.foo(); @@ -57,6 +36,6 @@ help: consider reborrowing the `Pin` instead of moving it LL | x.as_mut().foo(); | +++++++++ -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0382`. From 0dc250c4973d92cc92e534edeb05674218144d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20S=C3=A1nchez=20Mu=C3=B1oz?= Date: Sun, 15 Sep 2024 18:31:58 +0200 Subject: [PATCH 05/13] Stabilize `const_slice_from_raw_parts_mut` --- library/alloc/tests/lib.rs | 1 - library/core/src/lib.rs | 1 - library/core/src/ptr/mod.rs | 2 +- library/core/src/ptr/non_null.rs | 5 ++++- library/core/src/slice/raw.rs | 3 ++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs index 1d07a7690da43..58d39416d9577 100644 --- a/library/alloc/tests/lib.rs +++ b/library/alloc/tests/lib.rs @@ -7,7 +7,6 @@ #![feature(const_cow_is_borrowed)] #![feature(const_heap)] #![cfg_attr(bootstrap, feature(const_mut_refs))] -#![feature(const_slice_from_raw_parts_mut)] #![feature(const_ptr_write)] #![feature(const_try)] #![feature(core_intrinsics)] diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 817d9e3b962e3..b5bc985519187 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -147,7 +147,6 @@ #![feature(const_replace)] #![feature(const_size_of_val)] #![feature(const_size_of_val_raw)] -#![feature(const_slice_from_raw_parts_mut)] #![feature(const_slice_from_ref)] #![feature(const_slice_split_at_mut)] #![feature(const_str_as_mut)] diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index b6df780fe2f4a..205b25f2d1a5d 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -992,7 +992,7 @@ pub const fn slice_from_raw_parts(data: *const T, len: usize) -> *const [T] { /// ``` #[inline] #[stable(feature = "slice_from_raw_parts", since = "1.42.0")] -#[rustc_const_unstable(feature = "const_slice_from_raw_parts_mut", issue = "67456")] +#[rustc_const_stable(feature = "const_slice_from_raw_parts_mut", since = "CURRENT_RUSTC_VERSION")] #[rustc_diagnostic_item = "ptr_slice_from_raw_parts_mut"] pub const fn slice_from_raw_parts_mut(data: *mut T, len: usize) -> *mut [T] { from_raw_parts_mut(data, len) diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index e7a265f7e2b7d..da2404e25f389 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1433,7 +1433,10 @@ impl NonNull<[T]> { /// (Note that this example artificially demonstrates a use of this method, /// but `let slice = NonNull::from(&x[..]);` would be a better way to write code like this.) #[stable(feature = "nonnull_slice_from_raw_parts", since = "1.70.0")] - #[rustc_const_unstable(feature = "const_slice_from_raw_parts_mut", issue = "67456")] + #[rustc_const_stable( + feature = "const_slice_from_raw_parts_mut", + since = "CURRENT_RUSTC_VERSION" + )] #[must_use] #[inline] pub const fn slice_from_raw_parts(data: NonNull, len: usize) -> Self { diff --git a/library/core/src/slice/raw.rs b/library/core/src/slice/raw.rs index 2cf3fecb47542..84e916b9a84e7 100644 --- a/library/core/src/slice/raw.rs +++ b/library/core/src/slice/raw.rs @@ -171,7 +171,8 @@ pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] /// [`NonNull::dangling()`]: ptr::NonNull::dangling #[inline] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_slice_from_raw_parts_mut", issue = "67456")] +#[rustc_const_stable(feature = "const_slice_from_raw_parts_mut", since = "CURRENT_RUSTC_VERSION")] +#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))] #[must_use] #[rustc_diagnostic_item = "slice_from_raw_parts_mut"] pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T] { From 8918a9d265c38945fe442a8fcec71995f6e52b5a Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Thu, 3 Oct 2024 13:15:48 +0200 Subject: [PATCH 06/13] Fix needless_lifetimes in stable_mir --- compiler/stable_mir/src/mir/visit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/stable_mir/src/mir/visit.rs b/compiler/stable_mir/src/mir/visit.rs index aeae866e9d344..e2d1ff7fdd3a4 100644 --- a/compiler/stable_mir/src/mir/visit.rs +++ b/compiler/stable_mir/src/mir/visit.rs @@ -76,9 +76,9 @@ pub trait MirVisitor { self.super_place(place, ptx, location) } - fn visit_projection_elem<'a>( + fn visit_projection_elem( &mut self, - place_ref: PlaceRef<'a>, + place_ref: PlaceRef<'_>, elem: &ProjectionElem, ptx: PlaceContext, location: Location, From 3686e59913967072e47d64a6a466a6f5d9386c09 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 4 Oct 2024 09:45:34 -0700 Subject: [PATCH 07/13] rustdoc: cleaner errors on disambiguator/namespace mismatches --- .../passes/collect_intra_doc_links.rs | 21 ++++++++++++++----- .../intra-doc/disambiguator-mismatch.stderr | 6 +++--- tests/rustdoc-ui/intra-doc/errors.rs | 2 +- tests/rustdoc-ui/intra-doc/errors.stderr | 4 ++-- .../issue-110495-suffix-with-space.stderr | 4 ++-- .../rustdoc-ui/intra-doc/weird-syntax.stderr | 20 +++++++++--------- 6 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 0dba16cbaf32f..def9ac3ce4b5a 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -1996,11 +1996,22 @@ fn resolution_failure( &diag_info, ); - format!( - "this link resolves to {}, which is not in the {} namespace", - item(res), - expected_ns.descr() - ) + if let Some(disambiguator) = disambiguator + && !matches!(disambiguator, Disambiguator::Namespace(..)) + { + format!( + "this link resolves to {}, which is not {} {}", + item(res), + disambiguator.article(), + disambiguator.descr() + ) + } else { + format!( + "this link resolves to {}, which is not in the {} namespace", + item(res), + expected_ns.descr() + ) + } } }; if let Some(span) = sp { diff --git a/tests/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr b/tests/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr index 66b910eed8135..ef7fec77b1e0d 100644 --- a/tests/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr +++ b/tests/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr @@ -74,7 +74,7 @@ error: unresolved link to `m` --> $DIR/disambiguator-mismatch.rs:52:14 | LL | /// Link to [m()] - | ^^^ this link resolves to the macro `m`, which is not in the value namespace + | ^^^ this link resolves to the macro `m`, which is not a function | help: to link to the macro, add an exclamation mark | @@ -142,7 +142,7 @@ error: unresolved link to `std` --> $DIR/disambiguator-mismatch.rs:83:14 | LL | /// Link to [fn@std] - | ^^^^^^ this link resolves to the crate `std`, which is not in the value namespace + | ^^^^^^ this link resolves to the crate `std`, which is not a function | help: to link to the crate, prefix with `mod@` | @@ -164,7 +164,7 @@ error: unresolved link to `S::A` --> $DIR/disambiguator-mismatch.rs:93:14 | LL | /// Link to [field@S::A] - | ^^^^^^^^^^ this link resolves to the variant `A`, which is not in the value namespace + | ^^^^^^^^^^ this link resolves to the variant `A`, which is not a field | help: to link to the variant, prefix with `variant@` | diff --git a/tests/rustdoc-ui/intra-doc/errors.rs b/tests/rustdoc-ui/intra-doc/errors.rs index f37f49c24ccc5..e885a3b35f6c7 100644 --- a/tests/rustdoc-ui/intra-doc/errors.rs +++ b/tests/rustdoc-ui/intra-doc/errors.rs @@ -98,7 +98,7 @@ pub trait T { /// [m()] //~^ ERROR unresolved link //~| HELP to link to the macro -//~| NOTE not in the value namespace +//~| NOTE not a function #[macro_export] macro_rules! m { () => {}; diff --git a/tests/rustdoc-ui/intra-doc/errors.stderr b/tests/rustdoc-ui/intra-doc/errors.stderr index a982bba009591..07d328f99a308 100644 --- a/tests/rustdoc-ui/intra-doc/errors.stderr +++ b/tests/rustdoc-ui/intra-doc/errors.stderr @@ -104,7 +104,7 @@ error: unresolved link to `S` --> $DIR/errors.rs:68:6 | LL | /// [S!] - | ^^ this link resolves to the struct `S`, which is not in the macro namespace + | ^^ this link resolves to the struct `S`, which is not a macro | help: to link to the struct, prefix with `struct@` | @@ -158,7 +158,7 @@ error: unresolved link to `m` --> $DIR/errors.rs:98:6 | LL | /// [m()] - | ^^^ this link resolves to the macro `m`, which is not in the value namespace + | ^^^ this link resolves to the macro `m`, which is not a function | help: to link to the macro, add an exclamation mark | diff --git a/tests/rustdoc-ui/intra-doc/issue-110495-suffix-with-space.stderr b/tests/rustdoc-ui/intra-doc/issue-110495-suffix-with-space.stderr index 6c834fd0a1b61..a347044bfe979 100644 --- a/tests/rustdoc-ui/intra-doc/issue-110495-suffix-with-space.stderr +++ b/tests/rustdoc-ui/intra-doc/issue-110495-suffix-with-space.stderr @@ -2,7 +2,7 @@ error: unresolved link to `Clone` --> $DIR/issue-110495-suffix-with-space.rs:3:6 | LL | //! [Clone ()]. - | ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace + | ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function | note: the lint level is defined here --> $DIR/issue-110495-suffix-with-space.rs:2:9 @@ -31,7 +31,7 @@ error: unresolved link to `Clone` --> $DIR/issue-110495-suffix-with-space.rs:5:7 | LL | //! [`Clone ()`]. - | ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace + | ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function | help: to link to the trait, prefix with `trait@` | diff --git a/tests/rustdoc-ui/intra-doc/weird-syntax.stderr b/tests/rustdoc-ui/intra-doc/weird-syntax.stderr index f50feb57fccf2..17bcbc783fd9e 100644 --- a/tests/rustdoc-ui/intra-doc/weird-syntax.stderr +++ b/tests/rustdoc-ui/intra-doc/weird-syntax.stderr @@ -40,7 +40,7 @@ error: unresolved link to `Clone` --> $DIR/weird-syntax.rs:27:9 | LL | /// [ `Clone ()` ] - | ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace + | ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function | help: to link to the trait, prefix with `trait@` | @@ -52,7 +52,7 @@ error: unresolved link to `Clone` --> $DIR/weird-syntax.rs:30:7 | LL | /// [`Clone ()` ] - | ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace + | ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function | help: to link to the trait, prefix with `trait@` | @@ -64,7 +64,7 @@ error: unresolved link to `Clone` --> $DIR/weird-syntax.rs:33:9 | LL | /// [ `Clone ()`] - | ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace + | ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function | help: to link to the trait, prefix with `trait@` | @@ -76,7 +76,7 @@ error: unresolved link to `Clone` --> $DIR/weird-syntax.rs:36:9 | LL | /// [```Clone ()```] - | ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace + | ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function | help: to link to the trait, prefix with `trait@` | @@ -88,7 +88,7 @@ error: unresolved link to `Clone` --> $DIR/weird-syntax.rs:42:13 | LL | /// [ ``` Clone () ``` ] - | ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace + | ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function | help: to link to the trait, prefix with `trait@` | @@ -122,7 +122,7 @@ error: unresolved link to `Clone` --> $DIR/weird-syntax.rs:74:9 | LL | /// [x][Clone()] - | ^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace + | ^^^^^^^ this link resolves to the trait `Clone`, which is not a function | help: to link to the trait, prefix with `trait@` | @@ -134,7 +134,7 @@ error: unresolved link to `Clone` --> $DIR/weird-syntax.rs:77:9 | LL | /// [x][Clone ()] - | ^^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace + | ^^^^^^^^^ this link resolves to the trait `Clone`, which is not a function | help: to link to the trait, prefix with `trait@` | @@ -176,7 +176,7 @@ error: unresolved link to `Clone` --> $DIR/weird-syntax.rs:97:9 | LL | /// [w](Clone\(\)) - | ^^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace + | ^^^^^^^^^ this link resolves to the trait `Clone`, which is not a function | help: to link to the trait, prefix with `trait@` | @@ -188,7 +188,7 @@ error: unresolved link to `Clone` --> $DIR/weird-syntax.rs:103:9 | LL | /// [w](Clone()) - | ^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace + | ^^^^^^^ this link resolves to the trait `Clone`, which is not a function | help: to link to the trait, prefix with `trait@` | @@ -256,7 +256,7 @@ error: unresolved link to `Clone` --> $DIR/weird-syntax.rs:132:9 | LL | /// The [cln][] link here will produce a plain text suggestion - | ^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace + | ^^^^^ this link resolves to the trait `Clone`, which is not a function | = help: to link to the trait, prefix with `trait@`: trait@Clone From e08002f6d0bfcea06357137dd52ee2c163757154 Mon Sep 17 00:00:00 2001 From: okaneco <47607823+okaneco@users.noreply.github.com> Date: Fri, 4 Oct 2024 14:56:15 -0400 Subject: [PATCH 08/13] Stabilize `BufRead::skip_until` --- library/std/src/io/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index dd6458c38c6e9..8fedcb241d095 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -2382,8 +2382,6 @@ pub trait BufRead: Read { /// about Ferris from a binary string, skipping the fun fact: /// /// ``` - /// #![feature(bufread_skip_until)] - /// /// use std::io::{self, BufRead}; /// /// let mut cursor = io::Cursor::new(b"Ferris\0Likes long walks on the beach\0Crustacean\0"); @@ -2407,7 +2405,7 @@ pub trait BufRead: Read { /// assert_eq!(num_bytes, 11); /// assert_eq!(animal, b"Crustacean\0"); /// ``` - #[unstable(feature = "bufread_skip_until", issue = "111735")] + #[stable(feature = "bufread_skip_until", since = "CURRENT_RUSTC_VERSION")] fn skip_until(&mut self, byte: u8) -> Result { skip_until(self, byte) } From ae5f58d906e755bff56dd9667c1d8b13ca236286 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 14 Sep 2024 15:43:03 -0400 Subject: [PATCH 09/13] Check elaborated projections from dyn don't mention unconstrained late bound lifetimes --- .../src/hir_ty_lowering/dyn_compatibility.rs | 50 +++++++++++++++++++ ...ted-predicates-unconstrained-late-bound.rs | 24 +++++++++ ...predicates-unconstrained-late-bound.stderr | 9 ++++ tests/ui/traits/object/pretty.rs | 4 +- tests/ui/traits/object/pretty.stderr | 13 +---- 5 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.rs create mode 100644 tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.stderr diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs index e7b8e6e69b0c6..f8ae9adebe3d4 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs @@ -174,6 +174,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { // Include projections defined on supertraits. projection_bounds.push((pred, span)); } + + self.check_elaborated_projection_mentions_input_lifetimes(pred, span); } _ => (), } @@ -360,6 +362,54 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { Ty::new_dynamic(tcx, existential_predicates, region_bound, representation) } + + /// Check that elaborating the principal of a trait ref doesn't lead to projections + /// that are unconstrained. This can happen because an otherwise unconstrained + /// *type variable* can be substituted with a type that has late-bound regions. See + /// `elaborated-predicates-unconstrained-late-bound.rs` for a test. + fn check_elaborated_projection_mentions_input_lifetimes( + &self, + pred: ty::PolyProjectionPredicate<'tcx>, + span: Span, + ) { + let tcx = self.tcx(); + + // Find any late-bound regions declared in `ty` that are not + // declared in the trait-ref or assoc_item. These are not well-formed. + // + // Example: + // + // for<'a> ::Item = &'a str // <-- 'a is bad + // for<'a> >::Output = &'a str // <-- 'a is ok + let late_bound_in_projection_term = + tcx.collect_constrained_late_bound_regions(pred.map_bound(|pred| pred.projection_term)); + let late_bound_in_term = + tcx.collect_referenced_late_bound_regions(pred.map_bound(|pred| pred.term)); + debug!(?late_bound_in_projection_term); + debug!(?late_bound_in_term); + + // FIXME: point at the type params that don't have appropriate lifetimes: + // struct S1 Fn(&i32, &i32) -> &'a i32>(F); + // ---- ---- ^^^^^^^ + // NOTE(associated_const_equality): This error should be impossible to trigger + // with associated const equality constraints. + self.validate_late_bound_regions( + late_bound_in_projection_term, + late_bound_in_term, + |br_name| { + let item_name = tcx.item_name(pred.projection_def_id()); + struct_span_code_err!( + self.dcx(), + span, + E0582, + "binding for associated type `{}` references {}, \ + which does not appear in the trait input types", + item_name, + br_name + ) + }, + ); + } } fn replace_dummy_self_with_error<'tcx, T: TypeFoldable>>( diff --git a/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.rs b/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.rs new file mode 100644 index 0000000000000..b174776c596ee --- /dev/null +++ b/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.rs @@ -0,0 +1,24 @@ +// Make sure that when elaborating the principal of a dyn trait for projection predicates +// we don't end up in a situation where we have an unconstrained late-bound lifetime in +// the output of a projection. + +// Fix for . + +trait A: B {} + +trait B { + type T; +} + +struct Erase(T::T); + +fn main() { + let x = { + let x = String::from("hello"); + + Erase:: A<&'a _>>(x.as_str()) + //~^ ERROR binding for associated type `T` references lifetime `'a`, which does not appear in the trait input types + }; + + dbg!(x.0); +} diff --git a/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.stderr b/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.stderr new file mode 100644 index 0000000000000..bb3cc4b3fd786 --- /dev/null +++ b/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.stderr @@ -0,0 +1,9 @@ +error[E0582]: binding for associated type `T` references lifetime `'a`, which does not appear in the trait input types + --> $DIR/elaborated-predicates-unconstrained-late-bound.rs:19:21 + | +LL | Erase:: A<&'a _>>(x.as_str()) + | ^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0582`. diff --git a/tests/ui/traits/object/pretty.rs b/tests/ui/traits/object/pretty.rs index 6660ff040f753..603d7af526002 100644 --- a/tests/ui/traits/object/pretty.rs +++ b/tests/ui/traits/object/pretty.rs @@ -13,7 +13,7 @@ trait SuperGeneric<'a> { } trait AnyGeneric<'a>: SuperGeneric<'a> {} trait FixedGeneric1<'a>: SuperGeneric<'a, Assoc2 = &'a u8> {} -trait FixedGeneric2<'a>: Super {} +// trait FixedGeneric2<'a>: Super {} // Unsound! trait FixedHrtb: for<'a> SuperGeneric<'a, Assoc2 = &'a u8> {} trait AnyDifferentBinders: for<'a> SuperGeneric<'a, Assoc2 = &'a u8> + Super {} trait FixedDifferentBinders: for<'a> SuperGeneric<'a, Assoc2 = &'a u8> + Super {} @@ -32,7 +32,7 @@ fn dyn_fixed_static(x: &dyn FixedStatic) { x } //~ERROR mismatched types fn dyn_super_generic(x: &dyn for<'a> SuperGeneric<'a, Assoc2 = &'a u8>) { x } //~ERROR mismatched types fn dyn_any_generic(x: &dyn for<'a> AnyGeneric<'a, Assoc2 = &'a u8>) { x } //~ERROR mismatched types fn dyn_fixed_generic1(x: &dyn for<'a> FixedGeneric1<'a>) { x } //~ERROR mismatched types -fn dyn_fixed_generic2(x: &dyn for<'a> FixedGeneric2<'a>) { x } //~ERROR mismatched types +// fn dyn_fixed_generic2(x: &dyn for<'a> FixedGeneric2<'a>) { x } // Unsound! fn dyn_fixed_generic_multi(x: &dyn for<'a> FixedGeneric1<'a, Assoc2 = &u8>) { x } //~ERROR mismatched types fn dyn_fixed_hrtb(x: &dyn FixedHrtb) { x } //~ERROR mismatched types fn dyn_any_different_binders(x: &dyn AnyDifferentBinders) { x } //~ERROR mismatched types diff --git a/tests/ui/traits/object/pretty.stderr b/tests/ui/traits/object/pretty.stderr index ca56bdbb67a56..af941e69c5f84 100644 --- a/tests/ui/traits/object/pretty.stderr +++ b/tests/ui/traits/object/pretty.stderr @@ -106,17 +106,6 @@ LL | fn dyn_fixed_generic1(x: &dyn for<'a> FixedGeneric1<'a>) { x } = note: expected unit type `()` found reference `&dyn for<'a> FixedGeneric1<'a>` -error[E0308]: mismatched types - --> $DIR/pretty.rs:35:60 - | -LL | fn dyn_fixed_generic2(x: &dyn for<'a> FixedGeneric2<'a>) { x } - | - ^ expected `()`, found `&dyn FixedGeneric2<'a>` - | | - | help: try adding a return type: `-> &dyn for<'a> FixedGeneric2<'a>` - | - = note: expected unit type `()` - found reference `&dyn for<'a> FixedGeneric2<'a>` - error[E0308]: mismatched types --> $DIR/pretty.rs:36:79 | @@ -172,6 +161,6 @@ LL | fn dyn_has_gat(x: &dyn HasGat = ()>) { x } = note: expected unit type `()` found reference `&dyn HasGat = ()>` -error: aborting due to 15 previous errors; 1 warning emitted +error: aborting due to 14 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0308`. From fd7ee484f9da99120116dc560452dd551d4c6496 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 14 Sep 2024 15:55:16 -0400 Subject: [PATCH 10/13] Elaborate supertrait span correctly to label the error better --- .../src/hir_ty_lowering/dyn_compatibility.rs | 20 +++++++--- compiler/rustc_middle/src/ty/predicate.rs | 4 ++ compiler/rustc_type_ir/src/elaborate.rs | 40 +++++++++++++++++++ compiler/rustc_type_ir/src/inherent.rs | 2 + ...predicates-unconstrained-late-bound.stderr | 3 ++ 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs index f8ae9adebe3d4..394a263fbb595 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs @@ -13,6 +13,7 @@ use rustc_middle::ty::{ use rustc_span::{ErrorGuaranteed, Span}; use rustc_trait_selection::error_reporting::traits::report_dyn_incompatibility; use rustc_trait_selection::traits::{self, hir_ty_lowering_dyn_compatibility_violations}; +use rustc_type_ir::elaborate::ClauseWithSupertraitSpan; use smallvec::{SmallVec, smallvec}; use tracing::{debug, instrument}; @@ -124,16 +125,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { .into_iter() .filter(|(trait_ref, _)| !tcx.trait_is_auto(trait_ref.def_id())); - for (base_trait_ref, span) in regular_traits_refs_spans { + for (base_trait_ref, original_span) in regular_traits_refs_spans { let base_pred: ty::Predicate<'tcx> = base_trait_ref.upcast(tcx); - for pred in traits::elaborate(tcx, [base_pred]).filter_only_self() { + for ClauseWithSupertraitSpan { pred, original_span, supertrait_span } in + traits::elaborate(tcx, [ClauseWithSupertraitSpan::new(base_pred, original_span)]) + .filter_only_self() + { debug!("observing object predicate `{pred:?}`"); let bound_predicate = pred.kind(); match bound_predicate.skip_binder() { ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => { let pred = bound_predicate.rebind(pred); - associated_types.entry(span).or_default().extend( + associated_types.entry(original_span).or_default().extend( tcx.associated_items(pred.def_id()) .in_definition_order() .filter(|item| item.kind == ty::AssocKind::Type) @@ -172,10 +176,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { // the discussion in #56288 for alternatives. if !references_self { // Include projections defined on supertraits. - projection_bounds.push((pred, span)); + projection_bounds.push((pred, original_span)); } - self.check_elaborated_projection_mentions_input_lifetimes(pred, span); + self.check_elaborated_projection_mentions_input_lifetimes( + pred, + original_span, + supertrait_span, + ); } _ => (), } @@ -371,6 +379,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { &self, pred: ty::PolyProjectionPredicate<'tcx>, span: Span, + supertrait_span: Span, ) { let tcx = self.tcx(); @@ -407,6 +416,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { item_name, br_name ) + .with_span_label(supertrait_span, "due to this supertrait") }, ); } diff --git a/compiler/rustc_middle/src/ty/predicate.rs b/compiler/rustc_middle/src/ty/predicate.rs index fd4e8f1cd4e71..d20cb368278b3 100644 --- a/compiler/rustc_middle/src/ty/predicate.rs +++ b/compiler/rustc_middle/src/ty/predicate.rs @@ -179,6 +179,10 @@ pub struct Clause<'tcx>( ); impl<'tcx> rustc_type_ir::inherent::Clause> for Clause<'tcx> { + fn as_predicate(self) -> Predicate<'tcx> { + self.as_predicate() + } + fn instantiate_supertrait(self, tcx: TyCtxt<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>) -> Self { self.instantiate_supertrait(tcx, trait_ref) } diff --git a/compiler/rustc_type_ir/src/elaborate.rs b/compiler/rustc_type_ir/src/elaborate.rs index 61736633cfa28..dac45ff2aba3f 100644 --- a/compiler/rustc_type_ir/src/elaborate.rs +++ b/compiler/rustc_type_ir/src/elaborate.rs @@ -44,6 +44,46 @@ pub trait Elaboratable { ) -> Self; } +pub struct ClauseWithSupertraitSpan { + pub pred: I::Predicate, + // Span of the original elaborated predicate. + pub original_span: I::Span, + // Span of the supertrait predicatae that lead to this clause. + pub supertrait_span: I::Span, +} +impl ClauseWithSupertraitSpan { + pub fn new(pred: I::Predicate, span: I::Span) -> Self { + ClauseWithSupertraitSpan { pred, original_span: span, supertrait_span: span } + } +} +impl Elaboratable for ClauseWithSupertraitSpan { + fn predicate(&self) -> ::Predicate { + self.pred + } + + fn child(&self, clause: ::Clause) -> Self { + ClauseWithSupertraitSpan { + pred: clause.as_predicate(), + original_span: self.original_span, + supertrait_span: self.supertrait_span, + } + } + + fn child_with_derived_cause( + &self, + clause: ::Clause, + supertrait_span: ::Span, + _parent_trait_pred: crate::Binder>, + _index: usize, + ) -> Self { + ClauseWithSupertraitSpan { + pred: clause.as_predicate(), + original_span: self.original_span, + supertrait_span: supertrait_span, + } + } +} + pub fn elaborate>( cx: I, obligations: impl IntoIterator, diff --git a/compiler/rustc_type_ir/src/inherent.rs b/compiler/rustc_type_ir/src/inherent.rs index 59a83ea5412d5..69665df4bfc26 100644 --- a/compiler/rustc_type_ir/src/inherent.rs +++ b/compiler/rustc_type_ir/src/inherent.rs @@ -460,6 +460,8 @@ pub trait Clause>: + IntoKind>> + Elaboratable { + fn as_predicate(self) -> I::Predicate; + fn as_trait_clause(self) -> Option>> { self.kind() .map_bound(|clause| if let ty::ClauseKind::Trait(t) = clause { Some(t) } else { None }) diff --git a/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.stderr b/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.stderr index bb3cc4b3fd786..067eaf5e7f30f 100644 --- a/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.stderr +++ b/tests/ui/traits/object/elaborated-predicates-unconstrained-late-bound.stderr @@ -1,6 +1,9 @@ error[E0582]: binding for associated type `T` references lifetime `'a`, which does not appear in the trait input types --> $DIR/elaborated-predicates-unconstrained-late-bound.rs:19:21 | +LL | trait A: B {} + | ----- due to this supertrait +... LL | Erase:: A<&'a _>>(x.as_str()) | ^^^^^^^^^^^^^^^^ From e057c43382a1eacc5941bc4e78b36dc122b32419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 4 Oct 2024 22:59:03 +0000 Subject: [PATCH 11/13] Account for `impl Trait {` when `impl Trait for Type {` was intended On editions where bare traits are never allowed, detect if the user has written `impl Trait` with no type, silence any dyn-compatibility errors, and provide a structured suggestion for the potentially missing type: ``` error[E0782]: trait objects must include the `dyn` keyword --> $DIR/missing-for-type-in-impl.rs:8:6 | LL | impl Foo { | ^^^^^^^^ | help: add `dyn` keyword before this trait | LL | impl dyn Foo { | +++ help: you might have intended to implement this trait for a given type | LL | impl Foo for /* Type */ { | ++++++++++++++ ``` --- .../src/hir_ty_lowering/lint.rs | 17 +++-- .../traits/fulfillment_errors.rs | 22 +++++- .../missing-for-type-in-impl.e2015.stderr | 74 +++++++++++++++++++ .../missing-for-type-in-impl.e2021.stderr | 31 ++++++++ tests/ui/traits/missing-for-type-in-impl.rs | 22 ++++++ 5 files changed, 158 insertions(+), 8 deletions(-) create mode 100644 tests/ui/traits/missing-for-type-in-impl.e2015.stderr create mode 100644 tests/ui/traits/missing-for-type-in-impl.e2021.stderr create mode 100644 tests/ui/traits/missing-for-type-in-impl.rs diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs index a70f881f5fedc..5607fe873f652 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs @@ -108,17 +108,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { let tcx = self.tcx(); let parent_id = tcx.hir().get_parent_item(self_ty.hir_id).def_id; if let hir::Node::Item(hir::Item { - kind: - hir::ItemKind::Impl(hir::Impl { - self_ty: impl_self_ty, - of_trait: Some(of_trait_ref), - generics, - .. - }), + kind: hir::ItemKind::Impl(hir::Impl { self_ty: impl_self_ty, of_trait, generics, .. }), .. }) = tcx.hir_node_by_def_id(parent_id) && self_ty.hir_id == impl_self_ty.hir_id { + let Some(of_trait_ref) = of_trait else { + diag.span_suggestion_verbose( + impl_self_ty.span.shrink_to_hi(), + "you might have intended to implement this trait for a given type", + format!(" for /* Type */"), + Applicability::HasPlaceholders, + ); + return; + }; if !of_trait_ref.trait_def_id().is_some_and(|def_id| def_id.is_local()) { return; } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 1889ecc7670ee..824c25db07d2e 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -1,6 +1,7 @@ use core::ops::ControlFlow; use std::borrow::Cow; +use rustc_ast::TraitObjectSyntax; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::unord::UnordSet; use rustc_errors::codes::*; @@ -573,7 +574,26 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { ty::PredicateKind::DynCompatible(trait_def_id) => { let violations = self.tcx.dyn_compatibility_violations(trait_def_id); - report_dyn_incompatibility(self.tcx, span, None, trait_def_id, violations) + let mut err = report_dyn_incompatibility( + self.tcx, + span, + None, + trait_def_id, + violations, + ); + if let hir::Node::Item(item) = + self.tcx.hir_node_by_def_id(obligation.cause.body_id) + && let hir::ItemKind::Impl(impl_) = item.kind + && let None = impl_.of_trait + && let hir::TyKind::TraitObject(_, _, syntax) = impl_.self_ty.kind + && let TraitObjectSyntax::None = syntax + && impl_.self_ty.span.edition().at_least_rust_2021() + { + // Silence the dyn-compatibility error in favor of the missing dyn on + // self type error. #131051. + err.downgrade_to_delayed_bug(); + } + err } ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(ty)) => { diff --git a/tests/ui/traits/missing-for-type-in-impl.e2015.stderr b/tests/ui/traits/missing-for-type-in-impl.e2015.stderr new file mode 100644 index 0000000000000..541b49b024fda --- /dev/null +++ b/tests/ui/traits/missing-for-type-in-impl.e2015.stderr @@ -0,0 +1,74 @@ +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/missing-for-type-in-impl.rs:8:6 + | +LL | impl Foo { + | ^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see + = note: `#[warn(bare_trait_objects)]` on by default +help: if this is a dyn-compatible trait, use `dyn` + | +LL | impl dyn Foo { + | +++ +help: you might have intended to implement this trait for a given type + | +LL | impl Foo for /* Type */ { + | ++++++++++++++ + +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/missing-for-type-in-impl.rs:8:6 + | +LL | impl Foo { + | ^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: if this is a dyn-compatible trait, use `dyn` + | +LL | impl dyn Foo { + | +++ +help: you might have intended to implement this trait for a given type + | +LL | impl Foo for /* Type */ { + | ++++++++++++++ + +error[E0038]: the trait `Foo` cannot be made into an object + --> $DIR/missing-for-type-in-impl.rs:8:6 + | +LL | impl Foo { + | ^^^^^^^^ `Foo` cannot be made into an object + | +note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/missing-for-type-in-impl.rs:4:8 + | +LL | trait Foo { + | --- this trait cannot be made into an object... +LL | fn id(me: T) -> T; + | ^^ ...because associated function `id` has no `self` parameter +help: consider turning `id` into a method by giving it a `&self` argument + | +LL | fn id(&self, me: T) -> T; + | ++++++ +help: alternatively, consider constraining `id` so it does not apply to trait objects + | +LL | fn id(me: T) -> T where Self: Sized; + | +++++++++++++++++ + +error[E0277]: the trait bound `i64: Foo` is not satisfied + --> $DIR/missing-for-type-in-impl.rs:19:19 + | +LL | let x: i64 = >::id(10); + | ^^^ the trait `Foo` is not implemented for `i64` + | +help: this trait has no implementations, consider adding one + --> $DIR/missing-for-type-in-impl.rs:3:1 + | +LL | trait Foo { + | ^^^^^^^^^^^^ + +error: aborting due to 2 previous errors; 2 warnings emitted + +Some errors have detailed explanations: E0038, E0277. +For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/traits/missing-for-type-in-impl.e2021.stderr b/tests/ui/traits/missing-for-type-in-impl.e2021.stderr new file mode 100644 index 0000000000000..b5a607a54cb54 --- /dev/null +++ b/tests/ui/traits/missing-for-type-in-impl.e2021.stderr @@ -0,0 +1,31 @@ +error[E0277]: the trait bound `i64: Foo` is not satisfied + --> $DIR/missing-for-type-in-impl.rs:19:19 + | +LL | let x: i64 = >::id(10); + | ^^^ the trait `Foo` is not implemented for `i64` + | +help: this trait has no implementations, consider adding one + --> $DIR/missing-for-type-in-impl.rs:3:1 + | +LL | trait Foo { + | ^^^^^^^^^^^^ + +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/missing-for-type-in-impl.rs:8:6 + | +LL | impl Foo { + | ^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL | impl dyn Foo { + | +++ +help: you might have intended to implement this trait for a given type + | +LL | impl Foo for /* Type */ { + | ++++++++++++++ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0277, E0782. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/missing-for-type-in-impl.rs b/tests/ui/traits/missing-for-type-in-impl.rs new file mode 100644 index 0000000000000..7d4ad479e773c --- /dev/null +++ b/tests/ui/traits/missing-for-type-in-impl.rs @@ -0,0 +1,22 @@ +//@revisions: e2021 e2015 +//@[e2021]edition: 2021 +trait Foo { + fn id(me: T) -> T; +} + +/* note the "missing" for ... (in this case for i64, in order for this to compile) */ +impl Foo { +//[e2021]~^ ERROR trait objects must include the `dyn` keyword +//[e2015]~^^ WARNING trait objects without an explicit `dyn` are deprecated +//[e2015]~| WARNING trait objects without an explicit `dyn` are deprecated +//[e2015]~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! +//[e2015]~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! +//[e2015]~| ERROR the trait `Foo` cannot be made into an object + fn id(me: i64) -> i64 {me} +} + +fn main() { + let x: i64 = >::id(10); + //~^ ERROR the trait bound `i64: Foo` is not satisfied + println!("{}", x); +} From 6b67c46a253d453674401fad70c515d8fd439e35 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 24 Aug 2024 18:19:38 +0000 Subject: [PATCH 12/13] Compute array length from type for unconditional panic. --- .../rustc_mir_transform/src/known_panics_lint.rs | 16 +++++++++------- tests/ui/lint/unconditional_panic_promoted.rs | 8 ++++++++ .../ui/lint/unconditional_panic_promoted.stderr | 10 ++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 tests/ui/lint/unconditional_panic_promoted.rs create mode 100644 tests/ui/lint/unconditional_panic_promoted.stderr diff --git a/compiler/rustc_mir_transform/src/known_panics_lint.rs b/compiler/rustc_mir_transform/src/known_panics_lint.rs index ccc029b1e281e..8f490094d6030 100644 --- a/compiler/rustc_mir_transform/src/known_panics_lint.rs +++ b/compiler/rustc_mir_transform/src/known_panics_lint.rs @@ -600,13 +600,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } Len(place) => { - let len = match self.get_const(place)? { - Value::Immediate(src) => src.len(&self.ecx).discard_err()?, - Value::Aggregate { fields, .. } => fields.len() as u64, - Value::Uninit => match place.ty(self.local_decls(), self.tcx).ty.kind() { - ty::Array(_, n) => n.try_eval_target_usize(self.tcx, self.param_env)?, - _ => return None, - }, + let len = if let ty::Array(_, n) = place.ty(self.local_decls(), self.tcx).ty.kind() + { + n.try_eval_target_usize(self.tcx, self.param_env)? + } else { + match self.get_const(place)? { + Value::Immediate(src) => src.len(&self.ecx).discard_err()?, + Value::Aggregate { fields, .. } => fields.len() as u64, + Value::Uninit => return None, + } }; ImmTy::from_scalar(Scalar::from_target_usize(len, self), layout).into() } diff --git a/tests/ui/lint/unconditional_panic_promoted.rs b/tests/ui/lint/unconditional_panic_promoted.rs new file mode 100644 index 0000000000000..37bcf04651352 --- /dev/null +++ b/tests/ui/lint/unconditional_panic_promoted.rs @@ -0,0 +1,8 @@ +//@ build-fail + +fn main() { + // MIR encodes this as a reborrow from a promoted constant. + // But the array lenth can still be gotten from the type. + let slice = &[0, 1]; + let _ = slice[2]; //~ ERROR: this operation will panic at runtime [unconditional_panic] +} diff --git a/tests/ui/lint/unconditional_panic_promoted.stderr b/tests/ui/lint/unconditional_panic_promoted.stderr new file mode 100644 index 0000000000000..647a84a55fda5 --- /dev/null +++ b/tests/ui/lint/unconditional_panic_promoted.stderr @@ -0,0 +1,10 @@ +error: this operation will panic at runtime + --> $DIR/unconditional_panic_promoted.rs:7:13 + | +LL | let _ = slice[2]; + | ^^^^^^^^ index out of bounds: the length is 2 but the index is 2 + | + = note: `#[deny(unconditional_panic)]` on by default + +error: aborting due to 1 previous error + From 479779d6a90cc228fc45b5126c558ca52539b2c2 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 25 Aug 2024 12:13:15 +0000 Subject: [PATCH 13/13] Bless clippy. --- .../clippy/tests/ui-toml/unwrap_used/unwrap_used.fixed | 1 + src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs | 1 + .../clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr | 2 +- src/tools/clippy/tests/ui/get_unwrap.fixed | 1 + src/tools/clippy/tests/ui/get_unwrap.rs | 1 + src/tools/clippy/tests/ui/get_unwrap.stderr | 8 ++++---- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.fixed b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.fixed index baf939af24efb..cdb8fa0454cd4 100644 --- a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.fixed +++ b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.fixed @@ -86,6 +86,7 @@ mod issue9612 { util(); } + #[allow(unconditional_panic)] fn util() { let _a: u8 = 4.try_into().unwrap(); let _a: u8 = 5.try_into().expect(""); diff --git a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs index e300ba18c3309..e53d53db5f7a4 100644 --- a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs +++ b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs @@ -86,6 +86,7 @@ mod issue9612 { util(); } + #[allow(unconditional_panic)] fn util() { let _a: u8 = 4.try_into().unwrap(); let _a: u8 = 5.try_into().expect(""); diff --git a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr index 320578bfabce0..b58ce9b8af3e4 100644 --- a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr +++ b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr @@ -274,7 +274,7 @@ LL | let _ = &boxed_slice[1]; | ~~~~~~~~~~~~~~~ error: called `.get().unwrap()` on a slice - --> tests/ui-toml/unwrap_used/unwrap_used.rs:93:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:94:17 | LL | let _ = Box::new([0]).get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/get_unwrap.fixed b/src/tools/clippy/tests/ui/get_unwrap.fixed index 62beb195939c6..2dd3c30a4e29b 100644 --- a/src/tools/clippy/tests/ui/get_unwrap.fixed +++ b/src/tools/clippy/tests/ui/get_unwrap.fixed @@ -70,6 +70,7 @@ fn main() { mod issue9909 { #![allow(clippy::identity_op, clippy::unwrap_used, dead_code)] + #[allow(unconditional_panic)] fn reduced() { let f = &[1, 2, 3]; diff --git a/src/tools/clippy/tests/ui/get_unwrap.rs b/src/tools/clippy/tests/ui/get_unwrap.rs index 1e09ff5c67e51..94226564cacb5 100644 --- a/src/tools/clippy/tests/ui/get_unwrap.rs +++ b/src/tools/clippy/tests/ui/get_unwrap.rs @@ -70,6 +70,7 @@ fn main() { mod issue9909 { #![allow(clippy::identity_op, clippy::unwrap_used, dead_code)] + #[allow(unconditional_panic)] fn reduced() { let f = &[1, 2, 3]; diff --git a/src/tools/clippy/tests/ui/get_unwrap.stderr b/src/tools/clippy/tests/ui/get_unwrap.stderr index 0f8b279da1e7a..8eacb249c60c6 100644 --- a/src/tools/clippy/tests/ui/get_unwrap.stderr +++ b/src/tools/clippy/tests/ui/get_unwrap.stderr @@ -266,7 +266,7 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice - --> tests/ui/get_unwrap.rs:77:24 + --> tests/ui/get_unwrap.rs:78:24 | LL | let _x: &i32 = f.get(1 + 2).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^ @@ -277,7 +277,7 @@ LL | let _x: &i32 = &f[1 + 2]; | ~~~~~~~~~ error: called `.get().unwrap()` on a slice - --> tests/ui/get_unwrap.rs:80:18 + --> tests/ui/get_unwrap.rs:81:18 | LL | let _x = f.get(1 + 2).unwrap().to_string(); | ^^^^^^^^^^^^^^^^^^^^^ @@ -288,7 +288,7 @@ LL | let _x = f[1 + 2].to_string(); | ~~~~~~~~ error: called `.get().unwrap()` on a slice - --> tests/ui/get_unwrap.rs:83:18 + --> tests/ui/get_unwrap.rs:84:18 | LL | let _x = f.get(1 + 2).unwrap().abs(); | ^^^^^^^^^^^^^^^^^^^^^ @@ -299,7 +299,7 @@ LL | let _x = f[1 + 2].abs(); | ~~~~~~~~ error: called `.get_mut().unwrap()` on a slice - --> tests/ui/get_unwrap.rs:100:33 + --> tests/ui/get_unwrap.rs:101:33 | LL | let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^