From e8445818d49fe968b35a130c66071c1b56498f93 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 27 Jun 2024 12:58:35 -0400 Subject: [PATCH 01/15] Reorder modifiers and polarity to be *after* binder in trait bounds --- compiler/rustc_parse/src/parser/ty.rs | 4 +- .../async-fn/higher-ranked-async-fn.rs | 2 +- .../impl-trait/normalize-tait-in-const.stderr | 41 ++----------------- tests/ui/issues/issue-39089.rs | 3 +- tests/ui/issues/issue-39089.stderr | 8 ++++ tests/ui/parser/bounds-type.rs | 2 +- .../tilde-const-syntax.rs | 4 +- 7 files changed, 19 insertions(+), 45 deletions(-) create mode 100644 tests/ui/issues/issue-39089.stderr diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 1e5b227aaa9..24183ac1218 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -978,7 +978,7 @@ impl<'a> Parser<'a> { /// Parses a type bound according to: /// ```ebnf /// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN) - /// TY_BOUND_NOPAREN = [TRAIT_BOUND_MODIFIERS] [for] SIMPLE_PATH + /// TY_BOUND_NOPAREN = [for] [TRAIT_BOUND_MODIFIERS] SIMPLE_PATH /// ``` /// /// For example, this grammar accepts `for<'a: 'b> ~const ?m::Trait<'a>`. @@ -988,8 +988,8 @@ impl<'a> Parser<'a> { has_parens: bool, leading_token: &Token, ) -> PResult<'a, GenericBound> { - let modifiers = self.parse_trait_bound_modifiers()?; let (mut lifetime_defs, binder_span) = self.parse_late_bound_lifetime_defs()?; + let modifiers = self.parse_trait_bound_modifiers()?; // Recover erroneous lifetime bound with modifiers or binder. // e.g. `T: for<'a> 'a` or `T: ~const 'a`. diff --git a/tests/ui/async-await/async-fn/higher-ranked-async-fn.rs b/tests/ui/async-await/async-fn/higher-ranked-async-fn.rs index be338ddeb7d..f8da517213a 100644 --- a/tests/ui/async-await/async-fn/higher-ranked-async-fn.rs +++ b/tests/ui/async-await/async-fn/higher-ranked-async-fn.rs @@ -15,7 +15,7 @@ async fn f(arg: &i32) {} async fn func(f: F) where - F: async for<'a> Fn(&'a i32), + F: for<'a> async Fn(&'a i32), { let x: i32 = 0; f(&x).await; diff --git a/tests/ui/impl-trait/normalize-tait-in-const.stderr b/tests/ui/impl-trait/normalize-tait-in-const.stderr index 73f4d4c3885..77de689fb97 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.stderr +++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr @@ -1,41 +1,8 @@ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/normalize-tait-in-const.rs:27:42 +error: expected a trait, found type + --> $DIR/normalize-tait-in-const.rs:27:34 | LL | const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/normalize-tait-in-const.rs:27:69 - | -LL | const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { - | ^^^^^^^^ +error: aborting due to 1 previous error -error[E0015]: cannot call non-const closure in constant functions - --> $DIR/normalize-tait-in-const.rs:28:5 - | -LL | fun(filter_positive()); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -help: consider further restricting this bound - | -LL | const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct + ~const Fn(&foo::Alias<'_>)>(fun: F) { - | ++++++++++++++++++++++++++++ -help: add `#![feature(effects)]` to the crate attributes to enable - | -LL + #![feature(effects)] - | - -error[E0493]: destructor of `F` cannot be evaluated at compile-time - --> $DIR/normalize-tait-in-const.rs:27:79 - | -LL | const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { - | ^^^ the destructor for this type cannot be evaluated in constant functions -LL | fun(filter_positive()); -LL | } - | - value is dropped here - -error: aborting due to 4 previous errors - -Some errors have detailed explanations: E0015, E0493. -For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/issues/issue-39089.rs b/tests/ui/issues/issue-39089.rs index b00b8423802..e6bec337354 100644 --- a/tests/ui/issues/issue-39089.rs +++ b/tests/ui/issues/issue-39089.rs @@ -1,5 +1,4 @@ -//@ check-pass -#![allow(dead_code)] fn f Sized>() {} +//~^ ERROR expected a trait, found type fn main() {} diff --git a/tests/ui/issues/issue-39089.stderr b/tests/ui/issues/issue-39089.stderr new file mode 100644 index 00000000000..3e57a6fcbcb --- /dev/null +++ b/tests/ui/issues/issue-39089.stderr @@ -0,0 +1,8 @@ +error: expected a trait, found type + --> $DIR/issue-39089.rs:1:10 + | +LL | fn f Sized>() {} + | ^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/parser/bounds-type.rs b/tests/ui/parser/bounds-type.rs index a1971fa3146..2b2a44b7062 100644 --- a/tests/ui/parser/bounds-type.rs +++ b/tests/ui/parser/bounds-type.rs @@ -5,7 +5,7 @@ struct S< T: Tr + 'a, // OK T: 'a, // OK T:, // OK - T: ?for<'a> Trait, // OK + T: for<'a> ?Trait, // OK T: Tr +, // OK T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-syntax.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-syntax.rs index 496f97b5e24..4dd0e69598d 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-syntax.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-syntax.rs @@ -4,6 +4,6 @@ #![feature(const_trait_impl)] struct S< - T: ~const ?for<'a> Tr<'a> + 'static + ~const std::ops::Add, - T: ~const ?for<'a: 'b> m::Trait<'a>, + T: for<'a> ~const ?Tr<'a> + 'static + ~const std::ops::Add, + T: for<'a: 'b> ~const ?m::Trait<'a>, >; From 32c8bfdb11e519c6608ead730b6dfafc6cafb9c5 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 27 Jun 2024 13:07:03 -0400 Subject: [PATCH 02/15] Improve error message --- compiler/rustc_parse/messages.ftl | 3 ++ compiler/rustc_parse/src/errors.rs | 9 ++++ compiler/rustc_parse/src/parser/ty.rs | 8 ++++ src/tools/tidy/src/ui_tests.rs | 2 +- .../ui/impl-trait/normalize-tait-in-const.rs | 2 +- .../impl-trait/normalize-tait-in-const.stderr | 43 ++++++++++++++++--- tests/ui/issues/issue-39089.rs | 2 +- tests/ui/issues/issue-39089.stderr | 8 ++-- 8 files changed, 66 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index 02c3c87313b..5fb59eeb4f3 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -53,6 +53,9 @@ parse_bare_cr = {$double_quotes -> parse_bare_cr_in_raw_string = bare CR not allowed in raw string +parse_binder_before_modifiers = `for<...>` binder should be placed before trait bound modifiers + .label = place the `for<...>` binder before any modifiers + parse_bounds_not_allowed_on_trait_aliases = bounds are not allowed on trait aliases parse_box_not_pat = expected pattern, found {$descr} diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 3ae9b6dad99..6738cc4a120 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -3041,3 +3041,12 @@ pub struct UnsafeAttrOutsideUnsafeSuggestion { #[suggestion_part(code = ")")] pub right: Span, } + +#[derive(Diagnostic)] +#[diag(parse_binder_before_modifiers)] +pub struct BinderBeforeModifiers { + #[primary_span] + pub binder_span: Span, + #[label] + pub modifiers_span: Span, +} diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 24183ac1218..306029ca94c 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -989,7 +989,10 @@ impl<'a> Parser<'a> { leading_token: &Token, ) -> PResult<'a, GenericBound> { let (mut lifetime_defs, binder_span) = self.parse_late_bound_lifetime_defs()?; + + let modifiers_lo = self.token.span; let modifiers = self.parse_trait_bound_modifiers()?; + let modifiers_span = modifiers_lo.to(self.prev_token.span); // Recover erroneous lifetime bound with modifiers or binder. // e.g. `T: for<'a> 'a` or `T: ~const 'a`. @@ -998,6 +1001,11 @@ impl<'a> Parser<'a> { return self.parse_generic_lt_bound(lo, has_parens); } + if let (more_lifetime_defs, Some(binder_span)) = self.parse_late_bound_lifetime_defs()? { + lifetime_defs.extend(more_lifetime_defs); + self.dcx().emit_err(errors::BinderBeforeModifiers { binder_span, modifiers_span }); + } + let mut path = if self.token.is_keyword(kw::Fn) && self.look_ahead(1, |tok| tok.kind == TokenKind::OpenDelim(Delimiter::Parenthesis)) && let Some(path) = self.recover_path_from_fn() diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 5e6992038e3..0ae0356b2c4 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -16,7 +16,7 @@ use std::path::{Path, PathBuf}; const ENTRY_LIMIT: u32 = 901; // FIXME: The following limits should be reduced eventually. -const ISSUES_ENTRY_LIMIT: u32 = 1672; +const ISSUES_ENTRY_LIMIT: u32 = 1673; const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[ "rs", // test source files diff --git a/tests/ui/impl-trait/normalize-tait-in-const.rs b/tests/ui/impl-trait/normalize-tait-in-const.rs index fc90139d640..e3f53e5f8a8 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.rs +++ b/tests/ui/impl-trait/normalize-tait-in-const.rs @@ -24,7 +24,7 @@ mod foo { } use foo::*; -const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { +const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { fun(filter_positive()); } diff --git a/tests/ui/impl-trait/normalize-tait-in-const.stderr b/tests/ui/impl-trait/normalize-tait-in-const.stderr index 77de689fb97..b20dabe7b25 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.stderr +++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr @@ -1,8 +1,41 @@ -error: expected a trait, found type - --> $DIR/normalize-tait-in-const.rs:27:34 +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/normalize-tait-in-const.rs:27:42 | -LL | const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { + | ^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/normalize-tait-in-const.rs:27:69 + | +LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { + | ^^^^^^^^ +error[E0015]: cannot call non-const closure in constant functions + --> $DIR/normalize-tait-in-const.rs:28:5 + | +LL | fun(filter_positive()); + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +help: consider further restricting this bound + | +LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct + ~const Fn(&foo::Alias<'_>)>(fun: F) { + | ++++++++++++++++++++++++++++ +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | + +error[E0493]: destructor of `F` cannot be evaluated at compile-time + --> $DIR/normalize-tait-in-const.rs:27:79 + | +LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { + | ^^^ the destructor for this type cannot be evaluated in constant functions +LL | fun(filter_positive()); +LL | } + | - value is dropped here + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0015, E0493. +For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/issues/issue-39089.rs b/tests/ui/issues/issue-39089.rs index e6bec337354..822c47503af 100644 --- a/tests/ui/issues/issue-39089.rs +++ b/tests/ui/issues/issue-39089.rs @@ -1,4 +1,4 @@ fn f Sized>() {} -//~^ ERROR expected a trait, found type +//~^ ERROR `for<...>` binder should be placed before trait bound modifiers fn main() {} diff --git a/tests/ui/issues/issue-39089.stderr b/tests/ui/issues/issue-39089.stderr index 3e57a6fcbcb..a81010aedff 100644 --- a/tests/ui/issues/issue-39089.stderr +++ b/tests/ui/issues/issue-39089.stderr @@ -1,8 +1,10 @@ -error: expected a trait, found type - --> $DIR/issue-39089.rs:1:10 +error: `for<...>` binder should be placed before trait bound modifiers + --> $DIR/issue-39089.rs:1:13 | LL | fn f Sized>() {} - | ^^^^^^^^^^^^^ + | - ^^^^ + | | + | place the `for<...>` binder before any modifiers error: aborting due to 1 previous error From 898ed2ffa6c485530af1fbe6117c0deb4290715f Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 10 Jul 2024 17:49:50 -0400 Subject: [PATCH 03/15] Enforce that ? and for<...> are not combined --- compiler/rustc_parse/messages.ftl | 3 +++ compiler/rustc_parse/src/errors.rs | 10 ++++++++++ compiler/rustc_parse/src/parser/ty.rs | 13 +++++++++++++ tests/ui/parser/bounds-type.rs | 2 +- tests/ui/parser/bounds-type.stderr | 10 +++++++++- .../rfc-2632-const-trait-impl/tilde-const-syntax.rs | 4 ++-- 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index 5fb59eeb4f3..5b4a5f4dd38 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -53,6 +53,9 @@ parse_bare_cr = {$double_quotes -> parse_bare_cr_in_raw_string = bare CR not allowed in raw string +parse_binder_and_polarity = `for<...>` binder not allowed with `{$polarity}` trait polarity modifier + .label = there is not a well-defined meaning for a higher-ranked `{$polarity}` trait + parse_binder_before_modifiers = `for<...>` binder should be placed before trait bound modifiers .label = place the `for<...>` binder before any modifiers diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 6738cc4a120..9b18a771fde 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -3050,3 +3050,13 @@ pub struct BinderBeforeModifiers { #[label] pub modifiers_span: Span, } + +#[derive(Diagnostic)] +#[diag(parse_binder_and_polarity)] +pub struct BinderAndPolarity { + #[primary_span] + pub polarity_span: Span, + #[label] + pub binder_span: Span, + pub polarity: &'static str, +} diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 306029ca94c..6de778fa9f2 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -994,6 +994,19 @@ impl<'a> Parser<'a> { let modifiers = self.parse_trait_bound_modifiers()?; let modifiers_span = modifiers_lo.to(self.prev_token.span); + if let Some(binder_span) = binder_span { + match modifiers.polarity { + BoundPolarity::Negative(polarity_span) | BoundPolarity::Maybe(polarity_span) => { + self.dcx().emit_err(errors::BinderAndPolarity { + binder_span, + polarity_span, + polarity: modifiers.polarity.as_str(), + }); + } + BoundPolarity::Positive => {} + } + } + // Recover erroneous lifetime bound with modifiers or binder. // e.g. `T: for<'a> 'a` or `T: ~const 'a`. if self.token.is_lifetime() { diff --git a/tests/ui/parser/bounds-type.rs b/tests/ui/parser/bounds-type.rs index 2b2a44b7062..47fec7b1e77 100644 --- a/tests/ui/parser/bounds-type.rs +++ b/tests/ui/parser/bounds-type.rs @@ -5,7 +5,7 @@ struct S< T: Tr + 'a, // OK T: 'a, // OK T:, // OK - T: for<'a> ?Trait, // OK + T: for<'a> ?Trait, //~ ERROR `for<...>` binder not allowed with `?` trait polarity modifier T: Tr +, // OK T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds diff --git a/tests/ui/parser/bounds-type.stderr b/tests/ui/parser/bounds-type.stderr index d1210e88d66..fa8ab6812b1 100644 --- a/tests/ui/parser/bounds-type.stderr +++ b/tests/ui/parser/bounds-type.stderr @@ -1,3 +1,11 @@ +error: `for<...>` binder not allowed with `?` trait polarity modifier + --> $DIR/bounds-type.rs:8:16 + | +LL | T: for<'a> ?Trait, + | ---- ^ + | | + | there is not a well-defined meaning for a higher-ranked `?` trait + error: `?` may only modify trait bounds, not lifetime bounds --> $DIR/bounds-type.rs:10:8 | @@ -16,5 +24,5 @@ error: `const` may only modify trait bounds, not lifetime bounds LL | T: const 'a, | ^^^^^ -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-syntax.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-syntax.rs index 4dd0e69598d..d65ecae3d06 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-syntax.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-syntax.rs @@ -4,6 +4,6 @@ #![feature(const_trait_impl)] struct S< - T: for<'a> ~const ?Tr<'a> + 'static + ~const std::ops::Add, - T: for<'a: 'b> ~const ?m::Trait<'a>, + T: for<'a> ~const Tr<'a> + 'static + ~const std::ops::Add, + T: for<'a: 'b> ~const m::Trait<'a>, >; From de88bc5c8921774681ecac0a5249b370a9768a6c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 10 Jul 2024 18:06:44 -0400 Subject: [PATCH 04/15] And additionally enforce ? and async/const aren't mixed --- compiler/rustc_ast_passes/messages.ftl | 2 - .../rustc_ast_passes/src/ast_validation.rs | 11 ----- compiler/rustc_ast_passes/src/errors.rs | 9 ---- compiler/rustc_parse/messages.ftl | 3 ++ compiler/rustc_parse/src/errors.rs | 11 +++++ compiler/rustc_parse/src/parser/ty.rs | 29 ++++++++++++ tests/ui/parser/bounds-type.rs | 13 +++++- tests/ui/parser/bounds-type.stderr | 46 +++++++++++++++++-- ...utually-exclusive-trait-bound-modifiers.rs | 8 ++-- ...lly-exclusive-trait-bound-modifiers.stderr | 32 ++++++++----- 10 files changed, 120 insertions(+), 44 deletions(-) diff --git a/compiler/rustc_ast_passes/messages.ftl b/compiler/rustc_ast_passes/messages.ftl index 7da726ef408..0408f6ad543 100644 --- a/compiler/rustc_ast_passes/messages.ftl +++ b/compiler/rustc_ast_passes/messages.ftl @@ -152,8 +152,6 @@ ast_passes_impl_trait_path = `impl Trait` is not allowed in path parameters ast_passes_incompatible_features = `{$f1}` and `{$f2}` are incompatible, using them at the same time is not allowed .help = remove one of these features -ast_passes_incompatible_trait_bound_modifiers = `{$left}` and `{$right}` are mutually exclusive - ast_passes_inherent_cannot_be = inherent impls cannot be {$annotation} .because = {$annotation} because of this .type = inherent impl for this type diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index dd0d904c52c..8041b89abe2 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -1435,17 +1435,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> { }; self.dcx().emit_err(errors::TildeConstDisallowed { span, reason }); } - ( - _, - BoundConstness::Always(_) | BoundConstness::Maybe(_), - BoundPolarity::Negative(_) | BoundPolarity::Maybe(_), - ) => { - self.dcx().emit_err(errors::IncompatibleTraitBoundModifiers { - span: bound.span(), - left: modifiers.constness.as_str(), - right: modifiers.polarity.as_str(), - }); - } _ => {} } diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index bfb90476450..51f80b9ad4a 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -657,15 +657,6 @@ pub enum TildeConstReason { Item, } -#[derive(Diagnostic)] -#[diag(ast_passes_incompatible_trait_bound_modifiers)] -pub struct IncompatibleTraitBoundModifiers { - #[primary_span] - pub span: Span, - pub left: &'static str, - pub right: &'static str, -} - #[derive(Diagnostic)] #[diag(ast_passes_const_and_async)] pub struct ConstAndAsync { diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index 5b4a5f4dd38..f0cdb6c63a4 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -575,6 +575,9 @@ parse_missing_trait_in_trait_impl = missing trait in a trait impl parse_modifier_lifetime = `{$modifier}` may only modify trait bounds, not lifetime bounds .suggestion = remove the `{$modifier}` +parse_modifiers_and_polarity = `{$modifiers_concatenated}` trait not allowed with `{$polarity}` trait polarity modifier + .label = there is not a well-defined meaning for a `{$modifiers_concatenated} {$polarity}` trait + parse_more_than_one_char = character literal may only contain one codepoint .followed_by = this `{$chr}` is followed by the combining {$len -> [one] mark diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 9b18a771fde..75417885d2a 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -3060,3 +3060,14 @@ pub struct BinderAndPolarity { pub binder_span: Span, pub polarity: &'static str, } + +#[derive(Diagnostic)] +#[diag(parse_modifiers_and_polarity)] +pub struct PolarityAndModifiers { + #[primary_span] + pub polarity_span: Span, + #[label] + pub modifiers_span: Span, + pub polarity: &'static str, + pub modifiers_concatenated: String, +} diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 6de778fa9f2..a2db4b6feef 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -930,6 +930,7 @@ impl<'a> Parser<'a> { /// TRAIT_BOUND_MODIFIERS = [["~"] "const"] ["async"] ["?" | "!"] /// ``` fn parse_trait_bound_modifiers(&mut self) -> PResult<'a, TraitBoundModifiers> { + let modifier_lo = self.token.span; let constness = if self.eat(&token::Tilde) { let tilde = self.prev_token.span; self.expect_keyword(kw::Const)?; @@ -962,6 +963,7 @@ impl<'a> Parser<'a> { } else { BoundAsyncness::Normal }; + let modifier_hi = self.prev_token.span; let polarity = if self.eat(&token::Question) { BoundPolarity::Maybe(self.prev_token.span) @@ -972,6 +974,33 @@ impl<'a> Parser<'a> { BoundPolarity::Positive }; + // Enforce the mutual-exclusivity of `const`/`async` and `?`/`!`. + match polarity { + BoundPolarity::Positive => { + // All trait bound modifiers allowed to combine with positive polarity + } + BoundPolarity::Maybe(polarity_span) | BoundPolarity::Negative(polarity_span) => { + match (asyncness, constness) { + (BoundAsyncness::Normal, BoundConstness::Never) => { + // Ok, no modifiers. + } + (_, _) => { + let constness = constness.as_str(); + let asyncness = asyncness.as_str(); + let glue = + if !constness.is_empty() && !asyncness.is_empty() { " " } else { "" }; + let modifiers_concatenated = format!("{constness}{glue}{asyncness}"); + self.dcx().emit_err(errors::PolarityAndModifiers { + polarity_span, + polarity: polarity.as_str(), + modifiers_span: modifier_lo.to(modifier_hi), + modifiers_concatenated, + }); + } + } + } + } + Ok(TraitBoundModifiers { constness, asyncness, polarity }) } diff --git a/tests/ui/parser/bounds-type.rs b/tests/ui/parser/bounds-type.rs index 47fec7b1e77..7cee6def32f 100644 --- a/tests/ui/parser/bounds-type.rs +++ b/tests/ui/parser/bounds-type.rs @@ -1,4 +1,5 @@ //@ compile-flags: -Z parse-only +//@ edition: 2021 struct S< T: 'a + Tr, // OK @@ -10,10 +11,20 @@ struct S< T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds T: ~const Tr, // OK - T: ~const ?Tr, // OK + T: ~const ?Tr, //~ ERROR `~const` trait not allowed with `?` trait polarity modifier T: ~const Tr + 'a, // OK T: ~const 'a, //~ ERROR `~const` may only modify trait bounds, not lifetime bounds T: const 'a, //~ ERROR `const` may only modify trait bounds, not lifetime bounds + + T: async Tr, // OK + T: async ?Tr, //~ ERROR `async` trait not allowed with `?` trait polarity modifier + T: async Tr + 'a, // OK + T: async 'a, //~ ERROR `async` may only modify trait bounds, not lifetime bounds + + T: const async Tr, // OK + T: const async ?Tr, //~ ERROR `const async` trait not allowed with `?` trait polarity modifier + T: const async Tr + 'a, // OK + T: const async 'a, //~ ERROR `const` may only modify trait bounds, not lifetime bounds >; fn main() {} diff --git a/tests/ui/parser/bounds-type.stderr b/tests/ui/parser/bounds-type.stderr index fa8ab6812b1..09c35c12b00 100644 --- a/tests/ui/parser/bounds-type.stderr +++ b/tests/ui/parser/bounds-type.stderr @@ -1,5 +1,5 @@ error: `for<...>` binder not allowed with `?` trait polarity modifier - --> $DIR/bounds-type.rs:8:16 + --> $DIR/bounds-type.rs:9:16 | LL | T: for<'a> ?Trait, | ---- ^ @@ -7,22 +7,58 @@ LL | T: for<'a> ?Trait, | there is not a well-defined meaning for a higher-ranked `?` trait error: `?` may only modify trait bounds, not lifetime bounds - --> $DIR/bounds-type.rs:10:8 + --> $DIR/bounds-type.rs:11:8 | LL | T: ?'a, | ^ +error: `~const` trait not allowed with `?` trait polarity modifier + --> $DIR/bounds-type.rs:14:15 + | +LL | T: ~const ?Tr, + | ------ ^ + | | + | there is not a well-defined meaning for a `~const ?` trait + error: `~const` may only modify trait bounds, not lifetime bounds - --> $DIR/bounds-type.rs:15:8 + --> $DIR/bounds-type.rs:16:8 | LL | T: ~const 'a, | ^^^^^^ error: `const` may only modify trait bounds, not lifetime bounds - --> $DIR/bounds-type.rs:16:8 + --> $DIR/bounds-type.rs:17:8 | LL | T: const 'a, | ^^^^^ -error: aborting due to 4 previous errors +error: `async` trait not allowed with `?` trait polarity modifier + --> $DIR/bounds-type.rs:20:14 + | +LL | T: async ?Tr, + | ----- ^ + | | + | there is not a well-defined meaning for a `async ?` trait + +error: `async` may only modify trait bounds, not lifetime bounds + --> $DIR/bounds-type.rs:22:8 + | +LL | T: async 'a, + | ^^^^^ + +error: `const async` trait not allowed with `?` trait polarity modifier + --> $DIR/bounds-type.rs:25:20 + | +LL | T: const async ?Tr, + | ----------- ^ + | | + | there is not a well-defined meaning for a `const async ?` trait + +error: `const` may only modify trait bounds, not lifetime bounds + --> $DIR/bounds-type.rs:27:8 + | +LL | T: const async 'a, + | ^^^^^ + +error: aborting due to 9 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/mutually-exclusive-trait-bound-modifiers.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/mutually-exclusive-trait-bound-modifiers.rs index 37e285f2c65..aaab8e819a3 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/mutually-exclusive-trait-bound-modifiers.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/mutually-exclusive-trait-bound-modifiers.rs @@ -1,17 +1,17 @@ #![feature(const_trait_impl)] const fn maybe_const_maybe() {} -//~^ ERROR `~const` and `?` are mutually exclusive +//~^ ERROR `~const` trait not allowed with `?` trait polarity modifier fn const_maybe() {} -//~^ ERROR `const` and `?` are mutually exclusive +//~^ ERROR `const` trait not allowed with `?` trait polarity modifier const fn maybe_const_negative() {} -//~^ ERROR `~const` and `!` are mutually exclusive +//~^ ERROR `~const` trait not allowed with `!` trait polarity modifier //~| ERROR negative bounds are not supported fn const_negative() {} -//~^ ERROR `const` and `!` are mutually exclusive +//~^ ERROR `const` trait not allowed with `!` trait polarity modifier //~| ERROR negative bounds are not supported #[const_trait] diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/mutually-exclusive-trait-bound-modifiers.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/mutually-exclusive-trait-bound-modifiers.stderr index 1938f740170..18e4d160f5f 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/mutually-exclusive-trait-bound-modifiers.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/mutually-exclusive-trait-bound-modifiers.stderr @@ -1,26 +1,34 @@ -error: `~const` and `?` are mutually exclusive - --> $DIR/mutually-exclusive-trait-bound-modifiers.rs:3:31 +error: `~const` trait not allowed with `?` trait polarity modifier + --> $DIR/mutually-exclusive-trait-bound-modifiers.rs:3:38 | LL | const fn maybe_const_maybe() {} - | ^^^^^^^^^^^^^ + | ------ ^ + | | + | there is not a well-defined meaning for a `~const ?` trait -error: `const` and `?` are mutually exclusive - --> $DIR/mutually-exclusive-trait-bound-modifiers.rs:6:19 +error: `const` trait not allowed with `?` trait polarity modifier + --> $DIR/mutually-exclusive-trait-bound-modifiers.rs:6:25 | LL | fn const_maybe() {} - | ^^^^^^^^^^^^ + | ----- ^ + | | + | there is not a well-defined meaning for a `const ?` trait -error: `~const` and `!` are mutually exclusive - --> $DIR/mutually-exclusive-trait-bound-modifiers.rs:9:34 +error: `~const` trait not allowed with `!` trait polarity modifier + --> $DIR/mutually-exclusive-trait-bound-modifiers.rs:9:41 | LL | const fn maybe_const_negative() {} - | ^^^^^^^^^^^^^ + | ------ ^ + | | + | there is not a well-defined meaning for a `~const !` trait -error: `const` and `!` are mutually exclusive - --> $DIR/mutually-exclusive-trait-bound-modifiers.rs:13:22 +error: `const` trait not allowed with `!` trait polarity modifier + --> $DIR/mutually-exclusive-trait-bound-modifiers.rs:13:28 | LL | fn const_negative() {} - | ^^^^^^^^^^^^ + | ----- ^ + | | + | there is not a well-defined meaning for a `const !` trait error: negative bounds are not supported --> $DIR/mutually-exclusive-trait-bound-modifiers.rs:9:41 From 79d1ac66a8317083bb801a5b09ed180dacc8f70c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 11 Jul 2024 21:59:28 -0400 Subject: [PATCH 05/15] Remove rustdoc tests which no longer parse --- src/tools/rustfmt/tests/source/type.rs | 2 -- src/tools/rustfmt/tests/target/negative-bounds.rs | 6 ------ src/tools/rustfmt/tests/target/type.rs | 2 -- 3 files changed, 10 deletions(-) diff --git a/src/tools/rustfmt/tests/source/type.rs b/src/tools/rustfmt/tests/source/type.rs index 61ef73a3cab..7a232f85198 100644 --- a/src/tools/rustfmt/tests/source/type.rs +++ b/src/tools/rustfmt/tests/source/type.rs @@ -146,8 +146,6 @@ trait T: ~ const Super {} const fn not_quite_const() -> i32 { ::CONST } -struct S(std::marker::PhantomData); - impl ~ const T {} fn apit(_: impl ~ const T) {} diff --git a/src/tools/rustfmt/tests/target/negative-bounds.rs b/src/tools/rustfmt/tests/target/negative-bounds.rs index 4fb35cccf66..9fcb86ef4a4 100644 --- a/src/tools/rustfmt/tests/target/negative-bounds.rs +++ b/src/tools/rustfmt/tests/target/negative-bounds.rs @@ -3,9 +3,3 @@ where i32: !Copy, { } - -fn maybe_const_negative() -where - i32: ~const !Copy, -{ -} diff --git a/src/tools/rustfmt/tests/target/type.rs b/src/tools/rustfmt/tests/target/type.rs index c789ecb055a..325adb52f3f 100644 --- a/src/tools/rustfmt/tests/target/type.rs +++ b/src/tools/rustfmt/tests/target/type.rs @@ -153,8 +153,6 @@ const fn not_quite_const() -> i32 { ::CONST } -struct S(std::marker::PhantomData); - impl ~const T {} fn apit(_: impl ~const T) {} From 89f273f40dafb693139496ed6f914872b6533fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 9 Jul 2024 16:46:09 +0000 Subject: [PATCH 06/15] Replace ASCII control chars with Unicode Control Pictures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` error: bare CR not allowed in doc-comment --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:3:32 | LL | /// doc comment with bare CR: '␍' | ^ ``` --- compiler/rustc_errors/src/emitter.rs | 69 ++++++++++++++---- ...-bare-cr-string-literal-doc-comment.stderr | 14 ++-- tests/ui/parser/bad-char-literals.rs | Bin 496 -> 608 bytes tests/ui/parser/bad-char-literals.stderr | 17 ++++- tests/ui/parser/issues/issue-66473.stderr | Bin 1061 -> 1209 bytes tests/ui/parser/issues/issue-68629.stderr | Bin 944 -> 976 bytes tests/ui/parser/issues/issue-68730.stderr | Bin 1266 -> 1294 bytes .../raw/raw-byte-string-literals.stderr | 2 +- ...ral-carriage-returns-in-doc-comment.stderr | 6 +- .../trailing-carriage-return-in-string.stderr | 2 +- tests/ui/parser/utf16-be-without-bom.stderr | Bin 3641 -> 4029 bytes tests/ui/parser/utf16-le-without-bom.stderr | Bin 3603 -> 3939 bytes .../rfc-3348-c-string-literals/no-nuls.stderr | Bin 2028 -> 2040 bytes tests/ui/str/str-escape.stderr | 2 +- 14 files changed, 81 insertions(+), 31 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index aa47ca16676..95e1b5348b7 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -677,10 +677,7 @@ impl HumanEmitter { .skip(left) .take_while(|ch| { // Make sure that the trimming on the right will fall within the terminal width. - // FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` - // is. For now, just accept that sometimes the code line will be longer than - // desired. - let next = unicode_width::UnicodeWidthChar::width(*ch).unwrap_or(1); + let next = char_width(*ch); if taken + next > right - left { return false; } @@ -742,11 +739,7 @@ impl HumanEmitter { let left = margin.left(source_string.len()); // Account for unicode characters of width !=0 that were removed. - let left = source_string - .chars() - .take(left) - .map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)) - .sum(); + let left = source_string.chars().take(left).map(|ch| char_width(ch)).sum(); self.draw_line( buffer, @@ -2039,7 +2032,7 @@ impl HumanEmitter { let sub_len: usize = if is_whitespace_addition { &part.snippet } else { part.snippet.trim() } .chars() - .map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)) + .map(|ch| char_width(ch)) .sum(); let offset: isize = offsets @@ -2076,11 +2069,8 @@ impl HumanEmitter { } // length of the code after substitution - let full_sub_len = part - .snippet - .chars() - .map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)) - .sum::() as isize; + let full_sub_len = + part.snippet.chars().map(|ch| char_width(ch)).sum::() as isize; // length of the code to be substituted let snippet_len = span_end_pos as isize - span_start_pos as isize; @@ -2580,6 +2570,40 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[ ('\u{2068}', ""), ('\u{202C}', ""), ('\u{2069}', ""), + // In terminals without Unicode support the following will be garbled, but in *all* terminals + // the underlying codepoint will be as well. We could gate this replacement behind a "unicode + // support" gate. + ('\u{0000}', "␀"), + ('\u{0001}', "␁"), + ('\u{0002}', "␂"), + ('\u{0003}', "␃"), + ('\u{0004}', "␄"), + ('\u{0005}', "␅"), + ('\u{0006}', "␆"), + ('\u{0007}', "␇"), + ('\u{0008}', "␈"), + ('\u{000B}', "␋"), + ('\u{000C}', "␌"), + ('\u{000D}', "␍"), + ('\u{000E}', "␎"), + ('\u{000F}', "␏"), + ('\u{0010}', "␐"), + ('\u{0011}', "␑"), + ('\u{0012}', "␒"), + ('\u{0013}', "␓"), + ('\u{0014}', "␔"), + ('\u{0015}', "␕"), + ('\u{0016}', "␖"), + ('\u{0017}', "␗"), + ('\u{0018}', "␘"), + ('\u{0019}', "␙"), + ('\u{001A}', "␚"), + ('\u{001B}', "␛"), + ('\u{001C}', "␜"), + ('\u{001D}', "␝"), + ('\u{001E}', "␞"), + ('\u{001F}', "␟"), + ('\u{007F}', "␡"), ]; fn normalize_whitespace(str: &str) -> String { @@ -2590,6 +2614,21 @@ fn normalize_whitespace(str: &str) -> String { s } +fn char_width(ch: char) -> usize { + // FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is. For now, + // just accept that sometimes the code line will be longer than desired. + match ch { + '\t' => 4, + '\u{0000}' | '\u{0001}' | '\u{0002}' | '\u{0003}' | '\u{0004}' | '\u{0005}' + | '\u{0006}' | '\u{0007}' | '\u{0008}' | '\u{000B}' | '\u{000C}' | '\u{000D}' + | '\u{000E}' | '\u{000F}' | '\u{0010}' | '\u{0011}' | '\u{0012}' | '\u{0013}' + | '\u{0014}' | '\u{0015}' | '\u{0016}' | '\u{0017}' | '\u{0018}' | '\u{0019}' + | '\u{001A}' | '\u{001B}' | '\u{001C}' | '\u{001D}' | '\u{001E}' | '\u{001F}' + | '\u{007F}' => 1, + _ => unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1), + } +} + fn draw_col_separator(buffer: &mut StyledBuffer, line: usize, col: usize) { buffer.puts(line, col, "| ", Style::LineNumber); } diff --git a/tests/ui/lexer/lex-bare-cr-string-literal-doc-comment.stderr b/tests/ui/lexer/lex-bare-cr-string-literal-doc-comment.stderr index da80991c727..841d5236ede 100644 --- a/tests/ui/lexer/lex-bare-cr-string-literal-doc-comment.stderr +++ b/tests/ui/lexer/lex-bare-cr-string-literal-doc-comment.stderr @@ -1,31 +1,31 @@ error: bare CR not allowed in doc-comment --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:3:32 | -LL | /// doc comment with bare CR: ' ' +LL | /// doc comment with bare CR: '␍' | ^ error: bare CR not allowed in block doc-comment --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:7:38 | -LL | /** block doc comment with bare CR: ' ' */ +LL | /** block doc comment with bare CR: '␍' */ | ^ error: bare CR not allowed in doc-comment --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:12:36 | -LL | //! doc comment with bare CR: ' ' +LL | //! doc comment with bare CR: '␍' | ^ error: bare CR not allowed in block doc-comment --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:15:42 | -LL | /*! block doc comment with bare CR: ' ' */ +LL | /*! block doc comment with bare CR: '␍' */ | ^ error: bare CR not allowed in string, use `\r` instead --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:19:18 | -LL | let _s = "foo bar"; +LL | let _s = "foo␍bar"; | ^ | help: escape the character @@ -36,13 +36,13 @@ LL | let _s = "foo\rbar"; error: bare CR not allowed in raw string --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:22:19 | -LL | let _s = r"bar foo"; +LL | let _s = r"bar␍foo"; | ^ error: unknown character escape: `\r` --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:25:19 | -LL | let _s = "foo\ bar"; +LL | let _s = "foo\␍bar"; | ^ unknown character escape | = help: this is an isolated carriage return; consider checking your editor and version control settings diff --git a/tests/ui/parser/bad-char-literals.rs b/tests/ui/parser/bad-char-literals.rs index 748b4a22253f52301df92a22cf2b848ac6e4726f..c3d55d3f7e3bfbb53c98f8ce78ebfe4bff3fe477 100644 GIT binary patch delta 72 zcmeys{D5V{Oh#V6P#+&I1qB5KbzKJC$##qqYB`xDsYQu73b~1u3i)|Cl?uuEc_oRN cc?$V?sS3&YDX9hdnRz9XIT=+a&twb-05OplQ~&?~ delta 11 ScmaFB@_~87OvcHaOyK|>hy)h^ diff --git a/tests/ui/parser/bad-char-literals.stderr b/tests/ui/parser/bad-char-literals.stderr index 89253d7d4aa..38889da5da1 100644 --- a/tests/ui/parser/bad-char-literals.stderr +++ b/tests/ui/parser/bad-char-literals.stderr @@ -25,7 +25,7 @@ LL | '\n'; error: character constant must be escaped: `\r` --> $DIR/bad-char-literals.rs:15:6 | -LL | ' '; +LL | '␍'; | ^ | help: escape the character @@ -33,8 +33,19 @@ help: escape the character LL | '\r'; | ++ +error: character literal may only contain one codepoint + --> $DIR/bad-char-literals.rs:18:5 + | +LL | '-␀-'; + | ^^^^ + | +help: if you meant to write a string literal, use double quotes + | +LL | "-␀-"; + | ~ ~ + error: character constant must be escaped: `\t` - --> $DIR/bad-char-literals.rs:18:6 + --> $DIR/bad-char-literals.rs:21:6 | LL | ' '; | ^^^^ @@ -44,5 +55,5 @@ help: escape the character LL | '\t'; | ++ -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors diff --git a/tests/ui/parser/issues/issue-66473.stderr b/tests/ui/parser/issues/issue-66473.stderr index 0e8b0a5da220569b607fe3512ae59ee94e3fcf1b..4be992d58460ebac5cf5fa9ee562da839f670d59 100644 GIT binary patch delta 316 zcmZ3=v6FK`kjB=(S*5Xk0#88 z7&7@bW4IW)AhK<;a;8?MU;!>4AB7qPbhQ&Nte9-eoNNa%j#LtCu!4f_WItwUG3*vh Ie#qdTN7XWa45$gZ| diff --git a/tests/ui/parser/issues/issue-68629.stderr b/tests/ui/parser/issues/issue-68629.stderr index 2562baa1c49c3034012d9721c128aecc4303dc02..ccb0624208b2e20aee028a8efb2fd0fc25d61c94 100644 GIT binary patch delta 125 zcmdnMet~_0pV*@ba~@5YUsC*NLW5#-btadBfzJYy$AFGUfNioC3{rVF-bYSc#2xGDe<2@z@hRF@gqMK!zSQ(+By3D>1(EtFB CauJFE diff --git a/tests/ui/parser/issues/issue-68730.stderr b/tests/ui/parser/issues/issue-68730.stderr index 5bca5bbebeacb44984c8679e4d2c4757be4ee742..6025ea8c1ae7fbdec8c78ea332e3560ee2796981 100644 GIT binary patch delta 96 zcmeyw*~c{@kmJ#WhSc0g6B;IlK7q3*+cLgDa5R~AAvn*O(h!_L=E(@o3+7$~r;?=- E00Eybk^lez delta 67 zcmeC<`ouXQkcA;NmtkV$6EHp5mGK3HVal`%!uZaV24SQ!PX;q4vGjuJ$x~S>0kO^# AssI20 diff --git a/tests/ui/parser/raw/raw-byte-string-literals.stderr b/tests/ui/parser/raw/raw-byte-string-literals.stderr index a2f27d1ed70..a20ce845c32 100644 --- a/tests/ui/parser/raw/raw-byte-string-literals.stderr +++ b/tests/ui/parser/raw/raw-byte-string-literals.stderr @@ -1,7 +1,7 @@ error: bare CR not allowed in raw string --> $DIR/raw-byte-string-literals.rs:4:9 | -LL | br"a "; +LL | br"a␍"; | ^ error: non-ASCII character in raw byte string literal diff --git a/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr b/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr index 07066fc22e6..3150570e1c9 100644 --- a/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr +++ b/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr @@ -1,19 +1,19 @@ error: bare CR not allowed in doc-comment --> $DIR/several-carriage-returns-in-doc-comment.rs:6:12 | -LL | /// This do c comment contains three isolated `\r` symbols +LL | /// This do␍c comment contains ␍three isolated `\r`␍ symbols | ^ error: bare CR not allowed in doc-comment --> $DIR/several-carriage-returns-in-doc-comment.rs:6:32 | -LL | /// This do c comment contains three isolated `\r` symbols +LL | /// This do␍c comment contains ␍three isolated `\r`␍ symbols | ^ error: bare CR not allowed in doc-comment --> $DIR/several-carriage-returns-in-doc-comment.rs:6:52 | -LL | /// This do c comment contains three isolated `\r` symbols +LL | /// This do␍c comment contains ␍three isolated `\r`␍ symbols | ^ error: aborting due to 3 previous errors diff --git a/tests/ui/parser/trailing-carriage-return-in-string.stderr b/tests/ui/parser/trailing-carriage-return-in-string.stderr index fa2677921b3..c5949432af8 100644 --- a/tests/ui/parser/trailing-carriage-return-in-string.stderr +++ b/tests/ui/parser/trailing-carriage-return-in-string.stderr @@ -1,7 +1,7 @@ error: unknown character escape: `\r` --> $DIR/trailing-carriage-return-in-string.rs:10:25 | -LL | let bad = "This is \ a test"; +LL | let bad = "This is \␍ a test"; | ^ unknown character escape | = help: this is an isolated carriage return; consider checking your editor and version control settings diff --git a/tests/ui/parser/utf16-be-without-bom.stderr b/tests/ui/parser/utf16-be-without-bom.stderr index c041f3ecf53b22d8bfd994f7a8c24d583594e027..28cf6d97e96c2a8d08d193f97d4289da04c2aa38 100644 GIT binary patch literal 4029 zcmYc-D#|aiQYg*K&dV>)Qz$M;EGkjRPg5w#&rZ#=Qiv(7HmK!NP|(%2Q&4g74AL(x zNi#IlO-j`*&n(HvFD=nc%Fop+Dz-AQGUQTFP^jVZ@lmKzcr>9Q?a_pWyhjrnK)2C#00I4}hwY!xz6a|)~!it|g0l2aAZGILUk z6>>|9OB9mx^GXsk^Atiu+;lAzQuC7YQ&LkDN>VFIbQDVSQY#8llS@)l6!J=Qaukv( zOF-H((=$pG@{^NGixkQ;Qu7oN6;d+O(o&03^GYBFWagzSWELxw7N@3gaZxW!j6pu3 zG)#tDpqNr6P=;Hmm{TWIhFh>$QYl!5TeuifrMOi9fniqW8d9gw1%=G8OEgp}dWU7$ zP^$nQmVraHVt6=)juG|B;$ay)R4kB(W%y9DR33Bz1n-aK=cR%=mI;ap3i(9}3077K zItpp|rFkg|33&;`bumq-(in_Wz~d%}4Un#9a(-TMW=d+2LQ!gNei^8XSdx*dP+X9h zoT^ZguTWf&nv!b*TFk`-07RqE{Qv*} literal 3641 zcmYc-D#|aiQYg*K&dV>)Qz$M;EGkjRPg5w#&rZ#=Qiv(7HmK!NP|(%2Q&4g74AL(x zNi#IlO-j`*&n(HvFD=nc%Fop+Dz-AQGUQTFP^jVZ@lmKzU`S)gV^CnoWk_VmWXNOC zV9;bxV5nxOWdN&Dhyzm~!d4+8HK)Kzp*X*^C^=OjEi)&zSRuExxI`g2Kd&S)GfyEj z#7);iAvG^KKP5Fqp(M4UL`R`CFSVi|HMt};MIo;=Cr2TvvIL|pGd-h3AwM~}v`C>m zBQ;MUQ6VKWEiJVuHLnC>KxSULLT0f-X>n=_7Z>$>ZVd7XaXuezUN%-0O=A`(2 zxOv`^B+m~w-y4!p*eQU(Fe~v4Nh$I`{vUP;fTV(NScU*;#ow?D0ul?s;TQ%+q?Uxk zG7v~E4u@qZkX|MZx?q6!EAsPFLEWGP#RP@?B83Dis{|c|wEWV%6orJm1mZeGCL}bG z;uP@M3^51NQA*CwE6z+wEm9~-&CM?Zb!bX5QWc5|5|dLEO7azo3sQ4(6tYt*%kzs; x6cWfn8%#H9S95|G&`rC?JHO%w`>Qp+;)ON$l2-KJtLE&w*9SBd}t diff --git a/tests/ui/parser/utf16-le-without-bom.stderr b/tests/ui/parser/utf16-le-without-bom.stderr index cc2220441ac1073c755b178c4da74085faedd2a1..53004ac942d988ea867e0ea7573b4ffd6cfbd026 100644 GIT binary patch literal 3939 zcmYc-D#|aiQYg*K&dV>)Qz$M;EGkjRPg5w#&rZ#=Qiv(7HmK!NP|(%2Q&4g74AL(x zNi#Il%}LcQ&n(HvFD=nc%Fop+Dz-AQGU8HDP^jVZ@lmKzNP9G)A@9+I28Blx8gd^^ zXh?iCp&=70rtxS(gC&TF%&nrpH%u@&ranrR>NX<*mPf1NtC`qj-(NQSPORXqKO)g1IQOGOJ$x%qE zECFfDOwTA$$WKl#EmA1YNX=77R7lB8OG_ZaQ$-B#J>}=6f;xc-iU|t& zMG6U4RtY)^Y5ApjDGCXB3B+{=jgdS{Zg)@tkAon_LwbqH`FX{eDXB#YMX9;@WuV?% zNk*zdaY15oszOP=LUBQAPL4u$YGrwTQHnxB8rTc)t}5yM)Vex&FEKGGzo-OcVM;03 XDnk>6f}+&2%>2?~1#m~Qn2QSlk2ad; literal 3603 zcmYc-D#|aiQYg*K&dV>)Qz$M;EGkjRPg5w#&rZ#=Qiv(7HmK!NP|(%2Q&4g74AL(x zNi#Il%}LcQ&n(HvFD=nc%Fop+Dz-AQGU8HDP^jVZ@lmKzNMp!jP+-VqNMy)l$Yao8 z&}2|xsAi~T04q^Yhy&9g!d4+8HK)Kzp*X*^C^=OjEi)&zSRuExxI`g2Kd&S)GfyEj z#7);iAvG^KKP5Fqp(M4UL`R`CFSVi|HMt};MIo;=Cr2TvvIL|pGd-h3AwM~}v`C>m zBQ;MUQ6VKWEiJVuHLnC>KxSULLT0f-X>n=_7Z>$>ZUXWNaXuezUN%-0O7Nq!n zxOv{tfF$1!JMWWF+9`m*Fe~y5Nh$L{{vUP;fTWUdScU*;<==1&0wWR&!C@H&q?Uxk zG7v~E4u@YTm|7VkH3^_i{lQf2!TSvPd8wc-PJ&{BLVl4#f|XT*jzU^~Xu=T7!FxN2N%=)3Afr=C!G;=|C=?W>mSyIb7At@|M8#ZO E0L>Is2mk;8 diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderr b/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderr index a05dea3ff07e6003bbb459d776ea0b24a2338983..13cbd8370db64de67fd796516a2f95ff7df8f217 100644 GIT binary patch delta 66 zcmaFE|AT)+HY4++2@R8T82^Ci&6!NKFoD#`J}lEgf|E0u(l&ds+JhxFcd^NU8IzZ@ Gy8-~P(Hh_Y delta 62 zcmeyt|Av1j4q~+j2^O-7Z(hyD3So*( IKFO{R09Bt6mjD0& diff --git a/tests/ui/str/str-escape.stderr b/tests/ui/str/str-escape.stderr index c4aee2a110a..599c8de9757 100644 --- a/tests/ui/str/str-escape.stderr +++ b/tests/ui/str/str-escape.stderr @@ -22,7 +22,7 @@ warning: whitespace symbol '\u{c}' is not skipped | LL | let s = b"a\ | ________________^ -LL | | b"; +LL | | ␌b"; | | ^- whitespace symbol '\u{c}' is not skipped | |____| | From 2d7795dfb942d49d447837ef43db89216de15696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 9 Jul 2024 17:00:19 +0000 Subject: [PATCH 07/15] Be more accurate about calculating `display_col` from a `BytePos` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No longer track "zero-width" chars in `SourceMap`, read directly from the line when calculating the `display_col` of a `BytePos`. Move `char_width` to `rustc_span` and use it from the emitter. This change allows the following to properly align in terminals (depending on the font, the replaced control codepoints are rendered as 1 or 2 width, on my terminal they are rendered as 1, on VSCode text they are rendered as 2): ``` error: this file contains an unclosed delimiter --> $DIR/issue-68629.rs:5:17 | LL | ␜␟ts␀![{i | -- unclosed delimiter | | | unclosed delimiter LL | ␀␀ fn rݻoa>rݻm | ^ ``` --- Cargo.lock | 1 - compiler/rustc_errors/Cargo.toml | 1 - compiler/rustc_errors/src/emitter.rs | 17 +-- compiler/rustc_metadata/src/rmeta/decoder.rs | 2 - .../src/ich/impls_syntax.rs | 6 - .../rustc_span/src/analyze_source_file.rs | 40 +----- .../src/analyze_source_file/tests.rs | 24 +--- compiler/rustc_span/src/lib.rs | 133 +++++------------- compiler/rustc_span/src/source_map.rs | 2 - compiler/rustc_span/src/source_map/tests.rs | 2 - .../doctest/test-compile-fail3.stderr | 2 +- tests/ui/codemap_tests/tab_2.stderr | 2 +- tests/ui/error-codes/E0601.stderr | 2 +- tests/ui/issues/issue-44078.stderr | 2 +- tests/ui/lexer/unterminated-comment.stderr | 2 +- .../lexer/unterminated-nested-comment.stderr | 2 +- tests/ui/lint/issue-104897.stderr | 2 +- ...07423-unused-delim-only-one-no-pair.stderr | 2 +- tests/ui/parser/bad-char-literals.stderr | 4 +- tests/ui/parser/brace-in-let-chain.stderr | 2 +- tests/ui/parser/byte-string-literals.stderr | 2 +- tests/ui/parser/deli-ident-issue-1.stderr | 2 +- tests/ui/parser/issues/issue-103451.stderr | 2 +- tests/ui/parser/issues/issue-104367.stderr | 2 +- tests/ui/parser/issues/issue-105209.stderr | 2 +- tests/ui/parser/issues/issue-107705.stderr | 2 +- tests/ui/parser/issues/issue-2354.stderr | 2 +- tests/ui/parser/issues/issue-62546.stderr | 2 +- tests/ui/parser/issues/issue-62554.stderr | 2 +- tests/ui/parser/issues/issue-62881.stderr | 2 +- tests/ui/parser/issues/issue-62894.stderr | 2 +- tests/ui/parser/issues/issue-62973.stderr | 2 +- tests/ui/parser/issues/issue-63116.stderr | 2 +- tests/ui/parser/issues/issue-63135.stderr | 2 +- tests/ui/parser/issues/issue-66473.stderr | 10 +- ...invalid-syntax-in-enum-discriminant.stderr | 2 +- tests/ui/parser/issues/issue-68629.stderr | 14 +- tests/ui/parser/issues/issue-68730.stderr | 12 +- tests/ui/parser/issues/issue-81804.stderr | 2 +- tests/ui/parser/issues/issue-81827.stderr | 2 +- tests/ui/parser/issues/issue-84104.stderr | 2 +- tests/ui/parser/issues/issue-84148-2.stderr | 2 +- tests/ui/parser/issues/issue-88770.stderr | 2 +- .../missing-close-brace-in-impl-trait.stderr | 2 +- .../missing-close-brace-in-struct.stderr | 2 +- .../missing-close-brace-in-trait.stderr | 2 +- .../parser-ice-ed2021-await-105210.stderr | 2 +- tests/ui/parser/parser-recovery-1.stderr | 2 +- ...ral-carriage-returns-in-doc-comment.stderr | 4 +- tests/ui/parser/unbalanced-doublequote.stderr | 2 +- tests/ui/parser/unclosed-braces.stderr | 2 +- .../unmatched-delimiter-at-end-of-file.stderr | 2 +- tests/ui/parser/use-unclosed-brace.stderr | 2 +- tests/ui/parser/utf16-be-without-bom.stderr | 28 ++-- tests/ui/parser/utf16-le-without-bom.stderr | 24 ++-- .../rustdoc/unterminated-doc-comment.stderr | 2 +- ...incompatible-closure-captures-93117.stderr | 2 +- tests/ui/str/str-escape.stderr | 4 +- tests/ui/suggestions/issue-94171.stderr | 2 +- tests/ui/typeck/issue-91334.stderr | 2 +- 60 files changed, 134 insertions(+), 278 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1c1607e4c1a..d6060992ef2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4008,7 +4008,6 @@ dependencies = [ "termcolor", "termize", "tracing", - "unicode-width", "windows", ] diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml index cc114fdcd8c..2fff9f2de50 100644 --- a/compiler/rustc_errors/Cargo.toml +++ b/compiler/rustc_errors/Cargo.toml @@ -26,7 +26,6 @@ serde_json = "1.0.59" termcolor = "1.2.0" termize = "0.1.1" tracing = "0.1" -unicode-width = "0.1.4" # tidy-alphabetical-end [target.'cfg(windows)'.dependencies.windows] diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 95e1b5348b7..16fa0ff7a2d 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -8,7 +8,7 @@ //! The output types are defined in `rustc_session::config::ErrorOutputType`. use rustc_span::source_map::SourceMap; -use rustc_span::{FileLines, FileName, SourceFile, Span}; +use rustc_span::{char_width, FileLines, FileName, SourceFile, Span}; use crate::snippet::{ Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString, @@ -2614,21 +2614,6 @@ fn normalize_whitespace(str: &str) -> String { s } -fn char_width(ch: char) -> usize { - // FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is. For now, - // just accept that sometimes the code line will be longer than desired. - match ch { - '\t' => 4, - '\u{0000}' | '\u{0001}' | '\u{0002}' | '\u{0003}' | '\u{0004}' | '\u{0005}' - | '\u{0006}' | '\u{0007}' | '\u{0008}' | '\u{000B}' | '\u{000C}' | '\u{000D}' - | '\u{000E}' | '\u{000F}' | '\u{0010}' | '\u{0011}' | '\u{0012}' | '\u{0013}' - | '\u{0014}' | '\u{0015}' | '\u{0016}' | '\u{0017}' | '\u{0018}' | '\u{0019}' - | '\u{001A}' | '\u{001B}' | '\u{001C}' | '\u{001D}' | '\u{001E}' | '\u{001F}' - | '\u{007F}' => 1, - _ => unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1), - } -} - fn draw_col_separator(buffer: &mut StyledBuffer, line: usize, col: usize) { buffer.puts(line, col, "| ", Style::LineNumber); } diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 0ba9b940eed..9f2fe254753 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1727,7 +1727,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { source_len, lines, multibyte_chars, - non_narrow_chars, normalized_pos, stable_id, .. @@ -1779,7 +1778,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { self.cnum, lines, multibyte_chars, - non_narrow_chars, normalized_pos, source_file_index, ); diff --git a/compiler/rustc_query_system/src/ich/impls_syntax.rs b/compiler/rustc_query_system/src/ich/impls_syntax.rs index 5bd4fe04848..39da5e395c4 100644 --- a/compiler/rustc_query_system/src/ich/impls_syntax.rs +++ b/compiler/rustc_query_system/src/ich/impls_syntax.rs @@ -73,7 +73,6 @@ impl<'a> HashStable> for SourceFile { source_len: _, lines: _, ref multibyte_chars, - ref non_narrow_chars, ref normalized_pos, } = *self; @@ -98,11 +97,6 @@ impl<'a> HashStable> for SourceFile { char_pos.hash_stable(hcx, hasher); } - non_narrow_chars.len().hash_stable(hcx, hasher); - for &char_pos in non_narrow_chars.iter() { - char_pos.hash_stable(hcx, hasher); - } - normalized_pos.len().hash_stable(hcx, hasher); for &char_pos in normalized_pos.iter() { char_pos.hash_stable(hcx, hasher); diff --git a/compiler/rustc_span/src/analyze_source_file.rs b/compiler/rustc_span/src/analyze_source_file.rs index d9e1ebaf0bc..ba7e0cec5bd 100644 --- a/compiler/rustc_span/src/analyze_source_file.rs +++ b/compiler/rustc_span/src/analyze_source_file.rs @@ -1,5 +1,4 @@ use super::*; -use unicode_width::UnicodeWidthChar; #[cfg(test)] mod tests; @@ -9,15 +8,12 @@ mod tests; /// /// This function will use an SSE2 enhanced implementation if hardware support /// is detected at runtime. -pub fn analyze_source_file( - src: &str, -) -> (Vec, Vec, Vec) { +pub fn analyze_source_file(src: &str) -> (Vec, Vec) { let mut lines = vec![RelativeBytePos::from_u32(0)]; let mut multi_byte_chars = vec![]; - let mut non_narrow_chars = vec![]; // Calls the right implementation, depending on hardware support available. - analyze_source_file_dispatch(src, &mut lines, &mut multi_byte_chars, &mut non_narrow_chars); + analyze_source_file_dispatch(src, &mut lines, &mut multi_byte_chars); // The code above optimistically registers a new line *after* each \n // it encounters. If that point is already outside the source_file, remove @@ -30,7 +26,7 @@ pub fn analyze_source_file( } } - (lines, multi_byte_chars, non_narrow_chars) + (lines, multi_byte_chars) } cfg_match! { @@ -39,11 +35,10 @@ cfg_match! { src: &str, lines: &mut Vec, multi_byte_chars: &mut Vec, - non_narrow_chars: &mut Vec, ) { if is_x86_feature_detected!("sse2") { unsafe { - analyze_source_file_sse2(src, lines, multi_byte_chars, non_narrow_chars); + analyze_source_file_sse2(src, lines, multi_byte_chars); } } else { analyze_source_file_generic( @@ -52,7 +47,6 @@ cfg_match! { RelativeBytePos::from_u32(0), lines, multi_byte_chars, - non_narrow_chars, ); } } @@ -66,7 +60,6 @@ cfg_match! { src: &str, lines: &mut Vec, multi_byte_chars: &mut Vec, - non_narrow_chars: &mut Vec, ) { #[cfg(target_arch = "x86")] use std::arch::x86::*; @@ -159,7 +152,6 @@ cfg_match! { RelativeBytePos::from_usize(scan_start), lines, multi_byte_chars, - non_narrow_chars, ); } @@ -172,7 +164,6 @@ cfg_match! { RelativeBytePos::from_usize(tail_start), lines, multi_byte_chars, - non_narrow_chars, ); } } @@ -183,7 +174,6 @@ cfg_match! { src: &str, lines: &mut Vec, multi_byte_chars: &mut Vec, - non_narrow_chars: &mut Vec, ) { analyze_source_file_generic( src, @@ -191,7 +181,6 @@ cfg_match! { RelativeBytePos::from_u32(0), lines, multi_byte_chars, - non_narrow_chars, ); } } @@ -205,7 +194,6 @@ fn analyze_source_file_generic( output_offset: RelativeBytePos, lines: &mut Vec, multi_byte_chars: &mut Vec, - non_narrow_chars: &mut Vec, ) -> usize { assert!(src.len() >= scan_len); let mut i = 0; @@ -227,16 +215,8 @@ fn analyze_source_file_generic( let pos = RelativeBytePos::from_usize(i) + output_offset; - match byte { - b'\n' => { - lines.push(pos + RelativeBytePos(1)); - } - b'\t' => { - non_narrow_chars.push(NonNarrowChar::Tab(pos)); - } - _ => { - non_narrow_chars.push(NonNarrowChar::ZeroWidth(pos)); - } + if let b'\n' = byte { + lines.push(pos + RelativeBytePos(1)); } } else if byte >= 127 { // The slow path: @@ -252,14 +232,6 @@ fn analyze_source_file_generic( let mbc = MultiByteChar { pos, bytes: char_len as u8 }; multi_byte_chars.push(mbc); } - - // Assume control characters are zero width. - // FIXME: How can we decide between `width` and `width_cjk`? - let char_width = UnicodeWidthChar::width(c).unwrap_or(0); - - if char_width != 1 { - non_narrow_chars.push(NonNarrowChar::new(pos, char_width)); - } } i += char_len; diff --git a/compiler/rustc_span/src/analyze_source_file/tests.rs b/compiler/rustc_span/src/analyze_source_file/tests.rs index 0c77d080c17..e4a24239d8e 100644 --- a/compiler/rustc_span/src/analyze_source_file/tests.rs +++ b/compiler/rustc_span/src/analyze_source_file/tests.rs @@ -4,11 +4,10 @@ macro_rules! test { (case: $test_name:ident, text: $text:expr, lines: $lines:expr, - multi_byte_chars: $multi_byte_chars:expr, - non_narrow_chars: $non_narrow_chars:expr,) => { + multi_byte_chars: $multi_byte_chars:expr,) => { #[test] fn $test_name() { - let (lines, multi_byte_chars, non_narrow_chars) = analyze_source_file($text); + let (lines, multi_byte_chars) = analyze_source_file($text); let expected_lines: Vec = $lines.into_iter().map(RelativeBytePos).collect(); @@ -21,13 +20,6 @@ macro_rules! test { .collect(); assert_eq!(multi_byte_chars, expected_mbcs); - - let expected_nncs: Vec = $non_narrow_chars - .into_iter() - .map(|(pos, width)| NonNarrowChar::new(RelativeBytePos(pos), width)) - .collect(); - - assert_eq!(non_narrow_chars, expected_nncs); } }; } @@ -37,7 +29,6 @@ test!( text: "", lines: vec![], multi_byte_chars: vec![], - non_narrow_chars: vec![], ); test!( @@ -45,7 +36,6 @@ test!( text: "a\nc", lines: vec![0, 2], multi_byte_chars: vec![], - non_narrow_chars: vec![], ); test!( @@ -53,7 +43,6 @@ test!( text: "012345678\nabcdef012345678\na", lines: vec![0, 10, 26], multi_byte_chars: vec![], - non_narrow_chars: vec![], ); test!( @@ -61,7 +50,6 @@ test!( text: "01234β789\nbcdef0123456789abcdef", lines: vec![0, 11], multi_byte_chars: vec![(5, 2)], - non_narrow_chars: vec![], ); test!( @@ -69,7 +57,6 @@ test!( text: "01234\u{07}6789\nbcdef0123456789abcdef", lines: vec![0, 11], multi_byte_chars: vec![], - non_narrow_chars: vec![(5, 0)], ); test!( @@ -77,7 +64,6 @@ test!( text: "aβc", lines: vec![0], multi_byte_chars: vec![(1, 2)], - non_narrow_chars: vec![], ); test!( @@ -85,7 +71,6 @@ test!( text: "0123456789abcΔf012345β", lines: vec![0], multi_byte_chars: vec![(13, 2), (22, 2)], - non_narrow_chars: vec![], ); test!( @@ -93,7 +78,6 @@ test!( text: "0123456789abcdeΔ123456789abcdef01234", lines: vec![0], multi_byte_chars: vec![(15, 2)], - non_narrow_chars: vec![], ); test!( @@ -101,7 +85,6 @@ test!( text: "0123456789abcdeΔ....", lines: vec![0], multi_byte_chars: vec![(15, 2)], - non_narrow_chars: vec![], ); test!( @@ -109,7 +92,6 @@ test!( text: "0\t2", lines: vec![0], multi_byte_chars: vec![], - non_narrow_chars: vec![(1, 4)], ); test!( @@ -117,7 +99,6 @@ test!( text: "01\t3456789abcdef01234567\u{07}9", lines: vec![0], multi_byte_chars: vec![], - non_narrow_chars: vec![(2, 4), (24, 0)], ); test!( @@ -125,5 +106,4 @@ test!( text: "01\t345\n789abcΔf01234567\u{07}9\nbcΔf", lines: vec![0, 7, 27], multi_byte_chars: vec![(13, 2), (29, 2)], - non_narrow_chars: vec![(2, 4), (24, 0)], ); diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 266956d63d7..ea57c1ce818 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1345,68 +1345,6 @@ pub struct MultiByteChar { pub bytes: u8, } -/// Identifies an offset of a non-narrow character in a `SourceFile`. -#[derive(Copy, Clone, Encodable, Decodable, Eq, PartialEq, Debug, HashStable_Generic)] -pub enum NonNarrowChar { - /// Represents a zero-width character. - ZeroWidth(RelativeBytePos), - /// Represents a wide (full-width) character. - Wide(RelativeBytePos), - /// Represents a tab character, represented visually with a width of 4 characters. - Tab(RelativeBytePos), -} - -impl NonNarrowChar { - fn new(pos: RelativeBytePos, width: usize) -> Self { - match width { - 0 => NonNarrowChar::ZeroWidth(pos), - 2 => NonNarrowChar::Wide(pos), - 4 => NonNarrowChar::Tab(pos), - _ => panic!("width {width} given for non-narrow character"), - } - } - - /// Returns the relative offset of the character in the `SourceFile`. - pub fn pos(&self) -> RelativeBytePos { - match *self { - NonNarrowChar::ZeroWidth(p) | NonNarrowChar::Wide(p) | NonNarrowChar::Tab(p) => p, - } - } - - /// Returns the width of the character, 0 (zero-width) or 2 (wide). - pub fn width(&self) -> usize { - match *self { - NonNarrowChar::ZeroWidth(_) => 0, - NonNarrowChar::Wide(_) => 2, - NonNarrowChar::Tab(_) => 4, - } - } -} - -impl Add for NonNarrowChar { - type Output = Self; - - fn add(self, rhs: RelativeBytePos) -> Self { - match self { - NonNarrowChar::ZeroWidth(pos) => NonNarrowChar::ZeroWidth(pos + rhs), - NonNarrowChar::Wide(pos) => NonNarrowChar::Wide(pos + rhs), - NonNarrowChar::Tab(pos) => NonNarrowChar::Tab(pos + rhs), - } - } -} - -impl Sub for NonNarrowChar { - type Output = Self; - - fn sub(self, rhs: RelativeBytePos) -> Self { - match self { - NonNarrowChar::ZeroWidth(pos) => NonNarrowChar::ZeroWidth(pos - rhs), - NonNarrowChar::Wide(pos) => NonNarrowChar::Wide(pos - rhs), - NonNarrowChar::Tab(pos) => NonNarrowChar::Tab(pos - rhs), - } - } -} - /// Identifies an offset of a character that was normalized away from `SourceFile`. #[derive(Copy, Clone, Encodable, Decodable, Eq, PartialEq, Debug, HashStable_Generic)] pub struct NormalizedPos { @@ -1581,8 +1519,6 @@ pub struct SourceFile { pub lines: FreezeLock, /// Locations of multi-byte characters in the source code. pub multibyte_chars: Vec, - /// Width of characters that are not narrow in the source code. - pub non_narrow_chars: Vec, /// Locations of characters removed during normalization. pub normalized_pos: Vec, /// A hash of the filename & crate-id, used for uniquely identifying source @@ -1604,7 +1540,6 @@ impl Clone for SourceFile { source_len: self.source_len, lines: self.lines.clone(), multibyte_chars: self.multibyte_chars.clone(), - non_narrow_chars: self.non_narrow_chars.clone(), normalized_pos: self.normalized_pos.clone(), stable_id: self.stable_id, cnum: self.cnum, @@ -1679,7 +1614,6 @@ impl Encodable for SourceFile { } self.multibyte_chars.encode(s); - self.non_narrow_chars.encode(s); self.stable_id.encode(s); self.normalized_pos.encode(s); self.cnum.encode(s); @@ -1706,7 +1640,6 @@ impl Decodable for SourceFile { } }; let multibyte_chars: Vec = Decodable::decode(d); - let non_narrow_chars: Vec = Decodable::decode(d); let stable_id = Decodable::decode(d); let normalized_pos: Vec = Decodable::decode(d); let cnum: CrateNum = Decodable::decode(d); @@ -1721,7 +1654,6 @@ impl Decodable for SourceFile { external_src: FreezeLock::frozen(ExternalSource::Unneeded), lines: FreezeLock::new(lines), multibyte_chars, - non_narrow_chars, normalized_pos, stable_id, cnum, @@ -1809,8 +1741,7 @@ impl SourceFile { let source_len = src.len(); let source_len = u32::try_from(source_len).map_err(|_| OffsetOverflowError)?; - let (lines, multibyte_chars, non_narrow_chars) = - analyze_source_file::analyze_source_file(&src); + let (lines, multibyte_chars) = analyze_source_file::analyze_source_file(&src); Ok(SourceFile { name, @@ -1821,7 +1752,6 @@ impl SourceFile { source_len: RelativeBytePos::from_u32(source_len), lines: FreezeLock::frozen(SourceFileLines::Lines(lines)), multibyte_chars, - non_narrow_chars, normalized_pos, stable_id, cnum: LOCAL_CRATE, @@ -2130,41 +2060,44 @@ impl SourceFile { let pos = self.relative_position(pos); let (line, col_or_chpos) = self.lookup_file_pos(pos); if line > 0 { - let col = col_or_chpos; - let linebpos = self.lines()[line - 1]; - let col_display = { - let start_width_idx = self - .non_narrow_chars - .binary_search_by_key(&linebpos, |x| x.pos()) - .unwrap_or_else(|x| x); - let end_width_idx = self - .non_narrow_chars - .binary_search_by_key(&pos, |x| x.pos()) - .unwrap_or_else(|x| x); - let special_chars = end_width_idx - start_width_idx; - let non_narrow: usize = self.non_narrow_chars[start_width_idx..end_width_idx] - .iter() - .map(|x| x.width()) - .sum(); - col.0 - special_chars + non_narrow + let Some(code) = self.get_line(line - 1) else { + // If we don't have the code available, it is ok as a fallback to return the bytepos + // instead of the "display" column, which is only used to properly show underlines + // in the terminal. + // FIXME: we'll want better handling of this in the future for the sake of tools + // that want to use the display col instead of byte offsets to modify Rust code, but + // that is a problem for another day, the previous code was already incorrect for + // both displaying *and* third party tools using the json output naïvely. + tracing::info!("couldn't find line {line} {:?}", self.name); + return (line, col_or_chpos, col_or_chpos.0); }; - (line, col, col_display) + let display_col = code.chars().take(col_or_chpos.0).map(|ch| char_width(ch)).sum(); + (line, col_or_chpos, display_col) } else { - let chpos = col_or_chpos; - let col_display = { - let end_width_idx = self - .non_narrow_chars - .binary_search_by_key(&pos, |x| x.pos()) - .unwrap_or_else(|x| x); - let non_narrow: usize = - self.non_narrow_chars[0..end_width_idx].iter().map(|x| x.width()).sum(); - chpos.0 - end_width_idx + non_narrow - }; - (0, chpos, col_display) + // This is never meant to happen? + (0, col_or_chpos, col_or_chpos.0) } } } +pub fn char_width(ch: char) -> usize { + // FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is. For now, + // just accept that sometimes the code line will be longer than desired. + match ch { + '\t' => 4, + // Keep the following list in sync with `rustc_errors::emitter::OUTPUT_REPLACEMENTS`. These + // are control points that we replace before printing with a visible codepoint for the sake + // of being able to point at them with underlines. + '\u{0000}' | '\u{0001}' | '\u{0002}' | '\u{0003}' | '\u{0004}' | '\u{0005}' + | '\u{0006}' | '\u{0007}' | '\u{0008}' | '\u{000B}' | '\u{000C}' | '\u{000D}' + | '\u{000E}' | '\u{000F}' | '\u{0010}' | '\u{0011}' | '\u{0012}' | '\u{0013}' + | '\u{0014}' | '\u{0015}' | '\u{0016}' | '\u{0017}' | '\u{0018}' | '\u{0019}' + | '\u{001A}' | '\u{001B}' | '\u{001C}' | '\u{001D}' | '\u{001E}' | '\u{001F}' + | '\u{007F}' => 1, + _ => unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1), + } +} + /// Normalizes the source code and records the normalizations. fn normalize_src(src: &mut String) -> Vec { let mut normalized_pos = vec![]; diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index fb212d67997..14c157a0111 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -330,7 +330,6 @@ impl SourceMap { cnum: CrateNum, file_local_lines: FreezeLock, multibyte_chars: Vec, - non_narrow_chars: Vec, normalized_pos: Vec, metadata_index: u32, ) -> Lrc { @@ -348,7 +347,6 @@ impl SourceMap { source_len, lines: file_local_lines, multibyte_chars, - non_narrow_chars, normalized_pos, stable_id, cnum, diff --git a/compiler/rustc_span/src/source_map/tests.rs b/compiler/rustc_span/src/source_map/tests.rs index dcb02da3719..0c818b94b85 100644 --- a/compiler/rustc_span/src/source_map/tests.rs +++ b/compiler/rustc_span/src/source_map/tests.rs @@ -232,7 +232,6 @@ fn t10() { source_len, lines, multibyte_chars, - non_narrow_chars, normalized_pos, stable_id, .. @@ -246,7 +245,6 @@ fn t10() { CrateNum::ZERO, FreezeLock::new(lines.read().clone()), multibyte_chars, - non_narrow_chars, normalized_pos, 0, ); diff --git a/tests/rustdoc-ui/doctest/test-compile-fail3.stderr b/tests/rustdoc-ui/doctest/test-compile-fail3.stderr index 1ed45542251..09d78b2f346 100644 --- a/tests/rustdoc-ui/doctest/test-compile-fail3.stderr +++ b/tests/rustdoc-ui/doctest/test-compile-fail3.stderr @@ -2,7 +2,7 @@ error[E0765]: unterminated double quote string --> $DIR/test-compile-fail3.rs:3:1 | 3 | "fail - | ^^^^^^ + | ^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/codemap_tests/tab_2.stderr b/tests/ui/codemap_tests/tab_2.stderr index 4f9a937155d..b22c7b42665 100644 --- a/tests/ui/codemap_tests/tab_2.stderr +++ b/tests/ui/codemap_tests/tab_2.stderr @@ -4,7 +4,7 @@ error[E0765]: unterminated double quote string LL | """; | ___________________^ LL | | } - | |__^ + | |_^ error: aborting due to 1 previous error diff --git a/tests/ui/error-codes/E0601.stderr b/tests/ui/error-codes/E0601.stderr index 41a4a8f7dbb..c051bc0b31a 100644 --- a/tests/ui/error-codes/E0601.stderr +++ b/tests/ui/error-codes/E0601.stderr @@ -2,7 +2,7 @@ error[E0601]: `main` function not found in crate `E0601` --> $DIR/E0601.rs:1:37 | LL | - | ^ consider adding a `main` function to `$DIR/E0601.rs` + | ^ consider adding a `main` function to `$DIR/E0601.rs` error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-44078.stderr b/tests/ui/issues/issue-44078.stderr index 3e12de34e11..41106b29aad 100644 --- a/tests/ui/issues/issue-44078.stderr +++ b/tests/ui/issues/issue-44078.stderr @@ -4,7 +4,7 @@ error[E0765]: unterminated double quote string LL | "😊""; | _________^ LL | | } - | |__^ + | |_^ error: aborting due to 1 previous error diff --git a/tests/ui/lexer/unterminated-comment.stderr b/tests/ui/lexer/unterminated-comment.stderr index ea65bffd103..6ab5441ee05 100644 --- a/tests/ui/lexer/unterminated-comment.stderr +++ b/tests/ui/lexer/unterminated-comment.stderr @@ -2,7 +2,7 @@ error[E0758]: unterminated block comment --> $DIR/unterminated-comment.rs:1:1 | LL | /* - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/lexer/unterminated-nested-comment.stderr b/tests/ui/lexer/unterminated-nested-comment.stderr index 9117b689c94..78b72ce1fe4 100644 --- a/tests/ui/lexer/unterminated-nested-comment.stderr +++ b/tests/ui/lexer/unterminated-nested-comment.stderr @@ -12,7 +12,7 @@ LL | | /* | | | | | ...as last nested comment starts here, maybe you want to close this instead? LL | | */ - | |_--^ + | |_-^ | | | ...and last nested comment terminates here. diff --git a/tests/ui/lint/issue-104897.stderr b/tests/ui/lint/issue-104897.stderr index 1f3d40605f6..584902ee4c0 100644 --- a/tests/ui/lint/issue-104897.stderr +++ b/tests/ui/lint/issue-104897.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-104897.rs:5:18 | LL | fn f(){(print!(á - | -- - ^ + | -- - ^ | || | | || unclosed delimiter | |unclosed delimiter diff --git a/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.stderr b/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.stderr index ad90aeda1d1..d9748843fd7 100644 --- a/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.stderr +++ b/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-107423-unused-delim-only-one-no-pair.rs:7:11 | LL | fn a(){{{ - | --- ^ + | ---^ | ||| | ||unclosed delimiter | |unclosed delimiter diff --git a/tests/ui/parser/bad-char-literals.stderr b/tests/ui/parser/bad-char-literals.stderr index 38889da5da1..1fb324a1b7e 100644 --- a/tests/ui/parser/bad-char-literals.stderr +++ b/tests/ui/parser/bad-char-literals.stderr @@ -37,12 +37,12 @@ error: character literal may only contain one codepoint --> $DIR/bad-char-literals.rs:18:5 | LL | '-␀-'; - | ^^^^ + | ^^^^^ | help: if you meant to write a string literal, use double quotes | LL | "-␀-"; - | ~ ~ + | ~ ~ error: character constant must be escaped: `\t` --> $DIR/bad-char-literals.rs:21:6 diff --git a/tests/ui/parser/brace-in-let-chain.stderr b/tests/ui/parser/brace-in-let-chain.stderr index 7182d86d001..d76cb25ad8b 100644 --- a/tests/ui/parser/brace-in-let-chain.stderr +++ b/tests/ui/parser/brace-in-let-chain.stderr @@ -31,7 +31,7 @@ LL | && let () = () LL | } | - ...as it matches this but it has different indentation LL | } - | ^ + | ^ error: found a `{` in the middle of a let-chain --> $DIR/brace-in-let-chain.rs:14:24 diff --git a/tests/ui/parser/byte-string-literals.stderr b/tests/ui/parser/byte-string-literals.stderr index 655b6998e85..24e0eaac8fa 100644 --- a/tests/ui/parser/byte-string-literals.stderr +++ b/tests/ui/parser/byte-string-literals.stderr @@ -43,7 +43,7 @@ error[E0766]: unterminated double quote byte string LL | b"a | ______^ LL | | } - | |__^ + | |_^ error: aborting due to 6 previous errors diff --git a/tests/ui/parser/deli-ident-issue-1.stderr b/tests/ui/parser/deli-ident-issue-1.stderr index 78f5d7b63b9..d17913eb7ea 100644 --- a/tests/ui/parser/deli-ident-issue-1.stderr +++ b/tests/ui/parser/deli-ident-issue-1.stderr @@ -11,7 +11,7 @@ LL | } | - ...as it matches this but it has different indentation ... LL | fn main() { } - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/issues/issue-103451.stderr b/tests/ui/parser/issues/issue-103451.stderr index 7ad816e451e..f078e556e2b 100644 --- a/tests/ui/parser/issues/issue-103451.stderr +++ b/tests/ui/parser/issues/issue-103451.stderr @@ -4,7 +4,7 @@ error: this file contains an unclosed delimiter LL | struct S { | - unclosed delimiter LL | x: [u8; R - | - ^ + | - ^ | | | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-104367.stderr b/tests/ui/parser/issues/issue-104367.stderr index e6e76535761..c067d12e2d9 100644 --- a/tests/ui/parser/issues/issue-104367.stderr +++ b/tests/ui/parser/issues/issue-104367.stderr @@ -20,7 +20,7 @@ LL | #![cfg] { LL | #![w,) | - missing open `(` for this delimiter LL | - | ^ + | ^ error: aborting due to 2 previous errors diff --git a/tests/ui/parser/issues/issue-105209.stderr b/tests/ui/parser/issues/issue-105209.stderr index c75eafa1833..72017e4327d 100644 --- a/tests/ui/parser/issues/issue-105209.stderr +++ b/tests/ui/parser/issues/issue-105209.stderr @@ -16,7 +16,7 @@ LL | #![c={#![c[)x | | unclosed delimiter | unclosed delimiter LL | - | ^ + | ^ error: aborting due to 2 previous errors diff --git a/tests/ui/parser/issues/issue-107705.stderr b/tests/ui/parser/issues/issue-107705.stderr index 2d0c3e0e675..10a47b79931 100644 --- a/tests/ui/parser/issues/issue-107705.stderr +++ b/tests/ui/parser/issues/issue-107705.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-107705.rs:3:67 | LL | fn f() {a(b:&, - | - - unclosed delimiter ^ + | - - unclosed delimiter ^ | | | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-2354.stderr b/tests/ui/parser/issues/issue-2354.stderr index fd649a575c6..3e63473b6f4 100644 --- a/tests/ui/parser/issues/issue-2354.stderr +++ b/tests/ui/parser/issues/issue-2354.stderr @@ -10,7 +10,7 @@ LL | } | - ...as it matches this but it has different indentation ... LL | - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/issues/issue-62546.stderr b/tests/ui/parser/issues/issue-62546.stderr index 6889cb3b8e9..6435cb2b719 100644 --- a/tests/ui/parser/issues/issue-62546.stderr +++ b/tests/ui/parser/issues/issue-62546.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-62546.rs:1:60 | LL | pub t(# - | - unclosed delimiter ^ + | - unclosed delimiter ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/issues/issue-62554.stderr b/tests/ui/parser/issues/issue-62554.stderr index 37314dd39c7..d4aaef16181 100644 --- a/tests/ui/parser/issues/issue-62554.stderr +++ b/tests/ui/parser/issues/issue-62554.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-62554.rs:5:89 | LL | fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 { - | - - - - - ^ + | - - - - -^ | | | | | | | | | | | unclosed delimiter | | | | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-62881.stderr b/tests/ui/parser/issues/issue-62881.stderr index 2165a81a048..d8ae2cf0905 100644 --- a/tests/ui/parser/issues/issue-62881.stderr +++ b/tests/ui/parser/issues/issue-62881.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-62881.rs:3:96 | LL | fn f() -> isize { fn f() -> isize {} pub f< - | - unclosed delimiter ^ + | - unclosed delimiter ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/issues/issue-62894.stderr b/tests/ui/parser/issues/issue-62894.stderr index 870633fc96f..230319fc31e 100644 --- a/tests/ui/parser/issues/issue-62894.stderr +++ b/tests/ui/parser/issues/issue-62894.stderr @@ -8,7 +8,7 @@ LL | fn f() { assert_eq!(f(), (), assert_eq!(assert_eq! | unclosed delimiter LL | LL | fn main() {} - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/issues/issue-62973.stderr b/tests/ui/parser/issues/issue-62973.stderr index 14411a8cb78..493183988e1 100644 --- a/tests/ui/parser/issues/issue-62973.stderr +++ b/tests/ui/parser/issues/issue-62973.stderr @@ -25,7 +25,7 @@ LL | fn p() { match s { v, E { [) {) } | unclosed delimiter LL | LL | - | ^ + | ^ error: aborting due to 3 previous errors diff --git a/tests/ui/parser/issues/issue-63116.stderr b/tests/ui/parser/issues/issue-63116.stderr index 27c94f337bd..e0f7dd176ce 100644 --- a/tests/ui/parser/issues/issue-63116.stderr +++ b/tests/ui/parser/issues/issue-63116.stderr @@ -10,7 +10,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-63116.rs:3:18 | LL | impl W $DIR/issue-63135.rs:3:16 | LL | fn i(n{...,f # - | - - ^ + | - - ^ | | | | | unclosed delimiter | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-66473.stderr b/tests/ui/parser/issues/issue-66473.stderr index 4be992d5846..ba38c4fa1b7 100644 --- a/tests/ui/parser/issues/issue-66473.stderr +++ b/tests/ui/parser/issues/issue-66473.stderr @@ -8,7 +8,7 @@ error: unknown start of token: \u{0} --> $DIR/issue-66473.rs:4:3 | LL | #͈␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀ - | ^ + | ^^^^^^^^^^^^^^^^^^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used = note: character appears 17 more times @@ -17,19 +17,19 @@ error: unknown start of token: \u{1d} --> $DIR/issue-66473.rs:5:2 | LL | ␋␝6␝␀␀ - | ^ + | ^ error: unknown start of token: \u{1d} --> $DIR/issue-66473.rs:5:4 | LL | ␋␝6␝␀␀ - | ^ + | ^ error: unknown start of token: \u{0} --> $DIR/issue-66473.rs:5:5 | LL | ␋␝6␝␀␀ - | ^ + | ^^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used = note: character appears once more @@ -40,7 +40,7 @@ error: expected one of `!` or `[`, found `6` LL | #͈␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀ | - expected one of `!` or `[` LL | ␋␝6␝␀␀ - | ^ unexpected token + | ^ unexpected token error: aborting due to 6 previous errors diff --git a/tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.stderr b/tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.stderr index 9f631edf680..b82b0f3255b 100644 --- a/tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.stderr +++ b/tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.stderr @@ -41,7 +41,7 @@ LL | V = [Vec::new; { [0].len() ].len() as isize, | - missing open `[` for this delimiter ... LL | fn main() {} - | ^ + | ^ error: aborting due to 4 previous errors diff --git a/tests/ui/parser/issues/issue-68629.stderr b/tests/ui/parser/issues/issue-68629.stderr index ccb0624208b..f003f378179 100644 --- a/tests/ui/parser/issues/issue-68629.stderr +++ b/tests/ui/parser/issues/issue-68629.stderr @@ -8,13 +8,13 @@ error: unknown start of token: \u{1f} --> $DIR/issue-68629.rs:4:2 | LL | ␜␟ts␀![{i - | ^ + | ^ error: unknown start of token: \u{0} --> $DIR/issue-68629.rs:4:5 | LL | ␜␟ts␀![{i - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -22,7 +22,7 @@ error: unknown start of token: \u{0} --> $DIR/issue-68629.rs:5:1 | LL | ␀␀ fn rݻoa>rݻm - | ^ + | ^^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used = note: character appears once more @@ -31,11 +31,11 @@ error: this file contains an unclosed delimiter --> $DIR/issue-68629.rs:5:17 | LL | ␜␟ts␀![{i - | -- unclosed delimiter - | | - | unclosed delimiter + | -- unclosed delimiter + | | + | unclosed delimiter LL | ␀␀ fn rݻoa>rݻm - | ^ + | ^ error: aborting due to 5 previous errors diff --git a/tests/ui/parser/issues/issue-68730.stderr b/tests/ui/parser/issues/issue-68730.stderr index 6025ea8c1ae..9bd98287db3 100644 --- a/tests/ui/parser/issues/issue-68730.stderr +++ b/tests/ui/parser/issues/issue-68730.stderr @@ -10,7 +10,7 @@ error: unknown start of token: \u{0} --> $DIR/issue-68730.rs:5:8 | LL | enum␀em␀˂˂ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -18,30 +18,30 @@ error: unknown start of token: \u{2c2} --> $DIR/issue-68730.rs:5:9 | LL | enum␀em␀˂˂ - | ^^ + | ^^ | = note: character appears once more help: Unicode character '˂' (Modifier Letter Left Arrowhead) looks like '<' (Less-Than Sign), but it is not | LL | enum␀em␀<< - | ~~ + | ~~ error: unknown start of token: \u{2c2} --> $DIR/issue-68730.rs:5:10 | LL | enum␀em␀˂˂ - | ^ + | ^ | help: Unicode character '˂' (Modifier Letter Left Arrowhead) looks like '<' (Less-Than Sign), but it is not | LL | enum␀em␀˂< - | ~ + | ~ error: expected one of `#`, `>`, `const`, identifier, or lifetime, found `<` --> $DIR/issue-68730.rs:5:10 | LL | enum␀em␀˂˂ - | ^ expected one of `#`, `>`, `const`, identifier, or lifetime + | ^ expected one of `#`, `>`, `const`, identifier, or lifetime error: aborting due to 5 previous errors diff --git a/tests/ui/parser/issues/issue-81804.stderr b/tests/ui/parser/issues/issue-81804.stderr index de3b33ecd95..6caaaa792b1 100644 --- a/tests/ui/parser/issues/issue-81804.stderr +++ b/tests/ui/parser/issues/issue-81804.stderr @@ -10,7 +10,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-81804.rs:6:11 | LL | fn p([=(} - | -- ^ + | -- ^ | || | |unclosed delimiter | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-81827.stderr b/tests/ui/parser/issues/issue-81827.stderr index 63d135f73e6..d12c74b4a34 100644 --- a/tests/ui/parser/issues/issue-81827.stderr +++ b/tests/ui/parser/issues/issue-81827.stderr @@ -11,7 +11,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-81827.rs:10:27 | LL | fn r()->i{0|{#[cfg(r(0{]0 - | - - - ^ + | - - - ^ | | | | | | | missing open `[` for this delimiter | | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-84104.stderr b/tests/ui/parser/issues/issue-84104.stderr index e866d392267..b9b14c081a9 100644 --- a/tests/ui/parser/issues/issue-84104.stderr +++ b/tests/ui/parser/issues/issue-84104.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-84104.rs:2:13 | LL | #[i=i::<ښܖ< - | - ^ + | - ^ | | | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-84148-2.stderr b/tests/ui/parser/issues/issue-84148-2.stderr index d9b6b336a2c..b30f3d9114c 100644 --- a/tests/ui/parser/issues/issue-84148-2.stderr +++ b/tests/ui/parser/issues/issue-84148-2.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-84148-2.rs:2:16 | LL | fn f(t:for<>t? - | - ^ + | - ^ | | | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-88770.stderr b/tests/ui/parser/issues/issue-88770.stderr index 60ef025fa8b..5b54072d009 100644 --- a/tests/ui/parser/issues/issue-88770.stderr +++ b/tests/ui/parser/issues/issue-88770.stderr @@ -8,7 +8,7 @@ LL | fn m(){print!("",(c for&g | unclosed delimiter ... LL | e - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.stderr b/tests/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.stderr index 97aac661d46..39144246be2 100644 --- a/tests/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.stderr +++ b/tests/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.stderr @@ -5,7 +5,7 @@ LL | impl T for () { | - unclosed delimiter ... LL | - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr b/tests/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr index f70dac443e5..603aee02ad6 100644 --- a/tests/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr +++ b/tests/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr @@ -5,7 +5,7 @@ LL | pub(crate) struct Bar { | - unclosed delimiter ... LL | fn main() {} - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/mismatched-braces/missing-close-brace-in-trait.stderr b/tests/ui/parser/mismatched-braces/missing-close-brace-in-trait.stderr index a565ad49b22..a2fb698c80f 100644 --- a/tests/ui/parser/mismatched-braces/missing-close-brace-in-trait.stderr +++ b/tests/ui/parser/mismatched-braces/missing-close-brace-in-trait.stderr @@ -5,7 +5,7 @@ LL | trait T { | - unclosed delimiter ... LL | fn main() {} - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/parser-ice-ed2021-await-105210.stderr b/tests/ui/parser/parser-ice-ed2021-await-105210.stderr index fc54476c220..29abab2608e 100644 --- a/tests/ui/parser/parser-ice-ed2021-await-105210.stderr +++ b/tests/ui/parser/parser-ice-ed2021-await-105210.stderr @@ -28,7 +28,7 @@ LL | (( h (const {( default ( await ( await ( (move {await((((}} | unclosed delimiter ... LL | - | ^ + | ^ error: aborting due to 3 previous errors diff --git a/tests/ui/parser/parser-recovery-1.stderr b/tests/ui/parser/parser-recovery-1.stderr index 8162db3d8e5..4ed40d75326 100644 --- a/tests/ui/parser/parser-recovery-1.stderr +++ b/tests/ui/parser/parser-recovery-1.stderr @@ -10,7 +10,7 @@ LL | } | - ...as it matches this but it has different indentation ... LL | } - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr b/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr index 3150570e1c9..e235a158384 100644 --- a/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr +++ b/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr @@ -8,13 +8,13 @@ error: bare CR not allowed in doc-comment --> $DIR/several-carriage-returns-in-doc-comment.rs:6:32 | LL | /// This do␍c comment contains ␍three isolated `\r`␍ symbols - | ^ + | ^ error: bare CR not allowed in doc-comment --> $DIR/several-carriage-returns-in-doc-comment.rs:6:52 | LL | /// This do␍c comment contains ␍three isolated `\r`␍ symbols - | ^ + | ^ error: aborting due to 3 previous errors diff --git a/tests/ui/parser/unbalanced-doublequote.stderr b/tests/ui/parser/unbalanced-doublequote.stderr index d40b982da7c..9fdad87a86c 100644 --- a/tests/ui/parser/unbalanced-doublequote.stderr +++ b/tests/ui/parser/unbalanced-doublequote.stderr @@ -3,7 +3,7 @@ error[E0765]: unterminated double quote string | LL | / " LL | | } - | |__^ + | |_^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/unclosed-braces.stderr b/tests/ui/parser/unclosed-braces.stderr index acd92ac7925..74ac66af528 100644 --- a/tests/ui/parser/unclosed-braces.stderr +++ b/tests/ui/parser/unclosed-braces.stderr @@ -11,7 +11,7 @@ LL | } | - ...as it matches this but it has different indentation ... LL | - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/unmatched-delimiter-at-end-of-file.stderr b/tests/ui/parser/unmatched-delimiter-at-end-of-file.stderr index c6960892b2b..192f5324935 100644 --- a/tests/ui/parser/unmatched-delimiter-at-end-of-file.stderr +++ b/tests/ui/parser/unmatched-delimiter-at-end-of-file.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/unmatched-delimiter-at-end-of-file.rs:11:63 | LL | fn foo() { - | - unclosed delimiter ^ + | - unclosed delimiter ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/use-unclosed-brace.stderr b/tests/ui/parser/use-unclosed-brace.stderr index 6e624cb9131..1e62a0a06a3 100644 --- a/tests/ui/parser/use-unclosed-brace.stderr +++ b/tests/ui/parser/use-unclosed-brace.stderr @@ -5,7 +5,7 @@ LL | use foo::{bar, baz; | - unclosed delimiter ... LL | fn main() {} - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/utf16-be-without-bom.stderr b/tests/ui/parser/utf16-be-without-bom.stderr index 28cf6d97e96..55ebf7aacd2 100644 --- a/tests/ui/parser/utf16-be-without-bom.stderr +++ b/tests/ui/parser/utf16-be-without-bom.stderr @@ -10,7 +10,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:3 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -18,7 +18,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:5 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -26,7 +26,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:7 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -34,7 +34,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:9 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -42,7 +42,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:11 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -50,7 +50,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:13 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -58,7 +58,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:15 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -66,7 +66,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:17 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -74,7 +74,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:19 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -82,7 +82,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:21 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -90,7 +90,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:23 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -98,7 +98,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:25 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -106,12 +106,12 @@ error: expected one of `!` or `::`, found `n` --> $DIR/utf16-be-without-bom.rs:4:4 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ expected one of `!` or `::` + | ^ expected one of `!` or `::` | help: consider removing the space to spell keyword `fn` | LL | ␀fn␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ~~ + | ~~ error: aborting due to 14 previous errors diff --git a/tests/ui/parser/utf16-le-without-bom.stderr b/tests/ui/parser/utf16-le-without-bom.stderr index 53004ac942d..ad272a70f06 100644 --- a/tests/ui/parser/utf16-le-without-bom.stderr +++ b/tests/ui/parser/utf16-le-without-bom.stderr @@ -10,7 +10,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:4 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -18,7 +18,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:6 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -26,7 +26,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:8 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -34,7 +34,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:10 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -42,7 +42,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:12 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -50,7 +50,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:14 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -58,7 +58,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:16 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -66,7 +66,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:18 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -74,7 +74,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:20 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -82,7 +82,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:22 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -90,7 +90,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:24 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -106,7 +106,7 @@ error: expected one of `!` or `::`, found `n` --> $DIR/utf16-le-without-bom.rs:4:3 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ expected one of `!` or `::` + | ^ expected one of `!` or `::` | help: consider removing the space to spell keyword `fn` | diff --git a/tests/ui/rustdoc/unterminated-doc-comment.stderr b/tests/ui/rustdoc/unterminated-doc-comment.stderr index 2d96c606b16..f0b691333dc 100644 --- a/tests/ui/rustdoc/unterminated-doc-comment.stderr +++ b/tests/ui/rustdoc/unterminated-doc-comment.stderr @@ -2,7 +2,7 @@ error[E0758]: unterminated block doc-comment --> $DIR/unterminated-doc-comment.rs:1:1 | LL | /*! - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr b/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr index 004a057bbcd..c8cce162416 100644 --- a/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr +++ b/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:12:85 | LL | trait C{async fn new(val: T) {} - | - unclosed delimiter ^ + | - unclosed delimiter ^ error: aborting due to 1 previous error diff --git a/tests/ui/str/str-escape.stderr b/tests/ui/str/str-escape.stderr index 599c8de9757..4c8ee6bc013 100644 --- a/tests/ui/str/str-escape.stderr +++ b/tests/ui/str/str-escape.stderr @@ -23,8 +23,8 @@ warning: whitespace symbol '\u{c}' is not skipped LL | let s = b"a\ | ________________^ LL | | ␌b"; - | | ^- whitespace symbol '\u{c}' is not skipped - | |____| + | | ^ whitespace symbol '\u{c}' is not skipped + | |_____| | warning: 3 warnings emitted diff --git a/tests/ui/suggestions/issue-94171.stderr b/tests/ui/suggestions/issue-94171.stderr index b3440e46e8a..3d73ee1d27a 100644 --- a/tests/ui/suggestions/issue-94171.stderr +++ b/tests/ui/suggestions/issue-94171.stderr @@ -30,7 +30,7 @@ LL | (; {` | unclosed delimiter ... LL | - | ^ + | ^ error: aborting due to 3 previous errors diff --git a/tests/ui/typeck/issue-91334.stderr b/tests/ui/typeck/issue-91334.stderr index 7cb30eea530..01e34919ce6 100644 --- a/tests/ui/typeck/issue-91334.stderr +++ b/tests/ui/typeck/issue-91334.stderr @@ -11,7 +11,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-91334.rs:7:23 | LL | fn f(){||yield(((){), - | - - - ^ + | - - - ^ | | | | | | | missing open `(` for this delimiter | | unclosed delimiter From 9dffe9573be86ac7302fb2f27219ef8f9c78dea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 18 Jul 2024 20:02:08 +0000 Subject: [PATCH 08/15] =?UTF-8?q?Make=20unicode=20text=20flow=20control=20?= =?UTF-8?q?chars=20visible=20as=20=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We already point these out quite aggressively, telling people not to use them, but would normally be rendered as nothing. Having them visible will make it easier for people to actually deal with them. ``` error: unicode codepoint changing visible direction of text present in literal --> $DIR/unicode-control-codepoints.rs:26:22 | LL | println!("{:?}", '�'); | ^-^ | || | |'\u{202e}' | this literal contains an invisible unicode text flow control codepoint | = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen = help: if their presence wasn't intentional, you can remove them help: if you want to keep them but make them visible in your source code, you can escape them | LL | println!("{:?}", '\u{202e}'); | ~~~~~~~~ ``` vs the previous ``` error: unicode codepoint changing visible direction of text present in literal --> $DIR/unicode-control-codepoints.rs:26:22 | LL | println!("{:?}", ''); | ^- | || | |'\u{202e}' | this literal contains an invisible unicode text flow control codepoint | = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen = help: if their presence wasn't intentional, you can remove them help: if you want to keep them but make them visible in your source code, you can escape them | LL | println!("{:?}", '\u{202e}'); | ~~~~~~~~ ``` --- compiler/rustc_errors/src/emitter.rs | 21 ++-- compiler/rustc_span/src/lib.rs | 3 +- .../parser/unicode-control-codepoints.stderr | 98 +++++++++---------- 3 files changed, 62 insertions(+), 60 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 16fa0ff7a2d..58220c65490 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2558,18 +2558,19 @@ fn num_decimal_digits(num: usize) -> usize { } // We replace some characters so the CLI output is always consistent and underlines aligned. +// Keep the following list in sync with `rustc_span::char_width`. const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[ - ('\t', " "), // We do our own tab replacement + ('\t', " "), // We do our own tab replacement ('\u{200D}', ""), // Replace ZWJ with nothing for consistent terminal output of grapheme clusters. - ('\u{202A}', ""), // The following unicode text flow control characters are inconsistently - ('\u{202B}', ""), // supported across CLIs and can cause confusion due to the bytes on disk - ('\u{202D}', ""), // not corresponding to the visible source code, so we replace them always. - ('\u{202E}', ""), - ('\u{2066}', ""), - ('\u{2067}', ""), - ('\u{2068}', ""), - ('\u{202C}', ""), - ('\u{2069}', ""), + ('\u{202A}', "�"), // The following unicode text flow control characters are inconsistently + ('\u{202B}', "�"), // supported across CLIs and can cause confusion due to the bytes on disk + ('\u{202D}', "�"), // not corresponding to the visible source code, so we replace them always. + ('\u{202E}', "�"), + ('\u{2066}', "�"), + ('\u{2067}', "�"), + ('\u{2068}', "�"), + ('\u{202C}', "�"), + ('\u{2069}', "�"), // In terminals without Unicode support the following will be garbled, but in *all* terminals // the underlying codepoint will be as well. We could gate this replacement behind a "unicode // support" gate. diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index ea57c1ce818..7c8ac3be4be 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -2093,7 +2093,8 @@ pub fn char_width(ch: char) -> usize { | '\u{000E}' | '\u{000F}' | '\u{0010}' | '\u{0011}' | '\u{0012}' | '\u{0013}' | '\u{0014}' | '\u{0015}' | '\u{0016}' | '\u{0017}' | '\u{0018}' | '\u{0019}' | '\u{001A}' | '\u{001B}' | '\u{001C}' | '\u{001D}' | '\u{001E}' | '\u{001F}' - | '\u{007F}' => 1, + | '\u{007F}' | '\u{202A}' | '\u{202B}' | '\u{202D}' | '\u{202E}' | '\u{2066}' + | '\u{2067}' | '\u{2068}' | '\u{202C}' | '\u{2069}' => 1, _ => unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1), } } diff --git a/tests/ui/parser/unicode-control-codepoints.stderr b/tests/ui/parser/unicode-control-codepoints.stderr index fc071a94191..28de4ae72ab 100644 --- a/tests/ui/parser/unicode-control-codepoints.stderr +++ b/tests/ui/parser/unicode-control-codepoints.stderr @@ -17,78 +17,78 @@ LL | println!("{:?}", b"us\u{202B}e\u{202A}r"); error: non-ASCII character in byte string literal --> $DIR/unicode-control-codepoints.rs:16:26 | -LL | println!("{:?}", b"/* } if isAdmin begin admins only "); +LL | println!("{:?}", b"/*� } �if isAdmin� � begin admins only "); | ^ must be ASCII but is '\u{202e}' | help: if you meant to use the UTF-8 encoding of '\u{202e}', use \xHH escapes | -LL | println!("{:?}", b"/*\xE2\x80\xAE } if isAdmin begin admins only "); +LL | println!("{:?}", b"/*\xE2\x80\xAE } �if isAdmin� � begin admins only "); | ~~~~~~~~~~~~ error: non-ASCII character in byte string literal --> $DIR/unicode-control-codepoints.rs:16:30 | -LL | println!("{:?}", b"/* } if isAdmin begin admins only "); - | ^ must be ASCII but is '\u{2066}' +LL | println!("{:?}", b"/*� } �if isAdmin� � begin admins only "); + | ^ must be ASCII but is '\u{2066}' | help: if you meant to use the UTF-8 encoding of '\u{2066}', use \xHH escapes | -LL | println!("{:?}", b"/* } \xE2\x81\xA6if isAdmin begin admins only "); - | ~~~~~~~~~~~~ +LL | println!("{:?}", b"/*� } \xE2\x81\xA6if isAdmin� � begin admins only "); + | ~~~~~~~~~~~~ error: non-ASCII character in byte string literal --> $DIR/unicode-control-codepoints.rs:16:41 | -LL | println!("{:?}", b"/* } if isAdmin begin admins only "); - | ^ must be ASCII but is '\u{2069}' +LL | println!("{:?}", b"/*� } �if isAdmin� � begin admins only "); + | ^ must be ASCII but is '\u{2069}' | help: if you meant to use the UTF-8 encoding of '\u{2069}', use \xHH escapes | -LL | println!("{:?}", b"/* } if isAdmin\xE2\x81\xA9 begin admins only "); - | ~~~~~~~~~~~~ +LL | println!("{:?}", b"/*� } �if isAdmin\xE2\x81\xA9 � begin admins only "); + | ~~~~~~~~~~~~ error: non-ASCII character in byte string literal --> $DIR/unicode-control-codepoints.rs:16:43 | -LL | println!("{:?}", b"/* } if isAdmin begin admins only "); - | ^ must be ASCII but is '\u{2066}' +LL | println!("{:?}", b"/*� } �if isAdmin� � begin admins only "); + | ^ must be ASCII but is '\u{2066}' | help: if you meant to use the UTF-8 encoding of '\u{2066}', use \xHH escapes | -LL | println!("{:?}", b"/* } if isAdmin \xE2\x81\xA6 begin admins only "); - | ~~~~~~~~~~~~ +LL | println!("{:?}", b"/*� } �if isAdmin� \xE2\x81\xA6 begin admins only "); + | ~~~~~~~~~~~~ error: non-ASCII character in raw byte string literal --> $DIR/unicode-control-codepoints.rs:21:29 | -LL | println!("{:?}", br##"/* } if isAdmin begin admins only "##); +LL | println!("{:?}", br##"/*� } �if isAdmin� � begin admins only "##); | ^ must be ASCII but is '\u{202e}' error: non-ASCII character in raw byte string literal --> $DIR/unicode-control-codepoints.rs:21:33 | -LL | println!("{:?}", br##"/* } if isAdmin begin admins only "##); - | ^ must be ASCII but is '\u{2066}' +LL | println!("{:?}", br##"/*� } �if isAdmin� � begin admins only "##); + | ^ must be ASCII but is '\u{2066}' error: non-ASCII character in raw byte string literal --> $DIR/unicode-control-codepoints.rs:21:44 | -LL | println!("{:?}", br##"/* } if isAdmin begin admins only "##); - | ^ must be ASCII but is '\u{2069}' +LL | println!("{:?}", br##"/*� } �if isAdmin� � begin admins only "##); + | ^ must be ASCII but is '\u{2069}' error: non-ASCII character in raw byte string literal --> $DIR/unicode-control-codepoints.rs:21:46 | -LL | println!("{:?}", br##"/* } if isAdmin begin admins only "##); - | ^ must be ASCII but is '\u{2066}' +LL | println!("{:?}", br##"/*� } �if isAdmin� � begin admins only "##); + | ^ must be ASCII but is '\u{2066}' error: unicode codepoint changing visible direction of text present in comment --> $DIR/unicode-control-codepoints.rs:2:5 | -LL | // if access_level != "user" { // Check if admin - | ^^^^^^^^^^^^^^^^^^^^^^^^^--^^^^^^^^^^^^^^^^^^^^^ - | | || - | | |'\u{202a}' +LL | // if access_level != "us�e�r" { // Check if admin + | ^^^^^^^^^^^^^^^^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^^^ + | | | | + | | | '\u{202a}' | | '\u{202b}' | this comment contains invisible unicode text flow control codepoints | @@ -99,12 +99,12 @@ LL | // if access_level != "user" { // Check if admin error: unicode codepoint changing visible direction of text present in comment --> $DIR/unicode-control-codepoints.rs:30:1 | -LL | //"/* } if isAdmin begin admins only */" - | ^^^^^-^^-^^^^^^^^^--^^^^^^^^^^^^^^^^^^^^^ - | | | | || - | | | | |'\u{2066}' - | | | | '\u{2069}' - | | | '\u{2066}' +LL | //"/*� } �if isAdmin� � begin admins only */" + | ^^^^^-^^^-^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^^^ + | | | | | | + | | | | | '\u{2066}' + | | | | '\u{2069}' + | | | '\u{2066}' | | '\u{202e}' | this comment contains invisible unicode text flow control codepoints | @@ -114,12 +114,12 @@ LL | //"/* } if isAdmin begin admins only */" error: unicode codepoint changing visible direction of text present in literal --> $DIR/unicode-control-codepoints.rs:11:22 | -LL | println!("{:?}", "/* } if isAdmin begin admins only "); - | ^^^-^^-^^^^^^^^^--^^^^^^^^^^^^^^^^^^^ - | | | | || - | | | | |'\u{2066}' - | | | | '\u{2069}' - | | | '\u{2066}' +LL | println!("{:?}", "/*� } �if isAdmin� � begin admins only "); + | ^^^-^^^-^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^ + | | | | | | + | | | | | '\u{2066}' + | | | | '\u{2069}' + | | | '\u{2066}' | | '\u{202e}' | this literal contains invisible unicode text flow control codepoints | @@ -134,12 +134,12 @@ LL | println!("{:?}", "/*\u{202e} } \u{2066}if isAdmin\u{2069} \u{2066} begi error: unicode codepoint changing visible direction of text present in literal --> $DIR/unicode-control-codepoints.rs:14:22 | -LL | println!("{:?}", r##"/* } if isAdmin begin admins only "##); - | ^^^^^^-^^-^^^^^^^^^--^^^^^^^^^^^^^^^^^^^^^ - | | | | || - | | | | |'\u{2066}' - | | | | '\u{2069}' - | | | '\u{2066}' +LL | println!("{:?}", r##"/*� } �if isAdmin� � begin admins only "##); + | ^^^^^^-^^^-^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^^^ + | | | | | | + | | | | | '\u{2066}' + | | | | '\u{2069}' + | | | '\u{2066}' | | '\u{202e}' | this literal contains invisible unicode text flow control codepoints | @@ -153,8 +153,8 @@ LL | println!("{:?}", r##"/*\u{202e} } \u{2066}if isAdmin\u{2069} \u{2066} b error: unicode codepoint changing visible direction of text present in literal --> $DIR/unicode-control-codepoints.rs:26:22 | -LL | println!("{:?}", ''); - | ^- +LL | println!("{:?}", '�'); + | ^-^ | || | |'\u{202e}' | this literal contains an invisible unicode text flow control codepoint @@ -169,8 +169,8 @@ LL | println!("{:?}", '\u{202e}'); error: unicode codepoint changing visible direction of text present in doc comment --> $DIR/unicode-control-codepoints.rs:33:1 | -LL | /** ''); */fn foo() {} - | ^^^^^^^^^^^^ this doc comment contains an invisible unicode text flow control codepoint +LL | /** '�'); */fn foo() {} + | ^^^^^^^^^^^^^ this doc comment contains an invisible unicode text flow control codepoint | = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen = note: if their presence wasn't intentional, you can remove them @@ -181,8 +181,8 @@ error: unicode codepoint changing visible direction of text present in doc comme | LL | / /** LL | | * -LL | | * ''); */fn bar() {} - | |___________^ this doc comment contains an invisible unicode text flow control codepoint +LL | | * '�'); */fn bar() {} + | |____________^ this doc comment contains an invisible unicode text flow control codepoint | = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen = note: if their presence wasn't intentional, you can remove them From ef07fe1b2811836ee4b5b30e94c74061bc66d06c Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 17 Jul 2024 11:40:02 -0400 Subject: [PATCH 09/15] rewrite pointer-auth-link-with-c to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../pointer-auth-link-with-c/Makefile | 15 ---------- .../pointer-auth-link-with-c/rmake.rs | 28 +++++++++++++++++++ 3 files changed, 28 insertions(+), 16 deletions(-) delete mode 100644 tests/run-make/pointer-auth-link-with-c/Makefile create mode 100644 tests/run-make/pointer-auth-link-with-c/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 6b3533c2578..57e52551dee 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -60,7 +60,6 @@ run-make/pdb-buildinfo-cl-cmd/Makefile run-make/pgo-gen-lto/Makefile run-make/pgo-gen-no-imp-symbols/Makefile run-make/pgo-indirect-call-promotion/Makefile -run-make/pointer-auth-link-with-c/Makefile run-make/print-calling-conventions/Makefile run-make/print-target-list/Makefile run-make/raw-dylib-alt-calling-convention/Makefile diff --git a/tests/run-make/pointer-auth-link-with-c/Makefile b/tests/run-make/pointer-auth-link-with-c/Makefile deleted file mode 100644 index 8fcf10e2096..00000000000 --- a/tests/run-make/pointer-auth-link-with-c/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -include ../tools.mk - -# only-aarch64 -# ignore-cross-compile - -all: - $(COMPILE_OBJ) $(TMPDIR)/test.o test.c - $(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o - $(RUSTC) --target $(TARGET) -Z branch-protection=bti,pac-ret,leaf test.rs - $(call RUN,test) - - $(COMPILE_OBJ) $(TMPDIR)/test.o test.c -mbranch-protection=bti+pac-ret+leaf - $(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o - $(RUSTC) --target $(TARGET) -Z branch-protection=bti,pac-ret,leaf test.rs - $(call RUN,test) diff --git a/tests/run-make/pointer-auth-link-with-c/rmake.rs b/tests/run-make/pointer-auth-link-with-c/rmake.rs new file mode 100644 index 00000000000..960eafa546b --- /dev/null +++ b/tests/run-make/pointer-auth-link-with-c/rmake.rs @@ -0,0 +1,28 @@ +// `-Z branch protection` is an unstable compiler feature which adds pointer-authentication +// code (PAC), a useful hashing measure for verifying that pointers have not been modified. +// This test checks that compilation and execution is successful when this feature is activated, +// with some of its possible extra arguments (bti, pac-ret, leaf). +// See https://github.com/rust-lang/rust/pull/88354 + +//@ only-aarch64 +// Reason: branch protection is not supported on other architectures +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{build_native_static_lib, cc, is_msvc, llvm_ar, run, rustc}; + +fn main() { + build_native_static_lib("test"); + rustc().arg("-Zbranch-protection=bti,pac-ret,leaf").input("test.rs").run(); + run("test"); + cc().arg("-v") + .arg("-c") + .out_exe("test") + .input("test.c") + .arg("-mbranch-protection=bti+pac-ret+leaf") + .run(); + let obj_file = if is_msvc() { "test.obj" } else { "test" }; + llvm_ar().obj_to_ar().output_input("libtest.a", &obj_file).run(); + rustc().arg("-Zbranch-protection=bti,pac-ret,leaf").input("test.rs").run(); + run("test"); +} From 63286d80a1822df32c2f18fb7968a1368d8da8d6 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 17 Jul 2024 12:07:28 -0400 Subject: [PATCH 10/15] rewrite c-dynamic-rlib to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/c-dynamic-rlib/Makefile | 19 ---------------- tests/run-make/c-dynamic-rlib/rmake.rs | 22 +++++++++++++++++++ 3 files changed, 22 insertions(+), 20 deletions(-) delete mode 100644 tests/run-make/c-dynamic-rlib/Makefile create mode 100644 tests/run-make/c-dynamic-rlib/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 57e52551dee..b85e5dfe3ed 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -1,6 +1,5 @@ run-make/branch-protection-check-IBT/Makefile run-make/c-dynamic-dylib/Makefile -run-make/c-dynamic-rlib/Makefile run-make/c-unwind-abi-catch-lib-panic/Makefile run-make/cat-and-grep-sanity-check/Makefile run-make/cdylib-dylib-linkage/Makefile diff --git a/tests/run-make/c-dynamic-rlib/Makefile b/tests/run-make/c-dynamic-rlib/Makefile deleted file mode 100644 index 7b05e3d91a0..00000000000 --- a/tests/run-make/c-dynamic-rlib/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# This test checks that dynamic Rust linking with C does not encounter any errors, with static dependencies given preference over dynamic. (This is the default behaviour.) -# See https://github.com/rust-lang/rust/issues/10434 - -# ignore-cross-compile -include ../tools.mk - -# ignore-apple -# -# This hits an assertion in the linker on older versions of osx apparently - -# This overrides the LD_LIBRARY_PATH for RUN -TARGET_RPATH_DIR:=$(TARGET_RPATH_DIR):$(TMPDIR) - -all: $(call DYLIB,cfoo) - $(RUSTC) foo.rs - $(RUSTC) bar.rs - $(call RUN,bar) - $(call REMOVE_DYLIBS,cfoo) - $(call FAIL,bar) diff --git a/tests/run-make/c-dynamic-rlib/rmake.rs b/tests/run-make/c-dynamic-rlib/rmake.rs new file mode 100644 index 00000000000..c48b1edee9e --- /dev/null +++ b/tests/run-make/c-dynamic-rlib/rmake.rs @@ -0,0 +1,22 @@ +// This test checks that dynamic Rust linking with C does not encounter any errors in both +// compilation and execution, with static dependencies given preference over dynamic. +// (This is the default behaviour.) +// See https://github.com/rust-lang/rust/issues/10434 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +//FIXME(Oneirical): test on apple because older versions of osx are failing apparently + +use run_make_support::{ + build_native_dynamic_lib, dynamic_lib_name, fs_wrapper, run, run_fail, rustc, +}; + +fn main() { + build_native_dynamic_lib("cfoo"); + rustc().input("foo.rs").run(); + rustc().input("bar.rs").run(); + run("bar"); + fs_wrapper::remove_file(dynamic_lib_name("cfoo")); + run_fail("bar"); +} From 710e7b0c7581efcbb2d913738d1ec17f0a726387 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 17 Jul 2024 15:11:09 -0400 Subject: [PATCH 11/15] rewrite c-dynamic-dylib to rmake --- .../src/external_deps/c_build.rs | 37 ++++++++++++++++++- src/tools/run-make-support/src/fs.rs | 15 +++++++- src/tools/run-make-support/src/lib.rs | 2 +- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/c-dynamic-dylib/Makefile | 16 -------- tests/run-make/c-dynamic-dylib/rmake.rs | 17 +++++++++ tests/run-make/c-dynamic-rlib/rmake.rs | 8 +--- 7 files changed, 69 insertions(+), 27 deletions(-) delete mode 100644 tests/run-make/c-dynamic-dylib/Makefile create mode 100644 tests/run-make/c-dynamic-dylib/rmake.rs diff --git a/src/tools/run-make-support/src/external_deps/c_build.rs b/src/tools/run-make-support/src/external_deps/c_build.rs index 35b2bf75c95..86c9c081831 100644 --- a/src/tools/run-make-support/src/external_deps/c_build.rs +++ b/src/tools/run-make-support/src/external_deps/c_build.rs @@ -1,10 +1,13 @@ use std::path::PathBuf; -use crate::artifact_names::static_lib_name; +use super::cygpath::get_windows_path; +use crate::artifact_names::{dynamic_lib_name, static_lib_name}; use crate::external_deps::cc::cc; use crate::external_deps::llvm::llvm_ar; use crate::path_helpers::path; -use crate::targets::is_msvc; +use crate::targets::{is_darwin, is_msvc, is_windows}; + +// FIXME(Oneirical): These native build functions should take a Path-based generic. /// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name. #[track_caller] @@ -25,3 +28,33 @@ pub fn build_native_static_lib(lib_name: &str) -> PathBuf { llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run(); path(lib_path) } + +/// Builds a dynamic lib. The filename is computed in a target-dependent manner, relying on +/// [`std::env::consts::DLL_PREFIX`] and [`std::env::consts::DLL_EXTENSION`]. +#[track_caller] +pub fn build_native_dynamic_lib(lib_name: &str) -> PathBuf { + let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") }; + let src = format!("{lib_name}.c"); + let lib_path = dynamic_lib_name(lib_name); + if is_msvc() { + cc().arg("-c").out_exe(&obj_file).input(src).run(); + } else { + cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run(); + }; + let obj_file = if is_msvc() { format!("{lib_name}.obj") } else { format!("{lib_name}.o") }; + if is_msvc() { + let mut out_arg = "-out:".to_owned(); + out_arg.push_str(&get_windows_path(&lib_path)); + cc().input(&obj_file).args(&["-link", "-dll", &out_arg]).run(); + } else if is_darwin() { + cc().out_exe(&lib_path).input(&obj_file).args(&["-dynamiclib", "-Wl,-dylib"]).run(); + } else if is_windows() { + cc().out_exe(&lib_path) + .input(&obj_file) + .args(&["-shared", &format!("-Wl,--out-implib={lib_path}.a")]) + .run(); + } else { + cc().out_exe(&lib_path).input(&obj_file).arg("-shared").run(); + } + path(lib_path) +} diff --git a/src/tools/run-make-support/src/fs.rs b/src/tools/run-make-support/src/fs.rs index f346e983aea..0a796161633 100644 --- a/src/tools/run-make-support/src/fs.rs +++ b/src/tools/run-make-support/src/fs.rs @@ -1,5 +1,5 @@ use std::io; -use std::path::Path; +use std::path::{Path, PathBuf}; // FIXME(jieyouxu): modify create_symlink to panic on windows. @@ -176,3 +176,16 @@ pub fn set_permissions>(path: P, perm: std::fs::Permissions) { path.as_ref().display() )); } + +/// A function which prints all file names in the directory `dir` similarly to Unix's `ls`. +/// Useful for debugging. +/// Usage: `eprintln!("{:#?}", shallow_find_dir_entries(some_dir));` +#[track_caller] +pub fn shallow_find_dir_entries>(dir: P) -> Vec { + let paths = read_dir(dir); + let mut output = Vec::new(); + for path in paths { + output.push(path.unwrap().path()); + } + output +} diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index b85191970de..a4bb9056346 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -43,7 +43,7 @@ pub use wasmparser; pub use external_deps::{c_build, cc, clang, htmldocck, llvm, python, rustc, rustdoc}; // These rely on external dependencies. -pub use c_build::build_native_static_lib; +pub use c_build::{build_native_dynamic_lib, build_native_static_lib}; pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc}; pub use clang::{clang, Clang}; pub use htmldocck::htmldocck; diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index b85e5dfe3ed..88010f93906 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -1,5 +1,4 @@ run-make/branch-protection-check-IBT/Makefile -run-make/c-dynamic-dylib/Makefile run-make/c-unwind-abi-catch-lib-panic/Makefile run-make/cat-and-grep-sanity-check/Makefile run-make/cdylib-dylib-linkage/Makefile diff --git a/tests/run-make/c-dynamic-dylib/Makefile b/tests/run-make/c-dynamic-dylib/Makefile deleted file mode 100644 index 39561b28222..00000000000 --- a/tests/run-make/c-dynamic-dylib/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# This test checks that dynamic Rust linking with C does not encounter any errors, with dynamic dependencies given preference over static. -# See https://github.com/rust-lang/rust/issues/10434 - -# ignore-cross-compile -include ../tools.mk - -# ignore-apple -# -# This hits an assertion in the linker on older versions of osx apparently - -all: $(call DYLIB,cfoo) - $(RUSTC) foo.rs -C prefer-dynamic - $(RUSTC) bar.rs - $(call RUN,bar) - $(call REMOVE_DYLIBS,cfoo) - $(call FAIL,bar) diff --git a/tests/run-make/c-dynamic-dylib/rmake.rs b/tests/run-make/c-dynamic-dylib/rmake.rs new file mode 100644 index 00000000000..65b5e02abf0 --- /dev/null +++ b/tests/run-make/c-dynamic-dylib/rmake.rs @@ -0,0 +1,17 @@ +// This test checks that dynamic Rust linking with C does not encounter any errors in both +// compilation and execution, with dynamic dependencies given preference over static. +// See https://github.com/rust-lang/rust/issues/10434 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +use run_make_support::{build_native_dynamic_lib, dynamic_lib_name, rfs, run, run_fail, rustc}; + +fn main() { + build_native_dynamic_lib("cfoo"); + rustc().input("foo.rs").arg("-Cprefer-dynamic").run(); + rustc().input("bar.rs").run(); + run("bar"); + rfs::remove_file(dynamic_lib_name("cfoo")); + run_fail("bar"); +} diff --git a/tests/run-make/c-dynamic-rlib/rmake.rs b/tests/run-make/c-dynamic-rlib/rmake.rs index c48b1edee9e..b59887bbdd6 100644 --- a/tests/run-make/c-dynamic-rlib/rmake.rs +++ b/tests/run-make/c-dynamic-rlib/rmake.rs @@ -6,17 +6,13 @@ //@ ignore-cross-compile // Reason: the compiled binary is executed -//FIXME(Oneirical): test on apple because older versions of osx are failing apparently - -use run_make_support::{ - build_native_dynamic_lib, dynamic_lib_name, fs_wrapper, run, run_fail, rustc, -}; +use run_make_support::{build_native_dynamic_lib, dynamic_lib_name, rfs, run, run_fail, rustc}; fn main() { build_native_dynamic_lib("cfoo"); rustc().input("foo.rs").run(); rustc().input("bar.rs").run(); run("bar"); - fs_wrapper::remove_file(dynamic_lib_name("cfoo")); + rfs::remove_file(dynamic_lib_name("cfoo")); run_fail("bar"); } From 850faea030db4b260719d99be4191d7803efdb35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 23 Jul 2024 19:43:46 +0000 Subject: [PATCH 12/15] Do not use question as label We don't want to have questions in the diagnostic output. Instead, we use wording that communicates uncertainty, like "might": ``` error[E0432]: unresolved import `spam` --> $DIR/import-from-missing-star-3.rs:2:9 | LL | use spam::*; | ^^^^ you might be missing crate `spam` | = help: consider adding `extern crate spam` to use the `spam` crate ``` --- compiler/rustc_resolve/src/diagnostics.rs | 4 +- .../ice-unresolved-import-100241.stderr | 2 +- .../unresolved-import-recovery.stderr | 4 +- tests/rustdoc-ui/issues/issue-61732.rs | 2 +- tests/rustdoc-ui/issues/issue-61732.stderr | 4 +- .../session-diagnostic/diagnostic-derive.rs | 6 +-- .../diagnostic-derive.stderr | 12 ++--- .../subdiagnostic-derive.rs | 32 ++++++------- .../subdiagnostic-derive.stderr | 32 ++++++------- .../field-attributes-vis-unresolved.stderr | 8 ++-- tests/ui/error-codes/E0432.stderr | 2 +- .../feature-gate-extern_absolute_paths.stderr | 6 +-- .../imports/import-from-missing-star-2.stderr | 2 +- .../imports/import-from-missing-star-3.stderr | 4 +- .../imports/import-from-missing-star.stderr | 2 +- tests/ui/imports/import3.stderr | 2 +- tests/ui/imports/issue-109343.stderr | 2 +- tests/ui/imports/issue-1697.rs | 6 ++- tests/ui/imports/issue-1697.stderr | 2 +- tests/ui/imports/issue-33464.stderr | 6 +-- tests/ui/imports/issue-36881.stderr | 2 +- tests/ui/imports/issue-37887.stderr | 2 +- tests/ui/imports/issue-53269.stderr | 2 +- tests/ui/imports/issue-55457.stderr | 2 +- tests/ui/imports/issue-81413.stderr | 2 +- tests/ui/imports/tool-mod-child.rs | 4 +- tests/ui/imports/tool-mod-child.stderr | 12 ++--- .../ui/imports/unresolved-imports-used.stderr | 8 ++-- .../keyword-extern-as-identifier-use.stderr | 2 +- .../ui/macros/meta-item-absolute-path.stderr | 8 ++-- tests/ui/privacy/restricted/test.rs | 2 +- tests/ui/privacy/restricted/test.stderr | 4 +- tests/ui/resolve/editions-crate-root-2015.rs | 4 +- .../resolve/editions-crate-root-2015.stderr | 8 ++-- tests/ui/resolve/extern-prelude-fail.stderr | 6 +-- tests/ui/resolve/issue-82865.rs | 2 +- tests/ui/resolve/issue-82865.stderr | 4 +- .../ui/resolve/resolve-bad-visibility.stderr | 8 ++-- .../issue-102156.stderr | 8 ++-- .../portable-intrinsics-arent-exposed.stderr | 4 +- .../ui/underscore-imports/issue-110164.stderr | 8 ++-- .../unresolved-asterisk-imports.stderr | 2 +- tests/ui/unresolved/unresolved-import.rs | 48 +++++++++++-------- tests/ui/unresolved/unresolved-import.stderr | 12 ++--- 44 files changed, 156 insertions(+), 148 deletions(-) diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index bf7972e392c..046ae5fc593 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -2012,7 +2012,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { ) } else if ident.name == sym::core { ( - format!("maybe a missing crate `{ident}`?"), + format!("you might be missing crate `{ident}`"), Some(( vec![(ident.span, "std".to_string())], "try using `std` instead of `core`".to_string(), @@ -2021,7 +2021,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { ) } else if self.tcx.sess.is_rust_2015() { ( - format!("maybe a missing crate `{ident}`?"), + format!("you might be missing crate `{ident}`"), Some(( vec![], format!( diff --git a/tests/rustdoc-ui/ice-unresolved-import-100241.stderr b/tests/rustdoc-ui/ice-unresolved-import-100241.stderr index 57fbbb59c8d..e23e0f01fab 100644 --- a/tests/rustdoc-ui/ice-unresolved-import-100241.stderr +++ b/tests/rustdoc-ui/ice-unresolved-import-100241.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `inner` --> $DIR/ice-unresolved-import-100241.rs:9:13 | LL | pub use inner::S; - | ^^^^^ maybe a missing crate `inner`? + | ^^^^^ you might be missing crate `inner` | = help: consider adding `extern crate inner` to use the `inner` crate diff --git a/tests/rustdoc-ui/intra-doc/unresolved-import-recovery.stderr b/tests/rustdoc-ui/intra-doc/unresolved-import-recovery.stderr index 8315c73a639..a74e6b73938 100644 --- a/tests/rustdoc-ui/intra-doc/unresolved-import-recovery.stderr +++ b/tests/rustdoc-ui/intra-doc/unresolved-import-recovery.stderr @@ -1,8 +1,8 @@ -error[E0433]: failed to resolve: maybe a missing crate `unresolved_crate`? +error[E0433]: failed to resolve: you might be missing crate `unresolved_crate` --> $DIR/unresolved-import-recovery.rs:3:5 | LL | use unresolved_crate::module::Name; - | ^^^^^^^^^^^^^^^^ maybe a missing crate `unresolved_crate`? + | ^^^^^^^^^^^^^^^^ you might be missing crate `unresolved_crate` | = help: consider adding `extern crate unresolved_crate` to use the `unresolved_crate` crate diff --git a/tests/rustdoc-ui/issues/issue-61732.rs b/tests/rustdoc-ui/issues/issue-61732.rs index 4bd8efeaa3b..3969ab92c32 100644 --- a/tests/rustdoc-ui/issues/issue-61732.rs +++ b/tests/rustdoc-ui/issues/issue-61732.rs @@ -1,4 +1,4 @@ // This previously triggered an ICE. pub(in crate::r#mod) fn main() {} -//~^ ERROR failed to resolve: maybe a missing crate `r#mod` +//~^ ERROR failed to resolve: you might be missing crate `r#mod` diff --git a/tests/rustdoc-ui/issues/issue-61732.stderr b/tests/rustdoc-ui/issues/issue-61732.stderr index f351f52d1e1..f49d53b0d9a 100644 --- a/tests/rustdoc-ui/issues/issue-61732.stderr +++ b/tests/rustdoc-ui/issues/issue-61732.stderr @@ -1,8 +1,8 @@ -error[E0433]: failed to resolve: maybe a missing crate `r#mod`? +error[E0433]: failed to resolve: you might be missing crate `r#mod` --> $DIR/issue-61732.rs:3:15 | LL | pub(in crate::r#mod) fn main() {} - | ^^^^^ maybe a missing crate `r#mod`? + | ^^^^^ you might be missing crate `r#mod` | = help: consider adding `extern crate r#mod` to use the `r#mod` crate diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index dc268dfc5ca..e8cec632177 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -56,7 +56,7 @@ enum DiagnosticOnEnum { #[derive(Diagnostic)] #[diag(no_crate_example, code = E0123)] #[diag = "E0123"] -//~^ ERROR failed to resolve: maybe a missing crate `core` +//~^ ERROR failed to resolve: you might be missing crate `core` struct WrongStructAttrStyle {} #[derive(Diagnostic)] @@ -801,7 +801,7 @@ struct SuggestionsNoItem { struct SuggestionsInvalidItem { #[suggestion(code(foo))] //~^ ERROR `code(...)` must contain only string literals - //~| ERROR failed to resolve: maybe a missing crate `core` + //~| ERROR failed to resolve: you might be missing crate `core` sub: Span, } @@ -809,7 +809,7 @@ struct SuggestionsInvalidItem { #[diag(no_crate_example)] struct SuggestionsInvalidLiteral { #[suggestion(code = 3)] - //~^ ERROR failed to resolve: maybe a missing crate `core` + //~^ ERROR failed to resolve: you might be missing crate `core` sub: Span, } diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index e36c6852d3b..97f9896f3a7 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -524,23 +524,23 @@ LL | #[suggestion(no_crate_suggestion, code = "")] = help: to show a suggestion consisting of multiple parts, use a `Subdiagnostic` annotated with `#[multipart_suggestion(...)]` = help: to show a variable set of suggestions, use a `Vec` of `Subdiagnostic`s annotated with `#[suggestion(...)]` -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/diagnostic-derive.rs:58:8 | LL | #[diag = "E0123"] - | ^ maybe a missing crate `core`? + | ^ you might be missing crate `core` -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/diagnostic-derive.rs:802:23 | LL | #[suggestion(code(foo))] - | ^^^ maybe a missing crate `core`? + | ^^^ you might be missing crate `core` -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/diagnostic-derive.rs:811:25 | LL | #[suggestion(code = 3)] - | ^ maybe a missing crate `core`? + | ^ you might be missing crate `core` error: cannot find attribute `nonsense` in this scope --> $DIR/diagnostic-derive.rs:63:3 diff --git a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs index 659ae54f7a3..c837372a7a7 100644 --- a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs +++ b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs @@ -94,8 +94,8 @@ struct G { #[derive(Subdiagnostic)] #[label("...")] -//~^ ERROR failed to resolve: maybe a missing crate `core`? -//~| NOTE maybe a missing crate `core`? +//~^ ERROR failed to resolve: you might be missing crate `core` +//~| NOTE you might be missing crate `core` struct H { #[primary_span] span: Span, @@ -310,8 +310,8 @@ struct AB { #[derive(Subdiagnostic)] union AC { - //~^ ERROR failed to resolve: maybe a missing crate `core`? - //~| NOTE maybe a missing crate `core`? + //~^ ERROR failed to resolve: you might be missing crate `core` + //~| NOTE you might be missing crate `core` span: u32, b: u64, } @@ -581,8 +581,8 @@ struct BD { span2: Span, #[suggestion_part(foo = "bar")] //~^ ERROR `code` is the only valid nested attribute - //~| ERROR failed to resolve: maybe a missing crate `core`? - //~| NOTE maybe a missing crate `core`? + //~| ERROR failed to resolve: you might be missing crate `core` + //~| NOTE you might be missing crate `core` span4: Span, #[suggestion_part(code = "...")] //~^ ERROR the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` @@ -674,8 +674,8 @@ enum BL { struct BM { #[suggestion_part(code("foo"))] //~^ ERROR expected exactly one string literal for `code = ...` - //~| ERROR failed to resolve: maybe a missing crate `core`? - //~| NOTE maybe a missing crate `core`? + //~| ERROR failed to resolve: you might be missing crate `core` + //~| NOTE you might be missing crate `core` span: Span, r#type: String, } @@ -685,8 +685,8 @@ struct BM { struct BN { #[suggestion_part(code("foo", "bar"))] //~^ ERROR expected exactly one string literal for `code = ...` - //~| ERROR failed to resolve: maybe a missing crate `core`? - //~| NOTE maybe a missing crate `core`? + //~| ERROR failed to resolve: you might be missing crate `core` + //~| NOTE you might be missing crate `core` span: Span, r#type: String, } @@ -696,8 +696,8 @@ struct BN { struct BO { #[suggestion_part(code(3))] //~^ ERROR expected exactly one string literal for `code = ...` - //~| ERROR failed to resolve: maybe a missing crate `core`? - //~| NOTE maybe a missing crate `core`? + //~| ERROR failed to resolve: you might be missing crate `core` + //~| NOTE you might be missing crate `core` span: Span, r#type: String, } @@ -718,8 +718,8 @@ struct BP { #[multipart_suggestion(no_crate_example)] struct BQ { #[suggestion_part(code = 3)] - //~^ ERROR failed to resolve: maybe a missing crate `core`? - //~| NOTE maybe a missing crate `core`? + //~^ ERROR failed to resolve: you might be missing crate `core` + //~| NOTE you might be missing crate `core` span: Span, r#type: String, } @@ -811,8 +811,8 @@ struct SuggestionStyleInvalid3 { #[derive(Subdiagnostic)] #[suggestion(no_crate_example, code = "", style("foo"))] //~^ ERROR expected `= "xxx"` -//~| ERROR failed to resolve: maybe a missing crate `core`? -//~| NOTE maybe a missing crate `core`? +//~| ERROR failed to resolve: you might be missing crate `core` +//~| NOTE you might be missing crate `core` struct SuggestionStyleInvalid4 { #[primary_span] sub: Span, diff --git a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr index fccf3757dbe..96f6ef06d1d 100644 --- a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr +++ b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr @@ -451,53 +451,53 @@ error: suggestion without `#[primary_span]` field LL | #[suggestion(no_crate_example, code = "")] | ^ -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/subdiagnostic-derive.rs:96:9 | LL | #[label("...")] - | ^^^^^ maybe a missing crate `core`? + | ^^^^^ you might be missing crate `core` -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/subdiagnostic-derive.rs:312:1 | LL | union AC { - | ^^^^^ maybe a missing crate `core`? + | ^^^^^ you might be missing crate `core` -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/subdiagnostic-derive.rs:582:27 | LL | #[suggestion_part(foo = "bar")] - | ^ maybe a missing crate `core`? + | ^ you might be missing crate `core` -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/subdiagnostic-derive.rs:675:28 | LL | #[suggestion_part(code("foo"))] - | ^^^^^ maybe a missing crate `core`? + | ^^^^^ you might be missing crate `core` -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/subdiagnostic-derive.rs:686:28 | LL | #[suggestion_part(code("foo", "bar"))] - | ^^^^^ maybe a missing crate `core`? + | ^^^^^ you might be missing crate `core` -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/subdiagnostic-derive.rs:697:28 | LL | #[suggestion_part(code(3))] - | ^ maybe a missing crate `core`? + | ^ you might be missing crate `core` -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/subdiagnostic-derive.rs:720:30 | LL | #[suggestion_part(code = 3)] - | ^ maybe a missing crate `core`? + | ^ you might be missing crate `core` -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/subdiagnostic-derive.rs:812:48 | LL | #[suggestion(no_crate_example, code = "", style("foo"))] - | ^ maybe a missing crate `core`? + | ^ you might be missing crate `core` error: cannot find attribute `foo` in this scope --> $DIR/subdiagnostic-derive.rs:67:3 diff --git a/tests/ui/attributes/field-attributes-vis-unresolved.stderr b/tests/ui/attributes/field-attributes-vis-unresolved.stderr index 43976254638..819cd859ae9 100644 --- a/tests/ui/attributes/field-attributes-vis-unresolved.stderr +++ b/tests/ui/attributes/field-attributes-vis-unresolved.stderr @@ -1,16 +1,16 @@ -error[E0433]: failed to resolve: maybe a missing crate `nonexistent`? +error[E0433]: failed to resolve: you might be missing crate `nonexistent` --> $DIR/field-attributes-vis-unresolved.rs:17:12 | LL | pub(in nonexistent) field: u8 - | ^^^^^^^^^^^ maybe a missing crate `nonexistent`? + | ^^^^^^^^^^^ you might be missing crate `nonexistent` | = help: consider adding `extern crate nonexistent` to use the `nonexistent` crate -error[E0433]: failed to resolve: maybe a missing crate `nonexistent`? +error[E0433]: failed to resolve: you might be missing crate `nonexistent` --> $DIR/field-attributes-vis-unresolved.rs:22:12 | LL | pub(in nonexistent) u8 - | ^^^^^^^^^^^ maybe a missing crate `nonexistent`? + | ^^^^^^^^^^^ you might be missing crate `nonexistent` | = help: consider adding `extern crate nonexistent` to use the `nonexistent` crate diff --git a/tests/ui/error-codes/E0432.stderr b/tests/ui/error-codes/E0432.stderr index 473e82f8634..a0b17e35c94 100644 --- a/tests/ui/error-codes/E0432.stderr +++ b/tests/ui/error-codes/E0432.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `something` --> $DIR/E0432.rs:1:5 | LL | use something::Foo; - | ^^^^^^^^^ maybe a missing crate `something`? + | ^^^^^^^^^ you might be missing crate `something` | = help: consider adding `extern crate something` to use the `something` crate diff --git a/tests/ui/feature-gates/feature-gate-extern_absolute_paths.stderr b/tests/ui/feature-gates/feature-gate-extern_absolute_paths.stderr index 2fcad98be9f..0234480ac5a 100644 --- a/tests/ui/feature-gates/feature-gate-extern_absolute_paths.stderr +++ b/tests/ui/feature-gates/feature-gate-extern_absolute_paths.stderr @@ -4,14 +4,14 @@ error[E0432]: unresolved import `core` LL | use core::default; | ^^^^ | | - | maybe a missing crate `core`? + | you might be missing crate `core` | help: try using `std` instead of `core`: `std` -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/feature-gate-extern_absolute_paths.rs:4:19 | LL | let _: u8 = ::core::default::Default(); - | ^^^^ maybe a missing crate `core`? + | ^^^^ you might be missing crate `core` | help: try using `std` instead of `core` | diff --git a/tests/ui/imports/import-from-missing-star-2.stderr b/tests/ui/imports/import-from-missing-star-2.stderr index ea3876248c9..59b000a4382 100644 --- a/tests/ui/imports/import-from-missing-star-2.stderr +++ b/tests/ui/imports/import-from-missing-star-2.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `spam` --> $DIR/import-from-missing-star-2.rs:2:9 | LL | use spam::*; - | ^^^^ maybe a missing crate `spam`? + | ^^^^ you might be missing crate `spam` | = help: consider adding `extern crate spam` to use the `spam` crate diff --git a/tests/ui/imports/import-from-missing-star-3.stderr b/tests/ui/imports/import-from-missing-star-3.stderr index 1fe5d4f19a9..23df6b35445 100644 --- a/tests/ui/imports/import-from-missing-star-3.stderr +++ b/tests/ui/imports/import-from-missing-star-3.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `spam` --> $DIR/import-from-missing-star-3.rs:2:9 | LL | use spam::*; - | ^^^^ maybe a missing crate `spam`? + | ^^^^ you might be missing crate `spam` | = help: consider adding `extern crate spam` to use the `spam` crate @@ -10,7 +10,7 @@ error[E0432]: unresolved import `spam` --> $DIR/import-from-missing-star-3.rs:27:13 | LL | use spam::*; - | ^^^^ maybe a missing crate `spam`? + | ^^^^ you might be missing crate `spam` | = help: consider adding `extern crate spam` to use the `spam` crate diff --git a/tests/ui/imports/import-from-missing-star.stderr b/tests/ui/imports/import-from-missing-star.stderr index f8e29507804..b311527bc28 100644 --- a/tests/ui/imports/import-from-missing-star.stderr +++ b/tests/ui/imports/import-from-missing-star.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `spam` --> $DIR/import-from-missing-star.rs:1:5 | LL | use spam::*; - | ^^^^ maybe a missing crate `spam`? + | ^^^^ you might be missing crate `spam` | = help: consider adding `extern crate spam` to use the `spam` crate diff --git a/tests/ui/imports/import3.stderr b/tests/ui/imports/import3.stderr index 80b0a7f0619..06260ef9ebc 100644 --- a/tests/ui/imports/import3.stderr +++ b/tests/ui/imports/import3.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `main` --> $DIR/import3.rs:2:5 | LL | use main::bar; - | ^^^^ maybe a missing crate `main`? + | ^^^^ you might be missing crate `main` | = help: consider adding `extern crate main` to use the `main` crate diff --git a/tests/ui/imports/issue-109343.stderr b/tests/ui/imports/issue-109343.stderr index 1b95fcf5567..fe06eddeada 100644 --- a/tests/ui/imports/issue-109343.stderr +++ b/tests/ui/imports/issue-109343.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `unresolved` --> $DIR/issue-109343.rs:4:9 | LL | pub use unresolved::f; - | ^^^^^^^^^^ maybe a missing crate `unresolved`? + | ^^^^^^^^^^ you might be missing crate `unresolved` | = help: consider adding `extern crate unresolved` to use the `unresolved` crate diff --git a/tests/ui/imports/issue-1697.rs b/tests/ui/imports/issue-1697.rs index 5cd76d21f91..8ec48d4d286 100644 --- a/tests/ui/imports/issue-1697.rs +++ b/tests/ui/imports/issue-1697.rs @@ -1,6 +1,8 @@ // Testing that we don't fail abnormally after hitting the errors -use unresolved::*; //~ ERROR unresolved import `unresolved` [E0432] - //~^ maybe a missing crate `unresolved`? +use unresolved::*; +//~^ ERROR unresolved import `unresolved` [E0432] +//~| NOTE you might be missing crate `unresolved` +//~| HELP consider adding `extern crate unresolved` to use the `unresolved` crate fn main() {} diff --git a/tests/ui/imports/issue-1697.stderr b/tests/ui/imports/issue-1697.stderr index 840608ca2a1..df2957b8f2b 100644 --- a/tests/ui/imports/issue-1697.stderr +++ b/tests/ui/imports/issue-1697.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `unresolved` --> $DIR/issue-1697.rs:3:5 | LL | use unresolved::*; - | ^^^^^^^^^^ maybe a missing crate `unresolved`? + | ^^^^^^^^^^ you might be missing crate `unresolved` | = help: consider adding `extern crate unresolved` to use the `unresolved` crate diff --git a/tests/ui/imports/issue-33464.stderr b/tests/ui/imports/issue-33464.stderr index c4e5c555899..17cc0e4469e 100644 --- a/tests/ui/imports/issue-33464.stderr +++ b/tests/ui/imports/issue-33464.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `abc` --> $DIR/issue-33464.rs:3:5 | LL | use abc::one_el; - | ^^^ maybe a missing crate `abc`? + | ^^^ you might be missing crate `abc` | = help: consider adding `extern crate abc` to use the `abc` crate @@ -10,7 +10,7 @@ error[E0432]: unresolved import `abc` --> $DIR/issue-33464.rs:5:5 | LL | use abc::{a, bbb, cccccc}; - | ^^^ maybe a missing crate `abc`? + | ^^^ you might be missing crate `abc` | = help: consider adding `extern crate abc` to use the `abc` crate @@ -18,7 +18,7 @@ error[E0432]: unresolved import `a_very_long_name` --> $DIR/issue-33464.rs:7:5 | LL | use a_very_long_name::{el, el2}; - | ^^^^^^^^^^^^^^^^ maybe a missing crate `a_very_long_name`? + | ^^^^^^^^^^^^^^^^ you might be missing crate `a_very_long_name` | = help: consider adding `extern crate a_very_long_name` to use the `a_very_long_name` crate diff --git a/tests/ui/imports/issue-36881.stderr b/tests/ui/imports/issue-36881.stderr index e9b632d2718..3c136df83fe 100644 --- a/tests/ui/imports/issue-36881.stderr +++ b/tests/ui/imports/issue-36881.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `issue_36881_aux` --> $DIR/issue-36881.rs:5:9 | LL | use issue_36881_aux::Foo; - | ^^^^^^^^^^^^^^^ maybe a missing crate `issue_36881_aux`? + | ^^^^^^^^^^^^^^^ you might be missing crate `issue_36881_aux` | = help: consider adding `extern crate issue_36881_aux` to use the `issue_36881_aux` crate diff --git a/tests/ui/imports/issue-37887.stderr b/tests/ui/imports/issue-37887.stderr index e7792ac0d15..36020707405 100644 --- a/tests/ui/imports/issue-37887.stderr +++ b/tests/ui/imports/issue-37887.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `test` --> $DIR/issue-37887.rs:3:9 | LL | use test::*; - | ^^^^ maybe a missing crate `test`? + | ^^^^ you might be missing crate `test` | = help: consider adding `extern crate test` to use the `test` crate diff --git a/tests/ui/imports/issue-53269.stderr b/tests/ui/imports/issue-53269.stderr index 29c7556dac4..317b3c633a6 100644 --- a/tests/ui/imports/issue-53269.stderr +++ b/tests/ui/imports/issue-53269.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `nonexistent_module` --> $DIR/issue-53269.rs:6:9 | LL | use nonexistent_module::mac; - | ^^^^^^^^^^^^^^^^^^ maybe a missing crate `nonexistent_module`? + | ^^^^^^^^^^^^^^^^^^ you might be missing crate `nonexistent_module` | = help: consider adding `extern crate nonexistent_module` to use the `nonexistent_module` crate diff --git a/tests/ui/imports/issue-55457.stderr b/tests/ui/imports/issue-55457.stderr index 09bb13a0604..e9126e6575c 100644 --- a/tests/ui/imports/issue-55457.stderr +++ b/tests/ui/imports/issue-55457.stderr @@ -11,7 +11,7 @@ error[E0432]: unresolved import `non_existent` --> $DIR/issue-55457.rs:2:5 | LL | use non_existent::non_existent; - | ^^^^^^^^^^^^ maybe a missing crate `non_existent`? + | ^^^^^^^^^^^^ you might be missing crate `non_existent` | = help: consider adding `extern crate non_existent` to use the `non_existent` crate diff --git a/tests/ui/imports/issue-81413.stderr b/tests/ui/imports/issue-81413.stderr index c2a32125011..321b3695d2c 100644 --- a/tests/ui/imports/issue-81413.stderr +++ b/tests/ui/imports/issue-81413.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `doesnt_exist` --> $DIR/issue-81413.rs:7:9 | LL | pub use doesnt_exist::*; - | ^^^^^^^^^^^^ maybe a missing crate `doesnt_exist`? + | ^^^^^^^^^^^^ you might be missing crate `doesnt_exist` | = help: consider adding `extern crate doesnt_exist` to use the `doesnt_exist` crate diff --git a/tests/ui/imports/tool-mod-child.rs b/tests/ui/imports/tool-mod-child.rs index 4581dc2e2ad..a8249ab01df 100644 --- a/tests/ui/imports/tool-mod-child.rs +++ b/tests/ui/imports/tool-mod-child.rs @@ -1,7 +1,7 @@ use clippy::a; //~ ERROR unresolved import `clippy` -use clippy::a::b; //~ ERROR failed to resolve: maybe a missing crate `clippy`? +use clippy::a::b; //~ ERROR failed to resolve: you might be missing crate `clippy` use rustdoc::a; //~ ERROR unresolved import `rustdoc` -use rustdoc::a::b; //~ ERROR failed to resolve: maybe a missing crate `rustdoc`? +use rustdoc::a::b; //~ ERROR failed to resolve: you might be missing crate `rustdoc` fn main() {} diff --git a/tests/ui/imports/tool-mod-child.stderr b/tests/ui/imports/tool-mod-child.stderr index 6caf15bc724..764256e76f0 100644 --- a/tests/ui/imports/tool-mod-child.stderr +++ b/tests/ui/imports/tool-mod-child.stderr @@ -1,8 +1,8 @@ -error[E0433]: failed to resolve: maybe a missing crate `clippy`? +error[E0433]: failed to resolve: you might be missing crate `clippy` --> $DIR/tool-mod-child.rs:2:5 | LL | use clippy::a::b; - | ^^^^^^ maybe a missing crate `clippy`? + | ^^^^^^ you might be missing crate `clippy` | = help: consider adding `extern crate clippy` to use the `clippy` crate @@ -10,15 +10,15 @@ error[E0432]: unresolved import `clippy` --> $DIR/tool-mod-child.rs:1:5 | LL | use clippy::a; - | ^^^^^^ maybe a missing crate `clippy`? + | ^^^^^^ you might be missing crate `clippy` | = help: consider adding `extern crate clippy` to use the `clippy` crate -error[E0433]: failed to resolve: maybe a missing crate `rustdoc`? +error[E0433]: failed to resolve: you might be missing crate `rustdoc` --> $DIR/tool-mod-child.rs:5:5 | LL | use rustdoc::a::b; - | ^^^^^^^ maybe a missing crate `rustdoc`? + | ^^^^^^^ you might be missing crate `rustdoc` | = help: consider adding `extern crate rustdoc` to use the `rustdoc` crate @@ -26,7 +26,7 @@ error[E0432]: unresolved import `rustdoc` --> $DIR/tool-mod-child.rs:4:5 | LL | use rustdoc::a; - | ^^^^^^^ maybe a missing crate `rustdoc`? + | ^^^^^^^ you might be missing crate `rustdoc` | = help: consider adding `extern crate rustdoc` to use the `rustdoc` crate diff --git a/tests/ui/imports/unresolved-imports-used.stderr b/tests/ui/imports/unresolved-imports-used.stderr index 73f9d1bfb6c..1cbc2356320 100644 --- a/tests/ui/imports/unresolved-imports-used.stderr +++ b/tests/ui/imports/unresolved-imports-used.stderr @@ -14,7 +14,7 @@ error[E0432]: unresolved import `foo` --> $DIR/unresolved-imports-used.rs:11:5 | LL | use foo::bar; - | ^^^ maybe a missing crate `foo`? + | ^^^ you might be missing crate `foo` | = help: consider adding `extern crate foo` to use the `foo` crate @@ -22,7 +22,7 @@ error[E0432]: unresolved import `baz` --> $DIR/unresolved-imports-used.rs:12:5 | LL | use baz::*; - | ^^^ maybe a missing crate `baz`? + | ^^^ you might be missing crate `baz` | = help: consider adding `extern crate baz` to use the `baz` crate @@ -30,7 +30,7 @@ error[E0432]: unresolved import `foo2` --> $DIR/unresolved-imports-used.rs:14:5 | LL | use foo2::bar2; - | ^^^^ maybe a missing crate `foo2`? + | ^^^^ you might be missing crate `foo2` | = help: consider adding `extern crate foo2` to use the `foo2` crate @@ -38,7 +38,7 @@ error[E0432]: unresolved import `baz2` --> $DIR/unresolved-imports-used.rs:15:5 | LL | use baz2::*; - | ^^^^ maybe a missing crate `baz2`? + | ^^^^ you might be missing crate `baz2` | = help: consider adding `extern crate baz2` to use the `baz2` crate diff --git a/tests/ui/keyword/extern/keyword-extern-as-identifier-use.stderr b/tests/ui/keyword/extern/keyword-extern-as-identifier-use.stderr index 54ee45c2867..a647ca27f1c 100644 --- a/tests/ui/keyword/extern/keyword-extern-as-identifier-use.stderr +++ b/tests/ui/keyword/extern/keyword-extern-as-identifier-use.stderr @@ -13,7 +13,7 @@ error[E0432]: unresolved import `r#extern` --> $DIR/keyword-extern-as-identifier-use.rs:1:5 | LL | use extern::foo; - | ^^^^^^ maybe a missing crate `r#extern`? + | ^^^^^^ you might be missing crate `r#extern` | = help: consider adding `extern crate r#extern` to use the `r#extern` crate diff --git a/tests/ui/macros/meta-item-absolute-path.stderr b/tests/ui/macros/meta-item-absolute-path.stderr index f0d763d7abb..af56d935284 100644 --- a/tests/ui/macros/meta-item-absolute-path.stderr +++ b/tests/ui/macros/meta-item-absolute-path.stderr @@ -1,14 +1,14 @@ -error[E0433]: failed to resolve: maybe a missing crate `Absolute`? +error[E0433]: failed to resolve: you might be missing crate `Absolute` --> $DIR/meta-item-absolute-path.rs:1:12 | LL | #[derive(::Absolute)] - | ^^^^^^^^ maybe a missing crate `Absolute`? + | ^^^^^^^^ you might be missing crate `Absolute` -error[E0433]: failed to resolve: maybe a missing crate `Absolute`? +error[E0433]: failed to resolve: you might be missing crate `Absolute` --> $DIR/meta-item-absolute-path.rs:1:12 | LL | #[derive(::Absolute)] - | ^^^^^^^^ maybe a missing crate `Absolute`? + | ^^^^^^^^ you might be missing crate `Absolute` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` diff --git a/tests/ui/privacy/restricted/test.rs b/tests/ui/privacy/restricted/test.rs index e1d87cfcd88..3fdfd191b36 100644 --- a/tests/ui/privacy/restricted/test.rs +++ b/tests/ui/privacy/restricted/test.rs @@ -47,6 +47,6 @@ fn main() { } mod pathological { - pub(in bad::path) mod m1 {} //~ ERROR failed to resolve: maybe a missing crate `bad`? + pub(in bad::path) mod m1 {} //~ ERROR failed to resolve: you might be missing crate `bad` pub(in foo) mod m2 {} //~ ERROR visibilities can only be restricted to ancestor modules } diff --git a/tests/ui/privacy/restricted/test.stderr b/tests/ui/privacy/restricted/test.stderr index 76f19525df5..a48bb671d9f 100644 --- a/tests/ui/privacy/restricted/test.stderr +++ b/tests/ui/privacy/restricted/test.stderr @@ -1,8 +1,8 @@ -error[E0433]: failed to resolve: maybe a missing crate `bad`? +error[E0433]: failed to resolve: you might be missing crate `bad` --> $DIR/test.rs:50:12 | LL | pub(in bad::path) mod m1 {} - | ^^^ maybe a missing crate `bad`? + | ^^^ you might be missing crate `bad` | = help: consider adding `extern crate bad` to use the `bad` crate diff --git a/tests/ui/resolve/editions-crate-root-2015.rs b/tests/ui/resolve/editions-crate-root-2015.rs index 5f764d3ceef..869f4c82c8b 100644 --- a/tests/ui/resolve/editions-crate-root-2015.rs +++ b/tests/ui/resolve/editions-crate-root-2015.rs @@ -2,10 +2,10 @@ mod inner { fn global_inner(_: ::nonexistant::Foo) { - //~^ ERROR failed to resolve: maybe a missing crate `nonexistant`? + //~^ ERROR failed to resolve: you might be missing crate `nonexistant` } fn crate_inner(_: crate::nonexistant::Foo) { - //~^ ERROR failed to resolve: maybe a missing crate `nonexistant`? + //~^ ERROR failed to resolve: you might be missing crate `nonexistant` } fn bare_global(_: ::nonexistant) { diff --git a/tests/ui/resolve/editions-crate-root-2015.stderr b/tests/ui/resolve/editions-crate-root-2015.stderr index 00cdd0c58f4..74fb7e6019f 100644 --- a/tests/ui/resolve/editions-crate-root-2015.stderr +++ b/tests/ui/resolve/editions-crate-root-2015.stderr @@ -1,16 +1,16 @@ -error[E0433]: failed to resolve: maybe a missing crate `nonexistant`? +error[E0433]: failed to resolve: you might be missing crate `nonexistant` --> $DIR/editions-crate-root-2015.rs:4:26 | LL | fn global_inner(_: ::nonexistant::Foo) { - | ^^^^^^^^^^^ maybe a missing crate `nonexistant`? + | ^^^^^^^^^^^ you might be missing crate `nonexistant` | = help: consider adding `extern crate nonexistant` to use the `nonexistant` crate -error[E0433]: failed to resolve: maybe a missing crate `nonexistant`? +error[E0433]: failed to resolve: you might be missing crate `nonexistant` --> $DIR/editions-crate-root-2015.rs:7:30 | LL | fn crate_inner(_: crate::nonexistant::Foo) { - | ^^^^^^^^^^^ maybe a missing crate `nonexistant`? + | ^^^^^^^^^^^ you might be missing crate `nonexistant` | = help: consider adding `extern crate nonexistant` to use the `nonexistant` crate diff --git a/tests/ui/resolve/extern-prelude-fail.stderr b/tests/ui/resolve/extern-prelude-fail.stderr index a1591914b4d..4c2d5abb782 100644 --- a/tests/ui/resolve/extern-prelude-fail.stderr +++ b/tests/ui/resolve/extern-prelude-fail.stderr @@ -2,15 +2,15 @@ error[E0432]: unresolved import `extern_prelude` --> $DIR/extern-prelude-fail.rs:7:9 | LL | use extern_prelude::S; - | ^^^^^^^^^^^^^^ maybe a missing crate `extern_prelude`? + | ^^^^^^^^^^^^^^ you might be missing crate `extern_prelude` | = help: consider adding `extern crate extern_prelude` to use the `extern_prelude` crate -error[E0433]: failed to resolve: maybe a missing crate `extern_prelude`? +error[E0433]: failed to resolve: you might be missing crate `extern_prelude` --> $DIR/extern-prelude-fail.rs:8:15 | LL | let s = ::extern_prelude::S; - | ^^^^^^^^^^^^^^ maybe a missing crate `extern_prelude`? + | ^^^^^^^^^^^^^^ you might be missing crate `extern_prelude` | = help: consider adding `extern crate extern_prelude` to use the `extern_prelude` crate diff --git a/tests/ui/resolve/issue-82865.rs b/tests/ui/resolve/issue-82865.rs index 07d88c413bf..29a898906e9 100644 --- a/tests/ui/resolve/issue-82865.rs +++ b/tests/ui/resolve/issue-82865.rs @@ -2,7 +2,7 @@ #![feature(decl_macro)] -use x::y::z; //~ ERROR: failed to resolve: maybe a missing crate `x`? +use x::y::z; //~ ERROR: failed to resolve: you might be missing crate `x` macro mac () { Box::z //~ ERROR: no function or associated item diff --git a/tests/ui/resolve/issue-82865.stderr b/tests/ui/resolve/issue-82865.stderr index 730fd6d6026..ce0061a2b66 100644 --- a/tests/ui/resolve/issue-82865.stderr +++ b/tests/ui/resolve/issue-82865.stderr @@ -1,8 +1,8 @@ -error[E0433]: failed to resolve: maybe a missing crate `x`? +error[E0433]: failed to resolve: you might be missing crate `x` --> $DIR/issue-82865.rs:5:5 | LL | use x::y::z; - | ^ maybe a missing crate `x`? + | ^ you might be missing crate `x` | = help: consider adding `extern crate x` to use the `x` crate diff --git a/tests/ui/resolve/resolve-bad-visibility.stderr b/tests/ui/resolve/resolve-bad-visibility.stderr index 2ac41b87562..8e475735403 100644 --- a/tests/ui/resolve/resolve-bad-visibility.stderr +++ b/tests/ui/resolve/resolve-bad-visibility.stderr @@ -16,19 +16,19 @@ error[E0742]: visibilities can only be restricted to ancestor modules LL | pub(in std::vec) struct F; | ^^^^^^^^ -error[E0433]: failed to resolve: maybe a missing crate `nonexistent`? +error[E0433]: failed to resolve: you might be missing crate `nonexistent` --> $DIR/resolve-bad-visibility.rs:7:8 | LL | pub(in nonexistent) struct G; - | ^^^^^^^^^^^ maybe a missing crate `nonexistent`? + | ^^^^^^^^^^^ you might be missing crate `nonexistent` | = help: consider adding `extern crate nonexistent` to use the `nonexistent` crate -error[E0433]: failed to resolve: maybe a missing crate `too_soon`? +error[E0433]: failed to resolve: you might be missing crate `too_soon` --> $DIR/resolve-bad-visibility.rs:8:8 | LL | pub(in too_soon) struct H; - | ^^^^^^^^ maybe a missing crate `too_soon`? + | ^^^^^^^^ you might be missing crate `too_soon` | = help: consider adding `extern crate too_soon` to use the `too_soon` crate diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-102156.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-102156.stderr index c331236a460..0c836a614f8 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-102156.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-102156.stderr @@ -1,19 +1,19 @@ -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/issue-102156.rs:4:5 | LL | use core::convert::{From, TryFrom}; | ^^^^ | | - | maybe a missing crate `core`? + | you might be missing crate `core` | help: try using `std` instead of `core`: `std` -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/issue-102156.rs:4:5 | LL | use core::convert::{From, TryFrom}; | ^^^^ | | - | maybe a missing crate `core`? + | you might be missing crate `core` | help: try using `std` instead of `core`: `std` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` diff --git a/tests/ui/simd/portable-intrinsics-arent-exposed.stderr b/tests/ui/simd/portable-intrinsics-arent-exposed.stderr index a6f27af428b..d38667f750d 100644 --- a/tests/ui/simd/portable-intrinsics-arent-exposed.stderr +++ b/tests/ui/simd/portable-intrinsics-arent-exposed.stderr @@ -1,10 +1,10 @@ -error[E0433]: failed to resolve: maybe a missing crate `core`? +error[E0433]: failed to resolve: you might be missing crate `core` --> $DIR/portable-intrinsics-arent-exposed.rs:4:5 | LL | use core::simd::intrinsics; | ^^^^ | | - | maybe a missing crate `core`? + | you might be missing crate `core` | help: try using `std` instead of `core`: `std` error[E0432]: unresolved import `std::simd::intrinsics` diff --git a/tests/ui/underscore-imports/issue-110164.stderr b/tests/ui/underscore-imports/issue-110164.stderr index 5016c41e8a5..240742996e1 100644 --- a/tests/ui/underscore-imports/issue-110164.stderr +++ b/tests/ui/underscore-imports/issue-110164.stderr @@ -38,7 +38,7 @@ error[E0432]: unresolved import `_` --> $DIR/issue-110164.rs:8:5 | LL | use _::*; - | ^ maybe a missing crate `_`? + | ^ you might be missing crate `_` | = help: consider adding `extern crate _` to use the `_` crate @@ -46,7 +46,7 @@ error[E0432]: unresolved import `_` --> $DIR/issue-110164.rs:5:5 | LL | use _::a; - | ^ maybe a missing crate `_`? + | ^ you might be missing crate `_` | = help: consider adding `extern crate _` to use the `_` crate @@ -54,7 +54,7 @@ error[E0432]: unresolved import `_` --> $DIR/issue-110164.rs:13:9 | LL | use _::a; - | ^ maybe a missing crate `_`? + | ^ you might be missing crate `_` | = help: consider adding `extern crate _` to use the `_` crate @@ -62,7 +62,7 @@ error[E0432]: unresolved import `_` --> $DIR/issue-110164.rs:16:9 | LL | use _::*; - | ^ maybe a missing crate `_`? + | ^ you might be missing crate `_` | = help: consider adding `extern crate _` to use the `_` crate diff --git a/tests/ui/unresolved/unresolved-asterisk-imports.stderr b/tests/ui/unresolved/unresolved-asterisk-imports.stderr index 24ac2f8e621..299ec699775 100644 --- a/tests/ui/unresolved/unresolved-asterisk-imports.stderr +++ b/tests/ui/unresolved/unresolved-asterisk-imports.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `not_existing_crate` --> $DIR/unresolved-asterisk-imports.rs:1:5 | LL | use not_existing_crate::*; - | ^^^^^^^^^^^^^^^^^^ maybe a missing crate `not_existing_crate`? + | ^^^^^^^^^^^^^^^^^^ you might be missing crate `not_existing_crate` | = help: consider adding `extern crate not_existing_crate` to use the `not_existing_crate` crate diff --git a/tests/ui/unresolved/unresolved-import.rs b/tests/ui/unresolved/unresolved-import.rs index 4125c593c74..e8f3b323e33 100644 --- a/tests/ui/unresolved/unresolved-import.rs +++ b/tests/ui/unresolved/unresolved-import.rs @@ -1,21 +1,25 @@ -use foo::bar; //~ ERROR unresolved import `foo` [E0432] - //~^ maybe a missing crate `foo`? - //~| HELP consider adding `extern crate foo` to use the `foo` crate +use foo::bar; +//~^ ERROR unresolved import `foo` [E0432] +//~| NOTE you might be missing crate `foo` +//~| HELP consider adding `extern crate foo` to use the `foo` crate -use bar::Baz as x; //~ ERROR unresolved import `bar::Baz` [E0432] - //~| no `Baz` in `bar` - //~| HELP a similar name exists in the module - //~| SUGGESTION Bar +use bar::Baz as x; +//~^ ERROR unresolved import `bar::Baz` [E0432] +//~| NOTE no `Baz` in `bar` +//~| HELP a similar name exists in the module +//~| SUGGESTION Bar -use food::baz; //~ ERROR unresolved import `food::baz` - //~| no `baz` in `food` - //~| HELP a similar name exists in the module - //~| SUGGESTION bag +use food::baz; +//~^ ERROR unresolved import `food::baz` +//~| NOTE no `baz` in `food` +//~| HELP a similar name exists in the module +//~| SUGGESTION bag -use food::{beens as Foo}; //~ ERROR unresolved import `food::beens` [E0432] - //~| no `beens` in `food` - //~| HELP a similar name exists in the module - //~| SUGGESTION beans +use food::{beens as Foo}; +//~^ ERROR unresolved import `food::beens` [E0432] +//~| NOTE no `beens` in `food` +//~| HELP a similar name exists in the module +//~| SUGGESTION beans mod bar { pub struct Bar; @@ -36,9 +40,10 @@ mod m { MyVariant } - use MyEnum::*; //~ ERROR unresolved import `MyEnum` [E0432] - //~| HELP a similar path exists - //~| SUGGESTION self::MyEnum + use MyEnum::*; + //~^ ERROR unresolved import `MyEnum` [E0432] + //~| HELP a similar path exists + //~| SUGGESTION self::MyEnum } mod items { @@ -46,9 +51,10 @@ mod items { Variant } - use Enum::*; //~ ERROR unresolved import `Enum` [E0432] - //~| HELP a similar path exists - //~| SUGGESTION self::Enum + use Enum::*; + //~^ ERROR unresolved import `Enum` [E0432] + //~| HELP a similar path exists + //~| SUGGESTION self::Enum fn item() {} } diff --git a/tests/ui/unresolved/unresolved-import.stderr b/tests/ui/unresolved/unresolved-import.stderr index 0dd928c8b6f..7b03717c827 100644 --- a/tests/ui/unresolved/unresolved-import.stderr +++ b/tests/ui/unresolved/unresolved-import.stderr @@ -2,12 +2,12 @@ error[E0432]: unresolved import `foo` --> $DIR/unresolved-import.rs:1:5 | LL | use foo::bar; - | ^^^ maybe a missing crate `foo`? + | ^^^ you might be missing crate `foo` | = help: consider adding `extern crate foo` to use the `foo` crate error[E0432]: unresolved import `bar::Baz` - --> $DIR/unresolved-import.rs:5:5 + --> $DIR/unresolved-import.rs:6:5 | LL | use bar::Baz as x; | ^^^^^---^^^^^ @@ -16,7 +16,7 @@ LL | use bar::Baz as x; | no `Baz` in `bar` error[E0432]: unresolved import `food::baz` - --> $DIR/unresolved-import.rs:10:5 + --> $DIR/unresolved-import.rs:12:5 | LL | use food::baz; | ^^^^^^--- @@ -25,7 +25,7 @@ LL | use food::baz; | no `baz` in `food` error[E0432]: unresolved import `food::beens` - --> $DIR/unresolved-import.rs:15:12 + --> $DIR/unresolved-import.rs:18:12 | LL | use food::{beens as Foo}; | -----^^^^^^^ @@ -34,13 +34,13 @@ LL | use food::{beens as Foo}; | help: a similar name exists in the module: `beans` error[E0432]: unresolved import `MyEnum` - --> $DIR/unresolved-import.rs:39:9 + --> $DIR/unresolved-import.rs:43:9 | LL | use MyEnum::*; | ^^^^^^ help: a similar path exists: `self::MyEnum` error[E0432]: unresolved import `Enum` - --> $DIR/unresolved-import.rs:49:9 + --> $DIR/unresolved-import.rs:54:9 | LL | use Enum::*; | ^^^^ help: a similar path exists: `self::Enum` From 9bd7680b2e0f1f5680b04fdb2401bad3e082fa38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 24 Jul 2024 21:06:24 +0000 Subject: [PATCH 13/15] Fix ddltool-failed test --- tests/ui/rfcs/rfc-2627-raw-dylib/dlltool-failed.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/rfcs/rfc-2627-raw-dylib/dlltool-failed.stderr b/tests/ui/rfcs/rfc-2627-raw-dylib/dlltool-failed.stderr index 0c5a06e68b8..90cca83d1c1 100644 --- a/tests/ui/rfcs/rfc-2627-raw-dylib/dlltool-failed.stderr +++ b/tests/ui/rfcs/rfc-2627-raw-dylib/dlltool-failed.stderr @@ -1,6 +1,6 @@ error: Dlltool could not create import library with $DLLTOOL -d $DEF_FILE -D foo.dll -l $LIB_FILE $TARGET_MACHINE $ASM_FLAGS --no-leading-underscore $TEMP_PREFIX: - $DLLTOOL: Syntax error in def file $DEF_FILE:1 + $DLLTOOL: Syntax error in def file $DEF_FILE:1␍ error: aborting due to 1 previous error From 0919d0714ec49773d3a4c3a589b7651655b1b7c0 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 24 Jul 2024 17:19:41 -0400 Subject: [PATCH 14/15] Don't ICE when auto trait has assoc ty in old solver --- .../src/traits/project.rs | 6 +++ tests/crashes/117829-2.rs | 14 ------- tests/crashes/117829.rs | 9 ----- tests/ui/auto-traits/assoc-ty.current.stderr | 40 +++++++++++++++++++ tests/ui/auto-traits/assoc-ty.next.stderr | 40 +++++++++++++++++++ tests/ui/auto-traits/assoc-ty.rs | 17 ++++++++ 6 files changed, 103 insertions(+), 23 deletions(-) delete mode 100644 tests/crashes/117829-2.rs delete mode 100644 tests/crashes/117829.rs create mode 100644 tests/ui/auto-traits/assoc-ty.current.stderr create mode 100644 tests/ui/auto-traits/assoc-ty.next.stderr create mode 100644 tests/ui/auto-traits/assoc-ty.rs diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 1d7a0515044..b96e0c8a977 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1202,6 +1202,12 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( false } } + } else if tcx.trait_is_auto(trait_ref.def_id) { + tcx.dcx().span_delayed_bug( + tcx.def_span(obligation.predicate.def_id), + "associated types not allowed on auto traits", + ); + false } else { bug!("unexpected builtin trait with associated type: {trait_ref:?}") } diff --git a/tests/crashes/117829-2.rs b/tests/crashes/117829-2.rs deleted file mode 100644 index ecfd3148569..00000000000 --- a/tests/crashes/117829-2.rs +++ /dev/null @@ -1,14 +0,0 @@ -//@ known-bug: #117829 -#![feature(auto_traits)] - -trait B {} - -auto trait Z -where - T: Z, - >::W: B, -{ - type W; -} - -fn main() {} diff --git a/tests/crashes/117829.rs b/tests/crashes/117829.rs deleted file mode 100644 index 7544b5ec0fc..00000000000 --- a/tests/crashes/117829.rs +++ /dev/null @@ -1,9 +0,0 @@ -//@ known-bug: #117829 -auto trait Z<'a, T: ?Sized> -where - T: Z<'a, u16>, - - for<'b> >::W: Clone, -{ - type W: ?Sized; -} diff --git a/tests/ui/auto-traits/assoc-ty.current.stderr b/tests/ui/auto-traits/assoc-ty.current.stderr new file mode 100644 index 00000000000..77a1c8fb654 --- /dev/null +++ b/tests/ui/auto-traits/assoc-ty.current.stderr @@ -0,0 +1,40 @@ +error[E0380]: auto traits cannot have associated items + --> $DIR/assoc-ty.rs:10:10 + | +LL | auto trait Trait { + | ----- auto traits cannot have associated items +LL | +LL | type Output; + | -----^^^^^^- help: remove these associated items + +error[E0658]: auto traits are experimental and possibly buggy + --> $DIR/assoc-ty.rs:8:1 + | +LL | / auto trait Trait { +LL | | +LL | | type Output; +LL | | +LL | | } + | |_^ + | + = note: see issue #13231 for more information + = help: add `#![feature(auto_traits)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0308]: mismatched types + --> $DIR/assoc-ty.rs:15:36 + | +LL | let _: <() as Trait>::Output = (); + | --------------------- ^^ expected associated type, found `()` + | | + | expected due to this + | + = note: expected associated type `<() as Trait>::Output` + found unit type `()` + = help: consider constraining the associated type `<() as Trait>::Output` to `()` or calling a method that returns `<() as Trait>::Output` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0308, E0380, E0658. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/auto-traits/assoc-ty.next.stderr b/tests/ui/auto-traits/assoc-ty.next.stderr new file mode 100644 index 00000000000..b9f56d6c99c --- /dev/null +++ b/tests/ui/auto-traits/assoc-ty.next.stderr @@ -0,0 +1,40 @@ +error[E0380]: auto traits cannot have associated items + --> $DIR/assoc-ty.rs:10:10 + | +LL | auto trait Trait { + | ----- auto traits cannot have associated items +LL | +LL | type Output; + | -----^^^^^^- help: remove these associated items + +error[E0658]: auto traits are experimental and possibly buggy + --> $DIR/assoc-ty.rs:8:1 + | +LL | / auto trait Trait { +LL | | +LL | | type Output; +LL | | +LL | | } + | |_^ + | + = note: see issue #13231 for more information + = help: add `#![feature(auto_traits)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0308]: mismatched types + --> $DIR/assoc-ty.rs:15:36 + | +LL | let _: <() as Trait>::Output = (); + | --------------------- ^^ types differ + | | + | expected due to this + | + = note: expected associated type `<() as Trait>::Output` + found unit type `()` + = help: consider constraining the associated type `<() as Trait>::Output` to `()` or calling a method that returns `<() as Trait>::Output` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0308, E0380, E0658. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/auto-traits/assoc-ty.rs b/tests/ui/auto-traits/assoc-ty.rs new file mode 100644 index 00000000000..ada75147f6e --- /dev/null +++ b/tests/ui/auto-traits/assoc-ty.rs @@ -0,0 +1,17 @@ +//@ revisions: current next +//@[next] compile-flags: -Znext-solver +//@ ignore-compare-mode-next-solver (explicit revisions) + +// Tests that projection doesn't explode if we accidentally +// put an associated type on an auto trait. + +auto trait Trait { + //~^ ERROR auto traits are experimental and possibly buggy + type Output; + //~^ ERROR auto traits cannot have associated items +} + +fn main() { + let _: <() as Trait>::Output = (); + //~^ ERROR mismatched types +} From 7da751a108a31b52650d055202e89a15f43ce0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Thu, 25 Jul 2024 02:47:53 +0200 Subject: [PATCH 15/15] Apply suggestions from code review --- compiler/rustc_parse/src/parser/ty.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index a2db4b6feef..b2a0742f211 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -927,8 +927,12 @@ impl<'a> Parser<'a> { /// If no modifiers are present, this does not consume any tokens. /// /// ```ebnf - /// TRAIT_BOUND_MODIFIERS = [["~"] "const"] ["async"] ["?" | "!"] + /// CONSTNESS = [["~"] "const"] + /// ASYNCNESS = ["async"] + /// POLARITY = ["?" | "!"] /// ``` + /// + /// See `parse_generic_ty_bound` for the complete grammar of trait bound modifiers. fn parse_trait_bound_modifiers(&mut self) -> PResult<'a, TraitBoundModifiers> { let modifier_lo = self.token.span; let constness = if self.eat(&token::Tilde) { @@ -1007,7 +1011,7 @@ impl<'a> Parser<'a> { /// Parses a type bound according to: /// ```ebnf /// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN) - /// TY_BOUND_NOPAREN = [for] [TRAIT_BOUND_MODIFIERS] SIMPLE_PATH + /// TY_BOUND_NOPAREN = [for CONSTNESS ASYNCNESS | POLARITY] SIMPLE_PATH /// ``` /// /// For example, this grammar accepts `for<'a: 'b> ~const ?m::Trait<'a>`.