Skip to content

Rollup of 8 pull requests #111210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
May 4, 2023
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d77f636
libtest: add tests for junit output format
durin42 Apr 21, 2023
610f827
junit: also include per-case stdout in xml
durin42 Apr 21, 2023
fd4c81f
Add a `sysroot` crate to represent the standard library crates
Zoxc Mar 7, 2023
58537cd
junit: fix typo in comment and don't include output for passes when n…
durin42 Apr 28, 2023
77dac91
Add test.
cjgillot Apr 25, 2023
9325a25
Make PlaceMention a non-mutating use.
cjgillot Apr 25, 2023
4ec76df
Expand comment on NonMutatingUseContext.
cjgillot Apr 29, 2023
8972a23
Do not recurse into const generic args when resolving self lifetime e…
cjgillot Apr 29, 2023
8c781b0
Add the basic `ascii::Char` type
scottmcm Apr 29, 2023
c04106f
check array type of repeat exprs is wf
BoxyUwU May 2, 2023
7d9130f
do not allow rustc::pass_by_value lint
BoxyUwU May 4, 2023
70523fb
Add `is_positive` method for signed non-zero integers.
jmillikin May 4, 2023
6530b1b
bootstrap: add .gitmodules to the sources
krasimirgg May 4, 2023
0098cd4
Rollup merge of #108865 - Zoxc:library-dummy-crate, r=jyn514
matthiaskrgr May 4, 2023
bf72b64
Rollup merge of #110651 - durin42:xunit-stdout, r=cuviper
matthiaskrgr May 4, 2023
0ac8ebd
Rollup merge of #110826 - cjgillot:place-mention-use, r=JakobDegen,lcnr
matthiaskrgr May 4, 2023
8d66f01
Rollup merge of #110982 - cjgillot:elided-self-const, r=petrochenkov
matthiaskrgr May 4, 2023
ea0b650
Rollup merge of #111009 - scottmcm:ascii-char, r=BurntSushi
matthiaskrgr May 4, 2023
c0ca84b
Rollup merge of #111100 - BoxyUwU:array_repeat_expr_wf, r=compiler-er…
matthiaskrgr May 4, 2023
ab80b7a
Rollup merge of #111186 - jmillikin:nonzero-is-positive, r=dtolnay
matthiaskrgr May 4, 2023
75e8f87
Rollup merge of #111201 - krasimirgg:add_gitmodules, r=jyn514
matthiaskrgr May 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
@@ -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"
@@ -4823,7 +4832,6 @@ dependencies = [
"getopts",
"panic_abort",
"panic_unwind",
"proc_macro",
"std",
]

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
members = [
"compiler/rustc",
"library/std",
"library/test",
"library/sysroot",
"src/rustdoc-json-types",
"src/tools/build_helper",
"src/tools/cargotest",
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/def_use.rs
Original file line number Diff line number Diff line change
@@ -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) |
8 changes: 8 additions & 0 deletions compiler/rustc_borrowck/src/renumber.rs
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 10 additions & 5 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
}
@@ -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
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/analyze.rs
Original file line number Diff line number Diff line change
@@ -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,
6 changes: 6 additions & 0 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
@@ -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)
}

30 changes: 25 additions & 5 deletions compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
@@ -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,
@@ -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
);
}
@@ -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(_) => {}
@@ -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) {
}

@@ -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)
@@ -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)]
1 change: 1 addition & 0 deletions compiler/rustc_mir_dataflow/src/impls/liveness.rs
Original file line number Diff line number Diff line change
@@ -197,6 +197,7 @@ impl DefUse {
| NonMutatingUseContext::Copy
| NonMutatingUseContext::Inspect
| NonMutatingUseContext::Move
| NonMutatingUseContext::PlaceMention
| NonMutatingUseContext::ShallowBorrow
| NonMutatingUseContext::SharedBorrow
| NonMutatingUseContext::UniqueBorrow,
1 change: 1 addition & 0 deletions compiler/rustc_mir_transform/src/const_prop.rs
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
9 changes: 9 additions & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
@@ -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 {
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
@@ -17,6 +17,7 @@ use crate::ops::{
};
use crate::slice::{Iter, IterMut};

mod ascii;
mod drain;
mod equality;
mod iter;
4 changes: 4 additions & 0 deletions library/core/src/ascii.rs
Original file line number Diff line number Diff line change
@@ -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
Loading