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

+15-4
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

+2-1
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

+4-4
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

+9-9
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

+2-2
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

+1-1
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

+2-2
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

+2-2
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

+2-4
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

+1-1
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 };

src/librustc_builtin_macros/global_allocator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl AllocFnFactory<'_, '_> {
6363
let args = method.inputs.iter().map(|ty| self.arg_ty(ty, &mut abi_args, mk)).collect();
6464
let result = self.call_allocator(method.name, args);
6565
let (output_ty, output_expr) = self.ret_ty(&method.output, result);
66-
let decl = self.cx.fn_decl(abi_args, ast::FunctionRetTy::Ty(output_ty));
66+
let decl = self.cx.fn_decl(abi_args, ast::FnRetTy::Ty(output_ty));
6767
let header = FnHeader { unsafety: Unsafe::Yes(self.span), ..FnHeader::default() };
6868
let sig = FnSig { decl, header };
6969
let kind = ItemKind::Fn(sig, Generics::default(), Some(self.cx.block_expr(output_expr)));

src/librustc_builtin_macros/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
391391
// If the termination trait is active, the compiler will check that the output
392392
// type implements the `Termination` trait as `libtest` enforces that.
393393
let has_output = match sig.decl.output {
394-
ast::FunctionRetTy::Default(..) => false,
395-
ast::FunctionRetTy::Ty(ref t) if t.kind.is_unit() => false,
394+
ast::FnRetTy::Default(..) => false,
395+
ast::FnRetTy::Ty(ref t) if t.kind.is_unit() => false,
396396
_ => true,
397397
};
398398

src/librustc_builtin_macros/test_harness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
305305
ecx.block(sp, vec![call_test_main])
306306
};
307307

308-
let decl = ecx.fn_decl(vec![], ast::FunctionRetTy::Ty(main_ret_ty));
308+
let decl = ecx.fn_decl(vec![], ast::FnRetTy::Ty(main_ret_ty));
309309
let sig = ast::FnSig { decl, header: ast::FnHeader::default() };
310310
let main = ast::ItemKind::Fn(sig, ast::Generics::default(), Some(main_body));
311311

src/librustc_error_codes/error_codes/E0309.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
The type definition contains some field whose type
2-
requires an outlives annotation. Outlives annotations
3-
(e.g., `T: 'a`) are used to guarantee that all the data in T is valid
4-
for at least the lifetime `'a`. This scenario most commonly
5-
arises when the type contains an associated type reference
6-
like `<T as SomeTrait<'a>>::Output`, as shown in this example:
1+
A parameter type is missing an explicit lifetime bound and may not live long
2+
enough.
3+
4+
Erroneous code example:
75

86
```compile_fail,E0309
97
// This won't compile because the applicable impl of
@@ -25,9 +23,15 @@ where
2523
}
2624
```
2725

28-
Here, the where clause `T: 'a` that appears on the impl is not known to be
29-
satisfied on the struct. To make this example compile, you have to add
30-
a where-clause like `T: 'a` to the struct definition:
26+
The type definition contains some field whose type requires an outlives
27+
annotation. Outlives annotations (e.g., `T: 'a`) are used to guarantee that all
28+
the data in T is valid for at least the lifetime `'a`. This scenario most
29+
commonly arises when the type contains an associated type reference like
30+
`<T as SomeTrait<'a>>::Output`, as shown in the previous code.
31+
32+
There, the where clause `T: 'a` that appears on the impl is not known to be
33+
satisfied on the struct. To make this example compile, you have to add a
34+
where-clause like `T: 'a` to the struct definition:
3135

