Skip to content

Commit dcc9028

Browse files
committed
Auto merge of rust-lang#112450 - matthiaskrgr:rollup-fdbazkr, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#112323 (Don't mention already-set fields in struct constructor missing field error) - rust-lang#112395 (Add Terminator::InlineAsm conversion from MIR to SMIR) - rust-lang#112411 (add programmerjake to portable-simd cc list) - rust-lang#112428 (Structurally resolve pointee in `check_pat_lit`) - rust-lang#112444 (Don't debug-print `Interned` or `PrivateZst`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9c843d9 + 009fc56 commit dcc9028

File tree

17 files changed

+95
-26
lines changed

17 files changed

+95
-26
lines changed

compiler/rustc_data_structures/src/intern.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::stable_hasher::{HashStable, StableHasher};
22
use std::cmp::Ordering;
3+
use std::fmt::{self, Debug};
34
use std::hash::{Hash, Hasher};
45
use std::ops::Deref;
56
use std::ptr;
@@ -20,7 +21,6 @@ mod private {
2021
/// The `PrivateZst` field means you can pattern match with `Interned(v, _)`
2122
/// but you can only construct a `Interned` with `new_unchecked`, and not
2223
/// directly.
23-
#[derive(Debug)]
2424
#[rustc_pass_by_value]
2525
pub struct Interned<'a, T>(pub &'a T, pub private::PrivateZst);
2626

@@ -108,5 +108,11 @@ where
108108
}
109109
}
110110

111+
impl<T: Debug> Debug for Interned<'_, T> {
112+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
113+
self.0.fmt(f)
114+
}
115+
}
116+
111117
#[cfg(test)]
112118
mod tests;

