Skip to content

Rollup of 10 pull requests #142750

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

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
32cb8f1
Add trim_prefix and trim_suffix for slice and str.
deven Jun 11, 2025
067a99b
install docs for each target in different directory
Forist2034 Jun 13, 2025
71afc6f
Add test.
cjgillot Jun 16, 2025
c4b67c6
Reason about borrowed classes in CopyProp.
cjgillot Jun 16, 2025
b391494
add ChildExt(::send_signal)
Qelxiros Jun 18, 2025
b64fd13
convert the `optimize` attribute to a new parser
jdonszelmann Mar 9, 2025
5bd918f
vec_deque tests: remove static mut
hkBst Jun 18, 2025
3c418ec
bump rustdoc json format number for pretty print change of attribute
jdonszelmann Jun 18, 2025
021bcb9
fmt tests: remove static mut
hkBst Jun 18, 2025
c6e77b3
Reduce uses of `hir_crate`.
cjgillot Jun 18, 2025
7fa94af
Make feature suggestion more consistent.
cjgillot Jun 18, 2025
95cd989
expand: Remove some unnecessary generic parameters
petrochenkov Jun 18, 2025
f45ab4f
Update books
rustbot Jun 19, 2025
7760f8e
add comment to `src/bootstrap/build.rs`
fee1-dead Jun 19, 2025
ede4891
Update compiler/rustc_interface/src/passes.rs
cjgillot Jun 19, 2025
ecdf220
vec tests: remove static mut
hkBst Jun 19, 2025
456c9da
vec_deque alloctests: remove static mut
hkBst Jun 19, 2025
9c22768
atomic tests: remove static mut
hkBst Jun 19, 2025
6c3cf25
Rollup merge of #138291 - jdonszelmann:optimize-attr, r=oli-obk
jhpratt Jun 19, 2025
ec293fd
Rollup merge of #141990 - Qelxiros:141975-unix_send_signal, r=ChrisDe…
jhpratt Jun 19, 2025
ae2b09e
Rollup merge of #142331 - deven:trim_prefix_suffix, r=Amanieu
jhpratt Jun 19, 2025
aa370b5
Rollup merge of #142478 - Forist2034:master, r=clubby789
jhpratt Jun 19, 2025
b8e28b7
Rollup merge of #142571 - cjgillot:borrowed-classes, r=oli-obk
jhpratt Jun 19, 2025
2d582ad
Rollup merge of #142668 - hkBst:less-static-mut, r=tgross35
jhpratt Jun 19, 2025
433ead3
Rollup merge of #142687 - cjgillot:less-hir_crate, r=oli-obk
jhpratt Jun 19, 2025
ce4a04c
Rollup merge of #142690 - petrochenkov:expnoparam, r=compiler-errors
jhpratt Jun 19, 2025
ed57a53
Rollup merge of #142699 - rustbot:docs-update, r=ehuss
jhpratt Jun 19, 2025
1f9b14b
Rollup merge of #142714 - fee1-dead-contrib:push-roxtwrlvtzur, r=Kobzol
jhpratt Jun 19, 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
6 changes: 4 additions & 2 deletions compiler/rustc_attr_data_structures/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ pub enum InstructionSetAttr {
ArmT32,
}

#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable_Generic, Default)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default, PrintAttribute)]
#[derive(Encodable, Decodable, HashStable_Generic)]
pub enum OptimizeAttr {
/// No `#[optimize(..)]` attribute
#[default]
Expand Down Expand Up @@ -229,7 +230,8 @@ pub enum AttributeKind {

/// Represents `#[rustc_macro_transparency]`.
MacroTransparency(Transparency),

/// Represents `#[optimize(size|speed)]`
Optimize(OptimizeAttr, Span),
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
Repr(ThinVec<(ReprAttr, Span)>),

Expand Down
40 changes: 40 additions & 0 deletions compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use rustc_attr_data_structures::{AttributeKind, OptimizeAttr};
use rustc_feature::{AttributeTemplate, template};
use rustc_span::sym;

use super::{AttributeOrder, OnDuplicate, SingleAttributeParser};
use crate::context::{AcceptContext, Stage};
use crate::parser::ArgParser;

pub(crate) struct OptimizeParser;

impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
const PATH: &[rustc_span::Symbol] = &[sym::optimize];
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
const TEMPLATE: AttributeTemplate = template!(List: "size|speed|none");

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
let Some(list) = args.list() else {
cx.expected_list(cx.attr_span);
return None;
};

let Some(single) = list.single() else {
cx.expected_single_argument(list.span);
return None;
};

let res = match single.meta_item().and_then(|i| i.path().word().map(|i| i.name)) {
Some(sym::size) => OptimizeAttr::Size,
Some(sym::speed) => OptimizeAttr::Speed,
Some(sym::none) => OptimizeAttr::DoNotOptimize,
_ => {
cx.expected_specific_argument(single.span(), vec!["size", "speed", "none"]);
OptimizeAttr::Default
}
};

Some(AttributeKind::Optimize(res, cx.attr_span))
}
}
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::session_diagnostics::UnusedMultiple;