3236
```
3337
struct Foo<'a, T>

src/librustc_expand/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl<'a> ExtCtxt<'a> {
519519
pub fn lambda(&self, span: Span, ids: Vec<ast::Ident>, body: P<ast::Expr>) -> P<ast::Expr> {
520520
let fn_decl = self.fn_decl(
521521
ids.iter().map(|id| self.param(span, *id, self.ty(span, ast::TyKind::Infer))).collect(),
522-
ast::FunctionRetTy::Default(span),
522+
ast::FnRetTy::Default(span),
523523
);
524524

525525
// FIXME -- We are using `span` as the span of the `|...|`
@@ -569,7 +569,7 @@ impl<'a> ExtCtxt<'a> {
569569
}
570570

571571
// FIXME: unused `self`
572-
pub fn fn_decl(&self, inputs: Vec<ast::Param>, output: ast::FunctionRetTy) -> P<ast::FnDecl> {
572+
pub fn fn_decl(&self, inputs: Vec<ast::Param>, output: ast::FnRetTy) -> P<ast::FnDecl> {
573573
P(ast::FnDecl { inputs, output })
574574
}
575575

src/librustc_expand/mbe/macro_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ use crate::mbe::{KleeneToken, TokenTree};
109109
use rustc_data_structures::fx::FxHashMap;
110110
use rustc_session::lint::builtin::META_VARIABLE_MISUSE;
111111
use rustc_session::parse::ParseSess;
112-
use rustc_span::symbol::{kw, sym};
112+
use rustc_span::symbol::kw;
113113
use rustc_span::{symbol::Ident, MultiSpan, Span};
114114
use syntax::ast::NodeId;
115115
use syntax::token::{DelimToken, Token, TokenKind};
@@ -392,7 +392,7 @@ fn check_nested_occurrences(
392392
NestedMacroState::Empty,
393393
&TokenTree::Token(Token { kind: TokenKind::Ident(name, false), .. }),
394394
) => {
395-
if name == sym::macro_rules {
395+
if name == kw::MacroRules {
396396
state = NestedMacroState::MacroRules;
397397
} else if name == kw::Macro {
398398
state = NestedMacroState::Macro;

src/librustc_expand/parse/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn string_to_tts_macro() {
6565

6666
match tts {
6767
[TokenTree::Token(Token { kind: token::Ident(name_macro_rules, false), .. }), TokenTree::Token(Token { kind: token::Not, .. }), TokenTree::Token(Token { kind: token::Ident(name_zip, false), .. }), TokenTree::Delimited(_, macro_delim, macro_tts)]
68-
if name_macro_rules == &sym::macro_rules && name_zip.as_str() == "zip" =>
68+
if name_macro_rules == &kw::MacroRules && name_zip.as_str() == "zip" =>
6969
{
7070
let tts = &macro_tts.trees().collect::<Vec<_>>();
7171
match &tts[..] {

src/librustc_hir/hir.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::itemlikevisit;
55
use crate::print;
66

77
crate use BlockCheckMode::*;
8-
crate use FunctionRetTy::*;
8+
crate use FnRetTy::*;
99
crate use UnsafeSource::*;
1010

1111
use rustc_data_structures::fx::FxHashSet;
@@ -2082,7 +2082,7 @@ pub struct FnDecl<'hir> {
20822082
///
20832083
/// Additional argument data is stored in the function's [body](Body::parameters).
20842084
pub inputs: &'hir [Ty<'hir>],
2085-
pub output: FunctionRetTy<'hir>,
2085+
pub output: FnRetTy<'hir>,
20862086
pub c_variadic: bool,
20872087
/// Does the function have an implicit self?
20882088
pub implicit_self: ImplicitSelfKind,
@@ -2148,7 +2148,7 @@ impl Defaultness {
21482148
}
21492149

21502150
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
2151-
pub enum FunctionRetTy<'hir> {
2151+
pub enum FnRetTy<'hir> {
21522152
/// Return type is not specified.
21532153
///
21542154
/// Functions default to `()` and
@@ -2159,7 +2159,7 @@ pub enum FunctionRetTy<'hir> {
21592159
Return(&'hir Ty<'hir>),
21602160
}
21612161

2162-
impl fmt::Display for FunctionRetTy<'_> {
2162+
impl fmt::Display for FnRetTy<'_> {
21632163
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21642164
match self {
21652165
Self::Return(ref ty) => print::to_string(print::NO_ANN, |s| s.print_type(ty)).fmt(f),
@@ -2168,7 +2168,7 @@ impl fmt::Display for FunctionRetTy<'_> {
21682168
}
21692169
}
21702170

2171-
impl FunctionRetTy<'_> {
2171+
impl FnRetTy<'_> {
21722172
pub fn span(&self) -> Span {
21732173
match *self {
21742174
Self::DefaultReturn(span) => span,

0 commit comments

Comments
 (0)