compiler/rustc_hir_typeck/src/expr.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -2081,13 +2081,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20812081
},
20822082
_ => {
20832083
// prevent all specified fields from being suggested
2084-
let skip_fields = skip_fields.iter().map(|x| x.ident.name);
2085-
if let Some(field_name) = self.suggest_field_name(
2086-
variant,
2087-
field.ident.name,
2088-
skip_fields.collect(),
2089-
expr_span,
2090-
) {
2084+
let skip_fields: Vec<_> = skip_fields.iter().map(|x| x.ident.name).collect();
2085+
if let Some(field_name) =
2086+
self.suggest_field_name(variant, field.ident.name, &skip_fields, expr_span)
2087+
{
20912088
err.span_suggestion(
20922089
field.ident.span,
20932090
"a field with a similar name exists",
@@ -2108,9 +2105,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21082105
format!("`{ty}` does not have this field"),
21092106
);
21102107
}
2111-
let available_field_names =
2108+
let mut available_field_names =
21122109
self.available_field_names(variant, expr_span);
2113-
if !available_field_names.is_empty() {
2110+
available_field_names
2111+
.retain(|name| skip_fields.iter().all(|skip| name != skip));
2112+
if available_field_names.is_empty() {
2113+
err.note("all struct fields are already assigned");
2114+
} else {
21142115
err.note(format!(
21152116
"available fields are: {}",
21162117
self.name_series_display(available_field_names)
@@ -2130,7 +2131,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21302131
&self,
21312132
variant: &'tcx ty::VariantDef,
21322133
field: Symbol,
2133-
skip: Vec<Symbol>,
2134+
skip: &[Symbol],
21342135
// The span where stability will be checked
21352136
span: Span,
21362137
) -> Option<Symbol> {
@@ -2582,7 +2583,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25822583
access_span: Span,
25832584
) {
25842585
if let Some(suggested_field_name) =
2585-
self.suggest_field_name(def.non_enum_variant(), field.name, vec![], access_span)
2586+
self.suggest_field_name(def.non_enum_variant(), field.name, &[], access_span)
25862587
{
25872588
err.span_suggestion(
25882589
field.span,

compiler/rustc_hir_typeck/src/pat.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
393393
// They can denote both statically and dynamically-sized byte arrays.
394394
let mut pat_ty = ty;
395395
if let hir::ExprKind::Lit(Spanned { node: ast::LitKind::ByteStr(..), .. }) = lt.kind {
396-
let expected = self.structurally_resolved_type(span, expected);
397-
if let ty::Ref(_, inner_ty, _) = expected.kind()
398-
&& matches!(inner_ty.kind(), ty::Slice(_))
396+
if let ty::Ref(_, inner_ty, _) = *self.structurally_resolved_type(span, expected).kind()
397+
&& self.structurally_resolved_type(span, inner_ty).is_slice()
399398
{
400399
let tcx = self.tcx;
401400
trace!(?lt.hir_id.local_id, "polymorphic byte string lit");

compiler/rustc_smir/src/rustc_smir/mod.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,27 @@ fn rustc_generator_to_generator(
287287
}
288288
}
289289

290+
fn rustc_inline_asm_operand_to_inline_asm_operand(
291+
operand: &rustc_middle::mir::InlineAsmOperand<'_>,
292+
) -> stable_mir::mir::InlineAsmOperand {
293+
use rustc_middle::mir::InlineAsmOperand;
294+
295+
let (in_value, out_place) = match operand {
296+
InlineAsmOperand::In { value, .. } => (Some(rustc_op_to_op(value)), None),
297+
InlineAsmOperand::Out { place, .. } => {
298+
(None, place.map(|place| rustc_place_to_place(&place)))
299+
}
300+
InlineAsmOperand::InOut { in_value, out_place, .. } => {
301+
(Some(rustc_op_to_op(in_value)), out_place.map(|place| rustc_place_to_place(&place)))
302+
}
303+
InlineAsmOperand::Const { .. }
304+
| InlineAsmOperand::SymFn { .. }
305+
| InlineAsmOperand::SymStatic { .. } => (None, None),
306+
};
307+
308+
stable_mir::mir::InlineAsmOperand { in_value, out_place, raw_rpr: format!("{:?}", operand) }
309+
}
310+
290311
fn rustc_terminator_to_terminator(
291312
terminator: &rustc_middle::mir::Terminator<'_>,
292313
) -> stable_mir::mir::Terminator {
@@ -330,7 +351,19 @@ fn rustc_terminator_to_terminator(
330351
target: target.as_usize(),
331352
unwind: rustc_unwind_to_unwind(unwind),
332353
},
333-
InlineAsm { .. } => todo!(),
354+
InlineAsm { template, operands, options, line_spans, destination, unwind } => {
355+
Terminator::InlineAsm {
356+
template: format!("{:?}", template),
357+
operands: operands
358+
.iter()
359+
.map(|operand| rustc_inline_asm_operand_to_inline_asm_operand(operand))
360+
.collect(),
361+
options: format!("{:?}", options),
362+
line_spans: format!("{:?}", line_spans),
363+
destination: destination.map(|d| d.as_usize()),
364+
unwind: rustc_unwind_to_unwind(unwind),
365+
}
366+
}
334367
Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(),
335368
}
336369
}

compiler/rustc_smir/src/stable_mir/mir/body.rs

+17
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ pub enum Terminator {
4646
unwind: UnwindAction,
4747
},
4848
GeneratorDrop,
49+
InlineAsm {
50+
template: String,
51+
operands: Vec<InlineAsmOperand>,
52+
options: String,
53+
line_spans: String,
54+
destination: Option<usize>,
55+
unwind: UnwindAction,
56+
},
57+
}
58+
59+
#[derive(Clone, Debug)]
60+
pub struct InlineAsmOperand {
61+
pub in_value: Option<Operand>,
62+
pub out_place: Option<Place>,
63+
// This field has a raw debug representation of MIR's InlineAsmOperand.
64+
// For now we care about place/operand + the rest in a debug format.
65+
pub raw_rpr: String,
4966
}
5067

5168
#[derive(Clone, Debug)]

tests/ui/async-await/drop-track-bad-field-in-fru.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0559]: variant `Option<_>::None` has no field named `value`
33
|
44
LL | None { value: (), ..Default::default() }.await;
55
| ^^^^^ `Option<_>::None` does not have this field
6+
|
7+
= note: all struct fields are already assigned
68

79
error[E0277]: `Option<_>` is not a future
810
--> $DIR/drop-track-bad-field-in-fru.rs:7:46

tests/ui/did_you_mean/issue-42599_available_fields_note.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0560]: struct `Demo` has no field named `egregiously_nonexistent_field`
1010
LL | Self { secret_integer: 3, egregiously_nonexistent_field: () }
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Demo` does not have this field
1212
|
13-
= note: available fields are: `favorite_integer`, `secret_integer`, `innocently_misspellable`, `another_field`, `yet_another_field` ... and 2 others
13+
= note: available fields are: `favorite_integer`, `innocently_misspellable`, `another_field`, `yet_another_field`, `always_more_fields`, `and_ever`
1414

1515
error[E0609]: no field `inocently_mispellable` on type `Demo`
1616
--> $DIR/issue-42599_available_fields_note.rs:32:41

tests/ui/error-codes/E0560.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0560]: struct `Simba` has no field named `father`
44
LL | let s = Simba { mother: 1, father: 0 };
55
| ^^^^^^ `Simba` does not have this field
66
|
7-
= note: available fields are: `mother`
7+
= note: all struct fields are already assigned
88

99
error: aborting due to previous error
1010

tests/ui/issues/issue-5439.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0560]: struct `Foo` has no field named `nonexistent`
44
LL | return Box::new(Foo { nonexistent: self, foo: i });
55
| ^^^^^^^^^^^ `Foo` does not have this field
66
|
7-
= note: available fields are: `foo`
7+
= note: all struct fields are already assigned
88

99
error: aborting due to previous error
1010

tests/ui/proc-macro/span-preservation.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ error[E0560]: struct `Foo` has no field named `b`
3232
LL | let y = Foo { a: 10, b: 10isize };
3333
| ^ `Foo` does not have this field
3434
|
35-
= note: available fields are: `a`
35+
= note: all struct fields are already assigned
3636

3737
error[E0308]: mismatched types
3838
--> $DIR/span-preservation.rs:39:5

tests/ui/structs/struct-field-cfg.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0560]: struct `Foo` has no field named `absent`
1010
LL | let _ = Foo { present: (), #[cfg(all())] absent: () };
1111
| ^^^^^^ `Foo` does not have this field
1212
|
13-
= note: available fields are: `present`
13+
= note: all struct fields are already assigned
1414

1515
error[E0027]: pattern does not mention field `present`
1616
--> $DIR/struct-field-cfg.rs:13:9

tests/ui/structs/struct-fields-shorthand.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0560]: struct `Foo` has no field named `z`
44
LL | x, y, z
55
| ^ `Foo` does not have this field
66
|
7-
= note: available fields are: `x`, `y`
7+
= note: all struct fields are already assigned
88

99
error: aborting due to previous error
1010

tests/ui/structs/struct-fields-too-many.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0560]: struct `BuildData` has no field named `bar`
44
LL | bar: 0
55
| ^^^ `BuildData` does not have this field
66
|
7-
= note: available fields are: `foo`
7+
= note: all struct fields are already assigned
88

99
error: aborting due to previous error
1010

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
4+
fn test(s: &[u8]) {
5+
match &s[0..3] {
6+
b"uwu" => {}
7+
_ => {}
8+
}
9+
}
10+
11+
fn main() {}

tests/ui/union/union-fields-2.mirunsafeck.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error[E0560]: union `U` has no field named `c`
1616
LL | let u = U { a: 0, b: 1, c: 2 };
1717
| ^ `U` does not have this field
1818
|
19-
= note: available fields are: `a`, `b`
19+
= note: all struct fields are already assigned
2020

2121
error[E0784]: union expressions should have exactly one field
2222
--> $DIR/union-fields-2.rs:13:13

tests/ui/union/union-fields-2.thirunsafeck.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error[E0560]: union `U` has no field named `c`
1616
LL | let u = U { a: 0, b: 1, c: 2 };
1717
| ^ `U` does not have this field
1818
|
19-
= note: available fields are: `a`, `b`
19+
= note: all struct fields are already assigned
2020

2121
error[E0784]: union expressions should have exactly one field
2222
--> $DIR/union-fields-2.rs:13:13

triagebot.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ Portable SIMD is developed in its own repository. If possible, consider \
378378
making this change to [rust-lang/portable-simd](https://github.com/rust-lang/portable-simd) \
379379
instead.
380380
"""
381-
cc = ["@calebzulawski"]
381+
cc = ["@calebzulawski", "@programmerjake"]
382382

383383
[mentions."src/librustdoc/clean/types.rs"]
384384
cc = ["@camelid"]

0 commit comments

Comments
 (0)