Skip to content

Commit 249cf71

Browse files
committed
Auto merge of #128413 - matthiaskrgr:rollup-nrfcvdq, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #128357 (Detect non-lifetime binder params shadowing item params) - #128367 (CI: rfl: build the generated doctests and documentation) - #128376 (Mark `Parser::eat`/`check` methods as `#[must_use]`) - #128379 (the output in stderr expects panic-unwind) - #128380 (make `///` doc comments compatible with naked functions) - #128382 (cargo-miri: better error when we seem to run inside bootstrap but something is wrong) - #128398 (tidy: Fix quote in error message) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f8060d2 + 42a0cc8 commit 249cf71

File tree

23 files changed

+162
-40
lines changed

23 files changed

+162
-40
lines changed

compiler/rustc_builtin_macros/src/pattern_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn parse_pat_ty<'a>(cx: &mut ExtCtxt<'a>, stream: TokenStream) -> PResult<'a, (P
2424
let mut parser = cx.new_parser_from_tts(stream);
2525

2626
let ty = parser.parse_ty()?;
27-
parser.eat_keyword(sym::is);
27+
parser.expect_keyword(sym::is)?;
2828
let pat = parser.parse_pat_no_top_alt(None, None)?;
2929

3030
Ok((ty, pat))

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,7 +3153,8 @@ impl<'a> Parser<'a> {
31533153

31543154
if !require_comma {
31553155
arm_body = Some(expr);
3156-
this.eat(&token::Comma);
3156+
// Eat a comma if it exists, though.
3157+
let _ = this.eat(&token::Comma);
31573158
Ok(Recovered::No)
31583159
} else if let Some((span, guar)) =
31593160
this.parse_arm_body_missing_braces(&expr, arrow_span)
@@ -3654,7 +3655,7 @@ impl<'a> Parser<'a> {
36543655
fields.push(f);
36553656
}
36563657
self.recover_stmt_(SemiColonMode::Comma, BlockMode::Ignore);
3657-
self.eat(&token::Comma);
3658+
let _ = self.eat(&token::Comma);
36583659
}
36593660
}
36603661
}

compiler/rustc_parse/src/parser/generics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ impl<'a> Parser<'a> {
178178
span: this.prev_token.span,
179179
});
180180

181-
this.eat(&token::Comma);
181+
// Eat a trailing comma, if it exists.
182+
let _ = this.eat(&token::Comma);
182183
}
183184

