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 9 pull requests #103312

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
00a7bfc
Elaborate supertrait bounds when triggering unused_must_use on impl T…
compiler-errors Sep 25, 2022
afe29e4
split steps for generating the standalone docs and the shared assets
pietroalbini Oct 5, 2022
004b8b9
add a "standalone" path for doc::Standalone to be able to exclude it
pietroalbini Oct 5, 2022
76bec17
kmc-solid: Handle errors returned by `SOLID_FS_ReadDir`
kawadakk Oct 13, 2022
7fbaf27
macros: support doc comments in diag derives
davidtwco Oct 14, 2022
1045e69
macros: allow subdiagnostic-kind-less variants
davidtwco Oct 14, 2022
feeeb11
macros: fully specify path to `Fn`
davidtwco Oct 14, 2022
2a4b587
ast_lowering: use derive more
davidtwco Oct 14, 2022
ea5d258
ast_passes: use derive more
davidtwco Oct 14, 2022
21d3bbd
lint: use derive more
davidtwco Oct 14, 2022
f8b628b
session: use derive more
davidtwco Oct 14, 2022
913f597
infer: use derive more
davidtwco Oct 14, 2022
f134370
apply joshua's suggestion
pietroalbini Oct 18, 2022
0b27164
fix `SelfVisitor::is_self_ty` ICE
TaKO8Ki Oct 19, 2022
2cc4a0a
rustdoc: render bounds of cross-crate GAT params
fmease Oct 18, 2022
a3ccb19
Fixed docs typo in `library/std/src/time.rs`
johnmatthiggins Oct 20, 2022
9a9e2fe
check if impl_self is `Some`
TaKO8Ki Oct 20, 2022
d3c37b1
+/- shortcut now only expand/collapse, not both
GuillaumeGomez Oct 20, 2022
8e3b891
Add GUI tests for collapse/expand actions
GuillaumeGomez Oct 20, 2022
ed1f02b
fix typo
cuishuang Oct 20, 2022
8fcf2f7
Rollup merge of #102287 - compiler-errors:unused-must-use-also-supert…
matthiaskrgr Oct 20, 2022
4689679
Rollup merge of #102706 - ferrocene:pa-ignore-doc-index, r=jyn514
matthiaskrgr Oct 20, 2022
da11d2f
Rollup merge of #103005 - solid-rs:patch/kmc-solid/readdir-terminator…
matthiaskrgr Oct 20, 2022
dd348af
Rollup merge of #103051 - davidtwco:translation-tidying-up, r=compile…
matthiaskrgr Oct 20, 2022
38c5239
Rollup merge of #103190 - fmease:rustdoc-render-bounds-of-cross-crate…
matthiaskrgr Oct 20, 2022
ec378e6
Rollup merge of #103221 - TaKO8Ki:fix-103202, r=oli-obk
matthiaskrgr Oct 20, 2022
761ab0d
Rollup merge of #103288 - johnmatthiggins:master, r=thomcc
matthiaskrgr Oct 20, 2022
a13a000
Rollup merge of #103296 - GuillaumeGomez:collapse-expand-shortcuts, r…
matthiaskrgr Oct 20, 2022
8f942bb
Rollup merge of #103297 - catandcoder:master, r=JohnTitor
matthiaskrgr Oct 20, 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
59 changes: 18 additions & 41 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use rustc_errors::{
fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay,
SubdiagnosticMessage,
};
use rustc_errors::DiagnosticArgFromDisplay;
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{symbol::Ident, Span, Symbol};

Expand All @@ -15,25 +12,15 @@ pub struct GenericTypeWithParentheses {
pub sub: Option<UseAngleBrackets>,
}

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Subdiagnostic)]
#[multipart_suggestion(ast_lowering::use_angle_brackets, applicability = "maybe-incorrect")]
pub struct UseAngleBrackets {
#[suggestion_part(code = "<")]
pub open_param: Span,
#[suggestion_part(code = ">")]
pub close_param: Span,
}

impl AddToDiagnostic for UseAngleBrackets {
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
diag.multipart_suggestion(
fluent::ast_lowering::use_angle_brackets,
vec![(self.open_param, String::from("<")), (self.close_param, String::from(">"))],
Applicability::MaybeIncorrect,
);
}
}

