Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
2c752bc
Undeprecate env::home_dir
arlosi Feb 20, 2025
812b1de
ref_pat_eat_one_layer_2024: add context and examples to the unstable …
dianne Feb 21, 2025
9323ba5
Remove MaybeForgetReturn suggestion
compiler-errors Feb 20, 2025
a7bd4a3
Add DWARF test case for non-C-like `repr128` enums
beetrees Feb 25, 2025
fb3aa33
Revert "Derive `Clone` on fewer THIR types."
skius Feb 27, 2025
b5f0c82
Add note to Thir struct about necessity of Clone derive
skius Feb 27, 2025
b2bb7cc
Fix char count in Display for ByteStr
thaliaarchi Feb 28, 2025
41dd80a
add test to reproduce #137662 (using ty decl macro fragment in an att…
jdonszelmann Feb 26, 2025
50a37ca
miri native-call support: all previously exposed provenance is access…
RalfJung Feb 28, 2025
88f988c
use fixed-width integer types in C code
RalfJung Feb 28, 2025
476b098
adjust Layout debug printing to match the internal field names
RalfJung Feb 28, 2025
91034ad
Do not require that unsafe fields lack drop glue
jswrenn Feb 28, 2025
38b364b
rustc_fluent_macro: use CARGO_CRATE_NAME instead of CARGO_PKG_NAME
lolbinarycat Mar 1, 2025
adff091
Check dyn flavor before registering upcast goal on wide pointer cast …
compiler-errors Feb 25, 2025
649c0ff
Add minimal platform support documentation for powerpc-unknown-linux-…
taiki-e Mar 1, 2025
6867806
Document workings of successors more clearly
hkBst Jan 22, 2025
e213f4b
Improve error message for AsyncFn trait failure for RPIT
compiler-errors Mar 3, 2025
0aacfe9
interpret/provenance_map: consistently use range_is_empty
RalfJung Mar 3, 2025
133705c
[rustdoc] hide item that is not marked as doc(inline) and whose src i…
xizheyin Feb 27, 2025
a23566a
Provide more context on resolve error caused from incorrect RTN
estebank Feb 28, 2025
ab31129
Point of macro expansion from call expr if it involves macro var
compiler-errors Feb 24, 2025
e4dfca8
Point out macro expansion ident in resolver errors too
compiler-errors Feb 24, 2025
0607246
Fix associated type errors too
compiler-errors Feb 24, 2025
09e5846
Also note struct access, and fix macro expansion from foreign crates
compiler-errors Feb 24, 2025
69c4651
ci: use ubuntu 24 on arm large runner
marcoieni Mar 4, 2025
da3e736
Clarify why InhabitedPredicate::instantiate_opt exists
meithecatte Feb 28, 2025
a3d63fb
InhabitedPredicate: avoid using a wildcard branch
meithecatte Mar 3, 2025
3d62b27
Ensure that negative auto impls are always applicable
compiler-errors Feb 28, 2025
05a8060
Make rustdoc tests use always applicable negative auto impls
compiler-errors Feb 28, 2025
7923031
Update `compiler-builtins` to 0.1.151
tgross35 Mar 5, 2025
cb7d687
Implement `&pin const self` and `&pin mut self` sugars
frank-king Jan 19, 2025
52cd874
Simplify `parse_self_param`
frank-king Mar 5, 2025
50d0f99
Simplify `rewrite_explicit_self`
frank-king Mar 5, 2025
4f2b108
Prefer a two value enum over bool
oli-obk Feb 12, 2025
0e7b283
Avoid having to handle an `Option` in the type system
oli-obk Feb 5, 2025
e8f7a38
Remove the `Option` part of range ends in the HIR
oli-obk Feb 5, 2025
a2c1211
Hide the end of ranges in pretty printing if it's also the maximum of…
oli-obk Feb 5, 2025
91826b6
Rollup merge of #135733 - frank-king:feature/pin-self-receiver, r=oli…
compiler-errors Mar 6, 2025
5b07412
Rollup merge of #135895 - hkBst:patch-15, r=joboet
compiler-errors Mar 6, 2025
6ac714d
Rollup merge of #136922 - oli-obk:pattern-types-option-ends, r=BoxyUwU
compiler-errors Mar 6, 2025
ca9f615
Rollup merge of #137303 - compiler-errors:maybe-forgor, r=cjgillot
compiler-errors Mar 6, 2025
978893a
Rollup merge of #137327 - arlosi:home-dir, r=Mark-Simulacrum
compiler-errors Mar 6, 2025
98dfe93
Rollup merge of #137358 - dianne:new-match-ergonomics-examples, r=Nad…
compiler-errors Mar 6, 2025
cc5d90c
Rollup merge of #137534 - xizheyin:issue-137342, r=GuillaumeGomez
compiler-errors Mar 6, 2025
aab7b14
Rollup merge of #137565 - compiler-errors:macro-ex, r=estebank
compiler-errors Mar 6, 2025
3152f16
Rollup merge of #137637 - compiler-errors:dyn-cast-from-dyn-star, r=o…
compiler-errors Mar 6, 2025
e05a977
Rollup merge of #137643 - beetrees:repr128-dwarf-variant-test, r=jiey…
compiler-errors Mar 6, 2025
91175bd
Rollup merge of #137744 - skius:master, r=Nadrieril
compiler-errors Mar 6, 2025
34d273b
Rollup merge of #137758 - jdonszelmann:fix-137662, r=nnethercote
compiler-errors Mar 6, 2025
0013214
Rollup merge of #137764 - compiler-errors:always-applicable-negative-…
compiler-errors Mar 6, 2025
fe92638
Rollup merge of #137772 - thaliaarchi:bstr-display, r=joshtriplett
compiler-errors Mar 6, 2025
59cd967
Rollup merge of #137798 - marcoieni:ubuntu-24-large-runner-arm, r=Kobzol
compiler-errors Mar 6, 2025
b7b2179
Rollup merge of #137802 - RalfJung:miri-native-call-exposed, r=oli-obk
compiler-errors Mar 6, 2025
73d033f
Rollup merge of #137805 - RalfJung:layout-debug-print, r=Noratrieb
compiler-errors Mar 6, 2025
1c3733a
Rollup merge of #137808 - jswrenn:droppy-unsafe-fields, r=nnethercote
compiler-errors Mar 6, 2025
1e3a038
Rollup merge of #137820 - meithecatte:instantiate-opt, r=BoxyUwU
compiler-errors Mar 6, 2025
484d8dd
Rollup merge of #137825 - estebank:rtn-sugg-2, r=compiler-errors
compiler-errors Mar 6, 2025
56f0a60
Rollup merge of #137834 - lolbinarycat:rustc_fluent_macro-137815, r=B…
compiler-errors Mar 6, 2025
38b4820
Rollup merge of #137868 - taiki-e:powerpcspe-doc, r=workingjubilee
compiler-errors Mar 6, 2025
1458b35
Rollup merge of #137910 - compiler-errors:async-fn-goal-error, r=oli-obk
compiler-errors Mar 6, 2025
d21fc9d
Rollup merge of #137920 - RalfJung:provenance-map-emptiness, r=oli-obk
compiler-errors Mar 6, 2025
071bc46
Rollup merge of #138038 - tgross35:update-builtins, r=tgross35
compiler-errors Mar 6, 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
Prev Previous commit
Next Next commit
Hide the end of ranges in pretty printing if it's also the maximum of…
… the type
  • Loading branch information
