Skip to content

Commit 6064db8

Browse files
committed
fix tests
1 parent 929ad69 commit 6064db8

Some content is hidden

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

49 files changed

+481
-450
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub enum ReprAttr {
6262
ReprSimd,
6363
ReprTransparent,
6464
ReprAlign(Align),
65+
// this one is just so we can emit a lint for it
66+
ReprEmpty,
6567
}
6668
pub use ReprAttr::*;
6769

@@ -147,7 +149,7 @@ pub enum AttributeKind {
147149
Allow,
148150
AllowConstFnUnstable(ThinVec<Symbol>),
149151
AllowInternalUnsafe,
150-
AllowInternalUnstable(ThinVec<Symbol>),
152+
AllowInternalUnstable(ThinVec<(Symbol, Span)>),
151153
AutoDiff,
152154
AutomaticallyDerived,
153155
BodyStability {

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use std::iter;
2+
13
use rustc_attr_data_structures::AttributeKind;
2-
use rustc_span::{Symbol, sym};
4+
use rustc_span::{sym, Span, Symbol};
35

46
use super::{CombineAttributeGroup, ConvertFn};
57
use crate::context::AttributeAcceptContext;
@@ -9,14 +11,14 @@ use crate::session_diagnostics;
911
pub(crate) struct AllowInternalUnstableGroup;
1012
impl CombineAttributeGroup for AllowInternalUnstableGroup {
1113
const PATH: &'static [rustc_span::Symbol] = &[sym::allow_internal_unstable];
12-
type Item = Symbol;
14+
type Item = (Symbol, Span);
1315
const CONVERT: ConvertFn<Self::Item> = AttributeKind::AllowInternalUnstable;
1416

1517
fn extend<'a>(
1618
cx: &'a AttributeAcceptContext<'a>,
1719
args: &'a ArgParser<'a>,
1820
) -> impl IntoIterator<Item = Self::Item> + 'a {
19-
parse_unstable(cx, args, Self::PATH[0])
21+
parse_unstable(cx, args, Self::PATH[0]).into_iter().zip(iter::repeat(cx.attr_span))
2022
}
2123
}
2224

@@ -42,7 +44,7 @@ fn parse_unstable<'a>(
4244
let mut res = Vec::new();
4345

