Skip to content

Commit d8d1d10

Browse files
committed
Auto merge of rust-lang#89158 - the8472:rollup-3e4ijth, r=the8472
Rollup of 12 pull requests Successful merges: - rust-lang#88795 (Print a note if a character literal contains a variation selector) - rust-lang#89015 (core::ascii::escape_default: reduce struct size) - rust-lang#89078 (Cleanup: Remove needless reference in ParentHirIterator) - rust-lang#89086 (Stabilize `Iterator::map_while`) - rust-lang#89096 ([bootstrap] Improve the error message when `ninja` is not found to link to installation instructions) - rust-lang#89113 (dont `.ensure()` the `thir_abstract_const` query call in `mir_build`) - rust-lang#89114 (Fixes a technicality regarding the size of C's `char` type) - rust-lang#89115 (:arrow_up: rust-analyzer) - rust-lang#89126 (Fix ICE when `indirect_structural_match` is allowed) - rust-lang#89141 (Impl `Error` for `FromSecsError` without foreign type) - rust-lang#89142 (Fix match for placeholder region) - rust-lang#89147 (add case for checking const refs in check_const_value_eq) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ac2d9fc + a3e6c19 commit d8d1d10

File tree

29 files changed

+275
-67
lines changed

29 files changed

+275
-67
lines changed

compiler/rustc_data_structures/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#![feature(extend_one)]
1919
#![feature(hash_raw_entry)]
2020
#![feature(in_band_lifetimes)]
21-
#![feature(iter_map_while)]
2221
#![feature(maybe_uninit_uninit_array)]
2322
#![feature(min_specialization)]
2423
#![feature(never_type)]

compiler/rustc_middle/src/hir/map/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ pub struct Map<'hir> {
8383

8484
/// An iterator that walks up the ancestor tree of a given `HirId`.
8585
/// Constructed using `tcx.hir().parent_iter(hir_id)`.
86-
pub struct ParentHirIterator<'map, 'hir> {
86+
pub struct ParentHirIterator<'hir> {
8787
current_id: HirId,
88-
map: &'map Map<'hir>,
88+
map: Map<'hir>,
8989
}
9090

