Skip to content

Commit eedc229

Browse files
committed
Auto merge of #134374 - matthiaskrgr:rollup-2tbbrxq, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #134314 (Make sure to use normalized ty for unevaluated const in default struct value) - #134342 (crashes: more tests) - #134357 (Fix `trimmed_def_paths` ICE in the function ptr comparison lint) - #134369 (Update spelling of "referring") - #134372 (Disable `tests/ui/associated-consts/issue-93775.rs` on windows msvc) Failed merges: - #134365 (Rename `rustc_mir_build::build` to `builder`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f2b91cc + 0a77972 commit eedc229

25 files changed

+309
-65
lines changed

compiler/rustc_lint/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ lint_unexpected_cfg_doc_cargo = see <https://doc.rust-lang.org/nightly/rustc/che
813813
lint_unexpected_cfg_doc_rustc = see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
814814
815815
lint_unexpected_cfg_from_external_macro_origin = using a cfg inside a {$macro_kind} will use the cfgs from the destination crate and not the ones from the defining crate
816-
lint_unexpected_cfg_from_external_macro_refer = try refering to `{$macro_name}` crate for guidance on how handle this unexpected cfg
816+
lint_unexpected_cfg_from_external_macro_refer = try referring to `{$macro_name}` crate for guidance on how handle this unexpected cfg
817817
lint_unexpected_cfg_name = unexpected `cfg` condition name: `{$name}`
818818
lint_unexpected_cfg_name_expected_names = expected names are: {$possibilities}{$and_more ->
819819
[0] {""}

compiler/rustc_lint/src/lints.rs

+36-18
Original file line numberDiff line numberDiff line change
@@ -1816,14 +1816,14 @@ pub(crate) enum AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
18161816
}
18171817

18181818
#[derive(LintDiagnostic)]
1819-
pub(crate) enum UnpredictableFunctionPointerComparisons<'a> {
1819+
pub(crate) enum UnpredictableFunctionPointerComparisons<'a, 'tcx> {
18201820
#[diag(lint_unpredictable_fn_pointer_comparisons)]
18211821
#[note(lint_note_duplicated_fn)]
18221822
#[note(lint_note_deduplicated_fn)]
18231823
#[note(lint_note_visit_fn_addr_eq)]
18241824
Suggestion {
18251825
#[subdiagnostic]
1826-
sugg: UnpredictableFunctionPointerComparisonsSuggestion<'a>,
1826+
sugg: UnpredictableFunctionPointerComparisonsSuggestion<'a, 'tcx>,
18271827
},
18281828
#[diag(lint_unpredictable_fn_pointer_comparisons)]
18291829
#[note(lint_note_duplicated_fn)]
@@ -1833,22 +1833,40 @@ pub(crate) enum UnpredictableFunctionPointerComparisons<'a> {
18331833
}
18341834

18351835
#[derive(Subdiagnostic)]
1836-
#[multipart_suggestion(
1837-
lint_fn_addr_eq_suggestion,
1838-
style = "verbose",
1839-
applicability = "maybe-incorrect"
1840-
)]
1841-
pub(crate) struct UnpredictableFunctionPointerComparisonsSuggestion<'a> {
1842-
pub ne: &'a str,
1843-
pub cast_right: String,
1844-
pub deref_left: &'a str,
1845-
pub deref_right: &'a str,
1846-
#[suggestion_part(code = "{ne}std::ptr::fn_addr_eq({deref_left}")]
1847-
pub left: Span,
1848-
#[suggestion_part(code = ", {deref_right}")]
1849-
pub middle: Span,
1850-
#[suggestion_part(code = "{cast_right})")]
1851-
pub right: Span,
1836+
pub(crate) enum UnpredictableFunctionPointerComparisonsSuggestion<'a, 'tcx> {
1837+
#[multipart_suggestion(
1838+
lint_fn_addr_eq_suggestion,
1839+
style = "verbose",
1840+
applicability = "maybe-incorrect"
1841+
)]
1842+
FnAddrEq {
1843+
ne: &'a str,
1844+
deref_left: &'a str,
1845+
deref_right: &'a str,
1846+
#[suggestion_part(code = "{ne}std::ptr::fn_addr_eq({deref_left}")]
1847+
left: Span,
1848+
#[suggestion_part(code = ", {deref_right}")]
1849+
middle: Span,
1850+
#[suggestion_part(code = ")")]
1851+
right: Span,
1852+
},
1853+
#[multipart_suggestion(
1854+
lint_fn_addr_eq_suggestion,
1855+
style = "verbose",
1856+
applicability = "maybe-incorrect"
1857+
)]
1858+
FnAddrEqWithCast {
1859+
ne: &'a str,
1860+
deref_left: &'a str,
1861+
deref_right: &'a str,
1862+
fn_sig: rustc_middle::ty::PolyFnSig<'tcx>,
1863+
#[suggestion_part(code = "{ne}std::ptr::fn_addr_eq({deref_left}")]
1864+
left: Span,
1865+
#[suggestion_part(code = ", {deref_right}")]
1866+
middle: Span,
1867+
#[suggestion_part(code = " as {fn_sig})")]
1868+
right: Span,
1869+
},
18521870
}
18531871

