Skip to content

Commit 1d60f9e

Browse files
committed
Auto merge of #149515 - matthiaskrgr:rollup-djmciuc, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #149393 (expand valid edition range for use-path-segment-kw.rs) - #149427 (Make the capitalization explicit on keyword misspell error) - #149433 (Use a delayed bug for this layout ICE) - #149473 (Tidying up UI tests [7/N]) - #149505 (Update the comment in the add_typo_suggestion function) - #149513 (`rust-analyzer` subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a463b0e + c99912d commit 1d60f9e

Some content is hidden

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

41 files changed

+363
-260
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,6 +3544,8 @@ pub fn detect_confusion_type(sm: &SourceMap, suggested: &str, sp: Span) -> Confu
35443544
let mut has_digit_letter_confusable = false;
35453545
let mut has_other_diff = false;
35463546

3547+
// Letters whose lowercase version is very similar to the uppercase
3548+
// version.
35473549
let ascii_confusables = &['c', 'f', 'i', 'k', 'o', 's', 'u', 'v', 'w', 'x', 'y', 'z'];
35483550

35493551
let digit_letter_confusables = [('0', 'O'), ('1', 'l'), ('5', 'S'), ('8', 'B'), ('9', 'g')];

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ impl<'a> DiagCtxtHandle<'a> {
13661366
self.create_err(err).emit()
13671367
}
13681368

