diff options
| author | bors <bors@rust-lang.org> | 2022-05-12 10:22:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-12 10:22:07 +0000 |
| commit | 18bd2dd5cda08b09ace6e37c1a0312e9b2bb4beb (patch) | |
| tree | c419def06148595c6765e3cf04ae84b45fe43c09 /src | |
| parent | 4f8e2e3ad9fce35dc356ee1e87170814e4112d76 (diff) | |
| parent | 47582471c61e15f9e409b45e11f2f15e61a88e29 (diff) | |
| download | rust-18bd2dd5cda08b09ace6e37c1a0312e9b2bb4beb.tar.gz rust-18bd2dd5cda08b09ace6e37c1a0312e9b2bb4beb.zip | |
Auto merge of #96853 - davidtwco:diagnostic-translation-unit-and-more-porting, r=oli-obk
diagnostics: port more diagnostics to derive + support for `()` fields - Extend diagnostic derive so that spanless subdiagnostics (e.g. some uses of `help`/`note`) can be applied via attributes to fields of type `()` (currently spanless subdiagnostics are applied via attributes on the diagnostic struct itself). A consequence of this is that `Option<()>` fields can be used to represent optional spanless subdiagnostics, which are sometimes useful (e.g. for a `help` that should only show on nightly builds). - Simplify the "explicit generic args with impl trait" diagnostic struct (from #96760) using support for `Option<()>` spanless subdiagnostics. - Change `DiagnosticBuilder::set_arg`, used to provide context for Fluent messages, so that it takes anything that implements `IntoDiagnosticArg`, rather than `DiagnosticArgValue` - this improves the ergonomics of manual implementations of `SessionDiagnostic` which are translatable. - Port "the type parameter `T` must be explicitly specified", "manual implementations of `X` are experimental", "could not resolve substs on overridden impl" diagnostics to diagnostic structs. - When testing macros from `rustc_macros` in `ui-fulldeps` tests, sometimes paths from the compiler source tree can be shown in error messages - these need to be normalized in `compiletest`. r? `@oli-obk` cc `@pvdrz`
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs | 24 | ||||
| -rw-r--r-- | src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr | 23 | ||||
| -rw-r--r-- | src/tools/compiletest/src/runtest.rs | 19 |
3 files changed, 48 insertions, 18 deletions
diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index c63410fa35b..1cdc5d18c28 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -327,7 +327,7 @@ struct ErrorWithDefaultLabelAttr<'a> { } #[derive(SessionDiagnostic)] -//~^ ERROR no method named `into_diagnostic_arg` found for struct `Hello` in the current scope +//~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied #[error(code = "E0123", slug = "foo")] struct ArgFieldWithoutSkip { #[primary_span] @@ -482,3 +482,25 @@ struct VecField { #[label] spans: Vec<Span>, } + +#[derive(SessionDiagnostic)] +#[error(code = "E0123", slug = "foo")] +struct UnitField { + #[primary_span] + spans: Span, + #[help] + foo: (), + #[help = "a"] + bar: (), +} + +#[derive(SessionDiagnostic)] +#[error(code = "E0123", slug = "foo")] +struct OptUnitField { + #[primary_span] + spans: Span, + #[help] + foo: Option<()>, + #[help = "a"] + bar: Option<()>, +} diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index b1738b60bc0..2583363120a 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -349,17 +349,26 @@ error: cannot find attribute `nonsense` in this scope LL | #[nonsense] | ^^^^^^^^ -error[E0599]: no method named `into_diagnostic_arg` found for struct `Hello` in the current scope +error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied --> $DIR/diagnostic-derive.rs:329:10 | -LL | struct Hello {} - | ------------ method `into_diagnostic_arg` not found for this -... LL | #[derive(SessionDiagnostic)] - | ^^^^^^^^^^^^^^^^^ method not found in `Hello` - | + | ^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello` + | + = help: the following other types implement trait `IntoDiagnosticArg`: + &'a str + Ident + String + Symbol + rustc_middle::ty::Ty<'tcx> + usize +note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg` + --> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:531:19 + | +LL | arg: impl IntoDiagnosticArg, + | ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg` = note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 43 previous errors -For more information about this error, try `rustc --explain E0599`. +For more information about this error, try `rustc --explain E0277`. diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 6d94fe3ebb9..a59a0584d5e 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -3494,22 +3494,21 @@ impl<'test> TestCx<'test> { normalize_path(parent_dir, "$DIR"); // Paths into the libstd/libcore - let src_dir = self - .config - .src_base - .parent() - .unwrap() - .parent() - .unwrap() - .parent() - .unwrap() - .join("library"); + let base_dir = self.config.src_base.parent().unwrap().parent().unwrap().parent().unwrap(); + let src_dir = base_dir.join("library"); normalize_path(&src_dir, "$SRC_DIR"); + // `ui-fulldeps` tests can show paths to the compiler source when testing macros from + // `rustc_macros` + // eg. /home/user/rust/compiler + let compiler_src_dir = base_dir.join("compiler"); + normalize_path(&compiler_src_dir, "$COMPILER_DIR"); + if let Some(virtual_rust_source_base_dir) = option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(PathBuf::from) { normalize_path(&virtual_rust_source_base_dir.join("library"), "$SRC_DIR"); + normalize_path(&virtual_rust_source_base_dir.join("compiler"), "$COMPILER_DIR"); } // Paths into the build directory |
