Skip to content

Rollup of 11 pull requests #144038

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 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
803b4d2
core: Remove `BorrowedCursor::init_ref` method
a1phyr Jul 9, 2025
34555f1
core: Remove `BorrowedCursor::uninit_mut`
a1phyr Jul 9, 2025
65df668
core: Change `BorrowedCursor::written`'s origin
a1phyr Jul 9, 2025
81a6f18
added error for invalid char cast
Kivooeo Jul 9, 2025
28af500
Opaque type collection: Guard against endlessly recursing free alias …
fmease Jul 11, 2025
5d7db7e
Fixed a core crate compilation failure when enabling the `optimize_fo…
nazo6 Jul 12, 2025
5530744
Reword mismatched-lifetime-syntaxes text based on feedback
shepmaster Jul 10, 2025
4a77a62
rustc_resolve: rename `check_hidden_glob_reexports` to `lint_reexports`
mladedav Jul 15, 2025
8b868fa
Implement resolver warnings about reexporting private dependencies
mladedav Jul 12, 2025
d627e25
make `std_detect` public dependency of `std`
mladedav Jul 12, 2025
e7f5bbe
remove description from rust toml struct
Shourya742 Jul 14, 2025
76967af
remove ccache from llvm
Shourya742 Jul 14, 2025
3f2dc2b
add `const_make_global`; err for `const_allocate` ptrs if didn't call
fee1-dead Jul 7, 2025
44b38ca
format pointer later instead of eagerly converting to string
fee1-dead Jul 10, 2025
306928f
update change tracking with warning on removal of fields.
Shourya742 Jul 14, 2025
fd48b7b
Comment more code and make tests clearer
fee1-dead Jul 13, 2025
5bfb50b
Improve path segment joining.
nnethercote May 27, 2025
6f427b3
Use `join_path_syms` in one more place.
nnethercote Jun 20, 2025
42ec028
type_id_eq: check that the hash fully matches the type
RalfJung Jul 15, 2025
8f854d9
const heap: fix ICE on forgotten make_global
RalfJung Jul 16, 2025
0bf0860
simplfy memory kind handling during interning
RalfJung Jul 16, 2025
4e054fc
Port `#[coverage]` to the new attribute system
scrabsha Jul 13, 2025
198df9e
Rollup merge of #143595 - fee1-dead-contrib:push-sylpykzkmynr, r=Ralf…
matthiaskrgr Jul 16, 2025
b983433
Rollup merge of #143678 - Kivooeo:char-overflow, r=SparrowLii
matthiaskrgr Jul 16, 2025
f030a55
Rollup merge of #143793 - fmease:lta-opaq-inf-recur, r=oli-obk
matthiaskrgr Jul 16, 2025
2980c8d
Rollup merge of #143820 - nazo6:fix-optimize-for-size, r=Mark-Simulacrum
matthiaskrgr Jul 16, 2025
eb818f2
Rollup merge of #143829 - a1phyr:trim_borrowed_buf, r=ChrisDenton
matthiaskrgr Jul 16, 2025
0e8dab2
Rollup merge of #143856 - mladedav:dm/private-reexport, r=petrochenkov
matthiaskrgr Jul 16, 2025
acc0eb1
Rollup merge of #143891 - scrabsha:push-xxtttopqoprr, r=jdonszelmann
matthiaskrgr Jul 16, 2025
78b7c92
Rollup merge of #143914 - shepmaster:mismatched-lifetime-syntaxes-rew…
matthiaskrgr Jul 16, 2025
dbfd286
Rollup merge of #143922 - nnethercote:join_path, r=petrochenkov
matthiaskrgr Jul 16, 2025
24b69d8
Rollup merge of #143926 - Shourya742:2025-07-14-remove-deprecated-fie…
matthiaskrgr Jul 16, 2025
3140424
Rollup merge of #143975 - RalfJung:type-id-eq, r=oli-obk
matthiaskrgr Jul 16, 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
53 changes: 52 additions & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! - [`Attribute`]: Metadata associated with item.
//! - [`UnOp`], [`BinOp`], and [`BinOpKind`]: Unary and binary operators.

