Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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')];
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DiagMessage>` because bug messages aren't
// user-facing.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<PathBuf>) -> DiagArgValue {
match self {
Case::Upper => "uppercase",
Case::Lower => "lowercase",
Case::Mixed => "the correct case",
}
.into_diag_arg(path)
}
}

#[derive(Diagnostic)]
Expand Down
15 changes: 14 additions & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions compiler/rustc_ty_utils/src/layout/invariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,6 @@ impl<T: SpanTransformer> 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()
}
}
18 changes: 15 additions & 3 deletions src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"#]],
);
}
Expand Down
26 changes: 0 additions & 26 deletions tests/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ run-rustfix
struct Foo {
x: isize
x: isize,
}

impl Drop for Foo {
Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ run-rustfix
struct Foo {
x: isize
x: isize,
}

impl Drop for Foo {
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(dropping_references)]

struct Foo {
x: isize
x: isize,
}

#[allow(drop_bounds)]
Expand All @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(dropping_references)]

struct Foo {
x: isize
x: isize,
}

#[allow(drop_bounds)]
Expand All @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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`.
25 changes: 25 additions & 0 deletions tests/ui/enum-discriminant/invalid-niche-discriminant.rs
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/rust-lang/rust/issues/144501>
// 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
Loading
Loading