Skip to content

Commit 4aaff39

Browse files
committed
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_data_structures/src/attributes.rs

+4-4
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

@@ -139,13 +141,11 @@ impl Deprecation {
139141
/// happen.
140142
///
141143
/// For more docs, look in [`rustc_attr`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_attr/index.html)
142-
// FIXME(jdonszelmann): rename to AttributeKind once hir::AttributeKind is dissolved
143144
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable)]
144145
pub enum AttributeKind {
145146
// tidy-alphabetical-start
146147
AllowConstFnUnstable(ThinVec<Symbol>),
147-
AllowInternalUnsafe,
148-
AllowInternalUnstable(ThinVec<Symbol>),
148+
AllowInternalUnstable(ThinVec<(Symbol, Span)>),
149149
BodyStability {
150150
stability: DefaultBodyStability,
151151
/// Span of the `#[rustc_default_body_unstable(...)]` attribute
@@ -174,7 +174,7 @@ pub enum AttributeKind {
174174
comment: Symbol,
175175
},
176176
MacroTransparency(Transparency),
177-
Repr(ThinVec<ReprAttr>),
177+
Repr(ThinVec<(ReprAttr, Span)>),
178178
Stability {
179179
stability: Stability,
180180
/// Span of the `#[stable(...)]` or `#[unstable(...)]` attribute

compiler/rustc_attr_parsing/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ attr_parsing_non_ident_feature =
9292
9393
attr_parsing_repr_ident =
9494
meta item in `repr` must be an identifier
95+
9596
attr_parsing_rustc_allowed_unstable_pairing =
9697
`rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute
9798

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::{Span, Symbol, sym};
35

46
use super::{CombineAttributeParser, ConvertFn};
57
use crate::context::AcceptContext;
@@ -9,14 +11,14 @@ use crate::session_diagnostics;
911
pub(crate) struct AllowInternalUnstableParser;
1012
impl CombineAttributeParser for AllowInternalUnstableParser {
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 AcceptContext<'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/cfg.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// TODO: convert cfg properly.... And learn how cfg works I guess
21
use rustc_ast::{LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, NodeId};
32
use rustc_ast_pretty::pprust;
43
use rustc_attr_data_structures::RustcVersion;

compiler/rustc_attr_parsing/src/attributes/confusables.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ pub(crate) struct ConfusablesParser {
1515
impl AttributeParser for ConfusablesParser {
1616
const ATTRIBUTES: AcceptMapping<Self> = &[(&[sym::rustc_confusables], |this, cx, args| {
1717
let Some(list) = args.list() else {
18-
// TODO: error when not a list? Bring validation code here.
18+
// FIXME(jdonszelmann): error when not a list? Bring validation code here.
1919
// NOTE: currently subsequent attributes are silently ignored using
2020
// tcx.get_attr().
2121
return;
2222
};
2323

2424
if list.is_empty() {
25-
cx.dcx().emit_err(session_diagnostics::EmptyConfusables { span: cx.attr_span });
25+
cx.emit_err(session_diagnostics::EmptyConfusables { span: cx.attr_span });
2626
}
2727

2828
for param in list.mixed() {
2929
let span = param.span();
3030

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

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(),

0 commit comments

Comments
 (0)