4446
let Some(list) = args.list() else {
45-
cx.dcx().emit_err(session_diagnostics::ExpectsFeatureList {
47+
cx.emit_err(session_diagnostics::ExpectsFeatureList {
4648
span: cx.attr_span,
4749
name: symbol.to_ident_string(),
4850
});
@@ -54,7 +56,7 @@ fn parse_unstable<'a>(
5456
if let Some(ident) = param.meta_item().and_then(|i| i.word_without_args()) {
5557
res.push(ident.name);
5658
} else {
57-
cx.dcx().emit_err(session_diagnostics::ExpectsFeatures {
59+
cx.emit_err(session_diagnostics::ExpectsFeatures {
5860
span: param_span,
5961
name: symbol.to_ident_string(),
6062
});

compiler/rustc_attr_parsing/src/attributes/confusables.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ impl AttributeGroup for ConfusablesGroup {
2424
};
2525

2626
if list.is_empty() {
27-
cx.dcx().emit_err(session_diagnostics::EmptyConfusables { span: cx.attr_span });
27+
cx.emit_err(session_diagnostics::EmptyConfusables { span: cx.attr_span });
2828
}
2929

3030
for param in list.mixed() {
3131
let span = param.span();
3232

3333
let Some(lit) = param.lit() else {
34-
cx.dcx().emit_err(session_diagnostics::IncorrectMetaItem {
34+
cx.emit_err(session_diagnostics::IncorrectMetaItem {
3535
span,
3636
suggestion: Some(session_diagnostics::IncorrectMetaItemSuggestion {
3737
lo: span.shrink_to_lo(),

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

+10-10
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,7 +41,7 @@ fn get(
4141
}
4242
} else {
4343
// FIXME(jdonszelmann): suggestion?
44-
cx.dcx().emit_err(session_diagnostics::IncorrectMetaItem {
44+
cx.emit_err(session_diagnostics::IncorrectMetaItem {
4545
span: param_span,
4646
suggestion: None,
4747
});
@@ -54,7 +54,7 @@ impl SingleAttributeGroup for DeprecationGroup {
5454

5555
fn on_duplicate(cx: &AttributeAcceptContext<'_>, first_span: rustc_span::Span) {
5656
// FIXME(jdonszelmann): merge with errors from check_attrs.rs
57-
cx.dcx().emit_err(session_diagnostics::UnusedMultiple {
57+
cx.emit_err(session_diagnostics::UnusedMultiple {
5858
this: cx.attr_span,
5959
other: first_span,
6060
name: sym::deprecated,
@@ -78,7 +78,7 @@ impl SingleAttributeGroup for DeprecationGroup {
7878
for param in list.mixed() {
7979
let param_span = param.span();
8080
let Some(param) = param.meta_item() else {
81-
cx.dcx().emit_err(session_diagnostics::UnsupportedLiteral {
81+
cx.emit_err(session_diagnostics::UnsupportedLiteral {
8282
span: param_span,
8383
reason: UnsupportedLiteralReason::DeprecatedKvPair,
8484
is_bytestr: false,
@@ -102,7 +102,7 @@ impl SingleAttributeGroup for DeprecationGroup {
102102
}
103103
sym::suggestion => {
104104
if !features.deprecated_suggestion() {
105-
cx.dcx().emit_err(session_diagnostics::DeprecatedItemSuggestion {
105+
cx.emit_err(session_diagnostics::DeprecatedItemSuggestion {
106106
span: param_span,
107107
is_nightly: cx.sess().is_nightly_build(),
108108
details: (),
@@ -114,7 +114,7 @@ impl SingleAttributeGroup for DeprecationGroup {
114114
}
115115
}
116116
_ => {
117-
cx.dcx().emit_err(session_diagnostics::UnknownMetaItem {
117+
cx.emit_err(session_diagnostics::UnknownMetaItem {
118118
span: param_span,
119119
item: ident.to_string(),
120120
expected: if features.deprecated_suggestion() {
@@ -137,18 +137,18 @@ impl SingleAttributeGroup for DeprecationGroup {
137137
} else if let Some(version) = parse_version(since) {
138138
DeprecatedSince::RustcVersion(version)
139139
} else {
140-
cx.dcx().emit_err(session_diagnostics::InvalidSince { span: cx.attr_span });
140+
cx.emit_err(session_diagnostics::InvalidSince { span: cx.attr_span });
141141
DeprecatedSince::Err
142142
}
143143
} else if is_rustc {
144-
cx.dcx().emit_err(session_diagnostics::MissingSince { span: cx.attr_span });
144+
cx.emit_err(session_diagnostics::MissingSince { span: cx.attr_span });
145145
DeprecatedSince::Err
146146
} else {
147147
DeprecatedSince::Unspecified
148148
};
149149

150150
if is_rustc && note.is_none() {
151-
cx.dcx().emit_err(session_diagnostics::MissingNote { span: cx.attr_span });
151+
cx.emit_err(session_diagnostics::MissingNote { span: cx.attr_span });
152152
return None;
153153
}
154154

compiler/rustc_attr_parsing/src/attributes/repr.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,19 @@ impl CombineAttributeGroup for ReprGroup {
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() {
43+
if let Some(_) = param.lit() {
44+
cx.emit_err(session_diagnostics::ReprIdent {
45+
span: cx.attr_span,
46+
});
47+
continue;
48+
}
49+
3850
let span = param.span();
3951
reprs.extend(param.meta_item().and_then(|mi| parse_repr(cx, &mi)).map(|r| (r, span)));
4052
}
@@ -93,7 +105,7 @@ fn parse_repr(
93105

94106
match (ident.name, args) {
95107
(sym::align, ArgParser::NoArgs) => {
96-
cx.dcx().emit_err(session_diagnostics::InvalidReprAlignNeedArg { span: ident.span });
108+
cx.emit_err(session_diagnostics::InvalidReprAlignNeedArg { span: ident.span });
97109
None
98110
}
99111
(sym::align, ArgParser::List(l)) => parse_repr_align(cx, l, param.span(), AlignKind::Align),
@@ -102,7 +114,7 @@ fn parse_repr(
102114
(sym::packed, ArgParser::List(l)) => parse_repr_align(cx, l, param.span(), AlignKind::Packed),
103115

104116
(sym::align | sym::packed, ArgParser::NameValue(l)) => {
105-
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatGeneric {
117+
cx.emit_err(session_diagnostics::IncorrectReprFormatGeneric {
106118
span: param.span(),
107119
// FIXME(jdonszelmann) can just be a string in the diag type
108120
repr_arg: &ident.to_string(),
@@ -133,22 +145,22 @@ fn parse_repr(
133145
}
134146

135147
(sym::Rust | sym::C | sym::simd | sym::transparent | int_pat!(), ArgParser::NameValue(_)) => {
136-
cx.dcx().emit_err(session_diagnostics::InvalidReprHintNoValue {
148+
cx.emit_err(session_diagnostics::InvalidReprHintNoValue {
137149
span: param.span(),
138150
name: ident.to_string(),
139151
});
140152
None
141153
}
142154
(sym::Rust | sym::C | sym::simd | sym::transparent | int_pat!(), ArgParser::List(_)) => {
143-
cx.dcx().emit_err(session_diagnostics::InvalidReprHintNoParen {
155+
cx.emit_err(session_diagnostics::InvalidReprHintNoParen {
144156
span: param.span(),
145157
name: ident.to_string(),
146158
});
147159
None
148160
}
149161

150162
_ => {
151-
cx.dcx().emit_err(session_diagnostics::UnrecognizedReprHint { span: param.span() });
163+
cx.emit_err(session_diagnostics::UnrecognizedReprHint { span: param.span() });
152164
None
153165
}
154166
}
@@ -165,7 +177,7 @@ fn parse_repr_align(cx: &AttributeAcceptContext<'_>, list: &MetaItemListParser<'
165177
let Some(align) = list.single() else {
166178
match align_kind {
167179
Packed => {
168-
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
180+
cx.emit_err(session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
169181
span: param_span,
170182
});
171183
},
@@ -181,12 +193,12 @@ fn parse_repr_align(cx: &AttributeAcceptContext<'_>, list: &MetaItemListParser<'
181193
let Some(lit) = align.lit() else {
182194
match align_kind {
183195
Packed => {
184-
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatPackedExpectInteger {
196+
cx.emit_err(session_diagnostics::IncorrectReprFormatPackedExpectInteger {
185197
span: align.span(),
186198
});
187199
},
188200
Align => {
189-
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatExpectInteger {
201+
cx.emit_err(session_diagnostics::IncorrectReprFormatExpectInteger {
190202
span: align.span(),
191203
});
192204
}
@@ -201,7 +213,7 @@ fn parse_repr_align(cx: &AttributeAcceptContext<'_>, list: &MetaItemListParser<'
201213
AlignKind::Align => ReprAttr::ReprAlign(literal),
202214
}),
203215
Err(message) => {
204-
cx.dcx().emit_err(session_diagnostics::InvalidReprGeneric {
216+
cx.emit_err(session_diagnostics::InvalidReprGeneric {
205217
span: lit.span,
206218
repr_arg: match align_kind {
207219
Packed => "packed".to_string(),

0 commit comments

Comments
 (0)