18541872
pub(crate) struct ImproperCTypes<'a> {

compiler/rustc_lint/src/types.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -483,29 +483,36 @@ fn lint_fn_pointer<'tcx>(
483483
let middle = l_span.shrink_to_hi().until(r_span.shrink_to_lo());
484484
let right = r_span.shrink_to_hi().until(e.span.shrink_to_hi());
485485

486-
// We only check for a right cast as `FnDef` == `FnPtr` is not possible,
487-
// only `FnPtr == FnDef` is possible.
488-
let cast_right = if !r_ty.is_fn_ptr() {
489-
let fn_sig = r_ty.fn_sig(cx.tcx);
490-
format!(" as {fn_sig}")
491-
} else {
492-
String::new()
493-
};
486+
let sugg =
487+
// We only check for a right cast as `FnDef` == `FnPtr` is not possible,
488+
// only `FnPtr == FnDef` is possible.
489+
if !r_ty.is_fn_ptr() {
490+
let fn_sig = r_ty.fn_sig(cx.tcx);
494491

495-
cx.emit_span_lint(
496-
UNPREDICTABLE_FUNCTION_POINTER_COMPARISONS,
497-
e.span,
498-
UnpredictableFunctionPointerComparisons::Suggestion {
499-
sugg: UnpredictableFunctionPointerComparisonsSuggestion {
492+
UnpredictableFunctionPointerComparisonsSuggestion::FnAddrEqWithCast {
500493
ne,
494+
fn_sig,
501495
deref_left,
502496
deref_right,
503497
left,
504498
middle,
505499
right,
506-
cast_right,
507-
},
508-
},
500+
}
501+
} else {
502+
UnpredictableFunctionPointerComparisonsSuggestion::FnAddrEq {
503+
ne,
504+
deref_left,
505+
deref_right,
506+
left,
507+
middle,
508+
right,
509+
}
510+
};
511+
512+
cx.emit_span_lint(
513+
UNPREDICTABLE_FUNCTION_POINTER_COMPARISONS,
514+
e.span,
515+
UnpredictableFunctionPointerComparisons::Suggestion { sugg },
509516
);
510517
}
511518

