Skip to content

Commit 5f1173b

Browse files
committed
Auto merge of #149818 - matthiaskrgr:rollup-uw85yss, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #144938 (Enable `outline-atomics` by default on more AArch64 platforms) - #146579 (Handle macro invocation in attribute during parse) - #149400 (unstable proc_macro tracked::* rename/restructure) - #149664 (attempt to fix unreachable code regression ) - #149806 (Mirror `ubuntu:24.04` on ghcr) Failed merges: - #149789 (Cleanup in the attribute parsers) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c61a3a4 + a00807e commit 5f1173b

38 files changed

+260
-88
lines changed

.github/workflows/ghcr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ jobs:
5555
images=(
5656
# Mirrored because used by the tidy job, which doesn't cache Docker images
5757
"ubuntu:22.04"
58+
# Mirrored because used by x86-64-gnu-miri
59+
"ubuntu:24.04"
5860
# Mirrored because used by all linux CI jobs, including tidy
5961
"moby/buildkit:buildx-stable-1"
6062
# Mirrored because used when CI is running inside a Docker container

compiler/rustc_ast/src/ast.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,19 @@ pub enum StmtKind {
12591259
MacCall(Box<MacCallStmt>),
12601260
}
12611261

1262+
impl StmtKind {
1263+
pub fn descr(&self) -> &'static str {
1264+
match self {
1265+
StmtKind::Let(_) => "local",
1266+
StmtKind::Item(_) => "item",
1267+
StmtKind::Expr(_) => "expression",
1268+
StmtKind::Semi(_) => "statement",
1269+
StmtKind::Empty => "semicolon",
1270+
StmtKind::MacCall(_) => "macro call",
1271+
}
1272+
}
1273+
}
1274+
12621275
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
12631276
pub struct MacCallStmt {
12641277
pub mac: Box<MacCall>,

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ attr_parsing_invalid_link_modifier =
8787
attr_parsing_invalid_meta_item = expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found {$descr}
8888
.remove_neg_sugg = negative numbers are not literals, try removing the `-` sign
8989
.quote_ident_sugg = surround the identifier with quotation marks to make it into a string literal
90+
.label = {$descr}s are not allowed here
9091
9192
attr_parsing_invalid_predicate =
9293
invalid predicate `{$predicate}`

compiler/rustc_attr_parsing/src/parser.rs

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use std::fmt::{Debug, Display};
88

99
use rustc_ast::token::{self, Delimiter, MetaVarKind};
1010
use rustc_ast::tokenstream::TokenStream;
11-
use rustc_ast::{AttrArgs, Expr, ExprKind, LitKind, MetaItemLit, NormalAttr, Path};
11+
use rustc_ast::{AttrArgs, Expr, ExprKind, LitKind, MetaItemLit, NormalAttr, Path, StmtKind, UnOp};
1212
use rustc_ast_pretty::pprust;
1313
use rustc_errors::{Diag, PResult};
1414
use rustc_hir::{self as hir, AttrPath};
1515
use rustc_parse::exp;
16-
use rustc_parse::parser::{Parser, PathStyle, token_descr};
16+
use rustc_parse::parser::{ForceCollect, Parser, PathStyle, token_descr};
1717
use rustc_session::errors::{create_lit_error, report_lit_error};
1818
use rustc_session::parse::ParseSess;
1919
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, sym};
@@ -488,33 +488,55 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
488488
descr: token_descr(&self.parser.token),
489489
quote_ident_sugg: None,
490490
remove_neg_sugg: None,
491+
label: None,
491492
};
492493

