Skip to content

Commit 25b2d2a

Browse files
authored
Unrolled build for #155364
Rollup merge of #155364 - nnethercote:reduce-err-struct-visibilities, r=Kivooeo Reduce diagnostic type visibilities. Most diagnostic types are only used within their own crate, and so have a `pub(crate)` visibility. We have some diagnostic types that are unnecessarily `pub`. This is bad because (a) information hiding, and (b) if a `pub(crate)` type becomes unused the compiler will warn but it won't warn for a `pub` type. This commit eliminates unnecessary `pub` visibilities for some diagnostic types, and also some related things due to knock-on effects. (I found these types with some ad hoc use of `grep`.) r? @Kivooeo
2 parents d227e48 + f3fc537 commit 25b2d2a

16 files changed

Lines changed: 173 additions & 173 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use rustc_hir::attrs::{
66
BorrowckGraphvizFormatKind, CguFields, CguKind, DivergingBlockBehavior,
77
DivergingFallbackBehavior, RustcCleanAttribute, RustcCleanQueries, RustcMirKind,
88
};
9-
use rustc_session::errors;
109
use rustc_span::Symbol;
1110

1211
use super::prelude::*;
1312
use super::util::parse_single_integer;
13+
use crate::errors;
1414
use crate::session_diagnostics::{
1515
AttributeRequiresOpt, CguFieldsMissing, RustcScalableVectorCountOutOfRange, UnknownLangItem,
1616
};

compiler/rustc_attr_parsing/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ pub(crate) struct UnreachableCfgSelectPredicateWildcard {
5050
#[label("always matches")]
5151
pub wildcard_span: Span,
5252
}
53+
54+
#[derive(Diagnostic)]
55+
#[diag("must be a name of an associated function")]
56+
pub(crate) struct MustBeNameOfAssociatedFunction {
57+
#[primary_span]
58+
pub span: Span,
59+
}

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ pub(crate) struct TargetFeatureSafeTrait {
10691069

10701070
#[derive(Diagnostic)]
10711071
#[diag("target feature `{$feature}` cannot be enabled with `#[target_feature]`: {$reason}")]
1072-
pub struct ForbiddenTargetFeatureAttr<'a> {
1072+
pub(crate) struct ForbiddenTargetFeatureAttr<'a> {
10731073
#[primary_span]
10741074
pub span: Span,
10751075
pub feature: &'a str,
@@ -1211,15 +1211,15 @@ pub(crate) struct ForbiddenCTargetFeature<'a> {
12111211
pub reason: &'a str,
12121212
}
12131213

1214-
pub struct TargetFeatureDisableOrEnable<'a> {
1214+
pub(crate) struct TargetFeatureDisableOrEnable<'a> {
12151215
pub features: &'a [&'a str],
12161216
pub span: Option<Span>,
12171217
pub missing_features: Option<MissingFeatures>,
12181218
}
12191219

12201220
#[derive(Subdiagnostic)]
12211221
#[help("add the missing features in a `target_feature` attribute")]
1222-
pub struct MissingFeatures;
1222+
pub(crate) struct MissingFeatures;
12231223

12241224
impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
12251225
fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind {
9292
}
9393
}
9494