compiler/rustc_lint/src/unqualified_local_imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ declare_lint! {
3131
///
3232
/// This lint is meant to be used with the (unstable) rustfmt setting `group_imports = "StdExternalCrate"`.
3333
/// That setting makes rustfmt group `self::`, `super::`, and `crate::` imports separately from those
34-
/// refering to other crates. However, rustfmt cannot know whether `use c::S;` refers to a local module `c`
34+
/// referring to other crates. However, rustfmt cannot know whether `use c::S;` refers to a local module `c`
3535
/// or an external crate `c`, so it always gets categorized as an import from another crate.
3636
/// To ensure consistent grouping of imports from the local crate, all local imports must
3737
/// start with `self::`, `super::`, or `crate::`. This lint can be used to enforce that style.

compiler/rustc_mir_build/src/build/expr/into.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
367367
.collect()
368368
}
369369
AdtExprBase::DefaultFields(field_types) => {
370-
itertools::zip_eq(field_names, &**field_types)
371-
.map(|(n, ty)| match fields_map.get(&n) {
370+
itertools::zip_eq(field_names, field_types)
371+
.map(|(n, &ty)| match fields_map.get(&n) {
372372
Some(v) => v.clone(),
373373
None => match variant.fields[n].value {
374374
Some(def) => {
375-
let value = Const::from_unevaluated(this.tcx, def)
376-
.instantiate(this.tcx, args);
377-
this.literal_operand(expr_span, value)
375+
let value = Const::Unevaluated(
376+
UnevaluatedConst::new(def, args),
377+
ty,
378+
);
379+
Operand::Constant(Box::new(ConstOperand {
380+
span: expr_span,
381+
user_ty: None,
382+
const_: value,
383+
}))
378384
}
379385
None => {
380386
let name = variant.fields[n].name;

tests/crashes/130797.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ known-bug: #130797
2+
3+
trait Transform {
4+
type Output<'a>;
5+
}
6+
trait Propagate<O> {}
7+
trait AddChild<C> {
8+
fn add_child(&self) {}
9+
}
10+
11+
pub struct Node<T>(T);
12+
impl<T> AddChild<Box<dyn for<'b> Propagate<T::Output<'b>>>> for Node<T> where T: Transform {}
13+
14+
fn make_graph_root() {
15+
Node(Dummy).add_child()
16+
}
17+
18+
struct Dummy;
19+
impl Transform for Dummy {
20+
type Output<'a> = ();
21+
}
22+
23+
pub fn main() {}

tests/crashes/132103.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ known-bug: #132103
2+
//@compile-flags: -Zvalidate-mir --edition=2018 -Zinline-mir=yes
3+
use core::future::{async_drop_in_place, Future};
4+
use core::mem::{self};
5+
use core::pin::pin;
6+
use core::task::{Context, Waker};
7+
8+
async fn test_async_drop<T>(x: T) {
9+
let mut x = mem::MaybeUninit::new(x);
10+
pin!(unsafe { async_drop_in_place(x.as_mut_ptr()) });
11+
}
12+
13+
fn main() {
14+
let waker = Waker::noop();
15+
let mut cx = Context::from_waker(&waker);
16+
17+
let fut = pin!(async {
18+
test_async_drop(test_async_drop(0)).await;
19+
});
20+
fut.poll(&mut cx);
21+
}

tests/crashes/132960.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//@ known-bug: #132960
2+
3+
#![feature(adt_const_params, const_ptr_read, generic_const_exprs)]
4+
5+
const fn concat_strs<const A: &'static str, const B: &'static str>() -> &'static str
6+
where
7+
[(); A.len()]:,
8+
[(); B.len()]:,
9+
[(); A.len() + B.len()]:,
10+
{
11+
#[repr(C)]
12+
#[repr(C)]
13+
14+
const fn concat_arr<const M: usize, const N: usize>(a: [u8; M], b: [u8; N]) -> [u8; M + N] {}
15+
16+
struct Inner<const A: &'static str, const B: &'static str>;
17+
impl<const A: &'static str, const B: &'static str> Inner<A, B>
18+
where
19+
[(); A.len()]:,
20+
[(); B.len()]:,
21+
[(); A.len() + B.len()]:,
22+
{
23+
const ABSTR: &'static str = unsafe {
24+
std::str::from_utf8_unchecked(&concat_arr(
25+
A.as_ptr().cast().read(),
26+
B.as_ptr().cast().read(),
27+
))
28+
};
29+
}
30+
31+
Inner::<A, B>::ABSTR
32+
}
33+
34+
const FOO: &str = "foo";
35+
const BAR: &str = "bar";
36+
const FOOBAR: &str = concat_strs::<FOO, BAR>();

tests/crashes/133117.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ known-bug: #133117
2+
3+
fn main() {
4+
match () {
5+
(!|!) if true => {}
6+
(!|!) if true => {}
7+
}
8+
}

tests/crashes/133252.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//@ known-bug: #133252
2+
//@ edition:2021
3+
use std::future::Future;
4+
5+
trait Owned: 'static {}
6+
fn ice() -> impl Future<Output = &'static dyn Owned> {
7+
async {
8+
let not_static = 0;
9+
force_send(async_load(&not_static));
10+
loop {}
11+
}
12+
}
13+
14+
fn force_send<T: Send>(_: T) {}
15+
16+
fn async_load<'a, T: LoadQuery<'a>>(this: T) -> impl Future {
17+
async {
18+
this.get_future().await;
19+
}
20+
}
21+
22+
trait LoadQuery<'a>: Sized {
23+
type LoadFuture: Future;
24+
25+
fn get_future(self) -> Self::LoadFuture {
26+
loop {}
27+
}
28+
}
29+
30+
impl<'a> LoadQuery<'a> for &'a u8 {
31+
type LoadFuture = SimpleFuture;
32+
}
33+
34+
struct SimpleFuture;
35+
impl Future for SimpleFuture {
36+
type Output = ();
37+
fn poll(
38+
self: std::pin::Pin<&mut Self>,
39+
_: &mut std::task::Context<'_>,
40+
) -> std::task::Poll<Self::Output> {
41+
loop {}
42+
}
43+
}

tests/crashes/133613.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ known-bug: #133613
2+
3+
struct Wrapper<'a>();
4+
5+
trait IntFactory {
6+
fn stream(&self) -> impl IntFactory<stream(..): IntFactory<stream(..): Send>>;
7+
}

tests/crashes/134174.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ known-bug: #134175
2+
//@compile-flags: -Zvalidate-mir -Zinline-mir=yes
3+
use std::vec::IntoIter;
4+
5+
pub(crate) trait Foo: Iterator<Item = <Self as Foo>::Key> {
6+
type Key;
7+
}
8+
9+
impl Foo for IntoIter<i16> {}
10+
11+
fn sum_foo<F: Foo<Key = i32>>(f: F) -> i32 {
12+
f.fold(0, |a, b| a + b)
13+
}
14+
15+
fn main() {
16+
let x = sum_foo(vec![11, 10, 1].into_iter());
17+
}

tests/crashes/134334.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ known-bug: #134334
2+
//@ only-x86_64
3+
4+
#[repr(simd)]
5+
struct A();
6+
7+
fn main() {
8+
std::arch::asm!("{}", in(xmm_reg) A());
9+
}

tests/crashes/134335.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ known-bug: #134335
2+
//@compile-flags: -Zunstable-options --edition=2024 --crate-type=lib
3+
pub async fn async_closure(x: &mut i32) {
4+
let c = async move || {
5+
*x += 1;
6+
};
7+
call_once(c).await;
8+
}
9+
10+
fn call_once<T>(f: impl FnOnce() -> T) -> T {
11+
f()
12+
}

tests/ui/associated-consts/issue-93775.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//@ ignore-windows-msvc
2+
// FIXME(#132111, #133432): this test is flaky on windows msvc, it sometimes fail but it sometimes
3+
// passes.
4+
15
//@ build-pass
26
// ignore-tidy-linelength
37

tests/ui/check-cfg/report-in-external-macros.cargo.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | cfg_macro::my_lib_macro!();
66
|
77
= help: expected names are: `clippy`, `debug_assertions`, `doc`, `doctest`, `feature`, `fmt_debug`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, and `windows`
88
= note: using a cfg inside a macro will use the cfgs from the destination crate and not the ones from the defining crate
9-
= help: try refering to `cfg_macro::my_lib_macro` crate for guidance on how handle this unexpected cfg
9+
= help: try referring to `cfg_macro::my_lib_macro` crate for guidance on how handle this unexpected cfg
1010
= help: the macro `cfg_macro::my_lib_macro` may come from an old version of the `cfg_macro` crate, try updating your dependency with `cargo update -p cfg_macro`
1111
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
1212
= note: `#[warn(unexpected_cfgs)]` on by default
@@ -20,7 +20,7 @@ LL | cfg_macro::my_lib_macro_value!();
2020
|
2121
= note: expected values for `panic` are: `abort` and `unwind`
2222
= note: using a cfg inside a macro will use the cfgs from the destination crate and not the ones from the defining crate
23-
= help: try refering to `cfg_macro::my_lib_macro_value` crate for guidance on how handle this unexpected cfg
23+
= help: try referring to `cfg_macro::my_lib_macro_value` crate for guidance on how handle this unexpected cfg
2424
= help: the macro `cfg_macro::my_lib_macro_value` may come from an old version of the `cfg_macro` crate, try updating your dependency with `cargo update -p cfg_macro`
2525
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
2626
= note: this warning originates in the macro `cfg_macro::my_lib_macro_value` (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -33,7 +33,7 @@ LL | cfg_macro::my_lib_macro_feature!();
3333
|
3434
= note: no expected values for `feature`
3535
= note: using a cfg inside a macro will use the cfgs from the destination crate and not the ones from the defining crate
36-
= help: try refering to `cfg_macro::my_lib_macro_feature` crate for guidance on how handle this unexpected cfg
36+
= help: try referring to `cfg_macro::my_lib_macro_feature` crate for guidance on how handle this unexpected cfg
3737
= help: the macro `cfg_macro::my_lib_macro_feature` may come from an old version of the `cfg_macro` crate, try updating your dependency with `cargo update -p cfg_macro`
3838
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
3939
= note: this warning originates in the macro `cfg_macro::my_lib_macro_feature` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)