Skip to content

Commit

Permalink
Auto merge of rust-lang#111210 - matthiaskrgr:rollup-doquh2n, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

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
  • Loading branch information
bors committed May 4, 2023
2 parents eac3558 + 75e8f87 commit eb7a743
Show file tree
Hide file tree
Showing 49 changed files with 1,084 additions and 50 deletions.
10 changes: 9 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4739,6 +4739,15 @@ dependencies = [
"unicode-xid",
]

[[package]]
name = "sysroot"
version = "0.0.0"
dependencies = [
"proc_macro",
"std",
"test",
]

[[package]]
name = "tar"
version = "0.4.38"
Expand Down Expand Up @@ -4823,7 +4832,6 @@ dependencies = [
"getopts",
"panic_abort",
"panic_unwind",
"proc_macro",
"std",
]

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = [
"compiler/rustc",
"library/std",
"library/test",
"library/sysroot",
"src/rustdoc-json-types",
"src/tools/build_helper",
"src/tools/cargotest",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/def_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {

// `PlaceMention` and `AscribeUserType` both evaluate the place, which must not
// contain dangling references.
PlaceContext::NonUse(NonUseContext::PlaceMention) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention) |
PlaceContext::NonUse(NonUseContext::AscribeUserTy) |

PlaceContext::MutatingUse(MutatingUseContext::AddressOf) |
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_borrowck/src/renumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ impl<'a, 'tcx> MutVisitor<'tcx> for RegionRenumberer<'a, 'tcx> {
debug!(?region);
}

#[instrument(skip(self), level = "debug")]
fn visit_ty_const(&mut self, ct: &mut ty::Const<'tcx>, location: Location) {
let old_ct = *ct;
*ct = self.renumber_regions(old_ct, || RegionCtxt::Location(location));

debug!(?ct);
}

#[instrument(skip(self), level = "debug")]
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, location: Location) {
let literal = constant.literal;
Expand Down
15 changes: 10 additions & 5 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,12 +772,10 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {

match context {
PlaceContext::MutatingUse(_) => ty::Invariant,
PlaceContext::NonUse(StorageDead | StorageLive | PlaceMention | VarDebugInfo) => {
ty::Invariant
}
PlaceContext::NonUse(StorageDead | StorageLive | VarDebugInfo) => ty::Invariant,
PlaceContext::NonMutatingUse(
Inspect | Copy | Move | SharedBorrow | ShallowBorrow | UniqueBorrow | AddressOf
| Projection,
Inspect | Copy | Move | PlaceMention | SharedBorrow | ShallowBorrow | UniqueBorrow
| AddressOf | Projection,
) => ty::Covariant,
PlaceContext::NonUse(AscribeUserTy) => ty::Covariant,
}
Expand Down Expand Up @@ -1803,6 +1801,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Rvalue::Repeat(operand, len) => {
self.check_operand(operand, location);

let array_ty = rvalue.ty(body.local_decls(), tcx);
self.prove_predicate(
ty::PredicateKind::WellFormed(array_ty.into()),
Locations::Single(location),
ConstraintCategory::Boring,
);

// If the length cannot be evaluated we must assume that the length can be larger
// than 1.
// If the length is larger than 1, the repeat expression will need to copy the
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
self.assign(local, DefLocation::Body(location));
}

PlaceContext::NonUse(_) | PlaceContext::MutatingUse(MutatingUseContext::Retag) => {}
PlaceContext::NonUse(_)
| PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention)
| PlaceContext::MutatingUse(MutatingUseContext::Retag) => {}

PlaceContext::NonMutatingUse(
NonMutatingUseContext::Copy | NonMutatingUseContext::Move,
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

self.check_repeat_element_needs_copy_bound(element, count, element_ty);

self.register_wf_obligation(
tcx.mk_array_with_const_len(t, count).into(),
expr.span,
traits::WellFormed(None),
);

tcx.mk_array_with_const_len(t, count)
}

Expand Down
30 changes: 25 additions & 5 deletions compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ macro_rules! make_mir_visitor {
self.super_constant(constant, location);
}

fn visit_ty_const(
&mut self,
ct: $( & $mutability)? ty::Const<'tcx>,
location: Location,
) {
self.super_ty_const(ct, location);
}

fn visit_span(
&mut self,
span: $(& $mutability)? Span,
Expand Down Expand Up @@ -410,7 +418,7 @@ macro_rules! make_mir_visitor {
StatementKind::PlaceMention(place) => {
self.visit_place(
place,
PlaceContext::NonUse(NonUseContext::PlaceMention),
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention),
location
);
}
Expand Down Expand Up @@ -625,8 +633,9 @@ macro_rules! make_mir_visitor {
self.visit_operand(operand, location);
}

Rvalue::Repeat(value, _) => {
Rvalue::Repeat(value, ct) => {
self.visit_operand(value, location);
self.visit_ty_const($(&$mutability)? *ct, location);
}

Rvalue::ThreadLocalRef(_) => {}
Expand Down Expand Up @@ -878,12 +887,20 @@ macro_rules! make_mir_visitor {
self.visit_span($(& $mutability)? *span);
drop(user_ty); // no visit method for this
match literal {
ConstantKind::Ty(_) => {}
ConstantKind::Ty(ct) => self.visit_ty_const($(&$mutability)? *ct, location),
ConstantKind::Val(_, ty) => self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)),
ConstantKind::Unevaluated(_, ty) => self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)),
}
}