use std::borrow::Cow;
use std::borrow::{Borrow, Cow};
use std::{cmp, fmt};

pub use GenericArgs::*;
Expand Down Expand Up @@ -155,6 +155,57 @@ impl Path {
}
}

/// Joins multiple symbols with "::" into a path, e.g. "a::b::c". If the first
/// segment is `kw::PathRoot` it will be printed as empty, e.g. "::b::c".
///
/// The generics on the `path` argument mean it can accept many forms, such as:
/// - `&[Symbol]`
/// - `Vec<Symbol>`
/// - `Vec<&Symbol>`
/// - `impl Iterator<Item = Symbol>`
/// - `impl Iterator<Item = &Symbol>`
///
/// Panics if `path` is empty or a segment after the first is `kw::PathRoot`.
pub fn join_path_syms(path: impl IntoIterator<Item = impl Borrow<Symbol>>) -> String {
// This is a guess at the needed capacity that works well in practice. It is slightly faster
// than (a) starting with an empty string, or (b) computing the exact capacity required.
let mut iter = path.into_iter();
let len_hint = iter.size_hint().1.unwrap_or(1);
let mut s = String::with_capacity(len_hint * 8);

let first_sym = *iter.next().unwrap().borrow();
if first_sym != kw::PathRoot {
s.push_str(first_sym.as_str());
}
for sym in iter {
let sym = *sym.borrow();
debug_assert_ne!(sym, kw::PathRoot);
s.push_str("::");
s.push_str(sym.as_str());
}
s
}

/// Like `join_path_syms`, but for `Ident`s. This function is necessary because
/// `Ident::to_string` does more than just print the symbol in the `name` field.
pub fn join_path_idents(path: impl IntoIterator<Item = impl Borrow<Ident>>) -> String {
let mut iter = path.into_iter();
let len_hint = iter.size_hint().1.unwrap_or(1);
let mut s = String::with_capacity(len_hint * 8);

let first_ident = *iter.next().unwrap().borrow();
if first_ident.name != kw::PathRoot {
s.push_str(&first_ident.to_string());
}
for ident in iter {
let ident = *ident.borrow();
debug_assert_ne!(ident.name, kw::PathRoot);
s.push_str("::");
s.push_str(&ident.to_string());
}
s
}

/// A segment of a path: an identifier, an optional lifetime, and a set of types.
///
/// E.g., `std`, `String` or `Box<T>`.
Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_attr_data_structures/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ pub enum DeprecatedSince {
Err,
}

#[derive(
Copy,
Debug,
Eq,
PartialEq,
Encodable,
Decodable,
Clone,
HashStable_Generic,
PrintAttribute
)]
pub enum CoverageStatus {
On,
Off,
}

