Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
ty::Array(ty, _) | ty::Slice(ty) => {
self.describe_field_from_ty(ty, field, variant_index, including_tuple_field)
}
ty::Param(_) => Some(field.index().to_string()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind adding a comment to explain this surprising case?

ty::Closure(def_id, _) | ty::Coroutine(def_id, _) => {
// We won't be borrowck'ing here if the closure came from another crate,
// so it's safe to call `expect_local`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Regression test for #155344.
// Borrowck diagnostics should not ICE when describing a field access on a generic parameter.

//@ edition: 2024

#![crate_type = "lib"]
#![feature(no_core, lang_items)]
#![no_core]

#[lang = "pointee_sized"]
pub trait PointeeSized {}

#[lang = "meta_sized"]
pub trait MetaSized: PointeeSized {}

#[lang = "sized"]
pub trait Sized: MetaSized {}

#[lang = "legacy_receiver"]
pub trait LegacyReceiver {}

impl<T: PointeeSized> LegacyReceiver for &T {}
impl<T: PointeeSized> LegacyReceiver for &mut T {}

#[lang = "copy"]
pub trait Copy {}

impl Copy for *mut () {}

#[lang = "drop"]
pub trait Drop {
fn drop(&mut self);
}

unsafe extern "C" {
fn free(_: *mut ());
}

unsafe fn transmute<T, U>(_: T) -> U {
loop {}
}

#[repr(transparent)]
pub struct NonNull<T: ?Sized>(pub *const T);

#[lang = "owned_box"]
pub struct Box<T: ?Sized, A = ()>(NonNull<T>, A);

impl<T: ?Sized, A> Drop for Box<T, A> {
fn drop(&mut self) {
unsafe {
free(transmute::<NonNull<T>, *mut _>(self.0));
//~^ ERROR cannot move out of `self.0` which is behind a mutable reference
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0507]: cannot move out of `self.0` which is behind a mutable reference
--> $DIR/borrowck-describe-field-generic-param-owned-box.rs:52:50
|
LL | free(transmute::<NonNull<T>, *mut _>(self.0));
| ^^^^^^ move occurs because `self.0` has type `NonNull<T>`, which does not implement the `Copy` trait

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0507`.
Loading