Skip to content

Rollup of 9 pull requests #139781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
22dd86c
Encode dep node edge count as u32 instead of usize
Zoxc Apr 6, 2025
923f44c
consistent name for `UniversalRegions`
lcnr Apr 11, 2025
8cb7274
use input `def_id` to compute `movable_coroutine`
lcnr Apr 11, 2025
848187c
`local_names` creation to `mbcx` creation
lcnr Apr 11, 2025
0186459
do not buffer `#[rustc_regions]` dump
lcnr Apr 11, 2025
0e294f2
`MirBorrowckCtxt::polonius_output` to ref
lcnr Apr 11, 2025
2c65469
move `dump_polonius_mir`
lcnr Apr 11, 2025
c5fdddc
don't rely on `locals_are_invalidated_at_exit`
lcnr Apr 11, 2025
8303383
remove redundant fields
lcnr Apr 11, 2025
5d00483
`NonGenericOpaqueTypeParam::ty` to `arg`
lcnr Apr 11, 2025
420390c
eagerly initialize `definitions` in sub-fn
lcnr Apr 11, 2025
bc94c38
Proactively update coroutine drop shim's phase to account for later p…
compiler-errors Apr 12, 2025
accae53
Move FlagComputation, PatternKind, and TypeWalker to rustc_type_ir
jackh726 Apr 8, 2025
f472cc8
error on unsafe attributes in pre-2024 editions
folkertdev Apr 12, 2025
b203d40
compiletest: add `camino` for UTF-8 path handling
jieyouxu Apr 11, 2025
e24b0c8
compiletest: consistently use `{Utf8Path,Utf8PathBuf}`
jieyouxu Apr 11, 2025
957324b
rustdoc-gui-test: pass a `camino::Utf8PathBuf` to `compiletest`
jieyouxu Apr 12, 2025
93bee07
UI tests: migrate remaining compile time `error-pattern`s to line ann…
petrochenkov Apr 12, 2025
d50a8d5
Improve `-Z crate-attr` diagnostics
jyn514 Mar 11, 2025
3efd9f5
Switch to `diagnostic::on_unimplemented`
mejrs Apr 13, 2025
2b6835b
Rollup merge of #138336 - jyn514:crate-attr-diagnostics, r=compiler-e…
jhpratt Apr 14, 2025
5c494aa
Rollup merge of #139636 - Zoxc:graph-edges-len-u32, r=compiler-errors
jhpratt Apr 14, 2025
a642232
Rollup merge of #139666 - lcnr:pre-revealing-use-cleanup, r=compiler-…
jhpratt Apr 14, 2025
6fe6985
Rollup merge of #139695 - jieyouxu:compiletest-utf8path, r=Kobzol
jhpratt Apr 14, 2025
c0ad72e
Rollup merge of #139699 - compiler-errors:coroutine-drop-phase, r=sco…
jhpratt Apr 14, 2025
4a1d0cd
Rollup merge of #139718 - folkertdev:unsafe-attributes-earlier-editio…
jhpratt Apr 14, 2025
bb93324
Rollup merge of #139722 - jackh726:patternkind-walk-toir, r=compiler-…
jhpratt Apr 14, 2025
883c8dd
Rollup merge of #139760 - petrochenkov:noerrpat2, r=jieyouxu
jhpratt Apr 14, 2025
b06f38c
Rollup merge of #139776 - mejrs:diagn2, r=compiler-errors
jhpratt Apr 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ pub fn mk_doc_comment(
Attribute { kind: AttrKind::DocComment(comment_kind, data), id: g.mk_attr_id(), style, span }
}