oli-obk committed Mar 6, 2025
commit a2c1211b6de0c1a93c3ff1f97c49acc237f620a6
24 changes: 23 additions & 1 deletion compiler/rustc_middle/src/ty/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,29 @@ impl<'tcx> fmt::Debug for PatternKind<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
PatternKind::Range { start, end } => {
write!(f, "{start}..={end}")
write!(f, "{start}")?;

if let Some(c) = end.try_to_value() {
let end = c.valtree.unwrap_leaf();
let size = end.size();
let max = match c.ty.kind() {
ty::Int(_) => {
Some(ty::ScalarInt::truncate_from_int(size.signed_int_max(), size))
}
ty::Uint(_) => {
Some(ty::ScalarInt::truncate_from_uint(size.unsigned_int_max(), size))
}
ty::Char => Some(ty::ScalarInt::truncate_from_uint(char::MAX, size)),
_ => None,
};
if let Some((max, _)) = max
&& end == max
{
return write!(f, "..");
}
}

write!(f, "..={end}")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/pattern_type_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn bar() {
// CHECK: call pattern_type_symbols::foo::<u32>
// CHECK: call void @_RINvC[[CRATE_IDENT:[a-zA-Z0-9]{12}]]_20pattern_type_symbols3foomEB2_
foo::<u32>();
// CHECK: call pattern_type_symbols::foo::<(u32, [(); 0], [(); 999999999], [(); true])>
// CHECK: call void @_RINvC[[CRATE_IDENT]]_20pattern_type_symbols3fooTmAum0_Aum3b9ac9ff_Aub1_EEB2_
// CHECK: call pattern_type_symbols::foo::<(u32, [(); 0], [(); 999999999])>
// CHECK: call void @_RINvC[[CRATE_IDENT]]_20pattern_type_symbols3fooTmAum0_Aum3b9ac9ff_EEB2_
foo::<NanoU32>();
}
4 changes: 2 additions & 2 deletions tests/mir-opt/pattern_types.main.PreCodegen.after.mir
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
fn main() -> () {
let mut _0: ();
scope 1 {
debug x => const 2_u32 is 1..=u32::MAX;
debug x => const 2_u32 is 1..;
scope 2 {
debug y => const {transmute(0x00000000): (u32) is 1..=u32::MAX};
debug y => const {transmute(0x00000000): (u32) is 1..};
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/mir-opt/pattern_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::pat::pattern_type;

// EMIT_MIR pattern_types.main.PreCodegen.after.mir
fn main() {
// CHECK: debug x => const 2_u32 is 1..=u32::MAX
// CHECK: debug x => const 2_u32 is 1..
let x: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(2) };
// CHECK: debug y => const {transmute(0x00000000): (u32) is 1..=u32::MAX}
// CHECK: debug y => const {transmute(0x00000000): (u32) is 1..}
let y: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(0) };
}
2 changes: 1 addition & 1 deletion tests/ui/lint/clashing-extern-fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LL | fn hidden_niche_unsafe_cell() -> Option<UnsafeCell<NonZero<usiz
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint

warning: `extern` block uses type `Option<(usize) is 0..=usize::MAX>`, which is not FFI-safe
warning: `extern` block uses type `Option<(usize) is 0..>`, which is not FFI-safe
--> $DIR/clashing-extern-fn.rs:502:54
|
LL | fn pt_non_zero_usize_opt_full_range() -> Option<pattern_type!(usize is 0..)>;
Expand Down
28 changes: 14 additions & 14 deletions tests/ui/type/pattern_types/nested.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ error[E0308]: mismatched types
--> $DIR/nested.rs:10:63
|
LL | const BAD_NESTING: pattern_type!(pattern_type!(u32 is 1..) is 0..) = todo!();
| ^ expected `(u32) is 1..=u32::MAX`, found integer
| ^ expected `(u32) is 1..`, found integer
|
= note: expected pattern type `(u32) is 1..=u32::MAX`
= note: expected pattern type `(u32) is 1..`
found type `{integer}`

error[E0277]: `(u32) is 1..=u32::MAX` is not a valid base type for range patterns
error[E0277]: `(u32) is 1..` is not a valid base type for range patterns
--> $DIR/nested.rs:10:34
|
LL | const BAD_NESTING: pattern_type!(pattern_type!(u32 is 1..) is 0..) = todo!();
| ^^^^^^^^^^^^^^^^^^^^^^^^^ only integer types and `char` are supported
|
= help: the trait `core::pat::RangePattern` is not implemented for `(u32) is 1..=u32::MAX`
= help: the trait `core::pat::RangePattern` is not implemented for `(u32) is 1..`
= help: the following other types implement trait `core::pat::RangePattern`:
char
i128
Expand All @@ -25,13 +25,13 @@ LL | const BAD_NESTING: pattern_type!(pattern_type!(u32 is 1..) is 0..) = todo!(
u128
and 5 others

error[E0277]: `(i32) is 1..=i32::MAX` is not a valid base type for range patterns
error[E0277]: `(i32) is 1..` is not a valid base type for range patterns
--> $DIR/nested.rs:15:35
|
LL | const BAD_NESTING2: pattern_type!(pattern_type!(i32 is 1..) is ..=-1) = todo!();
| ^^^^^^^^^^^^^^^^^^^^^^^^^ only integer types and `char` are supported
|
= help: the trait `core::pat::RangePattern` is not implemented for `(i32) is 1..=i32::MAX`
= help: the trait `core::pat::RangePattern` is not implemented for `(i32) is 1..`
= help: the following other types implement trait `core::pat::RangePattern`:
char
i128
Expand All @@ -47,18 +47,18 @@ error[E0308]: mismatched types
--> $DIR/nested.rs:15:67
|
LL | const BAD_NESTING2: pattern_type!(pattern_type!(i32 is 1..) is ..=-1) = todo!();
| ^^ expected `(i32) is 1..=i32::MAX`, found integer
| ^^ expected `(i32) is 1..`, found integer
|
= note: expected pattern type `(i32) is 1..=i32::MAX`
= note: expected pattern type `(i32) is 1..`
found type `{integer}`

error[E0277]: `(i32) is 1..=i32::MAX` is not a valid base type for range patterns
error[E0277]: `(i32) is 1..` is not a valid base type for range patterns
--> $DIR/nested.rs:19:35
|
LL | const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo!();
| ^^^^^^^^^^^^^^^^^^^^^^^^^ only integer types and `char` are supported
|
= help: the trait `core::pat::RangePattern` is not implemented for `(i32) is 1..=i32::MAX`
= help: the trait `core::pat::RangePattern` is not implemented for `(i32) is 1..`
= help: the following other types implement trait `core::pat::RangePattern`:
char
i128
Expand All @@ -76,10 +76,10 @@ error[E0308]: mismatched types
LL | const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo!();
| ^
| |
| expected `(i32) is 1..=i32::MAX`, found integer
| expected `(i32) is 1..`, found integer
| arguments to this function are incorrect
|
= note: expected pattern type `(i32) is 1..=i32::MAX`
= note: expected pattern type `(i32) is 1..`
found type `{integer}`
help: the return type of this call is `{integer}` due to the type of the argument passed
--> $DIR/nested.rs:19:66
Expand All @@ -89,13 +89,13 @@ LL | const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo!
note: method defined here
--> $SRC_DIR/core/src/pat.rs:LL:COL

error[E0277]: `(i32) is 1..=i32::MAX` is not a valid base type for range patterns
error[E0277]: `(i32) is 1..` is not a valid base type for range patterns
--> $DIR/nested.rs:19:66
|
LL | const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo!();
| ^ only integer types and `char` are supported
|
= help: the trait `core::pat::RangePattern` is not implemented for `(i32) is 1..=i32::MAX`
= help: the trait `core::pat::RangePattern` is not implemented for `(i32) is 1..`
= help: the following other types implement trait `core::pat::RangePattern`:
char
i128
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/type/pattern_types/range_patterns.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ error: layout_of(NonZero<u32>) = Layout {
LL | type X = std::num::NonZeroU32;
| ^^^^^^

error: layout_of((u32) is 1..=u32::MAX) = Layout {
error: layout_of((u32) is 1..) = Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
Expand Down Expand Up @@ -83,7 +83,7 @@ error: layout_of((u32) is 1..=u32::MAX) = Layout {
LL | type Y = pattern_type!(u32 is 1..);
| ^^^^^^

error: layout_of(Option<(u32) is 1..=u32::MAX>) = Layout {
error: layout_of(Option<(u32) is 1..>) = Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/type/pattern_types/range_patterns_unusable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0512]: cannot transmute between types of different sizes, or dependently-
LL | let _: Option<u32> = unsafe { std::mem::transmute(z) };
| ^^^^^^^^^^^^^^^^^^^
|
= note: source type: `Option<(u32) is 1..=u32::MAX>` (32 bits)
= note: source type: `Option<(u32) is 1..>` (32 bits)
= note: target type: `Option<u32>` (64 bits)

error: aborting due to 1 previous error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ type Z = Option<pattern_type!(u32 is 1..)>;

fn main() {
let x: Y = unsafe { std::mem::transmute(42_u32) };
let x = x + 1_u32; //~ ERROR cannot add `u32` to `(u32) is 1..=u32::MAX`
let x = x + 1_u32; //~ ERROR cannot add `u32` to `(u32) is 1..`
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0369]: cannot add `u32` to `(u32) is 1..=u32::MAX`
error[E0369]: cannot add `u32` to `(u32) is 1..`
--> $DIR/range_patterns_unusable_math.rs:14:15
|
LL | let x = x + 1_u32;
| - ^ ----- u32
| |
| (u32) is 1..=u32::MAX
| (u32) is 1..

error: aborting due to 1 previous error

Expand Down
Loading