Skip to content

Commit 8c07d14

Browse files
committed
Auto merge of #137065 - jhpratt:rollup-ree9mej, r=jhpratt
Rollup of 9 pull requests Successful merges: - #135687 (re-export `FromCoroutine` from `core::iter`) - #135813 (CI: split i686-mingw job to three free runners) - #136749 (Implement Extend<AsciiChar> for String) - #136879 (Add safe new() to NotAllOnes) - #136978 (Windows: Update generated bindings) - #137028 (mir_build: Clarify some code for lowering `hir::PatExpr` to THIR) - #137029 (Remove unnecessary check code in unused_delims) - #137056 (made check_argument_compat public for use in miri) - #137062 (Forward all default methods for I/O impls) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f77247a + ba89ea8 commit 8c07d14

File tree

22 files changed

+2982
-2855
lines changed

22 files changed

+2982
-2855
lines changed

Cargo.lock

+2-13
Original file line numberDiff line numberDiff line change
@@ -6195,16 +6195,11 @@ dependencies = [
61956195

61966196
[[package]]
61976197
name = "windows-bindgen"
6198-
version = "0.58.0"
6198+
version = "0.59.0"
61996199
source = "registry+https://github.com/rust-lang/crates.io-index"
6200-
checksum = "91cd28d93c692351f3a6e5615567c56756e330bee1c99c6bdd57bfc5ab15f589"
6200+
checksum = "9b7fb600834d7e868f6e5bb748a86101427330fafbf9485c331b9d5f562d54a5"
62016201
dependencies = [
6202-
"proc-macro2",
62036202
"rayon",
6204-
"serde",
6205-
"serde_json",
6206-
"syn 2.0.96",
6207-
"windows-metadata",
62086203
]
62096204

62106205
[[package]]
@@ -6285,12 +6280,6 @@ dependencies = [
62856280
"syn 2.0.96",
62866281
]
62876282

6288-
[[package]]
6289-
name = "windows-metadata"
6290-
version = "0.58.0"
6291-
source = "registry+https://github.com/rust-lang/crates.io-index"
6292-
checksum = "2e837f3c3012cfe9e7086302a93f441a7999439be1ad4c530d55d2f6d2921809"
6293-
62946283
[[package]]
62956284
name = "windows-result"
62966285
version = "0.1.2"

compiler/rustc_const_eval/src/interpret/call.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
241241
interp_ok(caller == callee)
242242
}
243243

