Skip to content

Rollup of 23 pull requests #140231

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

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
fe03f76
std: Add performance warnings to HashMap::get_disjoint_mut
xizheyin Apr 3, 2025
2678d04
mitigate MSVC unsoundness by not emitting alignment attributes on win…
RalfJung Apr 2, 2025
e702f96
check_align: we can still check low alignments on MSVC
RalfJung Apr 4, 2025
75f86e6
fix LooseTypes flag and PrintMod behaviour, add debug helper
ZuseZ4 Apr 12, 2025
31578dc
fix "could not find source function" error by preventing function mer…
ZuseZ4 Apr 12, 2025
5ea9125
update documentation
ZuseZ4 Apr 12, 2025
f79a992
add tests for merge_function handling
ZuseZ4 Apr 12, 2025
35a20de
Implement `SmirInterface`
makai410 Apr 18, 2025
16381b3
Use `currently` for futher improvement
xizheyin Apr 20, 2025
2ef4f78
rustc_target: Adjust RISC-V feature implication
a4lg Apr 22, 2025
90fe280
Move `sys::pal::os::Env` into `sys::env`
thaliaarchi Apr 22, 2025
6518bcb
Fix `unsafe_op_in_unsafe_fn` for Unix env
thaliaarchi Apr 22, 2025
1b00ebe
Update !DynSend and !DynSync platform impls
thaliaarchi Apr 22, 2025
4695212
Deduplicate unsupported env items
thaliaarchi Apr 22, 2025
01485c9
Unify owned `Env` types between platforms
thaliaarchi Apr 22, 2025
08baec4
add a test for byte string literal pattern mutability mismatches
dianne Apr 22, 2025
6184025
make `str` literal patterns usable in deref patterns
dianne Mar 25, 2025
3250344
make `[u8]` and `[u8;N]` literal patterns usable in deref patterns
dianne Apr 16, 2025
4c7e866
update unstable book to mention string/bytestring typing
dianne Apr 19, 2025
19e44d4
Don't warn about `v128` in wasm ABI transition
alexcrichton Apr 14, 2025
09e36ce
[compiletest] Parallelize test discovery
tmandry Apr 22, 2025
51088fd
Remove `synstructure::Structure::underscore_const` calls.
nnethercote Apr 23, 2025
e18e599
set subsections_via_symbols for ld64 helper sections
usamoi Apr 13, 2025
17664d1
Update doc of cygwin target
Berrysoft Apr 23, 2025
fdf2c47
[AIX] Handle AIX dynamic library extensions within c-link-to-rust-dyl…
amy-kwan Apr 23, 2025
0a76ef8
Rename `compute_x` methods
BoxyUwU Apr 23, 2025
c6e6ac9
Module docs
BoxyUwU Apr 23, 2025
5b390cd
Make `SmirInterface` pub(crate) and rename `Context` to `SmirContext`
makai410 Apr 23, 2025
0296f05
Make algebraic intrinsics into 'const fn' items; Make algebraic funct…
bjoernager Apr 22, 2025
a4b9a1b
Remove `git_repository` field from `GitConfig`
Kobzol Apr 23, 2025
91da45a
Remove `git_repository` from the `stage0` file
Kobzol Apr 23, 2025
e3296cd
compiletest: `//@ add-core-stubs` implies `-Cforce-unwind-tables=yes`
jieyouxu Apr 23, 2025
c79f156
tests: account for CFI directives in `tests/assembly/x86-return-float…
jieyouxu Apr 23, 2025
f2ab763
rustc-dev-guide: document that `//@ add-core-stubs` imply `-Cforce-un…
jieyouxu Apr 23, 2025
f0399b8
triagebot: label minicore changes w/ `A-test-infra-minicore`
jieyouxu Apr 23, 2025
18c3370
CI: use aws codebuild for job dist-arm-linux
marcoieni Apr 23, 2025
157caee
fix f*::MAX_EXP and MIN_EXP docs
RalfJung Apr 22, 2025
7493e1c
Make #![feature(let_chains)] bootstrap conditional in compiler/
est31 Apr 23, 2025
1162f42
Remove hack
compiler-errors Apr 23, 2025
2a5c349
Extend HIR to track the source and syntax of a lifetime
shepmaster Mar 28, 2025
308cfb8
Rollup merge of #139261 - RalfJung:msvc-align-mitigation, r=oli-obk
Zalathar Apr 24, 2025
83ecddd
Rollup merge of #139307 - xizheyin:issue-139296, r=joboet
Zalathar Apr 24, 2025
331e4b0
Rollup merge of #139700 - EnzymeAD:autodiff-flags, r=oli-obk
Zalathar Apr 24, 2025
66979b2
Rollup merge of #139752 - usamoi:macos-used, r=saethlin,madsmtm
Zalathar Apr 24, 2025
54c65e6
Rollup merge of #139809 - alexcrichton:wasm-simd-safe, r=RalfJung
Zalathar Apr 24, 2025
1ba0ffe
Rollup merge of #139852 - makai410:smir-refactor, r=celinval
Zalathar Apr 24, 2025
570302d
Rollup merge of #139945 - shepmaster:hir-lifetime-syntax-source, r=nn…
Zalathar Apr 24, 2025
7a32312
Rollup merge of #140028 - dianne:lit-deref-pats-p1, r=oli-obk
Zalathar Apr 24, 2025
01271ba
Rollup merge of #140139 - a4lg:riscv-feature-imply-adjust-1, r=Amanieu
Zalathar Apr 24, 2025
6c1d167
Rollup merge of #140143 - thaliaarchi:move-env-pal, r=joboet
Zalathar Apr 24, 2025
9c368a8
Rollup merge of #140148 - marcoieni:ci-aws-codebuild, r=Kobzol
Zalathar Apr 24, 2025
8e8293e
Rollup merge of #140150 - RalfJung:MAX_EXP, r=tgross35
Zalathar Apr 24, 2025
42bc414
Rollup merge of #140172 - bjoernager:const-float-algebraic, r=RalfJung
Zalathar Apr 24, 2025
8d4283f
Rollup merge of #140177 - tmandry:compiletest-par, r=jieyouxu
Zalathar Apr 24, 2025
0f1f49a
Rollup merge of #140181 - nnethercote:rm-underscore_const, r=compiler…
Zalathar Apr 24, 2025
bd71363
Rollup merge of #140184 - Berrysoft:cygwin-target-doc, r=Noratrieb
Zalathar Apr 24, 2025
ca9a2d1
Rollup merge of #140186 - BoxyUwU:compute_what, r=compiler-errors
Zalathar Apr 24, 2025
81d17e6
Rollup merge of #140187 - amy-kwan:amy-kwan/update_runmake_tests_AIX,…
Zalathar Apr 24, 2025
11c4cc9
Rollup merge of #140191 - Kobzol:remove-git-repository-from-git-confi…
Zalathar Apr 24, 2025
d531fae
Rollup merge of #140194 - jieyouxu:minicore-force-unwind-tables, r=bj…
Zalathar Apr 24, 2025
6d371c5
Rollup merge of #140195 - jieyouxu:minicore-triagebot, r=jieyouxu
Zalathar Apr 24, 2025
f108448
Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr
Zalathar Apr 24, 2025
a415a28
Rollup merge of #140214 - compiler-errors:remove-hack, r=lcnr
Zalathar Apr 24, 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
make str literal patterns usable in deref patterns
Specifically, this allows string literal patterns to be used where a
`str` is expected when `deref_patterns` is enabled.
  • Loading branch information
