Skip to content

Commit 395e56f

Browse files
committed
Auto merge of #101617 - Dylan-DPC:rollup-iiy4ipc, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #101366 (Restore old behaviour on broken UNC paths) - #101492 (Suggest adding array lengths to references to arrays if possible) - #101529 (Fix the example code and doctest for Formatter::sign_plus) - #101573 (update `ParamKindOrd`) - #101612 (Fix code generation of `Rvalue::Repeat` with 128 bit values) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1d37ed6 + 07a9c10 commit 395e56f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+165
-182
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
3333
use rustc_span::source_map::{respan, Spanned};
3434
use rustc_span::symbol::{kw, sym, Ident, Symbol};
3535
use rustc_span::{Span, DUMMY_SP};
36-
use std::cmp::Ordering;
3736
use std::convert::TryFrom;
3837
use std::fmt;
3938
use std::mem;
@@ -324,46 +323,17 @@ pub type GenericBounds = Vec<GenericBound>;
324323
/// Specifies the enforced ordering for generic parameters. In the future,
325324
/// if we wanted to relax this order, we could override `PartialEq` and
326325
/// `PartialOrd`, to allow the kinds to be unordered.
327-
#[derive(Hash, Clone, Copy)]
326+
#[derive(Hash, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
328327
pub enum ParamKindOrd {
329328
Lifetime,
330-
Type,
331-
Const,
332-
// `Infer` is not actually constructed directly from the AST, but is implicitly constructed
333-
// during HIR lowering, and `ParamKindOrd` will implicitly order inferred variables last.
334-
Infer,
335-
}
336-
337-
impl Ord for ParamKindOrd {
338-
fn cmp(&self, other: &Self) -> Ordering {
339-
use ParamKindOrd::*;
340-
let to_int = |v| match v {
341-
Lifetime => 0,
342-
Infer | Type | Const => 1,
343-
};
344-
345-
to_int(*self).cmp(&to_int(*other))
346-
}
347-
}
348-
impl PartialOrd for ParamKindOrd {
349-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
350-
Some(self.cmp(other))
351-
}
352-
}
353-
impl PartialEq for ParamKindOrd {
354-
fn eq(&self, other: &Self) -> bool {
355-
self.cmp(other) == Ordering::Equal
356-
}
329+
TypeOrConst,
357330
}
358-
impl Eq for ParamKindOrd {}
359331

360332
impl fmt::Display for ParamKindOrd {
361333
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
362334
match self {
363335
ParamKindOrd::Lifetime => "lifetime".fmt(f),
364-
ParamKindOrd::Type => "type".fmt(f),
365-
ParamKindOrd::Const { .. } => "const".fmt(f),
366-
ParamKindOrd::Infer => "infer".fmt(f),
336+
ParamKindOrd::TypeOrConst => "type and const".fmt(f),
367337
}
368338
}
369339
}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,10 +839,10 @@ fn validate_generic_param_order(
839839
let (kind, bounds, span) = (&param.kind, &param.bounds, ident.span);
840840
let (ord_kind, ident) = match &param.kind {
841841
GenericParamKind::Lifetime => (ParamKindOrd::Lifetime, ident.to_string()),
842-
GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident.to_string()),
842+
GenericParamKind::Type { default: _ } => (ParamKindOrd::TypeOrConst, ident.to_string()),
843843
GenericParamKind::Const { ref ty, kw_span: _, default: _ } => {
844844
let ty = pprust::ty_to_string(ty);
845-
(ParamKindOrd::Const, format!("const {}: {}", ident, ty))
845+
(ParamKindOrd::TypeOrConst, format!("const {}: {}", ident, ty))
846846
}
847847
};
848848
param_idents.push((kind, ord_kind, bounds, idx, ident));

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
215215
}
216216

217217
fn const_to_opt_uint(&self, v: &'ll Value) -> Option<u64> {
218-
try_as_const_integral(v).map(|v| unsafe { llvm::LLVMConstIntGetZExtValue(v) })
218+
try_as_const_integral(v).and_then(|v| unsafe {
219+
let mut i = 0u64;
220+
let success = llvm::LLVMRustConstIntGetZExtValue(v, &mut i);
221+
success.then_some(i)
222+
})
219223
}
220224

