Skip to content
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

Rollup of 9 pull requests #137065

Merged
merged 21 commits into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f02c3f8
re-export `core::iter::FromCoroutine`
joseluis Jan 18, 2025
d566b5d
Implement Extend<AsciiChar> for String
mzeitlin11 Feb 8, 2025
26eeac1
Windows: Update generated bindings to 0.59
ChrisDenton Feb 13, 2025
00683a0
CI: split i686-mingw job to three free runners
marcoieni Feb 14, 2025
00964aa
Add safe new to NotAllOnes
kornelski Feb 11, 2025
1284765
Rename `PatCtxt::lower_lit` to `lower_pat_expr`
Zalathar Feb 5, 2025
c3eea53
Clarify control-flow in `lower_path`
Zalathar Feb 4, 2025
92fc085
More comments for `lower_inline_const`
Zalathar Feb 5, 2025
b2197ab
Remove unnecessary check code in unused_delims
chenyukang Feb 14, 2025
f3fa720
made check_argument_compat public
geetanshjuneja Feb 15, 2025
11c1740
Forward all default methods for I/O impls
thaliaarchi Feb 15, 2025
8769d03
add a doc comment
RalfJung Feb 15, 2025
afbeefb
Rollup merge of #135687 - joseluis:feat-reexport_from_coroutine, r=sc…
jhpratt Feb 15, 2025
92adb92
Rollup merge of #135813 - marcoieni:free-runner-i686-mingw, r=jdno
jhpratt Feb 15, 2025
26be558
Rollup merge of #136749 - mzeitlin11:extend-asciichar, r=scottmcm
jhpratt Feb 15, 2025
1524b53
Rollup merge of #136879 - kornelski:non1, r=Noratrieb
jhpratt Feb 15, 2025
224be79
Rollup merge of #136978 - ChrisDenton:windows-bindgen, r=Amanieu
jhpratt Feb 15, 2025
c133123
Rollup merge of #137028 - Zalathar:thir-pat-expr, r=compiler-errors
jhpratt Feb 15, 2025
221ba2d
Rollup merge of #137029 - chenyukang:yukang-fix-unused-check, r=jieyo…
jhpratt Feb 15, 2025
6593a25
Rollup merge of #137056 - geetanshjuneja:pub, r=RalfJung
jhpratt Feb 15, 2025
ba89ea8
Rollup merge of #137062 - thaliaarchi:io-optional-methods/write, r=wo…
jhpratt Feb 15, 2025
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
15 changes: 2 additions & 13 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6195,16 +6195,11 @@ dependencies = [

[[package]]
name = "windows-bindgen"
version = "0.58.0"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91cd28d93c692351f3a6e5615567c56756e330bee1c99c6bdd57bfc5ab15f589"
checksum = "9b7fb600834d7e868f6e5bb748a86101427330fafbf9485c331b9d5f562d54a5"
dependencies = [
"proc-macro2",
"rayon",
"serde",
"serde_json",
"syn 2.0.96",
"windows-metadata",
]

[[package]]
Expand Down Expand Up @@ -6285,12 +6280,6 @@ dependencies = [
"syn 2.0.96",
]

[[package]]
name = "windows-metadata"
version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e837f3c3012cfe9e7086302a93f441a7999439be1ad4c530d55d2f6d2921809"

[[package]]
name = "windows-result"
version = "0.1.2"
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_const_eval/src/interpret/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
interp_ok(caller == callee)
}

