Skip to content

Commit 4676552

Browse files
authored
Merge pull request #4532 from rust-lang/rustup-2025-08-20
Automatic Rustup
2 parents 49abb66 + 5556212 commit 4676552

File tree

609 files changed

+15854
-9022
lines changed

Some content is hidden

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

609 files changed

+15854
-9022
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4812,6 +4812,7 @@ dependencies = [
48124812
"serde_json",
48134813
"sha2",
48144814
"smallvec",
4815+
"stringdex",
48154816
"tempfile",
48164817
"threadpool",
48174818
"tracing",
@@ -5225,6 +5226,15 @@ dependencies = [
52255226
"quote",
52265227
]
52275228

5229+
[[package]]
5230+
name = "stringdex"
5231+
version = "0.0.1-alpha4"
5232+
source = "registry+https://github.com/rust-lang/crates.io-index"
5233+
checksum = "2841fd43df5b1ff1b042e167068a1fe9b163dc93041eae56ab2296859013a9a0"
5234+
dependencies = [
5235+
"stacker",
5236+
]
5237+
52285238
[[package]]
52295239
name = "strsim"
52305240
version = "0.11.1"

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ attr_parsing_empty_attribute =
1212
1313
attr_parsing_invalid_target = `#[{$name}]` attribute cannot be used on {$target}
1414
.help = `#[{$name}]` can {$only}be applied to {$applied}
15+
.suggestion = remove the attribute
1516
attr_parsing_invalid_target_lint = `#[{$name}]` attribute cannot be used on {$target}
1617
.warn = {-attr_parsing_previously_accepted}
1718
.help = `#[{$name}]` can {$only}be applied to {$applied}
19+
.suggestion = remove the attribute
1820
1921
attr_parsing_empty_confusables =
2022
expected at least one confusable name

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
5454
Allow(Target::TyAlias),
5555
Allow(Target::Use),
5656
Allow(Target::ForeignFn),
57+
Allow(Target::ForeignStatic),
58+
Allow(Target::ForeignTy),
5759
Allow(Target::Field),
5860
Allow(Target::Trait),
5961
Allow(Target::AssocTy),

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
6262
}
6363
}
6464
ArgParser::NameValue(_) => {
65-
let suggestions =
66-
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "inline");
65+
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
66+
.suggestions(cx.attr_style, "inline");
6767
let span = cx.attr_span;
6868
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
6969
return None;

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
107107
}
108108
}
109109
ArgParser::NameValue(_) => {
110-
let suggestions = MACRO_USE_TEMPLATE.suggestions(false, sym::macro_use);
110+
let suggestions = MACRO_USE_TEMPLATE.suggestions(cx.attr_style, sym::macro_use);
111111
cx.emit_err(session_diagnostics::IllFormedAttributeInputLint {
112112
num_suggestions: suggestions.len(),
113113
suggestions: DiagArgValue::StrListSepByAnd(

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub(crate) mod no_implicit_prelude;
4343
pub(crate) mod non_exhaustive;
4444
pub(crate) mod path;
4545
pub(crate) mod proc_macro_attrs;
46+
pub(crate) mod prototype;
4647
pub(crate) mod repr;
4748
pub(crate) mod rustc_internal;
4849
pub(crate) mod semantics;

compiler/rustc_attr_parsing/src/attributes/must_use.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use rustc_errors::DiagArgValue;
22
use rustc_feature::{AttributeTemplate, template};
33
use rustc_hir::attrs::AttributeKind;
4+
use rustc_hir::{MethodKind, Target};
45
use rustc_span::{Symbol, sym};
56

67
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
7-
use crate::context::{ALL_TARGETS, AcceptContext, AllowedTargets, Stage};
8+
use crate::context::MaybeWarn::{Allow, Error};
9+
use crate::context::{AcceptContext, AllowedTargets, Stage};
810
use crate::parser::ArgParser;
911
use crate::session_diagnostics;
1012
pub(crate) struct MustUseParser;
@@ -13,7 +15,21 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
1315
const PATH: &[Symbol] = &[sym::must_use];
1416
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1517
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
16-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); //FIXME Still checked fully in `check_attr.rs`
18+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
19+
Allow(Target::Fn),
20+
Allow(Target::Enum),
21+
Allow(Target::Struct),
22+
Allow(Target::Union),
23+
Allow(Target::Method(MethodKind::Trait { body: false })),
24+
Allow(Target::Method(MethodKind::Trait { body: true })),
25+
Allow(Target::Method(MethodKind::Inherent)),
26+
Allow(Target::ForeignFn),
27+
// `impl Trait` in return position can trip
28+
// `unused_must_use` if `Trait` is marked as
29+
// `#[must_use]`
30+
Allow(Target::Trait),
31+
Error(Target::WherePredicate),
32+
]);
1733
const TEMPLATE: AttributeTemplate = template!(
1834
Word, NameValueStr: "reason",
1935
"https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"
@@ -35,8 +51,8 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
3551
Some(value_str)
3652
}
3753
ArgParser::List(_) => {
38-
let suggestions =
39-
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "must_use");
54+
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
55+
.suggestions(cx.attr_style, "must_use");
4056
cx.emit_err(session_diagnostics::IllFormedAttributeInputLint {
4157
num_suggestions: suggestions.len(),
4258
suggestions: DiagArgValue::StrListSepByAnd(
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
//! Attributes that are only used on function prototypes.
2+
3+
use rustc_feature::{AttributeTemplate, template};
4+
use rustc_hir::Target;
5+
use rustc_hir::attrs::{AttributeKind, MirDialect, MirPhase};
6+
use rustc_span::{Span, Symbol, sym};
7+
8+
use super::{AttributeOrder, OnDuplicate};
9+
use crate::attributes::SingleAttributeParser;
10+
use crate::context::{AcceptContext, AllowedTargets, MaybeWarn, Stage};
11+
use crate::parser::ArgParser;
12+
13+
pub(crate) struct CustomMirParser;
14+
15+
impl<S: Stage> SingleAttributeParser<S> for CustomMirParser {
16+
const PATH: &[rustc_span::Symbol] = &[sym::custom_mir];
17+
18+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
19+
20+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
21+
22+
const ALLOWED_TARGETS: AllowedTargets =
23+
AllowedTargets::AllowList(&[MaybeWarn::Allow(Target::Fn)]);
24+
25+
const TEMPLATE: AttributeTemplate = template!(List: &[r#"dialect = "...", phase = "...""#]);
26+
27+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
28+
let Some(list) = args.list() else {
29+
cx.expected_list(cx.attr_span);
30+
return None;
31+
};
32+
33+
let mut dialect = None;
34+
let mut phase = None;
35+
let mut failed = false;
36+
37+
for item in list.mixed() {
38+
let Some(meta_item) = item.meta_item() else {
39+
cx.expected_name_value(item.span(), None);
40+
failed = true;
41+
break;
42+
};
43+
44+
if let Some(arg) = meta_item.word_is(sym::dialect) {
45+
extract_value(cx, sym::dialect, arg, meta_item.span(), &mut dialect, &mut failed);
46+
} else if let Some(arg) = meta_item.word_is(sym::phase) {
47+
extract_value(cx, sym::phase, arg, meta_item.span(), &mut phase, &mut failed);
48+
} else if let Some(word) = meta_item.path().word() {
49+
let word = word.to_string();
50+
cx.unknown_key(meta_item.span(), word, &["dialect", "phase"]);
51+
failed = true;
52+
} else {
53+
cx.expected_name_value(meta_item.span(), None);
54+
failed = true;
55+
};
56+
}
57+
58+
let dialect = parse_dialect(cx, dialect, &mut failed);
59+
let phase = parse_phase(cx, phase, &mut failed);
60+
61+
if failed {
62+
return None;
63+
}
64+
65+
Some(AttributeKind::CustomMir(dialect, phase, cx.attr_span))
66+
}
67+
}
68+
69+
fn extract_value<S: Stage>(
70+
cx: &mut AcceptContext<'_, '_, S>,
71+
key: Symbol,
72+
arg: &ArgParser<'_>,
73+
span: Span,
74+
out_val: &mut Option<(Symbol, Span)>,
75+
failed: &mut bool,
76+
) {
77+
if out_val.is_some() {
78+
cx.duplicate_key(span, key);
79+
*failed = true;
80+
return;
81+
}
82+
83+
let Some(val) = arg.name_value() else {
84+
cx.expected_single_argument(arg.span().unwrap_or(span));
85+
*failed = true;
86+
return;
87+
};
88+
89+
let Some(value_sym) = val.value_as_str() else {
90+
cx.expected_string_literal(val.value_span, Some(val.value_as_lit()));
91+
*failed = true;
92+
return;
93+
};
94+
95+
*out_val = Some((value_sym, val.value_span));
96+
}
97+
98+
fn parse_dialect<S: Stage>(
99+
cx: &mut AcceptContext<'_, '_, S>,
100+
dialect: Option<(Symbol, Span)>,
101+
failed: &mut bool,
102+
) -> Option<(MirDialect, Span)> {
103+
let (dialect, span) = dialect?;
104+
105+
let dialect = match dialect {
106+
sym::analysis => MirDialect::Analysis,
107+
sym::built => MirDialect::Built,
108+
sym::runtime => MirDialect::Runtime,
109+
110+
_ => {
111+
cx.expected_specific_argument(span, vec!["analysis", "built", "runtime"]);
112+
*failed = true;
113+
return None;
114+
}
115+
};
116+
117+
Some((dialect, span))
118+
}
119+
120+
fn parse_phase<S: Stage>(
121+
cx: &mut AcceptContext<'_, '_, S>,
122+
phase: Option<(Symbol, Span)>,
123+
failed: &mut bool,
124+
) -> Option<(MirPhase, Span)> {
125+
let (phase, span) = phase?;
126+
127+
let phase = match phase {
128+
sym::initial => MirPhase::Initial,
129+
sym::post_cleanup => MirPhase::PostCleanup,
130+
sym::optimized => MirPhase::Optimized,
131+
132+
_ => {
133+
cx.expected_specific_argument(span, vec!["initial", "post-cleanup", "optimized"]);
134+
*failed = true;
135+
return None;
136+
}
137+
};
138+
139+
Some((phase, span))
140+
}

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
5454
Allow(Target::Static),
5555
Allow(Target::ForeignFn),
5656
Allow(Target::ForeignStatic),
57+
Allow(Target::ExternCrate),
5758
]);
5859

5960
#[derive(Default)]

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
2929
ArgParser::NameValue(name_value) => {
3030
let Some(str_value) = name_value.value_as_str() else {
3131
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
32-
.suggestions(false, "ignore");
32+
.suggestions(cx.attr_style, "ignore");
3333
let span = cx.attr_span;
3434
cx.emit_lint(
3535
AttributeLintKind::IllFormedAttributeInput { suggestions },
@@ -40,8 +40,8 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
4040
Some(str_value)
4141
}
4242
ArgParser::List(_) => {
43-
let suggestions =
44-
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "ignore");
43+
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
44+
.suggestions(cx.attr_style, "ignore");
4545
let span = cx.attr_span;
4646
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
4747
return None;

0 commit comments

Comments
 (0)