impl Deprecation {
/// Whether an item marked with #[deprecated(since = "X")] is currently
/// deprecated (i.e., whether X is not greater than the current rustc
Expand Down Expand Up @@ -274,6 +290,9 @@ pub enum AttributeKind {
/// Represents `#[const_trait]`.
ConstTrait(Span),

/// Represents `#[coverage]`.
Coverage(Span, CoverageStatus),

///Represents `#[rustc_deny_explicit_impl]`.
DenyExplicitImpl(Span),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl AttributeKind {
ConstStability { .. } => Yes,
ConstStabilityIndirect => No,
ConstTrait(..) => No,
Coverage(..) => No,
DenyExplicitImpl(..) => No,
Deprecation { .. } => Yes,
DoNotImplementViaObject(..) => No,
Expand Down
41 changes: 40 additions & 1 deletion compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_attr_data_structures::{AttributeKind, OptimizeAttr, UsedBy};
use rustc_attr_data_structures::{AttributeKind, CoverageStatus, OptimizeAttr, UsedBy};
use rustc_feature::{AttributeTemplate, template};
use rustc_session::parse::feature_err;
use rustc_span::{Span, Symbol, sym};
Expand Down Expand Up @@ -52,6 +52,45 @@ impl<S: Stage> NoArgsAttributeParser<S> for ColdParser {
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Cold;
}

pub(crate) struct CoverageParser;

impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
const PATH: &[Symbol] = &[sym::coverage];
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
const TEMPLATE: AttributeTemplate = template!(OneOf: &[sym::off, sym::on]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
let Some(args) = args.list() else {
cx.expected_specific_argument_and_list(cx.attr_span, vec!["on", "off"]);
return None;
};

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

let fail_incorrect_argument = |span| cx.expected_specific_argument(span, vec!["on", "off"]);

let Some(arg) = arg.meta_item() else {
fail_incorrect_argument(args.span);
return None;
};

let status = match arg.path().word_sym() {
Some(sym::off) => CoverageStatus::Off,
Some(sym::on) => CoverageStatus::On,
None | Some(_) => {
fail_incorrect_argument(arg.span());
return None;
}
};

Some(AttributeKind::Coverage(cx.attr_span, status))
}
}

pub(crate) struct ExportNameParser;

impl<S: Stage> SingleAttributeParser<S> for ExportNameParser {
Expand Down
26 changes: 24 additions & 2 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};

use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
use crate::attributes::codegen_attrs::{
ColdParser, ExportNameParser, NakedParser, NoMangleParser, OmitGdbPrettyPrinterSectionParser,
OptimizeParser, TargetFeatureParser, TrackCallerParser, UsedParser,
ColdParser, CoverageParser, ExportNameParser, NakedParser, NoMangleParser,
OmitGdbPrettyPrinterSectionParser, OptimizeParser, TargetFeatureParser, TrackCallerParser,
UsedParser,
};
use crate::attributes::confusables::ConfusablesParser;
use crate::attributes::deprecation::DeprecationParser;
Expand Down Expand Up @@ -136,6 +137,7 @@ attribute_parsers!(
// tidy-alphabetical-end

// tidy-alphabetical-start
Single<CoverageParser>,
Single<DeprecationParser>,
Single<DummyParser>,
Single<ExportNameParser>,
Expand Down Expand Up @@ -449,6 +451,25 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
reason: AttributeParseErrorReason::ExpectedSpecificArgument {
possibilities,
strings: false,
list: false,
},
})
}