dianne committed Apr 22, 2025
commit 61840254c512412525dfe796b855af7237b8d7b9
11 changes: 11 additions & 0 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

// When `deref_patterns` is enabled, in order to allow `deref!("..."): String`, we allow
// string literal patterns to have type `str`. This is accounted for when lowering to MIR.
if self.tcx.features().deref_patterns()
&& let hir::PatExprKind::Lit {
lit: Spanned { node: ast::LitKind::Str(..), .. }, ..
} = lt.kind
&& self.try_structurally_resolve_type(span, expected).is_str()
{
pat_ty = self.tcx.types.str_;
}

if self.tcx.features().string_deref_patterns()
&& let hir::PatExprKind::Lit {
lit: Spanned { node: ast::LitKind::Str(..), .. }, ..
Expand Down
23 changes: 23 additions & 0 deletions compiler/rustc_mir_build/src/builder/matches/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,29 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let mut place = place;
let mut block = block;
match ty.kind() {
ty::Str => {
// String literal patterns may have type `str` if `deref_patterns` is
// enabled, in order to allow `deref!("..."): String`. In this case, `value`
// is of type `&str`, so we compare it to `&place`.
if !tcx.features().deref_patterns() {
span_bug!(
test.span,
"matching on `str` went through without enabling deref_patterns"
);
}
let re_erased = tcx.lifetimes.re_erased;
let ref_str_ty = Ty::new_imm_ref(tcx, re_erased, tcx.types.str_);
let ref_place = self.temp(ref_str_ty, test.span);
// `let ref_place: &str = &place;`
self.cfg.push_assign(
block,
self.source_info(test.span),
ref_place,
Rvalue::Ref(re_erased, BorrowKind::Shared, place),
);
place = ref_place;
ty = ref_str_ty;
}
ty::Adt(def, _) if tcx.is_lang_item(def.did(), LangItem::String) => {
if !tcx.features().string_deref_patterns() {
span_bug!(
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_mir_build/src/thir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ pub(crate) fn lit_to_const<'tcx>(
let str_bytes = s.as_str().as_bytes();
ty::ValTree::from_raw_bytes(tcx, str_bytes)
}
(ast::LitKind::Str(s, _), ty::Str) if tcx.features().deref_patterns() => {
// String literal patterns may have type `str` if `deref_patterns` is enabled, in order
// to allow `deref!("..."): String`.
let str_bytes = s.as_str().as_bytes();
ty::ValTree::from_raw_bytes(tcx, str_bytes)
}
(ast::LitKind::ByteStr(data, _), ty::Ref(_, inner_ty, _))
if matches!(inner_ty.kind(), ty::Slice(_)) =>
{
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ impl<'tcx> ConstToPat<'tcx> {
slice: None,
suffix: Box::new([]),
},
ty::Str => {
// String literal patterns may have type `str` if `deref_patterns` is enabled, in
// order to allow `deref!("..."): String`. Since we need a `&str` for the comparison
// when lowering to MIR in `Builder::perform_test`, treat the constant as a `&str`.
// This works because `str` and `&str` have the same valtree representation.
let ref_str_ty = Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, ty);
PatKind::Constant {
value: mir::Const::Ty(ref_str_ty, ty::Const::new_value(tcx, cv, ref_str_ty)),
}
}
ty::Ref(_, pointee_ty, ..) => match *pointee_ty.kind() {
// `&str` is represented as a valtree, let's keep using this
// optimization for now.
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/pattern/deref-patterns/needs-gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ fn main() {
//~^ ERROR: mismatched types
_ => {}
}

// `deref_patterns` allows string and byte string literals to have non-ref types.
match *"test" {
"test" => {}
//~^ ERROR: mismatched types
_ => {}
}
}
10 changes: 9 additions & 1 deletion tests/ui/pattern/deref-patterns/needs-gate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ help: consider dereferencing to access the inner value using the Deref trait
LL | match *Box::new(0) {
| +

error: aborting due to 2 previous errors
error[E0308]: mismatched types
--> $DIR/needs-gate.rs:18:9
|
LL | match *"test" {
| ------- this expression has type `str`
LL | "test" => {}
| ^^^^^^ expected `str`, found `&str`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0308, E0658.
For more information about an error, try `rustc --explain E0308`.
32 changes: 32 additions & 0 deletions tests/ui/pattern/deref-patterns/strings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//@ run-pass
//! Test deref patterns using string and bytestring literals.

#![feature(deref_patterns)]
#![allow(incomplete_features)]

fn main() {
for (test_in, test_expect) in [("zero", 0), ("one", 1), ("two", 2)] {
// Test string literal patterns having type `str`.
let test_actual = match *test_in {
"zero" => 0,
"one" => 1,
_ => 2,
};
assert_eq!(test_actual, test_expect);

// Test string literals in explicit `deref!(_)` patterns.
let test_actual = match test_in.to_string() {
deref!("zero") => 0,
deref!("one") => 1,
_ => 2,
};
assert_eq!(test_actual, test_expect);
}

// Test that we can still mutate in the match arm after using a literal to test equality:
let mut test = "test".to_string();
if let deref!(s @ "test") = &mut test {
s.make_ascii_uppercase();
}
assert_eq!(test, "TEST");
}
8 changes: 2 additions & 6 deletions tests/ui/pattern/deref-patterns/typeck_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
#![allow(incomplete_features)]

fn main() {
// FIXME(deref_patterns): fails to typecheck because `"foo"` has type &str but deref creates a
// place of type `str`.
// FIXME(deref_patterns): fails to typecheck because string literal patterns don't peel
// references from the scrutinee.
match "foo".to_string() {
deref!("foo") => {}
//~^ ERROR: mismatched types
"foo" => {}
//~^ ERROR: mismatched types
_ => {}
}
match &"foo".to_string() {
deref!("foo") => {}
//~^ ERROR: mismatched types
"foo" => {}
//~^ ERROR: mismatched types
_ => {}
Expand Down
26 changes: 4 additions & 22 deletions tests/ui/pattern/deref-patterns/typeck_fail.stderr
Original file line number Diff line number Diff line change
@@ -1,42 +1,24 @@
error[E0308]: mismatched types
--> $DIR/typeck_fail.rs:8:16
--> $DIR/typeck_fail.rs:8:9
|
LL | match "foo".to_string() {
| ----------------- this expression has type `String`
LL | deref!("foo") => {}
| ^^^^^ expected `str`, found `&str`

error[E0308]: mismatched types
--> $DIR/typeck_fail.rs:10:9
|
LL | match "foo".to_string() {
| ----------------- this expression has type `String`
...
LL | "foo" => {}
| ^^^^^ expected `String`, found `&str`

error[E0308]: mismatched types
--> $DIR/typeck_fail.rs:15:16
|
LL | match &"foo".to_string() {
| ------------------ this expression has type `&String`
LL | deref!("foo") => {}
| ^^^^^ expected `str`, found `&str`

error[E0308]: mismatched types
--> $DIR/typeck_fail.rs:17:9
--> $DIR/typeck_fail.rs:13:9
|
LL | match &"foo".to_string() {
| ------------------ this expression has type `&String`
...
LL | "foo" => {}
| ^^^^^ expected `&String`, found `&str`
|
= note: expected reference `&String`
found reference `&'static str`

error[E0308]: mismatched types
--> $DIR/typeck_fail.rs:24:9
--> $DIR/typeck_fail.rs:20:9
|
LL | match Some(0) {
| ------- this expression has type `Option<{integer}>`
Expand All @@ -46,6 +28,6 @@ LL | Ok(0) => {}
= note: expected enum `Option<{integer}>`
found enum `Result<_, _>`

error: aborting due to 5 previous errors
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0308`.