Skip to content

Commit cf79d03

Browse files
committed
Auto merge of #155720 - jhpratt:rollup-OEB9tQ5, r=jhpratt
Rollup of 9 pull requests Successful merges: - #155684 (Generalize IO Traits for `Arc<T>` where `&T: IoTrait`) - #155081 (Move and clean up some ui test) - #155379 (Avoid query cycles in DataflowConstProp) - #155663 (Eliminate `CrateMetadataRef`.) - #155669 (Add `Sender` diagnostic item for `std::sync::mpsc::Sender`) - #155698 (Syntactically reject tuple index shorthands in struct patterns to fix a correctness regression) - #155703 (Remove myself as a maintainer of `wasm32-wasip1-threads`) - #155706 (Remove `AttributeLintKind` variants - part 7) - #155712 (Forbid `*-pass` and `*-fail` directives in tests/crashes)
2 parents d493b7c + a2622ef commit cf79d03

77 files changed

Lines changed: 555 additions & 694 deletions

File tree

Some content is hidden

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

compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir::attrs::diagnostic::{
66
Directive, FilterFormatString, Flag, FormatArg, FormatString, LitOrArg, Name, NameValue,
77
OnUnimplementedCondition, Piece, Predicate,
88
};
9-
use rustc_hir::lints::{AttributeLintKind, FormatWarning};
9+
use rustc_hir::lints::FormatWarning;
1010
use rustc_macros::Diagnostic;
1111
use rustc_parse_format::{
1212
Argument, FormatSpec, ParseError, ParseMode, Parser, Piece as RpfPiece, Position,
@@ -20,7 +20,8 @@ use thin_vec::{ThinVec, thin_vec};
2020
use crate::context::{AcceptContext, Stage};
2121
use crate::errors::{
2222
DisallowedPlaceholder, DisallowedPositionalArgument, IgnoredDiagnosticOption,
23-
InvalidFormatSpecifier, MalFormedDiagnosticAttributeLint, WrappedParserError,
23+
InvalidFormatSpecifier, MalFormedDiagnosticAttributeLint, MissingOptionsForDiagnosticAttribute,
24+
NonMetaItemDiagnosticAttribute, WrappedParserError,
2425
};
2526
use crate::parser::{ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser};
2627

@@ -144,18 +145,21 @@ fn parse_list<'p, S: Stage>(
144145
// We're dealing with `#[diagnostic::attr()]`.
145146
// This can be because that is what the user typed, but that's also what we'd see
146147
// if the user used non-metaitem syntax. See `ArgParser::from_attr_args`.
147-
cx.emit_lint(
148+
cx.emit_dyn_lint(
148149
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
149-
AttributeLintKind::NonMetaItemDiagnosticAttribute,
150+
move |dcx, level| NonMetaItemDiagnosticAttribute.into_diag(dcx, level),
150151
list.span,
151152
);
152153
}
153154
ArgParser::NoArgs => {
154-
cx.emit_lint(
155+
cx.emit_dyn_lint(
155156
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
156-
AttributeLintKind::MissingOptionsForDiagnosticAttribute {
157-
attribute: mode.as_str(),
158-
options: mode.expected_options(),
157+
move |dcx, level| {
158+
MissingOptionsForDiagnosticAttribute {
159+
attribute: mode.as_str(),
160+
options: mode.expected_options(),
161+
}
162+
.into_diag(dcx, level)
159163
},
160164
span,
161165
);

compiler/rustc_attr_parsing/src/errors.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,18 @@ pub(crate) struct IgnoredDiagnosticOption {
392392
#[label("`{$option_name}` is later redundantly declared here")]
393393
pub later_span: Span,
394394
}
395+
396+
#[derive(Diagnostic)]
397+
#[diag("missing options for `{$attribute}` attribute")]
398+
#[help("{$options}")]
399+
pub(crate) struct MissingOptionsForDiagnosticAttribute {
400+
pub attribute: &'static str,
401+
pub options: &'static str,
402+
}
403+
404+
#[derive(Diagnostic)]
405+
#[diag("expected a literal or missing delimiter")]
406+
#[help(
407+
"only literals are allowed as values for the `message`, `note` and `label` options. These options must be separated by a comma"
408+
)]
409+
pub(crate) struct NonMetaItemDiagnosticAttribute;

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use rustc_hir::lints::AttributeLintKind;
66
use rustc_middle::ty::TyCtxt;
77
use rustc_session::Session;
88

9-
use crate::lints;
10-
119
mod check_cfg;
1210

1311
pub struct DiagAndSess<'sess> {
@@ -42,14 +40,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> {
4240
check_cfg::unexpected_cfg_value(self.sess, self.tcx, name, value)
4341
.into_diag(dcx, level)
4442
}
45-
46-
&AttributeLintKind::MissingOptionsForDiagnosticAttribute { attribute, options } => {
47-
lints::MissingOptionsForDiagnosticAttribute { attribute, options }
48-
.into_diag(dcx, level)
49-
}
50-
&AttributeLintKind::NonMetaItemDiagnosticAttribute => {
51-
lints::NonMetaItemDiagnosticAttribute.into_diag(dcx, level)
52-
}
5343
}
5444
}
5545
}