244-
fn check_argument_compat(
244+
/// Returns a `bool` saying whether the two arguments are ABI-compatible.
245+
pub fn check_argument_compat(
245246
&self,
246247
caller_abi: &ArgAbi<'tcx, Ty<'tcx>>,
247248
callee_abi: &ArgAbi<'tcx, Ty<'tcx>>,

compiler/rustc_lint/src/unused.rs

-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::iter;
2-
use std::ops::ControlFlow;
32

43
use rustc_ast as ast;
54
use rustc_ast::util::{classify, parser};
@@ -781,29 +780,6 @@ trait UnusedDelimLint {
781780
right_pos: Option<BytePos>,
782781
is_kw: bool,
783782
) {
784-
// If `value` has `ExprKind::Err`, unused delim lint can be broken.
785-
// For example, the following code caused ICE.
786-
// This is because the `ExprKind::Call` in `value` has `ExprKind::Err` as its argument
787-
// and this leads to wrong spans. #104897
788-
//
789-
// ```
790-
// fn f(){(print!(á
791-
// ```
792-
use rustc_ast::visit::{Visitor, walk_expr};
793-
struct ErrExprVisitor;
794-
impl<'ast> Visitor<'ast> for ErrExprVisitor {
795-
type Result = ControlFlow<()>;
796-
fn visit_expr(&mut self, expr: &'ast ast::Expr) -> ControlFlow<()> {
797-
if let ExprKind::Err(_) = expr.kind {
798-
ControlFlow::Break(())
799-
} else {
800-
walk_expr(self, expr)
801-
}
802-
}
803-
}
804-
if ErrExprVisitor.visit_expr(value).is_break() {
805-
return;
806-
}
807783
let spans = match value.kind {
808784
ast::ExprKind::Block(ref block, None) if let [stmt] = block.stmts.as_slice() => stmt
809785
.span

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

+44-38
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
189189

190190
// Lower the endpoint into a temporary `PatKind` that will then be
191191
// deconstructed to obtain the constant value and other data.
192-
let mut kind: PatKind<'tcx> = self.lower_lit(expr);
192+
let mut kind: PatKind<'tcx> = self.lower_pat_expr(expr);
193193

194194
// Unpeel any ascription or inline-const wrapper nodes.
195195
loop {
@@ -353,7 +353,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
353353

354354
hir::PatKind::Never => PatKind::Never,
355355

356-
hir::PatKind::Expr(value) => self.lower_lit(value),
356+
hir::PatKind::Expr(value) => self.lower_pat_expr(value),
357357

358358
hir::PatKind::Range(ref lo_expr, ref hi_expr, end) => {
359359
let (lo_expr, hi_expr) = (lo_expr.as_deref(), hi_expr.as_deref());
@@ -638,54 +638,57 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
638638
let ty = self.typeck_results.node_type(id);
639639
let res = self.typeck_results.qpath_res(qpath, id);
640640

641-
let pat_from_kind = |kind| Box::new(Pat { span, ty, kind });
642-
643-
let (def_id, is_associated_const) = match res {
644-
Res::Def(DefKind::Const, def_id) => (def_id, false),
645-
Res::Def(DefKind::AssocConst, def_id) => (def_id, true),
641+
let (def_id, user_ty) = match res {
642+
Res::Def(DefKind::Const, def_id) => (def_id, None),
643+
Res::Def(DefKind::AssocConst, def_id) => {
644+
(def_id, self.typeck_results.user_provided_types().get(id))
645+
}
646646

647-
_ => return pat_from_kind(self.lower_variant_or_leaf(res, id, span, ty, vec![])),
647+
_ => {
648+
// The path isn't the name of a constant, so it must actually
649+
// be a unit struct or unit variant (e.g. `Option::None`).
650+
let kind = self.lower_variant_or_leaf(res, id, span, ty, vec![]);
651+
return Box::new(Pat { span, ty, kind });
652+
}
648653
};
649654

655+
// Lower the named constant to a THIR pattern.
650656
let args = self.typeck_results.node_args(id);
651657
let c = ty::Const::new_unevaluated(self.tcx, ty::UnevaluatedConst { def: def_id, args });
652658
let subpattern = self.const_to_pat(c, ty, id, span);
653-
let pattern = Box::new(Pat {
654-
span,
655-
ty,
656-
kind: PatKind::ExpandedConstant { subpattern, def_id, is_inline: false },
657-
});
658659

659-
if !is_associated_const {
660-
return pattern;
661-
}
660+
// Wrap the pattern in a marker node to indicate that it is the result
661+
// of lowering a named constant. This marker is used for improved
662+
// diagnostics in some situations, but has no effect at runtime.
663+
let mut pattern = {
664+
let kind = PatKind::ExpandedConstant { subpattern, def_id, is_inline: false };
665+
Box::new(Pat { span, ty, kind })
666+
};
662667

663-
let user_provided_types = self.typeck_results.user_provided_types();
664-
if let Some(&user_ty) = user_provided_types.get(id) {
668+
// If this is an associated constant with an explicit user-written
669+
// type, add an ascription node (e.g. `<Foo<'a> as MyTrait>::CONST`).
670+
if let Some(&user_ty) = user_ty {
665671
let annotation = CanonicalUserTypeAnnotation {
666672
user_ty: Box::new(user_ty),
667673
span,
668674
inferred_ty: self.typeck_results.node_type(id),
669675
};
670-
Box::new(Pat {
671-
span,
672-
kind: PatKind::AscribeUserType {
673-
subpattern: pattern,
674-
ascription: Ascription {
675-
annotation,
676-
// Note that use `Contravariant` here. See the
677-
// `variance` field documentation for details.
678-
variance: ty::Contravariant,
679-
},
676+
let kind = PatKind::AscribeUserType {
677+
subpattern: pattern,
678+
ascription: Ascription {
679+
annotation,
680+
// Note that we use `Contravariant` here. See the
681+
// `variance` field documentation for details.
682+
variance: ty::Contravariant,
680683
},
681-
ty,
682-
})
683-
} else {
684-
pattern
684+
};
685+
pattern = Box::new(Pat { span, kind, ty });
685686
}
687+
688+
pattern
686689
}
687690

688-
/// Converts inline const patterns.
691+
/// Lowers an inline const block (e.g. `const { 1 + 1 }`) to a pattern.
689692
fn lower_inline_const(
690693
&mut self,
691694
block: &'tcx hir::ConstBlock,
@@ -705,14 +708,17 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
705708

706709
let ct = ty::UnevaluatedConst { def: def_id.to_def_id(), args };
707710
let subpattern = self.const_to_pat(ty::Const::new_unevaluated(self.tcx, ct), ty, id, span);
711+
712+
// Wrap the pattern in a marker node to indicate that it is the result
713+
// of lowering an inline const block.
708714
PatKind::ExpandedConstant { subpattern, def_id: def_id.to_def_id(), is_inline: true }
709715
}
710716

711-
/// Converts literals, paths and negation of literals to patterns.
712-
/// The special case for negation exists to allow things like `-128_i8`
713-
/// which would overflow if we tried to evaluate `128_i8` and then negate
714-
/// afterwards.
715-
fn lower_lit(&mut self, expr: &'tcx hir::PatExpr<'tcx>) -> PatKind<'tcx> {
717+
/// Lowers the kinds of "expression" that can appear in a HIR pattern:
718+
/// - Paths (e.g. `FOO`, `foo::BAR`, `Option::None`)
719+
/// - Inline const blocks (e.g. `const { 1 + 1 }`)
720+
/// - Literals, possibly negated (e.g. `-128u8`, `"hello"`)
721+
fn lower_pat_expr(&mut self, expr: &'tcx hir::PatExpr<'tcx>) -> PatKind<'tcx> {
716722
let (lit, neg) = match &expr.kind {
717723
hir::PatExprKind::Path(qpath) => {
718724
return self.lower_path(qpath, expr.hir_id, expr.span).kind;

library/alloc/src/string.rs

+26
Original file line numberDiff line numberDiff line change
@@ -2442,6 +2442,32 @@ impl<'a> Extend<Cow<'a, str>> for String {
24422442
}
24432443
}
24442444

2445+
#[cfg(not(no_global_oom_handling))]
2446+
#[unstable(feature = "ascii_char", issue = "110998")]
2447+
impl Extend<core::ascii::Char> for String {
2448+
fn extend<I: IntoIterator<Item = core::ascii::Char>>(&mut self, iter: I) {
2449+
self.vec.extend(iter.into_iter().map(|c| c.to_u8()));
2450+
}
2451+
2452+
#[inline]
2453+
fn extend_one(&mut self, c: core::ascii::Char) {
2454+
self.vec.push(c.to_u8());
2455+
}
2456+
}
2457+
2458+
#[cfg(not(no_global_oom_handling))]
2459+
#[unstable(feature = "ascii_char", issue = "110998")]
2460+
impl<'a> Extend<&'a core::ascii::Char> for String {
2461+
fn extend<I: IntoIterator<Item = &'a core::ascii::Char>>(&mut self, iter: I) {
2462+
self.extend(iter.into_iter().cloned());
2463+
}
2464+
2465+
#[inline]
2466+
fn extend_one(&mut self, c: &'a core::ascii::Char) {
2467+
self.vec.push(c.to_u8());
2468+
}
2469+
}
2470+
24452471
/// A convenience impl that delegates to the impl for `&str`.
24462472
///
24472473
/// # Examples

library/core/src/iter/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -420,14 +420,14 @@ pub use self::adapters::{Intersperse, IntersperseWith};
420420
issue = "42168"
421421
)]
422422
pub use self::range::Step;
423+
#[stable(feature = "iter_empty", since = "1.2.0")]
424+
pub use self::sources::{Empty, empty};
423425
#[unstable(
424426
feature = "iter_from_coroutine",
425427
issue = "43122",
426428
reason = "coroutines are unstable"
427429
)]
428-
pub use self::sources::from_coroutine;
429-
#[stable(feature = "iter_empty", since = "1.2.0")]
430-
pub use self::sources::{Empty, empty};
430+
pub use self::sources::{FromCoroutine, from_coroutine};
431431
#[stable(feature = "iter_from_fn", since = "1.34.0")]
432432
pub use self::sources::{FromFn, from_fn};
433433
#[stable(feature = "iter_once", since = "1.2.0")]

library/core/src/iter/sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use self::empty::{Empty, empty};
1515
issue = "43122",
1616
reason = "coroutines are unstable"
1717
)]
18-
pub use self::from_coroutine::from_coroutine;
18+
pub use self::from_coroutine::{FromCoroutine, from_coroutine};
1919
#[stable(feature = "iter_from_fn", since = "1.34.0")]
2020
pub use self::from_fn::{FromFn, from_fn};
2121
#[stable(feature = "iter_once", since = "1.2.0")]

library/core/src/num/niche_types.rs

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ macro_rules! define_valid_range_type {
3232
};
3333

3434
impl $name {
35+
#[inline]
36+
pub const fn new(val: $int) -> Option<Self> {
37+
if (val as $uint) >= ($low as $uint) && (val as $uint) <= ($high as $uint) {
38+
// SAFETY: just checked the inclusive range
39+
Some(unsafe { $name(val) })
40+
} else {
41+
None
42+
}
43+
}
44+
3545
/// Constructs an instance of this type from the underlying integer
3646
/// primitive without checking whether its zero.
3747
///

library/coretests/tests/ascii_char.rs

+12
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,15 @@ fn test_debug_control() {
2626
assert_eq!(want, format!("{chr:?}"), "byte: {byte}");
2727
}
2828
}
29+
30+
/// Tests Extend implementation for ascii::Char.
31+
#[test]
32+
fn test_extend() {
33+
let mut s = String::from("abc");
34+
s.extend_one(Char::SmallD);
35+
assert_eq!(s, String::from("abcd"));
36+
37+
let mut s = String::from("abc");
38+
s.extend(Char::CapitalA..=Char::CapitalC);
39+
assert_eq!(s, String::from("abcABC"));
40+
}

library/coretests/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#![feature(duration_constructors)]
2828
#![feature(error_generic_member_access)]
2929
#![feature(exact_size_is_empty)]
30+
#![feature(extend_one)]
3031
#![feature(extern_types)]
3132
#![feature(float_minimum_maximum)]
3233
#![feature(flt2dec)]

0 commit comments

Comments
 (0)