95-
pub fn get_span_and_frames<'tcx>(
95+
pub(crate) fn get_span_and_frames<'tcx>(
9696
tcx: TyCtxtAt<'tcx>,
9797
stack: &[Frame<'tcx, impl Provenance, impl Sized>],
9898
) -> (Span, Vec<errors::FrameNote>) {

compiler/rustc_const_eval/src/errors.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,14 @@ pub(crate) struct InteriorMutableBorrowEscaping {
314314
"this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
315315
If your compilation actually takes a long time, you can safely allow the lint"
316316
)]
317-
pub struct LongRunning {
317+
pub(crate) struct LongRunning {
318318
#[help("the constant being evaluated")]
319319
pub item_span: Span,
320320
}
321321

322322
#[derive(Diagnostic)]
323323
#[diag("constant evaluation is taking a long time")]
324-
pub struct LongRunningWarn {
324+
pub(crate) struct LongRunningWarn {
325325
#[primary_span]
326326
#[label("the const evaluator is currently interpreting this expression")]
327327
pub span: Span,
@@ -339,7 +339,7 @@ pub(crate) struct NonConstImplNote {
339339
}
340340

341341
#[derive(Clone)]
342-
pub struct FrameNote {
342+
pub(crate) struct FrameNote {
343343
pub span: Span,
344344
pub times: i32,
345345
pub where_: &'static str,
@@ -377,7 +377,7 @@ impl Subdiagnostic for FrameNote {
377377

378378
#[derive(Subdiagnostic)]
379379
#[note(r#"the raw bytes of the constant (size: {$size}, align: {$align}) {"{"}{$bytes}{"}"}"#)]
380-
pub struct RawBytesNote {
380+
pub(crate) struct RawBytesNote {
381381
pub size: u64,
382382
pub align: u64,
383383
pub bytes: String,
@@ -393,7 +393,7 @@ pub struct RawBytesNote {
393393
}s"#
394394
)]
395395
#[note("`{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es")]
396-
pub struct NonConstMatchEq<'tcx> {
396+
pub(crate) struct NonConstMatchEq<'tcx> {
397397
#[primary_span]
398398
pub span: Span,
399399
pub ty: Ty<'tcx>,
@@ -408,7 +408,7 @@ pub struct NonConstMatchEq<'tcx> {
408408
[const_fn] constant function
409409
*[other] {""}
410410
}s"#, code = E0015)]
411-
pub struct NonConstForLoopIntoIter<'tcx> {
411+
pub(crate) struct NonConstForLoopIntoIter<'tcx> {
412412
#[primary_span]
413413
pub span: Span,
414414
pub ty: Ty<'tcx>,
@@ -423,7 +423,7 @@ pub struct NonConstForLoopIntoIter<'tcx> {
423423
[const_fn] constant function
424424
*[other] {""}
425425
}s"#, code = E0015)]
426-
pub struct NonConstQuestionBranch<'tcx> {
426+
pub(crate) struct NonConstQuestionBranch<'tcx> {
427427
#[primary_span]
428428
pub span: Span,
429429
pub ty: Ty<'tcx>,
@@ -438,7 +438,7 @@ pub struct NonConstQuestionBranch<'tcx> {
438438
[const_fn] constant function
439439
*[other] {""}
440440
}s"#, code = E0015)]
441-
pub struct NonConstQuestionFromResidual<'tcx> {
441+
pub(crate) struct NonConstQuestionFromResidual<'tcx> {
442442
#[primary_span]
443443
pub span: Span,
444444
pub ty: Ty<'tcx>,
@@ -453,7 +453,7 @@ pub struct NonConstQuestionFromResidual<'tcx> {
453453
[const_fn] constant function
454454
*[other] {""}
455455
}s"#, code = E0015)]
456-
pub struct NonConstTryBlockFromOutput<'tcx> {
456+
pub(crate) struct NonConstTryBlockFromOutput<'tcx> {
457457
#[primary_span]
458458
pub span: Span,
459459
pub ty: Ty<'tcx>,
@@ -468,7 +468,7 @@ pub struct NonConstTryBlockFromOutput<'tcx> {
468468
[const_fn] constant function
469469
*[other] {""}
470470
}s"#, code = E0015)]
471-
pub struct NonConstAwait<'tcx> {
471+
pub(crate) struct NonConstAwait<'tcx> {
472472
#[primary_span]
473473
pub span: Span,
474474
pub ty: Ty<'tcx>,
@@ -483,7 +483,7 @@ pub struct NonConstAwait<'tcx> {
483483
[const_fn] constant function
484484
*[other] {""}
485485
}s"#, code = E0015)]
486-
pub struct NonConstClosure {
486+
pub(crate) struct NonConstClosure {
487487
#[primary_span]
488488
pub span: Span,
489489
pub kind: ConstContext,
@@ -499,14 +499,14 @@ pub struct NonConstClosure {
499499
[const_fn] constant function
500500
*[other] {""}
501501
}s"#, code = E0015)]
502-
pub struct NonConstCVariadicCall {
502+
pub(crate) struct NonConstCVariadicCall {
503503
#[primary_span]
504504
pub span: Span,
505505
pub kind: ConstContext,
506506
}
507507

508508
#[derive(Subdiagnostic)]
509-
pub enum NonConstClosureNote {
509+
pub(crate) enum NonConstClosureNote {
510510
#[note("function defined here, but it is not `const`")]
511511
FnDef {
512512
#[primary_span]
@@ -534,7 +534,7 @@ pub enum NonConstClosureNote {
534534

535535
#[derive(Subdiagnostic)]
536536
#[multipart_suggestion("consider dereferencing here", applicability = "machine-applicable")]
537-
pub struct ConsiderDereferencing {
537+
pub(crate) struct ConsiderDereferencing {
538538
pub deref: String,
539539
#[suggestion_part(code = "{deref}")]
540540
pub span: Span,
@@ -549,7 +549,7 @@ pub struct ConsiderDereferencing {
549549
[const_fn] constant function
550550
*[other] {""}
551551
}s"#, code = E0015)]
552-
pub struct NonConstOperator {
552+
pub(crate) struct NonConstOperator {
553553
#[primary_span]
554554
pub span: Span,
555555
pub kind: ConstContext,
@@ -566,7 +566,7 @@ pub struct NonConstOperator {
566566
*[other] {""}
567567
}s"#, code = E0015)]
568568
#[note("attempting to deref into `{$target_ty}`")]
569-
pub struct NonConstDerefCoercion<'tcx> {
569+
pub(crate) struct NonConstDerefCoercion<'tcx> {
570570
#[primary_span]
571571
pub span: Span,
572572
pub ty: Ty<'tcx>,
@@ -579,7 +579,7 @@ pub struct NonConstDerefCoercion<'tcx> {
579579

580580
#[derive(Diagnostic)]
581581
#[diag("destructor of `{$dropped_ty}` cannot be evaluated at compile-time", code = E0493)]
582-
pub struct LiveDrop<'tcx> {
582+
pub(crate) struct LiveDrop<'tcx> {
583583
#[primary_span]
584584
#[label(
585585
r#"the destructor for this type cannot be evaluated in {$kind ->

compiler/rustc_const_eval/src/interpret/stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
223223
}
224224

225225
impl<'tcx> FrameInfo<'tcx> {
226-
pub fn as_note(&self, tcx: TyCtxt<'tcx>) -> errors::FrameNote {
226+
pub(crate) fn as_note(&self, tcx: TyCtxt<'tcx>) -> errors::FrameNote {
227227
let span = self.span;
228228
if tcx.def_key(self.instance.def_id()).disambiguated_data.data == DefPathData::Closure {
229229
errors::FrameNote {

compiler/rustc_driver_impl/src/session_diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_macros::{Diagnostic, Subdiagnostic};
44

55
#[derive(Diagnostic)]
66
#[diag("could not emit MIR: {$error}")]
7-
pub struct CantEmitMIR {
7+
pub(crate) struct CantEmitMIR {
88
pub error: std::io::Error,
99
}
1010

compiler/rustc_interface/src/errors.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(crate) struct CrateNameInvalid<'a> {
2525

2626
#[derive(Diagnostic)]
2727
#[diag("Ferris cannot be used as an identifier")]
28-
pub struct FerrisIdentifier {
28+
pub(crate) struct FerrisIdentifier {
2929
#[primary_span]
3030
pub spans: Vec<Span>,
3131
#[suggestion(
@@ -39,53 +39,53 @@ pub struct FerrisIdentifier {
3939

4040
#[derive(Diagnostic)]
4141
#[diag("identifiers cannot contain emoji: `{$ident}`")]
42-
pub struct EmojiIdentifier {
42+
pub(crate) struct EmojiIdentifier {
4343
#[primary_span]
4444
pub spans: Vec<Span>,
4545
pub ident: Symbol,
4646
}
4747

4848
#[derive(Diagnostic)]
4949
#[diag("cannot mix `bin` crate type with others")]
50-
pub struct MixedBinCrate;
50+
pub(crate) struct MixedBinCrate;
5151

5252
#[derive(Diagnostic)]
5353
#[diag("cannot mix `proc-macro` crate type with others")]
54-
pub struct MixedProcMacroCrate;
54+
pub(crate) struct MixedProcMacroCrate;
5555

5656
#[derive(Diagnostic)]
5757
#[diag("error writing dependencies to `{$path}`: {$error}")]
58-
pub struct ErrorWritingDependencies<'a> {
58+
pub(crate) struct ErrorWritingDependencies<'a> {
5959
pub path: &'a Path,
6060
pub error: io::Error,
6161
}
6262

6363
#[derive(Diagnostic)]
6464
#[diag("the input file \"{$path}\" would be overwritten by the generated executable")]
65-
pub struct InputFileWouldBeOverWritten<'a> {
65+
pub(crate) struct InputFileWouldBeOverWritten<'a> {
6666
pub path: &'a Path,
6767
}
6868

6969
#[derive(Diagnostic)]
7070
#[diag(
7171
"the generated executable for the input file \"{$input_path}\" conflicts with the existing directory \"{$dir_path}\""
7272
)]
73-
pub struct GeneratedFileConflictsWithDirectory<'a> {
73+
pub(crate) struct GeneratedFileConflictsWithDirectory<'a> {
7474
pub input_path: &'a Path,
7575
pub dir_path: &'a Path,
7676
}
7777

7878
#[derive(Diagnostic)]
7979
#[diag("failed to find or create the directory specified by `--temps-dir`")]
80-
pub struct TempsDirError;
80+
pub(crate) struct TempsDirError;
8181

8282
#[derive(Diagnostic)]
8383
#[diag("failed to find or create the directory specified by `--out-dir`")]
84-
pub struct OutDirError;
84+
pub(crate) struct OutDirError;
8585

8686
#[derive(Diagnostic)]
8787
#[diag("failed to write file {$path}: {$error}\"")]
88-
pub struct FailedWritingFile<'a> {
88+
pub(crate) struct FailedWritingFile<'a> {
8989
pub path: &'a Path,
9090
pub error: io::Error,
9191
}
@@ -94,25 +94,25 @@ pub struct FailedWritingFile<'a> {
9494
#[diag(
9595
"building proc macro crate with `panic=abort` or `panic=immediate-abort` may crash the compiler should the proc-macro panic"
9696
)]
97-
pub struct ProcMacroCratePanicAbort;
97+
pub(crate) struct ProcMacroCratePanicAbort;
9898

9999
#[derive(Diagnostic)]
100100
#[diag(
101101
"due to multiple output types requested, the explicitly specified output file name will be adapted for each output type"
102102
)]
103-
pub struct MultipleOutputTypesAdaption;
103+
pub(crate) struct MultipleOutputTypesAdaption;
104104

105105
#[derive(Diagnostic)]
106106
#[diag("ignoring -C extra-filename flag due to -o flag")]
107-
pub struct IgnoringExtraFilename;
107+
pub(crate) struct IgnoringExtraFilename;
108108

109109
#[derive(Diagnostic)]
110110
#[diag("ignoring --out-dir flag due to -o flag")]
111-
pub struct IgnoringOutDir;
111+
pub(crate) struct IgnoringOutDir;
112112

113113
#[derive(Diagnostic)]
114114
#[diag("can't use option `-o` or `--emit` to write multiple output types to stdout")]
115-
pub struct MultipleOutputTypesToStdout;
115+
pub(crate) struct MultipleOutputTypesToStdout;
116116

117117
#[derive(Diagnostic)]
118118
#[diag(

0 commit comments

Comments
 (0)