diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index d9132ca123490..d08d5a5a1ea29 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -3544,6 +3544,8 @@ pub fn detect_confusion_type(sm: &SourceMap, suggested: &str, sp: Span) -> Confu let mut has_digit_letter_confusable = false; let mut has_other_diff = false; + // Letters whose lowercase version is very similar to the uppercase + // version. let ascii_confusables = &['c', 'f', 'i', 'k', 'o', 's', 'u', 'v', 'w', 'x', 'y', 'z']; let digit_letter_confusables = [('0', 'O'), ('1', 'l'), ('5', 'S'), ('8', 'B'), ('9', 'g')]; diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index b8dda9ed57431..313cd41fe9896 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1366,7 +1366,7 @@ impl<'a> DiagCtxtHandle<'a> { self.create_err(err).emit() } - /// Ensures that an error is printed. See `Level::DelayedBug`. + /// Ensures that an error is printed. See [`Level::DelayedBug`]. // // No `#[rustc_lint_diagnostics]` and no `impl Into` because bug messages aren't // user-facing. diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index 7055e60956a9c..bc81acefef743 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -512,7 +512,7 @@ parse_keyword_lifetime = lifetimes cannot use keyword names parse_kw_bad_case = keyword `{$kw}` is written in the wrong case - .suggestion = write it in the correct case + .suggestion = write it in {$case} parse_label_inner_attr_does_not_annotate_this = the inner attribute doesn't annotate this {$item} parse_label_unexpected_token = unexpected token diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 62a333fbf81d7..9344848c76531 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -1,14 +1,15 @@ // ignore-tidy-filelength use std::borrow::Cow; +use std::path::PathBuf; use rustc_ast::token::Token; use rustc_ast::util::parser::ExprPrecedence; use rustc_ast::{Path, Visibility}; use rustc_errors::codes::*; use rustc_errors::{ - Applicability, Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, Subdiagnostic, - SuggestionStyle, + Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, + Level, Subdiagnostic, SuggestionStyle, }; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_session::errors::ExprParenthesesNeeded; @@ -3335,6 +3336,24 @@ pub(crate) struct KwBadCase<'a> { #[suggestion(code = "{kw}", style = "verbose", applicability = "machine-applicable")] pub span: Span, pub kw: &'a str, + pub case: Case, +} + +pub(crate) enum Case { + Upper, + Lower, + Mixed, +} + +impl IntoDiagArg for Case { + fn into_diag_arg(self, path: &mut Option) -> DiagArgValue { + match self { + Case::Upper => "uppercase", + Case::Lower => "lowercase", + Case::Mixed => "the correct case", + } + .into_diag_arg(path) + } } #[derive(Diagnostic)] diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 14a738fb9d247..8577ea40589a8 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -606,7 +606,20 @@ impl<'a> Parser<'a> { // Do an ASCII case-insensitive match, because all keywords are ASCII. && ident.as_str().eq_ignore_ascii_case(exp.kw.as_str()) { - self.dcx().emit_err(errors::KwBadCase { span: ident.span, kw: exp.kw.as_str() }); + let kw = exp.kw.as_str(); + let is_upper = kw.chars().all(char::is_uppercase); + let is_lower = kw.chars().all(char::is_lowercase); + + let case = match (is_upper, is_lower) { + (true, true) => { + unreachable!("keyword that is both fully upper- and fully lowercase") + } + (true, false) => errors::Case::Upper, + (false, true) => errors::Case::Lower, + (false, false) => errors::Case::Mixed, + }; + + self.dcx().emit_err(errors::KwBadCase { span: ident.span, kw, case }); self.bump(); true } else { diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index fe299a6cebca7..1cdb4cc67dfff 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1902,7 +1902,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { if span.overlaps(def_span) { // Don't suggest typo suggestion for itself like in the following: // error[E0423]: expected function, tuple struct or tuple variant, found struct `X` - // --> $DIR/issue-64792-bad-unicode-ctor.rs:3:14 + // --> $DIR/unicode-string-literal-syntax-error-64792.rs:4:14 // | // LL | struct X {} // | ----------- `X` defined here diff --git a/compiler/rustc_ty_utils/src/layout/invariant.rs b/compiler/rustc_ty_utils/src/layout/invariant.rs index d1484aed16718..01435f7e67a46 100644 --- a/compiler/rustc_ty_utils/src/layout/invariant.rs +++ b/compiler/rustc_ty_utils/src/layout/invariant.rs @@ -281,10 +281,16 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou } // Ensure that for niche encoded tags the discriminant coincides with the variant index. - assert_eq!( - layout.ty.discriminant_for_variant(tcx, idx).unwrap().val, - u128::from(idx.as_u32()), - ); + let val = layout.ty.discriminant_for_variant(tcx, idx).unwrap().val; + if val != u128::from(idx.as_u32()) { + let adt_def = layout.ty.ty_adt_def().unwrap(); + cx.tcx().dcx().span_delayed_bug( + cx.tcx().def_span(adt_def.did()), + format!( + "variant {idx:?} has discriminant {val:?} in niche-encoded type" + ), + ); + } } } for variant in variants.iter() { diff --git a/src/tools/rust-analyzer/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs b/src/tools/rust-analyzer/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs index 425bd9bb37a52..92e9038554eb6 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs @@ -962,8 +962,6 @@ impl Reader<'_, T> { }; res[i] = Some(g); } - proc_macro_srv::TokenStream::new(vec![proc_macro_srv::TokenTree::Group( - res[0].take().unwrap(), - )]) + res[0].take().unwrap().stream.unwrap_or_default() } } diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs index ad3d9eef957f2..20507a6def54d 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs @@ -297,26 +297,38 @@ fn test_fn_like_macro_noop() { fn test_fn_like_macro_clone_ident_subtree() { assert_expand( "fn_like_clone_tokens", - r#"ident, []"#, + r#"ident, [ident2, ident3]"#, expect![[r#" IDENT 1 ident PUNCT 1 , [alone] GROUP [] 1 1 1 + IDENT 1 ident2 + PUNCT 1 , [alone] + IDENT 1 ident3 IDENT 1 ident PUNCT 1 , [alone] GROUP [] 1 1 1 + IDENT 1 ident2 + PUNCT 1 , [alone] + IDENT 1 ident3 "#]], expect![[r#" IDENT 42:Root[0000, 0]@0..5#ROOT2024 ident PUNCT 42:Root[0000, 0]@5..6#ROOT2024 , [alone] - GROUP [] 42:Root[0000, 0]@7..8#ROOT2024 42:Root[0000, 0]@8..9#ROOT2024 42:Root[0000, 0]@7..9#ROOT2024 + GROUP [] 42:Root[0000, 0]@7..8#ROOT2024 42:Root[0000, 0]@22..23#ROOT2024 42:Root[0000, 0]@7..23#ROOT2024 + IDENT 42:Root[0000, 0]@8..14#ROOT2024 ident2 + PUNCT 42:Root[0000, 0]@14..15#ROOT2024 , [alone] + IDENT 42:Root[0000, 0]@16..22#ROOT2024 ident3 IDENT 42:Root[0000, 0]@0..5#ROOT2024 ident PUNCT 42:Root[0000, 0]@5..6#ROOT2024 , [alone] - GROUP [] 42:Root[0000, 0]@7..9#ROOT2024 42:Root[0000, 0]@7..9#ROOT2024 42:Root[0000, 0]@7..9#ROOT2024 + GROUP [] 42:Root[0000, 0]@7..23#ROOT2024 42:Root[0000, 0]@7..23#ROOT2024 42:Root[0000, 0]@7..23#ROOT2024 + IDENT 42:Root[0000, 0]@8..14#ROOT2024 ident2 + PUNCT 42:Root[0000, 0]@14..15#ROOT2024 , [alone] + IDENT 42:Root[0000, 0]@16..22#ROOT2024 ident3 "#]], ); } diff --git a/tests/ui/README.md b/tests/ui/README.md index 11003bbef9928..344b0b2500df9 100644 --- a/tests/ui/README.md +++ b/tests/ui/README.md @@ -113,12 +113,6 @@ See [Tracking Issue for autodiff #124509](https://github.com/rust-lang/rust/issu Tests for automatic referencing and dereferencing behavior, such as automatically adding reference operations (`&` or `&mut`) to make a value match a method's receiver type. Sometimes abbreviated as "auto-ref" or "auto-deref". -## `tests/ui/auxiliary/`: Auxiliary files for tests directly under `tests/ui`. - -This top-level `auxiliary` subdirectory contains support files for tests immediately under `tests/ui/`. - -**FIXME(#133895)**: tests immediately under `tests/ui/` should be rehomed to more suitable subdirectories, after which this subdirectory can be removed. - ## `tests/ui/backtrace/`: Backtraces Runtime panics and error handling generate backtraces to assist in debugging and diagnostics. @@ -542,12 +536,6 @@ These tests are about very different topics, only unified by the fact that they Accompanies `tests/ui/error-codes/`, exercises the `--explain` cli flag. -## `tests/ui/explicit/`: Errors involving the concept of "explicit" - -This category contains three tests: two which are about the specific error `explicit use of destructor method`, and one which is about explicit annotation of lifetimes: https://doc.rust-lang.org/stable/rust-by-example/scope/lifetime/explicit.html. - -**FIXME**: Rehome the two tests about the destructor method with `drop`-related categories, and rehome the last test with a category related to lifetimes. - ## `tests/ui/explicit-tail-calls/` Exercises `#![feature(explicit_tail_calls)]` and the `become` keyword. See [Explicit Tail Calls #3407](https://github.com/rust-lang/rfcs/pull/3407). @@ -733,10 +721,6 @@ See [Instrument coverage | The rustc book](https://doc.rust-lang.org/rustc/instr See [Tracking issue for `-Z instrument-xray` #102921](https://github.com/rust-lang/rust/issues/102921). -## `tests/ui/interior-mutability/` - -**FIXME**: contains a single test, probably better rehomed. - ## `tests/ui/internal/` Tests for `internal_unstable` and the attribute header `#![feature(allow_internal_unstable)]`, which lets compiler developers mark features as internal to the compiler, and unstable for standard library use. @@ -759,16 +743,6 @@ Various tests related to rejecting invalid inputs. Tests for checking that invalid usage of compiler flags are rejected. -## `tests/ui/invalid-module-declaration/` - -**FIXME**: Consider merging into module/resolve directories. - -## `tests/ui/invalid-self-argument/`: `self` as a function argument incorrectly - -Tests with erroneous ways of using `self`, such as having it not be the first argument, or using it in a non-associated function (no `impl` or `trait`). - -**FIXME**: Maybe merge with `ui/self`. - ## `tests/ui/io-checks/` Contains a single test. The test tries to output a file into an invalid directory with `-o`, then checks that the result is an error, not an internal compiler error. diff --git a/tests/ui/explicit/explicit-call-to-dtor.fixed b/tests/ui/drop/explicit-call-to-dtor.fixed similarity index 71% rename from tests/ui/explicit/explicit-call-to-dtor.fixed rename to tests/ui/drop/explicit-call-to-dtor.fixed index 4c4142c79811d..167f557a6125a 100644 --- a/tests/ui/explicit/explicit-call-to-dtor.fixed +++ b/tests/ui/drop/explicit-call-to-dtor.fixed @@ -1,6 +1,6 @@ //@ run-rustfix struct Foo { - x: isize + x: isize, } impl Drop for Foo { @@ -12,5 +12,5 @@ impl Drop for Foo { fn main() { let x = Foo { x: 3 }; println!("{}", x.x); - drop(x); //~ ERROR explicit use of destructor method + drop(x); //~ ERROR explicit use of destructor method } diff --git a/tests/ui/explicit/explicit-call-to-dtor.rs b/tests/ui/drop/explicit-call-to-dtor.rs similarity index 71% rename from tests/ui/explicit/explicit-call-to-dtor.rs rename to tests/ui/drop/explicit-call-to-dtor.rs index 262dde54c7f6a..2c4e013f5c94d 100644 --- a/tests/ui/explicit/explicit-call-to-dtor.rs +++ b/tests/ui/drop/explicit-call-to-dtor.rs @@ -1,6 +1,6 @@ //@ run-rustfix struct Foo { - x: isize + x: isize, } impl Drop for Foo { @@ -12,5 +12,5 @@ impl Drop for Foo { fn main() { let x = Foo { x: 3 }; println!("{}", x.x); - x.drop(); //~ ERROR explicit use of destructor method + x.drop(); //~ ERROR explicit use of destructor method } diff --git a/tests/ui/explicit/explicit-call-to-dtor.stderr b/tests/ui/drop/explicit-call-to-dtor.stderr similarity index 100% rename from tests/ui/explicit/explicit-call-to-dtor.stderr rename to tests/ui/drop/explicit-call-to-dtor.stderr diff --git a/tests/ui/explicit/explicit-call-to-supertrait-dtor.fixed b/tests/ui/drop/explicit-call-to-supertrait-dtor.fixed similarity index 81% rename from tests/ui/explicit/explicit-call-to-supertrait-dtor.fixed rename to tests/ui/drop/explicit-call-to-supertrait-dtor.fixed index 57cb858aa0895..1526f7b46ea1b 100644 --- a/tests/ui/explicit/explicit-call-to-supertrait-dtor.fixed +++ b/tests/ui/drop/explicit-call-to-supertrait-dtor.fixed @@ -4,7 +4,7 @@ #![allow(dropping_references)] struct Foo { - x: isize + x: isize, } #[allow(drop_bounds)] @@ -20,7 +20,7 @@ impl Drop for Foo { impl Bar for Foo { fn blah(&self) { - drop(self); //~ ERROR explicit use of destructor method + drop(self); //~ ERROR explicit use of destructor method } } diff --git a/tests/ui/explicit/explicit-call-to-supertrait-dtor.rs b/tests/ui/drop/explicit-call-to-supertrait-dtor.rs similarity index 80% rename from tests/ui/explicit/explicit-call-to-supertrait-dtor.rs rename to tests/ui/drop/explicit-call-to-supertrait-dtor.rs index bb29e49524205..2de3d008aaaea 100644 --- a/tests/ui/explicit/explicit-call-to-supertrait-dtor.rs +++ b/tests/ui/drop/explicit-call-to-supertrait-dtor.rs @@ -4,7 +4,7 @@ #![allow(dropping_references)] struct Foo { - x: isize + x: isize, } #[allow(drop_bounds)] @@ -20,7 +20,7 @@ impl Drop for Foo { impl Bar for Foo { fn blah(&self) { - self.drop(); //~ ERROR explicit use of destructor method + self.drop(); //~ ERROR explicit use of destructor method } } diff --git a/tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr b/tests/ui/drop/explicit-call-to-supertrait-dtor.stderr similarity index 100% rename from tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr rename to tests/ui/drop/explicit-call-to-supertrait-dtor.stderr diff --git a/tests/ui/enum-discriminant/invalid-niche-discriminant.normal.stderr b/tests/ui/enum-discriminant/invalid-niche-discriminant.normal.stderr new file mode 100644 index 0000000000000..9c66c1782e4dc --- /dev/null +++ b/tests/ui/enum-discriminant/invalid-niche-discriminant.normal.stderr @@ -0,0 +1,35 @@ +error[E0732]: `#[repr(inttype)]` must be specified for enums with explicit discriminants and non-unit variants + --> $DIR/invalid-niche-discriminant.rs:11:1 + | +LL | enum E { + | ^^^^^^ +... +LL | S0 { + | -- non-unit discriminant declared here +... +LL | Bar = { + | ___________- +LL | | let x = 1; +LL | | 3 +LL | | }, + | |_____- explicit discriminant specified here + +error[E0599]: no variant named `S1` found for enum `E` + --> $DIR/invalid-niche-discriminant.rs:23:18 + | +LL | enum E { + | ------ variant `S1` not found here +... +LL | static C: E = E::S1 { u: 23 }; + | ^^ + | +help: there is a variant with a similar name + | +LL - static C: E = E::S1 { u: 23 }; +LL + static C: E = E::S0 { u: 23 }; + | + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0599, E0732. +For more information about an error, try `rustc --explain E0599`. diff --git a/tests/ui/enum-discriminant/invalid-niche-discriminant.rs b/tests/ui/enum-discriminant/invalid-niche-discriminant.rs new file mode 100644 index 0000000000000..f70f7d1736bae --- /dev/null +++ b/tests/ui/enum-discriminant/invalid-niche-discriminant.rs @@ -0,0 +1,25 @@ +//@ needs-rustc-debug-assertions +//@ revisions: normal with_delayed +//@ [with_delayed] compile-flags: -Z eagerly-emit-delayed-bugs + +#![crate_type = "lib"] + +// Repro for +// which ICEd because the calculated layout is invalid +// but which we needn't care about as the discriminant already was. + +enum E { +//~^ ERROR must be specified +//[with_delayed]~| ERROR variant 1 has discriminant 3 + S0 { + s: String, + }, + Bar = { + let x = 1; + 3 + }, +} + +static C: E = E::S1 { u: 23 }; +//~^ ERROR no variant named +//[with_delayed]~| ERROR but no error emitted diff --git a/tests/ui/enum-discriminant/invalid-niche-discriminant.with_delayed.stderr b/tests/ui/enum-discriminant/invalid-niche-discriminant.with_delayed.stderr new file mode 100644 index 0000000000000..20f118655a17a --- /dev/null +++ b/tests/ui/enum-discriminant/invalid-niche-discriminant.with_delayed.stderr @@ -0,0 +1,47 @@ +error[E0732]: `#[repr(inttype)]` must be specified for enums with explicit discriminants and non-unit variants + --> $DIR/invalid-niche-discriminant.rs:11:1 + | +LL | enum E { + | ^^^^^^ +... +LL | S0 { + | -- non-unit discriminant declared here +... +LL | Bar = { + | ___________- +LL | | let x = 1; +LL | | 3 +LL | | }, + | |_____- explicit discriminant specified here + +error: variant 1 has discriminant 3 in niche-encoded type + --> $DIR/invalid-niche-discriminant.rs:11:1 + | +LL | enum E { + | ^^^^^^ + +error[E0599]: no variant named `S1` found for enum `E` + --> $DIR/invalid-niche-discriminant.rs:23:18 + | +LL | enum E { + | ------ variant `S1` not found here +... +LL | static C: E = E::S1 { u: 23 }; + | ^^ + | +help: there is a variant with a similar name + | +LL - static C: E = E::S1 { u: 23 }; +LL + static C: E = E::S0 { u: 23 }; + | + +error: `Res::Err` but no error emitted + --> $DIR/invalid-niche-discriminant.rs:23:15 + | +LL | static C: E = E::S1 { u: 23 }; + | ^^^^^ + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0599, E0732. +For more information about an error, try `rustc --explain E0599`. diff --git a/tests/ui/explicit/explicit-self-lifetime-mismatch.rs b/tests/ui/explicit/explicit-self-lifetime-mismatch.rs deleted file mode 100644 index aa5e352b6ebef..0000000000000 --- a/tests/ui/explicit/explicit-self-lifetime-mismatch.rs +++ /dev/null @@ -1,22 +0,0 @@ -//@ dont-require-annotations: NOTE - -struct Foo<'a,'b> { - x: &'a isize, - y: &'b isize, -} - -impl<'a,'b> Foo<'a,'b> { - fn bar(self: - Foo<'b,'a> - //~^ ERROR mismatched `self` parameter type - //~| NOTE expected struct `Foo<'a, 'b>` - //~| NOTE found struct `Foo<'b, 'a>` - //~| NOTE lifetime mismatch - //~| ERROR mismatched `self` parameter type - //~| NOTE expected struct `Foo<'a, 'b>` - //~| NOTE found struct `Foo<'b, 'a>` - //~| NOTE lifetime mismatch - ) {} -} - -fn main() {} diff --git a/tests/ui/explicit/explicit-self-lifetime-mismatch.stderr b/tests/ui/explicit/explicit-self-lifetime-mismatch.stderr deleted file mode 100644 index a20901e8c74d2..0000000000000 --- a/tests/ui/explicit/explicit-self-lifetime-mismatch.stderr +++ /dev/null @@ -1,41 +0,0 @@ -error[E0308]: mismatched `self` parameter type - --> $DIR/explicit-self-lifetime-mismatch.rs:10:12 - | -LL | Foo<'b,'a> - | ^^^^^^^^^^ lifetime mismatch - | - = note: expected struct `Foo<'a, 'b>` - found struct `Foo<'b, 'a>` -note: the lifetime `'b` as defined here... - --> $DIR/explicit-self-lifetime-mismatch.rs:8:9 - | -LL | impl<'a,'b> Foo<'a,'b> { - | ^^ -note: ...does not necessarily outlive the lifetime `'a` as defined here - --> $DIR/explicit-self-lifetime-mismatch.rs:8:6 - | -LL | impl<'a,'b> Foo<'a,'b> { - | ^^ - -error[E0308]: mismatched `self` parameter type - --> $DIR/explicit-self-lifetime-mismatch.rs:10:12 - | -LL | Foo<'b,'a> - | ^^^^^^^^^^ lifetime mismatch - | - = note: expected struct `Foo<'a, 'b>` - found struct `Foo<'b, 'a>` -note: the lifetime `'a` as defined here... - --> $DIR/explicit-self-lifetime-mismatch.rs:8:6 - | -LL | impl<'a,'b> Foo<'a,'b> { - | ^^ -note: ...does not necessarily outlive the lifetime `'b` as defined here - --> $DIR/explicit-self-lifetime-mismatch.rs:8:9 - | -LL | impl<'a,'b> Foo<'a,'b> { - | ^^ - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/invalid-module-declaration/auxiliary/foo/bar.rs b/tests/ui/invalid-module-declaration/auxiliary/foo/bar.rs deleted file mode 100644 index bcfd7dc0ade75..0000000000000 --- a/tests/ui/invalid-module-declaration/auxiliary/foo/bar.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod baz; diff --git a/tests/ui/invalid-module-declaration/auxiliary/foo/mod.rs b/tests/ui/invalid-module-declaration/auxiliary/foo/mod.rs deleted file mode 100644 index 46f285ca47d69..0000000000000 --- a/tests/ui/invalid-module-declaration/auxiliary/foo/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod bar; diff --git a/tests/ui/invalid-module-declaration/invalid-module-declaration.rs b/tests/ui/invalid-module-declaration/invalid-module-declaration.rs deleted file mode 100644 index 1c6c282f4b7e6..0000000000000 --- a/tests/ui/invalid-module-declaration/invalid-module-declaration.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod auxiliary { - mod foo; -} - -fn main() {} - -//~? ERROR file not found for module `baz` diff --git a/tests/ui/invalid-module-declaration/invalid-module-declaration.stderr b/tests/ui/invalid-module-declaration/invalid-module-declaration.stderr deleted file mode 100644 index a8f65883d6364..0000000000000 --- a/tests/ui/invalid-module-declaration/invalid-module-declaration.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0583]: file not found for module `baz` - --> $DIR/auxiliary/foo/bar.rs:1:1 - | -LL | pub mod baz; - | ^^^^^^^^^^^^ - | - = help: to create the module `baz`, create file "$DIR/auxiliary/foo/bar/baz.rs" or "$DIR/auxiliary/foo/bar/baz/mod.rs" - = note: if there is a `mod baz` elsewhere in the crate already, import it with `use crate::...` instead - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0583`. diff --git a/tests/ui/invalid-self-argument/bare-fn-start.rs b/tests/ui/invalid-self-argument/bare-fn-start.rs deleted file mode 100644 index 7c580bc5a5dea..0000000000000 --- a/tests/ui/invalid-self-argument/bare-fn-start.rs +++ /dev/null @@ -1,6 +0,0 @@ -fn a(&self) { } -//~^ ERROR `self` parameter is only allowed in associated functions -//~| NOTE not semantically valid as function parameter -//~| NOTE associated functions are those in `impl` or `trait` definitions - -fn main() { } diff --git a/tests/ui/invalid-self-argument/bare-fn-start.stderr b/tests/ui/invalid-self-argument/bare-fn-start.stderr deleted file mode 100644 index bf7160bcd2d35..0000000000000 --- a/tests/ui/invalid-self-argument/bare-fn-start.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: `self` parameter is only allowed in associated functions - --> $DIR/bare-fn-start.rs:1:6 - | -LL | fn a(&self) { } - | ^^^^^ not semantically valid as function parameter - | - = note: associated functions are those in `impl` or `trait` definitions - -error: aborting due to 1 previous error - diff --git a/tests/ui/invalid-self-argument/bare-fn.rs b/tests/ui/invalid-self-argument/bare-fn.rs deleted file mode 100644 index 342bdc31a7c82..0000000000000 --- a/tests/ui/invalid-self-argument/bare-fn.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn b(foo: u32, &mut self) { } -//~^ ERROR unexpected `self` parameter in function -//~| NOTE must be the first parameter of an associated function - -fn main() { } diff --git a/tests/ui/invalid-self-argument/bare-fn.stderr b/tests/ui/invalid-self-argument/bare-fn.stderr deleted file mode 100644 index 7abb56602d4bc..0000000000000 --- a/tests/ui/invalid-self-argument/bare-fn.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: unexpected `self` parameter in function - --> $DIR/bare-fn.rs:1:16 - | -LL | fn b(foo: u32, &mut self) { } - | ^^^^^^^^^ must be the first parameter of an associated function - -error: aborting due to 1 previous error - diff --git a/tests/ui/invalid-self-argument/trait-fn.rs b/tests/ui/invalid-self-argument/trait-fn.rs deleted file mode 100644 index 5ccea589561cb..0000000000000 --- a/tests/ui/invalid-self-argument/trait-fn.rs +++ /dev/null @@ -1,11 +0,0 @@ -struct Foo {} - -impl Foo { - fn c(foo: u32, self) {} - //~^ ERROR unexpected `self` parameter in function - //~| NOTE must be the first parameter of an associated function - - fn good(&mut self, foo: u32) {} -} - -fn main() { } diff --git a/tests/ui/invalid-self-argument/trait-fn.stderr b/tests/ui/invalid-self-argument/trait-fn.stderr deleted file mode 100644 index c9d0a338ef428..0000000000000 --- a/tests/ui/invalid-self-argument/trait-fn.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: unexpected `self` parameter in function - --> $DIR/trait-fn.rs:4:20 - | -LL | fn c(foo: u32, self) {} - | ^^^^ must be the first parameter of an associated function - -error: aborting due to 1 previous error - diff --git a/tests/ui/issues/issue-17740.rs b/tests/ui/issues/issue-17740.rs deleted file mode 100644 index 20a73756ea3ea..0000000000000 --- a/tests/ui/issues/issue-17740.rs +++ /dev/null @@ -1,20 +0,0 @@ -//@ dont-require-annotations: NOTE - -struct Foo<'a> { - data: &'a[u8], -} - -impl <'a> Foo<'a>{ - fn bar(self: &mut Foo) { - //~^ ERROR mismatched `self` parameter type - //~| NOTE expected struct `Foo<'a>` - //~| NOTE found struct `Foo<'_>` - //~| NOTE lifetime mismatch - //~| ERROR mismatched `self` parameter type - //~| NOTE expected struct `Foo<'a>` - //~| NOTE found struct `Foo<'_>` - //~| NOTE lifetime mismatch - } -} - -fn main() {} diff --git a/tests/ui/issues/issue-17740.stderr b/tests/ui/issues/issue-17740.stderr deleted file mode 100644 index 198d7d5b37cc7..0000000000000 --- a/tests/ui/issues/issue-17740.stderr +++ /dev/null @@ -1,41 +0,0 @@ -error[E0308]: mismatched `self` parameter type - --> $DIR/issue-17740.rs:8:18 - | -LL | fn bar(self: &mut Foo) { - | ^^^^^^^^ lifetime mismatch - | - = note: expected struct `Foo<'a>` - found struct `Foo<'_>` -note: the anonymous lifetime defined here... - --> $DIR/issue-17740.rs:8:23 - | -LL | fn bar(self: &mut Foo) { - | ^^^ -note: ...does not necessarily outlive the lifetime `'a` as defined here - --> $DIR/issue-17740.rs:7:7 - | -LL | impl <'a> Foo<'a>{ - | ^^ - -error[E0308]: mismatched `self` parameter type - --> $DIR/issue-17740.rs:8:18 - | -LL | fn bar(self: &mut Foo) { - | ^^^^^^^^ lifetime mismatch - | - = note: expected struct `Foo<'a>` - found struct `Foo<'_>` -note: the lifetime `'a` as defined here... - --> $DIR/issue-17740.rs:7:7 - | -LL | impl <'a> Foo<'a>{ - | ^^ -note: ...does not necessarily outlive the anonymous lifetime defined here - --> $DIR/issue-17740.rs:8:23 - | -LL | fn bar(self: &mut Foo) { - | ^^^ - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/lifetimes/explicit-self-lifetime-mismatch.rs b/tests/ui/lifetimes/explicit-self-lifetime-mismatch.rs new file mode 100644 index 0000000000000..88b9d86a9fdf6 --- /dev/null +++ b/tests/ui/lifetimes/explicit-self-lifetime-mismatch.rs @@ -0,0 +1,41 @@ +//@ dont-require-annotations: NOTE +//! regression test for + +struct Foo<'a, 'b> { + x: &'a isize, + y: &'b isize, +} + +impl<'a, 'b> Foo<'a, 'b> { + fn bar( + self: Foo<'b, 'a>, + //~^ ERROR mismatched `self` parameter type + //~| NOTE expected struct `Foo<'a, 'b>` + //~| NOTE found struct `Foo<'b, 'a>` + //~| NOTE lifetime mismatch + //~| ERROR mismatched `self` parameter type + //~| NOTE expected struct `Foo<'a, 'b>` + //~| NOTE found struct `Foo<'b, 'a>` + //~| NOTE lifetime mismatch + ) { + } +} + +struct Bar<'a> { + data: &'a [u8], +} + +impl<'a> Bar<'a> { + fn bar(self: &mut Bar) { + //~^ ERROR mismatched `self` parameter type + //~| NOTE expected struct `Bar<'a>` + //~| NOTE found struct `Bar<'_>` + //~| NOTE lifetime mismatch + //~| ERROR mismatched `self` parameter type + //~| NOTE expected struct `Bar<'a>` + //~| NOTE found struct `Bar<'_>` + //~| NOTE lifetime mismatch + } +} + +fn main() {} diff --git a/tests/ui/lifetimes/explicit-self-lifetime-mismatch.stderr b/tests/ui/lifetimes/explicit-self-lifetime-mismatch.stderr new file mode 100644 index 0000000000000..ebd6383cb4de5 --- /dev/null +++ b/tests/ui/lifetimes/explicit-self-lifetime-mismatch.stderr @@ -0,0 +1,79 @@ +error[E0308]: mismatched `self` parameter type + --> $DIR/explicit-self-lifetime-mismatch.rs:11:15 + | +LL | self: Foo<'b, 'a>, + | ^^^^^^^^^^^ lifetime mismatch + | + = note: expected struct `Foo<'a, 'b>` + found struct `Foo<'b, 'a>` +note: the lifetime `'b` as defined here... + --> $DIR/explicit-self-lifetime-mismatch.rs:9:10 + | +LL | impl<'a, 'b> Foo<'a, 'b> { + | ^^ +note: ...does not necessarily outlive the lifetime `'a` as defined here + --> $DIR/explicit-self-lifetime-mismatch.rs:9:6 + | +LL | impl<'a, 'b> Foo<'a, 'b> { + | ^^ + +error[E0308]: mismatched `self` parameter type + --> $DIR/explicit-self-lifetime-mismatch.rs:11:15 + | +LL | self: Foo<'b, 'a>, + | ^^^^^^^^^^^ lifetime mismatch + | + = note: expected struct `Foo<'a, 'b>` + found struct `Foo<'b, 'a>` +note: the lifetime `'a` as defined here... + --> $DIR/explicit-self-lifetime-mismatch.rs:9:6 + | +LL | impl<'a, 'b> Foo<'a, 'b> { + | ^^ +note: ...does not necessarily outlive the lifetime `'b` as defined here + --> $DIR/explicit-self-lifetime-mismatch.rs:9:10 + | +LL | impl<'a, 'b> Foo<'a, 'b> { + | ^^ + +error[E0308]: mismatched `self` parameter type + --> $DIR/explicit-self-lifetime-mismatch.rs:29:18 + | +LL | fn bar(self: &mut Bar) { + | ^^^^^^^^ lifetime mismatch + | + = note: expected struct `Bar<'a>` + found struct `Bar<'_>` +note: the anonymous lifetime defined here... + --> $DIR/explicit-self-lifetime-mismatch.rs:29:23 + | +LL | fn bar(self: &mut Bar) { + | ^^^ +note: ...does not necessarily outlive the lifetime `'a` as defined here + --> $DIR/explicit-self-lifetime-mismatch.rs:28:6 + | +LL | impl<'a> Bar<'a> { + | ^^ + +error[E0308]: mismatched `self` parameter type + --> $DIR/explicit-self-lifetime-mismatch.rs:29:18 + | +LL | fn bar(self: &mut Bar) { + | ^^^^^^^^ lifetime mismatch + | + = note: expected struct `Bar<'a>` + found struct `Bar<'_>` +note: the lifetime `'a` as defined here... + --> $DIR/explicit-self-lifetime-mismatch.rs:28:6 + | +LL | impl<'a> Bar<'a> { + | ^^ +note: ...does not necessarily outlive the anonymous lifetime defined here + --> $DIR/explicit-self-lifetime-mismatch.rs:29:23 + | +LL | fn bar(self: &mut Bar) { + | ^^^ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/parser/item-kw-case-mismatch.stderr b/tests/ui/parser/item-kw-case-mismatch.stderr index d2a1eb7f2f521..55cbc6be943cc 100644 --- a/tests/ui/parser/item-kw-case-mismatch.stderr +++ b/tests/ui/parser/item-kw-case-mismatch.stderr @@ -4,7 +4,7 @@ error: keyword `use` is written in the wrong case LL | Use std::ptr::read; | ^^^ | -help: write it in the correct case (notice the capitalization) +help: write it in lowercase (notice the capitalization) | LL - Use std::ptr::read; LL + use std::ptr::read; @@ -16,7 +16,7 @@ error: keyword `use` is written in the wrong case LL | USE std::ptr::write; | ^^^ | -help: write it in the correct case +help: write it in lowercase | LL - USE std::ptr::write; LL + use std::ptr::write; @@ -28,7 +28,7 @@ error: keyword `fn` is written in the wrong case LL | async Fn _a() {} | ^^ | -help: write it in the correct case (notice the capitalization) +help: write it in lowercase (notice the capitalization) | LL - async Fn _a() {} LL + async fn _a() {} @@ -40,7 +40,7 @@ error: keyword `fn` is written in the wrong case LL | Fn _b() {} | ^^ | -help: write it in the correct case (notice the capitalization) +help: write it in lowercase (notice the capitalization) | LL - Fn _b() {} LL + fn _b() {} @@ -52,7 +52,7 @@ error: keyword `async` is written in the wrong case LL | aSYNC fN _c() {} | ^^^^^ | -help: write it in the correct case +help: write it in lowercase | LL - aSYNC fN _c() {} LL + async fN _c() {} @@ -64,7 +64,7 @@ error: keyword `fn` is written in the wrong case LL | aSYNC fN _c() {} | ^^ | -help: write it in the correct case +help: write it in lowercase | LL - aSYNC fN _c() {} LL + aSYNC fn _c() {} @@ -76,7 +76,7 @@ error: keyword `async` is written in the wrong case LL | Async fn _d() {} | ^^^^^ | -help: write it in the correct case +help: write it in lowercase | LL - Async fn _d() {} LL + async fn _d() {} @@ -88,7 +88,7 @@ error: keyword `const` is written in the wrong case LL | CONST UNSAFE FN _e() {} | ^^^^^ | -help: write it in the correct case +help: write it in lowercase | LL - CONST UNSAFE FN _e() {} LL + const UNSAFE FN _e() {} @@ -100,7 +100,7 @@ error: keyword `unsafe` is written in the wrong case LL | CONST UNSAFE FN _e() {} | ^^^^^^ | -help: write it in the correct case +help: write it in lowercase | LL - CONST UNSAFE FN _e() {} LL + CONST unsafe FN _e() {} @@ -112,7 +112,7 @@ error: keyword `fn` is written in the wrong case LL | CONST UNSAFE FN _e() {} | ^^ | -help: write it in the correct case +help: write it in lowercase | LL - CONST UNSAFE FN _e() {} LL + CONST UNSAFE fn _e() {} @@ -124,7 +124,7 @@ error: keyword `unsafe` is written in the wrong case LL | unSAFE EXTern "C" fn _f() {} | ^^^^^^ | -help: write it in the correct case +help: write it in lowercase | LL - unSAFE EXTern "C" fn _f() {} LL + unsafe EXTern "C" fn _f() {} @@ -136,7 +136,7 @@ error: keyword `extern` is written in the wrong case LL | unSAFE EXTern "C" fn _f() {} | ^^^^^^ | -help: write it in the correct case +help: write it in lowercase | LL - unSAFE EXTern "C" fn _f() {} LL + unSAFE extern "C" fn _f() {} @@ -148,7 +148,7 @@ error: keyword `extern` is written in the wrong case LL | EXTERN "C" FN _g() {} | ^^^^^^ | -help: write it in the correct case +help: write it in lowercase | LL - EXTERN "C" FN _g() {} LL + extern "C" FN _g() {} @@ -160,7 +160,7 @@ error: keyword `fn` is written in the wrong case LL | EXTERN "C" FN _g() {} | ^^ | -help: write it in the correct case +help: write it in lowercase | LL - EXTERN "C" FN _g() {} LL + EXTERN "C" fn _g() {} diff --git a/tests/ui/self/invalid-self-argument.rs b/tests/ui/self/invalid-self-argument.rs new file mode 100644 index 0000000000000..fef687e194cbb --- /dev/null +++ b/tests/ui/self/invalid-self-argument.rs @@ -0,0 +1,22 @@ +//! regression test for + +fn a(&self) {} +//~^ ERROR `self` parameter is only allowed in associated functions +//~| NOTE not semantically valid as function parameter +//~| NOTE associated functions are those in `impl` or `trait` definitions + +fn b(foo: u32, &mut self) {} +//~^ ERROR unexpected `self` parameter in function +//~| NOTE must be the first parameter of an associated function + +struct Foo {} + +impl Foo { + fn c(foo: u32, self) {} + //~^ ERROR unexpected `self` parameter in function + //~| NOTE must be the first parameter of an associated function + + fn good(&mut self, foo: u32) {} +} + +fn main() {} diff --git a/tests/ui/self/invalid-self-argument.stderr b/tests/ui/self/invalid-self-argument.stderr new file mode 100644 index 0000000000000..c92e5b2492bff --- /dev/null +++ b/tests/ui/self/invalid-self-argument.stderr @@ -0,0 +1,22 @@ +error: unexpected `self` parameter in function + --> $DIR/invalid-self-argument.rs:8:16 + | +LL | fn b(foo: u32, &mut self) {} + | ^^^^^^^^^ must be the first parameter of an associated function + +error: unexpected `self` parameter in function + --> $DIR/invalid-self-argument.rs:15:20 + | +LL | fn c(foo: u32, self) {} + | ^^^^ must be the first parameter of an associated function + +error: `self` parameter is only allowed in associated functions + --> $DIR/invalid-self-argument.rs:3:6 + | +LL | fn a(&self) {} + | ^^^^^ not semantically valid as function parameter + | + = note: associated functions are those in `impl` or `trait` definitions + +error: aborting due to 3 previous errors + diff --git a/tests/ui/interior-mutability/interior-mutability.rs b/tests/ui/traits/catch-unwind-cell-interior-mut.rs similarity index 79% rename from tests/ui/interior-mutability/interior-mutability.rs rename to tests/ui/traits/catch-unwind-cell-interior-mut.rs index 7e4fe76852d76..cfc52322399fd 100644 --- a/tests/ui/interior-mutability/interior-mutability.rs +++ b/tests/ui/traits/catch-unwind-cell-interior-mut.rs @@ -1,3 +1,4 @@ +//! related issue: //@ compile-flags: -Zwrite-long-types-to-disk=yes use std::cell::Cell; use std::panic::catch_unwind; diff --git a/tests/ui/interior-mutability/interior-mutability.stderr b/tests/ui/traits/catch-unwind-cell-interior-mut.stderr similarity index 91% rename from tests/ui/interior-mutability/interior-mutability.stderr rename to tests/ui/traits/catch-unwind-cell-interior-mut.stderr index b307d608a1fd9..6f58c880554a6 100644 --- a/tests/ui/interior-mutability/interior-mutability.stderr +++ b/tests/ui/traits/catch-unwind-cell-interior-mut.stderr @@ -1,5 +1,5 @@ error[E0277]: the type `UnsafeCell` may contain interior mutability and a reference may not be safely transferable across a catch_unwind boundary - --> $DIR/interior-mutability.rs:6:18 + --> $DIR/catch-unwind-cell-interior-mut.rs:7:18 | LL | catch_unwind(|| { x.set(23); }); | ------------ ^^^^^^^^^^^^^^^^^ `UnsafeCell` may contain interior mutability and a reference may not be safely transferable across a catch_unwind boundary @@ -11,7 +11,7 @@ note: required because it appears within the type `Cell` --> $SRC_DIR/core/src/cell.rs:LL:COL = note: required for `&Cell` to implement `UnwindSafe` note: required because it's used within this closure - --> $DIR/interior-mutability.rs:6:18 + --> $DIR/catch-unwind-cell-interior-mut.rs:7:18 | LL | catch_unwind(|| { x.set(23); }); | ^^ diff --git a/tests/ui/use/use-path-segment-kw.rs b/tests/ui/use/use-path-segment-kw.rs index 137a9e18aef30..680ecd3d03d49 100644 --- a/tests/ui/use/use-path-segment-kw.rs +++ b/tests/ui/use/use-path-segment-kw.rs @@ -1,4 +1,4 @@ -//@ edition: 2021 +//@ edition: 2018.. macro_rules! macro_dollar_crate { () => {