pub(crate) mod allow_unstable;
pub(crate) mod cfg;
pub(crate) mod codegen_attrs;
pub(crate) mod confusables;
pub(crate) mod deprecation;
pub(crate) mod inline;
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rustc_session::Session;
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};

use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
use crate::attributes::codegen_attrs::OptimizeParser;
use crate::attributes::confusables::ConfusablesParser;
use crate::attributes::deprecation::DeprecationParser;
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
Expand Down Expand Up @@ -108,6 +109,7 @@ attribute_parsers!(
Single<ConstStabilityIndirectParser>,
Single<DeprecationParser>,
Single<InlineParser>,
Single<OptimizeParser>,
Single<RustcForceInlineParser>,
Single<TransparencyParser>,
// tidy-alphabetical-end
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_codegen_ssa/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ codegen_ssa_error_writing_def_file =
codegen_ssa_expected_name_value_pair = expected name value pair
codegen_ssa_expected_one_argument = expected one argument
codegen_ssa_expected_used_symbol = expected `used`, `used(compiler)` or `used(linker)`
codegen_ssa_extern_funcs_not_found = some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
Expand Down Expand Up @@ -86,9 +84,6 @@ codegen_ssa_incorrect_cgu_reuse_type =
codegen_ssa_insufficient_vs_code_product = VS Code is a different product, and is not sufficient.
codegen_ssa_invalid_argument = invalid argument
.help = valid inline arguments are `always` and `never`
codegen_ssa_invalid_instruction_set = invalid instruction set specified
codegen_ssa_invalid_link_ordinal_nargs = incorrect number of arguments to `#[link_ordinal]`
Expand Down
29 changes: 2 additions & 27 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,33 +455,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
codegen_fn_attrs.inline = InlineAttr::Never;
}

codegen_fn_attrs.optimize = attrs.iter().fold(OptimizeAttr::Default, |ia, attr| {
if !attr.has_name(sym::optimize) {
return ia;
}
if attr.is_word() {
tcx.dcx().emit_err(errors::ExpectedOneArgumentOptimize { span: attr.span() });
return ia;
}
let Some(ref items) = attr.meta_item_list() else {
return OptimizeAttr::Default;
};

let [item] = &items[..] else {
tcx.dcx().emit_err(errors::ExpectedOneArgumentOptimize { span: attr.span() });
return OptimizeAttr::Default;
};
if item.has_name(sym::size) {
OptimizeAttr::Size
} else if item.has_name(sym::speed) {
OptimizeAttr::Speed
} else if item.has_name(sym::none) {
OptimizeAttr::DoNotOptimize
} else {
tcx.dcx().emit_err(errors::InvalidArgumentOptimize { span: item.span() });
OptimizeAttr::Default
}
});
codegen_fn_attrs.optimize =
find_attr!(attrs, AttributeKind::Optimize(i, _) => *i).unwrap_or(OptimizeAttr::Default);

// #73631: closures inherit `#[target_feature]` annotations
//
Expand Down
14 changes: 0 additions & 14 deletions compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,6 @@ pub(crate) struct OutOfRangeInteger {
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(codegen_ssa_expected_one_argument, code = E0722)]
pub(crate) struct ExpectedOneArgumentOptimize {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(codegen_ssa_invalid_argument, code = E0722)]
pub(crate) struct InvalidArgumentOptimize {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(codegen_ssa_copy_path_buf)]
pub(crate) struct CopyPathBuf {
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_const_eval/src/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,6 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
);
}

