Skip to content

Rollup of 8 pull requests #137093

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 19 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3f09a20
Do not allow attributes on struct field rest patterns
Skepfyr Feb 3, 2025
0aa2e6b
Try to recover from path sep error in parser
chenyukang Feb 11, 2025
351cc1f
rustdoc: Properly restore search input placeholder
fmease Feb 15, 2025
3b4ff16
Clean up rustc_session::output::{find,validate}_crate_name
fmease Jul 10, 2024
46d53a6
Move `#![crate_type]` UI tests into attributes directory
fmease Jul 10, 2024
02f1f34
fix(rustdoc): Fixed `Copy Item Path` in rust doc
tapanprakasht Feb 15, 2025
e341261
Do not generate invalid links in job summaries
Kobzol Feb 15, 2025
f065a55
triagebot.toml: ping me on changes to `tests/rustdoc-json`
aDotInTheVoid Feb 15, 2025
880d8c0
compiletest: add `{ignore,only}-rustc_abi-x86-sse2` directives
jieyouxu Feb 15, 2025
d419da1
rustc-dev-guide: document `{ignore,only}-rustc_abi-x86-sse2`
jieyouxu Feb 15, 2025
9b6fd35
Reject macro calls inside of `#![crate_name]`
fmease Jul 10, 2024
522c8f7
Rollup merge of #127581 - fmease:fix-crate_name-validation, r=bjorn3
matthiaskrgr Feb 15, 2025
06b2f62
Rollup merge of #136490 - Skepfyr:no-field-rest-pattern-attrs, r=comp…
matthiaskrgr Feb 15, 2025
f06b75d
Rollup merge of #136808 - chenyukang:yukang-fix-arg-list-error-129273…
matthiaskrgr Feb 15, 2025
df7002f
Rollup merge of #137055 - fmease:rustdoc-js-fix-input-placeholder-log…
matthiaskrgr Feb 15, 2025
29e2caf
Rollup merge of #137068 - tapanprakasht:fix-copy-item-path, r=aDotInT…
matthiaskrgr Feb 15, 2025
6a7bff2
Rollup merge of #137070 - Kobzol:ci-summary-invalid-link, r=marcoieni
matthiaskrgr Feb 15, 2025
77ed54a
Rollup merge of #137074 - jieyouxu:rustc_abi, r=onur-ozkan
matthiaskrgr Feb 15, 2025
b3d5a77
Rollup merge of #137076 - aDotInTheVoid:pingme-pingme-pingme, r=jieyouxu
matthiaskrgr Feb 15, 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
10 changes: 5 additions & 5 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,12 @@ fn print_crate_info(
return Compilation::Continue;
};
let t_outputs = rustc_interface::util::build_output_filenames(attrs, sess);
let id = rustc_session::output::find_crate_name(sess, attrs);
let crate_name = passes::get_crate_name(sess, attrs);
let crate_types = collect_crate_types(sess, attrs);
for &style in &crate_types {
let fname =
rustc_session::output::filename_for_input(sess, style, id, &t_outputs);
let fname = rustc_session::output::filename_for_input(
sess, style, crate_name, &t_outputs,
);
println_info!("{}", fname.as_path().file_name().unwrap().to_string_lossy());
}
}
Expand All @@ -680,8 +681,7 @@ fn print_crate_info(
// no crate attributes, print out an error and exit
return Compilation::Continue;
};
let id = rustc_session::output::find_crate_name(sess, attrs);
println_info!("{id}");
println_info!("{}", passes::get_crate_name(sess, attrs));
}
Cfg => {
let mut cfgs = sess
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_expand/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ pub(crate) fn mod_file_path_from_attr(
let first_path = attrs.iter().find(|at| at.has_name(sym::path))?;
let Some(path_sym) = first_path.value_str() else {
// This check is here mainly to catch attempting to use a macro,
// such as #[path = concat!(...)]. This isn't currently supported
// because otherwise the InvocationCollector would need to defer
// loading a module until the #[path] attribute was expanded, and
// it doesn't support that (and would likely add a bit of
// complexity). Usually bad forms are checked in AstValidator (via
// `check_builtin_attribute`), but by the time that runs the macro
// such as `#[path = concat!(...)]`. This isn't supported because
// otherwise the `InvocationCollector` would need to defer loading
// a module until the `#[path]` attribute was expanded, and it
// doesn't support that (and would likely add a bit of complexity).
// Usually bad forms are checked during semantic analysis via
// `TyCtxt::check_mod_attrs`), but by the time that runs the macro
// is expanded, and it doesn't give an error.
validate_attr::emit_fatal_malformed_builtin_attribute(&sess.psess, first_path, sym::path);
};
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_incremental/src/persist/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ use rustc_data_structures::{base_n, flock};
use rustc_fs_util::{LinkOrCopy, link_or_copy, try_canonicalize};
use rustc_middle::bug;
use rustc_session::config::CrateType;
use rustc_session::output::{collect_crate_types, find_crate_name};
use rustc_session::output::collect_crate_types;
use rustc_session::{Session, StableCrateId};
use rustc_span::Symbol;
use tracing::debug;

use crate::errors;
Expand Down Expand Up @@ -211,7 +212,7 @@ pub fn in_incr_comp_dir(incr_comp_session_dir: &Path, file_name: &str) -> PathBu
/// The garbage collection will take care of it.
///
/// [`rustc_interface::queries::dep_graph`]: ../../rustc_interface/struct.Queries.html#structfield.dep_graph
pub(crate) fn prepare_session_directory(sess: &Session) {
pub(crate) fn prepare_session_directory(sess: &Session, crate_name: Symbol) {
if sess.opts.incremental.is_none() {
return;
}
Expand All @@ -221,7 +222,7 @@ pub(crate) fn prepare_session_directory(sess: &Session) {
debug!("prepare_session_directory");

// {incr-comp-dir}/{crate-name-and-disambiguator}
let crate_dir = crate_path(sess);
let crate_dir = crate_path(sess, crate_name);
debug!("crate-dir: {}", crate_dir.display());
create_dir(sess, &crate_dir, "crate");

Expand Down Expand Up @@ -594,10 +595,9 @@ fn string_to_timestamp(s: &str) -> Result<SystemTime, &'static str> {
Ok(UNIX_EPOCH + duration)
}

fn crate_path(sess: &Session) -> PathBuf {
fn crate_path(sess: &Session, crate_name: Symbol) -> PathBuf {
let incr_dir = sess.opts.incremental.as_ref().unwrap().clone();

let crate_name = find_crate_name(sess, &[]);
let crate_types = collect_crate_types(sess, &[]);
let stable_crate_id = StableCrateId::new(
crate_name,
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_incremental/src/persist/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_serialize::Decodable;
use rustc_serialize::opaque::MemDecoder;
use rustc_session::Session;
use rustc_session::config::IncrementalStateAssertion;
use rustc_span::Symbol;
use tracing::{debug, warn};

use super::data::*;
Expand Down Expand Up @@ -203,9 +204,9 @@ pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache> {

/// Setups the dependency graph by loading an existing graph from disk and set up streaming of a
/// new graph to an incremental session directory.
pub fn setup_dep_graph(sess: &Session) -> DepGraph {
pub fn setup_dep_graph(sess: &Session, crate_name: Symbol) -> DepGraph {
// `load_dep_graph` can only be called after `prepare_session_directory`.
prepare_session_directory(sess);
prepare_session_directory(sess, crate_name);

let res = sess.opts.build_dep_graph().then(|| load_dep_graph(sess));

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_interface/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ interface_abi_required_feature_issue = for more information, see issue #116344 <
interface_cant_emit_mir =
could not emit MIR: {$error}

interface_crate_name_does_not_match = `--crate-name` and `#[crate_name]` are required to match, but `{$crate_name}` != `{$attr_crate_name}`

interface_crate_name_invalid = crate names cannot start with a `-`, but `{$crate_name}` has a leading hyphen

interface_emoji_identifier =
identifiers cannot contain emoji: `{$ident}`

Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_interface/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ use std::path::Path;
use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol};

#[derive(Diagnostic)]
#[diag(interface_crate_name_does_not_match)]
pub(crate) struct CrateNameDoesNotMatch {
#[primary_span]
pub(crate) span: Span,
pub(crate) crate_name: Symbol,
pub(crate) attr_crate_name: Symbol,
}

#[derive(Diagnostic)]
#[diag(interface_crate_name_invalid)]
pub(crate) struct CrateNameInvalid<'a> {
pub(crate) crate_name: &'a str,
}

#[derive(Diagnostic)]
#[diag(interface_ferris_identifier)]
pub struct FerrisIdentifier {
Expand Down
105 changes: 84 additions & 21 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ use rustc_passes::{abi_test, input_stats, layout_test};
use rustc_resolve::Resolver;
use rustc_session::config::{CrateType, Input, OutFileName, OutputFilenames, OutputType};
use rustc_session::cstore::Untracked;
use rustc_session::output::{collect_crate_types, filename_for_input, find_crate_name};
use rustc_session::output::{collect_crate_types, filename_for_input};
use rustc_session::search_paths::PathKind;
use rustc_session::{Limit, Session};
use rustc_span::{ErrorGuaranteed, FileName, SourceFileHash, SourceFileHashAlgorithm, Symbol, sym};
use rustc_span::{
ErrorGuaranteed, FileName, SourceFileHash, SourceFileHashAlgorithm, Span, Symbol, sym,
};
use rustc_target::spec::PanicStrategy;
use rustc_trait_selection::traits;
use tracing::{info, instrument};
Expand Down Expand Up @@ -725,8 +727,7 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(

let pre_configured_attrs = rustc_expand::config::pre_configure_attrs(sess, &krate.attrs);

// parse `#[crate_name]` even if `--crate-name` was passed, to make sure it matches.
let crate_name = find_crate_name(sess, &pre_configured_attrs);
let crate_name = get_crate_name(sess, &pre_configured_attrs);
let crate_types = collect_crate_types(sess, &pre_configured_attrs);
let stable_crate_id = StableCrateId::new(
crate_name,
Expand All @@ -735,7 +736,7 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(
sess.cfg_version,
);
let outputs = util::build_output_filenames(&pre_configured_attrs, sess);
let dep_graph = setup_dep_graph(sess);
let dep_graph = setup_dep_graph(sess, crate_name);

let cstore =
FreezeLock::new(Box::new(CStore::new(compiler.codegen_backend.metadata_loader())) as _);
Expand Down Expand Up @@ -1080,23 +1081,85 @@ pub(crate) fn start_codegen<'tcx>(
codegen
}

fn get_recursion_limit(krate_attrs: &[ast::Attribute], sess: &Session) -> Limit {
if let Some(attr) = krate_attrs
.iter()
.find(|attr| attr.has_name(sym::recursion_limit) && attr.value_str().is_none())
/// Compute and validate the crate name.
pub fn get_crate_name(sess: &Session, krate_attrs: &[ast::Attribute]) -> Symbol {
// We validate *all* occurrences of `#![crate_name]`, pick the first find and
// if a crate name was passed on the command line via `--crate-name` we enforce
// that they match.
// We perform the validation step here instead of later to ensure it gets run
// in all code paths that require the crate name very early on, namely before
// macro expansion.

let attr_crate_name =
validate_and_find_value_str_builtin_attr(sym::crate_name, sess, krate_attrs);

let validate = |name, span| {
rustc_session::output::validate_crate_name(sess, name, span);
name
};

if let Some(crate_name) = &sess.opts.crate_name {
let crate_name = Symbol::intern(crate_name);
if let Some((attr_crate_name, span)) = attr_crate_name
&& attr_crate_name != crate_name
{
sess.dcx().emit_err(errors::CrateNameDoesNotMatch {
span,
crate_name,
attr_crate_name,
});
}
return validate(crate_name, None);
}

if let Some((crate_name, span)) = attr_crate_name {
return validate(crate_name, Some(span));
}

if let Input::File(ref path) = sess.io.input
&& let Some(file_stem) = path.file_stem().and_then(|s| s.to_str())
{
// This is here mainly to check for using a macro, such as
// #![recursion_limit = foo!()]. That is not supported since that
// would require expanding this while in the middle of expansion,
// which needs to know the limit before expanding. Otherwise,
// validation would normally be caught in AstValidator (via
// `check_builtin_attribute`), but by the time that runs the macro
// is expanded, and it doesn't give an error.
validate_attr::emit_fatal_malformed_builtin_attribute(
&sess.psess,
attr,
sym::recursion_limit,
);
if file_stem.starts_with('-') {
sess.dcx().emit_err(errors::CrateNameInvalid { crate_name: file_stem });
} else {
return validate(Symbol::intern(&file_stem.replace('-', "_")), None);
}
}

sym::rust_out
}

fn get_recursion_limit(krate_attrs: &[ast::Attribute], sess: &Session) -> Limit {
// We don't permit macro calls inside of the attribute (e.g., #![recursion_limit = `expand!()`])
// because that would require expanding this while in the middle of expansion, which needs to
// know the limit before expanding.
let _ = validate_and_find_value_str_builtin_attr(sym::recursion_limit, sess, krate_attrs);
rustc_middle::middle::limits::get_recursion_limit(krate_attrs, sess)
}

/// Validate *all* occurrences of the given "[value-str]" built-in attribute and return the first find.
///
/// This validator is intended for built-in attributes whose value needs to be known very early
/// during compilation (namely, before macro expansion) and it mainly exists to reject macro calls
/// inside of the attributes, such as in `#![name = expand!()]`. Normal attribute validation happens
/// during semantic analysis via [`TyCtxt::check_mod_attrs`] which happens *after* macro expansion
/// when such macro calls (here: `expand`) have already been expanded and we can no longer check for
/// their presence.
///
/// [value-str]: ast::Attribute::value_str
fn validate_and_find_value_str_builtin_attr(
name: Symbol,
sess: &Session,
krate_attrs: &[ast::Attribute],
) -> Option<(Symbol, Span)> {
let mut result = None;
// Validate *all* relevant attributes, not just the first occurrence.
for attr in ast::attr::filter_by_name(krate_attrs, name) {
let Some(value) = attr.value_str() else {
validate_attr::emit_fatal_malformed_builtin_attribute(&sess.psess, attr, name)
};
// Choose the first occurrence as our result.
result.get_or_insert((value, attr.span));
}
result
}
6 changes: 3 additions & 3 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,11 @@ pub(crate) fn check_attr_crate_type(
}
} else {
// This is here mainly to check for using a macro, such as
// #![crate_type = foo!()]. That is not supported since the
// `#![crate_type = foo!()]`. That is not supported since the
// crate type needs to be known very early in compilation long
// before expansion. Otherwise, validation would normally be
// caught in AstValidator (via `check_builtin_attribute`), but
// by the time that runs the macro is expanded, and it doesn't
// caught during semantic analysis via `TyCtxt::check_mod_attrs`,
// but by the time that runs the macro is expanded, and it doesn't
// give an error.
validate_attr::emit_fatal_malformed_builtin_attribute(
&sess.psess,
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -743,9 +743,6 @@ parse_single_colon_import_path = expected `::`, found `:`
.suggestion = use double colon
.note = import paths are delimited using `::`

parse_single_colon_struct_type = found single colon in a struct field type path
.suggestion = write a path separator here

parse_static_with_generics = static items may not have generic parameters

parse_struct_literal_body_without_path =
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3071,14 +3071,6 @@ pub(crate) struct BadItemKind {
pub help: bool,
}

#[derive(Diagnostic)]
#[diag(parse_single_colon_struct_type)]
pub(crate) struct SingleColonStructType {
#[primary_span]
#[suggestion(code = "::", applicability = "maybe-incorrect", style = "verbose")]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(parse_macro_rules_missing_bang)]
pub(crate) struct MacroRulesMissingBang {
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2043,9 +2043,6 @@ impl<'a> Parser<'a> {
}
self.expect_field_ty_separator()?;
let ty = self.parse_ty()?;
if self.token == token::Colon && self.look_ahead(1, |t| *t != token::Colon) {
self.dcx().emit_err(errors::SingleColonStructType { span: self.token.span });
}
let default = if self.token == token::Eq {
self.bump();
let const_expr = self.parse_expr_anon_const()?;
Expand Down
22 changes: 11 additions & 11 deletions compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1472,17 +1472,6 @@ impl<'a> Parser<'a> {
let mut last_non_comma_dotdot_span = None;

while self.token != token::CloseDelim(Delimiter::Brace) {
let attrs = match self.parse_outer_attributes() {
Ok(attrs) => attrs,
Err(err) => {
if let Some(delayed) = delayed_err {
delayed.emit();
}
return Err(err);
}
};
let lo = self.token.span;

// check that a comma comes after every field
if !ate_comma {
let err = if self.token == token::At {
Expand Down Expand Up @@ -1585,6 +1574,17 @@ impl<'a> Parser<'a> {
}
}

let attrs = match self.parse_outer_attributes() {
Ok(attrs) => attrs,
Err(err) => {
if let Some(delayed) = delayed_err {
delayed.emit();
}
return Err(err);
}
};
let lo = self.token.span;

let field = self.collect_tokens(None, attrs, ForceCollect::No, |this, attrs| {
let field = match this.parse_pat_field(lo, attrs) {
Ok(field) => Ok(field),
Expand Down
15 changes: 13 additions & 2 deletions compiler/rustc_parse/src/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,19 @@ impl<'a> Parser<'a> {
segments.push(segment);

if self.is_import_coupler() || !self.eat_path_sep() {
if style == PathStyle::Expr
&& self.may_recover()
let ok_for_recovery = self.may_recover()
&& match style {
PathStyle::Expr => true,
PathStyle::Type if let Some((ident, _)) = self.prev_token.ident() => {
self.token == token::Colon
&& ident.as_str().chars().all(|c| c.is_lowercase())
&& self.token.span.lo() == self.prev_token.span.hi()
&& self
.look_ahead(1, |token| self.token.span.hi() == token.span.lo())
}
_ => false,
};
if ok_for_recovery
&& self.token == token::Colon
&& self.look_ahead(1, |token| token.is_ident() && !token.is_reserved_ident())
{
Expand Down
Loading
Loading