fn super_ty_const(
&mut self,
_ct: $(& $mutability)? ty::Const<'tcx>,
_location: Location,
) {

}

fn super_span(&mut self, _span: $(& $mutability)? Span) {
}

Expand Down Expand Up @@ -1251,6 +1268,11 @@ pub enum NonMutatingUseContext {
UniqueBorrow,
/// AddressOf for *const pointer.
AddressOf,
/// PlaceMention statement.
///
/// This statement is executed as a check that the `Place` is live without reading from it,
/// so it must be considered as a non-mutating use.
PlaceMention,
/// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place.
/// For example, the projection `x.y` is not marked as a mutation in these cases:
/// ```ignore (illustrative)
Expand Down Expand Up @@ -1301,8 +1323,6 @@ pub enum NonUseContext {
AscribeUserTy,
/// The data of a user variable, for debug info.
VarDebugInfo,
/// PlaceMention statement.
PlaceMention,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_dataflow/src/impls/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ impl DefUse {
| NonMutatingUseContext::Copy
| NonMutatingUseContext::Inspect
| NonMutatingUseContext::Move
| NonMutatingUseContext::PlaceMention
| NonMutatingUseContext::ShallowBorrow
| NonMutatingUseContext::SharedBorrow
| NonMutatingUseContext::UniqueBorrow,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_transform/src/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ impl Visitor<'_> for CanConstProp {
| NonMutatingUse(NonMutatingUseContext::Move)
| NonMutatingUse(NonMutatingUseContext::Inspect)
| NonMutatingUse(NonMutatingUseContext::Projection)
| NonMutatingUse(NonMutatingUseContext::PlaceMention)
| NonUse(_) => {}

// These could be propagated with a smarter analysis or just some careful thinking about
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
}
visit::walk_ty(self, ty)
}

// A type may have an expression as a const generic argument.
// We do not want to recurse into those.
fn visit_expr(&mut self, _: &'a Expr) {}
}

let impl_self = self
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
#![feature(array_into_iter_constructors)]
#![feature(array_methods)]
#![feature(array_windows)]
#![feature(ascii_char)]
#![feature(assert_matches)]
#![feature(async_iterator)]
#![feature(coerce_unsized)]
Expand Down
9 changes: 9 additions & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2526,6 +2526,15 @@ impl<T: fmt::Display + ?Sized> ToString for T {
}
}

#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "ascii_char", issue = "110998")]
impl ToString for core::ascii::Char {
#[inline]
fn to_string(&self) -> String {
self.as_str().to_owned()
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "char_to_string_specialization", since = "1.46.0")]
impl ToString for char {
Expand Down
34 changes: 34 additions & 0 deletions library/core/src/array/ascii.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::ascii;

#[cfg(not(test))]
impl<const N: usize> [u8; N] {
/// Converts this array of bytes into a array of ASCII characters,
/// or returns `None` if any of the characters is non-ASCII.
#[unstable(feature = "ascii_char", issue = "110998")]
#[must_use]
#[inline]
pub fn as_ascii(&self) -> Option<&[ascii::Char; N]> {
if self.is_ascii() {
// SAFETY: Just checked that it's ASCII
Some(unsafe { self.as_ascii_unchecked() })
} else {
None
}
}

/// Converts this array of bytes into a array of ASCII characters,
/// without checking whether they're valid.
///
/// # Safety
///
/// Every byte in the array must be in `0..=127`, or else this is UB.
#[unstable(feature = "ascii_char", issue = "110998")]
#[must_use]
#[inline]
pub const unsafe fn as_ascii_unchecked(&self) -> &[ascii::Char; N] {
let byte_ptr: *const [u8; N] = self;
let ascii_ptr = byte_ptr as *const [ascii::Char; N];
// SAFETY: The caller promised all the bytes are ASCII
unsafe { &*ascii_ptr }
}
}
1 change: 1 addition & 0 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::ops::{
};
use crate::slice::{Iter, IterMut};

mod ascii;
mod drain;
mod equality;
mod iter;
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ use crate::fmt;
use crate::iter::FusedIterator;
use crate::num::NonZeroUsize;

mod ascii_char;
#[unstable(feature = "ascii_char", issue = "110998")]
pub use ascii_char::AsciiChar as Char;

/// An iterator over the escaped version of a byte.
///
/// This `struct` is created by the [`escape_default`] function. See its
Expand Down
Loading

0 comments on commit eb7a743

Please sign in to comment.