494+
if let token::OpenInvisible(_) = self.parser.token.kind {
495+
// Do not attempt to suggest anything when encountered as part of a macro expansion.
496+
return self.parser.dcx().create_err(err);
497+
}
498+
493499
// Suggest quoting idents, e.g. in `#[cfg(key = value)]`. We don't use `Token::ident` and
494500
// don't `uninterpolate` the token to avoid suggesting anything butchered or questionable
495501
// when macro metavariables are involved.
496-
if self.parser.prev_token == token::Eq
497-
&& let token::Ident(..) = self.parser.token.kind
498-
{
499-
let before = self.parser.token.span.shrink_to_lo();
500-
while let token::Ident(..) = self.parser.token.kind {
501-
self.parser.bump();
502+
let snapshot = self.parser.create_snapshot_for_diagnostic();
503+
let stmt = self.parser.parse_stmt_without_recovery(false, ForceCollect::No, false);
504+
match stmt {
505+
Ok(Some(stmt)) => {
506+
// The user tried to write something like
507+
// `#[deprecated(note = concat!("a", "b"))]`.
508+
err.descr = stmt.kind.descr().to_string();
509+
err.label = Some(stmt.span);
510+
err.span = stmt.span;
511+
if let StmtKind::Expr(expr) = &stmt.kind
512+
&& let ExprKind::Unary(UnOp::Neg, val) = &expr.kind
513+
&& let ExprKind::Lit(_) = val.kind
514+
{
515+
err.remove_neg_sugg = Some(InvalidMetaItemRemoveNegSugg {
516+
negative_sign: expr.span.until(val.span),
517+
});
518+
} else if let StmtKind::Expr(expr) = &stmt.kind
519+
&& let ExprKind::Path(None, Path { segments, .. }) = &expr.kind
520+
&& segments.len() == 1
521+
{
522+
while let token::Ident(..) | token::Literal(_) | token::Dot =
523+
self.parser.token.kind
524+
{
525+
// We've got a word, so we try to consume the rest of a potential sentence.
526+
// We include `.` to correctly handle things like `A sentence here.`.
527+
self.parser.bump();
528+
}
529+
err.quote_ident_sugg = Some(InvalidMetaItemQuoteIdentSugg {
530+
before: expr.span.shrink_to_lo(),
531+
after: self.parser.prev_token.span.shrink_to_hi(),
532+
});
533+
}
534+
}
535+
Ok(None) => {}
536+
Err(e) => {
537+
e.cancel();
538+
self.parser.restore_snapshot(snapshot);
502539
}
503-
err.quote_ident_sugg = Some(InvalidMetaItemQuoteIdentSugg {
504-
before,
505-
after: self.parser.prev_token.span.shrink_to_hi(),
506-
});
507-
}
508-
509-
if self.parser.token == token::Minus
510-
&& self
511-
.parser
512-
.look_ahead(1, |t| matches!(t.kind, rustc_ast::token::TokenKind::Literal { .. }))
513-
{
514-
err.remove_neg_sugg =
515-
Some(InvalidMetaItemRemoveNegSugg { negative_sign: self.parser.token.span });
516-
self.parser.bump();
517-
self.parser.bump();
518540
}
519541

520542
self.parser.dcx().create_err(err)

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,8 @@ pub(crate) struct InvalidMetaItem {
804804
pub quote_ident_sugg: Option<InvalidMetaItemQuoteIdentSugg>,
805805
#[subdiagnostic]
806806
pub remove_neg_sugg: Option<InvalidMetaItemRemoveNegSugg>,
807+
#[label]
808+
pub label: Option<Span>,
807809
}
808810

809811
#[derive(Subdiagnostic)]

compiler/rustc_fluent_macro/src/fluent.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use fluent_syntax::ast::{
88
Attribute, Entry, Expression, Identifier, InlineExpression, Message, Pattern, PatternElement,
99
};
1010
use fluent_syntax::parser::ParserError;
11+
#[cfg(not(bootstrap))]
12+
use proc_macro::tracked::path;
13+
#[cfg(bootstrap)]
1114
use proc_macro::tracked_path::path;
1215
use proc_macro::{Diagnostic, Level, Span};
1316
use proc_macro2::TokenStream;

compiler/rustc_fluent_macro/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// tidy-alphabetical-start
22
#![allow(rustc::default_hash_types)]
3+
#![cfg_attr(bootstrap, feature(track_path))]
4+
#![cfg_attr(not(bootstrap), feature(proc_macro_tracked_path))]
35
#![feature(proc_macro_diagnostic)]
4-
#![feature(track_path)]
56
// tidy-alphabetical-end
67

78
use proc_macro::TokenStream;

compiler/rustc_macros/src/current_version.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ struct RustcVersion {
2222

2323
impl RustcVersion {
2424
fn parse_cfg_release(env_var: &str) -> Result<Self, Box<dyn std::error::Error>> {
25+
#[cfg(not(bootstrap))]
26+
let value = proc_macro::tracked::env_var(env_var)?;
27+
#[cfg(bootstrap)]
2528
let value = proc_macro::tracked_env::var(env_var)?;
29+
2630
Self::parse_str(&value)
2731
.ok_or_else(|| format!("failed to parse rustc version: {:?}", value).into())
2832
}

compiler/rustc_macros/src/symbols.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,13 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
259259
break;
260260
}
261261

262-
let value = match proc_macro::tracked_env::var(env_var.value()) {
262+
#[cfg(bootstrap)]
263+
let tracked_env = proc_macro::tracked_env::var(env_var.value());
264+
265+
#[cfg(not(bootstrap))]
266+
let tracked_env = proc_macro::tracked::env_var(env_var.value());
267+
268+
let value = match tracked_env {
263269
Ok(value) => value,
264270
Err(err) => {
265271
errors.list.push(syn::Error::new_spanned(expr, err));

compiler/rustc_mir_build/src/builder/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
839839
self.infcx.typing_env(self.param_env),
840840
);
841841

842+
// check if the function's return type is inhabited
843+
// this was added here because of this regression
844+
// https://github.com/rust-lang/rust/issues/149571
845+
let output_is_inhabited =
846+
if matches!(self.tcx.def_kind(self.def_id), DefKind::Fn | DefKind::AssocFn) {
847+
self.tcx
848+
.fn_sig(self.def_id)
849+
.instantiate_identity()
850+
.skip_binder()
851+
.output()
852+
.is_inhabited_from(
853+
self.tcx,
854+
self.parent_module,
855+
self.infcx.typing_env(self.param_env),
856+
)
857+
} else {
858+
true
859+
};
860+
842861
if !ty_is_inhabited {
843862
// Unreachable code warnings are already emitted during type checking.
844863
// However, during type checking, full type information is being
@@ -849,7 +868,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
849868
// uninhabited types (e.g. empty enums). The check above is used so
850869
// that we do not emit the same warning twice if the uninhabited type
851870
// is indeed `!`.
852-
if !ty.is_never() {
871+
if !ty.is_never() && output_is_inhabited {
853872
lints.push((target_bb, ty, term.source_info.span));
854873
}
855874

0 commit comments

Comments
 (0)