Skip to content

Commit a785176

Browse files
committed
Auto merge of rust-lang#100881 - Dylan-DPC:rollup-q9rr658, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - rust-lang#98200 (Expand potential inner `Or` pattern for THIR) - rust-lang#99770 (Make some const prop mir-opt tests `unit-test`s) - rust-lang#99957 (Rework Ipv6Addr::is_global to check for global reachability rather than global scope - rebase) - rust-lang#100331 (Guarantee `try_reserve` preserves the contents on error) - rust-lang#100336 (Fix two const_trait_impl issues) - rust-lang#100713 (Convert diagnostics in parser/expr to SessionDiagnostic) - rust-lang#100820 (Use pointer `is_aligned*` methods) - rust-lang#100872 (Add guarantee that Vec::default() does not alloc) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e0dc8d7 + 4ed8fa4 commit a785176

File tree

65 files changed

+1050
-425
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1050
-425
lines changed

Diff for: compiler/rustc_error_messages/locales/en-US/parser.ftl

+109
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,112 @@ parser_switch_mut_let_order =
4141
parser_missing_let_before_mut = missing keyword
4242
parser_use_let_not_auto = write `let` instead of `auto` to introduce a new variable
4343
parser_use_let_not_var = write `let` instead of `var` to introduce a new variable
44+
45+
parser_invalid_comparison_operator = invalid comparison operator `{$invalid}`
46+
.use_instead = `{$invalid}` is not a valid comparison operator, use `{$correct}`
47+
.spaceship_operator_invalid = `<=>` is not a valid comparison operator, use `std::cmp::Ordering`
48+
49+
parser_invalid_logical_operator = `{$incorrect}` is not a logical operator
50+
.note = unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
51+
.use_amp_amp_for_conjunction = use `&&` to perform logical conjunction
52+
.use_pipe_pipe_for_disjunction = use `||` to perform logical disjunction
53+
54+
parser_tilde_is_not_unary_operator = `~` cannot be used as a unary operator
55+
.suggestion = use `!` to perform bitwise not
56+
57+
parser_unexpected_token_after_not = unexpected {$negated_desc} after identifier
58+
.suggestion = use `!` to perform logical negation
59+
60+
parser_malformed_loop_label = malformed loop label
61+
.suggestion = use the correct loop label format
62+
63+
parser_lifetime_in_borrow_expression = borrow expressions cannot be annotated with lifetimes
64+
.suggestion = remove the lifetime annotation
65+
.label = annotated with lifetime here
66+
67+
parser_field_expression_with_generic = field expressions cannot have generic arguments
68+
69+
parser_macro_invocation_with_qualified_path = macros cannot use qualified paths
70+
71+
parser_unexpected_token_after_label = expected `while`, `for`, `loop` or `{"{"}` after a label
72+
73+
parser_require_colon_after_labeled_expression = labeled expression must be followed by `:`
74+
.note = labels are used before loops and blocks, allowing e.g., `break 'label` to them
75+
.label = the label
76+
.suggestion = add `:` after the label
77+
78+
parser_do_catch_syntax_removed = found removed `do catch` syntax
79+
.note = following RFC #2388, the new non-placeholder syntax is `try`
80+
.suggestion = replace with the new syntax
81+
82+
parser_float_literal_requires_integer_part = float literals must have an integer part
83+
.suggestion = must have an integer part
84+
85+
parser_invalid_int_literal_width = invalid width `{$width}` for integer literal
86+
.help = valid widths are 8, 16, 32, 64 and 128
87+
88+
parser_invalid_num_literal_base_prefix = invalid base prefix for number literal
89+
.note = base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
90+
.suggestion = try making the prefix lowercase
91+
92+
parser_invalid_num_literal_suffix = invalid suffix `{$suffix}` for number literal
93+
.label = invalid suffix `{$suffix}`
94+
.help = the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
95+
96+
parser_invalid_float_literal_width = invalid width `{$width}` for float literal
97+
.help = valid widths are 32 and 64
98+
99+
parser_invalid_float_literal_suffix = invalid suffix `{$suffix}` for float literal
100+
.label = invalid suffix `{$suffix}`
101+
.help = valid suffixes are `f32` and `f64`
102+
103+
parser_int_literal_too_large = integer literal is too large
104+
105+
parser_missing_semicolon_before_array = expected `;`, found `[`
106+
.suggestion = consider adding `;` here
107+
108+
parser_invalid_block_macro_segment = cannot use a `block` macro fragment here
109+
.label = the `block` fragment is within this context
110+
111+
parser_if_expression_missing_then_block = this `if` expression is missing a block after the condition
112+
.add_then_block = add a block here
113+
.condition_possibly_unfinished = this binary operation is possibly unfinished
114+
115+
parser_if_expression_missing_condition = missing condition for `if` expression
116+
.condition_label = expected condition here
117+
.block_label = if this block is the condition of the `if` expression, then it must be followed by another block
118+
119+
parser_expected_expression_found_let = expected expression, found `let` statement
120+
121+
parser_expected_else_block = expected `{"{"}`, found {$first_tok}
122+
.label = expected an `if` or a block after this `else`
123+
.suggestion = add an `if` if this is the condition of a chained `else if` statement
124+
125+
parser_outer_attribute_not_allowed_on_if_else = outer attributes are not allowed on `if` and `else` branches
126+
.branch_label = the attributes are attached to this branch
127+
.ctx_label = the branch belongs to this `{$ctx}`
128+
.suggestion = remove the attributes
129+
130+
parser_missing_in_in_for_loop = missing `in` in `for` loop
131+
.use_in_not_of = try using `in` here instead
132+
.add_in = try adding `in` here
133+
134+
parser_missing_comma_after_match_arm = expected `,` following `match` arm
135+
.suggestion = missing a comma here to end this `match` arm
136+
137+
parser_catch_after_try = keyword `catch` cannot follow a `try` block
138+
.help = try using `match` on the result of the `try` block instead
139+
140+
parser_comma_after_base_struct = cannot use a comma after the base struct
141+
.note = the base struct must always be the last field
142+
.suggestion = remove this comma
143+
144+
parser_eq_field_init = expected `:`, found `=`
145+
.suggestion = replace equals symbol with a colon
146+
147+
parser_dotdotdot = unexpected token: `...`
148+
.suggest_exclusive_range = use `..` for an exclusive range
149+
.suggest_inclusive_range = or `..=` for an inclusive range
150+
151+
parser_left_arrow_operator = unexpected token: `<-`
152+
.suggestion = if you meant to write a comparison against a negative value, add a space in between `<` and `-`

