Skip to content

Commit c00957a

Browse files
committed
Auto merge of rust-lang#125254 - matthiaskrgr:rollup-ukvsxbc, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#125117 (Improve parser) - rust-lang#125184 (Fix ICE in non-operand `aggregate_raw_ptr` intrinsic codegen) - rust-lang#125240 (Temporarily revert to NonZeroUsize in rustc-abi to fix building on stable) - rust-lang#125248 (Migrate `run-make/rustdoc-scrape-examples-invalid-expr` to `rmake.rs`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents cf2baaa + cd1ca14 commit c00957a

File tree

16 files changed

+120
-83
lines changed

16 files changed

+120
-83
lines changed

compiler/rustc_abi/src/layout.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::borrow::{Borrow, Cow};
22
use std::cmp;
33
use std::fmt::{self, Write};
44
use std::iter;
5-
use std::num::NonZero;
65
use std::ops::Bound;
76
use std::ops::Deref;
87

@@ -11,8 +10,8 @@ use tracing::debug;
1110

1211
use crate::{
1312
Abi, AbiAndPrefAlign, Align, FieldsShape, IndexSlice, IndexVec, Integer, LayoutS, Niche,
14-
Primitive, ReprOptions, Scalar, Size, StructKind, TagEncoding, TargetDataLayout, Variants,
15-
WrappingRange,
13+
NonZeroUsize, Primitive, ReprOptions, Scalar, Size, StructKind, TagEncoding, TargetDataLayout,
14+
Variants, WrappingRange,
1615
};
1716

