Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #100701

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
848f301
avoid assertion failures in try_to_scalar_int
RalfJung Jul 30, 2022
a73afe3
Improving Fuchsia rustc support documentation
andrewpollack Aug 16, 2022
1886aef
point at a type parameter shadowing another type
TaKO8Ki Aug 16, 2022
5a848c7
avoid a `&str` to `String` conversion
TaKO8Ki Aug 16, 2022
7e15fba
Added first migration for repeated expressions without syntax vars
nidnogg Aug 16, 2022
be18a9b
Migrated more diagnostics under transcribe.rs
nidnogg Aug 16, 2022
72ce216
Previous commit under x.py fmt
nidnogg Aug 16, 2022
d3bf103
Fix documentation of rustc_parse::parser::Parser::parse_stmt_without_…
Xiretza Aug 17, 2022
db48436
tidy: check fluent files for style
Xiretza Aug 17, 2022
fd05fa0
fluent: fix slug name for borrowck::generic_does_not_live_long_enough
Xiretza Aug 17, 2022
98fb65e
Migrate lint reports in typeck::check_unused to LintDiagnostic
PragmaTwice Aug 17, 2022
52418d6
use `suggestion_short` in `LintDiagnostic`
PragmaTwice Aug 17, 2022
b704843
fix test file
PragmaTwice Aug 17, 2022
2c9baf7
update Miri
RalfJung Aug 17, 2022
9efe979
remove #[primary_span]
PragmaTwice Aug 17, 2022
c6f9a9c
Moved structs to rustc_expand::errors, added several more migrations,…
nidnogg Aug 17, 2022
caab20c
Moved structs to rustc_expand::errors, added several more migrations,…
nidnogg Aug 17, 2022
a468f13
Hotfix for duplicated slug name on VarStillRepeating struct
nidnogg Aug 17, 2022
8283b36
Rollup merge of #99966 - RalfJung:try-dont-panic, r=lcnr
matthiaskrgr Aug 17, 2022
a003ad6
Rollup merge of #100637 - andrewpollack:fuchsia-docs-adjustments, r=t…
matthiaskrgr Aug 17, 2022
33a451c
Rollup merge of #100643 - TaKO8Ki:point-at-type-parameter-shadowing-a…
matthiaskrgr Aug 17, 2022
ca0abf8
Rollup merge of #100651 - nidnogg:diagnostics_migration_expand_transc…
matthiaskrgr Aug 17, 2022
5e1ed57
Rollup merge of #100670 - Xiretza:parser-stmt-force-collect-docs, r=d…
matthiaskrgr Aug 17, 2022
14ae393
Rollup merge of #100671 - Xiretza:tidy-fluent-files, r=davidtwco
matthiaskrgr Aug 17, 2022
b654022
Rollup merge of #100674 - PragmaTwice:mig-typeck-unused-crate-diag, r…
matthiaskrgr Aug 17, 2022
e76d218
Rollup merge of #100682 - RalfJung:miri, r=RalfJung
matthiaskrgr Aug 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_error_messages/locales/en-US/borrowck.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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

borrowck_generic_does_not_live_long_enough =
`{$kind}` does not live long enough
17 changes: 17 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/expand.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,20 @@ 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

expand_must_repeat_once =
this must repeat at least once

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}
8 changes: 8 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/typeck.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
3 changes: 2 additions & 1 deletion compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,6 +87,7 @@ into_diagnostic_arg_using_display!(
hir::Target,
Edition,
Ident,
MacroRulesNormalizedIdent,
);

impl IntoDiagnosticArg for bool {
Expand Down
48 changes: 48 additions & 0 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use rustc_macros::SessionDiagnostic;
use rustc_span::symbol::MacroRulesNormalizedIdent;
use rustc_span::Span;

#[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::meta_var_dif_seq_matchers)]
pub(crate) struct MetaVarsDifSeqMatchers {
#[primary_span]
pub span: Span,
pub msg: String,
}
1 change: 1 addition & 0 deletions compiler/rustc_expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 10 additions & 24 deletions compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -165,19 +169,15 @@ 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) => {
// FIXME: this really ought to be caught at macro definition time... It
// 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, _) => {
Expand All @@ -193,10 +193,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`
Expand Down Expand Up @@ -239,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 {
Expand Down Expand Up @@ -448,10 +442,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),
Expand Down Expand Up @@ -499,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
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/mir/interpret/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'tcx> ConstValue<'tcx> {
}

pub fn try_to_scalar_int(&self) -> Option<ScalarInt> {
Some(self.try_to_scalar()?.assert_int())
self.try_to_scalar()?.try_to_int().ok()
}

pub fn try_to_bits(&self, size: Size) -> Option<u128> {
Expand Down Expand Up @@ -368,6 +368,7 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> {
}

#[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()
}
Expand All @@ -389,6 +390,7 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> {
}

#[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()
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)>,
}
Expand All @@ -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.
Expand Down Expand Up @@ -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,
}
Expand All @@ -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);
}
Expand Down
63 changes: 27 additions & 36 deletions compiler/rustc_typeck/src/check_unused.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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),
},
);
}
}

Expand Down
18 changes: 17 additions & 1 deletion compiler/rustc_typeck/src/errors.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -324,3 +324,19 @@ pub struct SubstsOnOverriddenImpl {
#[primary_span]
pub span: Span,
}

#[derive(LintDiagnostic)]
#[lint(typeck::unused_extern_crate)]
pub struct UnusedExternCrate {
#[suggestion(applicability = "machine-applicable", code = "")]
pub span: Span,
}

#[derive(LintDiagnostic)]
#[lint(typeck::extern_crate_not_idiomatic)]
pub struct ExternCrateNotIdiomatic {
#[suggestion_short(applicability = "machine-applicable", code = "{suggestion_code}")]
pub span: Span,
pub msg_code: String,
pub suggestion_code: String,
}
Loading