Skip to content

Commit 395e56f

Browse files
committed
Auto merge of rust-lang#101617 - Dylan-DPC:rollup-iiy4ipc, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#101366 (Restore old behaviour on broken UNC paths) - rust-lang#101492 (Suggest adding array lengths to references to arrays if possible) - rust-lang#101529 (Fix the example code and doctest for Formatter::sign_plus) - rust-lang#101573 (update `ParamKindOrd`) - rust-lang#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

+3-33
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

+2-2
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

+5-1
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

+1-1
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

+1-1
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

+3-3
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

+8
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

+3-2
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

+2-2
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

+1-8
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

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

+19-10
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ fn test_parse_next_component() {
3131
parse_next_component(OsStr::new(r"servershare"), false),
3232
(OsStr::new(r"servershare"), OsStr::new(""))
3333
);
34-
35-
assert_eq!(
36-
parse_next_component(OsStr::new(r"server/\//\/\\\\/////\/share"), false),
37-
(OsStr::new(r"server"), OsStr::new(r"share"))
38-
);
39-
40-
assert_eq!(
41-
parse_next_component(OsStr::new(r"server\\\\\\\\\\\\\\share"), true),
42-
(OsStr::new(r"server"), OsStr::new(r"\\\\\\\\\\\\\share"))
43-
);
4434
}
4535

4636
#[test]
@@ -126,3 +116,22 @@ fn test_windows_prefix_components() {
126116
assert_eq!(drive.as_os_str(), OsStr::new("C:"));
127117
assert_eq!(components.as_path(), Path::new(""));
128118
}
119+
120+
/// See #101358.
121+
///
122+
/// Note that the exact behaviour here may change in the future.
123+
/// In which case this test will need to adjusted.
124+
#[test]
125+
fn broken_unc_path() {
126+
use crate::path::Component;
127+
128+
let mut components = Path::new(r"\\foo\\bar\\").components();
129+
assert_eq!(components.next(), Some(Component::RootDir));
130+
assert_eq!(components.next(), Some(Component::Normal("foo".as_ref())));
131+
assert_eq!(components.next(), Some(Component::Normal("bar".as_ref())));
132+
133+
let mut components = Path::new("//foo//bar//").components();
134+
assert_eq!(components.next(), Some(Component::RootDir));
135+
assert_eq!(components.next(), Some(Component::Normal("foo".as_ref())));
136+
assert_eq!(components.next(), Some(Component::Normal("bar".as_ref())));
137+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for issue 101585.
2+
// run-pass
3+
4+
fn main() {
5+
fn min_array_ok() -> [i128; 1] {
6+
[i128::MIN]
7+
}
8+
assert_eq!(min_array_ok(), [-170141183460469231731687303715884105728i128]);
9+
10+
fn min_array_nok() -> [i128; 1] {
11+
[i128::MIN; 1]
12+
}
13+
assert_eq!(min_array_nok(), [-170141183460469231731687303715884105728i128]);
14+
}

src/test/ui/const-generics/argument_order.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: lifetime parameters must be declared prior to const parameters
1+
error: lifetime parameters must be declared prior to type and const parameters
22
--> $DIR/argument_order.rs:6:32
33
|
44
LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
@@ -11,7 +11,7 @@ LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>;
1111
| ^^^^^^^
1212
|
1313
= note: lifetime arguments must be provided before type arguments
14-
= help: reorder the arguments: lifetimes, then consts: `<'a, 'b, N, T, M, U>`
14+
= help: reorder the arguments: lifetimes, then type and consts: `<'a, 'b, N, T, M, U>`
1515

1616
error: aborting due to 2 previous errors
1717

src/test/ui/const-generics/const-param-before-other-params.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn bar<const X: u8, 'a>(_: &'a ()) {
2-
//~^ ERROR lifetime parameters must be declared prior to const parameters
2+
//~^ ERROR lifetime parameters must be declared prior to type and const parameters
33
}
44

55
fn foo<const X: u8, T>(_: &T) {}