1369-
/// Ensures that an error is printed. See `Level::DelayedBug`.
1369+
/// Ensures that an error is printed. See [`Level::DelayedBug`].
13701370
//
13711371
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagMessage>` because bug messages aren't
13721372
// user-facing.

compiler/rustc_parse/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ parse_keyword_lifetime =
513513
lifetimes cannot use keyword names
514514
515515
parse_kw_bad_case = keyword `{$kw}` is written in the wrong case
516-
.suggestion = write it in the correct case
516+
.suggestion = write it in {$case}
517517
518518
parse_label_inner_attr_does_not_annotate_this = the inner attribute doesn't annotate this {$item}
519519
parse_label_unexpected_token = unexpected token

compiler/rustc_parse/src/errors.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// ignore-tidy-filelength
22

33
use std::borrow::Cow;
4+
use std::path::PathBuf;
45

56
use rustc_ast::token::Token;
67
use rustc_ast::util::parser::ExprPrecedence;
78
use rustc_ast::{Path, Visibility};
89
use rustc_errors::codes::*;
910
use rustc_errors::{
10-
Applicability, Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, Subdiagnostic,
11-
SuggestionStyle,
11+
Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg,
12+
Level, Subdiagnostic, SuggestionStyle,
1213
};
1314
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
1415
use rustc_session::errors::ExprParenthesesNeeded;
@@ -3341,6 +3342,24 @@ pub(crate) struct KwBadCase<'a> {
33413342
#[suggestion(code = "{kw}", style = "verbose", applicability = "machine-applicable")]
33423343
pub span: Span,
33433344
pub kw: &'a str,
3345+
pub case: Case,
3346+
}
3347+
3348+
pub(crate) enum Case {
3349+
Upper,
3350+
Lower,
3351+
Mixed,
3352+
}
3353+
3354+
impl IntoDiagArg for Case {
3355+
fn into_diag_arg(self, path: &mut Option<PathBuf>) -> DiagArgValue {
3356+
match self {
3357+
Case::Upper => "uppercase",
3358+
Case::Lower => "lowercase",
3359+
Case::Mixed => "the correct case",
3360+
}
3361+
.into_diag_arg(path)
3362+
}
33443363
}
33453364

33463365
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,20 @@ impl<'a> Parser<'a> {
606606
// Do an ASCII case-insensitive match, because all keywords are ASCII.
607607
&& ident.as_str().eq_ignore_ascii_case(exp.kw.as_str())
608608
{
609-
self.dcx().emit_err(errors::KwBadCase { span: ident.span, kw: exp.kw.as_str() });
609+
let kw = exp.kw.as_str();
610+
let is_upper = kw.chars().all(char::is_uppercase);
611+
let is_lower = kw.chars().all(char::is_lowercase);
612+
613+
let case = match (is_upper, is_lower) {
614+
(true, true) => {
615+
unreachable!("keyword that is both fully upper- and fully lowercase")
616+
}
617+
(true, false) => errors::Case::Upper,
618+
(false, true) => errors::Case::Lower,
619+
(false, false) => errors::Case::Mixed,
620+
};
621+
622+
self.dcx().emit_err(errors::KwBadCase { span: ident.span, kw, case });
610623
self.bump();
611624
true
612625
} else {

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19021902
if span.overlaps(def_span) {
19031903
// Don't suggest typo suggestion for itself like in the following:
19041904
// error[E0423]: expected function, tuple struct or tuple variant, found struct `X`
1905-
// --> $DIR/issue-64792-bad-unicode-ctor.rs:3:14
1905+
// --> $DIR/unicode-string-literal-syntax-error-64792.rs:4:14
19061906
// |
19071907
// LL | struct X {}
19081908
// | ----------- `X` defined here

compiler/rustc_ty_utils/src/layout/invariant.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,16 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou
281281
}
282282

283283
// Ensure that for niche encoded tags the discriminant coincides with the variant index.
284-
assert_eq!(
285-
layout.ty.discriminant_for_variant(tcx, idx).unwrap().val,
286-
u128::from(idx.as_u32()),
287-
);
284+
let val = layout.ty.discriminant_for_variant(tcx, idx).unwrap().val;
285+
if val != u128::from(idx.as_u32()) {
286+
let adt_def = layout.ty.ty_adt_def().unwrap();
287+
cx.tcx().dcx().span_delayed_bug(
288+
cx.tcx().def_span(adt_def.did()),
289+
format!(
290+
"variant {idx:?} has discriminant {val:?} in niche-encoded type"
291+
),
292+
);
293+
}
288294
}
289295
}
290296
for variant in variants.iter() {

src/tools/rust-analyzer/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,6 @@ impl<T: SpanTransformer> Reader<'_, T> {
962962
};
963963
res[i] = Some(g);
964964
}
965-
proc_macro_srv::TokenStream::new(vec![proc_macro_srv::TokenTree::Group(
966-
res[0].take().unwrap(),
967-
)])
965+
res[0].take().unwrap().stream.unwrap_or_default()
968966
}
969967
}

src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,26 +297,38 @@ fn test_fn_like_macro_noop() {
297297
fn test_fn_like_macro_clone_ident_subtree() {
298298
assert_expand(
299299
"fn_like_clone_tokens",
300-
r#"ident, []"#,
300+
r#"ident, [ident2, ident3]"#,
301301
expect![[r#"
302302
IDENT 1 ident
303303
PUNCT 1 , [alone]
304304
GROUP [] 1 1 1
305+
IDENT 1 ident2
306+
PUNCT 1 , [alone]
307+
IDENT 1 ident3
305308
306309
307310
IDENT 1 ident
308311
PUNCT 1 , [alone]
309312
GROUP [] 1 1 1
313+
IDENT 1 ident2
314+
PUNCT 1 , [alone]
315+
IDENT 1 ident3
310316
"#]],
311317
expect![[r#"
312318
IDENT 42:Root[0000, 0]@0..5#ROOT2024 ident
313319
PUNCT 42:Root[0000, 0]@5..6#ROOT2024 , [alone]
314-
GROUP [] 42:Root[0000, 0]@7..8#ROOT2024 42:Root[0000, 0]@8..9#ROOT2024 42:Root[0000, 0]@7..9#ROOT2024
320+
GROUP [] 42:Root[0000, 0]@7..8#ROOT2024 42:Root[0000, 0]@22..23#ROOT2024 42:Root[0000, 0]@7..23#ROOT2024
321+
IDENT 42:Root[0000, 0]@8..14#ROOT2024 ident2
322+
PUNCT 42:Root[0000, 0]@14..15#ROOT2024 , [alone]
323+
IDENT 42:Root[0000, 0]@16..22#ROOT2024 ident3
315324
316325
317326
IDENT 42:Root[0000, 0]@0..5#ROOT2024 ident
318327
PUNCT 42:Root[0000, 0]@5..6#ROOT2024 , [alone]
319-
GROUP [] 42:Root[0000, 0]@7..9#ROOT2024 42:Root[0000, 0]@7..9#ROOT2024 42:Root[0000, 0]@7..9#ROOT2024
328+
GROUP [] 42:Root[0000, 0]@7..23#ROOT2024 42:Root[0000, 0]@7..23#ROOT2024 42:Root[0000, 0]@7..23#ROOT2024
329+
IDENT 42:Root[0000, 0]@8..14#ROOT2024 ident2
330+
PUNCT 42:Root[0000, 0]@14..15#ROOT2024 , [alone]
331+
IDENT 42:Root[0000, 0]@16..22#ROOT2024 ident3
320332
"#]],
321333
);
322334
}

tests/ui/README.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,6 @@ See [Tracking Issue for autodiff #124509](https://github.com/rust-lang/rust/issu
113113

114114
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".
115115

116-
## `tests/ui/auxiliary/`: Auxiliary files for tests directly under `tests/ui`.
117-
118-
This top-level `auxiliary` subdirectory contains support files for tests immediately under `tests/ui/`.
119-
120-
**FIXME(#133895)**: tests immediately under `tests/ui/` should be rehomed to more suitable subdirectories, after which this subdirectory can be removed.
121-
122116
## `tests/ui/backtrace/`: Backtraces
123117

124118
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
542536

543537
Accompanies `tests/ui/error-codes/`, exercises the `--explain` cli flag.
544538

545-
## `tests/ui/explicit/`: Errors involving the concept of "explicit"
546-
547-
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.
548-
549-
**FIXME**: Rehome the two tests about the destructor method with `drop`-related categories, and rehome the last test with a category related to lifetimes.
550-
551539
## `tests/ui/explicit-tail-calls/`
552540

553541
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
733721

734722
See [Tracking issue for `-Z instrument-xray` #102921](https://github.com/rust-lang/rust/issues/102921).
735723

736-
## `tests/ui/interior-mutability/`
737-
738-
**FIXME**: contains a single test, probably better rehomed.
739-
740724
## `tests/ui/internal/`
741725

742726
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.
759743

760744
Tests for checking that invalid usage of compiler flags are rejected.
761745

762-
## `tests/ui/invalid-module-declaration/`
763-
764-
**FIXME**: Consider merging into module/resolve directories.
765-
766-
## `tests/ui/invalid-self-argument/`: `self` as a function argument incorrectly
767-
768-
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`).
769-
770-
**FIXME**: Maybe merge with `ui/self`.
771-
772746
## `tests/ui/io-checks/`
773747

774748
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.

0 commit comments

Comments
 (0)