Diff for: compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ impl<'a, 'p, 'tcx> fmt::Debug for PatCtxt<'a, 'p, 'tcx> {
364364
/// A row of a matrix. Rows of len 1 are very common, which is why `SmallVec[_; 2]`
365365
/// works well.
366366
#[derive(Clone)]
367-
struct PatStack<'p, 'tcx> {
368-
pats: SmallVec<[&'p DeconstructedPat<'p, 'tcx>; 2]>,
367+
pub(crate) struct PatStack<'p, 'tcx> {
368+
pub(crate) pats: SmallVec<[&'p DeconstructedPat<'p, 'tcx>; 2]>,
369369
}
370370

371371
impl<'p, 'tcx> PatStack<'p, 'tcx> {
@@ -403,6 +403,21 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> {
403403
})
404404
}
405405

406+
// Recursively expand all patterns into their subpatterns and push each `PatStack` to matrix.
407+
fn expand_and_extend<'a>(&'a self, matrix: &mut Matrix<'p, 'tcx>) {
408+
if !self.is_empty() && self.head().is_or_pat() {
409+
for pat in self.head().iter_fields() {
410+
let mut new_patstack = PatStack::from_pattern(pat);
411+
new_patstack.pats.extend_from_slice(&self.pats[1..]);
412+
if !new_patstack.is_empty() && new_patstack.head().is_or_pat() {
413+
new_patstack.expand_and_extend(matrix);
414+
} else if !new_patstack.is_empty() {
415+
matrix.push(new_patstack);
416+
}
417+
}
418+
}
419+
}
420+
406421
/// This computes `S(self.head().ctor(), self)`. See top of the file for explanations.
407422
///
408423
/// Structure patterns with a partial wild pattern (Foo { a: 42, .. }) have their missing
@@ -436,7 +451,7 @@ impl<'p, 'tcx> fmt::Debug for PatStack<'p, 'tcx> {
436451
/// A 2D matrix.
437452
#[derive(Clone)]
438453
pub(super) struct Matrix<'p, 'tcx> {
439-
patterns: Vec<PatStack<'p, 'tcx>>,
454+
pub patterns: Vec<PatStack<'p, 'tcx>>,
440455
}
441456

442457
impl<'p, 'tcx> Matrix<'p, 'tcx> {
@@ -453,7 +468,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
453468
/// expands it.
454469
fn push(&mut self, row: PatStack<'p, 'tcx>) {
455470
if !row.is_empty() && row.head().is_or_pat() {
456-
self.patterns.extend(row.expand_or_pat());
471+
row.expand_and_extend(self);
457472
} else {
458473
self.patterns.push(row);
459474
}

0 commit comments

Comments
 (0)