Skip to content

Commit eb7a743

Browse files
committed
Auto merge of rust-lang#111210 - matthiaskrgr:rollup-doquh2n, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#108865 (Add a `sysroot` crate to represent the standard library crates) - rust-lang#110651 (libtest: include test output in junit xml reports) - rust-lang#110826 (Make PlaceMention a non-mutating use.) - rust-lang#110982 (Do not recurse into const generic args when resolving self lifetime elision.) - rust-lang#111009 (Add `ascii::Char` (ACP#179)) - rust-lang#111100 (check array type of repeat exprs is wf) - rust-lang#111186 (Add `is_positive` method for signed non-zero integers.) - rust-lang#111201 (bootstrap: add .gitmodules to the sources) Failed merges: - rust-lang#110954 (Reject borrows of projections in ConstProp.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents eac3558 + 75e8f87 commit eb7a743

File tree

49 files changed

+1084
-50
lines changed

Some content is hidden

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

49 files changed

+1084
-50
lines changed

Cargo.lock

+9-1
Original file line numberDiff line numberDiff line change
@@ -4739,6 +4739,15 @@ dependencies = [
47394739
"unicode-xid",
47404740
]
47414741

4742+
[[package]]
4743+
name = "sysroot"
4744+
version = "0.0.0"
4745+
dependencies = [
4746+
"proc_macro",
4747+
"std",
4748+
"test",
4749+
]
4750+
47424751
[[package]]
47434752
name = "tar"
47444753
version = "0.4.38"
@@ -4823,7 +4832,6 @@ dependencies = [
48234832
"getopts",
48244833
"panic_abort",
48254834
"panic_unwind",
4826-
"proc_macro",
48274835
"std",
48284836
]
48294837

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
members = [
33
"compiler/rustc",
44
"library/std",
5-
"library/test",
5+
"library/sysroot",
66
"src/rustdoc-json-types",
77
"src/tools/build_helper",
88
"src/tools/cargotest",

compiler/rustc_borrowck/src/def_use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
5454

5555
// `PlaceMention` and `AscribeUserType` both evaluate the place, which must not
5656
// contain dangling references.
57-
PlaceContext::NonUse(NonUseContext::PlaceMention) |
57+
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention) |
5858
PlaceContext::NonUse(NonUseContext::AscribeUserTy) |
5959

6060
PlaceContext::MutatingUse(MutatingUseContext::AddressOf) |

compiler/rustc_borrowck/src/renumber.rs

+8
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ impl<'a, 'tcx> MutVisitor<'tcx> for RegionRenumberer<'a, 'tcx> {
108108
debug!(?region);
109109
}
110110

111+
#[instrument(skip(self), level = "debug")]
112+
fn visit_ty_const(&mut self, ct: &mut ty::Const<'tcx>, location: Location) {
113+
let old_ct = *ct;
114+
*ct = self.renumber_regions(old_ct, || RegionCtxt::Location(location));
115+
116+
debug!(?ct);
117+
}
118+
111119
#[instrument(skip(self), level = "debug")]
112120
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, location: Location) {
113121
let literal = constant.literal;

compiler/rustc_borrowck/src/type_check/mod.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -772,12 +772,10 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
772772

773773
match context {
774774
PlaceContext::MutatingUse(_) => ty::Invariant,
775-
PlaceContext::NonUse(StorageDead | StorageLive | PlaceMention | VarDebugInfo) => {
776-
ty::Invariant
777-
}
775+
PlaceContext::NonUse(StorageDead | StorageLive | VarDebugInfo) => ty::Invariant,
778776
PlaceContext::NonMutatingUse(
779-
Inspect | Copy | Move | SharedBorrow | ShallowBorrow | UniqueBorrow | AddressOf
780-
| Projection,
777+
Inspect | Copy | Move | PlaceMention | SharedBorrow | ShallowBorrow | UniqueBorrow
778+
| AddressOf | Projection,
781779
) => ty::Covariant,
782780
PlaceContext::NonUse(AscribeUserTy) => ty::Covariant,
783781
}
@@ -1803,6 +1801,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18031801
Rvalue::Repeat(operand, len) => {
18041802
self.check_operand(operand, location);
18051803

1804+
let array_ty = rvalue.ty(body.local_decls(), tcx);
1805+
self.prove_predicate(
1806+
ty::PredicateKind::WellFormed(array_ty.into()),
1807+
Locations::Single(location),
1808+
ConstraintCategory::Boring,
1809+
);
1810+
18061811
// If the length cannot be evaluated we must assume that the length can be larger
18071812
// than 1.
18081813
// If the length is larger than 1, the repeat expression will need to copy the

compiler/rustc_codegen_ssa/src/mir/analyze.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
203203
self.assign(local, DefLocation::Body(location));
204204
}
205205

206-
PlaceContext::NonUse(_) | PlaceContext::MutatingUse(MutatingUseContext::Retag) => {}
206+
PlaceContext::NonUse(_)
207+
| PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention)
208+
| PlaceContext::MutatingUse(MutatingUseContext::Retag) => {}
207209