221225
fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option<u128> {

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ extern "C" {
10961096
pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;
10971097
pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value;
10981098
pub fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value;
1099-
pub fn LLVMConstIntGetZExtValue(ConstantVal: &ConstantInt) -> c_ulonglong;
1099+
pub fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool;
11001100
pub fn LLVMRustConstInt128Get(
11011101
ConstantVal: &ConstantInt,
11021102
SExt: bool,

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
8787
let size = bx.const_usize(dest.layout.size.bytes());
8888

8989
// Use llvm.memset.p0i8.* to initialize all zero arrays
90-
if bx.cx().const_to_opt_uint(v) == Some(0) {
90+
if bx.cx().const_to_opt_u128(v, false) == Some(0) {
9191
let fill = bx.cx().const_u8(0);
9292
bx.memset(start, fill, size, dest.align, MemFlags::empty());
9393
return bx;

compiler/rustc_hir/src/hir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ impl GenericArg<'_> {
300300
pub fn to_ord(&self) -> ast::ParamKindOrd {
301301
match self {
302302
GenericArg::Lifetime(_) => ast::ParamKindOrd::Lifetime,
303-
GenericArg::Type(_) => ast::ParamKindOrd::Type,
304-
GenericArg::Const(_) => ast::ParamKindOrd::Const,
305-
GenericArg::Infer(_) => ast::ParamKindOrd::Infer,
303+
GenericArg::Type(_) | GenericArg::Const(_) | GenericArg::Infer(_) => {
304+
ast::ParamKindOrd::TypeOrConst
305+
}
306306
}
307307
}
308308

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,14 @@ extern "C" LLVMValueRef LLVMRustConstInBoundsGEP2(LLVMTypeRef Ty,
16181618
return wrap(ConstantExpr::getInBoundsGetElementPtr(unwrap(Ty), Val, IdxList));
16191619
}
16201620

1621+
extern "C" bool LLVMRustConstIntGetZExtValue(LLVMValueRef CV, uint64_t *value) {
1622+
auto C = unwrap<llvm::ConstantInt>(CV);
1623+
if (C->getBitWidth() > 64)
1624+
return false;
1625+
*value = C->getZExtValue();
1626+
return true;
1627+
}
1628+
16211629
// Returns true if both high and low were successfully set. Fails in case constant wasn’t any of
16221630
// the common sizes (1, 8, 16, 32, 64, 128 bits)
16231631
extern "C" bool LLVMRustConstInt128Get(LLVMValueRef CV, bool sext, uint64_t *high, uint64_t *low)

compiler/rustc_middle/src/ty/generics.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ impl GenericParamDefKind {
2727
pub fn to_ord(&self) -> ast::ParamKindOrd {
2828
match self {
2929
GenericParamDefKind::Lifetime => ast::ParamKindOrd::Lifetime,
30-
GenericParamDefKind::Type { .. } => ast::ParamKindOrd::Type,
31-
GenericParamDefKind::Const { .. } => ast::ParamKindOrd::Const,
30+
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
31+
ast::ParamKindOrd::TypeOrConst
32+
}
3233
}
3334
}
3435

compiler/rustc_typeck/src/collect/type_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
6565
let ty = item_ctxt.ast_ty_to_ty(hir_ty);
6666

6767
// Iterate through the generics of the projection to find the one that corresponds to
68-
// the def_id that this query was called with. We filter to only const args here as a
69-
// precaution for if it's ever allowed to elide lifetimes in GAT's. It currently isn't
68+
// the def_id that this query was called with. We filter to only type and const args here
69+
// as a precaution for if it's ever allowed to elide lifetimes in GAT's. It currently isn't
7070
// but it can't hurt to be safe ^^
7171
if let ty::Projection(projection) = ty.kind() {
7272
let generics = tcx.generics_of(projection.item_def_id);

library/std/src/sys/windows/path.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,7 @@ fn parse_next_component(path: &OsStr, verbatim: bool) -> (&OsStr, &OsStr) {
198198

199199
match path.bytes().iter().position(|&x| separator(x)) {
200200
Some(separator_start) => {
201-
let mut separator_end = separator_start + 1;
202-
203-
// a series of multiple separator characters is treated as a single separator,
204-
// except in verbatim paths
205-
while !verbatim && separator_end < path.len() && separator(path.bytes()[separator_end])
206-
{
207-
separator_end += 1;
208-
}
201+
let separator_end = separator_start + 1;
209202

210203
let component = &path.bytes()[..separator_start];
211204

0 commit comments

Comments
 (0)