Skip to content

Commit c341a59

Browse files
committed
Auto merge of #55893 - pnkfelix:issue-55810-beta-backport-of-pr-55819, r=estebank
[beta] backport rollup (typeck match arms eagerly; add rustc_promotable to unsigneds) Backport of 5f91373 from (beta-accepted) PR #55819 Fix #55810 Fix #55806
2 parents 9142ac9 + 1e145d1 commit c341a59

File tree

6 files changed

+103
-4
lines changed

6 files changed

+103
-4
lines changed

src/libcore/num/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2152,6 +2152,7 @@ Basic usage:
21522152
", $Feature, "assert_eq!(", stringify!($SelfT), "::min_value(), 0);", $EndFeature, "
21532153
```"),
21542154
#[stable(feature = "rust1", since = "1.0.0")]
2155+
#[rustc_promotable]
21552156
#[inline]
21562157
pub const fn min_value() -> Self { 0 }
21572158
}
@@ -2168,6 +2169,7 @@ Basic usage:
21682169
stringify!($MaxV), ");", $EndFeature, "
21692170
```"),
21702171
#[stable(feature = "rust1", since = "1.0.0")]
2172+
#[rustc_promotable]
21712173
#[inline]
21722174
pub const fn max_value() -> Self { !0 }
21732175
}

src/librustc_typeck/check/_match.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,9 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
626626
let discrim_diverges = self.diverges.get();
627627
self.diverges.set(Diverges::Maybe);
628628

629-
// Typecheck the patterns first, so that we get types for all the
630-
// bindings.
631-
let all_arm_pats_diverge = arms.iter().map(|arm| {
629+
// rust-lang/rust#55810: Typecheck patterns first (via eager
630+
// collection into `Vec`), so we get types for all bindings.
631+
let all_arm_pats_diverge: Vec<_> = arms.iter().map(|arm| {
632632
let mut all_pats_diverge = Diverges::WarnedAlways;
633633
for p in &arm.pats {
634634
self.diverges.set(Diverges::Maybe);
@@ -644,7 +644,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
644644
Diverges::Maybe => Diverges::Maybe,
645645
Diverges::Always | Diverges::WarnedAlways => Diverges::WarnedAlways,
646646
}
647-
});
647+
}).collect();
648648

649649
// Now typecheck the blocks.
650650
//
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Crate that exports a const fn. Used for testing cross-crate.
12+
13+
#![feature(staged_api, rustc_attrs)]
14+
#![stable(since="1.0.0", feature = "mep")]
15+
16+
#![crate_type="rlib"]
17+
18+
#[rustc_promotable]
19+
#[stable(since="1.0.0", feature = "mep")]
20+
#[inline]
21+
pub const fn foo() -> usize { 22 }
22+
23+
#[stable(since="1.0.0", feature = "mep")]
24+
pub struct Foo(usize);
25+
26+
impl Foo {
27+
#[stable(since="1.0.0", feature = "mep")]
28+
#[inline]
29+
#[rustc_promotable]
30+
pub const fn foo() -> usize { 22 }
31+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// compile-pass
2+
// aux-build:promotable_const_fn_lib.rs
3+
4+
#![feature(nll)]
5+
6+
extern crate promotable_const_fn_lib;
7+
8+
use promotable_const_fn_lib::{foo, Foo};
9+
10+
fn main() {
11+
let x: &'static usize = &foo();
12+
let x: &'static usize = &Foo::foo();
13+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// compile-pass
2+
3+
#![feature(nll)]
4+
5+
fn main() {
6+
let x: &'static u8 = &u8::max_value();
7+
let x: &'static u16 = &u16::max_value();
8+
let x: &'static u32 = &u32::max_value();
9+
let x: &'static u64 = &u64::max_value();
10+
let x: &'static u128 = &u128::max_value();
11+
let x: &'static usize = &usize::max_value();
12+
let x: &'static u8 = &u8::min_value();
13+
let x: &'static u16 = &u16::min_value();
14+
let x: &'static u32 = &u32::min_value();
15+
let x: &'static u64 = &u64::min_value();
16+
let x: &'static u128 = &u128::min_value();
17+
let x: &'static usize = &usize::min_value();
18+
let x: &'static i8 = &i8::max_value();
19+
let x: &'static i16 = &i16::max_value();
20+
let x: &'static i32 = &i32::max_value();
21+
let x: &'static i64 = &i64::max_value();
22+
let x: &'static i128 = &i128::max_value();
23+
let x: &'static isize = &isize::max_value();
24+
let x: &'static i8 = &i8::min_value();
25+
let x: &'static i16 = &i16::min_value();
26+
let x: &'static i32 = &i32::min_value();
27+
let x: &'static i64 = &i64::min_value();
28+
let x: &'static i128 = &i128::min_value();
29+
let x: &'static isize = &isize::min_value();
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// compile-pass
2+
3+
// rust-lang/rust#55810: types for a binding in a match arm can be
4+
// inferred from arms that come later in the match.
5+
6+
struct S;
7+
8+
impl S {
9+
fn method(&self) -> bool {
10+
unimplemented!()
11+
}
12+
}
13+
14+
fn get<T>() -> T {
15+
unimplemented!()
16+
}
17+
18+
fn main() {
19+
match get() {
20+
x if x.method() => {}
21+
&S => {}
22+
}
23+
}

0 commit comments

Comments
 (0)