diff options
| author | clubby789 <jamie@hill-daniel.co.uk> | 2023-05-16 19:08:57 +0000 |
|---|---|---|
| committer | clubby789 <jamie@hill-daniel.co.uk> | 2023-05-16 20:30:48 +0000 |
| commit | eaf47a30cb67bf1e802ee29bb8021b19a4df6095 (patch) | |
| tree | f09c4bfba85785403c4314c322d4c04c74473b76 /compiler/rustc_resolve/src | |
| parent | b652d9a0fd5c5a7eeacd1ae8299166941c221230 (diff) | |
| download | rust-eaf47a30cb67bf1e802ee29bb8021b19a4df6095.tar.gz rust-eaf47a30cb67bf1e802ee29bb8021b19a4df6095.zip | |
Better diagnostic for `use Self::..`
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/diagnostics.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 6675b8ed59b..5b7d9e40e86 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1832,7 +1832,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } (msg, None) } else if ident.name == kw::SelfUpper { - ("`Self` is only available in impls, traits, and type definitions".to_string(), None) + // As mentioned above, `opt_ns` being `None` indicates a module path in import. + // We can use this to improve a confusing error for, e.g. `use Self::Variant` in an + // impl + if opt_ns.is_none() { + ("`Self` cannot be used in imports".to_string(), None) + } else { + ( + "`Self` is only available in impls, traits, and type definitions".to_string(), + None, + ) + } } else if ident.name.as_str().chars().next().map_or(false, |c| c.is_ascii_uppercase()) { // Check whether the name refers to an item in the value namespace. let binding = if let Some(ribs) = ribs { |
