Skip to content

Commit ad07aa1

Browse files
committed
Auto merge of rust-lang#124289 - matthiaskrgr:rollup-oxw52jy, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#123050 (panic_str only exists for the migration to 2021 panic macros) - rust-lang#124067 (weak lang items are not allowed to be #[track_caller]) - rust-lang#124099 (Disallow ambiguous attributes on expressions) - rust-lang#124284 (parser: remove unused(no reads) max_angle_bracket_count field) - rust-lang#124288 (remove `push_trait_bound_inner`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c672773 + 802f629 commit ad07aa1

File tree

61 files changed

+307
-159
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+307
-159
lines changed

Diff for: compiler/rustc_error_codes/src/error_codes/E0522.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Erroneous code example:
66
#![feature(lang_items)]
77
88
#[lang = "cookie"]
9-
fn cookie() -> ! { // error: definition of an unknown language item: `cookie`
9+
fn cookie() -> ! { // error: definition of an unknown lang item: `cookie`
1010
loop {}
1111
}
1212
```

Diff for: compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
798798
// ==========================================================================
799799
gated!(
800800
lang, Normal, template!(NameValueStr: "name"), DuplicatesOk, EncodeCrossCrate::No, lang_items,
801-
"language items are subject to change",
801+
"lang items are subject to change",
802802
),
803803
rustc_attr!(
804804
rustc_pass_by_value, Normal, template!(Word), ErrorFollowing,

Diff for: compiler/rustc_hir/src/lang_items.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Defines language items.
1+
//! Defines lang items.
22
//!
33
//! Language items are items that represent concepts intrinsic to the language
44
//! itself. Examples are:
@@ -16,7 +16,7 @@ use rustc_macros::HashStable_Generic;
1616
use rustc_span::symbol::{kw, sym, Symbol};
1717
use rustc_span::Span;
1818

19-
/// All of the language items, defined or not.
19+
/// All of the lang items, defined or not.
2020
/// Defined lang items can come from the current crate or its dependencies.
2121
#[derive(HashStable_Generic, Debug)]
2222
pub struct LanguageItems {
@@ -57,7 +57,7 @@ macro_rules! language_item_table {
5757
) => {
5858

5959
enum_from_u32! {
60-
/// A representation of all the valid language items in Rust.
60+
/// A representation of all the valid lang items in Rust.
6161
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
6262
pub enum LangItem {
6363
$(
@@ -177,7 +177,7 @@ language_item_table! {
177177
CoerceUnsized, sym::coerce_unsized, coerce_unsized_trait, Target::Trait, GenericRequirement::Minimum(1);
178178
DispatchFromDyn, sym::dispatch_from_dyn, dispatch_from_dyn_trait, Target::Trait, GenericRequirement::Minimum(1);
179179

180-
// language items relating to transmutability
180+
// lang items relating to transmutability
181181
TransmuteOpts, sym::transmute_opts, transmute_opts, Target::Struct, GenericRequirement::Exact(0);
182182
TransmuteTrait, sym::transmute_trait, transmute_trait, Target::Trait, GenericRequirement::Exact(2);
183183

@@ -304,7 +304,7 @@ language_item_table! {
304304
OwnedBox, sym::owned_box, owned_box, Target::Struct, GenericRequirement::Minimum(1);
305305
GlobalAlloc, sym::global_alloc_ty, global_alloc_ty, Target::Struct, GenericRequirement::None;
306306

307-
// Experimental language item for Miri
307+
// Experimental lang item for Miri
308308
PtrUnique, sym::ptr_unique, ptr_unique, Target::Struct, GenericRequirement::Exact(1);
309309

310310
PhantomData, sym::phantom_data, phantom_data, Target::Struct, GenericRequirement::Exact(1);

Diff for: compiler/rustc_hir_analysis/src/bounds.rs

-10
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,6 @@ impl<'tcx> Bounds<'tcx> {
4343
trait_ref: ty::PolyTraitRef<'tcx>,
4444
span: Span,
4545
polarity: ty::PredicatePolarity,
46-
) {
47-
self.push_trait_bound_inner(tcx, trait_ref, span, polarity);
48-
}
49-
50-
fn push_trait_bound_inner(
51-
&mut self,
52-
tcx: TyCtxt<'tcx>,
53-
trait_ref: ty::PolyTraitRef<'tcx>,
54-
span: Span,
55-
polarity: ty::PredicatePolarity,
5646
) {
5747
let clause = (
5848
trait_ref

Diff for: compiler/rustc_hir_analysis/src/check/intrinsic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -535,20 +535,20 @@ pub fn check_intrinsic_type(
535535

536536
sym::va_start | sym::va_end => match mk_va_list_ty(hir::Mutability::Mut) {
537537
Some((va_list_ref_ty, _)) => (0, 0, vec![va_list_ref_ty], Ty::new_unit(tcx)),
538-
None => bug!("`va_list` language item needed for C-variadic intrinsics"),
538+
None => bug!("`va_list` lang item needed for C-variadic intrinsics"),
539539
},
540540

541541
sym::va_copy => match mk_va_list_ty(hir::Mutability::Not) {
542542
Some((va_list_ref_ty, va_list_ty)) => {
543543
let va_list_ptr_ty = Ty::new_mut_ptr(tcx, va_list_ty);
544544
(0, 0, vec![va_list_ptr_ty, va_list_ref_ty], Ty::new_unit(tcx))
545545
}
546-
None => bug!("`va_list` language item needed for C-variadic intrinsics"),
546+
None => bug!("`va_list` lang item needed for C-variadic intrinsics"),
547547
},
548548

549549
sym::va_arg => match mk_va_list_ty(hir::Mutability::Mut) {
550550
Some((va_list_ref_ty, _)) => (1, 0, vec![va_list_ref_ty], param(0)),
551-
None => bug!("`va_list` language item needed for C-variadic intrinsics"),
551+
None => bug!("`va_list` lang item needed for C-variadic intrinsics"),
552552
},
553553

554554
sym::nontemporal_store => {

Diff for: compiler/rustc_lint/src/non_fmt_panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for NonPanicFmt {
5353

5454
if Some(def_id) == cx.tcx.lang_items().begin_panic_fn()
5555
|| Some(def_id) == cx.tcx.lang_items().panic_fn()
56-
|| f_diagnostic_name == Some(sym::panic_str)
56+
|| f_diagnostic_name == Some(sym::panic_str_2015)
5757
{
5858
if let Some(id) = f.span.ctxt().outer_expn_data().macro_def_id {
5959
if matches!(

Diff for: compiler/rustc_metadata/src/rmeta/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12081208
tcx.arena.alloc_from_iter(self.root.stability_implications.decode(self))
12091209
}
12101210

1211-
/// Iterates over the language items in the given crate.
1211+
/// Iterates over the lang items in the given crate.
12121212
fn get_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, LangItem)] {
12131213
tcx.arena.alloc_from_iter(
12141214
self.root

Diff for: compiler/rustc_middle/src/middle/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Detecting language items.
1+
//! Detecting lang items.
22
//!
33
//! Language items are items that represent concepts intrinsic to the language
44
//! itself. Examples are:

Diff for: compiler/rustc_mir_transform/src/deduce_param_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub fn deduced_param_attrs<'tcx>(
160160
return &[];
161161
}
162162

163-
// If the Freeze language item isn't present, then don't bother.
163+
// If the Freeze lang item isn't present, then don't bother.
164164
if tcx.lang_items().freeze_trait().is_none() {
165165
return &[];
166166
}

Diff for: compiler/rustc_mir_transform/src/lower_slice_len.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<'tcx> MirPass<'tcx> for LowerSliceLenCalls {
2121
pub fn lower_slice_len_calls<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
2222
let language_items = tcx.lang_items();
2323
let Some(slice_len_fn_item_def_id) = language_items.slice_len_fn() else {
24-
// there is no language item to compare to :)
24+
// there is no lang item to compare to :)
2525
return;
2626
};
2727

Diff for: compiler/rustc_parse/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ parse_or_pattern_not_allowed_in_let_binding = top-level or-patterns are not allo
624624
parse_out_of_range_hex_escape = out of range hex escape
625625
.label = must be a character in the range [\x00-\x7f]
626626
627+
parse_outer_attr_ambiguous = ambiguous outer attributes
628+
627629
parse_outer_attr_explanation = outer attributes, like `#[test]`, annotate the item following them
628630
629631
parse_outer_attribute_not_allowed_on_if_else = outer attributes are not allowed on `if` and `else` branches

Diff for: compiler/rustc_parse/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,15 @@ pub(crate) struct OuterAttributeNotAllowedOnIfElse {
495495
pub attributes: Span,
496496
}
497497

498+
#[derive(Diagnostic)]
499+
#[diag(parse_outer_attr_ambiguous)]
500+
pub(crate) struct AmbiguousOuterAttributes {
501+
#[primary_span]
502+
pub span: Span,
503+
#[subdiagnostic]
504+
pub sugg: WrapInParentheses,
505+
}
506+
498507
#[derive(Diagnostic)]
499508
#[diag(parse_missing_in_in_for_loop)]
500509
pub(crate) struct MissingInInForLoop {

Diff for: compiler/rustc_parse/src/parser/expr.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ impl<'a> Parser<'a> {
327327
this.parse_expr_assoc_with(prec + prec_adjustment, LhsExpr::NotYetParsed)
328328
})?;
329329

330-
let span = self.mk_expr_sp(&lhs, lhs_span, rhs.span);
330+
self.error_ambiguous_outer_attrs(&lhs, lhs_span, rhs.span);
331+
let span = lhs_span.to(rhs.span);
332+
331333
lhs = match op {
332334
AssocOp::Add
333335
| AssocOp::Subtract
@@ -426,6 +428,18 @@ impl<'a> Parser<'a> {
426428
});
427429
}
428430

