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

+1-1
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

+3-2
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

+2-1
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

+4-3
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

+15-4
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

+2-1
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

+6
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

+10-10
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

+5-1
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

+4-1
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);

src/tools/rustfmt/src/parse/macros/lazy_static.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ pub(crate) fn parse_lazy_static(
3333
}
3434
while parser.token.kind != TokenKind::Eof {
3535
// Parse a `lazy_static!` item.
36+
// FIXME: These `eat_*` calls should be converted to `parse_or` to avoid
37+
// silently formatting malformed lazy-statics.
3638
let vis = parse_or!(parse_visibility, rustc_parse::parser::FollowedByType::No);
37-
parser.eat_keyword(kw::Static);
38-
parser.eat_keyword(kw::Ref);
39+
let _ = parser.eat_keyword(kw::Static);
40+
let _ = parser.eat_keyword(kw::Ref);
3941
let id = parse_or!(parse_ident);
40-
parser.eat(&TokenKind::Colon);
42+
let _ = parser.eat(&TokenKind::Colon);
4143
let ty = parse_or!(parse_ty);
42-
parser.eat(&TokenKind::Eq);
44+
let _ = parser.eat(&TokenKind::Eq);
4345
let expr = parse_or!(parse_expr);
44-
parser.eat(&TokenKind::Semi);
46+
let _ = parser.eat(&TokenKind::Semi);
4547
result.push((vis, id, ty, expr));
4648
}
4749

src/tools/tidy/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ fn check_error_codes_tests(
319319
if !found_code {
320320
verbose_print!(
321321
verbose,
322-
"warning: Error code {code}`` has a UI test file, but doesn't contain its own error code!"
322+
"warning: Error code `{code}` has a UI test file, but doesn't contain its own error code!"
323323
);
324324
}
325325
}

tests/crashes/119716-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
//@ known-bug: #119716
22
#![feature(non_lifetime_binders)]
33
trait Trait<T> {}
4-
fn f<T>() -> impl for<T> Trait<impl Trait<T>> {}
4+
fn f() -> impl for<T> Trait<impl Trait<T>> {}

tests/crashes/123809.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
//@ known-bug: #123809
2-
type Positive = std::pat::pattern_type!(std::pat:: is 0..);
2+
type Positive = std::pat::pattern_type!(std::pat is 0..);
33

44
pub fn main() {}

tests/ui/asm/naked-functions.rs

+3
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ pub unsafe extern "C" fn compatible_target_feature() {
239239
}
240240

241241
#[doc = "foo bar baz"]
242+
/// a doc comment
243+
// a normal comment
244+
#[doc(alias = "ADocAlias")]
242245
#[naked]
243246
pub unsafe extern "C" fn compatible_doc_attributes() {
244247
asm!("", options(noreturn, raw));

tests/ui/backtrace/synchronized-panic-handler.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//@ edition:2021
44
//@ exec-env:RUST_BACKTRACE=0
55
//@ needs-threads
6+
//@ needs-unwind
67
use std::thread;
78
const PANIC_MESSAGE: &str = "oops oh no woe is me";
89

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
thread '<unnamed>' panicked at $DIR/synchronized-panic-handler.rs:10:5:
1+
thread '<unnamed>' panicked at $DIR/synchronized-panic-handler.rs:11:5:
22
oops oh no woe is me
33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
4-
thread '<unnamed>' panicked at $DIR/synchronized-panic-handler.rs:10:5:
4+
thread '<unnamed>' panicked at $DIR/synchronized-panic-handler.rs:11:5:
55
oops oh no woe is me

tests/ui/const-generics/generic_const_exprs/ice-predicates-of-no-entry-found-for-key-119275.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ fn bug<const N: Nat>(&self)
99
where
1010
for<const N: usize = 3, T = u32> [(); COT::BYTES]:,
1111
//~^ ERROR only lifetime parameters can be used in this context
12-
//~^^ ERROR defaults for generic parameters are not allowed in `for<...>` binders
13-
//~^^^ ERROR defaults for generic parameters are not allowed in `for<...>` binders
14-
//~^^^^ ERROR failed to resolve: use of undeclared type `COT`
12+
//~| ERROR defaults for generic parameters are not allowed in `for<...>` binders
13+
//~| ERROR defaults for generic parameters are not allowed in `for<...>` binders
14+
//~| ERROR failed to resolve: use of undeclared type `COT`
15+
//~| ERROR the name `N` is already used for a generic parameter in this item's generic parameters
1516
{
1617
}
1718

tests/ui/const-generics/generic_const_exprs/ice-predicates-of-no-entry-found-for-key-119275.stderr

+12-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ LL | fn bug<const N: Nat>(&self)
66
|
77
= note: associated functions are those in `impl` or `trait` definitions
88

9+
error[E0403]: the name `N` is already used for a generic parameter in this item's generic parameters
10+
--> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:10:15
11+
|
12+
LL | fn bug<const N: Nat>(&self)
13+
| - first use of `N`
14+
...
15+
LL | for<const N: usize = 3, T = u32> [(); COT::BYTES]:,
16+
| ^ already used
17+
918
error[E0412]: cannot find type `Nat` in this scope
1019
--> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:6:17
1120
|
@@ -40,7 +49,7 @@ error[E0433]: failed to resolve: use of undeclared type `COT`
4049
LL | for<const N: usize = 3, T = u32> [(); COT::BYTES]:,
4150
| ^^^ use of undeclared type `COT`
4251

43-
error: aborting due to 6 previous errors
52+
error: aborting due to 7 previous errors
4453

45-
Some errors have detailed explanations: E0412, E0433, E0658.
46-
For more information about an error, try `rustc --explain E0412`.
54+
Some errors have detailed explanations: E0403, E0412, E0433, E0658.
55+
For more information about an error, try `rustc --explain E0403`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(non_lifetime_binders)]
2+
//~^ WARN the feature `non_lifetime_binders` is incomplete
3+
4+
fn function<T>() where for<T> (): Sized {}
5+
//~^ ERROR the name `T` is already used for a generic parameter
6+
7+
struct Struct<T>(T) where for<T> (): Sized;
8+
//~^ ERROR the name `T` is already used for a generic parameter
9+
10+
impl<T> Struct<T> {
11+
fn method() where for<T> (): Sized {}
12+
//~^ ERROR the name `T` is already used for a generic parameter
13+
}
14+
15+
fn repeated() where for<T, T> (): Sized {}
16+
//~^ ERROR the name `T` is already used for a generic parameter
17+
18+
fn main() {}

0 commit comments

Comments
 (0)