src/test/ui/const-generics/const-param-before-other-params.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: lifetime parameters must be declared prior to const parameters
1+
error: lifetime parameters must be declared prior to type and const parameters
22
--> $DIR/const-param-before-other-params.rs:1:21
33
|
44
LL | fn bar<const X: u8, 'a>(_: &'a ()) {
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Checks that lifetimes cannot be interspersed between consts and types.
22

33
struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
4-
//~^ Error lifetime parameters must be declared prior to const parameters
4+
//~^ ERROR lifetime parameters must be declared prior to type and const parameters
55

66
struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
7-
//~^ Error lifetime parameters must be declared prior to type parameters
7+
//~^ ERROR lifetime parameters must be declared prior to type and const parameters
88

99
fn main() {}

src/test/ui/const-generics/defaults/intermixed-lifetime.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: lifetime parameters must be declared prior to const parameters
1+
error: lifetime parameters must be declared prior to type and const parameters
22
--> $DIR/intermixed-lifetime.rs:3:28
33
|
44
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
55
| -----------------^^---------- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>`
66

7-
error: lifetime parameters must be declared prior to type parameters
7+
error: lifetime parameters must be declared prior to type and const parameters
88
--> $DIR/intermixed-lifetime.rs:6:37
99
|
1010
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
struct Foo<const M: usize = 10, 'a>(&'a u32);
2-
//~^ Error lifetime parameters must be declared prior to const parameters
2+
//~^ ERROR lifetime parameters must be declared prior to type and const parameters
33

44
fn main() {}

src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: lifetime parameters must be declared prior to const parameters
1+
error: lifetime parameters must be declared prior to type and const parameters
22
--> $DIR/param-order-err-pretty-prints-default.rs:1:33
33
|
44
LL | struct Foo<const M: usize = 10, 'a>(&'a u32);

src/test/ui/generics/issue-59508-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct A;
88

99
impl A {
1010
pub fn do_things<T, 'a, 'b: 'a>() {
11-
//~^ ERROR lifetime parameters must be declared prior to type parameters
11+
//~^ ERROR lifetime parameters must be declared prior to type and const parameters
1212
println!("panic");
1313
}
1414
}

src/test/ui/generics/issue-59508-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: lifetime parameters must be declared prior to type parameters
1+
error: lifetime parameters must be declared prior to type and const parameters
22
--> $DIR/issue-59508-1.rs:10:25
33
|
44
LL | pub fn do_things<T, 'a, 'b: 'a>() {

src/test/ui/generics/issue-59508.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct A;
88

99
impl A {
1010
pub fn do_things<'a, 'b: 'a, T>() {
11-
//~^ ERROR lifetime parameters must be declared prior to type parameters
11+
//~^ ERROR lifetime parameters must be declared prior to type and const parameters
1212
println!("panic");
1313
}
1414
}

src/test/ui/generics/issue-59508.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct A;
88

99
impl A {
1010
pub fn do_things<T, 'a, 'b: 'a>() {
11-
//~^ ERROR lifetime parameters must be declared prior to type parameters
11+
//~^ ERROR lifetime parameters must be declared prior to type and const parameters
1212
println!("panic");
1313
}
1414
}

src/test/ui/generics/issue-59508.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: lifetime parameters must be declared prior to type parameters
1+
error: lifetime parameters must be declared prior to type and const parameters
22
--> $DIR/issue-59508.rs:10:25
33
|
44
LL | pub fn do_things<T, 'a, 'b: 'a>() {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#![crate_type = "lib"]
22

33
struct S<T = (), 'a>(&'a T);
4-
//~^ ERROR lifetime parameters must be declared prior to type parameters
4+
//~^ ERROR lifetime parameters must be declared prior to type and const parameters

src/test/ui/generics/issue-80512-param-reordering-with-defaults.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: lifetime parameters must be declared prior to type parameters
1+
error: lifetime parameters must be declared prior to type and const parameters
22
--> $DIR/issue-80512-param-reordering-with-defaults.rs:3:18
33
|
44
LL | struct S<T = (), 'a>(&'a T);
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#![allow(unused)]
22
fn first<T, 'a, 'b>() {}
3-
//~^ ERROR lifetime parameters must be declared prior to type parameters
3+
//~^ ERROR lifetime parameters must be declared prior to type and const parameters
44
fn second<'a, T, 'b>() {}
5-
//~^ ERROR lifetime parameters must be declared prior to type parameters
5+
//~^ ERROR lifetime parameters must be declared prior to type and const parameters
66
fn third<T, U, 'a>() {}
7-
//~^ ERROR lifetime parameters must be declared prior to type parameters
7+
//~^ ERROR lifetime parameters must be declared prior to type and const parameters
88
fn fourth<'a, T, 'b, U, 'c, V>() {}
9-
//~^ ERROR lifetime parameters must be declared prior to type parameters
9+
//~^ ERROR lifetime parameters must be declared prior to type and const parameters
1010

1111
fn main() {}

src/test/ui/generics/lifetime-before-type-params.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
error: lifetime parameters must be declared prior to type parameters
1+
error: lifetime parameters must be declared prior to type and const parameters
22
--> $DIR/lifetime-before-type-params.rs:2:13
33
|
44
LL | fn first<T, 'a, 'b>() {}
55
| ----^^--^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>`
66

7-
error: lifetime parameters must be declared prior to type parameters
7+
error: lifetime parameters must be declared prior to type and const parameters
88
--> $DIR/lifetime-before-type-params.rs:4:18
99
|
1010
LL | fn second<'a, T, 'b>() {}
1111
| --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>`
1212

13-
error: lifetime parameters must be declared prior to type parameters
13+
error: lifetime parameters must be declared prior to type and const parameters
1414
--> $DIR/lifetime-before-type-params.rs:6:16
1515
|
1616
LL | fn third<T, U, 'a>() {}
1717
| -------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, T, U>`
1818

19-
error: lifetime parameters must be declared prior to type parameters
19+
error: lifetime parameters must be declared prior to type and const parameters
2020
--> $DIR/lifetime-before-type-params.rs:8:18
2121
|
2222
LL | fn fourth<'a, T, 'b, U, 'c, V>() {}

src/test/ui/parser/issues/issue-14303-enum.rs

-6
This file was deleted.

src/test/ui/parser/issues/issue-14303-enum.stderr

-8
This file was deleted.

0 commit comments

Comments
 (0)