Skip to content

Commit 75b98fb

Browse files
committed
Auto merge of #69226 - JohnTitor:rollup-syn03oj, r=JohnTitor
Rollup of 6 pull requests Successful merges: - #68495 (Updating str.chars docs to mention crates.io.) - #68701 (Improve #Safety of various methods in core::ptr) - #69158 (Don't print block exit state in dataflow graphviz if unchanged) - #69179 (Rename `FunctionRetTy` to `FnRetTy`) - #69186 ([tiny] parser: `macro_rules` is a weak keyword) - #69188 (Clean up E0309 explanation) Failed merges: r? @ghost
2 parents 3c4590f + cc497c4 commit 75b98fb

File tree

50 files changed

+185
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+185
-158
lines changed

src/libcore/ptr/mod.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,13 @@ mod mut_ptr;
119119
///
120120
/// Behavior is undefined if any of the following conditions are violated:
121121
///
122-
/// * `to_drop` must be [valid] for reads.
122+
/// * `to_drop` must be [valid] for both reads and writes.
123123
///
124124
/// * `to_drop` must be properly aligned.
125125
///
126+
/// * The value `to_drop` points to must be valid for dropping, which may mean it must uphold
127+
/// additional invariants - this is type-dependent.
128+
///
126129
/// Additionally, if `T` is not [`Copy`], using the pointed-to value after
127130
/// calling `drop_in_place` can cause undefined behavior. Note that `*to_drop =
128131
/// foo` counts as a use because it will cause the value to be dropped
@@ -289,7 +292,7 @@ pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
289292
///
290293
/// Behavior is undefined if any of the following conditions are violated:
291294
///
292-
/// * Both `x` and `y` must be [valid] for reads and writes.
295+
/// * Both `x` and `y` must be [valid] for both reads and writes.
293296
///
294297
/// * Both `x` and `y` must be properly aligned.
295298
///
@@ -355,7 +358,7 @@ pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
355358
///
356359
/// Behavior is undefined if any of the following conditions are violated:
357360
///
358-
/// * Both `x` and `y` must be [valid] for reads and writes of `count *
361+
/// * Both `x` and `y` must be [valid] for both reads and writes of `count *
359362
/// size_of::<T>()` bytes.
360363
///
361364
/// * Both `x` and `y` must be properly aligned.
@@ -471,10 +474,12 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
471474
///
472475
/// Behavior is undefined if any of the following conditions are violated:
473476
///
474-
/// * `dst` must be [valid] for writes.
477+
/// * `dst` must be [valid] for both reads and writes.
475478
///
476479
/// * `dst` must be properly aligned.
477480
///
481+
/// * `dst` must point to a properly initialized value of type `T`.
482+
///
478483
/// Note that even if `T` has size `0`, the pointer must be non-NULL and properly aligned.
479484
///
480485
/// [valid]: ../ptr/index.html#safety
@@ -514,6 +519,8 @@ pub unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
514519
/// * `src` must be properly aligned. Use [`read_unaligned`] if this is not the
515520
/// case.
516521
///
522+
/// * `src` must point to a properly initialized value of type `T`.
523+
///
517524
/// Note that even if `T` has size `0`, the pointer must be non-NULL and properly aligned.
518525
///
519526
/// # Examples
@@ -628,6 +635,8 @@ pub unsafe fn read<T>(src: *const T) -> T {
628635
///
629636
/// * `src` must be [valid] for reads.
630637
///
638+
/// * `src` must point to a properly initialized value of type `T`.
639+
///
631640
/// Like [`read`], `read_unaligned` creates a bitwise copy of `T`, regardless of
632641
/// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the returned
633642
/// value and the value at `*src` can [violate memory safety][read-ownership].
@@ -922,6 +931,8 @@ pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
922931
///
923932
/// * `src` must be properly aligned.
924933
///
934+
/// * `src` must point to a properly initialized value of type `T`.
935+
///
925936
/// Like [`read`], `read_volatile` creates a bitwise copy of `T`, regardless of
926937
/// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the returned
927938
/// value and the value at `*src` can [violate memory safety][read-ownership].

src/libcore/str/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2658,7 +2658,8 @@ impl str {
26582658
///
26592659
/// It's important to remember that [`char`] represents a Unicode Scalar
26602660
/// Value, and may not match your idea of what a 'character' is. Iteration
2661-
/// over grapheme clusters may be what you actually want.
2661+
/// over grapheme clusters may be what you actually want. This functionality
2662+
/// is not provided by Rust's standard library, check crates.io instead.
26622663
///
26632664
/// # Examples
26642665
///

src/librustc_ast_lowering/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
480480
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
481481
) -> hir::ExprKind<'hir> {
482482
let output = match ret_ty {
483-
Some(ty) => FunctionRetTy::Ty(ty),
484-
None => FunctionRetTy::Default(span),
483+
Some(ty) => FnRetTy::Ty(ty),
484+
None => FnRetTy::Default(span),
485485
};
486486
let ast_decl = FnDecl { inputs: vec![], output };
487487
let decl = self.lower_fn_decl(&ast_decl, None, /* impl trait allowed */ false, None);
@@ -721,7 +721,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
721721
fn_decl_span: Span,
722722
) -> hir::ExprKind<'hir> {
723723
let outer_decl =
724-
FnDecl { inputs: decl.inputs.clone(), output: FunctionRetTy::Default(fn_decl_span) };
724+
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
725725
// We need to lower the declaration outside the new scope, because we
726726
// have to conserve the state of being inside a loop condition for the
727727
// closure argument types.
@@ -747,7 +747,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
747747
// `|x: u8| future_from_generator(|| -> X { ... })`.
748748
let body_id = this.lower_fn_body(&outer_decl, |this| {
749749
let async_ret_ty =
750-
if let FunctionRetTy::Ty(ty) = &decl.output { Some(ty.clone()) } else { None };
750+
if let FnRetTy::Ty(ty) = &decl.output { Some(ty.clone()) } else { None };
751751
let async_body = this.make_async_expr(
752752
capture_clause,
753753
closure_id,

src/librustc_ast_lowering/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,16 +1725,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17251725
)
17261726
} else {
17271727
match decl.output {
1728-
FunctionRetTy::Ty(ref ty) => {
1728+
FnRetTy::Ty(ref ty) => {
17291729
let context = match in_band_ty_params {
17301730
Some((def_id, _)) if impl_trait_return_allow => {
17311731
ImplTraitContext::OpaqueTy(Some(def_id), hir::OpaqueTyOrigin::FnReturn)
17321732
}
17331733
_ => ImplTraitContext::disallowed(),
17341734
};
1735-
hir::FunctionRetTy::Return(self.lower_ty(ty, context))
1735+
hir::FnRetTy::Return(self.lower_ty(ty, context))
17361736
}
1737-
FunctionRetTy::Default(span) => hir::FunctionRetTy::DefaultReturn(span),
1737+
FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(span),
17381738
}
17391739
};
17401740

@@ -1781,10 +1781,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17811781
// `elided_lt_replacement`: replacement for elided lifetimes in the return type
17821782
fn lower_async_fn_ret_ty(
17831783
&mut self,
1784-
output: &FunctionRetTy,
1784+
output: &FnRetTy,
17851785
fn_def_id: DefId,
17861786
opaque_ty_node_id: NodeId,
1787-
) -> hir::FunctionRetTy<'hir> {
1787+
) -> hir::FnRetTy<'hir> {
17881788
debug!(
17891789
"lower_async_fn_ret_ty(\
17901790
output={:?}, \
@@ -1949,27 +1949,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19491949
// only the lifetime parameters that we must supply.
19501950
let opaque_ty_ref = hir::TyKind::Def(hir::ItemId { id: opaque_ty_id }, generic_args);
19511951
let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
1952-
hir::FunctionRetTy::Return(self.arena.alloc(opaque_ty))
1952+
hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
19531953
}
19541954

19551955
/// Transforms `-> T` into `Future<Output = T>`
19561956
fn lower_async_fn_output_type_to_future_bound(
19571957
&mut self,
1958-
output: &FunctionRetTy,
1958+
output: &FnRetTy,
19591959
fn_def_id: DefId,
19601960
span: Span,
19611961
) -> hir::GenericBound<'hir> {
19621962
// Compute the `T` in `Future<Output = T>` from the return type.
19631963
let output_ty = match output {
1964-
FunctionRetTy::Ty(ty) => {
1964+
FnRetTy::Ty(ty) => {
19651965
// Not `OpaqueTyOrigin::AsyncFn`: that's only used for the
19661966
// `impl Future` opaque type that `async fn` implicitly
19671967
// generates.
19681968
let context =
19691969
ImplTraitContext::OpaqueTy(Some(fn_def_id), hir::OpaqueTyOrigin::FnReturn);
19701970
self.lower_ty(ty, context)
19711971
}
1972-
FunctionRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
1972+
FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
19731973
};
19741974

19751975
// "<Output = T>"

src/librustc_ast_lowering/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
397397
inputs.iter().map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed())),
398398
);
399399
let output_ty = match output {
400-
FunctionRetTy::Ty(ty) => this.lower_ty(&ty, ImplTraitContext::disallowed()),
401-
FunctionRetTy::Default(_) => this.arena.alloc(this.ty_tup(span, &[])),
400+
FnRetTy::Ty(ty) => this.lower_ty(&ty, ImplTraitContext::disallowed()),
401+
FnRetTy::Default(_) => this.arena.alloc(this.ty_tup(span, &[])),
402402
};
403403
let args = smallvec![GenericArg::Type(this.ty_tup(span, inputs))];
404404
let binding = this.output_ty_binding(output_ty.span, output_ty);