91-
impl<'hir> Iterator for ParentHirIterator<'_, 'hir> {
91+
impl<'hir> Iterator for ParentHirIterator<'hir> {
9292
type Item = (HirId, Node<'hir>);
9393

9494
fn next(&mut self) -> Option<Self::Item> {
@@ -115,12 +115,12 @@ impl<'hir> Iterator for ParentHirIterator<'_, 'hir> {
115115

116116
/// An iterator that walks up the ancestor tree of a given `HirId`.
117117
/// Constructed using `tcx.hir().parent_owner_iter(hir_id)`.
118-
pub struct ParentOwnerIterator<'map, 'hir> {
118+
pub struct ParentOwnerIterator<'hir> {
119119
current_id: HirId,
120-
map: &'map Map<'hir>,
120+
map: Map<'hir>,
121121
}
122122

123-
impl<'hir> Iterator for ParentOwnerIterator<'_, 'hir> {
123+
impl<'hir> Iterator for ParentOwnerIterator<'hir> {
124124
type Item = (HirId, OwnerNode<'hir>);
125125

126126
fn next(&mut self) -> Option<Self::Item> {
@@ -588,13 +588,13 @@ impl<'hir> Map<'hir> {
588588

589589
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
590590
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
591-
pub fn parent_iter(&self, current_id: HirId) -> ParentHirIterator<'_, 'hir> {
591+
pub fn parent_iter(self, current_id: HirId) -> ParentHirIterator<'hir> {
592592
ParentHirIterator { current_id, map: self }
593593
}
594594

595595
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
596596
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
597-
pub fn parent_owner_iter(&self, current_id: HirId) -> ParentOwnerIterator<'_, 'hir> {
597+
pub fn parent_owner_iter(self, current_id: HirId) -> ParentOwnerIterator<'hir> {
598598
ParentOwnerIterator { current_id, map: self }
599599
}
600600

compiler/rustc_middle/src/ich/impls_ty.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionKind {
9090
ty::ReFree(ref free_region) => {
9191
free_region.hash_stable(hcx, hasher);
9292
}
93-
ty::ReVar(..) | ty::RePlaceholder(..) => {
93+
ty::RePlaceholder(p) => {
94+
p.hash_stable(hcx, hasher);
95+
}
96+
ty::ReVar(..) => {
9497
bug!("StableHasher: unexpected region {:?}", *self)
9598
}
9699
}

compiler/rustc_middle/src/ty/relate.rs

+9
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,15 @@ fn check_const_value_eq<R: TypeRelation<'tcx>>(
639639
get_slice_bytes(&tcx, a_val) == get_slice_bytes(&tcx, b_val)
640640
}
641641

642+
(ConstValue::ByRef { alloc: alloc_a, .. }, ConstValue::ByRef { alloc: alloc_b, .. })
643+
if a.ty.is_ref() || b.ty.is_ref() =>
644+
{
645+
if a.ty.is_ref() && b.ty.is_ref() {
646+
alloc_a == alloc_b
647+
} else {
648+
false
649+
}
650+
}
642651
(ConstValue::ByRef { .. }, ConstValue::ByRef { .. }) => {
643652
let a_destructured = tcx.destructure_const(relation.param_env().and(a));
644653
let b_destructured = tcx.destructure_const(relation.param_env().and(b));

compiler/rustc_mir_build/src/build/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,18 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
4444
let body_owner_kind = tcx.hir().body_owner_kind(id);
4545
let typeck_results = tcx.typeck_opt_const_arg(def);
4646

47-
// Ensure unsafeck is ran before we steal the THIR.
47+
// Ensure unsafeck and abstract const building is ran before we steal the THIR.
48+
// We can't use `ensure()` for `thir_abstract_const` as it doesn't compute the query
49+
// if inputs are green. This can cause ICEs when calling `thir_abstract_const` after
50+
// THIR has been stolen if we haven't computed this query yet.
4851
match def {
4952
ty::WithOptConstParam { did, const_param_did: Some(const_param_did) } => {
5053
tcx.ensure().thir_check_unsafety_for_const_arg((did, const_param_did));
51-
tcx.ensure().thir_abstract_const_of_const_arg((did, const_param_did));
54+
drop(tcx.thir_abstract_const_of_const_arg((did, const_param_did)));
5255
}
5356
ty::WithOptConstParam { did, const_param_did: None } => {
5457
tcx.ensure().thir_check_unsafety(did);
55-
tcx.ensure().thir_abstract_const(did);
58+
drop(tcx.thir_abstract_const(did));
5659
}
5760
}
5861

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,18 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
322322
&& !self.saw_const_match_lint.get()
323323
{
324324
self.saw_const_match_lint.set(true);
325-
let msg = format!(
326-
"to use a constant of type `{}` in a pattern, \
327-
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
328-
cv.ty, cv.ty,
329-
);
330325
tcx.struct_span_lint_hir(
331326
lint::builtin::INDIRECT_STRUCTURAL_MATCH,
332327
id,
333328
span,
334-
|lint| lint.build(&msg).emit(),
329+
|lint| {
330+
let msg = format!(
331+
"to use a constant of type `{}` in a pattern, \
332+
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
333+
cv.ty, cv.ty,
334+
);
335+
lint.build(&msg).emit()
336+
},
335337
);
336338
}
337339
// Since we are behind a reference, we can just bubble the error up so we get a

compiler/rustc_parse/src/lexer/unescape_error_reporting.rs

+47-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::iter::once;
44
use std::ops::Range;
55

6-
use rustc_errors::{Applicability, Handler};
6+
use rustc_errors::{pluralize, Applicability, Handler};
77
use rustc_lexer::unescape::{EscapeError, Mode};
88
use rustc_span::{BytePos, Span};
99

@@ -49,24 +49,57 @@ pub(crate) fn emit_unescape_error(
4949
.emit();
5050
}
5151
EscapeError::MoreThanOneChar => {
52-
let (prefix, msg) = if mode.is_bytes() {
53-
("b", "if you meant to write a byte string literal, use double quotes")
54-
} else {
55-
("", "if you meant to write a `str` literal, use double quotes")
56-
};
52+
use unicode_normalization::{char::is_combining_mark, UnicodeNormalization};
5753

58-
handler
59-
.struct_span_err(
60-
span_with_quotes,
61-
"character literal may only contain one codepoint",
62-
)
63-
.span_suggestion(
54+
let mut has_help = false;
55+
let mut handler = handler.struct_span_err(
56+
span_with_quotes,
57+
"character literal may only contain one codepoint",
58+
);
59+
60+
if lit.chars().skip(1).all(|c| is_combining_mark(c)) {
61+
let escaped_marks =
62+
lit.chars().skip(1).map(|c| c.escape_default().to_string()).collect::<Vec<_>>();
63+
handler.span_note(
64+
span,
65+
&format!(
66+
"this `{}` is followed by the combining mark{} `{}`",
67+
lit.chars().next().unwrap(),
68+
pluralize!(escaped_marks.len()),
69+
escaped_marks.join(""),
70+
),
71+
);
72+
let normalized = lit.nfc().to_string();
73+
if normalized.chars().count() == 1 {
74+
has_help = true;
75+
handler.span_suggestion(
76+
span,
77+
&format!(
78+
"consider using the normalized form `{}` of this character",
79+
normalized.chars().next().unwrap().escape_default()
80+
),
81+
normalized,
82+
Applicability::MachineApplicable,
83+
);
84+
}
85+
}
86+
87+
if !has_help {
88+
let (prefix, msg) = if mode.is_bytes() {
89+
("b", "if you meant to write a byte string literal, use double quotes")
90+
} else {
91+
("", "if you meant to write a `str` literal, use double quotes")
92+
};
93+
94+
handler.span_suggestion(
6495
span_with_quotes,
6596
msg,
6697
format!("{}\"{}\"", prefix, lit),
6798
Applicability::MachineApplicable,
68-
)
69-
.emit();
99+
);
100+
}
101+
102+
handler.emit();
70103
}
71104
EscapeError::EscapeOnlyChar => {
72105
let (c, char_span) = last_char();

compiler/rustc_resolve/src/late/lifetimes.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,7 @@ fn item_for(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> LocalDefId {
522522
_ => {}
523523
}
524524
let item = {
525-
let hir = tcx.hir();
526-
let mut parent_iter = hir.parent_iter(hir_id);
525+
let mut parent_iter = tcx.hir().parent_iter(hir_id);
527526
loop {
528527
let node = parent_iter.next().map(|n| n.1);
529528
match node {

library/alloc/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#![feature(binary_heap_retain)]
1919
#![feature(binary_heap_as_slice)]
2020
#![feature(inplace_iteration)]
21-
#![feature(iter_map_while)]
2221
#![feature(slice_group_by)]
2322
#![feature(slice_partition_dedup)]
2423
#![feature(vec_spare_capacity)]

library/core/src/ascii.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::str::from_utf8_unchecked;
2121
#[stable(feature = "rust1", since = "1.0.0")]
2222
#[derive(Clone)]
2323
pub struct EscapeDefault {
24-
range: Range<usize>,
24+
range: Range<u8>,
2525
data: [u8; 4],
2626
}
2727

@@ -114,7 +114,7 @@ pub fn escape_default(c: u8) -> EscapeDefault {
114114
impl Iterator for EscapeDefault {
115115
type Item = u8;
116116
fn next(&mut self) -> Option<u8> {
117-
self.range.next().map(|i| self.data[i])
117+
self.range.next().map(|i| self.data[i as usize])
118118
}
119119
fn size_hint(&self) -> (usize, Option<usize>) {
120120
self.range.size_hint()
@@ -126,7 +126,7 @@ impl Iterator for EscapeDefault {
126126
#[stable(feature = "rust1", since = "1.0.0")]
127127
impl DoubleEndedIterator for EscapeDefault {
128128
fn next_back(&mut self) -> Option<u8> {
129-
self.range.next_back().map(|i| self.data[i])
129+
self.range.next_back().map(|i| self.data[i as usize])
130130
}
131131
}
132132
#[stable(feature = "rust1", since = "1.0.0")]
@@ -138,7 +138,9 @@ impl FusedIterator for EscapeDefault {}
138138
impl fmt::Display for EscapeDefault {
139139
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
140140
// SAFETY: ok because `escape_default` created only valid utf-8 data
141-
f.write_str(unsafe { from_utf8_unchecked(&self.data[self.range.clone()]) })
141+
f.write_str(unsafe {
142+
from_utf8_unchecked(&self.data[(self.range.start as usize)..(self.range.end as usize)])
143+
})
142144
}
143145
}
144146

library/core/src/iter/adapters/map_while.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::ops::{ControlFlow, Try};
1010
/// [`map_while`]: Iterator::map_while
1111
/// [`Iterator`]: trait.Iterator.html
1212
#[must_use = "iterators are lazy and do nothing unless consumed"]
13-
#[unstable(feature = "iter_map_while", reason = "recently added", issue = "68537")]
13+
#[stable(feature = "iter_map_while", since = "1.57.0")]
1414
#[derive(Clone)]
1515
pub struct MapWhile<I, P> {
1616
iter: I,
@@ -23,14 +23,14 @@ impl<I, P> MapWhile<I, P> {
2323
}
2424
}
2525

26-
#[unstable(feature = "iter_map_while", reason = "recently added", issue = "68537")]
26+
#[stable(feature = "iter_map_while", since = "1.57.0")]
2727
impl<I: fmt::Debug, P> fmt::Debug for MapWhile<I, P> {
2828
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2929
f.debug_struct("MapWhile").field("iter", &self.iter).finish()
3030
}
3131
}
3232

33-
#[unstable(feature = "iter_map_while", reason = "recently added", issue = "68537")]
33+
#[stable(feature = "iter_map_while", since = "1.57.0")]
3434
impl<B, I: Iterator, P> Iterator for MapWhile<I, P>
3535
where
3636
P: FnMut(I::Item) -> Option<B>,

library/core/src/iter/adapters/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub use self::copied::Copied;
4545
#[stable(feature = "iter_intersperse", since = "1.56.0")]
4646
pub use self::intersperse::{Intersperse, IntersperseWith};
4747

48-
#[unstable(feature = "iter_map_while", reason = "recently added", issue = "68537")]
48+
#[stable(feature = "iter_map_while", since = "1.57.0")]
4949
pub use self::map_while::MapWhile;
5050

5151
#[unstable(feature = "trusted_random_access", issue = "none")]

library/core/src/iter/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ pub use self::adapters::Cloned;
399399
pub use self::adapters::Copied;
400400
#[stable(feature = "iterator_flatten", since = "1.29.0")]
401401
pub use self::adapters::Flatten;
402-
#[unstable(feature = "iter_map_while", reason = "recently added", issue = "68537")]
402+
#[stable(feature = "iter_map_while", since = "1.57.0")]
403403
pub use self::adapters::MapWhile;
404404
#[unstable(feature = "inplace_iteration", issue = "none")]
405405
pub use self::adapters::SourceIter;

library/core/src/iter/traits/iterator.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,6 @@ pub trait Iterator {
11161116
/// Basic usage:
11171117
///
11181118
/// ```
1119-
/// #![feature(iter_map_while)]
11201119
/// let a = [-1i32, 4, 0, 1];
11211120
///
11221121
/// let mut iter = a.iter().map_while(|x| 16i32.checked_div(*x));
@@ -1147,7 +1146,6 @@ pub trait Iterator {
11471146
/// Stopping after an initial [`None`]:
11481147
///
11491148
/// ```
1150-
/// #![feature(iter_map_while)]
11511149
/// use std::convert::TryFrom;
11521150
///
11531151
/// let a = [0, 1, 2, -3, 4, 5, -6];
@@ -1165,7 +1163,6 @@ pub trait Iterator {
11651163
/// removed:
11661164
///
11671165
/// ```
1168-
/// #![feature(iter_map_while)]
11691166
/// use std::convert::TryFrom;
11701167
///
11711168
/// let a = [1, 2, -3, 4];
@@ -1191,7 +1188,7 @@ pub trait Iterator {
11911188
///
11921189
/// [`fuse`]: Iterator::fuse
11931190
#[inline]
1194-
#[unstable(feature = "iter_map_while", reason = "recently added", issue = "68537")]
1191+
#[stable(feature = "iter_map_while", since = "1.57.0")]
11951192
fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P>
11961193
where
11971194
Self: Sized,

library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
#![feature(iter_partition_in_place)]
5151
#![feature(iter_is_partitioned)]
5252
#![feature(iter_order_by)]
53-
#![feature(iter_map_while)]
5453
#![feature(const_mut_refs)]
5554
#![feature(const_pin)]
5655
#![feature(const_slice_from_raw_parts)]

library/std/src/error.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use crate::num;
3131
use crate::str;
3232
use crate::string;
3333
use crate::sync::Arc;
34+
use crate::time;
3435

3536
/// `Error` is a trait representing the basic expectations for error values,
3637
/// i.e., values of type `E` in [`Result<T, E>`].
@@ -598,7 +599,7 @@ impl Error for char::ParseCharError {
598599
impl Error for alloc::collections::TryReserveError {}
599600

600601
#[unstable(feature = "duration_checked_float", issue = "83400")]
601-
impl Error for core::time::FromSecsError {}
602+
impl Error for time::FromSecsError {}
602603

603604
// Copied from `any.rs`.
604605
impl dyn Error + 'static {

library/std/src/os/raw/char.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Equivalent to C's `char` type.
22

3-
[C's `char` type] is completely unlike [Rust's `char` type]; while Rust's type represents a unicode scalar value, C's `char` type is just an ordinary integer. This type will always be either [`i8`] or [`u8`], as the type is defined as being one byte long.
3+
[C's `char` type] is completely unlike [Rust's `char` type]; while Rust's type represents a unicode scalar value, C's `char` type is just an ordinary integer. On modern architectures this type will always be either [`i8`] or [`u8`], as they use byte-addresses memory with 8-bit bytes.
44

55
C chars are most commonly used to make C strings. Unlike Rust, where the length of a string is included alongside the string, C strings mark the end of a string with the character `'\0'`. See [`CStr`] for more information.
66

library/std/src/time.rs

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ use crate::sys_common::FromInner;
4444
#[stable(feature = "time", since = "1.3.0")]
4545
pub use core::time::Duration;
4646

47+
#[unstable(feature = "duration_checked_float", issue = "83400")]
48+
pub use core::time::FromSecsError;
49+
4750
/// A measurement of a monotonically nondecreasing clock.
4851
/// Opaque and useful only with [`Duration`].
4952
///

0 commit comments

Comments
 (0)