compiler/rustc_lint/src/lints.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,22 +3282,7 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
32823282
}
32833283
}
32843284

3285-
#[derive(Diagnostic)]
3286-
#[diag("missing options for `{$attribute}` attribute")]
3287-
#[help("{$options}")]
3288-
pub(crate) struct MissingOptionsForDiagnosticAttribute {
3289-
pub attribute: &'static str,
3290-
pub options: &'static str,
3291-
}
3292-
32933285
#[derive(Diagnostic)]
32943286
#[diag("`Eq::assert_receiver_is_total_eq` should never be implemented by hand")]
32953287
#[note("this method was used to add checks to the `Eq` derive macro")]
32963288
pub(crate) struct EqInternalMethodImplemented;
3297-
3298-
#[derive(Diagnostic)]
3299-
#[diag("expected a literal or missing delimiter")]
3300-
#[help(
3301-
"only literals are allowed as values for the `message`, `note` and `label` options. These options must be separated by a comma"
3302-
)]
3303-
pub(crate) struct NonMetaItemDiagnosticAttribute;

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,6 @@ pub enum DeprecatedSinceKind {
656656
pub enum AttributeLintKind {
657657
UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>),
658658
UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>),
659-
MissingOptionsForDiagnosticAttribute { attribute: &'static str, options: &'static str },
660-
NonMetaItemDiagnosticAttribute,
661659
}
662660

663661
#[derive(Debug, Clone, HashStable_Generic)]

compiler/rustc_metadata/src/creader.rs

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,6 @@ enum LoadResult {
111111
Loaded(Library),
112112
}
113113

114-
/// A reference to `CrateMetadata` that can also give access to whole crate store when necessary.
115-
#[derive(Clone, Copy)]
116-
pub(crate) struct CrateMetadataRef<'a> {
117-
pub cdata: &'a CrateMetadata,
118-
pub cstore: &'a CStore,
119-
}
120-
121-
impl std::ops::Deref for CrateMetadataRef<'_> {
122-
type Target = CrateMetadata;
123-
124-
fn deref(&self) -> &Self::Target {
125-
self.cdata
126-
}
127-
}
128-
129114
struct CrateDump<'a>(&'a CStore);
130115