184185
let param = if this.check_lifetime() {

compiler/rustc_parse/src/parser/item.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,13 +1192,14 @@ impl<'a> Parser<'a> {
11921192
mut safety: Safety,
11931193
) -> PResult<'a, ItemInfo> {
11941194
let abi = self.parse_abi(); // ABI?
1195+
// FIXME: This recovery should be tested better.
11951196
if safety == Safety::Default
11961197
&& self.token.is_keyword(kw::Unsafe)
11971198
&& self.look_ahead(1, |t| t.kind == token::OpenDelim(Delimiter::Brace))
11981199
{
11991200
self.expect(&token::OpenDelim(Delimiter::Brace)).unwrap_err().emit();
12001201
safety = Safety::Unsafe(self.token.span);
1201-
self.eat_keyword(kw::Unsafe);
1202+
let _ = self.eat_keyword(kw::Unsafe);
12021203
}
12031204
let module = ast::ForeignMod {
12041205
safety,
@@ -1759,7 +1760,7 @@ impl<'a> Parser<'a> {
17591760
}
17601761
}
17611762
}
1762-
self.eat(&token::CloseDelim(Delimiter::Brace));
1763+
self.expect(&token::CloseDelim(Delimiter::Brace))?;
17631764
} else {
17641765
let token_str = super::token_descr(&self.token);
17651766
let where_str = if parsed_where { "" } else { "`where`, or " };
@@ -1902,7 +1903,7 @@ impl<'a> Parser<'a> {
19021903
if let Some(_guar) = guar {
19031904
// Handle a case like `Vec<u8>>,` where we can continue parsing fields
19041905
// after the comma
1905-
self.eat(&token::Comma);
1906+
let _ = self.eat(&token::Comma);
19061907

19071908
// `check_trailing_angle_brackets` already emitted a nicer error, as
19081909
// proven by the presence of `_guar`. We can continue parsing.

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ impl<'a> Parser<'a> {
547547
}
548548

549549
#[inline]
550+
#[must_use]
550551
fn check_noexpect(&self, tok: &TokenKind) -> bool {
551552
self.token == *tok
552553
}
@@ -556,6 +557,7 @@ impl<'a> Parser<'a> {
556557
/// the main purpose of this function is to reduce the cluttering of the suggestions list
557558
/// which using the normal eat method could introduce in some cases.
558559
#[inline]
560+
#[must_use]
559561
fn eat_noexpect(&mut self, tok: &TokenKind) -> bool {
560562
let is_present = self.check_noexpect(tok);
561563
if is_present {
@@ -566,6 +568,7 @@ impl<'a> Parser<'a> {
566568

567569
/// Consumes a token 'tok' if it exists. Returns whether the given token was present.
568570
#[inline]
571+
#[must_use]
569572
pub fn eat(&mut self, tok: &TokenKind) -> bool {
570573
let is_present = self.check(tok);
571574
if is_present {
@@ -577,12 +580,14 @@ impl<'a> Parser<'a> {
577580
/// If the next token is the given keyword, returns `true` without eating it.
578581
/// An expectation is also added for diagnostics purposes.
579582
#[inline]
583+
#[must_use]
580584
fn check_keyword(&mut self, kw: Symbol) -> bool {
581585
self.expected_tokens.push(TokenType::Keyword(kw));
582586
self.token.is_keyword(kw)
583587
}
584588

585589
#[inline]
590+
#[must_use]
586591
fn check_keyword_case(&mut self, kw: Symbol, case: Case) -> bool {
587592
if self.check_keyword(kw) {
588593
return true;
@@ -602,6 +607,7 @@ impl<'a> Parser<'a> {
602607
/// Otherwise, returns `false`. An expectation is also added for diagnostics purposes.
603608
// Public for rustc_builtin_macros and rustfmt usage.
604609
#[inline]
610+
#[must_use]
605611
pub fn eat_keyword(&mut self, kw: Symbol) -> bool {
606612
if self.check_keyword(kw) {
607613
self.bump();
@@ -615,6 +621,7 @@ impl<'a> Parser<'a> {
615621
/// If the case differs (and is ignored) an error is issued.
616622
/// This is useful for recovery.
617623
#[inline]
624+
#[must_use]
618625
fn eat_keyword_case(&mut self, kw: Symbol, case: Case) -> bool {
619626
if self.eat_keyword(kw) {
620627
return true;
@@ -636,6 +643,7 @@ impl<'a> Parser<'a> {
636643
/// Otherwise, returns `false`. No expectation is added.
637644
// Public for rustc_builtin_macros usage.
638645
#[inline]
646+
#[must_use]
639647
pub fn eat_keyword_noexpect(&mut self, kw: Symbol) -> bool {
640648
if self.token.is_keyword(kw) {
641649
self.bump();
@@ -648,7 +656,7 @@ impl<'a> Parser<'a> {
648656
/// If the given word is not a keyword, signals an error.
649657
/// If the next token is not the given word, signals an error.
650658
/// Otherwise, eats it.
651-
fn expect_keyword(&mut self, kw: Symbol) -> PResult<'a, ()> {
659+
pub fn expect_keyword(&mut self, kw: Symbol) -> PResult<'a, ()> {
652660
if !self.eat_keyword(kw) { self.unexpected() } else { Ok(()) }
653661
}
654662

@@ -1025,8 +1033,11 @@ impl<'a> Parser<'a> {
10251033
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
10261034
) -> PResult<'a, (ThinVec<T>, Trailing)> {
10271035
let (val, trailing, recovered) = self.parse_seq_to_before_end(ket, sep, f)?;
1028-
if matches!(recovered, Recovered::No) {
1029-
self.eat(ket);
1036+
if matches!(recovered, Recovered::No) && !self.eat(ket) {
1037+
self.dcx().span_delayed_bug(
1038+
self.token.span,
1039+
"recovered but `parse_seq_to_before_end` did not give us the ket token",
1040+
);
10301041
}
10311042
Ok((val, trailing))
10321043
}
@@ -1250,7 +1261,7 @@ impl<'a> Parser<'a> {
12501261
if pat {
12511262
self.psess.gated_spans.gate(sym::inline_const_pat, span);
12521263
}
1253-
self.eat_keyword(kw::Const);
1264+
self.expect_keyword(kw::Const)?;
12541265
let (attrs, blk) = self.parse_inner_attrs_and_block()?;
12551266
let anon_const = AnonConst {
12561267
id: DUMMY_NODE_ID,

compiler/rustc_parse/src/parser/path.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ impl<'a> Parser<'a> {
313313
}
314314

315315
// Generic arguments are found - `<`, `(`, `::<` or `::(`.
316-
self.eat(&token::PathSep);
316+
// First, eat `::` if it exists.
317+
let _ = self.eat(&token::PathSep);
317318
let lo = self.token.span;
318319
let args = if self.eat_lt() {
319320
// `<'a, T, A = U>`

compiler/rustc_passes/src/check_attr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,12 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
461461
Target::Fn
462462
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => {
463463
for other_attr in attrs {
464+
// this covers "sugared doc comments" of the form `/// ...`
465+
// it does not cover `#[doc = "..."]`, which is handled below
466+
if other_attr.is_doc_comment() {
467+
continue;
468+
}
469+
464470
if !ALLOW_LIST.iter().any(|name| other_attr.has_name(*name)) {
465471
self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
466472
span: other_attr.span,

compiler/rustc_resolve/src/late.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,17 +2671,17 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
26712671
// Store all seen lifetimes names from outer scopes.
26722672
let mut seen_lifetimes = FxHashSet::default();
26732673

2674-
// We also can't shadow bindings from the parent item
2675-
if let RibKind::AssocItem = kind {
2676-
let mut add_bindings_for_ns = |ns| {
2677-
let parent_rib = self.ribs[ns]
2678-
.iter()
2679-
.rfind(|r| matches!(r.kind, RibKind::Item(..)))
2680-
.expect("associated item outside of an item");
2674+
// We also can't shadow bindings from associated parent items.
2675+
for ns in [ValueNS, TypeNS] {
2676+
for parent_rib in self.ribs[ns].iter().rev() {
26812677
seen_bindings.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
2682-
};
2683-
add_bindings_for_ns(ValueNS);
2684-
add_bindings_for_ns(TypeNS);
2678+
2679+
// Break at mod level, to account for nested items which are
2680+
// allowed to shadow generic param names.
2681+
if matches!(parent_rib.kind, RibKind::Module(..)) {
2682+
break;
2683+
}
2684+
}
26852685
}
26862686

26872687
// Forbid shadowing lifetime bindings

src/ci/docker/scripts/rfl-build.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,8 @@ make -C linux LLVM=1 -j$(($(nproc) + 1)) \
6565
make -C linux LLVM=1 -j$(($(nproc) + 1)) \
6666
samples/rust/rust_minimal.o \
6767
samples/rust/rust_print.o \
68-
drivers/net/phy/ax88796b_rust.o
68+
drivers/net/phy/ax88796b_rust.o \
69+
rust/doctests_kernel_generated.o
70+
71+
make -C linux LLVM=1 -j$(($(nproc) + 1)) \
72+
rustdoc

src/tools/miri/cargo-miri/src/setup.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ pub fn setup(
100100
// for target crates.
101101
let cargo_miri_path = std::env::current_exe().expect("current executable path invalid");
102102
if env::var_os("RUSTC_STAGE").is_some() {
103-
assert!(env::var_os("RUSTC").is_some());
103+
assert!(
104+
env::var_os("RUSTC").is_some() && env::var_os("RUSTC_WRAPPER").is_some(),
105+
"cargo-miri setup is running inside rustc bootstrap but RUSTC or RUST_WRAPPER is not set"
106+
);
104107
command.env("RUSTC_REAL", &cargo_miri_path);
105108
} else {
106109
command.env("RUSTC", &cargo_miri_path);

0 commit comments

Comments
 (0)