431+
fn error_ambiguous_outer_attrs(&self, lhs: &P<Expr>, lhs_span: Span, rhs_span: Span) {
432+
if let Some(attr) = lhs.attrs.iter().find(|a| a.style == AttrStyle::Outer) {
433+
self.dcx().emit_err(errors::AmbiguousOuterAttributes {
434+
span: attr.span.to(rhs_span),
435+
sugg: errors::WrapInParentheses::Expression {
436+
left: attr.span.shrink_to_lo(),
437+
right: lhs_span.shrink_to_hi(),
438+
},
439+
});
440+
}
441+
}
442+
429443
/// Possibly translate the current token to an associative operator.
430444
/// The method does not advance the current token.
431445
///
@@ -506,7 +520,8 @@ impl<'a> Parser<'a> {
506520
None
507521
};
508522
let rhs_span = rhs.as_ref().map_or(cur_op_span, |x| x.span);
509-
let span = self.mk_expr_sp(&lhs, lhs.span, rhs_span);
523+
self.error_ambiguous_outer_attrs(&lhs, lhs.span, rhs_span);
524+
let span = lhs.span.to(rhs_span);
510525
let limits =
511526
if op == AssocOp::DotDot { RangeLimits::HalfOpen } else { RangeLimits::Closed };
512527
let range = self.mk_range(Some(lhs), rhs, limits);
@@ -722,7 +737,8 @@ impl<'a> Parser<'a> {
722737
expr_kind: fn(P<Expr>, P<Ty>) -> ExprKind,
723738
) -> PResult<'a, P<Expr>> {
724739
let mk_expr = |this: &mut Self, lhs: P<Expr>, rhs: P<Ty>| {
725-
this.mk_expr(this.mk_expr_sp(&lhs, lhs_span, rhs.span), expr_kind(lhs, rhs))
740+
this.error_ambiguous_outer_attrs(&lhs, lhs_span, rhs.span);
741+
this.mk_expr(lhs_span.to(rhs.span), expr_kind(lhs, rhs))
726742
};
727743