fn check_argument_compat(
/// Returns a `bool` saying whether the two arguments are ABI-compatible.
pub fn check_argument_compat(
&self,
caller_abi: &ArgAbi<'tcx, Ty<'tcx>>,
callee_abi: &ArgAbi<'tcx, Ty<'tcx>>,
Expand Down
24 changes: 0 additions & 24 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::iter;
use std::ops::ControlFlow;

use rustc_ast as ast;
use rustc_ast::util::{classify, parser};
Expand Down Expand Up @@ -781,29 +780,6 @@ trait UnusedDelimLint {
right_pos: Option<BytePos>,
is_kw: bool,
) {
// If `value` has `ExprKind::Err`, unused delim lint can be broken.
// For example, the following code caused ICE.
// This is because the `ExprKind::Call` in `value` has `ExprKind::Err` as its argument
// and this leads to wrong spans. #104897
//
// ```
// fn f(){(print!(á
// ```
use rustc_ast::visit::{Visitor, walk_expr};
struct ErrExprVisitor;
impl<'ast> Visitor<'ast> for ErrExprVisitor {
type Result = ControlFlow<()>;
fn visit_expr(&mut self, expr: &'ast ast::Expr) -> ControlFlow<()> {
if let ExprKind::Err(_) = expr.kind {
ControlFlow::Break(())
} else {
walk_expr(self, expr)
}
}
}
if ErrExprVisitor.visit_expr(value).is_break() {
return;
}
let spans = match value.kind {
ast::ExprKind::Block(ref block, None) if let [stmt] = block.stmts.as_slice() => stmt
.span
Expand Down
82 changes: 44 additions & 38 deletions compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {

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

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

hir::PatKind::Never => PatKind::Never,

hir::PatKind::Expr(value) => self.lower_lit(value),
hir::PatKind::Expr(value) => self.lower_pat_expr(value),

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

let pat_from_kind = |kind| Box::new(Pat { span, ty, kind });

let (def_id, is_associated_const) = match res {
Res::Def(DefKind::Const, def_id) => (def_id, false),
Res::Def(DefKind::AssocConst, def_id) => (def_id, true),
let (def_id, user_ty) = match res {
Res::Def(DefKind::Const, def_id) => (def_id, None),
Res::Def(DefKind::AssocConst, def_id) => {
(def_id, self.typeck_results.user_provided_types().get(id))
}

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

// Lower the named constant to a THIR pattern.
let args = self.typeck_results.node_args(id);
let c = ty::Const::new_unevaluated(self.tcx, ty::UnevaluatedConst { def: def_id, args });
let subpattern = self.const_to_pat(c, ty, id, span);
let pattern = Box::new(Pat {
span,
ty,
kind: PatKind::ExpandedConstant { subpattern, def_id, is_inline: false },
});

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

let user_provided_types = self.typeck_results.user_provided_types();
if let Some(&user_ty) = user_provided_types.get(id) {
// If this is an associated constant with an explicit user-written
// type, add an ascription node (e.g. `<Foo<'a> as MyTrait>::CONST`).
if let Some(&user_ty) = user_ty {
let annotation = CanonicalUserTypeAnnotation {
user_ty: Box::new(user_ty),
span,
inferred_ty: self.typeck_results.node_type(id),
};
Box::new(Pat {
span,
kind: PatKind::AscribeUserType {
subpattern: pattern,
ascription: Ascription {
annotation,
// Note that use `Contravariant` here. See the
// `variance` field documentation for details.
variance: ty::Contravariant,
},
let kind = PatKind::AscribeUserType {
subpattern: pattern,
ascription: Ascription {
annotation,
// Note that we use `Contravariant` here. See the
// `variance` field documentation for details.
variance: ty::Contravariant,
},
ty,
})
} else {
pattern
};
pattern = Box::new(Pat { span, kind, ty });
}

pattern
}

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

let ct = ty::UnevaluatedConst { def: def_id.to_def_id(), args };
let subpattern = self.const_to_pat(ty::Const::new_unevaluated(self.tcx, ct), ty, id, span);

// Wrap the pattern in a marker node to indicate that it is the result
// of lowering an inline const block.
PatKind::ExpandedConstant { subpattern, def_id: def_id.to_def_id(), is_inline: true }
}

/// Converts literals, paths and negation of literals to patterns.
/// The special case for negation exists to allow things like `-128_i8`
/// which would overflow if we tried to evaluate `128_i8` and then negate
/// afterwards.
fn lower_lit(&mut self, expr: &'tcx hir::PatExpr<'tcx>) -> PatKind<'tcx> {
/// Lowers the kinds of "expression" that can appear in a HIR pattern:
/// - Paths (e.g. `FOO`, `foo::BAR`, `Option::None`)
/// - Inline const blocks (e.g. `const { 1 + 1 }`)
/// - Literals, possibly negated (e.g. `-128u8`, `"hello"`)
fn lower_pat_expr(&mut self, expr: &'tcx hir::PatExpr<'tcx>) -> PatKind<'tcx> {
let (lit, neg) = match &expr.kind {
hir::PatExprKind::Path(qpath) => {
return self.lower_path(qpath, expr.hir_id, expr.span).kind;
Expand Down
26 changes: 26 additions & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2442,6 +2442,32 @@ impl<'a> Extend<Cow<'a, str>> for String {
}
}

#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "ascii_char", issue = "110998")]
impl Extend<core::ascii::Char> for String {
fn extend<I: IntoIterator<Item = core::ascii::Char>>(&mut self, iter: I) {
self.vec.extend(iter.into_iter().map(|c| c.to_u8()));
}

#[inline]
fn extend_one(&mut self, c: core::ascii::Char) {
self.vec.push(c.to_u8());
}
}

#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "ascii_char", issue = "110998")]
impl<'a> Extend<&'a core::ascii::Char> for String {
fn extend<I: IntoIterator<Item = &'a core::ascii::Char>>(&mut self, iter: I) {
self.extend(iter.into_iter().cloned());
}

#[inline]
fn extend_one(&mut self, c: &'a core::ascii::Char) {
self.vec.push(c.to_u8());
}
}

/// A convenience impl that delegates to the impl for `&str`.
///
/// # Examples
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,14 @@ pub use self::adapters::{Intersperse, IntersperseWith};
issue = "42168"
)]
pub use self::range::Step;
#[stable(feature = "iter_empty", since = "1.2.0")]
pub use self::sources::{Empty, empty};
#[unstable(
feature = "iter_from_coroutine",
issue = "43122",
reason = "coroutines are unstable"
)]
pub use self::sources::from_coroutine;
#[stable(feature = "iter_empty", since = "1.2.0")]
pub use self::sources::{Empty, empty};
pub use self::sources::{FromCoroutine, from_coroutine};
#[stable(feature = "iter_from_fn", since = "1.34.0")]
pub use self::sources::{FromFn, from_fn};
#[stable(feature = "iter_once", since = "1.2.0")]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use self::empty::{Empty, empty};
issue = "43122",
reason = "coroutines are unstable"
)]
pub use self::from_coroutine::from_coroutine;
pub use self::from_coroutine::{FromCoroutine, from_coroutine};
#[stable(feature = "iter_from_fn", since = "1.34.0")]
pub use self::from_fn::{FromFn, from_fn};
#[stable(feature = "iter_once", since = "1.2.0")]
Expand Down
10 changes: 10 additions & 0 deletions library/core/src/num/niche_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ macro_rules! define_valid_range_type {
};

impl $name {
#[inline]
pub const fn new(val: $int) -> Option<Self> {
if (val as $uint) >= ($low as $uint) && (val as $uint) <= ($high as $uint) {
// SAFETY: just checked the inclusive range
Some(unsafe { $name(val) })
} else {
None
}
}

/// Constructs an instance of this type from the underlying integer
/// primitive without checking whether its zero.
///
Expand Down
12 changes: 12 additions & 0 deletions library/coretests/tests/ascii_char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ fn test_debug_control() {
assert_eq!(want, format!("{chr:?}"), "byte: {byte}");
}
}

/// Tests Extend implementation for ascii::Char.
#[test]
fn test_extend() {
let mut s = String::from("abc");
s.extend_one(Char::SmallD);
assert_eq!(s, String::from("abcd"));

let mut s = String::from("abc");
s.extend(Char::CapitalA..=Char::CapitalC);
assert_eq!(s, String::from("abcABC"));
}
1 change: 1 addition & 0 deletions library/coretests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#![feature(duration_constructors)]
#![feature(error_generic_member_access)]
#![feature(exact_size_is_empty)]
#![feature(extend_one)]
#![feature(extern_types)]
#![feature(float_minimum_maximum)]
#![feature(flt2dec)]
Expand Down
Loading
Loading