Skip to content

Commit

Permalink
Auto merge of rust-lang#77867 - JohnTitor:rollup-0odg1n4, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

Successful merges:

 - rust-lang#77550 (add shims for WithOptConstParam query calls)
 - rust-lang#77699 (Add word wrap for short descriptions)
 - rust-lang#77724 (Implement `AsRawFd` for `StdinLock` etc. on WASI.)
 - rust-lang#77746 (Fix `x.py setup` sets `changelog-seen`)
 - rust-lang#77784 (Fix intra-docs link in core::ffi::VaList)
 - rust-lang#77811 (rustdoc: Make some functions private that don't need to be public)
 - rust-lang#77818 (Mono collector: replace pair of ints with Range)
 - rust-lang#77831 (Use std methods on char instead of open coding them)
 - rust-lang#77852 (update url in bootstrap README (gcc-rs -> cc-rs))
 - rust-lang#77863 (Remove `mark-i-m` from rustc-dev-guide maintainers)

Failed merges:

r? `@ghost`
  • Loading branch information
bors committed Oct 12, 2020
2 parents f3ab6f0 + 984f78b commit 1678854
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 86 deletions.
33 changes: 10 additions & 23 deletions compiler/rustc_builtin_macros/src/format_foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ pub mod printf {
if let Start = state {
match c {
'1'..='9' => {
let end = at_next_cp_while(next, is_digit);
let end = at_next_cp_while(next, char::is_ascii_digit);
match end.next_cp() {
// Yes, this *is* the parameter.
Some(('$', end2)) => {
Expand Down Expand Up @@ -427,7 +427,7 @@ pub mod printf {
move_to!(next);
}
'1'..='9' => {
let end = at_next_cp_while(next, is_digit);
let end = at_next_cp_while(next, char::is_ascii_digit);
state = Prec;
width = Some(Num::from_str(at.slice_between(end).unwrap(), None));
move_to!(end);
Expand All @@ -441,7 +441,7 @@ pub mod printf {
}

if let WidthArg = state {
let end = at_next_cp_while(at, is_digit);
let end = at_next_cp_while(at, char::is_ascii_digit);
match end.next_cp() {
Some(('$', end2)) => {
state = Prec;
Expand Down Expand Up @@ -473,7 +473,7 @@ pub mod printf {
if let PrecInner = state {
match c {
'*' => {
let end = at_next_cp_while(next, is_digit);
let end = at_next_cp_while(next, char::is_ascii_digit);
match end.next_cp() {
Some(('$', end2)) => {
state = Length;
Expand All @@ -488,7 +488,7 @@ pub mod printf {
}
}
'0'..='9' => {
let end = at_next_cp_while(next, is_digit);
let end = at_next_cp_while(next, char::is_ascii_digit);
state = Length;
precision = Some(Num::from_str(at.slice_between(end).unwrap(), None));
move_to!(end);
Expand Down Expand Up @@ -563,12 +563,12 @@ pub mod printf {

fn at_next_cp_while<F>(mut cur: Cur<'_>, mut pred: F) -> Cur<'_>
where
F: FnMut(char) -> bool,
F: FnMut(&char) -> bool,
{
loop {
match cur.next_cp() {
Some((c, next)) => {
if pred(c) {
if pred(&c) {
cur = next;
} else {
return cur;
Expand All @@ -579,14 +579,7 @@ pub mod printf {
}
}

fn is_digit(c: char) -> bool {
match c {
'0'..='9' => true,
_ => false,
}
}

fn is_flag(c: char) -> bool {
fn is_flag(c: &char) -> bool {
match c {
'0' | '-' | '+' | ' ' | '#' | '\'' => true,
_ => false,
Expand Down Expand Up @@ -723,17 +716,11 @@ pub mod shell {
}

fn is_ident_head(c: char) -> bool {
match c {
'a'..='z' | 'A'..='Z' | '_' => true,
_ => false,
}
c.is_ascii_alphabetic() || c == '_'
}

fn is_ident_tail(c: char) -> bool {
match c {
'0'..='9' => true,
c => is_ident_head(c),
}
c.is_ascii_alphanumeric() || c == '_'
}

#[cfg(test)]
Expand Down
36 changes: 34 additions & 2 deletions compiler/rustc_middle/src/mir/query.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Values computed by queries that use MIR.
use crate::mir::{Body, Promoted};
use crate::mir::{abstract_const, Body, Promoted};
use crate::ty::{self, Ty, TyCtxt};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lrc;
use rustc_errors::ErrorReported;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_index::bit_set::BitMatrix;
Expand Down Expand Up @@ -407,7 +408,12 @@ pub struct CoverageInfo {
pub num_expressions: u32,
}

/// Shims which make dealing with `WithOptConstParam` easier.
///
/// For more information on why this is needed, consider looking
/// at the docs for `WithOptConstParam` itself.
impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn mir_borrowck_opt_const_arg(
self,
def: ty::WithOptConstParam<LocalDefId>,
Expand All @@ -419,6 +425,7 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

#[inline]
pub fn mir_const_qualif_opt_const_arg(
self,
def: ty::WithOptConstParam<LocalDefId>,
Expand All @@ -430,7 +437,8 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

pub fn promoted_mir_of_opt_const_arg(
#[inline]
pub fn promoted_mir_opt_const_arg(
self,
def: ty::WithOptConstParam<DefId>,
) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
Expand All @@ -440,4 +448,28 @@ impl<'tcx> TyCtxt<'tcx> {
self.promoted_mir(def.did)
}
}

#[inline]
pub fn optimized_mir_opt_const_arg(
self,
def: ty::WithOptConstParam<DefId>,
) -> &'tcx Body<'tcx> {
if let Some((did, param_did)) = def.as_const_arg() {
self.optimized_mir_of_const_arg((did, param_did))
} else {
self.optimized_mir(def.did)
}
}

#[inline]
pub fn mir_abstract_const_opt_const_arg(
self,
def: ty::WithOptConstParam<DefId>,
) -> Result<Option<&'tcx [abstract_const::Node<'tcx>]>, ErrorReported> {
if let Some((did, param_did)) = def.as_const_arg() {
self.mir_abstract_const_of_const_arg((did, param_did))
} else {
self.mir_abstract_const(def.did)
}
}
}
8 changes: 1 addition & 7 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2953,13 +2953,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair.
pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> {
match instance {
ty::InstanceDef::Item(def) => {
if let Some((did, param_did)) = def.as_const_arg() {
self.optimized_mir_of_const_arg((did, param_did))
} else {
self.optimized_mir(def.did)
}
}
ty::InstanceDef::Item(def) => self.optimized_mir_opt_const_arg(def),
ty::InstanceDef::VtableShim(..)
| ty::InstanceDef::ReifyShim(..)
| ty::InstanceDef::Intrinsic(..)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
// deny-by-default lint
_ => {
if let Some(p) = cid.promoted {
let span = tcx.promoted_mir_of_opt_const_arg(def.to_global())[p].span;
let span = tcx.promoted_mir_opt_const_arg(def.to_global())[p].span;
if let err_inval!(ReferencedConstant) = err.error {
Err(err.report_as_error(
tcx.at(span),
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_mir/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
trace!("load mir(instance={:?}, promoted={:?})", instance, promoted);
if let Some(promoted) = promoted {
return Ok(&self.tcx.promoted_mir_of_opt_const_arg(def)[promoted]);
return Ok(&self.tcx.promoted_mir_opt_const_arg(def)[promoted]);
}
match instance {
ty::InstanceDef::Item(def) => {
if self.tcx.is_mir_available(def.did) {
if let Some((did, param_did)) = def.as_const_arg() {
Ok(self.tcx.optimized_mir_of_const_arg((did, param_did)))
} else {
Ok(self.tcx.optimized_mir(def.did))
}
Ok(self.tcx.optimized_mir_opt_const_arg(def))
} else {
throw_unsup!(NoMirFor(def.did))
}
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_mir/src/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ use rustc_session::config::EntryFnType;
use rustc_span::source_map::{dummy_spanned, respan, Span, Spanned, DUMMY_SP};
use smallvec::SmallVec;
use std::iter;
use std::ops::Range;
use std::path::PathBuf;

#[derive(PartialEq)]
Expand All @@ -210,9 +211,8 @@ pub enum MonoItemCollectionMode {
pub struct InliningMap<'tcx> {
// Maps a source mono item to the range of mono items
// accessed by it.
// The two numbers in the tuple are the start (inclusive) and
// end index (exclusive) within the `targets` vecs.
index: FxHashMap<MonoItem<'tcx>, (usize, usize)>,
// The range selects elements within the `targets` vecs.
index: FxHashMap<MonoItem<'tcx>, Range<usize>>,
targets: Vec<MonoItem<'tcx>>,

// Contains one bit per mono item in the `targets` field. That bit
Expand Down Expand Up @@ -245,7 +245,7 @@ impl<'tcx> InliningMap<'tcx> {
}

let end_index = self.targets.len();
assert!(self.index.insert(source, (start_index, end_index)).is_none());
assert!(self.index.insert(source, start_index..end_index).is_none());
}

// Internally iterate over all items referenced by `source` which will be
Expand All @@ -254,9 +254,9 @@ impl<'tcx> InliningMap<'tcx> {
where
F: FnMut(MonoItem<'tcx>),
{
if let Some(&(start_index, end_index)) = self.index.get(&source) {
for (i, candidate) in self.targets[start_index..end_index].iter().enumerate() {
if self.inlines.contains(start_index + i) {
if let Some(range) = self.index.get(&source) {
for (i, candidate) in self.targets[range.clone()].iter().enumerate() {
if self.inlines.contains(range.start + i) {
f(*candidate);
}
}
Expand All @@ -268,8 +268,8 @@ impl<'tcx> InliningMap<'tcx> {
where
F: FnMut(MonoItem<'tcx>, &[MonoItem<'tcx>]),
{
for (&accessor, &(start_index, end_index)) in &self.index {
f(accessor, &self.targets[start_index..end_index])
for (&accessor, range) in &self.index {
f(accessor, &self.targets[range.clone()])
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_mir/src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,7 @@ fn mir_promoted(
// this point, before we steal the mir-const result.
// Also this means promotion can rely on all const checks having been done.
let _ = tcx.mir_const_qualif_opt_const_arg(def);
let _ = if let Some(param_did) = def.const_param_did {
tcx.mir_abstract_const_of_const_arg((def.did, param_did))
} else {
tcx.mir_abstract_const(def.did.to_def_id())
};
let _ = tcx.mir_abstract_const_opt_const_arg(def.to_global());
let mut body = tcx.mir_const(def).steal();

let mut required_consts = Vec::new();
Expand Down
14 changes: 2 additions & 12 deletions compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
if concrete.is_ok() && substs.has_param_types_or_consts() {
match infcx.tcx.def_kind(def.did) {
DefKind::AnonConst => {
let mir_body = if let Some(def) = def.as_const_arg() {
infcx.tcx.optimized_mir_of_const_arg(def)
} else {
infcx.tcx.optimized_mir(def.did)
};
let mir_body = infcx.tcx.optimized_mir_opt_const_arg(def);

if mir_body.is_polymorphic {
future_compat_lint();
Expand Down Expand Up @@ -212,13 +208,7 @@ impl AbstractConst<'tcx> {
def: ty::WithOptConstParam<DefId>,
substs: SubstsRef<'tcx>,
) -> Result<Option<AbstractConst<'tcx>>, ErrorReported> {
let inner = match (def.did.as_local(), def.const_param_did) {
(Some(did), Some(param_did)) => {
tcx.mir_abstract_const_of_const_arg((did, param_did))?
}
_ => tcx.mir_abstract_const(def.did)?,
};

let inner = tcx.mir_abstract_const_opt_const_arg(def)?;
Ok(inner.map(|inner| AbstractConst { inner, substs }))
}

Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl<'a, 'f: 'a> DerefMut for VaList<'a, 'f> {
// within a private module. Once RFC 2145 has been implemented look into
// improving this.
mod sealed_trait {
/// Trait which permits the allowed types to be used with [VaList::arg].
/// Trait which permits the allowed types to be used with [super::VaListImpl::arg].
#[unstable(
feature = "c_variadic",
reason = "the `c_variadic` feature has not been properly tested on \
Expand Down
18 changes: 18 additions & 0 deletions library/std/src/sys/wasi/ext/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,21 @@ impl AsRawFd for io::Stderr {
sys::stdio::Stderr.as_raw_fd()
}
}

impl<'a> AsRawFd for io::StdinLock<'a> {
fn as_raw_fd(&self) -> RawFd {
sys::stdio::Stdin.as_raw_fd()
}
}

impl<'a> AsRawFd for io::StdoutLock<'a> {
fn as_raw_fd(&self) -> RawFd {
sys::stdio::Stdout.as_raw_fd()
}
}

impl<'a> AsRawFd for io::StderrLock<'a> {
fn as_raw_fd(&self) -> RawFd {
sys::stdio::Stderr.as_raw_fd()
}
}
6 changes: 3 additions & 3 deletions src/bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ handled naturally. `./configure` should almost never be used for local
installations, and is primarily useful for CI. Prefer to customize behavior
using `config.toml`.

Finally, rustbuild makes use of the [gcc-rs crate] which has [its own
Finally, rustbuild makes use of the [cc-rs crate] which has [its own
method][env-vars] of configuring C compilers and C flags via environment
variables.

[gcc-rs crate]: https://github.com/alexcrichton/gcc-rs
[env-vars]: https://github.com/alexcrichton/gcc-rs#external-configuration-via-environment-variables
[cc-rs crate]: https://github.com/alexcrichton/cc-rs
[env-vars]: https://github.com/alexcrichton/cc-rs#external-configuration-via-environment-variables

## Build stages

Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
use std::env;

use bootstrap::{Build, Config, Subcommand};
use bootstrap::{Build, Config, Subcommand, VERSION};

fn main() {
let args = env::args().skip(1).collect::<Vec<_>>();
let config = Config::parse(&args);

let changelog_suggestion = check_version(&config);
// check_version warnings are not printed during setup
let changelog_suggestion =
if matches!(config.cmd, Subcommand::Setup {..}) { None } else { check_version(&config) };

// NOTE: Since `./configure` generates a `config.toml`, distro maintainers will see the
// changelog warning, not the `x.py setup` message.
Expand All @@ -40,8 +42,6 @@ fn main() {
}

fn check_version(config: &Config) -> Option<String> {
const VERSION: usize = 2;

let mut msg = String::new();

let suggestion = if let Some(seen) = config.changelog_seen {
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ const LLVM_TOOLS: &[&str] = &[
"llvm-ar", // used for creating and modifying archive files
];

pub const VERSION: usize = 2;

/// A structure representing a Rust compiler.
///
/// Each compiler has a `stage` that it is associated with and a `host` that
Expand Down
Loading

0 comments on commit 1678854

Please sign in to comment.