208210
PlaceContext::NonMutatingUse(
209211
NonMutatingUseContext::Copy | NonMutatingUseContext::Move,

compiler/rustc_hir_typeck/src/expr.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14261426

14271427
self.check_repeat_element_needs_copy_bound(element, count, element_ty);
14281428

1429+
self.register_wf_obligation(
1430+
tcx.mk_array_with_const_len(t, count).into(),
1431+
expr.span,
1432+
traits::WellFormed(None),
1433+
);
1434+
14291435
tcx.mk_array_with_const_len(t, count)
14301436
}
14311437

compiler/rustc_middle/src/mir/visit.rs

+25-5
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ macro_rules! make_mir_visitor {
192192
self.super_constant(constant, location);
193193
}
194194

195+
fn visit_ty_const(
196+
&mut self,
197+
ct: $( & $mutability)? ty::Const<'tcx>,
198+
location: Location,
199+
) {
200+
self.super_ty_const(ct, location);
201+
}
202+
195203
fn visit_span(
196204
&mut self,
197205
span: $(& $mutability)? Span,
@@ -410,7 +418,7 @@ macro_rules! make_mir_visitor {
410418
StatementKind::PlaceMention(place) => {
411419
self.visit_place(
412420
place,
413-
PlaceContext::NonUse(NonUseContext::PlaceMention),
421+
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention),
414422
location
415423
);
416424
}
@@ -625,8 +633,9 @@ macro_rules! make_mir_visitor {
625633
self.visit_operand(operand, location);
626634
}
627635

628-
Rvalue::Repeat(value, _) => {
636+
Rvalue::Repeat(value, ct) => {
629637
self.visit_operand(value, location);
638+
self.visit_ty_const($(&$mutability)? *ct, location);
630639
}
631640

632641
Rvalue::ThreadLocalRef(_) => {}
@@ -878,12 +887,20 @@ macro_rules! make_mir_visitor {
878887
self.visit_span($(& $mutability)? *span);
879888
drop(user_ty); // no visit method for this
880889
match literal {
881-
ConstantKind::Ty(_) => {}
890+
ConstantKind::Ty(ct) => self.visit_ty_const($(&$mutability)? *ct, location),
882891
ConstantKind::Val(_, ty) => self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)),
883892
ConstantKind::Unevaluated(_, ty) => self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)),
884893
}
885894
}
886895

896+
fn super_ty_const(
897+
&mut self,
898+
_ct: $(& $mutability)? ty::Const<'tcx>,
899+
_location: Location,
900+
) {
901+
902+
}
903+
887904
fn super_span(&mut self, _span: $(& $mutability)? Span) {
888905
}
889906

