Skip to content

Clarify cryptic comments #115578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2023
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
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
};
let def_id = trait_predicate.trait_ref.def_id;
if cx.tcx.lang_items().drop_trait() == Some(def_id) {
// Explicitly allow `impl Drop`, a drop-guards-as-Voldemort-type pattern.
// Explicitly allow `impl Drop`, a drop-guards-as-unnameable-type pattern.
if trait_predicate.trait_ref.self_ty().is_impl_trait() {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4408,7 +4408,7 @@ declare_lint! {
/// pub struct S;
/// }
///
/// pub fn get_voldemort() -> m::S { m::S }
/// pub fn get_unnameable() -> m::S { m::S }
/// # fn main() {}
/// ```
///
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2857,7 +2857,7 @@ impl<'tcx> Ty<'tcx> {
| ty::Uint(..)
| ty::Float(..) => true,

// The voldemort ZSTs are fine.
// ZST which can't be named are fine.
ty::FnDef(..) => true,

ty::Array(element_ty, _len) => element_ty.is_trivially_pure_clone_copy(),
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/drop-bounds/drop-bounds-impl-drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#![deny(drop_bounds)]
// As a special exemption, `impl Drop` in the return position raises no error.
// This allows a convenient way to return an unnamed drop guard.
fn voldemort_type() -> impl Drop {
struct Voldemort;
impl Drop for Voldemort {
fn unnameable_type() -> impl Drop {
struct Unnameable;
impl Drop for Unnameable {
fn drop(&mut self) {}
}
Voldemort
Unnameable
}
fn main() {
let _ = voldemort_type();
let _ = unnameable_type();
}
8 changes: 4 additions & 4 deletions tests/ui/privacy/unnameable_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ mod m {
}
}

pub trait Voldemort<T> {}
pub trait Unnameable<T> {}

impl Voldemort<m::PubStruct> for i32 {}
impl Voldemort<m::PubE> for i32 {}
impl<T> Voldemort<T> for u32 where T: m::PubTr {}
impl Unnameable<m::PubStruct> for i32 {}
impl Unnameable<m::PubE> for i32 {}
impl<T> Unnameable<T> for u32 where T: m::PubTr {}

fn main() {}