pub(crate) fn expected_specific_argument_and_list(
&self,
span: Span,
possibilities: Vec<&'static str>,
) -> ErrorGuaranteed {
self.emit_err(AttributeParseError {
span,
attr_span: self.attr_span,
template: self.template.clone(),
attribute: self.attr_path.clone(),
reason: AttributeParseErrorReason::ExpectedSpecificArgument {
possibilities,
strings: false,
list: true,
},
})
}
Expand All @@ -466,6 +487,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
reason: AttributeParseErrorReason::ExpectedSpecificArgument {
possibilities,
strings: true,
list: false,
},
})
}
Expand Down
49 changes: 46 additions & 3 deletions compiler/rustc_attr_parsing/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,22 @@ pub(crate) struct LinkOrdinalOutOfRange {

pub(crate) enum AttributeParseErrorReason {
ExpectedNoArgs,
ExpectedStringLiteral { byte_string: Option<Span> },
ExpectedStringLiteral {
byte_string: Option<Span>,
},
ExpectedIntegerLiteral,
ExpectedAtLeastOneArgument,
ExpectedSingleArgument,
ExpectedList,
UnexpectedLiteral,
ExpectedNameValue(Option<Symbol>),
DuplicateKey(Symbol),
ExpectedSpecificArgument { possibilities: Vec<&'static str>, strings: bool },
ExpectedSpecificArgument {
possibilities: Vec<&'static str>,
strings: bool,
/// Should we tell the user to write a list when they didn't?
list: bool,
},
}

pub(crate) struct AttributeParseError {
Expand Down Expand Up @@ -607,7 +614,11 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError {
format!("expected this to be of the form `{name} = \"...\"`"),
);
}
AttributeParseErrorReason::ExpectedSpecificArgument { possibilities, strings } => {
AttributeParseErrorReason::ExpectedSpecificArgument {
possibilities,
strings,
list: false,
} => {
let quote = if strings { '"' } else { '`' };
match possibilities.as_slice() {
&[] => {}
Expand All @@ -633,6 +644,38 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError {
}
}
}
AttributeParseErrorReason::ExpectedSpecificArgument {
possibilities,
strings,
list: true,
} => {
let quote = if strings { '"' } else { '`' };
match possibilities.as_slice() {
&[] => {}
&[x] => {
diag.span_label(
self.span,
format!(
"this attribute is only valid with {quote}{x}{quote} as an argument"
),
);
}
[first, second] => {
diag.span_label(self.span, format!("this attribute is only valid with either {quote}{first}{quote} or {quote}{second}{quote} as an argument"));
}
[first @ .., second_to_last, last] => {
let mut res = String::new();
for i in first {
res.push_str(&format!("{quote}{i}{quote}, "));
}
res.push_str(&format!(
"{quote}{second_to_last}{quote} or {quote}{last}{quote}"
));

diag.span_label(self.span, format!("this attribute is only valid with one of the following arguments: {res}"));
}
}
}
}

let suggestions = self.template.suggestions(false, &name);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::sync::Arc;

use rustc_ast as ast;
use rustc_ast::ptr::P;
use rustc_ast::token;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::{join_path_idents, token};
use rustc_ast_pretty::pprust;
use rustc_expand::base::{
DummyResult, ExpandResult, ExtCtxt, MacEager, MacResult, MacroExpanderResult, resolve_path,
Expand Down Expand Up @@ -100,7 +100,7 @@ pub(crate) fn expand_mod(
let sp = cx.with_def_site_ctxt(sp);
check_zero_tts(cx, sp, tts, "module_path!");
let mod_path = &cx.current_expansion.module.mod_path;
let string = mod_path.iter().map(|x| x.to_string()).collect::<Vec<String>>().join("::");
let string = join_path_idents(mod_path);

ExpandResult::Ready(MacEager::expr(cx.expr_str(sp, Symbol::intern(&string))))
}
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::assert_matches::assert_matches;
use std::iter;

use rustc_ast::ptr::P;
use rustc_ast::{self as ast, GenericParamKind, attr};
use rustc_ast::{self as ast, GenericParamKind, attr, join_path_idents};
use rustc_ast_pretty::pprust;
use rustc_errors::{Applicability, Diag, Level};
use rustc_expand::base::*;
Expand Down Expand Up @@ -446,12 +446,7 @@ fn get_location_info(cx: &ExtCtxt<'_>, fn_: &ast::Fn) -> (Symbol, usize, usize,
}

fn item_path(mod_path: &[Ident], item_ident: &Ident) -> String {
mod_path
.iter()
.chain(iter::once(item_ident))
.map(|x| x.to_string())
.collect::<Vec<String>>()
.join("::")
join_path_idents(mod_path.iter().chain(iter::once(item_ident)))
}

enum ShouldPanic {
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ const_eval_const_context = {$kind ->
*[other] {""}
}

const_eval_const_heap_ptr_in_final = encountered `const_allocate` pointer in final value that was not made global
.note = use `const_make_global` to make allocated pointers immutable before returning

const_eval_const_make_global_ptr_already_made_global = attempting to call `const_make_global` twice on the same allocation {$alloc}

const_eval_const_make_global_ptr_is_non_heap = pointer passed to `const_make_global` does not point to a heap allocation: {$ptr}

const_eval_const_make_global_with_dangling_ptr = pointer passed to `const_make_global` is dangling: {$ptr}

const_eval_const_make_global_with_offset = making {$ptr} global which does not point to the beginning of an object

const_eval_copy_nonoverlapping_overlapping =
`copy_nonoverlapping` called on overlapping ranges

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_const_eval/src/const_eval/dummy_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ impl HasStaticRootDefId for DummyMachine {

impl<'tcx> interpret::Machine<'tcx> for DummyMachine {
interpret::compile_time_machine!(<'tcx>);
type MemoryKind = !;
const PANIC_ON_ALLOC_FAIL: bool = true;

// We want to just eval random consts in the program, so `eval_mir_const` can fail.
Expand Down
Loading
Loading