@@ -1251,6 +1268,11 @@ pub enum NonMutatingUseContext {
12511268
UniqueBorrow,
12521269
/// AddressOf for *const pointer.
12531270
AddressOf,
1271+
/// PlaceMention statement.
1272+
///
1273+
/// This statement is executed as a check that the `Place` is live without reading from it,
1274+
/// so it must be considered as a non-mutating use.
1275+
PlaceMention,
12541276
/// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place.
12551277
/// For example, the projection `x.y` is not marked as a mutation in these cases:
12561278
/// ```ignore (illustrative)
@@ -1301,8 +1323,6 @@ pub enum NonUseContext {
13011323
AscribeUserTy,
13021324
/// The data of a user variable, for debug info.
13031325
VarDebugInfo,
1304-
/// PlaceMention statement.
1305-
PlaceMention,
13061326
}
13071327

13081328
#[derive(Copy, Clone, Debug, PartialEq, Eq)]

compiler/rustc_mir_dataflow/src/impls/liveness.rs

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ impl DefUse {
197197
| NonMutatingUseContext::Copy
198198
| NonMutatingUseContext::Inspect
199199
| NonMutatingUseContext::Move
200+
| NonMutatingUseContext::PlaceMention
200201
| NonMutatingUseContext::ShallowBorrow
201202
| NonMutatingUseContext::SharedBorrow
202203
| NonMutatingUseContext::UniqueBorrow,

compiler/rustc_mir_transform/src/const_prop.rs

+1
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ impl Visitor<'_> for CanConstProp {
752752
| NonMutatingUse(NonMutatingUseContext::Move)
753753
| NonMutatingUse(NonMutatingUseContext::Inspect)
754754
| NonMutatingUse(NonMutatingUseContext::Projection)
755+
| NonMutatingUse(NonMutatingUseContext::PlaceMention)
755756
| NonUse(_) => {}
756757

757758
// These could be propagated with a smarter analysis or just some careful thinking about

compiler/rustc_resolve/src/late.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20702070
}
20712071
visit::walk_ty(self, ty)
20722072
}
2073+
2074+
// A type may have an expression as a const generic argument.
2075+
// We do not want to recurse into those.
2076+
fn visit_expr(&mut self, _: &'a Expr) {}
20732077
}
20742078

20752079
let impl_self = self

library/alloc/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#![feature(array_into_iter_constructors)]
102102
#![feature(array_methods)]
103103
#![feature(array_windows)]
104+
#![feature(ascii_char)]
104105
#![feature(assert_matches)]
105106
#![feature(async_iterator)]
106107
#![feature(coerce_unsized)]

library/alloc/src/string.rs

+9
Original file line numberDiff line numberDiff line change
@@ -2526,6 +2526,15 @@ impl<T: fmt::Display + ?Sized> ToString for T {
25262526
}
25272527
}
25282528

2529+
#[cfg(not(no_global_oom_handling))]
2530+
#[unstable(feature = "ascii_char", issue = "110998")]
2531+
impl ToString for core::ascii::Char {
2532+
#[inline]
2533+
fn to_string(&self) -> String {
2534+
self.as_str().to_owned()
2535+
}
2536+
}
2537+
25292538
#[cfg(not(no_global_oom_handling))]
25302539
#[stable(feature = "char_to_string_specialization", since = "1.46.0")]
25312540
impl ToString for char {

library/core/src/array/ascii.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use crate::ascii;
2+
3+
#[cfg(not(test))]
4+
impl<const N: usize> [u8; N] {
5+
/// Converts this array of bytes into a array of ASCII characters,
6+
/// or returns `None` if any of the characters is non-ASCII.
7+
#[unstable(feature = "ascii_char", issue = "110998")]
8+
#[must_use]
9+
#[inline]
10+
pub fn as_ascii(&self) -> Option<&[ascii::Char; N]> {
11+
if self.is_ascii() {
12+
// SAFETY: Just checked that it's ASCII
13+
Some(unsafe { self.as_ascii_unchecked() })
14+
} else {
15+
None
16+
}
17+
}
18+
19+
/// Converts this array of bytes into a array of ASCII characters,
20+
/// without checking whether they're valid.
21+
///
22+
/// # Safety
23+
///
24+
/// Every byte in the array must be in `0..=127`, or else this is UB.
25+
#[unstable(feature = "ascii_char", issue = "110998")]
26+
#[must_use]
27+
#[inline]
28+
pub const unsafe fn as_ascii_unchecked(&self) -> &[ascii::Char; N] {
29+
let byte_ptr: *const [u8; N] = self;
30+
let ascii_ptr = byte_ptr as *const [ascii::Char; N];
31+
// SAFETY: The caller promised all the bytes are ASCII
32+
unsafe { &*ascii_ptr }
33+
}
34+
}

library/core/src/array/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::ops::{
1717
};
1818
use crate::slice::{Iter, IterMut};
1919

20+
mod ascii;
2021
mod drain;
2122
mod equality;
2223
mod iter;

library/core/src/ascii.rs

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ use crate::fmt;
1414
use crate::iter::FusedIterator;
1515
use crate::num::NonZeroUsize;
1616

17+
mod ascii_char;
18+
#[unstable(feature = "ascii_char", issue = "110998")]
19+
pub use ascii_char::AsciiChar as Char;
20+
1721
/// An iterator over the escaped version of a byte.
1822
///
1923
/// This `struct` is created by the [`escape_default`] function. See its

0 commit comments

Comments
 (0)