Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit eedc229

Browse files
committed
Auto merge of rust-lang#134374 - matthiaskrgr:rollup-2tbbrxq, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#134314 (Make sure to use normalized ty for unevaluated const in default struct value) - rust-lang#134342 (crashes: more tests) - rust-lang#134357 (Fix `trimmed_def_paths` ICE in the function ptr comparison lint) - rust-lang#134369 (Update spelling of "referring") - rust-lang#134372 (Disable `tests/ui/associated-consts/issue-93775.rs` on windows msvc) Failed merges: - rust-lang#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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 36 additions & 18 deletions
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

Lines changed: 23 additions & 16 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 11 additions & 5 deletions
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

Lines changed: 23 additions & 0 deletions
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

Lines changed: 21 additions & 0 deletions
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

Lines changed: 36 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 43 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)