pub fn mk_attr(
fn mk_attr(
g: &AttrIdGenerator,
style: AttrStyle,
unsafety: Safety,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_builtin_macros/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ builtin_macros_format_unused_args = multiple unused formatting arguments

builtin_macros_format_use_positional = consider using a positional formatting argument instead

builtin_macros_invalid_crate_attribute = invalid crate attribute

builtin_macros_multiple_default_attrs = multiple `#[default]` attributes
.note = only one `#[default]` attribute is needed
.label = `#[default]` used here
Expand Down
57 changes: 25 additions & 32 deletions compiler/rustc_builtin_macros/src/cmdline_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
//! Attributes injected into the crate root from command line using `-Z crate-attr`.

use rustc_ast::attr::mk_attr;
use rustc_ast::{self as ast, AttrItem, AttrStyle, token};
use rustc_parse::parser::ForceCollect;
use rustc_parse::{new_parser_from_source_str, unwrap_or_emit_fatal};
use rustc_ast::{self as ast};
use rustc_errors::Diag;
use rustc_parse::parser::attr::InnerAttrPolicy;
use rustc_parse::{parse_in, source_str_to_stream};
use rustc_session::parse::ParseSess;
use rustc_span::FileName;

use crate::errors;

pub fn inject(krate: &mut ast::Crate, psess: &ParseSess, attrs: &[String]) {
for raw_attr in attrs {
let mut parser = unwrap_or_emit_fatal(new_parser_from_source_str(
psess,
FileName::cli_crate_attr_source_code(raw_attr),
raw_attr.clone(),
));

let start_span = parser.token.span;
let AttrItem { unsafety, path, args, tokens: _ } =
match parser.parse_attr_item(ForceCollect::No) {
Ok(ai) => ai,
Err(err) => {
let source = format!("#![{raw_attr}]");
let parse = || -> Result<ast::Attribute, Vec<Diag<'_>>> {
let tokens = source_str_to_stream(
psess,
FileName::cli_crate_attr_source_code(raw_attr),
source,
None,
)?;
parse_in(psess, tokens, "<crate attribute>", |p| {
p.parse_attribute(InnerAttrPolicy::Permitted)
})
.map_err(|e| vec![e])
};
let meta = match parse() {
Ok(meta) => meta,
Err(errs) => {
for err in errs {
err.emit();
continue;
}
};
let end_span = parser.token.span;
if parser.token != token::Eof {
psess.dcx().emit_err(errors::InvalidCrateAttr { span: start_span.to(end_span) });
continue;
}
continue;
}
};

krate.attrs.push(mk_attr(
&psess.attr_id_generator,
AttrStyle::Inner,
unsafety,
path,
args,
start_span.to(end_span),
));
krate.attrs.push(meta);
}
}
7 changes: 0 additions & 7 deletions compiler/rustc_builtin_macros/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@ pub(crate) struct ProcMacro {
pub(crate) span: Span,
}

#[derive(Diagnostic)]
#[diag(builtin_macros_invalid_crate_attribute)]
pub(crate) struct InvalidCrateAttr {
#[primary_span]
pub(crate) span: Span,
}

#[derive(Diagnostic)]
#[diag(builtin_macros_non_abi)]
pub(crate) struct NonABI {
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/attributes/z-crate-attr/garbage.stderr
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
error: unknown start of token: `
--> <crate attribute>:1:1
--> <crate attribute>:1:4
|
LL | `%~@$#
| ^
LL | #![`%~@$#]
| ^
|
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
|
LL - `%~@$#
LL + '%~@$#
LL - #![`%~@$#]
LL + #!['%~@$#]
|

error: expected identifier, found `%`
--> <crate attribute>:1:2
--> <crate attribute>:1:5
|
LL | `%~@$#
| ^ expected identifier
LL | #![`%~@$#]
| ^ expected identifier

error: aborting due to 2 previous errors

6 changes: 2 additions & 4 deletions tests/ui/attributes/z-crate-attr/injection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ compile-flags: '-Zcrate-attr=feature(yeet_expr)]fn main(){}#[inline'

fn foo() {}

//~? ERROR unexpected closing delimiter: `]`
//~? ERROR unexpected token
fn foo() {} //~ ERROR `main` function not found
17 changes: 12 additions & 5 deletions tests/ui/attributes/z-crate-attr/injection.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
error: unexpected closing delimiter: `]`
--> <crate attribute>:1:19
error: unexpected token: keyword `fn`
--> <crate attribute>:1:23
|
LL | feature(yeet_expr)]fn main(){}#[inline
| ^ unexpected closing delimiter
LL | #![feature(yeet_expr)]fn main(){}#[inline]
| ^^ unexpected token after this

error: aborting due to 1 previous error
error[E0601]: `main` function not found in crate `injection`
--> $DIR/injection.rs:3:12
|
LL | fn foo() {}
| ^ consider adding a `main` function to `$DIR/injection.rs`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0601`.
3 changes: 3 additions & 0 deletions tests/ui/attributes/z-crate-attr/injection2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//@ compile-flags: -Zcrate-attr=feature(yeet_expr)]#![allow(warnings)
//~? ERROR unexpected token
fn foo() {} //~ ERROR `main` function not found
15 changes: 15 additions & 0 deletions tests/ui/attributes/z-crate-attr/injection2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: unexpected token: `#`
--> <crate attribute>:1:23
|
LL | #![feature(yeet_expr)]#![allow(warnings)]
| ^ unexpected token after this

error[E0601]: `main` function not found in crate `injection2`
--> $DIR/injection2.rs:3:12
|
LL | fn foo() {}
| ^ consider adding a `main` function to `$DIR/injection2.rs`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0601`.
6 changes: 3 additions & 3 deletions tests/ui/attributes/z-crate-attr/inner-attr.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected identifier, found `#`
--> <crate attribute>:1:1
--> <crate attribute>:1:4
|
LL | #![feature(foo)]
| ^ expected identifier
LL | #![#![feature(foo)]]
| ^ expected identifier

error: aborting due to 1 previous error

4 changes: 1 addition & 3 deletions tests/ui/attributes/z-crate-attr/multiple.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ compile-flags: -Zcrate-attr=feature(foo),feature(bar)

//~? ERROR expected `]`
fn main() {}

//~? ERROR invalid crate attribute
8 changes: 4 additions & 4 deletions tests/ui/attributes/z-crate-attr/multiple.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: invalid crate attribute
--> <crate attribute>:1:1
error: expected `]`, found `,`
--> <crate attribute>:1:16
|
LL | feature(foo),feature(bar)
| ^^^^^^^^^^^^^
LL | #![feature(foo),feature(bar)]
| ^ expected `]`

error: aborting due to 1 previous error

4 changes: 1 addition & 3 deletions tests/ui/attributes/z-crate-attr/unbalanced-paren.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Show diagnostics for unbalanced parens.
//@ compile-flags: -Zcrate-attr=(

//~? ERROR mismatched closing delimiter
fn main() {}

//~? ERROR this file contains an unclosed delimiter
13 changes: 7 additions & 6 deletions tests/ui/attributes/z-crate-attr/unbalanced-paren.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
error: this file contains an unclosed delimiter
--> <crate attribute>:1:2
error: mismatched closing delimiter: `]`
--> <crate attribute>:1:4
|
LL | (
| -^
| |
| unclosed delimiter
LL | #![(]
| -^^ mismatched closing delimiter
| ||
| |unclosed delimiter
| closing delimiter possibly meant for this

error: aborting due to 1 previous error