Skip to content

Commit 7852822

Browse files
committed
Auto merge of rust-lang#124710 - matthiaskrgr:rollup-per6u61, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#122441 (Improve several `Read` implementations) - rust-lang#124584 (Various improvements to entrypoint code) - rust-lang#124699 (Use `unchecked_sub` in `split_at`) - rust-lang#124704 (Fix ignored tests for formatting) - rust-lang#124709 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d7ea278 + ee62903 commit 7852822

File tree

103 files changed

+929
-717
lines changed

Some content is hidden

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

103 files changed

+929
-717
lines changed

Cargo.lock

+79-9
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,28 @@ dependencies = [
512512
"windows-targets 0.52.4",
513513
]
514514

515+
[[package]]
516+
name = "chrono-tz"
517+
version = "0.9.0"
518+
source = "registry+https://github.com/rust-lang/crates.io-index"
519+
checksum = "93698b29de5e97ad0ae26447b344c482a7284c737d9ddc5f9e52b74a336671bb"
520+
dependencies = [
521+
"chrono",
522+
"chrono-tz-build",
523+
"phf 0.11.2",
524+
]
525+
526+
[[package]]
527+
name = "chrono-tz-build"
528+
version = "0.3.0"
529+
source = "registry+https://github.com/rust-lang/crates.io-index"
530+
checksum = "0c088aee841df9c3041febbb73934cfc39708749bf96dc827e3359cd39ef11b1"
531+
dependencies = [
532+
"parse-zoneinfo",
533+
"phf 0.11.2",
534+
"phf_codegen 0.11.2",
535+
]
536+
515537
[[package]]
516538
name = "cipher"
517539
version = "0.4.4"
@@ -2318,8 +2340,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
23182340
checksum = "7a2629bb1404f3d34c2e921f21fd34ba00b206124c81f65c50b43b6aaefeb016"
23192341
dependencies = [
23202342
"log",
2321-
"phf",
2322-
"phf_codegen",
2343+
"phf 0.10.1",
2344+
"phf_codegen 0.10.0",
23232345
"string_cache",
23242346
"string_cache_codegen",
23252347
"tendril",
@@ -2480,6 +2502,7 @@ version = "0.1.0"
24802502
dependencies = [
24812503
"aes",
24822504
"chrono",
2505+
"chrono-tz",
24832506
"colored",
24842507
"ctrlc",
24852508
"directories",
@@ -2835,6 +2858,15 @@ dependencies = [
28352858
"windows-targets 0.48.5",
28362859
]
28372860

2861+
[[package]]
2862+
name = "parse-zoneinfo"
2863+
version = "0.3.1"
2864+
source = "registry+https://github.com/rust-lang/crates.io-index"
2865+
checksum = "1f2a05b18d44e2957b88f96ba460715e295bc1d7510468a2f3d3b44535d26c24"
2866+
dependencies = [
2867+
"regex",
2868+
]
2869+
28382870
[[package]]
28392871
name = "pathdiff"
28402872
version = "0.2.1"
@@ -2907,7 +2939,16 @@ version = "0.10.1"
29072939
source = "registry+https://github.com/rust-lang/crates.io-index"
29082940
checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259"
29092941
dependencies = [
2910-
"phf_shared",
2942+
"phf_shared 0.10.0",
2943+
]
2944+
2945+
[[package]]
2946+
name = "phf"
2947+
version = "0.11.2"
2948+
source = "registry+https://github.com/rust-lang/crates.io-index"
2949+
checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"
2950+
dependencies = [
2951+
"phf_shared 0.11.2",
29112952
]
29122953

29132954
[[package]]
@@ -2916,8 +2957,18 @@ version = "0.10.0"
29162957
source = "registry+https://github.com/rust-lang/crates.io-index"
29172958
checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd"
29182959
dependencies = [
2919-
"phf_generator",
2920-
"phf_shared",
2960+
"phf_generator 0.10.0",
2961+
"phf_shared 0.10.0",
2962+
]
2963+
2964+
[[package]]
2965+
name = "phf_codegen"
2966+
version = "0.11.2"
2967+
source = "registry+https://github.com/rust-lang/crates.io-index"
2968+
checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a"
2969+
dependencies = [
2970+
"phf_generator 0.11.2",
2971+
"phf_shared 0.11.2",
29212972
]
29222973

29232974
[[package]]
@@ -2926,7 +2977,17 @@ version = "0.10.0"
29262977
source = "registry+https://github.com/rust-lang/crates.io-index"
29272978
checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
29282979
dependencies = [
2929-
"phf_shared",
2980+
"phf_shared 0.10.0",
2981+
"rand",
2982+
]
2983+
2984+
[[package]]
2985+
name = "phf_generator"
2986+
version = "0.11.2"
2987+
source = "registry+https://github.com/rust-lang/crates.io-index"
2988+
checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0"
2989+
dependencies = [
2990+
"phf_shared 0.11.2",
29302991
"rand",
29312992
]
29322993

@@ -2939,6 +3000,15 @@ dependencies = [
29393000
"siphasher",
29403001
]
29413002

3003+
[[package]]
3004+
name = "phf_shared"
3005+
version = "0.11.2"
3006+
source = "registry+https://github.com/rust-lang/crates.io-index"
3007+
checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b"
3008+
dependencies = [
3009+
"siphasher",
3010+
]
3011+
29423012
[[package]]
29433013
name = "pin-project-lite"
29443014
version = "0.2.14"
@@ -5285,7 +5355,7 @@ dependencies = [
52855355
"new_debug_unreachable",
52865356
"once_cell",
52875357
"parking_lot",
5288-
"phf_shared",
5358+
"phf_shared 0.10.0",
52895359
"precomputed-hash",
52905360
"serde",
52915361
]
@@ -5296,8 +5366,8 @@ version = "0.5.2"
52965366
source = "registry+https://github.com/rust-lang/crates.io-index"
52975367
checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988"
52985368
dependencies = [
5299-
"phf_generator",
5300-
"phf_shared",
5369+
"phf_generator 0.10.0",
5370+
"phf_shared 0.10.0",
53015371
"proc-macro2",
53025372
"quote",
53035373
]

compiler/rustc_ast/src/entry.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,35 @@ use rustc_span::Symbol;
44

55
#[derive(Debug)]
66
pub enum EntryPointType {
7+
/// This function is not an entrypoint.
78
None,
9+
/// This is a function called `main` at the root level.
10+
/// ```
11+
/// fn main() {}
12+
/// ```
813
MainNamed,
14+
/// This is a function with the `#[rustc_main]` attribute.
15+
/// Used by the testing harness to create the test entrypoint.
16+
/// ```ignore (clashes with test entrypoint)
17+
/// #[rustc_main]
18+
/// fn main() {}
19+
/// ```
920
RustcMainAttr,
21+
/// This is a function with the `#[start]` attribute.
22+
/// ```ignore (clashes with test entrypoint)
23+
/// #[start]
24+
/// fn main() {}
25+
/// ```
1026
Start,
11-
OtherMain, // Not an entry point, but some other function named main
27+
/// This function is **not** an entrypoint but simply named `main` (not at the root).
28+
/// This is only used for diagnostics.
29+
/// ```
30+
/// #[allow(dead_code)]
31+
/// mod meow {
32+
/// fn main() {}
33+
/// }
34+
/// ```
35+
OtherMain,
1236
}
1337

1438
pub fn entry_point_type(

compiler/rustc_builtin_macros/src/test_harness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ fn generate_test_harness(
266266
///
267267
/// By default this expands to
268268
///
269-
/// ```ignore UNSOLVED (I think I still need guidance for this one. Is it correct? Do we try to make it run? How do we nicely fill it out?)
269+
/// ```ignore (messes with test internals)
270270
/// #[rustc_main]
271271
/// pub fn main() {
272272
/// extern crate test;

compiler/rustc_passes/messages.ftl

-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ passes_attr_crate_level =
4949
passes_attr_only_in_functions =
5050
`{$attr}` attribute can only be used on functions
5151
52-
passes_attr_only_on_main =
53-
`{$attr}` attribute can only be used on `fn main()`
54-
55-
passes_attr_only_on_root_main =
56-
`{$attr}` attribute can only be used on root `fn main()`
57-
5852
passes_both_ffi_const_and_pure =
5953
`#[ffi_const]` function cannot be `#[ffi_pure]`
6054

compiler/rustc_passes/src/entry.rs

+23-19
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use crate::errors::{
1818
struct EntryContext<'tcx> {
1919
tcx: TyCtxt<'tcx>,
2020

21-
/// The function that has attribute named `main`.
22-
attr_main_fn: Option<(LocalDefId, Span)>,
21+
/// The function has the `#[rustc_main]` attribute.
22+
rustc_main_fn: Option<(LocalDefId, Span)>,
2323

24-
/// The function that has the attribute 'start' on it.
24+
/// The function that has the attribute `#[start]` on it.
2525
start_fn: Option<(LocalDefId, Span)>,
2626

2727
/// The functions that one might think are `main` but aren't, e.g.
@@ -42,10 +42,10 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> {
4242
}
4343

4444
let mut ctxt =
45-
EntryContext { tcx, attr_main_fn: None, start_fn: None, non_main_fns: Vec::new() };
45+
EntryContext { tcx, rustc_main_fn: None, start_fn: None, non_main_fns: Vec::new() };
4646

4747
for id in tcx.hir().items() {
48-
find_item(id, &mut ctxt);
48+
check_and_search_item(id, &mut ctxt);
4949
}
5050

5151
configure_main(tcx, &ctxt)
@@ -56,7 +56,16 @@ fn attr_span_by_symbol(ctxt: &EntryContext<'_>, id: ItemId, sym: Symbol) -> Opti
5656
attr::find_by_name(attrs, sym).map(|attr| attr.span)
5757
}
5858

59-
fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
59+
fn check_and_search_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
60+
if !matches!(ctxt.tcx.def_kind(id.owner_id), DefKind::Fn) {
61+
for attr in [sym::start, sym::rustc_main] {
62+
if let Some(span) = attr_span_by_symbol(ctxt, id, attr) {
63+
ctxt.tcx.dcx().emit_err(AttrOnlyInFunctions { span, attr });
64+
}
65+
}
66+
return;
67+
}
68+
6069
let at_root = ctxt.tcx.opt_local_parent(id.owner_id.def_id) == Some(CRATE_DEF_ID);
6170

6271
let attrs = ctxt.tcx.hir().attrs(id.hir_id());
@@ -65,26 +74,20 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
6574
at_root,
6675
ctxt.tcx.opt_item_name(id.owner_id.to_def_id()),
6776
);
77+
6878
match entry_point_type {
69-
EntryPointType::None => (),
70-
_ if !matches!(ctxt.tcx.def_kind(id.owner_id), DefKind::Fn) => {
71-
for attr in [sym::start, sym::rustc_main] {
72-
if let Some(span) = attr_span_by_symbol(ctxt, id, attr) {
73-
ctxt.tcx.dcx().emit_err(AttrOnlyInFunctions { span, attr });
74-
}
75-
}
76-
}
77-
EntryPointType::MainNamed => (),
79+
EntryPointType::None => {}
80+
EntryPointType::MainNamed => {}
7881
EntryPointType::OtherMain => {
7982
ctxt.non_main_fns.push(ctxt.tcx.def_span(id.owner_id));
8083
}
8184
EntryPointType::RustcMainAttr => {
82-
if ctxt.attr_main_fn.is_none() {
83-
ctxt.attr_main_fn = Some((id.owner_id.def_id, ctxt.tcx.def_span(id.owner_id)));
85+
if ctxt.rustc_main_fn.is_none() {
86+
ctxt.rustc_main_fn = Some((id.owner_id.def_id, ctxt.tcx.def_span(id.owner_id)));
8487
} else {
8588
ctxt.tcx.dcx().emit_err(MultipleRustcMain {
8689
span: ctxt.tcx.def_span(id.owner_id.to_def_id()),
87-
first: ctxt.attr_main_fn.unwrap().1,
90+
first: ctxt.rustc_main_fn.unwrap().1,
8891
additional: ctxt.tcx.def_span(id.owner_id.to_def_id()),
8992
});
9093
}
@@ -107,10 +110,11 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
107110
fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId, EntryFnType)> {
108111
if let Some((def_id, _)) = visitor.start_fn {
109112
Some((def_id.to_def_id(), EntryFnType::Start))
110-
} else if let Some((local_def_id, _)) = visitor.attr_main_fn {
113+
} else if let Some((local_def_id, _)) = visitor.rustc_main_fn {
111114
let def_id = local_def_id.to_def_id();
112115
Some((def_id, EntryFnType::Main { sigpipe: sigpipe(tcx) }))
113116
} else {
117+
// The actual resolution of main happens in the resolver, this here
114118
if let Some(main_def) = tcx.resolutions(()).main_def
115119
&& let Some(def_id) = main_def.opt_fn_def_id()
116120
{

compiler/rustc_passes/src/errors.rs

-16
Original file line numberDiff line numberDiff line change
@@ -1206,22 +1206,6 @@ pub struct NakedFunctionsMustUseNoreturn {
12061206
pub last_span: Span,
12071207
}
12081208

1209-
#[derive(Diagnostic)]
1210-
#[diag(passes_attr_only_on_main)]
1211-
pub struct AttrOnlyOnMain {
1212-
#[primary_span]
1213-
pub span: Span,
1214-
pub attr: Symbol,
1215-
}
1216-
1217-
#[derive(Diagnostic)]
1218-
#[diag(passes_attr_only_on_root_main)]
1219-
pub struct AttrOnlyOnRootMain {
1220-
#[primary_span]
1221-
pub span: Span,
1222-
pub attr: Symbol,
1223-
}
1224-
12251209
#[derive(Diagnostic)]
12261210
#[diag(passes_attr_only_in_functions)]
12271211
pub struct AttrOnlyInFunctions {

library/core/src/slice/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use crate::cmp::Ordering::{self, Equal, Greater, Less};
1010
use crate::fmt;
1111
use crate::hint;
12-
use crate::intrinsics::exact_div;
12+
use crate::intrinsics::{exact_div, unchecked_sub};
1313
use crate::mem::{self, SizedTypeProperties};
1414
use crate::num::NonZero;
1515
use crate::ops::{Bound, OneSidedRange, Range, RangeBounds};
@@ -1983,7 +1983,7 @@ impl<T> [T] {
19831983
);
19841984

19851985
// SAFETY: Caller has to check that `0 <= mid <= self.len()`
1986-
unsafe { (from_raw_parts(ptr, mid), from_raw_parts(ptr.add(mid), len - mid)) }
1986+
unsafe { (from_raw_parts(ptr, mid), from_raw_parts(ptr.add(mid), unchecked_sub(len, mid))) }
19871987
}
19881988

19891989
/// Divides one mutable slice into two at an index, without doing bounds checking.
@@ -2035,7 +2035,12 @@ impl<T> [T] {
20352035
//
20362036
// `[ptr; mid]` and `[mid; len]` are not overlapping, so returning a mutable reference
20372037
// is fine.
2038-
unsafe { (from_raw_parts_mut(ptr, mid), from_raw_parts_mut(ptr.add(mid), len - mid)) }
2038+
unsafe {
2039+
(
2040+
from_raw_parts_mut(ptr, mid),
2041+
from_raw_parts_mut(ptr.add(mid), unchecked_sub(len, mid)),
2042+
)
2043+
}
20392044
}
20402045

20412046
/// Divides one slice into two at an index, returning `None` if the slice is

library/std/src/io/cursor.rs

+21
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,27 @@ where
364364
self.pos += n as u64;
365365
Ok(())
366366
}
367+
368+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
369+
let content = self.remaining_slice();
370+
let len = content.len();
371+
buf.try_reserve(len)?;
372+
buf.extend_from_slice(content);
373+
self.pos += len as u64;
374+
375+
Ok(len)
376+
}
377+
378+
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
379+
let content =
380+
crate::str::from_utf8(self.remaining_slice()).map_err(|_| io::Error::INVALID_UTF8)?;
381+
let len = content.len();
382+
buf.try_reserve(len)?;
383+
buf.push_str(content);
384+
self.pos += len as u64;
385+
386+
Ok(len)
387+
}
367388
}
368389

369390
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)