1817
// A variant is absent if it's uninhabited and only has ZST fields.
@@ -328,7 +327,7 @@ pub trait LayoutCalculator {
328327

329328
Some(LayoutS {
330329
variants: Variants::Single { index: VariantIdx::new(0) },
331-
fields: FieldsShape::Union(NonZero::new(only_variant.len())?),
330+
fields: FieldsShape::Union(NonZeroUsize::new(only_variant.len())?),
332331
abi,
333332
largest_niche: None,
334333
align,

compiler/rustc_abi/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![cfg_attr(feature = "nightly", feature(rustdoc_internals))]
55

66
use std::fmt;
7-
use std::num::{NonZero, ParseIntError};
7+
use std::num::{NonZeroUsize, ParseIntError};
88
use std::ops::{Add, AddAssign, Mul, RangeInclusive, Sub};
99
use std::str::FromStr;
1010

@@ -1175,7 +1175,7 @@ pub enum FieldsShape<FieldIdx: Idx> {
11751175
Primitive,
11761176

11771177
/// All fields start at no offset. The `usize` is the field count.
1178-
Union(NonZero<usize>),
1178+
Union(NonZeroUsize),
11791179

11801180
/// Array/vector-like placement, with all fields of identical types.
11811181
Array { stride: Size, count: u64 },

compiler/rustc_ast/src/ast.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3262,6 +3262,7 @@ pub enum ItemKind {
32623262
}
32633263

32643264
impl ItemKind {
3265+
/// "a" or "an"
32653266
pub fn article(&self) -> &'static str {
32663267
use ItemKind::*;
32673268
match self {

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
121121
bx.write_operand_repeatedly(cg_elem, count, dest);
122122
}
123123

124-
mir::Rvalue::Aggregate(ref kind, ref operands) => {
124+
// This implementation does field projection, so never use it for `RawPtr`,
125+
// which will always be fine with the `codegen_rvalue_operand` path below.
126+
mir::Rvalue::Aggregate(ref kind, ref operands)
127+
if !matches!(**kind, mir::AggregateKind::RawPtr(..)) =>
128+
{
125129
let (variant_index, variant_dest, active_field_index) = match **kind {
126130
mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
127131
let variant_dest = dest.project_downcast(bx, variant_index);

compiler/rustc_parse/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(crate) struct IncorrectSemicolon<'a> {
8383
#[suggestion(style = "short", code = "", applicability = "machine-applicable")]
8484
pub span: Span,
8585
#[help]
86-
pub opt_help: Option<()>,
86+
pub show_help: bool,
8787
pub name: &'a str,
8888
}
8989

compiler/rustc_parse/src/lexer/tokentrees.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<'psess, 'src> TokenTreesReader<'psess, 'src> {
241241
// we have no way of tracking this in the lexer itself, so we piggyback on the parser
242242
let mut in_cond = false;
243243
while parser.token != token::Eof {
244-
if let Err(diff_err) = parser.err_diff_marker() {
244+
if let Err(diff_err) = parser.err_vcs_conflict_marker() {
245245
diff_errs.push(diff_err);
246246
} else if parser.is_keyword_ahead(0, &[kw::If, kw::While]) {
247247
in_cond = true;

compiler/rustc_parse/src/parser/diagnostics.rs

+43-33
Original file line numberDiff line numberDiff line change
@@ -1817,34 +1817,31 @@ impl<'a> Parser<'a> {
18171817
Ok(P(T::recovered(Some(P(QSelf { ty, path_span, position: 0 })), path)))
18181818
}
18191819

1820-
pub fn maybe_consume_incorrect_semicolon(&mut self, items: &[P<Item>]) -> bool {
1821-
if self.token.kind == TokenKind::Semi {
1822-
self.bump();
1823-
1824-
let mut err =
1825-
IncorrectSemicolon { span: self.prev_token.span, opt_help: None, name: "" };
1820+
/// This function gets called in places where a semicolon is NOT expected and if there's a
1821+
/// semicolon it emits the appropriate error and returns true.
1822+
pub fn maybe_consume_incorrect_semicolon(&mut self, previous_item: Option<&Item>) -> bool {
1823+
if self.token.kind != TokenKind::Semi {
1824+
return false;
1825+
}
18261826

1827-
if !items.is_empty() {
1828-
let previous_item = &items[items.len() - 1];
1829-
let previous_item_kind_name = match previous_item.kind {
1827+
// Check previous item to add it to the diagnostic, for example to say
1828+
// `enum declarations are not followed by a semicolon`
1829+
let err = match previous_item {
1830+
Some(previous_item) => {
1831+
let name = match previous_item.kind {
18301832
// Say "braced struct" because tuple-structs and
18311833
// braceless-empty-struct declarations do take a semicolon.
1832-
ItemKind::Struct(..) => Some("braced struct"),
1833-
ItemKind::Enum(..) => Some("enum"),
1834-
ItemKind::Trait(..) => Some("trait"),
1835-
ItemKind::Union(..) => Some("union"),
1836-
_ => None,
1834+
ItemKind::Struct(..) => "braced struct",
1835+
_ => previous_item.kind.descr(),
18371836
};
1838-
if let Some(name) = previous_item_kind_name {
1839-
err.opt_help = Some(());
1840-
err.name = name;
1841-
}
1837+
IncorrectSemicolon { span: self.token.span, name, show_help: true }
18421838
}
1843-
self.dcx().emit_err(err);
1844-
true
1845-
} else {
1846-
false
1847-
}
1839+
None => IncorrectSemicolon { span: self.token.span, name: "", show_help: false },
1840+
};
1841+
self.dcx().emit_err(err);
1842+
1843+
self.bump();
1844+
true
18481845
}
18491846

18501847
/// Creates a `Diag` for an unexpected token `t` and tries to recover if it is a
@@ -2957,13 +2954,23 @@ impl<'a> Parser<'a> {
29572954
err
29582955
}
29592956

2960-
pub fn is_diff_marker(&mut self, long_kind: &TokenKind, short_kind: &TokenKind) -> bool {
2957+
/// This checks if this is a conflict marker, depending of the parameter passed.
2958+
///
2959+
/// * `>>>>>`
2960+
/// * `=====`
2961+
/// * `<<<<<`
2962+
///
2963+
pub fn is_vcs_conflict_marker(
2964+
&mut self,
2965+
long_kind: &TokenKind,
2966+
short_kind: &TokenKind,
2967+
) -> bool {
29612968
(0..3).all(|i| self.look_ahead(i, |tok| tok == long_kind))
29622969
&& self.look_ahead(3, |tok| tok == short_kind)
29632970
}
29642971

2965-
fn diff_marker(&mut self, long_kind: &TokenKind, short_kind: &TokenKind) -> Option<Span> {
2966-
if self.is_diff_marker(long_kind, short_kind) {
2972+
fn conflict_marker(&mut self, long_kind: &TokenKind, short_kind: &TokenKind) -> Option<Span> {
2973+
if self.is_vcs_conflict_marker(long_kind, short_kind) {
29672974
let lo = self.token.span;
29682975
for _ in 0..4 {
29692976
self.bump();
@@ -2973,15 +2980,16 @@ impl<'a> Parser<'a> {
29732980
None
29742981
}
29752982

2976-
pub fn recover_diff_marker(&mut self) {
2977-
if let Err(err) = self.err_diff_marker() {
2983+
pub fn recover_vcs_conflict_marker(&mut self) {
2984+
if let Err(err) = self.err_vcs_conflict_marker() {
29782985
err.emit();
29792986
FatalError.raise();
29802987
}
29812988
}
29822989

2983-
pub fn err_diff_marker(&mut self) -> PResult<'a, ()> {
2984-
let Some(start) = self.diff_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt) else {
2990+
pub fn err_vcs_conflict_marker(&mut self) -> PResult<'a, ()> {
2991+
let Some(start) = self.conflict_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt)
2992+
else {
29852993
return Ok(());
29862994
};
29872995
let mut spans = Vec::with_capacity(3);
@@ -2993,13 +3001,15 @@ impl<'a> Parser<'a> {
29933001
if self.token.kind == TokenKind::Eof {
29943002
break;
29953003
}
2996-
if let Some(span) = self.diff_marker(&TokenKind::OrOr, &TokenKind::BinOp(token::Or)) {
3004+
if let Some(span) = self.conflict_marker(&TokenKind::OrOr, &TokenKind::BinOp(token::Or))
3005+
{
29973006
middlediff3 = Some(span);
29983007
}
2999-
if let Some(span) = self.diff_marker(&TokenKind::EqEq, &TokenKind::Eq) {
3008+
if let Some(span) = self.conflict_marker(&TokenKind::EqEq, &TokenKind::Eq) {
30003009
middle = Some(span);
30013010
}
3002-
if let Some(span) = self.diff_marker(&TokenKind::BinOp(token::Shr), &TokenKind::Gt) {
3011+
if let Some(span) = self.conflict_marker(&TokenKind::BinOp(token::Shr), &TokenKind::Gt)
3012+
{
30033013
spans.push(span);
30043014
end = Some(span);
30053015
break;

compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3734,7 +3734,7 @@ impl<'a> Parser<'a> {
37343734
/// Parses `ident (COLON expr)?`.
37353735
fn parse_expr_field(&mut self) -> PResult<'a, ExprField> {
37363736
let attrs = self.parse_outer_attributes()?;
3737-
self.recover_diff_marker();
3737+
self.recover_vcs_conflict_marker();
37383738
self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
37393739
let lo = this.token.span;
37403740

compiler/rustc_parse/src/parser/item.rs

+26-30
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl<'a> Parser<'a> {
4949
}
5050

5151
/// Parses the contents of a module (inner attributes followed by module items).
52+
/// We exit once we hit `term`
5253
pub fn parse_mod(
5354
&mut self,
5455
term: &TokenKind,
@@ -59,13 +60,13 @@ impl<'a> Parser<'a> {
5960
let post_attr_lo = self.token.span;
6061
let mut items = ThinVec::new();
6162
while let Some(item) = self.parse_item(ForceCollect::No)? {
63+
self.maybe_consume_incorrect_semicolon(Some(&item));
6264
items.push(item);
63-
self.maybe_consume_incorrect_semicolon(&items);
6465
}
6566

6667
if !self.eat(term) {
6768
let token_str = super::token_descr(&self.token);
68-
if !self.maybe_consume_incorrect_semicolon(&items) {
69+
if !self.maybe_consume_incorrect_semicolon(items.last().map(|x| &**x)) {
6970
let msg = format!("expected item, found {token_str}");
7071
let mut err = self.dcx().struct_span_err(self.token.span, msg);
7172
let span = self.token.span;
@@ -101,9 +102,9 @@ impl<'a> Parser<'a> {
101102
fn_parse_mode: FnParseMode,
102103
force_collect: ForceCollect,
103104
) -> PResult<'a, Option<Item>> {
104-
self.recover_diff_marker();
105+
self.recover_vcs_conflict_marker();
105106
let attrs = self.parse_outer_attributes()?;
106-
self.recover_diff_marker();
107+
self.recover_vcs_conflict_marker();
107108
self.parse_item_common(attrs, true, false, fn_parse_mode, force_collect)
108109
}
109110

@@ -194,12 +195,12 @@ impl<'a> Parser<'a> {
194195
fn_parse_mode: FnParseMode,
195196
case: Case,
196197
) -> PResult<'a, Option<ItemInfo>> {
197-
let def_final = def == &Defaultness::Final;
198+
let check_pub = def == &Defaultness::Final;
198199
let mut def_ = || mem::replace(def, Defaultness::Final);
199200

200201
let info = if self.eat_keyword_case(kw::Use, case) {
201202
self.parse_use_item()?
202-
} else if self.check_fn_front_matter(def_final, case) {
203+
} else if self.check_fn_front_matter(check_pub, case) {
203204
// FUNCTION ITEM
204205
let (ident, sig, generics, body) =
205206
self.parse_fn(attrs, fn_parse_mode, lo, vis, case)?;
@@ -310,7 +311,7 @@ impl<'a> Parser<'a> {
310311
Ok(Some(info))
311312
}
312313

313-
fn recover_import_as_use(&mut self) -> PResult<'a, Option<(Ident, ItemKind)>> {
314+
fn recover_import_as_use(&mut self) -> PResult<'a, Option<ItemInfo>> {
314315
let span = self.token.span;
315316
let token_name = super::token_descr(&self.token);
316317
let snapshot = self.create_snapshot_for_diagnostic();
@@ -328,7 +329,7 @@ impl<'a> Parser<'a> {
328329
}
329330
}
330331

331-
fn parse_use_item(&mut self) -> PResult<'a, (Ident, ItemKind)> {
332+
fn parse_use_item(&mut self) -> PResult<'a, ItemInfo> {
332333
let tree = self.parse_use_tree()?;
333334
if let Err(mut e) = self.expect_semi() {
334335
match tree.kind {
@@ -738,7 +739,7 @@ impl<'a> Parser<'a> {
738739
if self.recover_doc_comment_before_brace() {
739740
continue;
740741
}
741-
self.recover_diff_marker();
742+
self.recover_vcs_conflict_marker();
742743
match parse_item(self) {
743744
Ok(None) => {
744745
let mut is_unnecessary_semicolon = !items.is_empty()
@@ -1085,7 +1086,7 @@ impl<'a> Parser<'a> {
10851086
/// ```
10861087
fn parse_use_tree_list(&mut self) -> PResult<'a, ThinVec<(UseTree, ast::NodeId)>> {
10871088
self.parse_delim_comma_seq(Delimiter::Brace, |p| {
1088-
p.recover_diff_marker();
1089+
p.recover_vcs_conflict_marker();
10891090
Ok((p.parse_use_tree()?, DUMMY_NODE_ID))
10901091
})
10911092
.map(|(r, _)| r)
@@ -1512,9 +1513,9 @@ impl<'a> Parser<'a> {
15121513
}
15131514

15141515
fn parse_enum_variant(&mut self, span: Span) -> PResult<'a, Option<Variant>> {
1515-
self.recover_diff_marker();
1516+
self.recover_vcs_conflict_marker();
15161517
let variant_attrs = self.parse_outer_attributes()?;
1517-
self.recover_diff_marker();
1518+
self.recover_vcs_conflict_marker();
15181519
let help = "enum variants can be `Variant`, `Variant = <integer>`, \
15191520
`Variant(Type, ..., TypeN)` or `Variant { fields: Types }`";
15201521
self.collect_tokens_trailing_token(
@@ -1703,6 +1704,10 @@ impl<'a> Parser<'a> {
17031704
Ok((class_name, ItemKind::Union(vdata, generics)))
17041705
}
17051706

1707+
/// This function parses the fields of record structs:
1708+
///
1709+
/// - `struct S { ... }`
1710+
/// - `enum E { Variant { ... } }`
17061711
pub(crate) fn parse_record_struct_body(
17071712
&mut self,
17081713
adt_ty: &str,
@@ -1729,19 +1734,10 @@ impl<'a> Parser<'a> {
17291734
self.eat(&token::CloseDelim(Delimiter::Brace));
17301735
} else {
17311736
let token_str = super::token_descr(&self.token);
1732-
let msg = format!(
1733-
"expected {}`{{` after struct name, found {}",
1734-
if parsed_where { "" } else { "`where`, or " },
1735-
token_str
1736-
);
1737+
let where_str = if parsed_where { "" } else { "`where`, or " };
1738+
let msg = format!("expected {where_str}`{{` after struct name, found {token_str}");
17371739
let mut err = self.dcx().struct_span_err(self.token.span, msg);
1738-
err.span_label(
1739-
self.token.span,
1740-
format!(
1741-
"expected {}`{{` after struct name",
1742-
if parsed_where { "" } else { "`where`, or " }
1743-
),
1744-
);
1740+
err.span_label(self.token.span, format!("expected {where_str}`{{` after struct name",));
17451741
return Err(err);
17461742
}
17471743

@@ -1755,7 +1751,7 @@ impl<'a> Parser<'a> {
17551751
let attrs = p.parse_outer_attributes()?;
17561752
p.collect_tokens_trailing_token(attrs, ForceCollect::No, |p, attrs| {
17571753
let mut snapshot = None;
1758-
if p.is_diff_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt) {
1754+
if p.is_vcs_conflict_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt) {
17591755
// Account for `<<<<<<<` diff markers. We can't proactively error here because
17601756
// that can be a valid type start, so we snapshot and reparse only we've
17611757
// encountered another parse error.
@@ -1766,7 +1762,7 @@ impl<'a> Parser<'a> {
17661762
Ok(vis) => vis,
17671763
Err(err) => {
17681764
if let Some(ref mut snapshot) = snapshot {
1769-
snapshot.recover_diff_marker();
1765+
snapshot.recover_vcs_conflict_marker();
17701766
}
17711767
return Err(err);
17721768
}
@@ -1775,7 +1771,7 @@ impl<'a> Parser<'a> {
17751771
Ok(ty) => ty,
17761772
Err(err) => {
17771773
if let Some(ref mut snapshot) = snapshot {
1778-
snapshot.recover_diff_marker();
1774+
snapshot.recover_vcs_conflict_marker();
17791775
}
17801776
return Err(err);
17811777
}
@@ -1800,9 +1796,9 @@ impl<'a> Parser<'a> {
18001796

18011797
/// Parses an element of a struct declaration.
18021798
fn parse_field_def(&mut self, adt_ty: &str) -> PResult<'a, FieldDef> {
1803-
self.recover_diff_marker();
1799+
self.recover_vcs_conflict_marker();
18041800
let attrs = self.parse_outer_attributes()?;
1805-
self.recover_diff_marker();
1801+
self.recover_vcs_conflict_marker();
18061802
self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
18071803
let lo = this.token.span;
18081804
let vis = this.parse_visibility(FollowedByType::No)?;
@@ -2662,7 +2658,7 @@ impl<'a> Parser<'a> {
26622658
}
26632659

26642660
let (mut params, _) = self.parse_paren_comma_seq(|p| {
2665-
p.recover_diff_marker();
2661+
p.recover_vcs_conflict_marker();
26662662
let snapshot = p.create_snapshot_for_diagnostic();
26672663
let param = p.parse_param_general(req_name, first_param).or_else(|e| {
26682664
let guar = e.emit();

0 commit comments

Comments
 (0)