Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4aaff39

Browse files
committedJan 20, 2025
Fix all tests
1 parent 7c94afd commit 4aaff39

File tree

64 files changed

+523
-570
lines changed

Some content is hidden

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

64 files changed

+523
-570
lines changed
 

‎compiler/rustc_attr_parsing/src/attributes/deprecation.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn get(
1919
item: &mut Option<Symbol>,
2020
) -> bool {
2121
if item.is_some() {
22-
cx.dcx().emit_err(session_diagnostics::MultipleItem {
22+
cx.emit_err(session_diagnostics::MultipleItem {
2323
span: param_span,
2424
item: ident.to_string(),
2525
});
@@ -31,7 +31,7 @@ fn get(
3131
true
3232
} else {
3333
let lit = v.value_as_lit();
34-
cx.dcx().emit_err(session_diagnostics::UnsupportedLiteral {
34+
cx.emit_err(session_diagnostics::UnsupportedLiteral {
3535
span: v.value_span,
3636
reason: UnsupportedLiteralReason::DeprecatedString,
3737
is_bytestr: lit.kind.is_bytestr(),
@@ -41,10 +41,7 @@ fn get(
4141
}
4242
} else {
4343
// FIXME(jdonszelmann): suggestion?
44-
cx.dcx().emit_err(session_diagnostics::IncorrectMetaItem {
45-
span: param_span,
46-
suggestion: None,
47-
});
44+
cx.emit_err(session_diagnostics::IncorrectMetaItem { span: param_span, suggestion: None });
4845
false
4946
}
5047
}
@@ -54,7 +51,7 @@ impl SingleAttributeParser for DeprecationParser {
5451

5552
fn on_duplicate(cx: &AcceptContext<'_>, first_span: rustc_span::Span) {
5653
// FIXME(jdonszelmann): merge with errors from check_attrs.rs
57-
cx.dcx().emit_err(session_diagnostics::UnusedMultiple {
54+
cx.emit_err(session_diagnostics::UnusedMultiple {
5855
this: cx.attr_span,
5956
other: first_span,
6057
name: sym::deprecated,
@@ -78,7 +75,7 @@ impl SingleAttributeParser for DeprecationParser {
7875
for param in list.mixed() {
7976
let param_span = param.span();
8077
let Some(param) = param.meta_item() else {
81-
cx.dcx().emit_err(session_diagnostics::UnsupportedLiteral {
78+
cx.emit_err(session_diagnostics::UnsupportedLiteral {
8279
span: param_span,
8380
reason: UnsupportedLiteralReason::DeprecatedKvPair,
8481
is_bytestr: false,
@@ -102,7 +99,7 @@ impl SingleAttributeParser for DeprecationParser {
10299
}
103100
sym::suggestion => {
104101
if !features.deprecated_suggestion() {
105-
cx.dcx().emit_err(session_diagnostics::DeprecatedItemSuggestion {
102+
cx.emit_err(session_diagnostics::DeprecatedItemSuggestion {
106103
span: param_span,
107104
is_nightly: cx.sess().is_nightly_build(),
108105
details: (),
@@ -114,7 +111,7 @@ impl SingleAttributeParser for DeprecationParser {
114111
}
115112
}
116113
_ => {
117-
cx.dcx().emit_err(session_diagnostics::UnknownMetaItem {
114+
cx.emit_err(session_diagnostics::UnknownMetaItem {
118115
span: param_span,
119116
item: ident.to_string(),
120117
expected: if features.deprecated_suggestion() {
@@ -137,18 +134,18 @@ impl SingleAttributeParser for DeprecationParser {
137134
} else if let Some(version) = parse_version(since) {
138135
DeprecatedSince::RustcVersion(version)
139136
} else {
140-
cx.dcx().emit_err(session_diagnostics::InvalidSince { span: cx.attr_span });
137+
cx.emit_err(session_diagnostics::InvalidSince { span: cx.attr_span });
141138
DeprecatedSince::Err
142139
}
143140
} else if is_rustc {
144-
cx.dcx().emit_err(session_diagnostics::MissingSince { span: cx.attr_span });
141+
cx.emit_err(session_diagnostics::MissingSince { span: cx.attr_span });
145142
DeprecatedSince::Err
146143
} else {
147144
DeprecatedSince::Unspecified
148145
};
149146

150147
if is_rustc && note.is_none() {
151-
cx.dcx().emit_err(session_diagnostics::MissingNote { span: cx.attr_span });
148+
cx.emit_err(session_diagnostics::MissingNote { span: cx.attr_span });
152149
return None;
153150
}
154151

‎compiler/rustc_attr_parsing/src/attributes/repr.rs

+24-13
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use crate::session_diagnostics::IncorrectReprFormatGenericCause;
2020
pub(crate) struct ReprParser;
2121

2222
impl CombineAttributeParser for ReprParser {
23-
type Item = ReprAttr;
23+
type Item = (ReprAttr, Span);
2424
const PATH: &'static [rustc_span::Symbol] = &[sym::repr];
25-
const CONVERT: ConvertFn<ReprAttr> = AttributeKind::Repr;
25+
const CONVERT: ConvertFn<Self::Item> = AttributeKind::Repr;
2626

2727
fn extend<'a>(
2828
cx: &'a AcceptContext<'a>,
@@ -34,8 +34,20 @@ impl CombineAttributeParser for ReprParser {
3434
return reprs;
3535
};
3636

37+
if list.is_empty() {
38+
// this is so validation can emit a lint
39+
reprs.push((ReprAttr::ReprEmpty, cx.attr_span));
40+
}
41+
3742
for param in list.mixed() {
38-
reprs.extend(param.meta_item().and_then(|mi| parse_repr(cx, &mi)));
43+
if let Some(_) = param.lit() {
44+
cx.emit_err(session_diagnostics::ReprIdent { span: cx.attr_span });
45+
continue;
46+
}
47+
48+
reprs.extend(
49+
param.meta_item().and_then(|mi| parse_repr(cx, &mi)).map(|r| (r, param.span())),
50+
);
3951
}
4052

4153
reprs
@@ -58,7 +70,6 @@ macro_rules! int_pat {
5870
};
5971
}
6072

61-
// TODO: inline
6273
fn int_type_of_word(s: Symbol) -> Option<IntType> {
6374
use IntType::*;
6475

@@ -88,7 +99,7 @@ fn parse_repr(cx: &AcceptContext<'_>, param: &MetaItemParser<'_>) -> Option<Repr
8899

89100
match (ident.name, args) {
90101
(sym::align, ArgParser::NoArgs) => {
91-
cx.dcx().emit_err(session_diagnostics::InvalidReprAlignNeedArg { span: ident.span });
102+
cx.emit_err(session_diagnostics::InvalidReprAlignNeedArg { span: ident.span });
92103
None
93104
}
94105
(sym::align, ArgParser::List(l)) => parse_repr_align(cx, l, param.span(), AlignKind::Align),
@@ -99,7 +110,7 @@ fn parse_repr(cx: &AcceptContext<'_>, param: &MetaItemParser<'_>) -> Option<Repr
99110
}
100111

101112
(sym::align | sym::packed, ArgParser::NameValue(l)) => {
102-
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatGeneric {
113+
cx.emit_err(session_diagnostics::IncorrectReprFormatGeneric {
103114
span: param.span(),
104115
// FIXME(jdonszelmann) can just be a string in the diag type
105116
repr_arg: &ident.to_string(),
@@ -125,22 +136,22 @@ fn parse_repr(cx: &AcceptContext<'_>, param: &MetaItemParser<'_>) -> Option<Repr
125136
sym::Rust | sym::C | sym::simd | sym::transparent | int_pat!(),
126137
ArgParser::NameValue(_),
127138
) => {
128-
cx.dcx().emit_err(session_diagnostics::InvalidReprHintNoValue {
139+
cx.emit_err(session_diagnostics::InvalidReprHintNoValue {
129140
span: param.span(),
130141
name: ident.to_string(),
131142
});
132143
None
133144
}
134145
(sym::Rust | sym::C | sym::simd | sym::transparent | int_pat!(), ArgParser::List(_)) => {
135-
cx.dcx().emit_err(session_diagnostics::InvalidReprHintNoParen {
146+
cx.emit_err(session_diagnostics::InvalidReprHintNoParen {
136147
span: param.span(),
137148
name: ident.to_string(),
138149
});
139150
None
140151
}
141152

142153
_ => {
143-
cx.dcx().emit_err(session_diagnostics::UnrecognizedReprHint { span: param.span() });
154+
cx.emit_err(session_diagnostics::UnrecognizedReprHint { span: param.span() });
144155
None
145156
}
146157
}
@@ -162,7 +173,7 @@ fn parse_repr_align(
162173
let Some(align) = list.single() else {
163174
match align_kind {
164175
Packed => {
165-
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
176+
cx.emit_err(session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
166177
span: param_span,
167178
});
168179
}
@@ -179,12 +190,12 @@ fn parse_repr_align(
179190
let Some(lit) = align.lit() else {
180191
match align_kind {
181192
Packed => {
182-
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatPackedExpectInteger {
193+
cx.emit_err(session_diagnostics::IncorrectReprFormatPackedExpectInteger {
183194
span: align.span(),
184195
});
185196
}
186197
Align => {
187-
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatExpectInteger {
198+
cx.emit_err(session_diagnostics::IncorrectReprFormatExpectInteger {
188199
span: align.span(),
189200
});
190201
}
@@ -199,7 +210,7 @@ fn parse_repr_align(
199210
AlignKind::Align => ReprAttr::ReprAlign(literal),
200211
}),
201212
Err(message) => {
202-
cx.dcx().emit_err(session_diagnostics::InvalidReprGeneric {
213+
cx.emit_err(session_diagnostics::InvalidReprGeneric {
203214
span: lit.span,
204215
repr_arg: match align_kind {
205216
Packed => "packed".to_string(),
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.