Skip to content

Commit 1678854

Browse files
committed
Auto merge of rust-lang#77867 - JohnTitor:rollup-0odg1n4, r=JohnTitor
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`
2 parents f3ab6f0 + 984f78b commit 1678854

File tree

17 files changed

+98
-86
lines changed

17 files changed

+98
-86
lines changed

compiler/rustc_builtin_macros/src/format_foreign.rs

+10-23
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ pub mod printf {
385385
if let Start = state {
386386
match c {
387387
'1'..='9' => {
388-
let end = at_next_cp_while(next, is_digit);
388+
let end = at_next_cp_while(next, char::is_ascii_digit);
389389
match end.next_cp() {
390390
// Yes, this *is* the parameter.
391391
Some(('$', end2)) => {
@@ -427,7 +427,7 @@ pub mod printf {
427427
move_to!(next);
428428
}
429429
'1'..='9' => {
430-
let end = at_next_cp_while(next, is_digit);
430+
let end = at_next_cp_while(next, char::is_ascii_digit);
431431
state = Prec;
432432
width = Some(Num::from_str(at.slice_between(end).unwrap(), None));
433433
move_to!(end);
@@ -441,7 +441,7 @@ pub mod printf {
441441
}
442442

443443
if let WidthArg = state {
444-
let end = at_next_cp_while(at, is_digit);
444+
let end = at_next_cp_while(at, char::is_ascii_digit);
445445
match end.next_cp() {
446446
Some(('$', end2)) => {
447447
state = Prec;
@@ -473,7 +473,7 @@ pub mod printf {
473473
if let PrecInner = state {
474474
match c {
475475
'*' => {
476-
let end = at_next_cp_while(next, is_digit);
476+
let end = at_next_cp_while(next, char::is_ascii_digit);
477477
match end.next_cp() {
478478
Some(('$', end2)) => {
479479
state = Length;
@@ -488,7 +488,7 @@ pub mod printf {
488488
}
489489
}
490490
'0'..='9' => {
491-
let end = at_next_cp_while(next, is_digit);
491+
let end = at_next_cp_while(next, char::is_ascii_digit);
492492
state = Length;
493493
precision = Some(Num::from_str(at.slice_between(end).unwrap(), None));
494494
move_to!(end);
@@ -563,12 +563,12 @@ pub mod printf {
563563

564564
fn at_next_cp_while<F>(mut cur: Cur<'_>, mut pred: F) -> Cur<'_>
565565
where
566-
F: FnMut(char) -> bool,
566+
F: FnMut(&char) -> bool,
567567
{
568568
loop {
569569
match cur.next_cp() {
570570
Some((c, next)) => {
571-
if pred(c) {
571+
if pred(&c) {
572572
cur = next;
573573
} else {
574574
return cur;
@@ -579,14 +579,7 @@ pub mod printf {
579579
}
580580
}
581581

582-
fn is_digit(c: char) -> bool {
583-
match c {
584-
'0'..='9' => true,
585-
_ => false,
586-
}
587-
}
588-
589-
fn is_flag(c: char) -> bool {
582+
fn is_flag(c: &char) -> bool {
590583
match c {
591584
'0' | '-' | '+' | ' ' | '#' | '\'' => true,
592585
_ => false,
@@ -723,17 +716,11 @@ pub mod shell {
723716
}
724717

725718
fn is_ident_head(c: char) -> bool {
726-
match c {
727-
'a'..='z' | 'A'..='Z' | '_' => true,
728-
_ => false,
729-
}
719+
c.is_ascii_alphabetic() || c == '_'
730720
}
731721

732722
fn is_ident_tail(c: char) -> bool {
733-
match c {
734-
'0'..='9' => true,
735-
c => is_ident_head(c),
736-
}
723+
c.is_ascii_alphanumeric() || c == '_'
737724
}
738725

739726
#[cfg(test)]

compiler/rustc_middle/src/mir/query.rs

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//! Values computed by queries that use MIR.
22
3-
use crate::mir::{Body, Promoted};
3+
use crate::mir::{abstract_const, Body, Promoted};
44
use crate::ty::{self, Ty, TyCtxt};
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::sync::Lrc;
7+
use rustc_errors::ErrorReported;
78
use rustc_hir as hir;
89
use rustc_hir::def_id::{DefId, LocalDefId};
910
use rustc_index::bit_set::BitMatrix;
@@ -407,7 +408,12 @@ pub struct CoverageInfo {
407408
pub num_expressions: u32,
408409
}
409410

411+
/// Shims which make dealing with `WithOptConstParam` easier.
412+
///
413+
/// For more information on why this is needed, consider looking
414+
/// at the docs for `WithOptConstParam` itself.
410415
impl<'tcx> TyCtxt<'tcx> {
416+
#[inline]
411417
pub fn mir_borrowck_opt_const_arg(
412418
self,
413419
def: ty::WithOptConstParam<LocalDefId>,
@@ -419,6 +425,7 @@ impl<'tcx> TyCtxt<'tcx> {
419425
}
420426
}
421427

428+
#[inline]
422429
pub fn mir_const_qualif_opt_const_arg(
423430
self,
424431
def: ty::WithOptConstParam<LocalDefId>,
@@ -430,7 +437,8 @@ impl<'tcx> TyCtxt<'tcx> {
430437
}
431438
}
432439

433-
pub fn promoted_mir_of_opt_const_arg(
440+
#[inline]
441+
pub fn promoted_mir_opt_const_arg(
434442
self,
435443
def: ty::WithOptConstParam<DefId>,
436444
) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
@@ -440,4 +448,28 @@ impl<'tcx> TyCtxt<'tcx> {
440448
self.promoted_mir(def.did)
441449
}
442450
}
451+
452+
#[inline]
453+
pub fn optimized_mir_opt_const_arg(
454+
self,
455+
def: ty::WithOptConstParam<DefId>,
456+
) -> &'tcx Body<'tcx> {
457+
if let Some((did, param_did)) = def.as_const_arg() {
458+
self.optimized_mir_of_const_arg((did, param_did))
459+
} else {
460+
self.optimized_mir(def.did)
461+
}
462+
}
463+
464+
#[inline]
465+
pub fn mir_abstract_const_opt_const_arg(
466+
self,
467+
def: ty::WithOptConstParam<DefId>,
468+
) -> Result<Option<&'tcx [abstract_const::Node<'tcx>]>, ErrorReported> {
469+
if let Some((did, param_did)) = def.as_const_arg() {
470+
self.mir_abstract_const_of_const_arg((did, param_did))
471+
} else {
472+
self.mir_abstract_const(def.did)
473+
}
474+
}
443475
}

compiler/rustc_middle/src/ty/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -2953,13 +2953,7 @@ impl<'tcx> TyCtxt<'tcx> {
29532953
/// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair.
29542954
pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> {
29552955
match instance {
2956-
ty::InstanceDef::Item(def) => {
2957-
if let Some((did, param_did)) = def.as_const_arg() {
2958-
self.optimized_mir_of_const_arg((did, param_did))
2959-
} else {
2960-
self.optimized_mir(def.did)
2961-
}
2962-
}
2956+
ty::InstanceDef::Item(def) => self.optimized_mir_opt_const_arg(def),
29632957
ty::InstanceDef::VtableShim(..)
29642958
| ty::InstanceDef::ReifyShim(..)
29652959
| ty::InstanceDef::Intrinsic(..)

compiler/rustc_mir/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
343343
// deny-by-default lint
344344
_ => {
345345
if let Some(p) = cid.promoted {
346-
let span = tcx.promoted_mir_of_opt_const_arg(def.to_global())[p].span;
346+
let span = tcx.promoted_mir_opt_const_arg(def.to_global())[p].span;
347347
if let err_inval!(ReferencedConstant) = err.error {
348348
Err(err.report_as_error(
349349
tcx.at(span),

compiler/rustc_mir/src/interpret/eval_context.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -477,16 +477,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
477477
}
478478
trace!("load mir(instance={:?}, promoted={:?})", instance, promoted);
479479
if let Some(promoted) = promoted {
480-
return Ok(&self.tcx.promoted_mir_of_opt_const_arg(def)[promoted]);
480+
return Ok(&self.tcx.promoted_mir_opt_const_arg(def)[promoted]);
481481
}
482482
match instance {
483483
ty::InstanceDef::Item(def) => {
484484
if self.tcx.is_mir_available(def.did) {
485-
if let Some((did, param_did)) = def.as_const_arg() {
486-
Ok(self.tcx.optimized_mir_of_const_arg((did, param_did)))
487-
} else {
488-
Ok(self.tcx.optimized_mir(def.did))
489-
}
485+
Ok(self.tcx.optimized_mir_opt_const_arg(def))
490486
} else {
491487
throw_unsup!(NoMirFor(def.did))
492488
}

compiler/rustc_mir/src/monomorphize/collector.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ use rustc_session::config::EntryFnType;
197197
use rustc_span::source_map::{dummy_spanned, respan, Span, Spanned, DUMMY_SP};
198198
use smallvec::SmallVec;
199199
use std::iter;
200+
use std::ops::Range;
200201
use std::path::PathBuf;
201202

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

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

247247
let end_index = self.targets.len();
248-
assert!(self.index.insert(source, (start_index, end_index)).is_none());
248+
assert!(self.index.insert(source, start_index..end_index).is_none());
249249
}
250250

251251
// Internally iterate over all items referenced by `source` which will be
@@ -254,9 +254,9 @@ impl<'tcx> InliningMap<'tcx> {
254254
where
255255
F: FnMut(MonoItem<'tcx>),
256256
{
257-
if let Some(&(start_index, end_index)) = self.index.get(&source) {
258-
for (i, candidate) in self.targets[start_index..end_index].iter().enumerate() {
259-
if self.inlines.contains(start_index + i) {
257+
if let Some(range) = self.index.get(&source) {
258+
for (i, candidate) in self.targets[range.clone()].iter().enumerate() {
259+
if self.inlines.contains(range.start + i) {
260260
f(*candidate);
261261
}
262262
}
@@ -268,8 +268,8 @@ impl<'tcx> InliningMap<'tcx> {
268268
where
269269
F: FnMut(MonoItem<'tcx>, &[MonoItem<'tcx>]),
270270
{
271-
for (&accessor, &(start_index, end_index)) in &self.index {
272-
f(accessor, &self.targets[start_index..end_index])
271+
for (&accessor, range) in &self.index {
272+
f(accessor, &self.targets[range.clone()])
273273
}
274274
}
275275
}

compiler/rustc_mir/src/transform/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,7 @@ fn mir_promoted(
287287
// this point, before we steal the mir-const result.
288288
// Also this means promotion can rely on all const checks having been done.
289289
let _ = tcx.mir_const_qualif_opt_const_arg(def);
290-
let _ = if let Some(param_did) = def.const_param_did {
291-
tcx.mir_abstract_const_of_const_arg((def.did, param_did))
292-
} else {
293-
tcx.mir_abstract_const(def.did.to_def_id())
294-
};
290+
let _ = tcx.mir_abstract_const_opt_const_arg(def.to_global());
295291
let mut body = tcx.mir_const(def).steal();
296292

297293
let mut required_consts = Vec::new();

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
147147
if concrete.is_ok() && substs.has_param_types_or_consts() {
148148
match infcx.tcx.def_kind(def.did) {
149149
DefKind::AnonConst => {
150-
let mir_body = if let Some(def) = def.as_const_arg() {
151-
infcx.tcx.optimized_mir_of_const_arg(def)
152-
} else {
153-
infcx.tcx.optimized_mir(def.did)
154-
};
150+
let mir_body = infcx.tcx.optimized_mir_opt_const_arg(def);
155151

156152
if mir_body.is_polymorphic {
157153
future_compat_lint();
@@ -212,13 +208,7 @@ impl AbstractConst<'tcx> {
212208
def: ty::WithOptConstParam<DefId>,
213209
substs: SubstsRef<'tcx>,
214210
) -> Result<Option<AbstractConst<'tcx>>, ErrorReported> {
215-
let inner = match (def.did.as_local(), def.const_param_did) {
216-
(Some(did), Some(param_did)) => {
217-
tcx.mir_abstract_const_of_const_arg((did, param_did))?
218-
}
219-
_ => tcx.mir_abstract_const(def.did)?,
220-
};
221-
211+
let inner = tcx.mir_abstract_const_opt_const_arg(def)?;
222212
Ok(inner.map(|inner| AbstractConst { inner, substs }))
223213
}
224214

library/core/src/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl<'a, 'f: 'a> DerefMut for VaList<'a, 'f> {
280280
// within a private module. Once RFC 2145 has been implemented look into
281281
// improving this.
282282
mod sealed_trait {
283-
/// Trait which permits the allowed types to be used with [VaList::arg].
283+
/// Trait which permits the allowed types to be used with [super::VaListImpl::arg].
284284
#[unstable(
285285
feature = "c_variadic",
286286
reason = "the `c_variadic` feature has not been properly tested on \

library/std/src/sys/wasi/ext/io.rs

+18
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,21 @@ impl AsRawFd for io::Stderr {
160160
sys::stdio::Stderr.as_raw_fd()
161161
}
162162
}
163+
164+
impl<'a> AsRawFd for io::StdinLock<'a> {
165+
fn as_raw_fd(&self) -> RawFd {
166+
sys::stdio::Stdin.as_raw_fd()
167+
}
168+
}
169+
170+
impl<'a> AsRawFd for io::StdoutLock<'a> {
171+
fn as_raw_fd(&self) -> RawFd {
172+
sys::stdio::Stdout.as_raw_fd()
173+
}
174+
}
175+
176+
impl<'a> AsRawFd for io::StderrLock<'a> {
177+
fn as_raw_fd(&self) -> RawFd {
178+
sys::stdio::Stderr.as_raw_fd()
179+
}
180+
}

src/bootstrap/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ handled naturally. `./configure` should almost never be used for local
9393
installations, and is primarily useful for CI. Prefer to customize behavior
9494
using `config.toml`.
9595

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

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

103103
## Build stages
104104

src/bootstrap/bin/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
88
use std::env;
99

10-
use bootstrap::{Build, Config, Subcommand};
10+
use bootstrap::{Build, Config, Subcommand, VERSION};
1111

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

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

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

4244
fn check_version(config: &Config) -> Option<String> {
43-
const VERSION: usize = 2;
44-
4545
let mut msg = String::new();
4646

4747
let suggestion = if let Some(seen) = config.changelog_seen {

src/bootstrap/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ const LLVM_TOOLS: &[&str] = &[
179179
"llvm-ar", // used for creating and modifying archive files
180180
];
181181

182+
pub const VERSION: usize = 2;
183+
182184
/// A structure representing a Rust compiler.
183185
///
184186
/// Each compiler has a `stage` that it is associated with and a `host` that

0 commit comments

Comments
 (0)