fn crate_inject_span(&self) -> Option<Span> {
self.tcx.hir_crate_items(()).definitions().next().and_then(|id| {
self.tcx.crate_level_attribute_injection_span(self.tcx.local_def_id_to_hir_id(id))
})
}

/// Check the const stability of the given item (fn or trait).
fn check_callee_stability(&mut self, def_id: DefId) {
match self.tcx.lookup_const_stability(def_id) {
Expand Down Expand Up @@ -543,7 +537,6 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
feature,
feature_enabled,
safe_to_expose_on_stable: callee_safe_to_expose_on_stable,
suggestion_span: self.crate_inject_span(),
is_function_call: self.tcx.def_kind(def_id) != DefKind::Trait,
});
}
Expand Down Expand Up @@ -919,7 +912,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
name: intrinsic.name,
feature,
const_stable_indirect: is_const_stable,
suggestion: self.crate_inject_span(),
});
}
Some(attrs::ConstStability {
Expand Down
22 changes: 3 additions & 19 deletions compiler/rustc_const_eval/src/check_consts/ops.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Concrete error types for all operations which may be invalid in a certain const context.
use hir::{ConstContext, LangItem};
use rustc_errors::Diag;
use rustc_errors::codes::*;
use rustc_errors::{Applicability, Diag};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_infer::infer::TyCtxtInferExt;
Expand Down Expand Up @@ -384,7 +384,6 @@ pub(crate) struct CallUnstable {
/// expose on stable.
pub feature_enabled: bool,
pub safe_to_expose_on_stable: bool,
pub suggestion_span: Option<Span>,
/// true if `def_id` is the function we are calling, false if `def_id` is an unstable trait.
pub is_function_call: bool,
}
Expand Down Expand Up @@ -412,20 +411,7 @@ impl<'tcx> NonConstOp<'tcx> for CallUnstable {
def_path: ccx.tcx.def_path_str(self.def_id),
})
};
// FIXME: make this translatable
let msg = format!("add `#![feature({})]` to the crate attributes to enable", self.feature);
#[allow(rustc::untranslatable_diagnostic)]
if let Some(span) = self.suggestion_span {
err.span_suggestion_verbose(
span,
msg,
format!("#![feature({})]\n", self.feature),
Applicability::MachineApplicable,
);
} else {
err.help(msg);
}

ccx.tcx.disabled_nightly_features(&mut err, [(String::new(), self.feature)]);
err
}
}
Expand All @@ -452,7 +438,6 @@ pub(crate) struct IntrinsicUnstable {
pub name: Symbol,
pub feature: Symbol,
pub const_stable_indirect: bool,
pub suggestion: Option<Span>,
}

impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
Expand All @@ -472,8 +457,7 @@ impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
span,
name: self.name,
feature: self.feature,
suggestion: self.suggestion,
help: self.suggestion.is_none(),
suggestion: ccx.tcx.crate_level_attribute_injection_span(),
})
}
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ pub(crate) struct UnstableIntrinsic {
code = "#![feature({feature})]\n",
applicability = "machine-applicable"
)]
pub suggestion: Option<Span>,
#[help(const_eval_unstable_intrinsic_suggestion)]
pub help: bool,
pub suggestion: Span,
}

#[derive(Diagnostic)]
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_driver_impl/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,11 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
}
HirTree => {
debug!("pretty printing HIR tree");
format!("{:#?}", ex.tcx().hir_crate(()))
ex.tcx()
.hir_crate_items(())
.owners()
.map(|owner| format!("{:#?} => {:#?}\n", owner, ex.tcx().hir_owner_nodes(owner)))
.collect()
}
Mir => {
let mut out = Vec::new();
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0722.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#### Note: this error code is no longer emitted by the compiler

This is because it was too specific to the `optimize` attribute.
Similar diagnostics occur for other attributes too.
The example here will now emit `E0539`

The `optimize` attribute was malformed.

Erroneous code example:

```compile_fail,E0722
```compile_fail,E0539
#![feature(optimize_attribute)]
#[optimize(something)] // error: invalid argument
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ E0805: 0805,
// E0707, // multiple elided lifetimes used in arguments of `async fn`
// E0709, // multiple different lifetimes used in arguments of `async fn`
// E0721, // `await` keyword
// E0722, // replaced with a generic attribute input check
// E0723, // unstable feature in `const` context
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
// E0744, // merged into E0728
Expand Down
Loading
Loading