728744
// Save the state of the parser before parsing type normally, in case there is a
@@ -3813,16 +3829,6 @@ impl<'a> Parser<'a> {
38133829
self.mk_expr(span, ExprKind::Err(guar))
38143830
}
38153831

3816-
/// Create expression span ensuring the span of the parent node
3817-
/// is larger than the span of lhs and rhs, including the attributes.
3818-
fn mk_expr_sp(&self, lhs: &P<Expr>, lhs_span: Span, rhs_span: Span) -> Span {
3819-
lhs.attrs
3820-
.iter()
3821-
.find(|a| a.style == AttrStyle::Outer)
3822-
.map_or(lhs_span, |a| a.span)
3823-
.to(rhs_span)
3824-
}
3825-
38263832
fn collect_tokens_for_expr(
38273833
&mut self,
38283834
attrs: AttrWrapper,

Diff for: compiler/rustc_parse/src/parser/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ pub struct Parser<'a> {
162162
///
163163
/// See the comments in the `parse_path_segment` function for more details.
164164
unmatched_angle_bracket_count: u16,
165-
max_angle_bracket_count: u16,
166165
angle_bracket_nesting: u16,
167166

168167
last_unexpected_token_span: Option<Span>,
@@ -430,7 +429,6 @@ impl<'a> Parser<'a> {
430429
num_bump_calls: 0,
431430
break_last_token: false,
432431
unmatched_angle_bracket_count: 0,
433-
max_angle_bracket_count: 0,
434432
angle_bracket_nesting: 0,
435433
last_unexpected_token_span: None,
436434
subparser_name,
@@ -778,7 +776,6 @@ impl<'a> Parser<'a> {
778776
if ate {
779777
// See doc comment for `unmatched_angle_bracket_count`.
780778
self.unmatched_angle_bracket_count += 1;
781-
self.max_angle_bracket_count += 1;
782779
debug!("eat_lt: (increment) count={:?}", self.unmatched_angle_bracket_count);
783780
}
784781
ate

Diff for: compiler/rustc_parse/src/parser/path.rs

-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ impl<'a> Parser<'a> {
299299
// parsing a new path.
300300
if style == PathStyle::Expr {
301301
self.unmatched_angle_bracket_count = 0;
302-
self.max_angle_bracket_count = 0;
303302
}
304303

305304
// Generic arguments are found - `<`, `(`, `::<` or `::(`.

Diff for: compiler/rustc_passes/messages.ftl

+16-7
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ passes_incorrect_meta_item = expected a quoted string literal
353353
passes_incorrect_meta_item_suggestion = consider surrounding this with quotes
354354
355355
passes_incorrect_target =
356-
`{$name}` language item must be applied to a {$kind} with {$at_least ->
356+
`{$name}` lang item must be applied to a {$kind} with {$at_least ->
357357
[true] at least {$num}
358358
*[false] {$num}
359359
} generic {$num ->
@@ -394,12 +394,21 @@ passes_invalid_macro_export_arguments = `{$name}` isn't a valid `#[macro_export]
394394
395395
passes_invalid_macro_export_arguments_too_many_items = `#[macro_export]` can only take 1 or 0 arguments
396396
397+
passes_lang_item_fn = {$name ->
398+
[panic_impl] `#[panic_handler]`
399+
*[other] `{$name}` lang item
400+
} function
401+
397402
passes_lang_item_fn_with_target_feature =
398-
`{$name}` language item function is not allowed to have `#[target_feature]`
399-
.label = `{$name}` language item function is not allowed to have `#[target_feature]`
403+
{passes_lang_item_fn} is not allowed to have `#[target_feature]`
404+
.label = {passes_lang_item_fn} is not allowed to have `#[target_feature]`
405+
406+
passes_lang_item_fn_with_track_caller =
407+
{passes_lang_item_fn} is not allowed to have `#[track_caller]`
408+
.label = {passes_lang_item_fn} is not allowed to have `#[target_feature]`
400409
401410
passes_lang_item_on_incorrect_target =
402-
`{$name}` language item must be applied to a {$expected_target}
411+
`{$name}` lang item must be applied to a {$expected_target}
403412
.label = attribute should be applied to a {$expected_target}, not a {$actual_target}
404413
405414
passes_layout_abi =
@@ -455,7 +464,7 @@ passes_missing_const_stab_attr =
455464
{$descr} has missing const stability attribute
456465
457466
passes_missing_lang_item =
458-
language item required, but not found: `{$name}`
467+
lang item required, but not found: `{$name}`
459468
.note = this can occur when a binary crate with `#![no_std]` is compiled for a target where `{$name}` is defined in the standard library
460469
.help = you may be able to compile for a target that doesn't need `{$name}`, specify a target with `--target` or in `.cargo/config`
461470
@@ -696,8 +705,8 @@ passes_unknown_feature =
696705
unknown feature `{$feature}`
697706
698707
passes_unknown_lang_item =
699-
definition of an unknown language item: `{$name}`
700-
.label = definition of unknown language item `{$name}`
708+
definition of an unknown lang item: `{$name}`
709+
.label = definition of unknown lang item `{$name}`
701710
702711
passes_unlabeled_cf_in_while_condition =
703712
`break` or `continue` with no label in the condition of a `while` loop

Diff for: compiler/rustc_passes/src/check_attr.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use rustc_data_structures::fx::FxHashMap;
1111
use rustc_errors::StashKey;
1212
use rustc_errors::{Applicability, DiagCtxt, IntoDiagArg, MultiSpan};
1313
use rustc_feature::{AttributeDuplicates, AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
14-
use rustc_hir as hir;
1514
use rustc_hir::def_id::LocalModDefId;
1615
use rustc_hir::intravisit::{self, Visitor};
16+
use rustc_hir::{self as hir};
1717
use rustc_hir::{
1818
self, FnSig, ForeignItem, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID, CRATE_OWNER_ID,
1919
};
@@ -519,7 +519,26 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
519519
self.dcx().emit_err(errors::NakedTrackedCaller { attr_span });
520520
false
521521
}
522-
Target::Fn | Target::Method(..) | Target::ForeignFn | Target::Closure => true,
522+
Target::Fn => {
523+
// `#[track_caller]` is not valid on weak lang items because they are called via
524+
// `extern` declarations and `#[track_caller]` would alter their ABI.
525+
if let Some((lang_item, _)) = hir::lang_items::extract(attrs)
526+
&& let Some(item) = hir::LangItem::from_name(lang_item)
527+
&& item.is_weak()
528+
{
529+
let sig = self.tcx.hir_node(hir_id).fn_sig().unwrap();
530+
531+
self.dcx().emit_err(errors::LangItemWithTrackCaller {
532+
attr_span,
533+
name: lang_item,
534+
sig_span: sig.span,
535+
});
536+
false
537+
} else {
538+
true
539+
}
540+
}
541+
Target::Method(..) | Target::ForeignFn | Target::Closure => true,
523542
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
524543
// `#[track_caller]` attribute with just a lint, because we previously
525544
// erroneously allowed it and some crates used it accidentally, to be compatible
@@ -602,7 +621,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
602621
) -> bool {
603622
match target {
604623
Target::Fn => {
605-
// `#[target_feature]` is not allowed in language items.
624+
// `#[target_feature]` is not allowed in lang items.
606625
if let Some((lang_item, _)) = hir::lang_items::extract(attrs)
607626
// Calling functions with `#[target_feature]` is
608627
// not unsafe on WASM, see #84988

Diff for: compiler/rustc_passes/src/errors.rs

+10
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,16 @@ pub struct MissingLangItem {
819819
pub name: Symbol,
820820
}
821821

822+
#[derive(Diagnostic)]
823+
#[diag(passes_lang_item_fn_with_track_caller)]
824+
pub struct LangItemWithTrackCaller {
825+
#[primary_span]
826+
pub attr_span: Span,
827+
pub name: Symbol,
828+
#[label]
829+
pub sig_span: Span,
830+
}
831+
822832
#[derive(Diagnostic)]
823833
#[diag(passes_lang_item_fn_with_target_feature)]
824834
pub struct LangItemWithTargetFeature {

Diff for: compiler/rustc_passes/src/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Detecting language items.
1+
//! Detecting lang items.
22
//!
33
//! Language items are items that represent concepts intrinsic to the language
44
//! itself. Examples are:

0 commit comments

Comments
 (0)