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
4 changes: 1 addition & 3 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,6 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {

/// Disposes of a value.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Disposes of a value.
/// Disposes of a value by taking ownership of it and letting it go out of scope (which invokes its [`Drop`][drop] implementation).

Copy link
Contributor

Choose a reason for hiding this comment

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

This kind of goes against the original purpose of this change.

Sure, Drop is invoked when something goes out of scope, but the clarification is that this function does not actually interact with Drop at all directly; it's just an empty function body.

This change puts the clarification that it's just an empty function body before the actual mention of [Drop], making things more clear.

Copy link
Member

Choose a reason for hiding this comment

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

The "letting it go out of scope" is just a bit more general and direct than saying "just an empty function body", otherwise you still need to infer that an empty function makes all its arguments go out of scope...

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree with @clarfonthey, I think there are a lot of ways to explain this and this is why I've decided to just do the minimal possible thing until somebody maybe from @rust-lang/libs-contributors comes and suggest a way in which they would approve the change.
I guess the best possible way is to say ... very informal version ... This is just an empty function that works like any other empty function which takes ownership of the value, at the end, due to what the compiler does in the process of mir building which injects Drop Terminators, drop elaboration refines this and then we would insert the corresponding drop glue, then potentially calling Drop::drop. Something / something like that, or maybe that is too technical for libs documentation and we don't want to explain things in terms of what happens inside the compiler.
Maybe just, This is just an empty function that works like any other empty function which takes ownership of the value, at the end, when the value goes out of scope it gets droppped.

///
/// This does so by calling the argument's implementation of [`Drop`][drop].
///
/// This effectively does nothing for types which implement `Copy`, e.g.
/// integers. Such values are copied and _then_ moved into the function, so the
/// value persists after this function call.
Expand All @@ -910,7 +908,7 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {
/// pub fn drop<T>(_x: T) {}
/// ```
///
/// Because `_x` is moved into the function, it is automatically dropped before
/// Because `_x` is moved into the function, it is automatically [dropped][drop] before
/// the function returns.
///
/// [drop]: Drop
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/thir-print/offset_of.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ body:
)
else_block: None
lint_level: Explicit(HirId(DefId(offset_of::concrete).10))
span: $DIR/offset_of.rs:37:5: 1435:57 (#0)
span: $DIR/offset_of.rs:37:5: 1433:57 (#0)
}
}
Stmt {
Expand Down Expand Up @@ -117,7 +117,7 @@ body:
)
else_block: None
lint_level: Explicit(HirId(DefId(offset_of::concrete).20))
span: $DIR/offset_of.rs:38:5: 1435:57 (#0)
span: $DIR/offset_of.rs:38:5: 1433:57 (#0)
}
}
Stmt {
Expand Down Expand Up @@ -166,7 +166,7 @@ body:
)
else_block: None
lint_level: Explicit(HirId(DefId(offset_of::concrete).30))
span: $DIR/offset_of.rs:39:5: 1435:57 (#0)
span: $DIR/offset_of.rs:39:5: 1433:57 (#0)
}
}
Stmt {
Expand Down Expand Up @@ -215,7 +215,7 @@ body:
)
else_block: None
lint_level: Explicit(HirId(DefId(offset_of::concrete).40))
span: $DIR/offset_of.rs:40:5: 1435:57 (#0)
span: $DIR/offset_of.rs:40:5: 1433:57 (#0)
}
}
Stmt {
Expand Down Expand Up @@ -264,7 +264,7 @@ body:
)
else_block: None
lint_level: Explicit(HirId(DefId(offset_of::concrete).50))
span: $DIR/offset_of.rs:41:5: 1435:57 (#0)
span: $DIR/offset_of.rs:41:5: 1433:57 (#0)
}
}
]
Expand Down Expand Up @@ -864,7 +864,7 @@ body:
)
else_block: None
lint_level: Explicit(HirId(DefId(offset_of::generic).12))
span: $DIR/offset_of.rs:45:5: 1435:57 (#0)
span: $DIR/offset_of.rs:45:5: 1433:57 (#0)
}
}
Stmt {
Expand Down Expand Up @@ -913,7 +913,7 @@ body:
)
else_block: None
lint_level: Explicit(HirId(DefId(offset_of::generic).24))
span: $DIR/offset_of.rs:46:5: 1435:57 (#0)
span: $DIR/offset_of.rs:46:5: 1433:57 (#0)
}
}
Stmt {
Expand Down Expand Up @@ -962,7 +962,7 @@ body:
)
else_block: None
lint_level: Explicit(HirId(DefId(offset_of::generic).36))
span: $DIR/offset_of.rs:47:5: 1435:57 (#0)
span: $DIR/offset_of.rs:47:5: 1433:57 (#0)
}
}
Stmt {
Expand Down Expand Up @@ -1011,7 +1011,7 @@ body:
)
else_block: None
lint_level: Explicit(HirId(DefId(offset_of::generic).48))
span: $DIR/offset_of.rs:48:5: 1435:57 (#0)
span: $DIR/offset_of.rs:48:5: 1433:57 (#0)
}
}
]
Expand Down
Loading