Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
Some(self.infcx.tcx.hir_name(var_id).to_string())
}
_ => {
// Might need a revision when the fields in trait RFC is implemented
// (https://github.com/rust-lang/rfcs/pull/1546)
bug!("End-user description not implemented for field access on `{:?}`", ty);
// This can happen for field accesses on `Box<T>`: the field is
// described from the boxed type, which may have no named fields
Some(field.index().to_string())
}
}
}
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