#[derive(Diagnostic)]
#[diag(ast_lowering::invalid_abi, code = "E0703")]
#[note]
Expand Down Expand Up @@ -68,30 +55,20 @@ pub struct AssocTyParentheses {
pub sub: AssocTyParenthesesSub,
}

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Subdiagnostic)]
pub enum AssocTyParenthesesSub {
Empty { parentheses_span: Span },
NotEmpty { open_param: Span, close_param: Span },
}

impl AddToDiagnostic for AssocTyParenthesesSub {
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
match self {
Self::Empty { parentheses_span } => diag.multipart_suggestion(
fluent::ast_lowering::remove_parentheses,
vec![(parentheses_span, String::new())],
Applicability::MaybeIncorrect,
),
Self::NotEmpty { open_param, close_param } => diag.multipart_suggestion(
fluent::ast_lowering::use_angle_brackets,
vec![(open_param, String::from("<")), (close_param, String::from(">"))],
Applicability::MaybeIncorrect,
),
};
}
#[multipart_suggestion(ast_lowering::remove_parentheses)]
Empty {
#[suggestion_part(code = "")]
parentheses_span: Span,
},
#[multipart_suggestion(ast_lowering::use_angle_brackets)]
NotEmpty {
#[suggestion_part(code = "<")]
open_param: Span,
#[suggestion_part(code = ">")]
close_param: Span,
},
}

#[derive(Diagnostic)]
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use rustc_ast::*;
use rustc_ast_pretty::pprust::{self, State};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{error_code, fluent, pluralize, struct_span_err, Applicability};
use rustc_macros::Subdiagnostic;
use rustc_parse::validate_attr;
use rustc_session::lint::builtin::{
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, PATTERNS_IN_FNS_WITHOUT_BODY,
Expand Down Expand Up @@ -1782,15 +1783,17 @@ pub fn check_crate(session: &Session, krate: &Crate, lints: &mut LintBuffer) ->
}

/// Used to forbid `let` expressions in certain syntactic locations.
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Subdiagnostic)]
pub(crate) enum ForbiddenLetReason {
/// `let` is not valid and the source environment is not important
GenericForbidden,
/// A let chain with the `||` operator
NotSupportedOr(Span),
#[note(ast_passes::not_supported_or)]
NotSupportedOr(#[primary_span] Span),
/// A let chain with invalid parentheses
///
/// For example, `let 1 = 1 && (expr && expr)` is allowed
/// but `(let 1 = 1 && (let 1 = 1 && (let 1 = 1))) && let a = 1` is not
NotSupportedParentheses(Span),
#[note(ast_passes::not_supported_parentheses)]
NotSupportedParentheses(#[primary_span] Span),
}
17 changes: 0 additions & 17 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,6 @@ pub struct ForbiddenLet {
pub(crate) reason: ForbiddenLetReason,
}

impl AddToDiagnostic for ForbiddenLetReason {
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
match self {
Self::GenericForbidden => {}
Self::NotSupportedOr(span) => {
diag.span_note(span, fluent::ast_passes::not_supported_or);
}
Self::NotSupportedParentheses(span) => {
diag.span_note(span, fluent::ast_passes::not_supported_parentheses);
}
}
}
}

#[derive(Diagnostic)]
#[diag(ast_passes::forbidden_let_stable)]
#[note]
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_error_messages/locales/en-US/infer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ infer_region_explanation = {$pref_kind ->
}

infer_mismatched_static_lifetime = incompatible lifetime on type
infer_msl_impl_note = ...does not necessarily outlive the static lifetime introduced by the compatible `impl`
infer_does_not_outlive_static_from_impl = ...does not necessarily outlive the static lifetime introduced by the compatible `impl`
infer_implicit_static_lifetime_note = this has an implicit `'static` lifetime requirement
infer_implicit_static_lifetime_suggestion = consider relaxing the implicit `'static` requirement
infer_msl_introduces_static = introduces a `'static` lifetime requirement
infer_msl_unmet_req = because this has an unmet lifetime requirement
infer_msl_trait_note = this has an implicit `'static` lifetime requirement
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/session.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ session_crate_name_empty = crate name must not be empty
session_invalid_character_in_create_name = invalid character `{$character}` in crate name: `{$crate_name}`

session_expr_parentheses_needed = parentheses are required to parse this as an expression

session_skipping_const_checks = skipping const checks
session_unleashed_feature_help_named = skipping check for `{$gate}` feature
session_unleashed_feature_help_unnamed = skipping check that does not even have a feature gate
21 changes: 18 additions & 3 deletions compiler/rustc_errors/src/diagnostic_impls.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::{
fluent, DiagnosticArgValue, DiagnosticBuilder, Handler, IntoDiagnostic, IntoDiagnosticArg,
};
use rustc_target::abi::TargetDataLayoutErrors;
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};

