From 848f301782f1dc2e40241e503711fd6e11aefebe Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 30 Jul 2022 17:17:21 -0400 Subject: [PATCH 01/18] avoid assertion failures in try_to_scalar_int --- compiler/rustc_middle/src/mir/interpret/value.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/mir/interpret/value.rs b/compiler/rustc_middle/src/mir/interpret/value.rs index 834c114ee1c58..a1c111ae372a8 100644 --- a/compiler/rustc_middle/src/mir/interpret/value.rs +++ b/compiler/rustc_middle/src/mir/interpret/value.rs @@ -79,7 +79,7 @@ impl<'tcx> ConstValue<'tcx> { } pub fn try_to_scalar_int(&self) -> Option { - Some(self.try_to_scalar()?.assert_int()) + self.try_to_scalar()?.try_to_int().ok() } pub fn try_to_bits(&self, size: Size) -> Option { @@ -368,6 +368,7 @@ impl<'tcx, Prov: Provenance> Scalar { } #[inline(always)] + #[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980) pub fn assert_int(self) -> ScalarInt { self.try_to_int().unwrap() } @@ -389,6 +390,7 @@ impl<'tcx, Prov: Provenance> Scalar { } #[inline(always)] + #[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980) pub fn assert_bits(self, target_size: Size) -> u128 { self.to_bits(target_size).unwrap() } From a73afe3b7ec292366d116c4449377020c5066e6a Mon Sep 17 00:00:00 2001 From: Andrew Pollack Date: Tue, 16 Aug 2022 15:56:38 +0000 Subject: [PATCH 02/18] Improving Fuchsia rustc support documentation Improving wording --- src/doc/rustc/src/platform-support/fuchsia.md | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/doc/rustc/src/platform-support/fuchsia.md b/src/doc/rustc/src/platform-support/fuchsia.md index 61bd1b425bc35..f51ccfdafeeb4 100644 --- a/src/doc/rustc/src/platform-support/fuchsia.md +++ b/src/doc/rustc/src/platform-support/fuchsia.md @@ -127,7 +127,10 @@ following files inside: **`package/meta/package`** ```json -{"name":"hello_fuchsia","version":0} +{ + "name": "hello_fuchsia", + "version": "0" +} ``` The `package` file describes our package's name and version number. Every @@ -238,10 +241,17 @@ ${SDK_PATH}/tools/${ARCH}/ffx product-bundle get workstation_eng.qemu-${ARCH} ${SDK_PATH}/tools/${ARCH}/ffx emu start workstation_eng.qemu-${ARCH} --headless ``` -Then, once the emulator has been started: +Once the emulator is running, start a package repository server to serve our +package to the emulator: ```sh -${SDK_PATH}/tools/${ARCH}/ffx target repository register +${SDK_PATH}/tools/${ARCH}/ffx repository server start +``` + +Once the repository server is up and running, register our repository: + +```sh +${SDK_PATH}/tools/${ARCH}/ffx target repository register --repository hello-fuchsia ``` And watch the logs from the emulator in a separate terminal: @@ -259,6 +269,10 @@ ${SDK_PATH}/tools/${ARCH}/ffx component run fuchsia-pkg://hello-fuchsia/hello_fu On reruns of the component, the `--recreate` argument may also need to be passed. +```sh +${SDK_PATH}/tools/${ARCH}/ffx component run --recreate fuchsia-pkg://hello-fuchsia/hello_fuchsia#meta/hello_fuchsia.cm +``` + ## Testing ### Running unit tests From 1886aef0355cbb4666368a0b74609006b2221045 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 17 Aug 2022 04:53:06 +0900 Subject: [PATCH 03/18] point at a type parameter shadowing another type --- .../rustc_resolve/src/late/diagnostics.rs | 12 +++++++++++ .../generic_const_exprs/issue-69654.stderr | 4 +++- src/test/ui/lexical-scopes.stderr | 2 ++ ...t-type-parameter-shadowing-another-type.rs | 21 +++++++++++++++++++ ...pe-parameter-shadowing-another-type.stderr | 12 +++++++++++ src/test/ui/span/issue-35987.stderr | 4 +++- 6 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.rs create mode 100644 src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.stderr diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index cb133841bca5a..e1f2f8ae09797 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -161,6 +161,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { msg: String, fallback_label: String, span: Span, + span_label: Option<(Span, &'a str)>, could_be_expr: bool, suggestion: Option<(Span, &'a str, String)>, } @@ -172,6 +173,12 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { msg: format!("expected {}, found {} `{}`", expected, res.descr(), path_str), fallback_label: format!("not a {expected}"), span, + span_label: match res { + Res::Def(kind, def_id) if kind == DefKind::TyParam => { + self.def_span(def_id).map(|span| (span, "found this type pararmeter")) + } + _ => None, + }, could_be_expr: match res { Res::Def(DefKind::Fn, _) => { // Verify whether this is a fn call or an Fn used as a type. @@ -251,6 +258,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { format!("not found in {mod_str}") }, span: item_span, + span_label: None, could_be_expr: false, suggestion, } @@ -262,6 +270,10 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { self.suggest_swapping_misplaced_self_ty_and_trait(&mut err, source, res, base_error.span); + if let Some((span, label)) = base_error.span_label { + err.span_label(span, label); + } + if let Some(sugg) = base_error.suggestion { err.span_suggestion_verbose(sugg.0, sugg.1, sugg.2, Applicability::MaybeIncorrect); } diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-69654.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-69654.stderr index 7a083733a2cd1..5ad457d547a69 100644 --- a/src/test/ui/const-generics/generic_const_exprs/issue-69654.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/issue-69654.stderr @@ -2,7 +2,9 @@ error[E0423]: expected value, found type parameter `T` --> $DIR/issue-69654.rs:5:25 | LL | impl Bar for [u8; T] {} - | ^ not a value + | - ^ not a value + | | + | found this type pararmeter error[E0599]: the function or associated item `foo` exists for struct `Foo<_>`, but its trait bounds were not satisfied --> $DIR/issue-69654.rs:17:10 diff --git a/src/test/ui/lexical-scopes.stderr b/src/test/ui/lexical-scopes.stderr index 3b2a062c1c254..ad11f72a31d37 100644 --- a/src/test/ui/lexical-scopes.stderr +++ b/src/test/ui/lexical-scopes.stderr @@ -1,6 +1,8 @@ error[E0574]: expected struct, variant or union type, found type parameter `T` --> $DIR/lexical-scopes.rs:3:13 | +LL | fn f() { + | - found this type pararmeter LL | let t = T { i: 0 }; | ^ not a struct, variant or union type diff --git a/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.rs b/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.rs new file mode 100644 index 0000000000000..bd496875e80b9 --- /dev/null +++ b/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.rs @@ -0,0 +1,21 @@ +trait Foo { + fn foo(&self, name: T) -> usize; +} + +struct Bar { + baz: Baz, +} + +struct Baz { + num: usize, +} + +impl Foo for Bar { + fn foo(&self, _name: Baz) -> usize { + match self.baz { + Baz { num } => num, //~ ERROR expected struct, variant or union type, found type parameter `Baz` + } + } +} + +fn main() {} diff --git a/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.stderr b/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.stderr new file mode 100644 index 0000000000000..d9c404e94acb4 --- /dev/null +++ b/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.stderr @@ -0,0 +1,12 @@ +error[E0574]: expected struct, variant or union type, found type parameter `Baz` + --> $DIR/point-at-type-parameter-shadowing-another-type.rs:16:13 + | +LL | impl Foo for Bar { + | --- found this type pararmeter +... +LL | Baz { num } => num, + | ^^^ not a struct, variant or union type + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0574`. diff --git a/src/test/ui/span/issue-35987.stderr b/src/test/ui/span/issue-35987.stderr index 2bc3ff4c3b619..ea9c4c82c3610 100644 --- a/src/test/ui/span/issue-35987.stderr +++ b/src/test/ui/span/issue-35987.stderr @@ -2,7 +2,9 @@ error[E0404]: expected trait, found type parameter `Add` --> $DIR/issue-35987.rs:5:21 | LL | impl Add for Foo { - | ^^^ not a trait + | --- ^^^ not a trait + | | + | found this type pararmeter | help: consider importing this trait instead | From 5a848c701b98bf99b7dd480dc95bf1227b134e55 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 17 Aug 2022 04:58:26 +0900 Subject: [PATCH 04/18] avoid a `&str` to `String` conversion --- src/tools/rust-analyzer/bench_data/glorious_old_parser | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer/bench_data/glorious_old_parser b/src/tools/rust-analyzer/bench_data/glorious_old_parser index 7e900dfeb1eeb..764893daa12ad 100644 --- a/src/tools/rust-analyzer/bench_data/glorious_old_parser +++ b/src/tools/rust-analyzer/bench_data/glorious_old_parser @@ -1988,7 +1988,7 @@ impl<'a> Parser<'a> { err.span_suggestion( span, "declare the type after the parameter binding", - String::from(": "), + ": ", Applicability::HasPlaceholders, ); } else if require_name && is_trait_item { From 7e15fbab75ab919238ec86011fd54cba7ad78e68 Mon Sep 17 00:00:00 2001 From: nidnogg Date: Tue, 16 Aug 2022 18:34:13 -0300 Subject: [PATCH 05/18] Added first migration for repeated expressions without syntax vars --- .../rustc_error_messages/locales/en-US/expand.ftl | 3 +++ compiler/rustc_expand/src/mbe/transcribe.rs | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_error_messages/locales/en-US/expand.ftl b/compiler/rustc_error_messages/locales/en-US/expand.ftl index bdfa22e77eb2f..42519fd22ce63 100644 --- a/compiler/rustc_error_messages/locales/en-US/expand.ftl +++ b/compiler/rustc_error_messages/locales/en-US/expand.ftl @@ -3,3 +3,6 @@ expand_explain_doc_comment_outer = expand_explain_doc_comment_inner = inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match + +expand_expr_repeat_no_syntax_vars = + attempted to repeat an expression containing no syntax variables matched as repeating at this depth diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index e47ea83ac3809..69090cb457e75 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -9,6 +9,7 @@ use rustc_errors::{pluralize, PResult}; use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; use rustc_span::hygiene::{LocalExpnId, Transparency}; use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent}; +use rustc_macros::SessionDiagnostic; use rustc_span::Span; use smallvec::{smallvec, SmallVec}; @@ -53,6 +54,13 @@ impl<'a> Iterator for Frame<'a> { } } +#[derive(SessionDiagnostic)] +#[error(expand::expr_repeat_no_syntax_vars)] +struct NoSyntaxVarsExprRepeat { + #[primary_span] + span: Span, +} + /// This can do Macro-By-Example transcription. /// - `interp` is a map of meta-variables to the tokens (non-terminals) they matched in the /// invocation. We are assuming we already know there is a match. @@ -165,11 +173,7 @@ pub(super) fn transcribe<'a>( seq @ mbe::TokenTree::Sequence(_, delimited) => { match lockstep_iter_size(&seq, interp, &repeats) { LockstepIterSize::Unconstrained => { - return Err(cx.struct_span_err( - seq.span(), /* blame macro writer */ - "attempted to repeat an expression containing no syntax variables \ - matched as repeating at this depth", - )); + return Err(cx.create_err(NoSyntaxVarsExprRepeat { span: seq.span() })); } LockstepIterSize::Contradiction(msg) => { From be18a9bf75f6c92ee734838fd3eca9257556cf40 Mon Sep 17 00:00:00 2001 From: nidnogg Date: Tue, 16 Aug 2022 19:02:51 -0300 Subject: [PATCH 06/18] Migrated more diagnostics under transcribe.rs --- .../locales/en-US/expand.ftl | 6 +++++ compiler/rustc_expand/src/mbe/transcribe.rs | 26 ++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_error_messages/locales/en-US/expand.ftl b/compiler/rustc_error_messages/locales/en-US/expand.ftl index 42519fd22ce63..b25aaaa0e5175 100644 --- a/compiler/rustc_error_messages/locales/en-US/expand.ftl +++ b/compiler/rustc_error_messages/locales/en-US/expand.ftl @@ -6,3 +6,9 @@ expand_explain_doc_comment_inner = expand_expr_repeat_no_syntax_vars = attempted to repeat an expression containing no syntax variables matched as repeating at this depth + +expand_must_repeat_once = + this must repeat at least once + +count_repetition_misplaced = + `count` can not be placed inside the inner-most repetition \ No newline at end of file diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 69090cb457e75..4c8f7a59bbac2 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -7,9 +7,9 @@ use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{pluralize, PResult}; use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; +use rustc_macros::SessionDiagnostic; use rustc_span::hygiene::{LocalExpnId, Transparency}; use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent}; -use rustc_macros::SessionDiagnostic; use rustc_span::Span; use smallvec::{smallvec, SmallVec}; @@ -61,6 +61,13 @@ struct NoSyntaxVarsExprRepeat { span: Span, } +#[derive(SessionDiagnostic)] +#[error(expand::must_repeat_once)] +struct MustRepeatOnce { + #[primary_span] + span: Span, +} + /// This can do Macro-By-Example transcription. /// - `interp` is a map of meta-variables to the tokens (non-terminals) they matched in the /// invocation. We are assuming we already know there is a match. @@ -197,10 +204,7 @@ pub(super) fn transcribe<'a>( // FIXME: this really ought to be caught at macro definition // time... It happens when the Kleene operator in the matcher and // the body for the same meta-variable do not match. - return Err(cx.struct_span_err( - sp.entire(), - "this must repeat at least once", - )); + return Err(cx.create_err(MustRepeatOnce { span: sp.entire() })); } } else { // 0 is the initial counter (we have done 0 repetitions so far). `len` @@ -424,6 +428,13 @@ fn lockstep_iter_size( } } +#[derive(SessionDiagnostic)] +#[error(expand::count_repetition_misplaced)] +struct CountRepetitionMisplaced { + #[primary_span] + span: Span, +} + /// Used solely by the `count` meta-variable expression, counts the outer-most repetitions at a /// given optional nested depth. /// @@ -452,10 +463,7 @@ fn count_repetitions<'a>( match matched { MatchedTokenTree(_) | MatchedNonterminal(_) => { if declared_lhs_depth == 0 { - return Err(cx.struct_span_err( - sp.entire(), - "`count` can not be placed inside the inner-most repetition", - )); + return Err(cx.create_err( CountRepetitionMisplaced { span: sp.entire()} )); } match depth_opt { None => Ok(1), From 72ce216def236055f5bee03d06085d0ec9c270a9 Mon Sep 17 00:00:00 2001 From: nidnogg Date: Tue, 16 Aug 2022 19:19:59 -0300 Subject: [PATCH 07/18] Previous commit under x.py fmt --- compiler/rustc_expand/src/mbe/transcribe.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 4c8f7a59bbac2..af5489761920f 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -463,7 +463,7 @@ fn count_repetitions<'a>( match matched { MatchedTokenTree(_) | MatchedNonterminal(_) => { if declared_lhs_depth == 0 { - return Err(cx.create_err( CountRepetitionMisplaced { span: sp.entire()} )); + return Err(cx.create_err(CountRepetitionMisplaced { span: sp.entire() })); } match depth_opt { None => Ok(1), From d3bf103d1b3e8391a8d0a4ebecbfa1004e1297cb Mon Sep 17 00:00:00 2001 From: Xiretza Date: Wed, 17 Aug 2022 11:18:48 +0200 Subject: [PATCH 08/18] Fix documentation of rustc_parse::parser::Parser::parse_stmt_without_recovery Something seems to have gotten out of sync during the creation of #81177, where both the argument and comment were introduced. --- compiler/rustc_parse/src/parser/stmt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index ade0f4fbc86a2..cac39f8f25fb8 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -34,7 +34,7 @@ impl<'a> Parser<'a> { })) } - /// If `force_capture` is true, forces collection of tokens regardless of whether + /// If `force_collect` is [`ForceCollect::Yes`], forces collection of tokens regardless of whether /// or not we have attributes pub(crate) fn parse_stmt_without_recovery( &mut self, From db48436b277d5331b55c89385963851796bdeb55 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Wed, 17 Aug 2022 11:35:17 +0200 Subject: [PATCH 09/18] tidy: check fluent files for style --- .../locales/en-US/borrowck.ftl | 4 ++-- src/tools/tidy/src/style.rs | 15 ++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_error_messages/locales/en-US/borrowck.ftl b/compiler/rustc_error_messages/locales/en-US/borrowck.ftl index 4af40d2062d3a..93224f843fbae 100644 --- a/compiler/rustc_error_messages/locales/en-US/borrowck.ftl +++ b/compiler/rustc_error_messages/locales/en-US/borrowck.ftl @@ -13,6 +13,6 @@ borrowck_could_not_normalize = borrowck_higher_ranked_subtype_error = higher-ranked subtype error - + generic_does_not_live_long_enough = - `{$kind}` does not live long enough \ No newline at end of file + `{$kind}` does not live long enough diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index 3cf44a2d7d1ef..dee58ff2fb510 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -125,16 +125,13 @@ fn should_ignore(line: &str) -> bool { /// Returns `true` if `line` is allowed to be longer than the normal limit. fn long_line_is_ok(extension: &str, is_error_code: bool, max_columns: usize, line: &str) -> bool { - if extension != "md" || is_error_code { - if line_is_url(is_error_code, max_columns, line) || should_ignore(line) { - return true; - } - } else if extension == "md" { + match extension { + // fluent files are allowed to be any length + "ftl" => true, // non-error code markdown is allowed to be any length - return true; + "md" if !is_error_code => true, + _ => line_is_url(is_error_code, max_columns, line) || should_ignore(line), } - - false } enum Directive { @@ -230,7 +227,7 @@ pub fn check(path: &Path, bad: &mut bool) { super::walk(path, &mut skip, &mut |entry, contents| { let file = entry.path(); let filename = file.file_name().unwrap().to_string_lossy(); - let extensions = [".rs", ".py", ".js", ".sh", ".c", ".cpp", ".h", ".md", ".css"]; + let extensions = [".rs", ".py", ".js", ".sh", ".c", ".cpp", ".h", ".md", ".css", ".ftl"]; if extensions.iter().all(|e| !filename.ends_with(e)) || filename.starts_with(".#") { return; } From fd05fa0bf40c651501c8bac84f90625d3c67944c Mon Sep 17 00:00:00 2001 From: Xiretza Date: Wed, 17 Aug 2022 11:45:35 +0200 Subject: [PATCH 10/18] fluent: fix slug name for borrowck::generic_does_not_live_long_enough --- compiler/rustc_error_messages/locales/en-US/borrowck.ftl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_error_messages/locales/en-US/borrowck.ftl b/compiler/rustc_error_messages/locales/en-US/borrowck.ftl index 93224f843fbae..a96fe7c8a05d5 100644 --- a/compiler/rustc_error_messages/locales/en-US/borrowck.ftl +++ b/compiler/rustc_error_messages/locales/en-US/borrowck.ftl @@ -14,5 +14,5 @@ borrowck_could_not_normalize = borrowck_higher_ranked_subtype_error = higher-ranked subtype error -generic_does_not_live_long_enough = +borrowck_generic_does_not_live_long_enough = `{$kind}` does not live long enough From 98fb65eff9885f1dea6372f007962d9cbeb4a40c Mon Sep 17 00:00:00 2001 From: PragmaTwice Date: Wed, 17 Aug 2022 17:47:44 +0800 Subject: [PATCH 11/18] Migrate lint reports in typeck::check_unused to LintDiagnostic --- .../locales/en-US/typeck.ftl | 8 +++ compiler/rustc_typeck/src/check_unused.rs | 63 ++++++++----------- compiler/rustc_typeck/src/errors.rs | 20 +++++- 3 files changed, 54 insertions(+), 37 deletions(-) diff --git a/compiler/rustc_error_messages/locales/en-US/typeck.ftl b/compiler/rustc_error_messages/locales/en-US/typeck.ftl index 494b8f913934f..0014da17c88e5 100644 --- a/compiler/rustc_error_messages/locales/en-US/typeck.ftl +++ b/compiler/rustc_error_messages/locales/en-US/typeck.ftl @@ -123,3 +123,11 @@ typeck_manual_implementation = .help = add `#![feature(unboxed_closures)]` to the crate attributes to enable typeck_substs_on_overridden_impl = could not resolve substs on overridden impl + +typeck_unused_extern_crate = + unused extern crate + .suggestion = remove it + +typeck_extern_crate_not_idiomatic = + `extern crate` is not idiomatic in the new edition + .suggestion = convert it to a `{$msg_code}` diff --git a/compiler/rustc_typeck/src/check_unused.rs b/compiler/rustc_typeck/src/check_unused.rs index 4a3cfa1ca376a..1d23ed9292180 100644 --- a/compiler/rustc_typeck/src/check_unused.rs +++ b/compiler/rustc_typeck/src/check_unused.rs @@ -1,5 +1,5 @@ +use crate::errors::{ExternCrateNotIdiomatic, UnusedExternCrate}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -108,25 +108,16 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) { // We do this in any edition. if extern_crate.warn_if_unused { if let Some(&span) = unused_extern_crates.get(&def_id) { + // Removal suggestion span needs to include attributes (Issue #54400) let id = tcx.hir().local_def_id_to_hir_id(def_id); - tcx.struct_span_lint_hir(lint, id, span, |lint| { - // Removal suggestion span needs to include attributes (Issue #54400) - let span_with_attrs = tcx - .hir() - .attrs(id) - .iter() - .map(|attr| attr.span) - .fold(span, |acc, attr_span| acc.to(attr_span)); - - lint.build("unused extern crate") - .span_suggestion_short( - span_with_attrs, - "remove it", - "", - Applicability::MachineApplicable, - ) - .emit(); - }); + let span_with_attrs = tcx + .hir() + .attrs(id) + .iter() + .map(|attr| attr.span) + .fold(span, |acc, attr_span| acc.to(attr_span)); + + tcx.emit_spanned_lint(lint, id, span, UnusedExternCrate { span: span_with_attrs }); continue; } } @@ -158,23 +149,23 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) { if !tcx.hir().attrs(id).is_empty() { continue; } - tcx.struct_span_lint_hir(lint, id, extern_crate.span, |lint| { - // Otherwise, we can convert it into a `use` of some kind. - let base_replacement = match extern_crate.orig_name { - Some(orig_name) => format!("use {} as {};", orig_name, item.ident.name), - None => format!("use {};", item.ident.name), - }; - let vis = tcx.sess.source_map().span_to_snippet(item.vis_span).unwrap_or_default(); - let add_vis = |to| if vis.is_empty() { to } else { format!("{} {}", vis, to) }; - lint.build("`extern crate` is not idiomatic in the new edition") - .span_suggestion_short( - extern_crate.span, - &format!("convert it to a `{}`", add_vis("use".to_string())), - add_vis(base_replacement), - Applicability::MachineApplicable, - ) - .emit(); - }) + + let base_replacement = match extern_crate.orig_name { + Some(orig_name) => format!("use {} as {};", orig_name, item.ident.name), + None => format!("use {};", item.ident.name), + }; + let vis = tcx.sess.source_map().span_to_snippet(item.vis_span).unwrap_or_default(); + let add_vis = |to| if vis.is_empty() { to } else { format!("{} {}", vis, to) }; + tcx.emit_spanned_lint( + lint, + id, + extern_crate.span, + ExternCrateNotIdiomatic { + span: extern_crate.span, + msg_code: add_vis("use".to_string()), + suggestion_code: add_vis(base_replacement), + }, + ); } } diff --git a/compiler/rustc_typeck/src/errors.rs b/compiler/rustc_typeck/src/errors.rs index 0438ac02ea91a..7dfd2e9cb48be 100644 --- a/compiler/rustc_typeck/src/errors.rs +++ b/compiler/rustc_typeck/src/errors.rs @@ -1,6 +1,6 @@ //! Errors emitted by typeck. use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed}; -use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic}; use rustc_middle::ty::Ty; use rustc_session::{parse::ParseSess, SessionDiagnostic}; use rustc_span::{symbol::Ident, Span, Symbol}; @@ -324,3 +324,21 @@ pub struct SubstsOnOverriddenImpl { #[primary_span] pub span: Span, } + +#[derive(LintDiagnostic)] +#[lint(typeck::unused_extern_crate)] +pub struct UnusedExternCrate { + #[primary_span] + #[suggestion(applicability = "machine-applicable", code = "")] + pub span: Span, +} + +#[derive(LintDiagnostic)] +#[lint(typeck::extern_crate_not_idiomatic)] +pub struct ExternCrateNotIdiomatic { + #[primary_span] + #[suggestion(applicability = "machine-applicable", code = "{suggestion_code}")] + pub span: Span, + pub msg_code: String, + pub suggestion_code: String, +} From 52418d661bf7c66b8605c041a249203458036993 Mon Sep 17 00:00:00 2001 From: Twice Date: Wed, 17 Aug 2022 20:45:18 +0800 Subject: [PATCH 12/18] use `suggestion_short` in `LintDiagnostic` Co-authored-by: David Wood --- compiler/rustc_typeck/src/errors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/errors.rs b/compiler/rustc_typeck/src/errors.rs index 7dfd2e9cb48be..a33d88dfee0c7 100644 --- a/compiler/rustc_typeck/src/errors.rs +++ b/compiler/rustc_typeck/src/errors.rs @@ -337,7 +337,7 @@ pub struct UnusedExternCrate { #[lint(typeck::extern_crate_not_idiomatic)] pub struct ExternCrateNotIdiomatic { #[primary_span] - #[suggestion(applicability = "machine-applicable", code = "{suggestion_code}")] + #[suggestion_short(applicability = "machine-applicable", code = "{suggestion_code}")] pub span: Span, pub msg_code: String, pub suggestion_code: String, From b704843c4438387a66111b3464bb3987c45ce294 Mon Sep 17 00:00:00 2001 From: PragmaTwice Date: Wed, 17 Aug 2022 21:05:21 +0800 Subject: [PATCH 13/18] fix test file --- .../issue-54400-unused-extern-crate-attr-span.stderr | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/ui/rust-2018/issue-54400-unused-extern-crate-attr-span.stderr b/src/test/ui/rust-2018/issue-54400-unused-extern-crate-attr-span.stderr index 2ef97e7f20e9f..01bd924a415bb 100644 --- a/src/test/ui/rust-2018/issue-54400-unused-extern-crate-attr-span.stderr +++ b/src/test/ui/rust-2018/issue-54400-unused-extern-crate-attr-span.stderr @@ -1,11 +1,9 @@ error: unused extern crate - --> $DIR/issue-54400-unused-extern-crate-attr-span.rs:12:1 + --> $DIR/issue-54400-unused-extern-crate-attr-span.rs:11:1 | LL | / #[cfg(blandiloquence)] LL | | extern crate edition_lint_paths; - | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | |________________________________| - | help: remove it + | |________________________________^ help: remove it | note: the lint level is defined here --> $DIR/issue-54400-unused-extern-crate-attr-span.rs:6:9 From 2c9baf73f30442bcc255295b6a1eedddf8b0bdbe Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 17 Aug 2022 09:09:33 -0400 Subject: [PATCH 14/18] update Miri --- src/tools/miri | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri b/src/tools/miri index 50ef22af522f2..b8f617897a669 160000 --- a/src/tools/miri +++ b/src/tools/miri @@ -1 +1 @@ -Subproject commit 50ef22af522f2545295090cc1ad3e4bd4aa8632c +Subproject commit b8f617897a66953b9026c02f7a8f93a2e9611f63 From 9efe97951165a144c17ab08c8842f4f1cf23b4da Mon Sep 17 00:00:00 2001 From: PragmaTwice Date: Wed, 17 Aug 2022 22:08:06 +0800 Subject: [PATCH 15/18] remove #[primary_span] --- compiler/rustc_typeck/src/errors.rs | 2 -- .../issue-54400-unused-extern-crate-attr-span.stderr | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_typeck/src/errors.rs b/compiler/rustc_typeck/src/errors.rs index a33d88dfee0c7..76599721e586f 100644 --- a/compiler/rustc_typeck/src/errors.rs +++ b/compiler/rustc_typeck/src/errors.rs @@ -328,7 +328,6 @@ pub struct SubstsOnOverriddenImpl { #[derive(LintDiagnostic)] #[lint(typeck::unused_extern_crate)] pub struct UnusedExternCrate { - #[primary_span] #[suggestion(applicability = "machine-applicable", code = "")] pub span: Span, } @@ -336,7 +335,6 @@ pub struct UnusedExternCrate { #[derive(LintDiagnostic)] #[lint(typeck::extern_crate_not_idiomatic)] pub struct ExternCrateNotIdiomatic { - #[primary_span] #[suggestion_short(applicability = "machine-applicable", code = "{suggestion_code}")] pub span: Span, pub msg_code: String, diff --git a/src/test/ui/rust-2018/issue-54400-unused-extern-crate-attr-span.stderr b/src/test/ui/rust-2018/issue-54400-unused-extern-crate-attr-span.stderr index 01bd924a415bb..2ef97e7f20e9f 100644 --- a/src/test/ui/rust-2018/issue-54400-unused-extern-crate-attr-span.stderr +++ b/src/test/ui/rust-2018/issue-54400-unused-extern-crate-attr-span.stderr @@ -1,9 +1,11 @@ error: unused extern crate - --> $DIR/issue-54400-unused-extern-crate-attr-span.rs:11:1 + --> $DIR/issue-54400-unused-extern-crate-attr-span.rs:12:1 | LL | / #[cfg(blandiloquence)] LL | | extern crate edition_lint_paths; - | |________________________________^ help: remove it + | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- + | |________________________________| + | help: remove it | note: the lint level is defined here --> $DIR/issue-54400-unused-extern-crate-attr-span.rs:6:9 From c6f9a9c410e063f59bc2f6958674099b3fe5f184 Mon Sep 17 00:00:00 2001 From: nidnogg Date: Wed, 17 Aug 2022 11:18:19 -0300 Subject: [PATCH 16/18] Moved structs to rustc_expand::errors, added several more migrations, fixed slug name --- .../locales/en-US/expand.ftl | 12 ++++- compiler/rustc_errors/src/diagnostic.rs | 3 +- compiler/rustc_expand/src/errors.rs | 50 +++++++++++++++++++ compiler/rustc_expand/src/lib.rs | 1 + compiler/rustc_expand/src/mbe/transcribe.rs | 40 +++------------ 5 files changed, 70 insertions(+), 36 deletions(-) create mode 100644 compiler/rustc_expand/src/errors.rs diff --git a/compiler/rustc_error_messages/locales/en-US/expand.ftl b/compiler/rustc_error_messages/locales/en-US/expand.ftl index b25aaaa0e5175..ee76a4f45005d 100644 --- a/compiler/rustc_error_messages/locales/en-US/expand.ftl +++ b/compiler/rustc_error_messages/locales/en-US/expand.ftl @@ -10,5 +10,13 @@ expand_expr_repeat_no_syntax_vars = expand_must_repeat_once = this must repeat at least once -count_repetition_misplaced = - `count` can not be placed inside the inner-most repetition \ No newline at end of file +expand_count_repetition_misplaced = + `count` can not be placed inside the inner-most repetition + +expand_meta_var_expr_unrecognized_var = + variable `{$key}` is not recognized in meta-variable expression + +expand_var_still_repeating = + variable '{$ident}' is still repeating at this depth + +expand_meta_var_dif_seq_matchers = {$msg} \ No newline at end of file diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 17e6c9e9575fd..356f9dfdb3b2e 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -8,7 +8,7 @@ use rustc_error_messages::FluentValue; use rustc_hir as hir; use rustc_lint_defs::{Applicability, LintExpectationId}; use rustc_span::edition::LATEST_STABLE_EDITION; -use rustc_span::symbol::{Ident, Symbol}; +use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol}; use rustc_span::{edition::Edition, Span, DUMMY_SP}; use std::borrow::Cow; use std::fmt; @@ -87,6 +87,7 @@ into_diagnostic_arg_using_display!( hir::Target, Edition, Ident, + MacroRulesNormalizedIdent, ); impl IntoDiagnosticArg for bool { diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs new file mode 100644 index 0000000000000..f8b8750a78965 --- /dev/null +++ b/compiler/rustc_expand/src/errors.rs @@ -0,0 +1,50 @@ +use rustc_macros::SessionDiagnostic; +use rustc_span::Span; +use rustc_span::symbol::{MacroRulesNormalizedIdent}; + +#[derive(SessionDiagnostic)] +#[error(expand::expr_repeat_no_syntax_vars)] +pub(crate) struct NoSyntaxVarsExprRepeat { + #[primary_span] + pub span: Span, +} + +#[derive(SessionDiagnostic)] +#[error(expand::must_repeat_once)] +pub(crate) struct MustRepeatOnce { + #[primary_span] + pub span: Span, +} + +#[derive(SessionDiagnostic)] +#[error(expand::count_repetition_misplaced)] +pub(crate) struct CountRepetitionMisplaced { + #[primary_span] + pub span: Span, +} + +#[derive(SessionDiagnostic)] +#[error(expand::meta_var_expr_unrecognized_var)] +pub(crate) struct MetaVarExprUnrecognizedVar { + #[primary_span] + pub span: Span, + pub key: MacroRulesNormalizedIdent, +} + +#[derive(SessionDiagnostic)] +#[error(expand::var_still_repeating)] +pub(crate) struct VarStillRepeating { + #[primary_span] + pub span: Span, + pub ident: MacroRulesNormalizedIdent, +} + +#[derive(SessionDiagnostic)] +#[error(expand::var_still_repeating)] +pub(crate) struct MetaVarsDifSeqMatchers { + #[primary_span] + pub span: Span, + pub msg: String, +} + + diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index 91a183427843e..e1dde1672c190 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -25,6 +25,7 @@ pub mod base; pub mod build; #[macro_use] pub mod config; +pub mod errors; pub mod expand; pub mod module; pub mod proc_macro; diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index af5489761920f..bec6d1a2df7d8 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -1,4 +1,8 @@ use crate::base::ExtCtxt; +use crate::errors::{ + CountRepetitionMisplaced, MetaVarExprUnrecognizedVar, MetaVarsDifSeqMatchers, MustRepeatOnce, + NoSyntaxVarsExprRepeat, VarStillRepeating, +}; use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, MatchedTokenTree, NamedMatch}; use crate::mbe::{self, MetaVarExpr}; use rustc_ast::mut_visit::{self, MutVisitor}; @@ -7,7 +11,6 @@ use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{pluralize, PResult}; use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; -use rustc_macros::SessionDiagnostic; use rustc_span::hygiene::{LocalExpnId, Transparency}; use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent}; use rustc_span::Span; @@ -54,20 +57,6 @@ impl<'a> Iterator for Frame<'a> { } } -#[derive(SessionDiagnostic)] -#[error(expand::expr_repeat_no_syntax_vars)] -struct NoSyntaxVarsExprRepeat { - #[primary_span] - span: Span, -} - -#[derive(SessionDiagnostic)] -#[error(expand::must_repeat_once)] -struct MustRepeatOnce { - #[primary_span] - span: Span, -} - /// This can do Macro-By-Example transcription. /// - `interp` is a map of meta-variables to the tokens (non-terminals) they matched in the /// invocation. We are assuming we already know there is a match. @@ -188,7 +177,7 @@ pub(super) fn transcribe<'a>( // happens when two meta-variables are used in the same repetition in a // sequence, but they come from different sequence matchers and repeat // different amounts. - return Err(cx.struct_span_err(seq.span(), &msg)); + return Err(cx.create_err(MetaVarsDifSeqMatchers { span: seq.span(), msg })); } LockstepIterSize::Constraint(len, _) => { @@ -247,10 +236,7 @@ pub(super) fn transcribe<'a>( } MatchedSeq(..) => { // We were unable to descend far enough. This is an error. - return Err(cx.struct_span_err( - sp, /* blame the macro writer */ - &format!("variable '{}' is still repeating at this depth", ident), - )); + return Err(cx.create_err(VarStillRepeating { span: sp, ident })); } } } else { @@ -428,13 +414,6 @@ fn lockstep_iter_size( } } -#[derive(SessionDiagnostic)] -#[error(expand::count_repetition_misplaced)] -struct CountRepetitionMisplaced { - #[primary_span] - span: Span, -} - /// Used solely by the `count` meta-variable expression, counts the outer-most repetitions at a /// given optional nested depth. /// @@ -511,12 +490,7 @@ where { let span = ident.span; let key = MacroRulesNormalizedIdent::new(ident); - interp.get(&key).ok_or_else(|| { - cx.struct_span_err( - span, - &format!("variable `{}` is not recognized in meta-variable expression", key), - ) - }) + interp.get(&key).ok_or_else(|| cx.create_err(MetaVarExprUnrecognizedVar { span, key })) } /// Used by meta-variable expressions when an user input is out of the actual declared bounds. For From caab20c431a05dc3f01d3810ac13b6315f2d9b70 Mon Sep 17 00:00:00 2001 From: nidnogg Date: Wed, 17 Aug 2022 11:20:37 -0300 Subject: [PATCH 17/18] Moved structs to rustc_expand::errors, added several more migrations, fixed slug name --- compiler/rustc_expand/src/errors.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index f8b8750a78965..3f62120b1c81f 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -1,6 +1,6 @@ use rustc_macros::SessionDiagnostic; +use rustc_span::symbol::MacroRulesNormalizedIdent; use rustc_span::Span; -use rustc_span::symbol::{MacroRulesNormalizedIdent}; #[derive(SessionDiagnostic)] #[error(expand::expr_repeat_no_syntax_vars)] @@ -46,5 +46,3 @@ pub(crate) struct MetaVarsDifSeqMatchers { pub span: Span, pub msg: String, } - - From a468f131628341ff83bdabd1133f432c17fa1cbe Mon Sep 17 00:00:00 2001 From: nidnogg Date: Wed, 17 Aug 2022 13:13:07 -0300 Subject: [PATCH 18/18] Hotfix for duplicated slug name on VarStillRepeating struct --- compiler/rustc_expand/src/errors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index 3f62120b1c81f..0d7e137c7dd0c 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -40,7 +40,7 @@ pub(crate) struct VarStillRepeating { } #[derive(SessionDiagnostic)] -#[error(expand::var_still_repeating)] +#[error(expand::meta_var_dif_seq_matchers)] pub(crate) struct MetaVarsDifSeqMatchers { #[primary_span] pub span: Span,