131116
impl<'a> std::fmt::Debug for CrateDump<'a> {
@@ -245,11 +230,8 @@ impl CStore {
245230
self.metas[cnum].is_some()
246231
}
247232

248-
pub(crate) fn get_crate_data(&self, cnum: CrateNum) -> CrateMetadataRef<'_> {
249-
let cdata = self.metas[cnum]
250-
.as_ref()
251-
.unwrap_or_else(|| panic!("Failed to get crate data for {cnum:?}"));
252-
CrateMetadataRef { cdata, cstore: self }
233+
pub(crate) fn get_crate_data(&self, cnum: CrateNum) -> &CrateMetadata {
234+
self.metas[cnum].as_ref().unwrap_or_else(|| panic!("Failed to get crate data for {cnum:?}"))
253235
}
254236

255237
pub(crate) fn get_crate_data_mut(&mut self, cnum: CrateNum) -> &mut CrateMetadata {
@@ -284,14 +266,13 @@ impl CStore {
284266
}
285267

286268
pub fn all_proc_macro_def_ids(&self, tcx: TyCtxt<'_>) -> impl Iterator<Item = DefId> {
287-
self.iter_crate_data()
288-
.flat_map(move |(krate, data)| data.proc_macros_for_crate(tcx, krate, self))
269+
self.iter_crate_data().flat_map(move |(krate, data)| data.proc_macros_for_crate(tcx, krate))
289270
}
290271

291272
fn push_dependencies_in_postorder(&self, deps: &mut IndexSet<CrateNum>, cnum: CrateNum) {
292273
if !deps.contains(&cnum) {
293-
let data = self.get_crate_data(cnum);
294-
for dep in data.dependencies() {
274+
let cdata = self.get_crate_data(cnum);
275+
for dep in cdata.dependencies() {
295276
if dep != cnum {
296277
self.push_dependencies_in_postorder(deps, dep);
297278
}
@@ -676,7 +657,6 @@ impl CStore {
676657

677658
let crate_metadata = CrateMetadata::new(
678659
tcx,
679-
self,
680660
metadata,
681661
crate_root,
682662
raw_proc_macros,
@@ -865,12 +845,12 @@ impl CStore {
865845
// `private-dependency` when `register_crate` is called for the first time. Then it must be updated to
866846
// `public-dependency` here.
867847
let private_dep = self.is_private_dep(&tcx.sess.opts.externs, name, private_dep);
868-
let data = self.get_crate_data_mut(cnum);
869-
if data.is_proc_macro_crate() {
848+
let cdata = self.get_crate_data_mut(cnum);
849+
if cdata.is_proc_macro_crate() {
870850
dep_kind = CrateDepKind::MacrosOnly;
871851
}
872-
data.set_dep_kind(cmp::max(data.dep_kind(), dep_kind));
873-
data.update_and_private_dep(private_dep);
852+
cdata.set_dep_kind(cmp::max(cdata.dep_kind(), dep_kind));
853+
cdata.update_and_private_dep(private_dep);
874854
Ok(cnum)
875855
}
876856
(LoadResult::Loaded(library), host_library) => {
@@ -1045,14 +1025,14 @@ impl CStore {
10451025
) else {
10461026
return;
10471027
};
1048-
let data = self.get_crate_data(cnum);
1028+
let cdata = self.get_crate_data(cnum);
10491029

10501030
// Sanity check the loaded crate to ensure it is indeed a panic runtime
10511031
// and the panic strategy is indeed what we thought it was.
1052-
if !data.is_panic_runtime() {
1032+
if !cdata.is_panic_runtime() {
10531033
tcx.dcx().emit_err(errors::CrateNotPanicRuntime { crate_name: name });
10541034
}
1055-
if data.required_panic_strategy() != Some(desired_strategy) {
1035+
if cdata.required_panic_strategy() != Some(desired_strategy) {
10561036
tcx.dcx()
10571037
.emit_err(errors::NoPanicStrategy { crate_name: name, strategy: desired_strategy });
10581038
}
@@ -1086,10 +1066,10 @@ impl CStore {
10861066
) else {
10871067
return;
10881068
};
1089-
let data = self.get_crate_data(cnum);
1069+
let cdata = self.get_crate_data(cnum);
10901070

10911071
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
1092-
if !data.is_profiler_runtime() {
1072+
if !cdata.is_profiler_runtime() {
10931073
tcx.dcx().emit_err(errors::NotProfilerRuntime { crate_name: name });
10941074
}
10951075
}
@@ -1243,9 +1223,9 @@ impl CStore {
12431223
};
12441224

12451225
// Sanity check that the loaded crate is `#![compiler_builtins]`
1246-
let cmeta = self.get_crate_data(cnum);
1247-
if !cmeta.is_compiler_builtins() {
1248-
tcx.dcx().emit_err(errors::CrateNotCompilerBuiltins { crate_name: cmeta.name() });
1226+
let cdata = self.get_crate_data(cnum);
1227+
if !cdata.is_compiler_builtins() {
1228+
tcx.dcx().emit_err(errors::CrateNotCompilerBuiltins { crate_name: cdata.name() });
12491229
}
12501230
}
12511231

0 commit comments

Comments
 (0)