use rustc_ast as ast;
use rustc_ast_pretty::pprust;
use rustc_hir as hir;
use rustc_lint_defs::Level;
use rustc_span::edition::Edition;
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
use rustc_target::abi::TargetDataLayoutErrors;
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};
use std::borrow::Cow;
use std::fmt;
use std::num::ParseIntError;
Expand Down Expand Up @@ -155,6 +155,21 @@ impl IntoDiagnosticArg for ast::token::TokenKind {
}
}

impl IntoDiagnosticArg for Level {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
DiagnosticArgValue::Str(Cow::Borrowed(match self {
Level::Allow => "-A",
Level::Warn => "-W",
Level::ForceWarn(_) => "--force-warn",
Level::Deny => "-D",
Level::Forbid => "-F",
Level::Expect(_) => {
unreachable!("lints with the level of `expect` should not run this code");
}
}))
}
}

impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> {
let mut diag;
Expand Down
71 changes: 29 additions & 42 deletions compiler/rustc_infer/src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,47 +459,34 @@ impl AddToDiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
}
}

pub struct ImplNote {
pub impl_span: Option<Span>,
}

impl AddToDiagnostic for ImplNote {
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
match self.impl_span {
Some(span) => diag.span_note(span, fluent::infer::msl_impl_note),
None => diag.note(fluent::infer::msl_impl_note),
};
}
}

pub enum TraitSubdiag {
Note { span: Span },
Sugg { span: Span },
// FIXME(#100717): replace with a `Option<Span>` when subdiagnostic supports that
#[derive(Subdiagnostic)]
pub enum DoesNotOutliveStaticFromImpl {
#[note(infer::does_not_outlive_static_from_impl)]
Spanned {
#[primary_span]
span: Span,
},
#[note(infer::does_not_outlive_static_from_impl)]
Unspanned,
}

// FIXME(#100717) used in `Vec<TraitSubdiag>` so requires eager translation/list support
impl AddToDiagnostic for TraitSubdiag {
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
match self {
TraitSubdiag::Note { span } => {
diag.span_note(span, "this has an implicit `'static` lifetime requirement");
}
TraitSubdiag::Sugg { span } => {
diag.span_suggestion_verbose(
span,
"consider relaxing the implicit `'static` requirement",
" + '_".to_owned(),
rustc_errors::Applicability::MaybeIncorrect,
);
}
}
}
#[derive(Subdiagnostic)]
pub enum ImplicitStaticLifetimeSubdiag {
#[note(infer::implicit_static_lifetime_note)]
Note {
#[primary_span]
span: Span,
},
#[suggestion_verbose(
infer::implicit_static_lifetime_suggestion,
code = " + '_",
applicability = "maybe-incorrect"
)]
Sugg {
#[primary_span]
span: Span,
},
}

#[derive(Diagnostic)]
Expand All @@ -512,7 +499,7 @@ pub struct MismatchedStaticLifetime<'a> {
#[subdiagnostic]
pub expl: Option<note_and_explain::RegionExplanation<'a>>,
#[subdiagnostic]
pub impl_note: ImplNote,
#[subdiagnostic]
pub trait_subdiags: Vec<TraitSubdiag>,
pub does_not_outlive_static_from_impl: DoesNotOutliveStaticFromImpl,
#[subdiagnostic(eager)]
pub implicit_static_lifetimes: Vec<ImplicitStaticLifetimeSubdiag>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
//! to hold.

