Skip to content

Commit d10ac47

Browse files
committed
Auto merge of rust-lang#151506 - JonathanBrouwer:rollup-MDuFdim, r=JonathanBrouwer
Rollup of 3 pull requests Successful merges: - rust-lang#151412 (diagnostics: suggest deriving Default for enums) - rust-lang#151495 (Fix ICE when using zero-length SIMD type in extern static) - rust-lang#151497 (Fix typo: 'recieve' -> 'receive' in lldb-visualizers.md) r? @ghost
2 parents 39052da + 04246de commit d10ac47

File tree

8 files changed

+84
-7
lines changed

8 files changed

+84
-7
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_middle::ty::{
2424
TypeVisitable, TypeVisitableExt, fold_regions,
2525
};
2626
use rustc_session::lint::builtin::UNINHABITED_STATIC;
27+
use rustc_span::source_map::Spanned;
2728
use rustc_target::spec::{AbiMap, AbiMapping};
2829
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2930
use rustc_trait_selection::error_reporting::traits::on_unimplemented::OnUnimplementedDirective;
@@ -192,6 +193,12 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
192193
tcx.dcx().emit_err(errors::TooLargeStatic { span });
193194
return;
194195
}
196+
// SIMD types with invalid layout (e.g., zero-length) should emit an error
197+
Err(e @ LayoutError::InvalidSimd { .. }) => {
198+
let ty_span = tcx.ty_span(def_id);
199+
tcx.dcx().emit_err(Spanned { span: ty_span, node: e.into_diagnostic() });
200+
return;
201+
}
195202
// Generic statics are rejected, but we still reach this case.
196203
Err(e) => {
197204
tcx.dcx().span_delayed_bug(span, format!("{e:?}"));

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3300,8 +3300,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33003300
};
33013301
if let Some(diagnostic_name) = self.tcx.get_diagnostic_name(trait_pred.def_id()) {
33023302
let can_derive = match diagnostic_name {
3303-
sym::Default => !adt.is_enum(),
3304-
sym::Eq
3303+
sym::Default
3304+
| sym::Eq
33053305
| sym::PartialEq
33063306
| sym::Ord
33073307
| sym::PartialOrd

src/doc/rustc-dev-guide/src/debuginfo/lldb-visualizers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> NOTE: LLDB's C++<->Python FFI expects a version of python designated at the time LLDB was
44
>compiled. LLDB is careful to correspond this version to the minimum in typical Linux and macOS
5-
>distributions, but on Windows there is no easy solution. If you recieve an import error regarding
5+
>distributions, but on Windows there is no easy solution. If you receive an import error regarding
66
>`_lldb` not existing, a mismatched Python version is likely the cause.
77
>
88
> LLDB is considering solutions this issue. For updates, see
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(repr_simd)]
2+
3+
#[repr(simd)]
4+
struct Simd<T, const N: usize>([T; N]);
5+
6+
unsafe extern "C" {
7+
static VAR: Simd<u8, 0>;
8+
//~^ ERROR the SIMD type `Simd<u8, 0>` has zero elements
9+
static VAR2: Simd<u8, 1_000_000>;
10+
//~^ ERROR the SIMD type `Simd<u8, 1000000>` has more elements than the limit 32768
11+
}
12+
13+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: the SIMD type `Simd<u8, 0>` has zero elements
2+
--> $DIR/extern-static-zero-length.rs:7:17
3+
|
4+
LL | static VAR: Simd<u8, 0>;
5+
| ^^^^^^^^^^^
6+
7+
error: the SIMD type `Simd<u8, 1000000>` has more elements than the limit 32768
8+
--> $DIR/extern-static-zero-length.rs:9:18
9+
|
10+
LL | static VAR2: Simd<u8, 1_000_000>;
11+
| ^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+

tests/ui/suggestions/derive-trait-for-method-call.stderr

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ LL | impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> {
2525
| | | unsatisfied trait bound introduced here
2626
| | unsatisfied trait bound introduced here
2727
| unsatisfied trait bound introduced here
28-
note: the trait `Default` must be implemented
29-
--> $SRC_DIR/core/src/default.rs:LL:COL
30-
help: consider annotating `Enum` with `#[derive(Clone)]`
28+
help: consider annotating `CloneEnum` with `#[derive(Default)]`
3129
|
32-
LL + #[derive(Clone)]
30+
LL + #[derive(Default)]
31+
LL | enum CloneEnum {
32+
|
33+
help: consider annotating `Enum` with `#[derive(Clone, Default)]`
34+
|
35+
LL + #[derive(Clone, Default)]
3336
LL | enum Enum {
3437
|
3538

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// A test showing that we suggest deriving `Default` for enums.
2+
enum MyEnum {
3+
A,
4+
}
5+
6+
trait Foo {
7+
fn bar(&self) {}
8+
}
9+
impl<T: Default> Foo for T {}
10+
11+
fn main() {
12+
let x = MyEnum::A;
13+
x.bar();
14+
//~^ ERROR the method `bar` exists for enum `MyEnum`, but its trait bounds were not satisfied
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0599]: the method `bar` exists for enum `MyEnum`, but its trait bounds were not satisfied
2+
--> $DIR/suggest-derive-default-for-enums.rs:13:7
3+
|
4+
LL | enum MyEnum {
5+
| ----------- method `bar` not found for this enum because it doesn't satisfy `MyEnum: Default` or `MyEnum: Foo`
6+
...
7+
LL | x.bar();
8+
| ^^^ method cannot be called on `MyEnum` due to unsatisfied trait bounds
9+
|
10+
note: trait bound `MyEnum: Default` was not satisfied
11+
--> $DIR/suggest-derive-default-for-enums.rs:9:9
12+
|
13+
LL | impl<T: Default> Foo for T {}
14+
| ^^^^^^^ --- -
15+
| |
16+
| unsatisfied trait bound introduced here
17+
help: consider annotating `MyEnum` with `#[derive(Default)]`
18+
|
19+
LL + #[derive(Default)]
20+
LL | enum MyEnum {
21+
|
22+
23+
error: aborting due to 1 previous error
24+
25+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)