src/librustc_ast_passes/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
954954
}
955955
GenericArgs::Parenthesized(ref data) => {
956956
walk_list!(self, visit_ty, &data.inputs);
957-
if let FunctionRetTy::Ty(ty) = &data.output {
957+
if let FnRetTy::Ty(ty) = &data.output {
958958
// `-> Foo` syntax is essentially an associated type binding,
959959
// so it is also allowed to contain nested `impl Trait`.
960960
self.with_impl_trait(None, |this| this.visit_ty(ty));

src/librustc_ast_passes/feature_gate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
419419
visit::walk_ty(self, ty)
420420
}
421421

422-
fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FunctionRetTy) {
423-
if let ast::FunctionRetTy::Ty(ref output_ty) = *ret_ty {
422+
fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FnRetTy) {
423+
if let ast::FnRetTy::Ty(ref output_ty) = *ret_ty {
424424
if let ast::TyKind::Never = output_ty.kind {
425425
// Do nothing.
426426
} else {

src/librustc_ast_pretty/pprust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,8 +2673,8 @@ impl<'a> State<'a> {
26732673
self.end();
26742674
}
26752675

2676-
crate fn print_fn_ret_ty(&mut self, fn_ret_ty: &ast::FunctionRetTy) {
2677-
if let ast::FunctionRetTy::Ty(ty) = fn_ret_ty {
2676+
crate fn print_fn_ret_ty(&mut self, fn_ret_ty: &ast::FnRetTy) {
2677+
if let ast::FnRetTy::Ty(ty) = fn_ret_ty {
26782678
self.space_if_not_bol();
26792679
self.ibox(INDENT_UNIT);
26802680
self.word_space("->");

src/librustc_ast_pretty/pprust/tests.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ fn test_fun_to_string() {
3434
with_default_globals(|| {
3535
let abba_ident = ast::Ident::from_str("abba");
3636

37-
let decl = ast::FnDecl {
38-
inputs: Vec::new(),
39-
output: ast::FunctionRetTy::Default(rustc_span::DUMMY_SP),
40-
};
37+
let decl =
38+
ast::FnDecl { inputs: Vec::new(), output: ast::FnRetTy::Default(rustc_span::DUMMY_SP) };
4139
let generics = ast::Generics::default();
4240
assert_eq!(
4341
fun_to_string(&decl, ast::FnHeader::default(), abba_ident, &generics),

src/librustc_builtin_macros/deriving/generic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ impl<'a> MethodDef<'a> {
957957
let ret_type = self.get_ret_ty(cx, trait_, generics, type_ident);
958958

959959
let method_ident = cx.ident_of(self.name, trait_.span);
960-
let fn_decl = cx.fn_decl(args, ast::FunctionRetTy::Ty(ret_type));
960+
let fn_decl = cx.fn_decl(args, ast::FnRetTy::Ty(ret_type));
961961
let body_block = cx.block_expr(body);
962962

963963
let unsafety = if self.is_unsafe { ast::Unsafe::Yes(trait_.span) } else { ast::Unsafe::No };

0 commit comments

Comments
 (0)