use crate::errors::{note_and_explain, IntroducesStaticBecauseUnmetLifetimeReq};
use crate::errors::{ImplNote, MismatchedStaticLifetime, TraitSubdiag};
use crate::errors::{
DoesNotOutliveStaticFromImpl, ImplicitStaticLifetimeSubdiag, MismatchedStaticLifetime,
};
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::infer::lexical_region_resolve::RegionResolutionError;
use crate::infer::{SubregionOrigin, TypeTrace};
Expand Down Expand Up @@ -56,7 +58,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
note_and_explain::SuffixKind::Continues,
);
let mut impl_span = None;
let mut trait_subdiags = Vec::new();
let mut implicit_static_lifetimes = Vec::new();
if let Some(impl_node) = self.tcx().hir().get_if_local(*impl_def_id) {
// If an impl is local, then maybe this isn't what they want. Try to
// be as helpful as possible with implicit lifetimes.
Expand Down Expand Up @@ -90,10 +92,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
// Otherwise, point at all implicit static lifetimes

for span in &traits {
trait_subdiags.push(TraitSubdiag::Note { span: *span });
implicit_static_lifetimes
.push(ImplicitStaticLifetimeSubdiag::Note { span: *span });
// It would be nice to put this immediately under the above note, but they get
// pushed to the end.
trait_subdiags.push(TraitSubdiag::Sugg { span: span.shrink_to_hi() });
implicit_static_lifetimes
.push(ImplicitStaticLifetimeSubdiag::Sugg { span: span.shrink_to_hi() });
}
}
} else {
Expand All @@ -105,8 +109,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
cause_span: cause.span,
unmet_lifetime_reqs: multispan_subdiag,
expl,
impl_note: ImplNote { impl_span },
trait_subdiags,
does_not_outlive_static_from_impl: impl_span
.map(|span| DoesNotOutliveStaticFromImpl::Spanned { span })
.unwrap_or(DoesNotOutliveStaticFromImpl::Unspanned),
implicit_static_lifetimes,
};
let reported = self.tcx().sess.emit_err(err);
Some(reported)
Expand Down
25 changes: 2 additions & 23 deletions compiler/rustc_lint/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,13 @@ pub struct BuiltinEllpisisInclusiveRangePatterns {
pub replace: String,
}

#[derive(Subdiagnostic)]
#[note(lint::requested_level)]
pub struct RequestedLevel {
pub level: Level,
pub lint_name: String,
}

impl AddToDiagnostic for RequestedLevel {
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
diag.note(fluent::lint::requested_level);
diag.set_arg(
"level",
match self.level {
Level::Allow => "-A",
Level::Warn => "-W",
Level::ForceWarn(_) => "--force-warn",
Level::Deny => "-D",
Level::Forbid => "-F",
Level::Expect(_) => {
unreachable!("lints with the level of `expect` should not run this code");
}
},
);
diag.set_arg("lint_name", self.lint_name);
}
}

#[derive(Diagnostic)]
#[diag(lint::unsupported_group, code = "E0602")]
pub struct UnsupportedGroup {
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_errors::{fluent, pluralize, Applicability, MultiSpan};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_infer::traits::util::elaborate_predicates_with_span;
use rustc_middle::ty::adjustment;
use rustc_middle::ty::{self, Ty};
use rustc_span::symbol::Symbol;
Expand Down Expand Up @@ -204,10 +205,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
ty::Adt(def, _) => check_must_use_def(cx, def.did(), span, descr_pre, descr_post),
ty::Opaque(def, _) => {
let mut has_emitted = false;
for &(predicate, _) in cx.tcx.explicit_item_bounds(def) {
for obligation in elaborate_predicates_with_span(
cx.tcx,
cx.tcx.explicit_item_bounds(def).iter().cloned(),
) {
// We only look at the `DefId`, so it is safe to skip the binder here.
if let ty::PredicateKind::Trait(ref poly_trait_predicate) =
predicate.kind().skip_binder()
obligation.predicate.kind().skip_binder()
{
let def_id = poly_trait_predicate.trait_ref.def_id;
let descr_pre =
Expand Down
Loading