Auto merge of #93368 - eddyb:diagbld-guarantee, r=estebank
rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission". That is, `DiagnosticBuilder` is now generic over the return type of `.emit()`, so we'll now have: * `DiagnosticBuilder<ErrorReported>` for error (incl. fatal/bug) diagnostics * can only be created via a `const L: Level`-generic constructor, that limits allowed variants via a `where` clause, so not even `rustc_errors` can accidentally bypass this limitation * asserts `diagnostic.is_error()` on emission, just in case the construction restriction was bypassed (e.g. by replacing the whole `Diagnostic` inside `DiagnosticBuilder`) * `.emit()` returns `ErrorReported`, as a "proof" token that `.emit()` was called (though note that this isn't a real guarantee until after completing the work on #69426) * `DiagnosticBuilder<()>` for everything else (warnings, notes, etc.) * can also be obtained from other `DiagnosticBuilder`s by calling `.forget_guarantee()` This PR is a companion to other ongoing work, namely: * #69426 and it's ongoing implementation: #93222 the API changes in this PR are needed to get statically-checked "only errors produce `ErrorReported` from `.emit()`", but doesn't itself provide any really strong guarantees without those other `ErrorReported` changes * #93244 would make the choices of API changes (esp. naming) in this PR fit better overall In order to be able to let `.emit()` return anything trustable, several changes had to be made: * `Diagnostic`'s `level` field is now private to `rustc_errors`, to disallow arbitrary "downgrade"s from "some kind of error" to "warning" (or anything else that doesn't cause compilation to fail) * it's still possible to replace the whole `Diagnostic` inside the `DiagnosticBuilder`, sadly, that's harder to fix, but it's unlikely enough that we can paper over it with asserts on `.emit()` * `.cancel()` now consumes `DiagnosticBuilder`, preventing `.emit()` calls on a cancelled diagnostic * it's also now done internally, through `DiagnosticBuilder`-private state, instead of having a `Level::Cancelled` variant that can be read (or worse, written) by the user * this removes a hazard of calling `.cancel()` on an error then continuing to attach details to it, and even expect to be able to `.emit()` it * warnings were switched to *only* `can_emit_warnings` on emission (instead of pre-cancelling early) * `struct_dummy` was removed (as it relied on a pre-`Cancelled` `Diagnostic`) * since `.emit()` doesn't consume the `DiagnosticBuilder` <sub>(I tried and gave up, it's much more work than this PR)</sub>, we have to make `.emit()` idempotent wrt the guarantees it returns * thankfully, `err.emit(); err.emit();` can return `ErrorReported` both times, as the second `.emit()` call has no side-effects *only* because the first one did do the appropriate emission * `&mut Diagnostic` is now used in a lot of function signatures, which used to take `&mut DiagnosticBuilder` (in the interest of not having to make those functions generic) * the APIs were already mostly identical, allowing for low-effort porting to this new setup * only some of the suggestion methods needed some rework, to have the extra `DiagnosticBuilder` functionality on the `Diagnostic` methods themselves (that change is also present in #93259) * `.emit()`/`.cancel()` aren't available, but IMO calling them from an "error decorator/annotator" function isn't a good practice, and can lead to strange behavior (from the caller's perspective) * `.downgrade_to_delayed_bug()` was added, letting you convert any `.is_error()` diagnostic into a `delay_span_bug` one (which works because in both cases the guarantees available are the same) This PR should ideally be reviewed commit-by-commit, since there is a lot of fallout in each. r? `@estebank` cc `@Manishearth` `@nikomatsakis` `@mark-i-m`
This commit is contained in:
commit
d4de1f230c
134 changed files with 1497 additions and 1143 deletions
|
@ -1,9 +1,13 @@
|
||||||
use rustc_errors::{struct_span_err, DiagnosticBuilder, DiagnosticId};
|
use rustc_errors::{struct_span_err, DiagnosticBuilder, DiagnosticId, ErrorReported};
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_span::{MultiSpan, Span};
|
use rustc_span::{MultiSpan, Span};
|
||||||
|
|
||||||
impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
crate fn cannot_move_when_borrowed(&self, span: Span, desc: &str) -> DiagnosticBuilder<'cx> {
|
crate fn cannot_move_when_borrowed(
|
||||||
|
&self,
|
||||||
|
span: Span,
|
||||||
|
desc: &str,
|
||||||
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
struct_span_err!(self, span, E0505, "cannot move out of {} because it is borrowed", desc,)
|
struct_span_err!(self, span, E0505, "cannot move out of {} because it is borrowed", desc,)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +17,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
desc: &str,
|
desc: &str,
|
||||||
borrow_span: Span,
|
borrow_span: Span,
|
||||||
borrow_desc: &str,
|
borrow_desc: &str,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self,
|
self,
|
||||||
span,
|
span,
|
||||||
|
@ -32,7 +36,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
verb: &str,
|
verb: &str,
|
||||||
desc: &str,
|
desc: &str,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
self,
|
self,
|
||||||
span,
|
span,
|
||||||
|
@ -51,7 +55,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
old_loan_span: Span,
|
old_loan_span: Span,
|
||||||
old_opt_via: &str,
|
old_opt_via: &str,
|
||||||
old_load_end_span: Option<Span>,
|
old_load_end_span: Option<Span>,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let via =
|
let via =
|
||||||
|msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {})", msg) };
|
|msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {})", msg) };
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
|
@ -99,7 +103,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
desc: &str,
|
desc: &str,
|
||||||
old_loan_span: Span,
|
old_loan_span: Span,
|
||||||
old_load_end_span: Option<Span>,
|
old_load_end_span: Option<Span>,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self,
|
self,
|
||||||
new_loan_span,
|
new_loan_span,
|
||||||
|
@ -132,7 +136,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
noun_old: &str,
|
noun_old: &str,
|
||||||
old_opt_via: &str,
|
old_opt_via: &str,
|
||||||
previous_end_span: Option<Span>,
|
previous_end_span: Option<Span>,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self,
|
self,
|
||||||
new_loan_span,
|
new_loan_span,
|
||||||
|
@ -164,7 +168,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
old_opt_via: &str,
|
old_opt_via: &str,
|
||||||
previous_end_span: Option<Span>,
|
previous_end_span: Option<Span>,
|
||||||
second_borrow_desc: &str,
|
second_borrow_desc: &str,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self,
|
self,
|
||||||
new_loan_span,
|
new_loan_span,
|
||||||
|
@ -200,7 +204,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
kind_old: &str,
|
kind_old: &str,
|
||||||
msg_old: &str,
|
msg_old: &str,
|
||||||
old_load_end_span: Option<Span>,
|
old_load_end_span: Option<Span>,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let via =
|
let via =
|
||||||
|msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {})", msg) };
|
|msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {})", msg) };
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
|
@ -243,7 +247,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
borrow_span: Span,
|
borrow_span: Span,
|
||||||
desc: &str,
|
desc: &str,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self,
|
self,
|
||||||
span,
|
span,
|
||||||
|
@ -262,12 +266,12 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
desc: &str,
|
desc: &str,
|
||||||
is_arg: bool,
|
is_arg: bool,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let msg = if is_arg { "to immutable argument" } else { "twice to immutable variable" };
|
let msg = if is_arg { "to immutable argument" } else { "twice to immutable variable" };
|
||||||
struct_span_err!(self, span, E0384, "cannot assign {} {}", msg, desc)
|
struct_span_err!(self, span, E0384, "cannot assign {} {}", msg, desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn cannot_assign(&self, span: Span, desc: &str) -> DiagnosticBuilder<'cx> {
|
crate fn cannot_assign(&self, span: Span, desc: &str) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
struct_span_err!(self, span, E0594, "cannot assign to {}", desc)
|
struct_span_err!(self, span, E0594, "cannot assign to {}", desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +279,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
move_from_span: Span,
|
move_from_span: Span,
|
||||||
move_from_desc: &str,
|
move_from_desc: &str,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
struct_span_err!(self, move_from_span, E0507, "cannot move out of {}", move_from_desc,)
|
struct_span_err!(self, move_from_span, E0507, "cannot move out of {}", move_from_desc,)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +291,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
move_from_span: Span,
|
move_from_span: Span,
|
||||||
ty: Ty<'_>,
|
ty: Ty<'_>,
|
||||||
is_index: Option<bool>,
|
is_index: Option<bool>,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let type_name = match (&ty.kind(), is_index) {
|
let type_name = match (&ty.kind(), is_index) {
|
||||||
(&ty::Array(_, _), Some(true)) | (&ty::Array(_, _), None) => "array",
|
(&ty::Array(_, _), Some(true)) | (&ty::Array(_, _), None) => "array",
|
||||||
(&ty::Slice(_), _) => "slice",
|
(&ty::Slice(_), _) => "slice",
|
||||||
|
@ -309,7 +313,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
move_from_span: Span,
|
move_from_span: Span,
|
||||||
container_ty: Ty<'_>,
|
container_ty: Ty<'_>,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self,
|
self,
|
||||||
move_from_span,
|
move_from_span,
|
||||||
|
@ -327,7 +331,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
verb: &str,
|
verb: &str,
|
||||||
optional_adverb_for_moved: &str,
|
optional_adverb_for_moved: &str,
|
||||||
moved_path: Option<String>,
|
moved_path: Option<String>,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let moved_path = moved_path.map(|mp| format!(": `{}`", mp)).unwrap_or_default();
|
let moved_path = moved_path.map(|mp| format!(": `{}`", mp)).unwrap_or_default();
|
||||||
|
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
|
@ -346,7 +350,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
path: &str,
|
path: &str,
|
||||||
reason: &str,
|
reason: &str,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
struct_span_err!(self, span, E0596, "cannot borrow {} as mutable{}", path, reason,)
|
struct_span_err!(self, span, E0596, "cannot borrow {} as mutable{}", path, reason,)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,7 +361,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
immutable_place: &str,
|
immutable_place: &str,
|
||||||
immutable_section: &str,
|
immutable_section: &str,
|
||||||
action: &str,
|
action: &str,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self,
|
self,
|
||||||
mutate_span,
|
mutate_span,
|
||||||
|
@ -376,7 +380,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
yield_span: Span,
|
yield_span: Span,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self,
|
self,
|
||||||
span,
|
span,
|
||||||
|
@ -387,7 +391,10 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn cannot_borrow_across_destructor(&self, borrow_span: Span) -> DiagnosticBuilder<'cx> {
|
crate fn cannot_borrow_across_destructor(
|
||||||
|
&self,
|
||||||
|
borrow_span: Span,
|
||||||
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
self,
|
self,
|
||||||
borrow_span,
|
borrow_span,
|
||||||
|
@ -400,7 +407,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
path: &str,
|
path: &str,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
struct_span_err!(self, span, E0597, "{} does not live long enough", path,)
|
struct_span_err!(self, span, E0597, "{} does not live long enough", path,)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +417,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
return_kind: &str,
|
return_kind: &str,
|
||||||
reference_desc: &str,
|
reference_desc: &str,
|
||||||
path_desc: &str,
|
path_desc: &str,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self,
|
self,
|
||||||
span,
|
span,
|
||||||
|
@ -435,7 +442,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
closure_kind: &str,
|
closure_kind: &str,
|
||||||
borrowed_path: &str,
|
borrowed_path: &str,
|
||||||
capture_span: Span,
|
capture_span: Span,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self,
|
self,
|
||||||
closure_span,
|
closure_span,
|
||||||
|
@ -454,11 +461,14 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
crate fn thread_local_value_does_not_live_long_enough(
|
crate fn thread_local_value_does_not_live_long_enough(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
struct_span_err!(self, span, E0712, "thread-local variable borrowed past end of function",)
|
struct_span_err!(self, span, E0712, "thread-local variable borrowed past end of function",)
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn temporary_value_borrowed_for_too_long(&self, span: Span) -> DiagnosticBuilder<'cx> {
|
crate fn temporary_value_borrowed_for_too_long(
|
||||||
|
&self,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
struct_span_err!(self, span, E0716, "temporary value dropped while borrowed",)
|
struct_span_err!(self, span, E0716, "temporary value dropped while borrowed",)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,7 +477,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
sp: S,
|
sp: S,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
code: DiagnosticId,
|
code: DiagnosticId,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
self.infcx.tcx.sess.struct_span_err_with_code(sp, msg, code)
|
self.infcx.tcx.sess.struct_span_err_with_code(sp, msg, code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -476,7 +486,7 @@ crate fn borrowed_data_escapes_closure<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
escape_span: Span,
|
escape_span: Span,
|
||||||
escapes_from: &str,
|
escapes_from: &str,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
tcx.sess,
|
tcx.sess,
|
||||||
escape_span,
|
escape_span,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::{DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_infer::infer::canonical::Canonical;
|
use rustc_infer::infer::canonical::Canonical;
|
||||||
use rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError;
|
use rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError;
|
||||||
use rustc_infer::infer::region_constraints::Constraint;
|
use rustc_infer::infer::region_constraints::Constraint;
|
||||||
|
@ -120,7 +120,11 @@ impl<'tcx, F, G> ToUniverseInfo<'tcx> for Canonical<'tcx, type_op::custom::Custo
|
||||||
trait TypeOpInfo<'tcx> {
|
trait TypeOpInfo<'tcx> {
|
||||||
/// Returns an error to be reported if rerunning the type op fails to
|
/// Returns an error to be reported if rerunning the type op fails to
|
||||||
/// recover the error's cause.
|
/// recover the error's cause.
|
||||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx>;
|
fn fallback_error(
|
||||||
|
&self,
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported>;
|
||||||
|
|
||||||
fn base_universe(&self) -> ty::UniverseIndex;
|
fn base_universe(&self) -> ty::UniverseIndex;
|
||||||
|
|
||||||
|
@ -130,7 +134,7 @@ trait TypeOpInfo<'tcx> {
|
||||||
cause: ObligationCause<'tcx>,
|
cause: ObligationCause<'tcx>,
|
||||||
placeholder_region: ty::Region<'tcx>,
|
placeholder_region: ty::Region<'tcx>,
|
||||||
error_region: Option<ty::Region<'tcx>>,
|
error_region: Option<ty::Region<'tcx>>,
|
||||||
) -> Option<DiagnosticBuilder<'tcx>>;
|
) -> Option<DiagnosticBuilder<'tcx, ErrorReported>>;
|
||||||
|
|
||||||
fn report_error(
|
fn report_error(
|
||||||
&self,
|
&self,
|
||||||
|
@ -188,7 +192,11 @@ struct PredicateQuery<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
|
impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
|
||||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn fallback_error(
|
||||||
|
&self,
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let mut err = tcx.sess.struct_span_err(span, "higher-ranked lifetime error");
|
let mut err = tcx.sess.struct_span_err(span, "higher-ranked lifetime error");
|
||||||
err.note(&format!("could not prove {}", self.canonical_query.value.value.predicate));
|
err.note(&format!("could not prove {}", self.canonical_query.value.value.predicate));
|
||||||
err
|
err
|
||||||
|
@ -204,7 +212,7 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
|
||||||
cause: ObligationCause<'tcx>,
|
cause: ObligationCause<'tcx>,
|
||||||
placeholder_region: ty::Region<'tcx>,
|
placeholder_region: ty::Region<'tcx>,
|
||||||
error_region: Option<ty::Region<'tcx>>,
|
error_region: Option<ty::Region<'tcx>>,
|
||||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
|
||||||
tcx.infer_ctxt().enter_with_canonical(
|
tcx.infer_ctxt().enter_with_canonical(
|
||||||
cause.span,
|
cause.span,
|
||||||
&self.canonical_query,
|
&self.canonical_query,
|
||||||
|
@ -231,7 +239,11 @@ impl<'tcx, T> TypeOpInfo<'tcx> for NormalizeQuery<'tcx, T>
|
||||||
where
|
where
|
||||||
T: Copy + fmt::Display + TypeFoldable<'tcx> + 'tcx,
|
T: Copy + fmt::Display + TypeFoldable<'tcx> + 'tcx,
|
||||||
{
|
{
|
||||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn fallback_error(
|
||||||
|
&self,
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let mut err = tcx.sess.struct_span_err(span, "higher-ranked lifetime error");
|
let mut err = tcx.sess.struct_span_err(span, "higher-ranked lifetime error");
|
||||||
err.note(&format!("could not normalize `{}`", self.canonical_query.value.value.value));
|
err.note(&format!("could not normalize `{}`", self.canonical_query.value.value.value));
|
||||||
err
|
err
|
||||||
|
@ -247,7 +259,7 @@ where
|
||||||
cause: ObligationCause<'tcx>,
|
cause: ObligationCause<'tcx>,
|
||||||
placeholder_region: ty::Region<'tcx>,
|
placeholder_region: ty::Region<'tcx>,
|
||||||
error_region: Option<ty::Region<'tcx>>,
|
error_region: Option<ty::Region<'tcx>>,
|
||||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
|
||||||
tcx.infer_ctxt().enter_with_canonical(
|
tcx.infer_ctxt().enter_with_canonical(
|
||||||
cause.span,
|
cause.span,
|
||||||
&self.canonical_query,
|
&self.canonical_query,
|
||||||
|
@ -288,7 +300,11 @@ struct AscribeUserTypeQuery<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
|
impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
|
||||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn fallback_error(
|
||||||
|
&self,
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
// FIXME: This error message isn't great, but it doesn't show up in the existing UI tests,
|
// FIXME: This error message isn't great, but it doesn't show up in the existing UI tests,
|
||||||
// and is only the fallback when the nice error fails. Consider improving this some more.
|
// and is only the fallback when the nice error fails. Consider improving this some more.
|
||||||
tcx.sess.struct_span_err(span, "higher-ranked lifetime error")
|
tcx.sess.struct_span_err(span, "higher-ranked lifetime error")
|
||||||
|
@ -304,7 +320,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
|
||||||
cause: ObligationCause<'tcx>,
|
cause: ObligationCause<'tcx>,
|
||||||
placeholder_region: ty::Region<'tcx>,
|
placeholder_region: ty::Region<'tcx>,
|
||||||
error_region: Option<ty::Region<'tcx>>,
|
error_region: Option<ty::Region<'tcx>>,
|
||||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
|
||||||
tcx.infer_ctxt().enter_with_canonical(
|
tcx.infer_ctxt().enter_with_canonical(
|
||||||
cause.span,
|
cause.span,
|
||||||
&self.canonical_query,
|
&self.canonical_query,
|
||||||
|
@ -329,7 +345,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
|
||||||
infcx: &InferCtxt<'_, 'tcx>,
|
infcx: &InferCtxt<'_, 'tcx>,
|
||||||
placeholder_region: ty::Region<'tcx>,
|
placeholder_region: ty::Region<'tcx>,
|
||||||
error_region: Option<ty::Region<'tcx>>,
|
error_region: Option<ty::Region<'tcx>>,
|
||||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
|
||||||
let tcx = infcx.tcx;
|
let tcx = infcx.tcx;
|
||||||
|
|
||||||
// We generally shouldn't have errors here because the query was
|
// We generally shouldn't have errors here because the query was
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use rustc_const_eval::util::{CallDesugaringKind, CallKind};
|
use rustc_const_eval::util::{CallDesugaringKind, CallKind};
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::{AsyncGeneratorKind, GeneratorKind};
|
use rustc_hir::{AsyncGeneratorKind, GeneratorKind};
|
||||||
|
@ -507,7 +507,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
location: Location,
|
location: Location,
|
||||||
(place, _span): (Place<'tcx>, Span),
|
(place, _span): (Place<'tcx>, Span),
|
||||||
borrow: &BorrowData<'tcx>,
|
borrow: &BorrowData<'tcx>,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let borrow_spans = self.retrieve_borrow_spans(borrow);
|
let borrow_spans = self.retrieve_borrow_spans(borrow);
|
||||||
let borrow_span = borrow_spans.args_or_use();
|
let borrow_span = borrow_spans.args_or_use();
|
||||||
|
|
||||||
|
@ -554,7 +554,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
(place, span): (Place<'tcx>, Span),
|
(place, span): (Place<'tcx>, Span),
|
||||||
gen_borrow_kind: BorrowKind,
|
gen_borrow_kind: BorrowKind,
|
||||||
issued_borrow: &BorrowData<'tcx>,
|
issued_borrow: &BorrowData<'tcx>,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let issued_spans = self.retrieve_borrow_spans(issued_borrow);
|
let issued_spans = self.retrieve_borrow_spans(issued_borrow);
|
||||||
let issued_span = issued_spans.args_or_use();
|
let issued_span = issued_spans.args_or_use();
|
||||||
|
|
||||||
|
@ -782,7 +782,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
#[instrument(level = "debug", skip(self, err))]
|
#[instrument(level = "debug", skip(self, err))]
|
||||||
fn suggest_using_local_if_applicable(
|
fn suggest_using_local_if_applicable(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
location: Location,
|
location: Location,
|
||||||
(place, span): (Place<'tcx>, Span),
|
(place, span): (Place<'tcx>, Span),
|
||||||
gen_borrow_kind: BorrowKind,
|
gen_borrow_kind: BorrowKind,
|
||||||
|
@ -855,7 +855,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
|
|
||||||
fn suggest_split_at_mut_if_applicable(
|
fn suggest_split_at_mut_if_applicable(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
place: Place<'tcx>,
|
place: Place<'tcx>,
|
||||||
borrowed_place: Place<'tcx>,
|
borrowed_place: Place<'tcx>,
|
||||||
) {
|
) {
|
||||||
|
@ -1120,7 +1120,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
drop_span: Span,
|
drop_span: Span,
|
||||||
borrow_spans: UseSpans<'tcx>,
|
borrow_spans: UseSpans<'tcx>,
|
||||||
explanation: BorrowExplanation,
|
explanation: BorrowExplanation,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
debug!(
|
debug!(
|
||||||
"report_local_value_does_not_live_long_enough(\
|
"report_local_value_does_not_live_long_enough(\
|
||||||
{:?}, {:?}, {:?}, {:?}, {:?}\
|
{:?}, {:?}, {:?}, {:?}, {:?}\
|
||||||
|
@ -1298,7 +1298,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
drop_span: Span,
|
drop_span: Span,
|
||||||
borrow_span: Span,
|
borrow_span: Span,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
debug!(
|
debug!(
|
||||||
"report_thread_local_value_does_not_live_long_enough(\
|
"report_thread_local_value_does_not_live_long_enough(\
|
||||||
{:?}, {:?}\
|
{:?}, {:?}\
|
||||||
|
@ -1325,7 +1325,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
borrow_spans: UseSpans<'tcx>,
|
borrow_spans: UseSpans<'tcx>,
|
||||||
proper_span: Span,
|
proper_span: Span,
|
||||||
explanation: BorrowExplanation,
|
explanation: BorrowExplanation,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
debug!(
|
debug!(
|
||||||
"report_temporary_value_does_not_live_long_enough(\
|
"report_temporary_value_does_not_live_long_enough(\
|
||||||
{:?}, {:?}, {:?}, {:?}\
|
{:?}, {:?}, {:?}, {:?}\
|
||||||
|
@ -1384,7 +1384,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
return_span: Span,
|
return_span: Span,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory,
|
||||||
opt_place_desc: Option<&String>,
|
opt_place_desc: Option<&String>,
|
||||||
) -> Option<DiagnosticBuilder<'cx>> {
|
) -> Option<DiagnosticBuilder<'cx, ErrorReported>> {
|
||||||
let return_kind = match category {
|
let return_kind = match category {
|
||||||
ConstraintCategory::Return(_) => "return",
|
ConstraintCategory::Return(_) => "return",
|
||||||
ConstraintCategory::Yield => "yield",
|
ConstraintCategory::Yield => "yield",
|
||||||
|
@ -1483,7 +1483,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory,
|
||||||
constraint_span: Span,
|
constraint_span: Span,
|
||||||
captured_var: &str,
|
captured_var: &str,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
let args_span = use_span.args_or_use();
|
let args_span = use_span.args_or_use();
|
||||||
|
|
||||||
|
@ -1560,7 +1560,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
upvar_span: Span,
|
upvar_span: Span,
|
||||||
upvar_name: &str,
|
upvar_name: &str,
|
||||||
escape_span: Span,
|
escape_span: Span,
|
||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx, ErrorReported> {
|
||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
|
|
||||||
let (_, escapes_from) = tcx.article_and_description(self.mir_def_id().to_def_id());
|
let (_, escapes_from) = tcx.article_and_description(self.mir_def_id().to_def_id());
|
||||||
|
@ -1835,7 +1835,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
self.buffer_error(err);
|
self.buffer_error(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut DiagnosticBuilder<'_>) {
|
fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut Diagnostic) {
|
||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
if let (
|
if let (
|
||||||
Some(Terminator { kind: TerminatorKind::Call { from_hir_call: false, .. }, .. }),
|
Some(Terminator { kind: TerminatorKind::Call { from_hir_call: false, .. }, .. }),
|
||||||
|
@ -2362,11 +2362,7 @@ enum AnnotatedBorrowFnSignature<'tcx> {
|
||||||
impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
|
impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
|
||||||
/// Annotate the provided diagnostic with information about borrow from the fn signature that
|
/// Annotate the provided diagnostic with information about borrow from the fn signature that
|
||||||
/// helps explain.
|
/// helps explain.
|
||||||
pub(crate) fn emit(
|
pub(crate) fn emit(&self, cx: &mut MirBorrowckCtxt<'_, 'tcx>, diag: &mut Diagnostic) -> String {
|
||||||
&self,
|
|
||||||
cx: &mut MirBorrowckCtxt<'_, 'tcx>,
|
|
||||||
diag: &mut DiagnosticBuilder<'_>,
|
|
||||||
) -> String {
|
|
||||||
match self {
|
match self {
|
||||||
&AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span } => {
|
&AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span } => {
|
||||||
diag.span_label(
|
diag.span_label(
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, Diagnostic};
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_infer::infer::NllRegionVariableOrigin;
|
use rustc_infer::infer::NllRegionVariableOrigin;
|
||||||
use rustc_middle::mir::{
|
use rustc_middle::mir::{
|
||||||
|
@ -60,7 +60,7 @@ impl BorrowExplanation {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
local_names: &IndexVec<Local, Option<Symbol>>,
|
local_names: &IndexVec<Local, Option<Symbol>>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
borrow_desc: &str,
|
borrow_desc: &str,
|
||||||
borrow_span: Option<Span>,
|
borrow_span: Option<Span>,
|
||||||
multiple_borrow_span: Option<(Span, Span)>,
|
multiple_borrow_span: Option<(Span, Span)>,
|
||||||
|
@ -275,7 +275,7 @@ impl BorrowExplanation {
|
||||||
}
|
}
|
||||||
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(
|
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
category: &ConstraintCategory,
|
category: &ConstraintCategory,
|
||||||
span: Span,
|
span: Span,
|
||||||
region_name: &RegionName,
|
region_name: &RegionName,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Borrow checker diagnostics.
|
//! Borrow checker diagnostics.
|
||||||
|
|
||||||
use rustc_const_eval::util::call_kind;
|
use rustc_const_eval::util::call_kind;
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::Diagnostic;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::Namespace;
|
use rustc_hir::def::Namespace;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
|
@ -57,7 +57,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
location: Location,
|
location: Location,
|
||||||
place: PlaceRef<'tcx>,
|
place: PlaceRef<'tcx>,
|
||||||
diag: &mut DiagnosticBuilder<'_>,
|
diag: &mut Diagnostic,
|
||||||
) {
|
) {
|
||||||
debug!("add_moved_or_invoked_closure_note: location={:?} place={:?}", location, place);
|
debug!("add_moved_or_invoked_closure_note: location={:?} place={:?}", location, place);
|
||||||
let mut target = place.local_or_deref_local();
|
let mut target = place.local_or_deref_local();
|
||||||
|
@ -409,7 +409,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
/// Add a note that a type does not implement `Copy`
|
/// Add a note that a type does not implement `Copy`
|
||||||
pub(super) fn note_type_does_not_implement_copy(
|
pub(super) fn note_type_does_not_implement_copy(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
place_desc: &str,
|
place_desc: &str,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
span: Option<Span>,
|
span: Option<Span>,
|
||||||
|
@ -609,11 +609,7 @@ impl UseSpans<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a span label to the arguments of the closure, if it exists.
|
// Add a span label to the arguments of the closure, if it exists.
|
||||||
pub(super) fn args_span_label(
|
pub(super) fn args_span_label(self, err: &mut Diagnostic, message: impl Into<String>) {
|
||||||
self,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
message: impl Into<String>,
|
|
||||||
) {
|
|
||||||
if let UseSpans::ClosureUse { args_span, .. } = self {
|
if let UseSpans::ClosureUse { args_span, .. } = self {
|
||||||
err.span_label(args_span, message);
|
err.span_label(args_span, message);
|
||||||
}
|
}
|
||||||
|
@ -621,11 +617,7 @@ impl UseSpans<'_> {
|
||||||
|
|
||||||
// Add a span label to the use of the captured variable, if it exists.
|
// Add a span label to the use of the captured variable, if it exists.
|
||||||
// only adds label to the `path_span`
|
// only adds label to the `path_span`
|
||||||
pub(super) fn var_span_label_path_only(
|
pub(super) fn var_span_label_path_only(self, err: &mut Diagnostic, message: impl Into<String>) {
|
||||||
self,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
message: impl Into<String>,
|
|
||||||
) {
|
|
||||||
if let UseSpans::ClosureUse { path_span, .. } = self {
|
if let UseSpans::ClosureUse { path_span, .. } = self {
|
||||||
err.span_label(path_span, message);
|
err.span_label(path_span, message);
|
||||||
}
|
}
|
||||||
|
@ -634,7 +626,7 @@ impl UseSpans<'_> {
|
||||||
// Add a span label to the use of the captured variable, if it exists.
|
// Add a span label to the use of the captured variable, if it exists.
|
||||||
pub(super) fn var_span_label(
|
pub(super) fn var_span_label(
|
||||||
self,
|
self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
message: impl Into<String>,
|
message: impl Into<String>,
|
||||||
kind_desc: impl Into<String>,
|
kind_desc: impl Into<String>,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use rustc_const_eval::util::CallDesugaringKind;
|
use rustc_const_eval::util::CallDesugaringKind;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
|
@ -271,7 +271,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
place: Place<'tcx>,
|
place: Place<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> DiagnosticBuilder<'a> {
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
let description = if place.projection.len() == 1 {
|
let description = if place.projection.len() == 1 {
|
||||||
format!("static item {}", self.describe_any_place(place.as_ref()))
|
format!("static item {}", self.describe_any_place(place.as_ref()))
|
||||||
} else {
|
} else {
|
||||||
|
@ -293,7 +293,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
deref_target_place: Place<'tcx>,
|
deref_target_place: Place<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
use_spans: Option<UseSpans<'tcx>>,
|
use_spans: Option<UseSpans<'tcx>>,
|
||||||
) -> DiagnosticBuilder<'a> {
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
// Inspect the type of the content behind the
|
// Inspect the type of the content behind the
|
||||||
// borrow to provide feedback about why this
|
// borrow to provide feedback about why this
|
||||||
// was a move rather than a copy.
|
// was a move rather than a copy.
|
||||||
|
@ -441,12 +441,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_move_hints(
|
fn add_move_hints(&self, error: GroupedMoveError<'tcx>, err: &mut Diagnostic, span: Span) {
|
||||||
&self,
|
|
||||||
error: GroupedMoveError<'tcx>,
|
|
||||||
err: &mut DiagnosticBuilder<'a>,
|
|
||||||
span: Span,
|
|
||||||
) {
|
|
||||||
match error {
|
match error {
|
||||||
GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => {
|
GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => {
|
||||||
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
|
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
|
||||||
|
@ -505,7 +500,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_move_error_suggestions(&self, err: &mut DiagnosticBuilder<'a>, binds_to: &[Local]) {
|
fn add_move_error_suggestions(&self, err: &mut Diagnostic, binds_to: &[Local]) {
|
||||||
let mut suggestions: Vec<(Span, &str, String)> = Vec::new();
|
let mut suggestions: Vec<(Span, &str, String)> = Vec::new();
|
||||||
for local in binds_to {
|
for local in binds_to {
|
||||||
let bind_to = &self.body.local_decls[*local];
|
let bind_to = &self.body.local_decls[*local];
|
||||||
|
@ -541,7 +536,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_move_error_details(&self, err: &mut DiagnosticBuilder<'a>, binds_to: &[Local]) {
|
fn add_move_error_details(&self, err: &mut Diagnostic, binds_to: &[Local]) {
|
||||||
for (j, local) in binds_to.iter().enumerate() {
|
for (j, local) in binds_to.iter().enumerate() {
|
||||||
let bind_to = &self.body.local_decls[*local];
|
let bind_to = &self.body.local_decls[*local];
|
||||||
let binding_span = bind_to.source_info.span;
|
let binding_span = bind_to.source_info.span;
|
||||||
|
|
|
@ -17,7 +17,7 @@ use rustc_span::{BytePos, Span};
|
||||||
use crate::diagnostics::BorrowedContentSource;
|
use crate::diagnostics::BorrowedContentSource;
|
||||||
use crate::MirBorrowckCtxt;
|
use crate::MirBorrowckCtxt;
|
||||||
use rustc_const_eval::util::collect_writes::FindAssignments;
|
use rustc_const_eval::util::collect_writes::FindAssignments;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, Diagnostic};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub(crate) enum AccessKind {
|
pub(crate) enum AccessKind {
|
||||||
|
@ -689,7 +689,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
id: &hir::def_id::DefId,
|
id: &hir::def_id::DefId,
|
||||||
the_place_err: PlaceRef<'tcx>,
|
the_place_err: PlaceRef<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
) {
|
) {
|
||||||
let closure_local_def_id = id.expect_local();
|
let closure_local_def_id = id.expect_local();
|
||||||
let tables = tcx.typeck(closure_local_def_id);
|
let tables = tcx.typeck(closure_local_def_id);
|
||||||
|
@ -754,7 +754,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
// Attempt to search similar mutable associated items for suggestion.
|
// Attempt to search similar mutable associated items for suggestion.
|
||||||
// In the future, attempt in all path but initially for RHS of for_loop
|
// In the future, attempt in all path but initially for RHS of for_loop
|
||||||
fn suggest_similar_mut_method_for_for_loop(&self, err: &mut DiagnosticBuilder<'_>) {
|
fn suggest_similar_mut_method_for_for_loop(&self, err: &mut Diagnostic) {
|
||||||
use hir::{
|
use hir::{
|
||||||
BodyId, Expr,
|
BodyId, Expr,
|
||||||
ExprKind::{Block, Call, DropTemps, Match, MethodCall},
|
ExprKind::{Block, Call, DropTemps, Match, MethodCall},
|
||||||
|
@ -843,7 +843,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected.
|
/// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected.
|
||||||
fn expected_fn_found_fn_mut_call(&self, err: &mut DiagnosticBuilder<'_>, sp: Span, act: &str) {
|
fn expected_fn_found_fn_mut_call(&self, err: &mut Diagnostic, sp: Span, act: &str) {
|
||||||
err.span_label(sp, format!("cannot {}", act));
|
err.span_label(sp, format!("cannot {}", act));
|
||||||
|
|
||||||
let hir = self.infcx.tcx.hir();
|
let hir = self.infcx.tcx.hir();
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//! outlives constraints.
|
//! outlives constraints.
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::Diagnostic;
|
||||||
use rustc_middle::ty::RegionVid;
|
use rustc_middle::ty::RegionVid;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
@ -162,7 +162,7 @@ impl OutlivesSuggestionBuilder {
|
||||||
&mut self,
|
&mut self,
|
||||||
mbcx: &MirBorrowckCtxt<'_, '_>,
|
mbcx: &MirBorrowckCtxt<'_, '_>,
|
||||||
errci: &ErrorConstraintInfo,
|
errci: &ErrorConstraintInfo,
|
||||||
diag: &mut DiagnosticBuilder<'_>,
|
diag: &mut Diagnostic,
|
||||||
) {
|
) {
|
||||||
// Emit an intermediate note.
|
// Emit an intermediate note.
|
||||||
let fr_name = self.region_vid_to_name(mbcx, errci.fr);
|
let fr_name = self.region_vid_to_name(mbcx, errci.fr);
|
||||||
|
@ -256,6 +256,6 @@ impl OutlivesSuggestionBuilder {
|
||||||
diag.sort_span = mir_span.shrink_to_hi();
|
diag.sort_span = mir_span.shrink_to_hi();
|
||||||
|
|
||||||
// Buffer the diagnostic
|
// Buffer the diagnostic
|
||||||
mbcx.buffer_error(diag);
|
mbcx.buffer_non_error_diag(diag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Error reporting machinery for lifetime errors.
|
//! Error reporting machinery for lifetime errors.
|
||||||
|
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_infer::infer::{
|
use rustc_infer::infer::{
|
||||||
error_reporting::nice_region_error::NiceRegionError,
|
error_reporting::nice_region_error::NiceRegionError,
|
||||||
error_reporting::unexpected_hidden_region_diagnostic, NllRegionVariableOrigin,
|
error_reporting::unexpected_hidden_region_diagnostic, NllRegionVariableOrigin,
|
||||||
|
@ -392,7 +392,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
errci: &ErrorConstraintInfo,
|
errci: &ErrorConstraintInfo,
|
||||||
kind: ReturnConstraint,
|
kind: ReturnConstraint,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
|
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
|
||||||
|
|
||||||
let mut diag = self
|
let mut diag = self
|
||||||
|
@ -469,7 +469,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
/// LL | ref_obj(x)
|
/// LL | ref_obj(x)
|
||||||
/// | ^^^^^^^^^^ `x` escapes the function body here
|
/// | ^^^^^^^^^^ `x` escapes the function body here
|
||||||
/// ```
|
/// ```
|
||||||
fn report_escaping_data_error(&self, errci: &ErrorConstraintInfo) -> DiagnosticBuilder<'tcx> {
|
fn report_escaping_data_error(
|
||||||
|
&self,
|
||||||
|
errci: &ErrorConstraintInfo,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let ErrorConstraintInfo { span, category, .. } = errci;
|
let ErrorConstraintInfo { span, category, .. } = errci;
|
||||||
|
|
||||||
let fr_name_and_span = self.regioncx.get_var_name_and_span_for_region(
|
let fr_name_and_span = self.regioncx.get_var_name_and_span_for_region(
|
||||||
|
@ -570,7 +573,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
/// | ^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it
|
/// | ^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it
|
||||||
/// | is returning data with lifetime `'b`
|
/// | is returning data with lifetime `'b`
|
||||||
/// ```
|
/// ```
|
||||||
fn report_general_error(&self, errci: &ErrorConstraintInfo) -> DiagnosticBuilder<'tcx> {
|
fn report_general_error(
|
||||||
|
&self,
|
||||||
|
errci: &ErrorConstraintInfo,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let ErrorConstraintInfo {
|
let ErrorConstraintInfo {
|
||||||
fr,
|
fr,
|
||||||
fr_is_local,
|
fr_is_local,
|
||||||
|
@ -632,7 +638,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
/// ```
|
/// ```
|
||||||
fn add_static_impl_trait_suggestion(
|
fn add_static_impl_trait_suggestion(
|
||||||
&self,
|
&self,
|
||||||
diag: &mut DiagnosticBuilder<'tcx>,
|
diag: &mut Diagnostic,
|
||||||
fr: RegionVid,
|
fr: RegionVid,
|
||||||
// We need to pass `fr_name` - computing it again will label it twice.
|
// We need to pass `fr_name` - computing it again will label it twice.
|
||||||
fr_name: RegionName,
|
fr_name: RegionName,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::Diagnostic;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_middle::ty::print::RegionHighlightMode;
|
use rustc_middle::ty::print::RegionHighlightMode;
|
||||||
|
@ -98,7 +98,7 @@ impl RegionName {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn highlight_region_name(&self, diag: &mut DiagnosticBuilder<'_>) {
|
crate fn highlight_region_name(&self, diag: &mut Diagnostic) {
|
||||||
match &self.source {
|
match &self.source {
|
||||||
RegionNameSource::NamedFreeRegion(span)
|
RegionNameSource::NamedFreeRegion(span)
|
||||||
| RegionNameSource::NamedEarlyBoundRegion(span) => {
|
| RegionNameSource::NamedEarlyBoundRegion(span) => {
|
||||||
|
|
|
@ -379,7 +379,7 @@ fn do_mir_borrowck<'a, 'tcx>(
|
||||||
// Convert any reservation warnings into lints.
|
// Convert any reservation warnings into lints.
|
||||||
let reservation_warnings = mem::take(&mut mbcx.reservation_warnings);
|
let reservation_warnings = mem::take(&mut mbcx.reservation_warnings);
|
||||||
for (_, (place, span, location, bk, borrow)) in reservation_warnings {
|
for (_, (place, span, location, bk, borrow)) in reservation_warnings {
|
||||||
let mut initial_diag = mbcx.report_conflicting_borrow(location, (place, span), bk, &borrow);
|
let initial_diag = mbcx.report_conflicting_borrow(location, (place, span), bk, &borrow);
|
||||||
|
|
||||||
let scope = mbcx.body.source_info(location).scope;
|
let scope = mbcx.body.source_info(location).scope;
|
||||||
let lint_root = match &mbcx.body.source_scopes[scope].local_data {
|
let lint_root = match &mbcx.body.source_scopes[scope].local_data {
|
||||||
|
@ -398,7 +398,7 @@ fn do_mir_borrowck<'a, 'tcx>(
|
||||||
diag.message = initial_diag.styled_message().clone();
|
diag.message = initial_diag.styled_message().clone();
|
||||||
diag.span = initial_diag.span.clone();
|
diag.span = initial_diag.span.clone();
|
||||||
|
|
||||||
mbcx.buffer_error(diag);
|
mbcx.buffer_non_error_diag(diag);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
initial_diag.cancel();
|
initial_diag.cancel();
|
||||||
|
@ -2293,8 +2293,8 @@ mod error {
|
||||||
/// when errors in the map are being re-added to the error buffer so that errors with the
|
/// when errors in the map are being re-added to the error buffer so that errors with the
|
||||||
/// same primary span come out in a consistent order.
|
/// same primary span come out in a consistent order.
|
||||||
buffered_move_errors:
|
buffered_move_errors:
|
||||||
BTreeMap<Vec<MoveOutIndex>, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)>,
|
BTreeMap<Vec<MoveOutIndex>, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx, ErrorReported>)>,
|
||||||
/// Errors to be reported buffer
|
/// Diagnostics to be reported buffer.
|
||||||
buffered: Vec<Diagnostic>,
|
buffered: Vec<Diagnostic>,
|
||||||
/// Set to Some if we emit an error during borrowck
|
/// Set to Some if we emit an error during borrowck
|
||||||
tainted_by_errors: Option<ErrorReported>,
|
tainted_by_errors: Option<ErrorReported>,
|
||||||
|
@ -2309,27 +2309,37 @@ mod error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_>) {
|
// FIXME(eddyb) this is a suboptimal API because `tainted_by_errors` is
|
||||||
|
// set before any emission actually happens (weakening the guarantee).
|
||||||
|
pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorReported>) {
|
||||||
self.tainted_by_errors = Some(ErrorReported {});
|
self.tainted_by_errors = Some(ErrorReported {});
|
||||||
t.buffer(&mut self.buffered);
|
t.buffer(&mut self.buffered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn buffer_non_error_diag(&mut self, t: DiagnosticBuilder<'_, ()>) {
|
||||||
|
t.buffer(&mut self.buffered);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_tainted_by_errors(&mut self) {
|
pub fn set_tainted_by_errors(&mut self) {
|
||||||
self.tainted_by_errors = Some(ErrorReported {});
|
self.tainted_by_errors = Some(ErrorReported {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_>) {
|
pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorReported>) {
|
||||||
self.errors.buffer_error(t);
|
self.errors.buffer_error(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn buffer_non_error_diag(&mut self, t: DiagnosticBuilder<'_, ()>) {
|
||||||
|
self.errors.buffer_non_error_diag(t);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn buffer_move_error(
|
pub fn buffer_move_error(
|
||||||
&mut self,
|
&mut self,
|
||||||
move_out_indices: Vec<MoveOutIndex>,
|
move_out_indices: Vec<MoveOutIndex>,
|
||||||
place_and_err: (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>),
|
place_and_err: (PlaceRef<'tcx>, DiagnosticBuilder<'tcx, ErrorReported>),
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let Some((_, mut diag)) =
|
if let Some((_, diag)) =
|
||||||
self.errors.buffered_move_errors.insert(move_out_indices, place_and_err)
|
self.errors.buffered_move_errors.insert(move_out_indices, place_and_err)
|
||||||
{
|
{
|
||||||
// Cancel the old diagnostic so we don't ICE
|
// Cancel the old diagnostic so we don't ICE
|
||||||
|
@ -2365,7 +2375,7 @@ mod error {
|
||||||
pub fn has_move_error(
|
pub fn has_move_error(
|
||||||
&self,
|
&self,
|
||||||
move_out_indices: &[MoveOutIndex],
|
move_out_indices: &[MoveOutIndex],
|
||||||
) -> Option<&(PlaceRef<'tcx>, DiagnosticBuilder<'cx>)> {
|
) -> Option<&(PlaceRef<'tcx>, DiagnosticBuilder<'cx, ErrorReported>)> {
|
||||||
self.errors.buffered_move_errors.get(move_out_indices)
|
self.errors.buffered_move_errors.get(move_out_indices)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,7 +417,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
|
||||||
err.note(&format!("Inferred opaque type values:\n{:#?}", opaque_type_values));
|
err.note(&format!("Inferred opaque type values:\n{:#?}", opaque_type_values));
|
||||||
}
|
}
|
||||||
|
|
||||||
errors.buffer_error(err);
|
errors.buffer_non_error_diag(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn for_each_region_constraint(
|
fn for_each_region_constraint(
|
||||||
|
|
|
@ -5,6 +5,7 @@ use rustc_data_structures::binary_search_util;
|
||||||
use rustc_data_structures::frozen::Frozen;
|
use rustc_data_structures::frozen::Frozen;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::graph::scc::Sccs;
|
use rustc_data_structures::graph::scc::Sccs;
|
||||||
|
use rustc_errors::Diagnostic;
|
||||||
use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
|
use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
|
||||||
use rustc_hir::CRATE_HIR_ID;
|
use rustc_hir::CRATE_HIR_ID;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
|
@ -510,7 +511,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds annotations for `#[rustc_regions]`; see `UniversalRegions::annotate`.
|
/// Adds annotations for `#[rustc_regions]`; see `UniversalRegions::annotate`.
|
||||||
crate fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut rustc_errors::DiagnosticBuilder<'_>) {
|
crate fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diagnostic) {
|
||||||
self.universal_regions.annotate(tcx, err)
|
self.universal_regions.annotate(tcx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::Diagnostic;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
|
@ -336,7 +336,7 @@ impl<'tcx> UniversalRegions<'tcx> {
|
||||||
/// that this region imposes on others. The methods in this file
|
/// that this region imposes on others. The methods in this file
|
||||||
/// handle the part about dumping the inference context internal
|
/// handle the part about dumping the inference context internal
|
||||||
/// state.
|
/// state.
|
||||||
crate fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut DiagnosticBuilder<'_>) {
|
crate fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diagnostic) {
|
||||||
match self.defining_ty {
|
match self.defining_ty {
|
||||||
DefiningTy::Closure(def_id, substs) => {
|
DefiningTy::Closure(def_id, substs) => {
|
||||||
err.note(&format!(
|
err.note(&format!(
|
||||||
|
|
|
@ -3,7 +3,7 @@ use rustc_ast::ptr::P;
|
||||||
use rustc_ast::token;
|
use rustc_ast::token;
|
||||||
use rustc_ast::tokenstream::TokenStream;
|
use rustc_ast::tokenstream::TokenStream;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, PResult};
|
||||||
use rustc_expand::base::{self, *};
|
use rustc_expand::base::{self, *};
|
||||||
use rustc_parse::parser::Parser;
|
use rustc_parse::parser::Parser;
|
||||||
use rustc_parse_format as parse;
|
use rustc_parse_format as parse;
|
||||||
|
@ -30,7 +30,7 @@ fn parse_args<'a>(
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: TokenStream,
|
tts: TokenStream,
|
||||||
is_global_asm: bool,
|
is_global_asm: bool,
|
||||||
) -> Result<AsmArgs, DiagnosticBuilder<'a>> {
|
) -> PResult<'a, AsmArgs> {
|
||||||
let mut p = ecx.new_parser_from_tts(tts);
|
let mut p = ecx.new_parser_from_tts(tts);
|
||||||
let sess = &ecx.sess.parse_sess;
|
let sess = &ecx.sess.parse_sess;
|
||||||
parse_asm_args(&mut p, sess, sp, is_global_asm)
|
parse_asm_args(&mut p, sess, sp, is_global_asm)
|
||||||
|
@ -43,7 +43,7 @@ pub fn parse_asm_args<'a>(
|
||||||
sess: &'a ParseSess,
|
sess: &'a ParseSess,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
is_global_asm: bool,
|
is_global_asm: bool,
|
||||||
) -> Result<AsmArgs, DiagnosticBuilder<'a>> {
|
) -> PResult<'a, AsmArgs> {
|
||||||
let diag = &sess.span_diagnostic;
|
let diag = &sess.span_diagnostic;
|
||||||
|
|
||||||
if p.token == token::Eof {
|
if p.token == token::Eof {
|
||||||
|
@ -390,7 +390,7 @@ fn parse_options<'a>(
|
||||||
p: &mut Parser<'a>,
|
p: &mut Parser<'a>,
|
||||||
args: &mut AsmArgs,
|
args: &mut AsmArgs,
|
||||||
is_global_asm: bool,
|
is_global_asm: bool,
|
||||||
) -> Result<(), DiagnosticBuilder<'a>> {
|
) -> PResult<'a, ()> {
|
||||||
let span_start = p.prev_token.span;
|
let span_start = p.prev_token.span;
|
||||||
|
|
||||||
p.expect(&token::OpenDelim(token::DelimToken::Paren))?;
|
p.expect(&token::OpenDelim(token::DelimToken::Paren))?;
|
||||||
|
@ -431,10 +431,7 @@ fn parse_options<'a>(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_clobber_abi<'a>(
|
fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a, ()> {
|
||||||
p: &mut Parser<'a>,
|
|
||||||
args: &mut AsmArgs,
|
|
||||||
) -> Result<(), DiagnosticBuilder<'a>> {
|
|
||||||
let span_start = p.prev_token.span;
|
let span_start = p.prev_token.span;
|
||||||
|
|
||||||
p.expect(&token::OpenDelim(token::DelimToken::Paren))?;
|
p.expect(&token::OpenDelim(token::DelimToken::Paren))?;
|
||||||
|
@ -501,7 +498,7 @@ fn parse_clobber_abi<'a>(
|
||||||
fn parse_reg<'a>(
|
fn parse_reg<'a>(
|
||||||
p: &mut Parser<'a>,
|
p: &mut Parser<'a>,
|
||||||
explicit_reg: &mut bool,
|
explicit_reg: &mut bool,
|
||||||
) -> Result<ast::InlineAsmRegOrRegClass, DiagnosticBuilder<'a>> {
|
) -> PResult<'a, ast::InlineAsmRegOrRegClass> {
|
||||||
p.expect(&token::OpenDelim(token::DelimToken::Paren))?;
|
p.expect(&token::OpenDelim(token::DelimToken::Paren))?;
|
||||||
let result = match p.token.uninterpolate().kind {
|
let result = match p.token.uninterpolate().kind {
|
||||||
token::Ident(name, false) => ast::InlineAsmRegOrRegClass::RegClass(name),
|
token::Ident(name, false) => ast::InlineAsmRegOrRegClass::RegClass(name),
|
||||||
|
|
|
@ -4,7 +4,7 @@ use rustc_ast::token;
|
||||||
use rustc_ast::tokenstream::{DelimSpan, TokenStream};
|
use rustc_ast::tokenstream::{DelimSpan, TokenStream};
|
||||||
use rustc_ast::{self as ast, *};
|
use rustc_ast::{self as ast, *};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, PResult};
|
||||||
use rustc_expand::base::*;
|
use rustc_expand::base::*;
|
||||||
use rustc_parse::parser::Parser;
|
use rustc_parse::parser::Parser;
|
||||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||||
|
@ -83,11 +83,7 @@ struct Assert {
|
||||||
custom_message: Option<TokenStream>,
|
custom_message: Option<TokenStream>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_assert<'a>(
|
fn parse_assert<'a>(cx: &mut ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PResult<'a, Assert> {
|
||||||
cx: &mut ExtCtxt<'a>,
|
|
||||||
sp: Span,
|
|
||||||
stream: TokenStream,
|
|
||||||
) -> Result<Assert, DiagnosticBuilder<'a>> {
|
|
||||||
let mut parser = cx.new_parser_from_tts(stream);
|
let mut parser = cx.new_parser_from_tts(stream);
|
||||||
|
|
||||||
if parser.token == token::Eof {
|
if parser.token == token::Eof {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use rustc_ast as ast;
|
||||||
use rustc_ast::token;
|
use rustc_ast::token;
|
||||||
use rustc_ast::tokenstream::TokenStream;
|
use rustc_ast::tokenstream::TokenStream;
|
||||||
use rustc_attr as attr;
|
use rustc_attr as attr;
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::PResult;
|
||||||
use rustc_expand::base::{self, *};
|
use rustc_expand::base::{self, *};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
|
@ -29,11 +29,7 @@ pub fn expand_cfg(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_cfg<'a>(
|
fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
|
||||||
cx: &mut ExtCtxt<'a>,
|
|
||||||
sp: Span,
|
|
||||||
tts: TokenStream,
|
|
||||||
) -> Result<ast::MetaItem, DiagnosticBuilder<'a>> {
|
|
||||||
let mut p = cx.new_parser_from_tts(tts);
|
let mut p = cx.new_parser_from_tts(tts);
|
||||||
|
|
||||||
if p.token == token::Eof {
|
if p.token == token::Eof {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use rustc_ast::tokenstream::TokenStream;
|
||||||
use rustc_ast::visit::{self, Visitor};
|
use rustc_ast::visit::{self, Visitor};
|
||||||
use rustc_ast::{token, BlockCheckMode, UnsafeSource};
|
use rustc_ast::{token, BlockCheckMode, UnsafeSource};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_errors::{pluralize, Applicability, DiagnosticBuilder};
|
use rustc_errors::{pluralize, Applicability, PResult};
|
||||||
use rustc_expand::base::{self, *};
|
use rustc_expand::base::{self, *};
|
||||||
use rustc_parse_format as parse;
|
use rustc_parse_format as parse;
|
||||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||||
|
@ -130,7 +130,7 @@ fn parse_args<'a>(
|
||||||
ecx: &mut ExtCtxt<'a>,
|
ecx: &mut ExtCtxt<'a>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: TokenStream,
|
tts: TokenStream,
|
||||||
) -> Result<(P<ast::Expr>, Vec<P<ast::Expr>>, FxHashMap<Symbol, usize>), DiagnosticBuilder<'a>> {
|
) -> PResult<'a, (P<ast::Expr>, Vec<P<ast::Expr>>, FxHashMap<Symbol, usize>)> {
|
||||||
let mut args = Vec::<P<ast::Expr>>::new();
|
let mut args = Vec::<P<ast::Expr>>::new();
|
||||||
let mut names = FxHashMap::<Symbol, usize>::default();
|
let mut names = FxHashMap::<Symbol, usize>::default();
|
||||||
|
|
||||||
|
|
|
@ -376,9 +376,13 @@ fn get_test_runner(
|
||||||
match &*meta_list {
|
match &*meta_list {
|
||||||
[single] => match single.meta_item() {
|
[single] => match single.meta_item() {
|
||||||
Some(meta_item) if meta_item.is_word() => return Some(meta_item.path.clone()),
|
Some(meta_item) if meta_item.is_word() => return Some(meta_item.path.clone()),
|
||||||
_ => sd.struct_span_err(span, "`test_runner` argument must be a path").emit(),
|
_ => {
|
||||||
|
sd.struct_span_err(span, "`test_runner` argument must be a path").emit();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => sd.struct_span_err(span, "`#![test_runner(..)]` accepts exactly 1 argument").emit(),
|
_ => {
|
||||||
|
sd.struct_span_err(span, "`#![test_runner(..)]` accepts exactly 1 argument").emit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -1709,7 +1709,7 @@ impl Emitter for SharedEmitter {
|
||||||
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
||||||
msg: diag.message(),
|
msg: diag.message(),
|
||||||
code: diag.code.clone(),
|
code: diag.code.clone(),
|
||||||
lvl: diag.level,
|
lvl: diag.level(),
|
||||||
})));
|
})));
|
||||||
for child in &diag.children {
|
for child in &diag.children {
|
||||||
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
||||||
|
@ -1753,7 +1753,7 @@ impl SharedEmitterMain {
|
||||||
let msg = msg.strip_prefix("error: ").unwrap_or(&msg);
|
let msg = msg.strip_prefix("error: ").unwrap_or(&msg);
|
||||||
|
|
||||||
let mut err = match level {
|
let mut err = match level {
|
||||||
Level::Error { lint: false } => sess.struct_err(&msg),
|
Level::Error { lint: false } => sess.struct_err(&msg).forget_guarantee(),
|
||||||
Level::Warning => sess.struct_warn(&msg),
|
Level::Warning => sess.struct_warn(&msg),
|
||||||
Level::Note => sess.struct_note_without_error(&msg),
|
Level::Note => sess.struct_note_without_error(&msg),
|
||||||
_ => bug!("Invalid inline asm diagnostic level"),
|
_ => bug!("Invalid inline asm diagnostic level"),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use rustc_errors::{DiagnosticBuilder, ErrorReported};
|
use rustc_errors::Diagnostic;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_middle::mir::AssertKind;
|
use rustc_middle::mir::AssertKind;
|
||||||
use rustc_middle::ty::{layout::LayoutError, query::TyCtxtAt, ConstInt};
|
use rustc_middle::ty::{layout::LayoutError, query::TyCtxtAt, ConstInt};
|
||||||
|
@ -94,13 +94,13 @@ impl<'tcx> ConstEvalErr<'tcx> {
|
||||||
&self,
|
&self,
|
||||||
tcx: TyCtxtAt<'tcx>,
|
tcx: TyCtxtAt<'tcx>,
|
||||||
message: &str,
|
message: &str,
|
||||||
emit: impl FnOnce(DiagnosticBuilder<'_>),
|
decorate: impl FnOnce(&mut Diagnostic),
|
||||||
) -> ErrorHandled {
|
) -> ErrorHandled {
|
||||||
self.struct_generic(tcx, message, emit, None)
|
self.struct_generic(tcx, message, decorate, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn report_as_error(&self, tcx: TyCtxtAt<'tcx>, message: &str) -> ErrorHandled {
|
pub fn report_as_error(&self, tcx: TyCtxtAt<'tcx>, message: &str) -> ErrorHandled {
|
||||||
self.struct_error(tcx, message, |mut e| e.emit())
|
self.struct_error(tcx, message, |_| {})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn report_as_lint(
|
pub fn report_as_lint(
|
||||||
|
@ -113,7 +113,7 @@ impl<'tcx> ConstEvalErr<'tcx> {
|
||||||
self.struct_generic(
|
self.struct_generic(
|
||||||
tcx,
|
tcx,
|
||||||
message,
|
message,
|
||||||
|mut lint: DiagnosticBuilder<'_>| {
|
|lint: &mut Diagnostic| {
|
||||||
// Apply the span.
|
// Apply the span.
|
||||||
if let Some(span) = span {
|
if let Some(span) = span {
|
||||||
let primary_spans = lint.span.primary_spans().to_vec();
|
let primary_spans = lint.span.primary_spans().to_vec();
|
||||||
|
@ -127,7 +127,6 @@ impl<'tcx> ConstEvalErr<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lint.emit();
|
|
||||||
},
|
},
|
||||||
Some(lint_root),
|
Some(lint_root),
|
||||||
)
|
)
|
||||||
|
@ -136,9 +135,8 @@ impl<'tcx> ConstEvalErr<'tcx> {
|
||||||
/// Create a diagnostic for this const eval error.
|
/// Create a diagnostic for this const eval error.
|
||||||
///
|
///
|
||||||
/// Sets the message passed in via `message` and adds span labels with detailed error
|
/// Sets the message passed in via `message` and adds span labels with detailed error
|
||||||
/// information before handing control back to `emit` to do any final processing.
|
/// information before handing control back to `decorate` to do any final annotations,
|
||||||
/// It's the caller's responsibility to call emit(), stash(), etc. within the `emit`
|
/// after which the diagnostic is emitted.
|
||||||
/// function to dispose of the diagnostic properly.
|
|
||||||
///
|
///
|
||||||
/// If `lint_root.is_some()` report it as a lint, else report it as a hard error.
|
/// If `lint_root.is_some()` report it as a lint, else report it as a hard error.
|
||||||
/// (Except that for some errors, we ignore all that -- see `must_error` below.)
|
/// (Except that for some errors, we ignore all that -- see `must_error` below.)
|
||||||
|
@ -146,10 +144,10 @@ impl<'tcx> ConstEvalErr<'tcx> {
|
||||||
&self,
|
&self,
|
||||||
tcx: TyCtxtAt<'tcx>,
|
tcx: TyCtxtAt<'tcx>,
|
||||||
message: &str,
|
message: &str,
|
||||||
emit: impl FnOnce(DiagnosticBuilder<'_>),
|
decorate: impl FnOnce(&mut Diagnostic),
|
||||||
lint_root: Option<hir::HirId>,
|
lint_root: Option<hir::HirId>,
|
||||||
) -> ErrorHandled {
|
) -> ErrorHandled {
|
||||||
let finish = |mut err: DiagnosticBuilder<'_>, span_msg: Option<String>| {
|
let finish = |err: &mut Diagnostic, span_msg: Option<String>| {
|
||||||
trace!("reporting const eval failure at {:?}", self.span);
|
trace!("reporting const eval failure at {:?}", self.span);
|
||||||
if let Some(span_msg) = span_msg {
|
if let Some(span_msg) = span_msg {
|
||||||
err.span_label(self.span, span_msg);
|
err.span_label(self.span, span_msg);
|
||||||
|
@ -188,8 +186,8 @@ impl<'tcx> ConstEvalErr<'tcx> {
|
||||||
}
|
}
|
||||||
flush_last_line(last_frame, times);
|
flush_last_line(last_frame, times);
|
||||||
}
|
}
|
||||||
// Let the caller finish the job.
|
// Let the caller attach any additional information it wants.
|
||||||
emit(err)
|
decorate(err);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Special handling for certain errors
|
// Special handling for certain errors
|
||||||
|
@ -206,8 +204,9 @@ impl<'tcx> ConstEvalErr<'tcx> {
|
||||||
// The `message` makes little sense here, this is a more serious error than the
|
// The `message` makes little sense here, this is a more serious error than the
|
||||||
// caller thinks anyway.
|
// caller thinks anyway.
|
||||||
// See <https://github.com/rust-lang/rust/pull/63152>.
|
// See <https://github.com/rust-lang/rust/pull/63152>.
|
||||||
finish(struct_error(tcx, &self.error.to_string()), None);
|
let mut err = struct_error(tcx, &self.error.to_string());
|
||||||
return ErrorHandled::Reported(ErrorReported);
|
finish(&mut err, None);
|
||||||
|
return ErrorHandled::Reported(err.emit());
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
@ -223,13 +222,18 @@ impl<'tcx> ConstEvalErr<'tcx> {
|
||||||
rustc_session::lint::builtin::CONST_ERR,
|
rustc_session::lint::builtin::CONST_ERR,
|
||||||
hir_id,
|
hir_id,
|
||||||
tcx.span,
|
tcx.span,
|
||||||
|lint| finish(lint.build(message), Some(err_msg)),
|
|lint| {
|
||||||
|
let mut lint = lint.build(message);
|
||||||
|
finish(&mut lint, Some(err_msg));
|
||||||
|
lint.emit();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
ErrorHandled::Linted
|
ErrorHandled::Linted
|
||||||
} else {
|
} else {
|
||||||
// Report as hard error.
|
// Report as hard error.
|
||||||
finish(struct_error(tcx, message), Some(err_msg));
|
let mut err = struct_error(tcx, message);
|
||||||
ErrorHandled::Reported(ErrorReported)
|
finish(&mut err, Some(err_msg));
|
||||||
|
ErrorHandled::Reported(err.emit())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -361,7 +361,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
|
||||||
Err(err.struct_error(
|
Err(err.struct_error(
|
||||||
ecx.tcx,
|
ecx.tcx,
|
||||||
"it is undefined behavior to use this value",
|
"it is undefined behavior to use this value",
|
||||||
|mut diag| {
|
|diag| {
|
||||||
diag.note(note_on_undefined_behavior_error());
|
diag.note(note_on_undefined_behavior_error());
|
||||||
diag.note(&format!(
|
diag.note(&format!(
|
||||||
"the raw bytes of the constant ({}",
|
"the raw bytes of the constant ({}",
|
||||||
|
@ -370,7 +370,6 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
|
||||||
ecx.tcx.global_alloc(alloc_id).unwrap_memory()
|
ecx.tcx.global_alloc(alloc_id).unwrap_memory()
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
diag.emit();
|
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Concrete error types for all operations which may be invalid in a certain const context.
|
//! Concrete error types for all operations which may be invalid in a certain const context.
|
||||||
|
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
|
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
|
@ -47,7 +47,11 @@ pub trait NonConstOp<'tcx>: std::fmt::Debug {
|
||||||
DiagnosticImportance::Primary
|
DiagnosticImportance::Primary
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx>;
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -61,7 +65,11 @@ impl<'tcx> NonConstOp<'tcx> for FloatingPointOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
feature_err(
|
feature_err(
|
||||||
&ccx.tcx.sess.parse_sess,
|
&ccx.tcx.sess.parse_sess,
|
||||||
sym::const_fn_floating_point_arithmetic,
|
sym::const_fn_floating_point_arithmetic,
|
||||||
|
@ -75,7 +83,11 @@ impl<'tcx> NonConstOp<'tcx> for FloatingPointOp {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FnCallIndirect;
|
pub struct FnCallIndirect;
|
||||||
impl<'tcx> NonConstOp<'tcx> for FnCallIndirect {
|
impl<'tcx> NonConstOp<'tcx> for FnCallIndirect {
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
ccx.tcx.sess.struct_span_err(span, "function pointers are not allowed in const fn")
|
ccx.tcx.sess.struct_span_err(span, "function pointers are not allowed in const fn")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,11 +103,15 @@ pub struct FnCallNonConst<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, _: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
_: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let FnCallNonConst { caller, callee, substs, span, from_hir_call } = *self;
|
let FnCallNonConst { caller, callee, substs, span, from_hir_call } = *self;
|
||||||
let ConstCx { tcx, param_env, .. } = *ccx;
|
let ConstCx { tcx, param_env, .. } = *ccx;
|
||||||
|
|
||||||
let diag_trait = |mut err, self_ty: Ty<'_>, trait_id| {
|
let diag_trait = |err, self_ty: Ty<'_>, trait_id| {
|
||||||
let trait_ref = TraitRef::from_method(tcx, trait_id, substs);
|
let trait_ref = TraitRef::from_method(tcx, trait_id, substs);
|
||||||
|
|
||||||
match self_ty.kind() {
|
match self_ty.kind() {
|
||||||
|
@ -115,7 +131,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
suggest_constraining_type_param(
|
suggest_constraining_type_param(
|
||||||
tcx,
|
tcx,
|
||||||
generics,
|
generics,
|
||||||
&mut err,
|
err,
|
||||||
¶m_ty.name.as_str(),
|
¶m_ty.name.as_str(),
|
||||||
&constraint,
|
&constraint,
|
||||||
None,
|
None,
|
||||||
|
@ -146,8 +162,6 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
err
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let call_kind = call_kind(tcx, ccx.param_env, callee, substs, span, from_hir_call, None);
|
let call_kind = call_kind(tcx, ccx.param_env, callee, substs, span, from_hir_call, None);
|
||||||
|
@ -162,7 +176,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let err = match kind {
|
let mut err = match kind {
|
||||||
CallDesugaringKind::ForLoopIntoIter => {
|
CallDesugaringKind::ForLoopIntoIter => {
|
||||||
error!("cannot convert `{}` into an iterator in {}s")
|
error!("cannot convert `{}` into an iterator in {}s")
|
||||||
}
|
}
|
||||||
|
@ -177,7 +191,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
diag_trait(err, self_ty, kind.trait_def_id(tcx))
|
diag_trait(&mut err, self_ty, kind.trait_def_id(tcx));
|
||||||
|
err
|
||||||
}
|
}
|
||||||
CallKind::FnCall { fn_trait_id, self_ty } => {
|
CallKind::FnCall { fn_trait_id, self_ty } => {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
|
@ -212,7 +227,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
diag_trait(err, self_ty, fn_trait_id)
|
diag_trait(&mut err, self_ty, fn_trait_id);
|
||||||
|
err
|
||||||
}
|
}
|
||||||
CallKind::Operator { trait_id, self_ty, .. } => {
|
CallKind::Operator { trait_id, self_ty, .. } => {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
|
@ -262,7 +278,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
diag_trait(err, self_ty, trait_id)
|
diag_trait(&mut err, self_ty, trait_id);
|
||||||
|
err
|
||||||
}
|
}
|
||||||
CallKind::DerefCoercion { deref_target, deref_target_ty, self_ty } => {
|
CallKind::DerefCoercion { deref_target, deref_target_ty, self_ty } => {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
|
@ -281,7 +298,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
err.span_note(deref_target, "deref defined here");
|
err.span_note(deref_target, "deref defined here");
|
||||||
}
|
}
|
||||||
|
|
||||||
diag_trait(err, self_ty, tcx.lang_items().deref_trait().unwrap())
|
diag_trait(&mut err, self_ty, tcx.lang_items().deref_trait().unwrap());
|
||||||
|
err
|
||||||
}
|
}
|
||||||
_ => struct_span_err!(
|
_ => struct_span_err!(
|
||||||
ccx.tcx.sess,
|
ccx.tcx.sess,
|
||||||
|
@ -310,7 +328,11 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
pub struct FnCallUnstable(pub DefId, pub Option<Symbol>);
|
pub struct FnCallUnstable(pub DefId, pub Option<Symbol>);
|
||||||
|
|
||||||
impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
|
impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let FnCallUnstable(def_id, feature) = *self;
|
let FnCallUnstable(def_id, feature) = *self;
|
||||||
|
|
||||||
let mut err = ccx.tcx.sess.struct_span_err(
|
let mut err = ccx.tcx.sess.struct_span_err(
|
||||||
|
@ -344,7 +366,11 @@ impl<'tcx> NonConstOp<'tcx> for FnPtrCast {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
feature_err(
|
feature_err(
|
||||||
&ccx.tcx.sess.parse_sess,
|
&ccx.tcx.sess.parse_sess,
|
||||||
sym::const_fn_fn_ptr_basics,
|
sym::const_fn_fn_ptr_basics,
|
||||||
|
@ -365,7 +391,11 @@ impl<'tcx> NonConstOp<'tcx> for Generator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let msg = format!("{}s are not allowed in {}s", self.0, ccx.const_kind());
|
let msg = format!("{}s are not allowed in {}s", self.0, ccx.const_kind());
|
||||||
if let hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) = self.0 {
|
if let hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) = self.0 {
|
||||||
feature_err(&ccx.tcx.sess.parse_sess, sym::const_async_blocks, span, &msg)
|
feature_err(&ccx.tcx.sess.parse_sess, sym::const_async_blocks, span, &msg)
|
||||||
|
@ -378,7 +408,11 @@ impl<'tcx> NonConstOp<'tcx> for Generator {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct HeapAllocation;
|
pub struct HeapAllocation;
|
||||||
impl<'tcx> NonConstOp<'tcx> for HeapAllocation {
|
impl<'tcx> NonConstOp<'tcx> for HeapAllocation {
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
ccx.tcx.sess,
|
ccx.tcx.sess,
|
||||||
span,
|
span,
|
||||||
|
@ -402,7 +436,11 @@ impl<'tcx> NonConstOp<'tcx> for HeapAllocation {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct InlineAsm;
|
pub struct InlineAsm;
|
||||||
impl<'tcx> NonConstOp<'tcx> for InlineAsm {
|
impl<'tcx> NonConstOp<'tcx> for InlineAsm {
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
ccx.tcx.sess,
|
ccx.tcx.sess,
|
||||||
span,
|
span,
|
||||||
|
@ -418,7 +456,11 @@ pub struct LiveDrop {
|
||||||
pub dropped_at: Option<Span>,
|
pub dropped_at: Option<Span>,
|
||||||
}
|
}
|
||||||
impl<'tcx> NonConstOp<'tcx> for LiveDrop {
|
impl<'tcx> NonConstOp<'tcx> for LiveDrop {
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
ccx.tcx.sess,
|
ccx.tcx.sess,
|
||||||
span,
|
span,
|
||||||
|
@ -446,7 +488,11 @@ impl<'tcx> NonConstOp<'tcx> for TransientCellBorrow {
|
||||||
// not additionally emit a feature gate error if activating the feature gate won't work.
|
// not additionally emit a feature gate error if activating the feature gate won't work.
|
||||||
DiagnosticImportance::Secondary
|
DiagnosticImportance::Secondary
|
||||||
}
|
}
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
feature_err(
|
feature_err(
|
||||||
&ccx.tcx.sess.parse_sess,
|
&ccx.tcx.sess.parse_sess,
|
||||||
sym::const_refs_to_cell,
|
sym::const_refs_to_cell,
|
||||||
|
@ -462,7 +508,11 @@ impl<'tcx> NonConstOp<'tcx> for TransientCellBorrow {
|
||||||
/// it in the future for static items.
|
/// it in the future for static items.
|
||||||
pub struct CellBorrow;
|
pub struct CellBorrow;
|
||||||
impl<'tcx> NonConstOp<'tcx> for CellBorrow {
|
impl<'tcx> NonConstOp<'tcx> for CellBorrow {
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
ccx.tcx.sess,
|
ccx.tcx.sess,
|
||||||
span,
|
span,
|
||||||
|
@ -509,7 +559,11 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow {
|
||||||
DiagnosticImportance::Secondary
|
DiagnosticImportance::Secondary
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let raw = match self.0 {
|
let raw = match self.0 {
|
||||||
hir::BorrowKind::Raw => "raw ",
|
hir::BorrowKind::Raw => "raw ",
|
||||||
hir::BorrowKind::Ref => "",
|
hir::BorrowKind::Ref => "",
|
||||||
|
@ -548,7 +602,11 @@ impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow {
|
||||||
Status::Unstable(sym::const_mut_refs)
|
Status::Unstable(sym::const_mut_refs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let raw = match self.0 {
|
let raw = match self.0 {
|
||||||
hir::BorrowKind::Raw => "raw ",
|
hir::BorrowKind::Raw => "raw ",
|
||||||
hir::BorrowKind::Ref => "",
|
hir::BorrowKind::Ref => "",
|
||||||
|
@ -575,7 +633,11 @@ impl<'tcx> NonConstOp<'tcx> for MutDeref {
|
||||||
DiagnosticImportance::Secondary
|
DiagnosticImportance::Secondary
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
feature_err(
|
feature_err(
|
||||||
&ccx.tcx.sess.parse_sess,
|
&ccx.tcx.sess.parse_sess,
|
||||||
sym::const_mut_refs,
|
sym::const_mut_refs,
|
||||||
|
@ -589,7 +651,11 @@ impl<'tcx> NonConstOp<'tcx> for MutDeref {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PanicNonStr;
|
pub struct PanicNonStr;
|
||||||
impl<'tcx> NonConstOp<'tcx> for PanicNonStr {
|
impl<'tcx> NonConstOp<'tcx> for PanicNonStr {
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
ccx.tcx.sess.struct_span_err(
|
ccx.tcx.sess.struct_span_err(
|
||||||
span,
|
span,
|
||||||
"argument to `panic!()` in a const context must have type `&str`",
|
"argument to `panic!()` in a const context must have type `&str`",
|
||||||
|
@ -603,7 +669,11 @@ impl<'tcx> NonConstOp<'tcx> for PanicNonStr {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RawPtrComparison;
|
pub struct RawPtrComparison;
|
||||||
impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
|
impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let mut err = ccx
|
let mut err = ccx
|
||||||
.tcx
|
.tcx
|
||||||
.sess
|
.sess
|
||||||
|
@ -623,7 +693,11 @@ impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref {
|
||||||
Status::Unstable(sym::const_mut_refs)
|
Status::Unstable(sym::const_mut_refs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
feature_err(
|
feature_err(
|
||||||
&ccx.tcx.sess.parse_sess,
|
&ccx.tcx.sess.parse_sess,
|
||||||
sym::const_mut_refs,
|
sym::const_mut_refs,
|
||||||
|
@ -639,7 +713,11 @@ impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RawPtrToIntCast;
|
pub struct RawPtrToIntCast;
|
||||||
impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
|
impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let mut err = ccx
|
let mut err = ccx
|
||||||
.tcx
|
.tcx
|
||||||
.sess
|
.sess
|
||||||
|
@ -664,7 +742,11 @@ impl<'tcx> NonConstOp<'tcx> for StaticAccess {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
ccx.tcx.sess,
|
ccx.tcx.sess,
|
||||||
span,
|
span,
|
||||||
|
@ -690,7 +772,11 @@ impl<'tcx> NonConstOp<'tcx> for StaticAccess {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ThreadLocalAccess;
|
pub struct ThreadLocalAccess;
|
||||||
impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess {
|
impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess {
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
ccx.tcx.sess,
|
ccx.tcx.sess,
|
||||||
span,
|
span,
|
||||||
|
@ -721,7 +807,11 @@ pub mod ty {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
feature_err(
|
feature_err(
|
||||||
&ccx.tcx.sess.parse_sess,
|
&ccx.tcx.sess.parse_sess,
|
||||||
sym::const_mut_refs,
|
sym::const_mut_refs,
|
||||||
|
@ -751,7 +841,11 @@ pub mod ty {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
feature_err(
|
feature_err(
|
||||||
&ccx.tcx.sess.parse_sess,
|
&ccx.tcx.sess.parse_sess,
|
||||||
sym::const_fn_fn_ptr_basics,
|
sym::const_fn_fn_ptr_basics,
|
||||||
|
@ -768,7 +862,11 @@ pub mod ty {
|
||||||
Status::Unstable(sym::const_impl_trait)
|
Status::Unstable(sym::const_impl_trait)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
feature_err(
|
feature_err(
|
||||||
&ccx.tcx.sess.parse_sess,
|
&ccx.tcx.sess.parse_sess,
|
||||||
sym::const_impl_trait,
|
sym::const_impl_trait,
|
||||||
|
@ -798,7 +896,11 @@ pub mod ty {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let mut err = feature_err(
|
let mut err = feature_err(
|
||||||
&ccx.tcx.sess.parse_sess,
|
&ccx.tcx.sess.parse_sess,
|
||||||
sym::const_fn_trait_bound,
|
sym::const_fn_trait_bound,
|
||||||
|
@ -837,7 +939,11 @@ pub mod ty {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let mut err = feature_err(
|
let mut err = feature_err(
|
||||||
&ccx.tcx.sess.parse_sess,
|
&ccx.tcx.sess.parse_sess,
|
||||||
sym::const_fn_trait_bound,
|
sym::const_fn_trait_bound,
|
||||||
|
@ -864,7 +970,11 @@ pub mod ty {
|
||||||
Status::Unstable(sym::const_trait_bound_opt_out)
|
Status::Unstable(sym::const_trait_bound_opt_out)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(
|
||||||
|
&self,
|
||||||
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
|
span: Span,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
feature_err(
|
feature_err(
|
||||||
&ccx.tcx.sess.parse_sess,
|
&ccx.tcx.sess.parse_sess,
|
||||||
sym::const_trait_bound_opt_out,
|
sym::const_trait_bound_opt_out,
|
||||||
|
|
|
@ -66,12 +66,14 @@ fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
|
||||||
/// Maps `Diagnostic::Level` to `snippet::AnnotationType`
|
/// Maps `Diagnostic::Level` to `snippet::AnnotationType`
|
||||||
fn annotation_type_for_level(level: Level) -> AnnotationType {
|
fn annotation_type_for_level(level: Level) -> AnnotationType {
|
||||||
match level {
|
match level {
|
||||||
Level::Bug | Level::Fatal | Level::Error { .. } => AnnotationType::Error,
|
Level::Bug | Level::DelayedBug | Level::Fatal | Level::Error { .. } => {
|
||||||
|
AnnotationType::Error
|
||||||
|
}
|
||||||
Level::Warning => AnnotationType::Warning,
|
Level::Warning => AnnotationType::Warning,
|
||||||
Level::Note => AnnotationType::Note,
|
Level::Note => AnnotationType::Note,
|
||||||
Level::Help => AnnotationType::Help,
|
Level::Help => AnnotationType::Help,
|
||||||
// FIXME(#59346): Not sure how to map these two levels
|
// FIXME(#59346): Not sure how to map this level
|
||||||
Level::Cancelled | Level::FailureNote => AnnotationType::Error,
|
Level::FailureNote => AnnotationType::Error,
|
||||||
Level::Allow => panic!("Should not call with Allow"),
|
Level::Allow => panic!("Should not call with Allow"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,10 @@ pub struct SuggestionsDisabled;
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[derive(Clone, Debug, Encodable, Decodable)]
|
#[derive(Clone, Debug, Encodable, Decodable)]
|
||||||
pub struct Diagnostic {
|
pub struct Diagnostic {
|
||||||
pub level: Level,
|
// NOTE(eddyb) this is private to disallow arbitrary after-the-fact changes,
|
||||||
|
// outside of what methods in this crate themselves allow.
|
||||||
|
crate level: Level,
|
||||||
|
|
||||||
pub message: Vec<(String, Style)>,
|
pub message: Vec<(String, Style)>,
|
||||||
pub code: Option<DiagnosticId>,
|
pub code: Option<DiagnosticId>,
|
||||||
pub span: MultiSpan,
|
pub span: MultiSpan,
|
||||||
|
@ -117,11 +120,20 @@ impl Diagnostic {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn level(&self) -> Level {
|
||||||
|
self.level
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_error(&self) -> bool {
|
pub fn is_error(&self) -> bool {
|
||||||
match self.level {
|
match self.level {
|
||||||
Level::Bug | Level::Fatal | Level::Error { .. } | Level::FailureNote => true,
|
Level::Bug
|
||||||
|
| Level::DelayedBug
|
||||||
|
| Level::Fatal
|
||||||
|
| Level::Error { .. }
|
||||||
|
| Level::FailureNote => true,
|
||||||
|
|
||||||
Level::Warning | Level::Note | Level::Help | Level::Cancelled | Level::Allow => false,
|
Level::Warning | Level::Note | Level::Help | Level::Allow => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,15 +151,26 @@ impl Diagnostic {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Cancel the diagnostic (a structured diagnostic must either be emitted or
|
/// Delay emission of this diagnostic as a bug.
|
||||||
/// canceled or it will panic when dropped).
|
///
|
||||||
pub fn cancel(&mut self) {
|
/// This can be useful in contexts where an error indicates a bug but
|
||||||
self.level = Level::Cancelled;
|
/// typically this only happens when other compilation errors have already
|
||||||
}
|
/// happened. In those cases this can be used to defer emission of this
|
||||||
|
/// diagnostic as a bug in the compiler only if no other errors have been
|
||||||
|
/// emitted.
|
||||||
|
///
|
||||||
|
/// In the meantime, though, callsites are required to deal with the "bug"
|
||||||
|
/// locally in whichever way makes the most sense.
|
||||||
|
#[track_caller]
|
||||||
|
pub fn downgrade_to_delayed_bug(&mut self) -> &mut Self {
|
||||||
|
assert!(
|
||||||
|
self.is_error(),
|
||||||
|
"downgrade_to_delayed_bug: cannot downgrade {:?} to DelayedBug: not an error",
|
||||||
|
self.level
|
||||||
|
);
|
||||||
|
self.level = Level::DelayedBug;
|
||||||
|
|
||||||
/// Check if this diagnostic [was cancelled][Self::cancel()].
|
self
|
||||||
pub fn cancelled(&self) -> bool {
|
|
||||||
self.level == Level::Cancelled
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a span/label to be included in the resulting snippet.
|
/// Adds a span/label to be included in the resulting snippet.
|
||||||
|
@ -163,6 +186,20 @@ impl Diagnostic {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Labels all the given spans with the provided label.
|
||||||
|
/// See [`Self::span_label()`] for more information.
|
||||||
|
pub fn span_labels(
|
||||||
|
&mut self,
|
||||||
|
spans: impl IntoIterator<Item = Span>,
|
||||||
|
label: impl AsRef<str>,
|
||||||
|
) -> &mut Self {
|
||||||
|
let label = label.as_ref();
|
||||||
|
for span in spans {
|
||||||
|
self.span_label(span, label);
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn replace_span_with(&mut self, after: Span) -> &mut Self {
|
pub fn replace_span_with(&mut self, after: Span) -> &mut Self {
|
||||||
let before = self.span.clone();
|
let before = self.span.clone();
|
||||||
self.set_span(after);
|
self.set_span(after);
|
||||||
|
@ -174,7 +211,7 @@ impl Diagnostic {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn note_expected_found(
|
pub fn note_expected_found(
|
||||||
&mut self,
|
&mut self,
|
||||||
expected_label: &dyn fmt::Display,
|
expected_label: &dyn fmt::Display,
|
||||||
expected: DiagnosticStyledString,
|
expected: DiagnosticStyledString,
|
||||||
|
@ -184,7 +221,7 @@ impl Diagnostic {
|
||||||
self.note_expected_found_extra(expected_label, expected, found_label, found, &"", &"")
|
self.note_expected_found_extra(expected_label, expected, found_label, found, &"", &"")
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn note_unsuccessful_coercion(
|
pub fn note_unsuccessful_coercion(
|
||||||
&mut self,
|
&mut self,
|
||||||
expected: DiagnosticStyledString,
|
expected: DiagnosticStyledString,
|
||||||
found: DiagnosticStyledString,
|
found: DiagnosticStyledString,
|
||||||
|
@ -274,33 +311,33 @@ impl Diagnostic {
|
||||||
|
|
||||||
/// Prints the span with a note above it.
|
/// Prints the span with a note above it.
|
||||||
/// This is like [`Diagnostic::note()`], but it gets its own span.
|
/// This is like [`Diagnostic::note()`], but it gets its own span.
|
||||||
crate fn span_note<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
|
pub fn span_note<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
|
||||||
self.sub(Level::Note, msg, sp.into(), None);
|
self.sub(Level::Note, msg, sp.into(), None);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a warning attached to this diagnostic.
|
/// Add a warning attached to this diagnostic.
|
||||||
crate fn warn(&mut self, msg: &str) -> &mut Self {
|
pub fn warn(&mut self, msg: &str) -> &mut Self {
|
||||||
self.sub(Level::Warning, msg, MultiSpan::new(), None);
|
self.sub(Level::Warning, msg, MultiSpan::new(), None);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints the span with a warning above it.
|
/// Prints the span with a warning above it.
|
||||||
/// This is like [`Diagnostic::warn()`], but it gets its own span.
|
/// This is like [`Diagnostic::warn()`], but it gets its own span.
|
||||||
crate fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
|
pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
|
||||||
self.sub(Level::Warning, msg, sp.into(), None);
|
self.sub(Level::Warning, msg, sp.into(), None);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a help message attached to this diagnostic.
|
/// Add a help message attached to this diagnostic.
|
||||||
crate fn help(&mut self, msg: &str) -> &mut Self {
|
pub fn help(&mut self, msg: &str) -> &mut Self {
|
||||||
self.sub(Level::Help, msg, MultiSpan::new(), None);
|
self.sub(Level::Help, msg, MultiSpan::new(), None);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints the span with some help above it.
|
/// Prints the span with some help above it.
|
||||||
/// This is like [`Diagnostic::help()`], but it gets its own span.
|
/// This is like [`Diagnostic::help()`], but it gets its own span.
|
||||||
crate fn span_help<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
|
pub fn span_help<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
|
||||||
self.sub(Level::Help, msg, sp.into(), None);
|
self.sub(Level::Help, msg, sp.into(), None);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -634,7 +671,7 @@ impl Diagnostic {
|
||||||
self.code.clone()
|
self.code.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn set_primary_message<M: Into<String>>(&mut self, msg: M) -> &mut Self {
|
pub fn set_primary_message<M: Into<String>>(&mut self, msg: M) -> &mut Self {
|
||||||
self.message[0] = (msg.into(), Style::NoStyle);
|
self.message[0] = (msg.into(), Style::NoStyle);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::{Diagnostic, DiagnosticId, DiagnosticStyledString};
|
use crate::{Diagnostic, DiagnosticId, DiagnosticStyledString, ErrorReported};
|
||||||
use crate::{Handler, Level, StashKey};
|
use crate::{Handler, Level, StashKey};
|
||||||
use rustc_lint_defs::Applicability;
|
use rustc_lint_defs::Applicability;
|
||||||
|
|
||||||
use rustc_span::{MultiSpan, Span};
|
use rustc_span::{MultiSpan, Span};
|
||||||
use std::fmt::{self, Debug};
|
use std::fmt::{self, Debug};
|
||||||
|
use std::marker::PhantomData;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::thread::panicking;
|
use std::thread::panicking;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
@ -15,8 +16,25 @@ use tracing::debug;
|
||||||
/// extending `HandlerFlags`, accessed via `self.handler.flags`.
|
/// extending `HandlerFlags`, accessed via `self.handler.flags`.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DiagnosticBuilder<'a> {
|
pub struct DiagnosticBuilder<'a, G: EmissionGuarantee> {
|
||||||
handler: &'a Handler,
|
inner: DiagnosticBuilderInner<'a>,
|
||||||
|
_marker: PhantomData<G>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This type exists only for `DiagnosticBuilder::forget_guarantee`, because it:
|
||||||
|
/// 1. lacks the `G` parameter and therefore `DiagnosticBuilder<G1>` can be
|
||||||
|
/// converted into `DiagnosticBuilder<G2>` while reusing the `inner` field
|
||||||
|
/// 2. can implement the `Drop` "bomb" instead of `DiagnosticBuilder`, as it
|
||||||
|
/// contains all of the data (`state` + `diagnostic`) of `DiagnosticBuilder`
|
||||||
|
///
|
||||||
|
/// The `diagnostic` field is not `Copy` and can't be moved out of whichever
|
||||||
|
/// type implements the `Drop` "bomb", but because of the above two facts, that
|
||||||
|
/// never needs to happen - instead, the whole `inner: DiagnosticBuilderInner`
|
||||||
|
/// can be moved out of a `DiagnosticBuilder` and into another.
|
||||||
|
#[must_use]
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct DiagnosticBuilderInner<'a> {
|
||||||
|
state: DiagnosticBuilderState<'a>,
|
||||||
|
|
||||||
/// `Diagnostic` is a large type, and `DiagnosticBuilder` is often used as a
|
/// `Diagnostic` is a large type, and `DiagnosticBuilder` is often used as a
|
||||||
/// return value, especially within the frequently-used `PResult` type.
|
/// return value, especially within the frequently-used `PResult` type.
|
||||||
|
@ -25,6 +43,161 @@ pub struct DiagnosticBuilder<'a> {
|
||||||
diagnostic: Box<Diagnostic>,
|
diagnostic: Box<Diagnostic>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
enum DiagnosticBuilderState<'a> {
|
||||||
|
/// Initial state of a `DiagnosticBuilder`, before `.emit()` or `.cancel()`.
|
||||||
|
///
|
||||||
|
/// The `Diagnostic` will be emitted through this `Handler`.
|
||||||
|
Emittable(&'a Handler),
|
||||||
|
|
||||||
|
/// State of a `DiagnosticBuilder`, after `.emit()` or *during* `.cancel()`.
|
||||||
|
///
|
||||||
|
/// The `Diagnostic` will be ignored when calling `.emit()`, and it can be
|
||||||
|
/// assumed that `.emit()` was previously called, to end up in this state.
|
||||||
|
///
|
||||||
|
/// While this is also used by `.cancel()`, this state is only observed by
|
||||||
|
/// the `Drop` `impl` of `DiagnosticBuilderInner`, as `.cancel()` takes
|
||||||
|
/// `self` by-value specifically to prevent any attempts to `.emit()`.
|
||||||
|
///
|
||||||
|
// FIXME(eddyb) currently this doesn't prevent extending the `Diagnostic`,
|
||||||
|
// despite that being potentially lossy, if important information is added
|
||||||
|
// *after* the original `.emit()` call.
|
||||||
|
AlreadyEmittedOrDuringCancellation,
|
||||||
|
}
|
||||||
|
|
||||||
|
// `DiagnosticBuilderState` should be pointer-sized.
|
||||||
|
rustc_data_structures::static_assert_size!(
|
||||||
|
DiagnosticBuilderState<'_>,
|
||||||
|
std::mem::size_of::<&Handler>()
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Trait for types that `DiagnosticBuilder::emit` can return as a "guarantee"
|
||||||
|
/// (or "proof") token that the emission happened.
|
||||||
|
pub trait EmissionGuarantee: Sized {
|
||||||
|
/// Implementation of `DiagnosticBuilder::emit`, fully controlled by each
|
||||||
|
/// `impl` of `EmissionGuarantee`, to make it impossible to create a value
|
||||||
|
/// of `Self` without actually performing the emission.
|
||||||
|
#[track_caller]
|
||||||
|
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Private module for sealing the `IsError` helper trait.
|
||||||
|
mod sealed_level_is_error {
|
||||||
|
use crate::Level;
|
||||||
|
|
||||||
|
/// Sealed helper trait for statically checking that a `Level` is an error.
|
||||||
|
crate trait IsError<const L: Level> {}
|
||||||
|
|
||||||
|
impl IsError<{ Level::Bug }> for () {}
|
||||||
|
impl IsError<{ Level::DelayedBug }> for () {}
|
||||||
|
impl IsError<{ Level::Fatal }> for () {}
|
||||||
|
// NOTE(eddyb) `Level::Error { lint: true }` is also an error, but lints
|
||||||
|
// don't need error guarantees, as their levels are always dynamic.
|
||||||
|
impl IsError<{ Level::Error { lint: false } }> for () {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
|
/// Convenience function for internal use, clients should use one of the
|
||||||
|
/// `struct_*` methods on [`Handler`].
|
||||||
|
crate fn new_guaranteeing_error<const L: Level>(handler: &'a Handler, message: &str) -> Self
|
||||||
|
where
|
||||||
|
(): sealed_level_is_error::IsError<L>,
|
||||||
|
{
|
||||||
|
Self {
|
||||||
|
inner: DiagnosticBuilderInner {
|
||||||
|
state: DiagnosticBuilderState::Emittable(handler),
|
||||||
|
diagnostic: Box::new(Diagnostic::new_with_code(L, None, message)),
|
||||||
|
},
|
||||||
|
_marker: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Discard the guarantee `.emit()` would return, in favor of having the
|
||||||
|
/// type `DiagnosticBuilder<'a, ()>`. This may be necessary whenever there
|
||||||
|
/// is a common codepath handling both errors and warnings.
|
||||||
|
pub fn forget_guarantee(self) -> DiagnosticBuilder<'a, ()> {
|
||||||
|
DiagnosticBuilder { inner: self.inner, _marker: PhantomData }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME(eddyb) make `ErrorReported` impossible to create outside `.emit()`.
|
||||||
|
impl EmissionGuarantee for ErrorReported {
|
||||||
|
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
|
||||||
|
match db.inner.state {
|
||||||
|
// First `.emit()` call, the `&Handler` is still available.
|
||||||
|
DiagnosticBuilderState::Emittable(handler) => {
|
||||||
|
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
||||||
|
|
||||||
|
handler.emit_diagnostic(&db.inner.diagnostic);
|
||||||
|
|
||||||
|
// Only allow a guarantee if the `level` wasn't switched to a
|
||||||
|
// non-error - the field isn't `pub`, but the whole `Diagnostic`
|
||||||
|
// can be overwritten with a new one, thanks to `DerefMut`.
|
||||||
|
assert!(
|
||||||
|
db.inner.diagnostic.is_error(),
|
||||||
|
"emitted non-error ({:?}) diagnostic \
|
||||||
|
from `DiagnosticBuilder<ErrorReported>`",
|
||||||
|
db.inner.diagnostic.level,
|
||||||
|
);
|
||||||
|
ErrorReported
|
||||||
|
}
|
||||||
|
// `.emit()` was previously called, disallowed from repeating it,
|
||||||
|
// but can take advantage of the previous `.emit()`'s guarantee
|
||||||
|
// still being applicable (i.e. as a form of idempotency).
|
||||||
|
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {
|
||||||
|
// Only allow a guarantee if the `level` wasn't switched to a
|
||||||
|
// non-error - the field isn't `pub`, but the whole `Diagnostic`
|
||||||
|
// can be overwritten with a new one, thanks to `DerefMut`.
|
||||||
|
assert!(
|
||||||
|
db.inner.diagnostic.is_error(),
|
||||||
|
"`DiagnosticBuilder<ErrorReported>`'s diagnostic \
|
||||||
|
became non-error ({:?}), after original `.emit()`",
|
||||||
|
db.inner.diagnostic.level,
|
||||||
|
);
|
||||||
|
ErrorReported
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> DiagnosticBuilder<'a, ()> {
|
||||||
|
/// Convenience function for internal use, clients should use one of the
|
||||||
|
/// `struct_*` methods on [`Handler`].
|
||||||
|
crate fn new(handler: &'a Handler, level: Level, message: &str) -> Self {
|
||||||
|
let diagnostic = Diagnostic::new_with_code(level, None, message);
|
||||||
|
Self::new_diagnostic(handler, diagnostic)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new `DiagnosticBuilder` with an already constructed
|
||||||
|
/// diagnostic.
|
||||||
|
crate fn new_diagnostic(handler: &'a Handler, diagnostic: Diagnostic) -> Self {
|
||||||
|
debug!("Created new diagnostic");
|
||||||
|
Self {
|
||||||
|
inner: DiagnosticBuilderInner {
|
||||||
|
state: DiagnosticBuilderState::Emittable(handler),
|
||||||
|
diagnostic: Box::new(diagnostic),
|
||||||
|
},
|
||||||
|
_marker: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME(eddyb) should there be a `Option<ErrorReported>` impl as well?
|
||||||
|
impl EmissionGuarantee for () {
|
||||||
|
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
|
||||||
|
match db.inner.state {
|
||||||
|
// First `.emit()` call, the `&Handler` is still available.
|
||||||
|
DiagnosticBuilderState::Emittable(handler) => {
|
||||||
|
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
||||||
|
|
||||||
|
handler.emit_diagnostic(&db.inner.diagnostic);
|
||||||
|
}
|
||||||
|
// `.emit()` was previously called, disallowed from repeating it.
|
||||||
|
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// In general, the `DiagnosticBuilder` uses deref to allow access to
|
/// In general, the `DiagnosticBuilder` uses deref to allow access to
|
||||||
/// the fields and methods of the embedded `diagnostic` in a
|
/// the fields and methods of the embedded `diagnostic` in a
|
||||||
/// transparent way. *However,* many of the methods are intended to
|
/// transparent way. *However,* many of the methods are intended to
|
||||||
|
@ -55,60 +228,54 @@ macro_rules! forward {
|
||||||
$(#[$attrs])*
|
$(#[$attrs])*
|
||||||
#[doc = concat!("See [`Diagnostic::", stringify!($n), "()`].")]
|
#[doc = concat!("See [`Diagnostic::", stringify!($n), "()`].")]
|
||||||
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
|
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
|
||||||
self.diagnostic.$n($($name),*);
|
self.inner.diagnostic.$n($($name),*);
|
||||||
self
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Forward pattern for &mut self -> &mut Self, with generic parameters.
|
|
||||||
(
|
|
||||||
$(#[$attrs:meta])*
|
|
||||||
pub fn $n:ident<$($generic:ident: $bound:path),*>(
|
|
||||||
&mut self,
|
|
||||||
$($name:ident: $ty:ty),*
|
|
||||||
$(,)?
|
|
||||||
) -> &mut Self
|
|
||||||
) => {
|
|
||||||
$(#[$attrs])*
|
|
||||||
#[doc = concat!("See [`Diagnostic::", stringify!($n), "()`].")]
|
|
||||||
pub fn $n<$($generic: $bound),*>(&mut self, $($name: $ty),*) -> &mut Self {
|
|
||||||
self.diagnostic.$n($($name),*);
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Deref for DiagnosticBuilder<'a> {
|
impl<G: EmissionGuarantee> Deref for DiagnosticBuilder<'_, G> {
|
||||||
type Target = Diagnostic;
|
type Target = Diagnostic;
|
||||||
|
|
||||||
fn deref(&self) -> &Diagnostic {
|
fn deref(&self) -> &Diagnostic {
|
||||||
&self.diagnostic
|
&self.inner.diagnostic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DerefMut for DiagnosticBuilder<'a> {
|
impl<G: EmissionGuarantee> DerefMut for DiagnosticBuilder<'_, G> {
|
||||||
fn deref_mut(&mut self) -> &mut Diagnostic {
|
fn deref_mut(&mut self) -> &mut Diagnostic {
|
||||||
&mut self.diagnostic
|
&mut self.inner.diagnostic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DiagnosticBuilder<'a> {
|
impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||||
/// Emit the diagnostic.
|
/// Emit the diagnostic.
|
||||||
pub fn emit(&mut self) {
|
#[track_caller]
|
||||||
self.handler.emit_diagnostic(&self);
|
pub fn emit(&mut self) -> G {
|
||||||
self.cancel();
|
G::diagnostic_builder_emit_producing_guarantee(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Emit the diagnostic unless `delay` is true,
|
/// Emit the diagnostic unless `delay` is true,
|
||||||
/// in which case the emission will be delayed as a bug.
|
/// in which case the emission will be delayed as a bug.
|
||||||
///
|
///
|
||||||
/// See `emit` and `delay_as_bug` for details.
|
/// See `emit` and `delay_as_bug` for details.
|
||||||
pub fn emit_unless(&mut self, delay: bool) {
|
#[track_caller]
|
||||||
|
pub fn emit_unless(&mut self, delay: bool) -> G {
|
||||||
if delay {
|
if delay {
|
||||||
self.delay_as_bug();
|
self.downgrade_to_delayed_bug();
|
||||||
} else {
|
|
||||||
self.emit();
|
|
||||||
}
|
}
|
||||||
|
self.emit()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cancel the diagnostic (a structured diagnostic must either be emitted or
|
||||||
|
/// cancelled or it will panic when dropped).
|
||||||
|
///
|
||||||
|
/// This method takes `self` by-value to disallow calling `.emit()` on it,
|
||||||
|
/// which may be expected to *guarantee* the emission of an error, either
|
||||||
|
/// at the time of the call, or through a prior `.emit()` call.
|
||||||
|
pub fn cancel(mut self) {
|
||||||
|
self.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
||||||
|
drop(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stashes diagnostic for possible later improvement in a different,
|
/// Stashes diagnostic for possible later improvement in a different,
|
||||||
|
@ -123,21 +290,28 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the builder to a `Diagnostic` for later emission,
|
/// Converts the builder to a `Diagnostic` for later emission,
|
||||||
/// unless handler has disabled such buffering.
|
/// unless handler has disabled such buffering, or `.emit()` was called.
|
||||||
pub fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a Handler)> {
|
pub fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a Handler)> {
|
||||||
if self.handler.flags.dont_buffer_diagnostics
|
let handler = match self.inner.state {
|
||||||
|| self.handler.flags.treat_err_as_bug.is_some()
|
// No `.emit()` calls, the `&Handler` is still available.
|
||||||
{
|
DiagnosticBuilderState::Emittable(handler) => handler,
|
||||||
|
// `.emit()` was previously called, nothing we can do.
|
||||||
|
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if handler.flags.dont_buffer_diagnostics || handler.flags.treat_err_as_bug.is_some() {
|
||||||
self.emit();
|
self.emit();
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let handler = self.handler;
|
// Take the `Diagnostic` by replacing it with a dummy.
|
||||||
|
let dummy = Diagnostic::new(Level::Allow, "");
|
||||||
|
let diagnostic = std::mem::replace(&mut *self.inner.diagnostic, dummy);
|
||||||
|
|
||||||
// We must use `Level::Cancelled` for `dummy` to avoid an ICE about an
|
// Disable the ICE on `Drop`.
|
||||||
// unused diagnostic.
|
self.cancel();
|
||||||
let dummy = Diagnostic::new(Level::Cancelled, "");
|
|
||||||
let diagnostic = std::mem::replace(&mut *self.diagnostic, dummy);
|
|
||||||
|
|
||||||
// Logging here is useful to help track down where in logs an error was
|
// Logging here is useful to help track down where in logs an error was
|
||||||
// actually emitted.
|
// actually emitted.
|
||||||
|
@ -162,12 +336,18 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||||
///
|
///
|
||||||
/// In the meantime, though, callsites are required to deal with the "bug"
|
/// In the meantime, though, callsites are required to deal with the "bug"
|
||||||
/// locally in whichever way makes the most sense.
|
/// locally in whichever way makes the most sense.
|
||||||
|
#[track_caller]
|
||||||
pub fn delay_as_bug(&mut self) {
|
pub fn delay_as_bug(&mut self) {
|
||||||
self.level = Level::Bug;
|
self.downgrade_to_delayed_bug();
|
||||||
self.handler.delay_as_bug((*self.diagnostic).clone());
|
self.emit();
|
||||||
self.cancel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
forward!(
|
||||||
|
#[track_caller]
|
||||||
|
pub fn downgrade_to_delayed_bug(&mut self,) -> &mut Self
|
||||||
|
);
|
||||||
|
|
||||||
|
forward!(
|
||||||
/// Appends a labeled span to the diagnostic.
|
/// Appends a labeled span to the diagnostic.
|
||||||
///
|
///
|
||||||
/// Labels are used to convey additional context for the diagnostic's primary span. They will
|
/// Labels are used to convey additional context for the diagnostic's primary span. They will
|
||||||
|
@ -180,24 +360,16 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||||
/// the diagnostic was constructed. However, the label span is *not* considered a
|
/// the diagnostic was constructed. However, the label span is *not* considered a
|
||||||
/// ["primary span"][`MultiSpan`]; only the `Span` supplied when creating the diagnostic is
|
/// ["primary span"][`MultiSpan`]; only the `Span` supplied when creating the diagnostic is
|
||||||
/// primary.
|
/// primary.
|
||||||
pub fn span_label(&mut self, span: Span, label: impl Into<String>) -> &mut Self {
|
pub fn span_label(&mut self, span: Span, label: impl Into<String>) -> &mut Self);
|
||||||
self.diagnostic.span_label(span, label);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
|
forward!(
|
||||||
/// Labels all the given spans with the provided label.
|
/// Labels all the given spans with the provided label.
|
||||||
/// See [`Diagnostic::span_label()`] for more information.
|
/// See [`Diagnostic::span_label()`] for more information.
|
||||||
pub fn span_labels(
|
pub fn span_labels(
|
||||||
&mut self,
|
&mut self,
|
||||||
spans: impl IntoIterator<Item = Span>,
|
spans: impl IntoIterator<Item = Span>,
|
||||||
label: impl AsRef<str>,
|
label: impl AsRef<str>,
|
||||||
) -> &mut Self {
|
) -> &mut Self);
|
||||||
let label = label.as_ref();
|
|
||||||
for span in spans {
|
|
||||||
self.diagnostic.span_label(span, label);
|
|
||||||
}
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
forward!(pub fn note_expected_found(
|
forward!(pub fn note_expected_found(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -224,17 +396,17 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||||
) -> &mut Self);
|
) -> &mut Self);
|
||||||
|
|
||||||
forward!(pub fn note(&mut self, msg: &str) -> &mut Self);
|
forward!(pub fn note(&mut self, msg: &str) -> &mut Self);
|
||||||
forward!(pub fn span_note<S: Into<MultiSpan>>(
|
forward!(pub fn span_note(
|
||||||
&mut self,
|
&mut self,
|
||||||
sp: S,
|
sp: impl Into<MultiSpan>,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
) -> &mut Self);
|
) -> &mut Self);
|
||||||
forward!(pub fn warn(&mut self, msg: &str) -> &mut Self);
|
forward!(pub fn warn(&mut self, msg: &str) -> &mut Self);
|
||||||
forward!(pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self);
|
forward!(pub fn span_warn(&mut self, sp: impl Into<MultiSpan>, msg: &str) -> &mut Self);
|
||||||
forward!(pub fn help(&mut self, msg: &str) -> &mut Self);
|
forward!(pub fn help(&mut self, msg: &str) -> &mut Self);
|
||||||
forward!(pub fn span_help<S: Into<MultiSpan>>(
|
forward!(pub fn span_help(
|
||||||
&mut self,
|
&mut self,
|
||||||
sp: S,
|
sp: impl Into<MultiSpan>,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
) -> &mut Self);
|
) -> &mut Self);
|
||||||
forward!(pub fn set_is_lint(&mut self,) -> &mut Self);
|
forward!(pub fn set_is_lint(&mut self,) -> &mut Self);
|
||||||
|
@ -308,57 +480,37 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||||
applicability: Applicability,
|
applicability: Applicability,
|
||||||
) -> &mut Self);
|
) -> &mut Self);
|
||||||
|
|
||||||
forward!(pub fn set_primary_message<M: Into<String>>(&mut self, msg: M) -> &mut Self);
|
forward!(pub fn set_primary_message(&mut self, msg: impl Into<String>) -> &mut Self);
|
||||||
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self);
|
forward!(pub fn set_span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self);
|
||||||
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
|
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
|
||||||
|
|
||||||
/// Convenience function for internal use, clients should use one of the
|
|
||||||
/// `struct_*` methods on [`Handler`].
|
|
||||||
crate fn new(handler: &'a Handler, level: Level, message: &str) -> DiagnosticBuilder<'a> {
|
|
||||||
DiagnosticBuilder::new_with_code(handler, level, None, message)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience function for internal use, clients should use one of the
|
impl<G: EmissionGuarantee> Debug for DiagnosticBuilder<'_, G> {
|
||||||
/// `struct_*` methods on [`Handler`].
|
|
||||||
crate fn new_with_code(
|
|
||||||
handler: &'a Handler,
|
|
||||||
level: Level,
|
|
||||||
code: Option<DiagnosticId>,
|
|
||||||
message: &str,
|
|
||||||
) -> DiagnosticBuilder<'a> {
|
|
||||||
let diagnostic = Diagnostic::new_with_code(level, code, message);
|
|
||||||
DiagnosticBuilder::new_diagnostic(handler, diagnostic)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new `DiagnosticBuilder` with an already constructed
|
|
||||||
/// diagnostic.
|
|
||||||
crate fn new_diagnostic(handler: &'a Handler, diagnostic: Diagnostic) -> DiagnosticBuilder<'a> {
|
|
||||||
debug!("Created new diagnostic");
|
|
||||||
DiagnosticBuilder { handler, diagnostic: Box::new(diagnostic) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Debug for DiagnosticBuilder<'a> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
self.diagnostic.fmt(f)
|
self.inner.diagnostic.fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructor bomb - a `DiagnosticBuilder` must be either emitted or canceled
|
/// Destructor bomb - a `DiagnosticBuilder` must be either emitted or cancelled
|
||||||
/// or we emit a bug.
|
/// or we emit a bug.
|
||||||
impl<'a> Drop for DiagnosticBuilder<'a> {
|
impl Drop for DiagnosticBuilderInner<'_> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if !panicking() && !self.cancelled() {
|
match self.state {
|
||||||
let mut db = DiagnosticBuilder::new(
|
// No `.emit()` or `.cancel()` calls.
|
||||||
self.handler,
|
DiagnosticBuilderState::Emittable(handler) => {
|
||||||
|
if !panicking() {
|
||||||
|
handler.emit_diagnostic(&Diagnostic::new(
|
||||||
Level::Bug,
|
Level::Bug,
|
||||||
"the following error was constructed but not emitted",
|
"the following error was constructed but not emitted",
|
||||||
);
|
));
|
||||||
db.emit();
|
handler.emit_diagnostic(&self.diagnostic);
|
||||||
self.emit();
|
|
||||||
panic!();
|
panic!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// `.emit()` was previously called, or maybe we're during `.cancel()`.
|
||||||
|
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#![feature(let_else)]
|
#![feature(let_else)]
|
||||||
#![feature(nll)]
|
#![feature(nll)]
|
||||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||||
|
#![feature(adt_const_params)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rustc_macros;
|
extern crate rustc_macros;
|
||||||
|
@ -52,7 +54,7 @@ mod snippet;
|
||||||
mod styled_buffer;
|
mod styled_buffer;
|
||||||
pub use snippet::Style;
|
pub use snippet::Style;
|
||||||
|
|
||||||
pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a>>;
|
pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a, ErrorReported>>;
|
||||||
|
|
||||||
// `PResult` is used a lot. Make sure it doesn't unintentionally get bigger.
|
// `PResult` is used a lot. Make sure it doesn't unintentionally get bigger.
|
||||||
// (See also the comment on `DiagnosticBuilder`'s `diagnostic` field.)
|
// (See also the comment on `DiagnosticBuilder`'s `diagnostic` field.)
|
||||||
|
@ -491,10 +493,15 @@ impl Drop for HandlerInner {
|
||||||
self.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued");
|
self.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(eddyb) this explains what `delayed_good_path_bugs` are!
|
||||||
|
// They're `delayed_span_bugs` but for "require some diagnostic happened"
|
||||||
|
// instead of "require some error happened". Sadly that isn't ideal, as
|
||||||
|
// lints can be `#[allow]`'d, potentially leading to this triggering.
|
||||||
|
// Also, "good path" should be replaced with a better naming.
|
||||||
if !self.has_any_message() {
|
if !self.has_any_message() {
|
||||||
let bugs = std::mem::replace(&mut self.delayed_good_path_bugs, Vec::new());
|
let bugs = std::mem::replace(&mut self.delayed_good_path_bugs, Vec::new());
|
||||||
self.flush_delayed(
|
self.flush_delayed(
|
||||||
bugs.into_iter().map(DelayedDiagnostic::decorate).collect(),
|
bugs.into_iter().map(DelayedDiagnostic::decorate),
|
||||||
"no warnings or errors encountered even though `delayed_good_path_bugs` issued",
|
"no warnings or errors encountered even though `delayed_good_path_bugs` issued",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -604,7 +611,7 @@ impl Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Steal a previously stashed diagnostic with the given `Span` and `StashKey` as the key.
|
/// Steal a previously stashed diagnostic with the given `Span` and `StashKey` as the key.
|
||||||
pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option<DiagnosticBuilder<'_>> {
|
pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option<DiagnosticBuilder<'_, ()>> {
|
||||||
self.inner
|
self.inner
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.stashed_diagnostics
|
.stashed_diagnostics
|
||||||
|
@ -617,33 +624,17 @@ impl Handler {
|
||||||
self.inner.borrow_mut().emit_stashed_diagnostics();
|
self.inner.borrow_mut().emit_stashed_diagnostics();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a dummy builder with `Level::Cancelled`.
|
|
||||||
///
|
|
||||||
/// Using this will neither report anything to the user (e.g. a warning),
|
|
||||||
/// nor will compilation cancel as a result.
|
|
||||||
pub fn struct_dummy(&self) -> DiagnosticBuilder<'_> {
|
|
||||||
DiagnosticBuilder::new(self, Level::Cancelled, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
|
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
|
||||||
///
|
///
|
||||||
/// The builder will be canceled if warnings cannot be emitted.
|
/// Attempting to `.emit()` the builder will only emit if either:
|
||||||
pub fn struct_span_warn(&self, span: impl Into<MultiSpan>, msg: &str) -> DiagnosticBuilder<'_> {
|
/// * `can_emit_warnings` is `true`
|
||||||
let mut result = self.struct_warn(msg);
|
/// * `is_force_warn` was set in `DiagnosticId::Lint`
|
||||||
result.set_span(span);
|
pub fn struct_span_warn(
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
|
|
||||||
///
|
|
||||||
/// This will "force" the warning meaning it will not be canceled even
|
|
||||||
/// if warnings cannot be emitted.
|
|
||||||
pub fn struct_span_force_warn(
|
|
||||||
&self,
|
&self,
|
||||||
span: impl Into<MultiSpan>,
|
span: impl Into<MultiSpan>,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
) -> DiagnosticBuilder<'_> {
|
) -> DiagnosticBuilder<'_, ()> {
|
||||||
let mut result = self.struct_force_warn(msg);
|
let mut result = self.struct_warn(msg);
|
||||||
result.set_span(span);
|
result.set_span(span);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -653,7 +644,7 @@ impl Handler {
|
||||||
&self,
|
&self,
|
||||||
span: impl Into<MultiSpan>,
|
span: impl Into<MultiSpan>,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
) -> DiagnosticBuilder<'_> {
|
) -> DiagnosticBuilder<'_, ()> {
|
||||||
let mut result = self.struct_allow(msg);
|
let mut result = self.struct_allow(msg);
|
||||||
result.set_span(span);
|
result.set_span(span);
|
||||||
result
|
result
|
||||||
|
@ -666,7 +657,7 @@ impl Handler {
|
||||||
span: impl Into<MultiSpan>,
|
span: impl Into<MultiSpan>,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
code: DiagnosticId,
|
code: DiagnosticId,
|
||||||
) -> DiagnosticBuilder<'_> {
|
) -> DiagnosticBuilder<'_, ()> {
|
||||||
let mut result = self.struct_span_warn(span, msg);
|
let mut result = self.struct_span_warn(span, msg);
|
||||||
result.code(code);
|
result.code(code);
|
||||||
result
|
result
|
||||||
|
@ -674,30 +665,24 @@ impl Handler {
|
||||||
|
|
||||||
/// Construct a builder at the `Warning` level with the `msg`.
|
/// Construct a builder at the `Warning` level with the `msg`.
|
||||||
///
|
///
|
||||||
/// The builder will be canceled if warnings cannot be emitted.
|
/// Attempting to `.emit()` the builder will only emit if either:
|
||||||
pub fn struct_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
/// * `can_emit_warnings` is `true`
|
||||||
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
|
/// * `is_force_warn` was set in `DiagnosticId::Lint`
|
||||||
if !self.flags.can_emit_warnings {
|
pub fn struct_warn(&self, msg: &str) -> DiagnosticBuilder<'_, ()> {
|
||||||
result.cancel();
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Construct a builder at the `Warning` level with the `msg`.
|
|
||||||
///
|
|
||||||
/// This will "force" a warning meaning it will not be canceled even
|
|
||||||
/// if warnings cannot be emitted.
|
|
||||||
pub fn struct_force_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
|
||||||
DiagnosticBuilder::new(self, Level::Warning, msg)
|
DiagnosticBuilder::new(self, Level::Warning, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a builder at the `Allow` level with the `msg`.
|
/// Construct a builder at the `Allow` level with the `msg`.
|
||||||
pub fn struct_allow(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_allow(&self, msg: &str) -> DiagnosticBuilder<'_, ()> {
|
||||||
DiagnosticBuilder::new(self, Level::Allow, msg)
|
DiagnosticBuilder::new(self, Level::Allow, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a builder at the `Error` level at the given `span` and with the `msg`.
|
/// Construct a builder at the `Error` level at the given `span` and with the `msg`.
|
||||||
pub fn struct_span_err(&self, span: impl Into<MultiSpan>, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_span_err(
|
||||||
|
&self,
|
||||||
|
span: impl Into<MultiSpan>,
|
||||||
|
msg: &str,
|
||||||
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
let mut result = self.struct_err(msg);
|
let mut result = self.struct_err(msg);
|
||||||
result.set_span(span);
|
result.set_span(span);
|
||||||
result
|
result
|
||||||
|
@ -709,7 +694,7 @@ impl Handler {
|
||||||
span: impl Into<MultiSpan>,
|
span: impl Into<MultiSpan>,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
code: DiagnosticId,
|
code: DiagnosticId,
|
||||||
) -> DiagnosticBuilder<'_> {
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
let mut result = self.struct_span_err(span, msg);
|
let mut result = self.struct_span_err(span, msg);
|
||||||
result.code(code);
|
result.code(code);
|
||||||
result
|
result
|
||||||
|
@ -717,18 +702,22 @@ impl Handler {
|
||||||
|
|
||||||
/// Construct a builder at the `Error` level with the `msg`.
|
/// Construct a builder at the `Error` level with the `msg`.
|
||||||
// FIXME: This method should be removed (every error should have an associated error code).
|
// FIXME: This method should be removed (every error should have an associated error code).
|
||||||
pub fn struct_err(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_err(&self, msg: &str) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
DiagnosticBuilder::new(self, Level::Error { lint: false }, msg)
|
DiagnosticBuilder::new_guaranteeing_error::<{ Level::Error { lint: false } }>(self, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This should only be used by `rustc_middle::lint::struct_lint_level`. Do not use it for hard errors.
|
/// This should only be used by `rustc_middle::lint::struct_lint_level`. Do not use it for hard errors.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn struct_err_lint(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_err_lint(&self, msg: &str) -> DiagnosticBuilder<'_, ()> {
|
||||||
DiagnosticBuilder::new(self, Level::Error { lint: true }, msg)
|
DiagnosticBuilder::new(self, Level::Error { lint: true }, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a builder at the `Error` level with the `msg` and the `code`.
|
/// Construct a builder at the `Error` level with the `msg` and the `code`.
|
||||||
pub fn struct_err_with_code(&self, msg: &str, code: DiagnosticId) -> DiagnosticBuilder<'_> {
|
pub fn struct_err_with_code(
|
||||||
|
&self,
|
||||||
|
msg: &str,
|
||||||
|
code: DiagnosticId,
|
||||||
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
let mut result = self.struct_err(msg);
|
let mut result = self.struct_err(msg);
|
||||||
result.code(code);
|
result.code(code);
|
||||||
result
|
result
|
||||||
|
@ -739,7 +728,7 @@ impl Handler {
|
||||||
&self,
|
&self,
|
||||||
span: impl Into<MultiSpan>,
|
span: impl Into<MultiSpan>,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
) -> DiagnosticBuilder<'_> {
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
let mut result = self.struct_fatal(msg);
|
let mut result = self.struct_fatal(msg);
|
||||||
result.set_span(span);
|
result.set_span(span);
|
||||||
result
|
result
|
||||||
|
@ -751,24 +740,24 @@ impl Handler {
|
||||||
span: impl Into<MultiSpan>,
|
span: impl Into<MultiSpan>,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
code: DiagnosticId,
|
code: DiagnosticId,
|
||||||
) -> DiagnosticBuilder<'_> {
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
let mut result = self.struct_span_fatal(span, msg);
|
let mut result = self.struct_span_fatal(span, msg);
|
||||||
result.code(code);
|
result.code(code);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a builder at the `Error` level with the `msg`.
|
/// Construct a builder at the `Error` level with the `msg`.
|
||||||
pub fn struct_fatal(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_fatal(&self, msg: &str) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
DiagnosticBuilder::new(self, Level::Fatal, msg)
|
DiagnosticBuilder::new_guaranteeing_error::<{ Level::Fatal }>(self, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a builder at the `Help` level with the `msg`.
|
/// Construct a builder at the `Help` level with the `msg`.
|
||||||
pub fn struct_help(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_help(&self, msg: &str) -> DiagnosticBuilder<'_, ()> {
|
||||||
DiagnosticBuilder::new(self, Level::Help, msg)
|
DiagnosticBuilder::new(self, Level::Help, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a builder at the `Note` level with the `msg`.
|
/// Construct a builder at the `Note` level with the `msg`.
|
||||||
pub fn struct_note_without_error(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_note_without_error(&self, msg: &str) -> DiagnosticBuilder<'_, ()> {
|
||||||
DiagnosticBuilder::new(self, Level::Note, msg)
|
DiagnosticBuilder::new(self, Level::Note, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -815,6 +804,8 @@ impl Handler {
|
||||||
self.inner.borrow_mut().delay_span_bug(span, msg)
|
self.inner.borrow_mut().delay_span_bug(span, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(eddyb) note the comment inside `impl Drop for HandlerInner`, that's
|
||||||
|
// where the explanation of what "good path" is (also, it should be renamed).
|
||||||
pub fn delay_good_path_bug(&self, msg: &str) {
|
pub fn delay_good_path_bug(&self, msg: &str) {
|
||||||
self.inner.borrow_mut().delay_good_path_bug(msg)
|
self.inner.borrow_mut().delay_good_path_bug(msg)
|
||||||
}
|
}
|
||||||
|
@ -827,7 +818,7 @@ impl Handler {
|
||||||
self.emit_diag_at_span(Diagnostic::new(Note, msg), span);
|
self.emit_diag_at_span(Diagnostic::new(Note, msg), span);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn span_note_diag(&self, span: Span, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn span_note_diag(&self, span: Span, msg: &str) -> DiagnosticBuilder<'_, ()> {
|
||||||
let mut db = DiagnosticBuilder::new(self, Note, msg);
|
let mut db = DiagnosticBuilder::new(self, Note, msg);
|
||||||
db.set_span(span);
|
db.set_span(span);
|
||||||
db
|
db
|
||||||
|
@ -915,10 +906,6 @@ impl Handler {
|
||||||
pub fn emit_unused_externs(&self, lint_level: &str, unused_externs: &[&str]) {
|
pub fn emit_unused_externs(&self, lint_level: &str, unused_externs: &[&str]) {
|
||||||
self.inner.borrow_mut().emit_unused_externs(lint_level, unused_externs)
|
self.inner.borrow_mut().emit_unused_externs(lint_level, unused_externs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delay_as_bug(&self, diagnostic: Diagnostic) {
|
|
||||||
self.inner.borrow_mut().delay_as_bug(diagnostic)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HandlerInner {
|
impl HandlerInner {
|
||||||
|
@ -936,10 +923,19 @@ impl HandlerInner {
|
||||||
diags.iter().for_each(|diag| self.emit_diagnostic(diag));
|
diags.iter().for_each(|diag| self.emit_diagnostic(diag));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(eddyb) this should ideally take `diagnostic` by value.
|
||||||
fn emit_diagnostic(&mut self, diagnostic: &Diagnostic) {
|
fn emit_diagnostic(&mut self, diagnostic: &Diagnostic) {
|
||||||
if diagnostic.cancelled() {
|
if diagnostic.level == Level::DelayedBug {
|
||||||
|
// FIXME(eddyb) this should check for `has_errors` and stop pushing
|
||||||
|
// once *any* errors were emitted (and truncate `delayed_span_bugs`
|
||||||
|
// when an error is first emitted, also), but maybe there's a case
|
||||||
|
// in which that's not sound? otherwise this is really inefficient.
|
||||||
|
self.delayed_span_bugs.push(diagnostic.clone());
|
||||||
|
|
||||||
|
if !self.flags.report_delayed_bugs {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if diagnostic.has_future_breakage() {
|
if diagnostic.has_future_breakage() {
|
||||||
self.future_breakage_diagnostics.push(diagnostic.clone());
|
self.future_breakage_diagnostics.push(diagnostic.clone());
|
||||||
|
@ -1119,14 +1115,16 @@ impl HandlerInner {
|
||||||
// FIXME: don't abort here if report_delayed_bugs is off
|
// FIXME: don't abort here if report_delayed_bugs is off
|
||||||
self.span_bug(sp, msg);
|
self.span_bug(sp, msg);
|
||||||
}
|
}
|
||||||
let mut diagnostic = Diagnostic::new(Level::Bug, msg);
|
let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg);
|
||||||
diagnostic.set_span(sp.into());
|
diagnostic.set_span(sp.into());
|
||||||
diagnostic.note(&format!("delayed at {}", std::panic::Location::caller()));
|
diagnostic.note(&format!("delayed at {}", std::panic::Location::caller()));
|
||||||
self.delay_as_bug(diagnostic)
|
self.emit_diagnostic(&diagnostic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(eddyb) note the comment inside `impl Drop for HandlerInner`, that's
|
||||||
|
// where the explanation of what "good path" is (also, it should be renamed).
|
||||||
fn delay_good_path_bug(&mut self, msg: &str) {
|
fn delay_good_path_bug(&mut self, msg: &str) {
|
||||||
let diagnostic = Diagnostic::new(Level::Bug, msg);
|
let diagnostic = Diagnostic::new(Level::DelayedBug, msg);
|
||||||
if self.flags.report_delayed_bugs {
|
if self.flags.report_delayed_bugs {
|
||||||
self.emit_diagnostic(&diagnostic);
|
self.emit_diagnostic(&diagnostic);
|
||||||
}
|
}
|
||||||
|
@ -1160,20 +1158,34 @@ impl HandlerInner {
|
||||||
panic::panic_any(ExplicitBug);
|
panic::panic_any(ExplicitBug);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delay_as_bug(&mut self, diagnostic: Diagnostic) {
|
fn flush_delayed(&mut self, bugs: impl IntoIterator<Item = Diagnostic>, explanation: &str) {
|
||||||
if self.flags.report_delayed_bugs {
|
let mut no_bugs = true;
|
||||||
self.emit_diagnostic(&diagnostic);
|
for mut bug in bugs {
|
||||||
}
|
if no_bugs {
|
||||||
self.delayed_span_bugs.push(diagnostic);
|
// Put the overall explanation before the `DelayedBug`s, to
|
||||||
|
// frame them better (e.g. separate warnings from them).
|
||||||
|
self.emit_diagnostic(&Diagnostic::new(Bug, explanation));
|
||||||
|
no_bugs = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush_delayed(&mut self, bugs: Vec<Diagnostic>, explanation: &str) {
|
// "Undelay" the `DelayedBug`s (into plain `Bug`s).
|
||||||
let has_bugs = !bugs.is_empty();
|
if bug.level != Level::DelayedBug {
|
||||||
for bug in bugs {
|
// NOTE(eddyb) not panicking here because we're already producing
|
||||||
|
// an ICE, and the more information the merrier.
|
||||||
|
bug.note(&format!(
|
||||||
|
"`flushed_delayed` got diagnostic with level {:?}, \
|
||||||
|
instead of the expected `DelayedBug`",
|
||||||
|
bug.level,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
bug.level = Level::Bug;
|
||||||
|
|
||||||
self.emit_diagnostic(&bug);
|
self.emit_diagnostic(&bug);
|
||||||
}
|
}
|
||||||
if has_bugs {
|
|
||||||
panic!("{}", explanation);
|
// Panic with `ExplicitBug` to avoid "unexpected panic" messages.
|
||||||
|
if !no_bugs {
|
||||||
|
panic::panic_any(ExplicitBug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1224,9 +1236,10 @@ impl DelayedDiagnostic {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, PartialEq, Clone, Hash, Debug, Encodable, Decodable)]
|
#[derive(Copy, PartialEq, Eq, Clone, Hash, Debug, Encodable, Decodable)]
|
||||||
pub enum Level {
|
pub enum Level {
|
||||||
Bug,
|
Bug,
|
||||||
|
DelayedBug,
|
||||||
Fatal,
|
Fatal,
|
||||||
Error {
|
Error {
|
||||||
/// If this error comes from a lint, don't abort compilation even when abort_if_errors() is called.
|
/// If this error comes from a lint, don't abort compilation even when abort_if_errors() is called.
|
||||||
|
@ -1235,7 +1248,6 @@ pub enum Level {
|
||||||
Warning,
|
Warning,
|
||||||
Note,
|
Note,
|
||||||
Help,
|
Help,
|
||||||
Cancelled,
|
|
||||||
FailureNote,
|
FailureNote,
|
||||||
Allow,
|
Allow,
|
||||||
}
|
}
|
||||||
|
@ -1250,7 +1262,7 @@ impl Level {
|
||||||
fn color(self) -> ColorSpec {
|
fn color(self) -> ColorSpec {
|
||||||
let mut spec = ColorSpec::new();
|
let mut spec = ColorSpec::new();
|
||||||
match self {
|
match self {
|
||||||
Bug | Fatal | Error { .. } => {
|
Bug | DelayedBug | Fatal | Error { .. } => {
|
||||||
spec.set_fg(Some(Color::Red)).set_intense(true);
|
spec.set_fg(Some(Color::Red)).set_intense(true);
|
||||||
}
|
}
|
||||||
Warning => {
|
Warning => {
|
||||||
|
@ -1263,20 +1275,19 @@ impl Level {
|
||||||
spec.set_fg(Some(Color::Cyan)).set_intense(true);
|
spec.set_fg(Some(Color::Cyan)).set_intense(true);
|
||||||
}
|
}
|
||||||
FailureNote => {}
|
FailureNote => {}
|
||||||
Allow | Cancelled => unreachable!(),
|
Allow => unreachable!(),
|
||||||
}
|
}
|
||||||
spec
|
spec
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_str(self) -> &'static str {
|
pub fn to_str(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Bug => "error: internal compiler error",
|
Bug | DelayedBug => "error: internal compiler error",
|
||||||
Fatal | Error { .. } => "error",
|
Fatal | Error { .. } => "error",
|
||||||
Warning => "warning",
|
Warning => "warning",
|
||||||
Note => "note",
|
Note => "note",
|
||||||
Help => "help",
|
Help => "help",
|
||||||
FailureNote => "failure-note",
|
FailureNote => "failure-note",
|
||||||
Cancelled => panic!("Shouldn't call on cancelled error"),
|
|
||||||
Allow => panic!("Shouldn't call on allowed error"),
|
Allow => panic!("Shouldn't call on allowed error"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1286,9 +1297,10 @@ impl Level {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(eddyb) this doesn't belong here AFAICT, should be moved to callsite.
|
||||||
pub fn add_elided_lifetime_in_path_suggestion(
|
pub fn add_elided_lifetime_in_path_suggestion(
|
||||||
source_map: &SourceMap,
|
source_map: &SourceMap,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
diag: &mut Diagnostic,
|
||||||
n: usize,
|
n: usize,
|
||||||
path_span: Span,
|
path_span: Span,
|
||||||
incl_angl_brckt: bool,
|
incl_angl_brckt: bool,
|
||||||
|
@ -1320,7 +1332,7 @@ pub fn add_elided_lifetime_in_path_suggestion(
|
||||||
(insertion_span, anon_lts)
|
(insertion_span, anon_lts)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
db.span_suggestion(
|
diag.span_suggestion(
|
||||||
replace_span,
|
replace_span,
|
||||||
&format!("indicate the anonymous lifetime{}", pluralize!(n)),
|
&format!("indicate the anonymous lifetime{}", pluralize!(n)),
|
||||||
suggestion,
|
suggestion,
|
||||||
|
|
|
@ -10,7 +10,7 @@ use rustc_ast::{self as ast, AstLike, Attribute, Item, NodeId, PatKind};
|
||||||
use rustc_attr::{self as attr, Deprecation, Stability};
|
use rustc_attr::{self as attr, Deprecation, Stability};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::sync::{self, Lrc};
|
use rustc_data_structures::sync::{self, Lrc};
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorReported};
|
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorReported, PResult};
|
||||||
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
|
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
|
||||||
use rustc_lint_defs::BuiltinLintDiagnostics;
|
use rustc_lint_defs::BuiltinLintDiagnostics;
|
||||||
use rustc_parse::{self, nt_to_tokenstream, parser, MACRO_ARGUMENTS};
|
use rustc_parse::{self, nt_to_tokenstream, parser, MACRO_ARGUMENTS};
|
||||||
|
@ -1072,7 +1072,11 @@ impl<'a> ExtCtxt<'a> {
|
||||||
self.current_expansion.id.expansion_cause()
|
self.current_expansion.id.expansion_cause()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn struct_span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'a> {
|
pub fn struct_span_err<S: Into<MultiSpan>>(
|
||||||
|
&self,
|
||||||
|
sp: S,
|
||||||
|
msg: &str,
|
||||||
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
self.sess.parse_sess.span_diagnostic.struct_span_err(sp, msg)
|
self.sess.parse_sess.span_diagnostic.struct_span_err(sp, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1130,11 +1134,7 @@ impl<'a> ExtCtxt<'a> {
|
||||||
/// This unifies the logic used for resolving `include_X!`.
|
/// This unifies the logic used for resolving `include_X!`.
|
||||||
///
|
///
|
||||||
/// FIXME: move this to `rustc_builtin_macros` and make it private.
|
/// FIXME: move this to `rustc_builtin_macros` and make it private.
|
||||||
pub fn resolve_path(
|
pub fn resolve_path(&self, path: impl Into<PathBuf>, span: Span) -> PResult<'a, PathBuf> {
|
||||||
&self,
|
|
||||||
path: impl Into<PathBuf>,
|
|
||||||
span: Span,
|
|
||||||
) -> Result<PathBuf, DiagnosticBuilder<'a>> {
|
|
||||||
let path = path.into();
|
let path = path.into();
|
||||||
|
|
||||||
// Relative paths are resolved relative to the file in which they are found
|
// Relative paths are resolved relative to the file in which they are found
|
||||||
|
@ -1174,7 +1174,7 @@ pub fn expr_to_spanned_string<'a>(
|
||||||
cx: &'a mut ExtCtxt<'_>,
|
cx: &'a mut ExtCtxt<'_>,
|
||||||
expr: P<ast::Expr>,
|
expr: P<ast::Expr>,
|
||||||
err_msg: &str,
|
err_msg: &str,
|
||||||
) -> Result<(Symbol, ast::StrStyle, Span), Option<(DiagnosticBuilder<'a>, bool)>> {
|
) -> Result<(Symbol, ast::StrStyle, Span), Option<(DiagnosticBuilder<'a, ErrorReported>, bool)>> {
|
||||||
// Perform eager expansion on the expression.
|
// Perform eager expansion on the expression.
|
||||||
// We want to be able to handle e.g., `concat!("foo", "bar")`.
|
// We want to be able to handle e.g., `concat!("foo", "bar")`.
|
||||||
let expr = cx.expander().fully_expand_fragment(AstFragment::Expr(expr)).make_expr();
|
let expr = cx.expander().fully_expand_fragment(AstFragment::Expr(expr)).make_expr();
|
||||||
|
@ -1233,7 +1233,9 @@ pub fn check_zero_tts(cx: &ExtCtxt<'_>, sp: Span, tts: TokenStream, name: &str)
|
||||||
pub fn parse_expr(p: &mut parser::Parser<'_>) -> Option<P<ast::Expr>> {
|
pub fn parse_expr(p: &mut parser::Parser<'_>) -> Option<P<ast::Expr>> {
|
||||||
match p.parse_expr() {
|
match p.parse_expr() {
|
||||||
Ok(e) => return Some(e),
|
Ok(e) => return Some(e),
|
||||||
Err(mut err) => err.emit(),
|
Err(mut err) => {
|
||||||
|
err.emit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while p.token != token::Eof {
|
while p.token != token::Eof {
|
||||||
p.bump();
|
p.bump();
|
||||||
|
|
|
@ -16,7 +16,7 @@ use rustc_ast_pretty::pprust;
|
||||||
use rustc_attr::{self as attr, TransparencyError};
|
use rustc_attr::{self as attr, TransparencyError};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
|
||||||
use rustc_feature::Features;
|
use rustc_feature::Features;
|
||||||
use rustc_lint_defs::builtin::{
|
use rustc_lint_defs::builtin::{
|
||||||
RUST_2021_INCOMPATIBLE_OR_PATTERNS, SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
|
RUST_2021_INCOMPATIBLE_OR_PATTERNS, SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
|
||||||
|
@ -49,11 +49,7 @@ crate struct ParserAnyMacro<'a> {
|
||||||
is_local: bool,
|
is_local: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn annotate_err_with_kind(
|
crate fn annotate_err_with_kind(err: &mut Diagnostic, kind: AstFragmentKind, span: Span) {
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
kind: AstFragmentKind,
|
|
||||||
span: Span,
|
|
||||||
) {
|
|
||||||
match kind {
|
match kind {
|
||||||
AstFragmentKind::Ty => {
|
AstFragmentKind::Ty => {
|
||||||
err.span_label(span, "this macro call doesn't expand to a type");
|
err.span_label(span, "this macro call doesn't expand to a type");
|
||||||
|
@ -66,7 +62,7 @@ crate fn annotate_err_with_kind(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_frag_parse_err(
|
fn emit_frag_parse_err(
|
||||||
mut e: DiagnosticBuilder<'_>,
|
mut e: DiagnosticBuilder<'_, rustc_errors::ErrorReported>,
|
||||||
parser: &Parser<'_>,
|
parser: &Parser<'_>,
|
||||||
orig_parser: &mut Parser<'_>,
|
orig_parser: &mut Parser<'_>,
|
||||||
site_span: Span,
|
site_span: Span,
|
||||||
|
@ -99,7 +95,7 @@ fn emit_frag_parse_err(
|
||||||
match kind {
|
match kind {
|
||||||
// Try a statement if an expression is wanted but failed and suggest adding `;` to call.
|
// Try a statement if an expression is wanted but failed and suggest adding `;` to call.
|
||||||
AstFragmentKind::Expr => match parse_ast_fragment(orig_parser, AstFragmentKind::Stmts) {
|
AstFragmentKind::Expr => match parse_ast_fragment(orig_parser, AstFragmentKind::Stmts) {
|
||||||
Err(mut err) => err.cancel(),
|
Err(err) => err.cancel(),
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
e.note(
|
e.note(
|
||||||
"the macro call doesn't expand to an expression, but it can expand to a statement",
|
"the macro call doesn't expand to an expression, but it can expand to a statement",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::base::ModuleData;
|
use crate::base::ModuleData;
|
||||||
use rustc_ast::ptr::P;
|
use rustc_ast::ptr::P;
|
||||||
use rustc_ast::{token, Attribute, Inline, Item};
|
use rustc_ast::{token, Attribute, Inline, Item};
|
||||||
use rustc_errors::{struct_span_err, DiagnosticBuilder};
|
use rustc_errors::{struct_span_err, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_parse::new_parser_from_file;
|
use rustc_parse::new_parser_from_file;
|
||||||
use rustc_parse::validate_attr;
|
use rustc_parse::validate_attr;
|
||||||
use rustc_session::parse::ParseSess;
|
use rustc_session::parse::ParseSess;
|
||||||
|
@ -39,7 +39,7 @@ pub enum ModError<'a> {
|
||||||
ModInBlock(Option<Ident>),
|
ModInBlock(Option<Ident>),
|
||||||
FileNotFound(Ident, PathBuf, PathBuf),
|
FileNotFound(Ident, PathBuf, PathBuf),
|
||||||
MultipleCandidates(Ident, PathBuf, PathBuf),
|
MultipleCandidates(Ident, PathBuf, PathBuf),
|
||||||
ParserError(DiagnosticBuilder<'a>),
|
ParserError(DiagnosticBuilder<'a, ErrorReported>),
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn parse_external_mod(
|
crate fn parse_external_mod(
|
||||||
|
@ -242,7 +242,7 @@ pub fn default_submod_path<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModError<'_> {
|
impl ModError<'_> {
|
||||||
fn report(self, sess: &Session, span: Span) {
|
fn report(self, sess: &Session, span: Span) -> ErrorReported {
|
||||||
let diag = &sess.parse_sess.span_diagnostic;
|
let diag = &sess.parse_sess.span_diagnostic;
|
||||||
match self {
|
match self {
|
||||||
ModError::CircularInclusion(file_paths) => {
|
ModError::CircularInclusion(file_paths) => {
|
||||||
|
|
|
@ -446,7 +446,9 @@ impl server::TokenStream for Rustc<'_, '_> {
|
||||||
}
|
}
|
||||||
expr
|
expr
|
||||||
};
|
};
|
||||||
let expr = expr.map_err(|mut err| err.emit())?;
|
let expr = expr.map_err(|mut err| {
|
||||||
|
err.emit();
|
||||||
|
})?;
|
||||||
|
|
||||||
// Perform eager expansion on the expression.
|
// Perform eager expansion on the expression.
|
||||||
let expr = self
|
let expr = self
|
||||||
|
|
|
@ -58,7 +58,7 @@ use crate::traits::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_errors::{pluralize, struct_span_err};
|
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorReported};
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
|
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
|
@ -85,7 +85,7 @@ pub mod nice_region_error;
|
||||||
|
|
||||||
pub(super) fn note_and_explain_region<'tcx>(
|
pub(super) fn note_and_explain_region<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
prefix: &str,
|
prefix: &str,
|
||||||
region: ty::Region<'tcx>,
|
region: ty::Region<'tcx>,
|
||||||
suffix: &str,
|
suffix: &str,
|
||||||
|
@ -118,7 +118,7 @@ pub(super) fn note_and_explain_region<'tcx>(
|
||||||
|
|
||||||
fn explain_free_region<'tcx>(
|
fn explain_free_region<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
prefix: &str,
|
prefix: &str,
|
||||||
region: ty::Region<'tcx>,
|
region: ty::Region<'tcx>,
|
||||||
suffix: &str,
|
suffix: &str,
|
||||||
|
@ -194,7 +194,7 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_msg_span(
|
fn emit_msg_span(
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
prefix: &str,
|
prefix: &str,
|
||||||
description: String,
|
description: String,
|
||||||
span: Option<Span>,
|
span: Option<Span>,
|
||||||
|
@ -210,7 +210,7 @@ fn emit_msg_span(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn label_msg_span(
|
fn label_msg_span(
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
prefix: &str,
|
prefix: &str,
|
||||||
description: String,
|
description: String,
|
||||||
span: Option<Span>,
|
span: Option<Span>,
|
||||||
|
@ -230,7 +230,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
|
||||||
span: Span,
|
span: Span,
|
||||||
hidden_ty: Ty<'tcx>,
|
hidden_ty: Ty<'tcx>,
|
||||||
hidden_region: ty::Region<'tcx>,
|
hidden_region: ty::Region<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
tcx.sess,
|
tcx.sess,
|
||||||
span,
|
span,
|
||||||
|
@ -471,11 +471,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a note if the types come from similarly named crates
|
/// Adds a note if the types come from similarly named crates
|
||||||
fn check_and_note_conflicting_crates(
|
fn check_and_note_conflicting_crates(&self, err: &mut Diagnostic, terr: &TypeError<'tcx>) {
|
||||||
&self,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
terr: &TypeError<'tcx>,
|
|
||||||
) {
|
|
||||||
use hir::def_id::CrateNum;
|
use hir::def_id::CrateNum;
|
||||||
use rustc_hir::definitions::DisambiguatedDefPathData;
|
use rustc_hir::definitions::DisambiguatedDefPathData;
|
||||||
use ty::print::Printer;
|
use ty::print::Printer;
|
||||||
|
@ -557,7 +553,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let report_path_match = |err: &mut DiagnosticBuilder<'_>, did1: DefId, did2: DefId| {
|
let report_path_match = |err: &mut Diagnostic, did1: DefId, did2: DefId| {
|
||||||
// Only external crates, if either is from a local
|
// Only external crates, if either is from a local
|
||||||
// module we could have false positives
|
// module we could have false positives
|
||||||
if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate {
|
if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate {
|
||||||
|
@ -598,7 +594,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn note_error_origin(
|
fn note_error_origin(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
err: &mut Diagnostic,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
exp_found: Option<ty::error::ExpectedFound<Ty<'tcx>>>,
|
exp_found: Option<ty::error::ExpectedFound<Ty<'tcx>>>,
|
||||||
terr: &TypeError<'tcx>,
|
terr: &TypeError<'tcx>,
|
||||||
|
@ -792,7 +788,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn suggest_boxing_for_return_impl_trait(
|
fn suggest_boxing_for_return_impl_trait(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
err: &mut Diagnostic,
|
||||||
return_sp: Span,
|
return_sp: Span,
|
||||||
arm_spans: impl Iterator<Item = Span>,
|
arm_spans: impl Iterator<Item = Span>,
|
||||||
) {
|
) {
|
||||||
|
@ -1436,7 +1432,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
/// E0271, like `src/test/ui/issues/issue-39970.stderr`.
|
/// E0271, like `src/test/ui/issues/issue-39970.stderr`.
|
||||||
pub fn note_type_err(
|
pub fn note_type_err(
|
||||||
&self,
|
&self,
|
||||||
diag: &mut DiagnosticBuilder<'tcx>,
|
diag: &mut Diagnostic,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
secondary_span: Option<(Span, String)>,
|
secondary_span: Option<(Span, String)>,
|
||||||
mut values: Option<ValuePairs<'tcx>>,
|
mut values: Option<ValuePairs<'tcx>>,
|
||||||
|
@ -1483,14 +1479,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
types_visitor
|
types_visitor
|
||||||
}
|
}
|
||||||
|
|
||||||
fn report(&self, err: &mut DiagnosticBuilder<'_>) {
|
fn report(&self, err: &mut Diagnostic) {
|
||||||
self.add_labels_for_types(err, "expected", &self.expected);
|
self.add_labels_for_types(err, "expected", &self.expected);
|
||||||
self.add_labels_for_types(err, "found", &self.found);
|
self.add_labels_for_types(err, "found", &self.found);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_labels_for_types(
|
fn add_labels_for_types(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
target: &str,
|
target: &str,
|
||||||
types: &FxHashMap<TyCategory, FxHashSet<Span>>,
|
types: &FxHashMap<TyCategory, FxHashSet<Span>>,
|
||||||
) {
|
) {
|
||||||
|
@ -1601,7 +1597,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
Some((expected, found)) => Some((expected, found)),
|
Some((expected, found)) => Some((expected, found)),
|
||||||
None => {
|
None => {
|
||||||
// Derived error. Cancel the emitter.
|
// Derived error. Cancel the emitter.
|
||||||
diag.cancel();
|
// NOTE(eddyb) this was `.cancel()`, but `diag`
|
||||||
|
// is borrowed, so we can't fully defuse it.
|
||||||
|
diag.downgrade_to_delayed_bug();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1817,7 +1815,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
exp_span: Span,
|
exp_span: Span,
|
||||||
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
|
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
|
||||||
diag: &mut DiagnosticBuilder<'tcx>,
|
diag: &mut Diagnostic,
|
||||||
) {
|
) {
|
||||||
debug!(
|
debug!(
|
||||||
"suggest_await_on_expect_found: exp_span={:?}, expected_ty={:?}, found_ty={:?}",
|
"suggest_await_on_expect_found: exp_span={:?}, expected_ty={:?}, found_ty={:?}",
|
||||||
|
@ -1905,7 +1903,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
|
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
|
||||||
diag: &mut DiagnosticBuilder<'tcx>,
|
diag: &mut Diagnostic,
|
||||||
) {
|
) {
|
||||||
debug!(
|
debug!(
|
||||||
"suggest_accessing_field_where_appropriate(cause={:?}, exp_found={:?})",
|
"suggest_accessing_field_where_appropriate(cause={:?}, exp_found={:?})",
|
||||||
|
@ -1954,7 +1952,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
|
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
|
||||||
diag: &mut DiagnosticBuilder<'tcx>,
|
diag: &mut Diagnostic,
|
||||||
) {
|
) {
|
||||||
if let (ty::Adt(exp_def, exp_substs), ty::Ref(_, found_ty, _)) =
|
if let (ty::Adt(exp_def, exp_substs), ty::Ref(_, found_ty, _)) =
|
||||||
(exp_found.expected.kind(), exp_found.found.kind())
|
(exp_found.expected.kind(), exp_found.found.kind())
|
||||||
|
@ -2015,7 +2013,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
trace: TypeTrace<'tcx>,
|
trace: TypeTrace<'tcx>,
|
||||||
terr: &TypeError<'tcx>,
|
terr: &TypeError<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
use crate::traits::ObligationCauseCode::MatchExpressionArm;
|
use crate::traits::ObligationCauseCode::MatchExpressionArm;
|
||||||
|
|
||||||
debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr);
|
debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr);
|
||||||
|
@ -2107,7 +2105,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn emit_tuple_wrap_err(
|
fn emit_tuple_wrap_err(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
err: &mut Diagnostic,
|
||||||
span: Span,
|
span: Span,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
expected_fields: &List<Ty<'tcx>>,
|
expected_fields: &List<Ty<'tcx>>,
|
||||||
|
@ -2223,7 +2221,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
origin: Option<SubregionOrigin<'tcx>>,
|
origin: Option<SubregionOrigin<'tcx>>,
|
||||||
bound_kind: GenericKind<'tcx>,
|
bound_kind: GenericKind<'tcx>,
|
||||||
sub: Region<'tcx>,
|
sub: Region<'tcx>,
|
||||||
) -> DiagnosticBuilder<'a> {
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
let hir = self.tcx.hir();
|
let hir = self.tcx.hir();
|
||||||
// Attempt to obtain the span of the parameter so we can
|
// Attempt to obtain the span of the parameter so we can
|
||||||
// suggest adding an explicit lifetime bound to it.
|
// suggest adding an explicit lifetime bound to it.
|
||||||
|
@ -2339,7 +2337,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn binding_suggestion<'tcx, S: fmt::Display>(
|
fn binding_suggestion<'tcx, S: fmt::Display>(
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
err: &mut Diagnostic,
|
||||||
type_param_span: Option<(Span, bool, bool)>,
|
type_param_span: Option<(Span, bool, bool)>,
|
||||||
bound_kind: GenericKind<'tcx>,
|
bound_kind: GenericKind<'tcx>,
|
||||||
sub: S,
|
sub: S,
|
||||||
|
@ -2373,7 +2371,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_binding_suggestion =
|
let new_binding_suggestion =
|
||||||
|err: &mut DiagnosticBuilder<'tcx>,
|
|err: &mut Diagnostic,
|
||||||
type_param_span: Option<(Span, bool, bool)>,
|
type_param_span: Option<(Span, bool, bool)>,
|
||||||
bound_kind: GenericKind<'tcx>| {
|
bound_kind: GenericKind<'tcx>| {
|
||||||
let msg = "consider introducing an explicit lifetime bound";
|
let msg = "consider introducing an explicit lifetime bound";
|
||||||
|
@ -2649,7 +2647,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
fn report_inference_failure(
|
fn report_inference_failure(
|
||||||
&self,
|
&self,
|
||||||
var_origin: RegionVariableOrigin,
|
var_origin: RegionVariableOrigin,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let br_string = |br: ty::BoundRegionKind| {
|
let br_string = |br: ty::BoundRegionKind| {
|
||||||
let mut s = match br {
|
let mut s = match br {
|
||||||
ty::BrNamed(_, name) => name.to_string(),
|
ty::BrNamed(_, name) => name.to_string(),
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use crate::infer::type_variable::TypeVariableOriginKind;
|
use crate::infer::type_variable::TypeVariableOriginKind;
|
||||||
use crate::infer::{InferCtxt, Symbol};
|
use crate::infer::{InferCtxt, Symbol};
|
||||||
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
|
use rustc_errors::{
|
||||||
|
pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorReported,
|
||||||
|
};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Namespace};
|
use rustc_hir::def::{DefKind, Namespace};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
|
@ -195,7 +197,7 @@ impl UseDiagnostic<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn attach_note(&self, err: &mut DiagnosticBuilder<'_>) {
|
fn attach_note(&self, err: &mut Diagnostic) {
|
||||||
match *self {
|
match *self {
|
||||||
Self::TryConversion { pre_ty, post_ty, .. } => {
|
Self::TryConversion { pre_ty, post_ty, .. } => {
|
||||||
let intro = "`?` implicitly converts the error value";
|
let intro = "`?` implicitly converts the error value";
|
||||||
|
@ -224,7 +226,7 @@ impl UseDiagnostic<'_> {
|
||||||
|
|
||||||
/// Suggest giving an appropriate return type to a closure expression.
|
/// Suggest giving an appropriate return type to a closure expression.
|
||||||
fn closure_return_type_suggestion(
|
fn closure_return_type_suggestion(
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
output: &FnRetTy<'_>,
|
output: &FnRetTy<'_>,
|
||||||
body: &Body<'_>,
|
body: &Body<'_>,
|
||||||
ret: &str,
|
ret: &str,
|
||||||
|
@ -488,7 +490,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
arg: GenericArg<'tcx>,
|
arg: GenericArg<'tcx>,
|
||||||
impl_candidates: Vec<ty::TraitRef<'tcx>>,
|
impl_candidates: Vec<ty::TraitRef<'tcx>>,
|
||||||
error_code: TypeAnnotationNeeded,
|
error_code: TypeAnnotationNeeded,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let arg = self.resolve_vars_if_possible(arg);
|
let arg = self.resolve_vars_if_possible(arg);
|
||||||
let arg_data = self.extract_inference_diagnostics_data(arg, None);
|
let arg_data = self.extract_inference_diagnostics_data(arg, None);
|
||||||
|
|
||||||
|
@ -868,7 +870,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
segment: &hir::PathSegment<'_>,
|
segment: &hir::PathSegment<'_>,
|
||||||
e: &Expr<'_>,
|
e: &Expr<'_>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
) {
|
) {
|
||||||
if let (Some(typeck_results), None) = (self.in_progress_typeck_results, &segment.args) {
|
if let (Some(typeck_results), None) = (self.in_progress_typeck_results, &segment.args) {
|
||||||
let borrow = typeck_results.borrow();
|
let borrow = typeck_results.borrow();
|
||||||
|
@ -913,7 +915,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
kind: hir::GeneratorKind,
|
kind: hir::GeneratorKind,
|
||||||
span: Span,
|
span: Span,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let ty = self.resolve_vars_if_possible(ty);
|
let ty = self.resolve_vars_if_possible(ty);
|
||||||
let data = self.extract_inference_diagnostics_data(ty.into(), None);
|
let data = self.extract_inference_diagnostics_data(ty.into(), None);
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
||||||
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
||||||
use crate::infer::SubregionOrigin;
|
use crate::infer::SubregionOrigin;
|
||||||
|
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
|
use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorReported};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::{GenericParamKind, Ty};
|
use rustc_hir::{GenericParamKind, Ty};
|
||||||
use rustc_middle::ty::Region;
|
use rustc_middle::ty::Region;
|
||||||
|
@ -156,7 +156,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
sub: Region<'tcx>,
|
sub: Region<'tcx>,
|
||||||
ty_sup: &Ty<'_>,
|
ty_sup: &Ty<'_>,
|
||||||
ty_sub: &Ty<'_>,
|
ty_sub: &Ty<'_>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
) {
|
) {
|
||||||
if let (
|
if let (
|
||||||
hir::Ty { kind: hir::TyKind::Rptr(lifetime_sub, _), .. },
|
hir::Ty { kind: hir::TyKind::Rptr(lifetime_sub, _), .. },
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl<'cx, 'tcx> NiceRegionError<'cx, 'tcx> {
|
||||||
self.infcx.tcx
|
self.infcx.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_report_from_nll(&self) -> Option<DiagnosticBuilder<'tcx>> {
|
pub fn try_report_from_nll(&self) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
|
||||||
// Due to the improved diagnostics returned by the MIR borrow checker, only a subset of
|
// Due to the improved diagnostics returned by the MIR borrow checker, only a subset of
|
||||||
// the nice region errors are required when running under the MIR borrow checker.
|
// the nice region errors are required when running under the MIR borrow checker.
|
||||||
self.try_report_named_anon_conflict().or_else(|| self.try_report_placeholder_conflict())
|
self.try_report_named_anon_conflict().or_else(|| self.try_report_placeholder_conflict())
|
||||||
|
|
|
@ -2,13 +2,15 @@
|
||||||
//! where one region is named and the other is anonymous.
|
//! where one region is named and the other is anonymous.
|
||||||
use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type;
|
use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type;
|
||||||
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
|
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
|
|
||||||
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
/// When given a `ConcreteFailure` for a function with parameters containing a named region and
|
/// When given a `ConcreteFailure` for a function with parameters containing a named region and
|
||||||
/// an anonymous region, emit an descriptive diagnostic error.
|
/// an anonymous region, emit an descriptive diagnostic error.
|
||||||
pub(super) fn try_report_named_anon_conflict(&self) -> Option<DiagnosticBuilder<'tcx>> {
|
pub(super) fn try_report_named_anon_conflict(
|
||||||
|
&self,
|
||||||
|
) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
|
||||||
let (span, sub, sup) = self.regions()?;
|
let (span, sub, sup) = self.regions()?;
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::infer::ValuePairs;
|
||||||
use crate::infer::{SubregionOrigin, TypeTrace};
|
use crate::infer::{SubregionOrigin, TypeTrace};
|
||||||
use crate::traits::{ObligationCause, ObligationCauseCode};
|
use crate::traits::{ObligationCause, ObligationCauseCode};
|
||||||
use rustc_data_structures::intern::Interned;
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::{Diagnostic, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_hir::def::Namespace;
|
use rustc_hir::def::Namespace;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_middle::ty::error::ExpectedFound;
|
use rustc_middle::ty::error::ExpectedFound;
|
||||||
|
@ -17,7 +17,9 @@ use std::fmt::{self, Write};
|
||||||
impl<'tcx> NiceRegionError<'_, 'tcx> {
|
impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||||
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
|
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
|
||||||
/// an anonymous region, emit a descriptive diagnostic error.
|
/// an anonymous region, emit a descriptive diagnostic error.
|
||||||
pub(super) fn try_report_placeholder_conflict(&self) -> Option<DiagnosticBuilder<'tcx>> {
|
pub(super) fn try_report_placeholder_conflict(
|
||||||
|
&self,
|
||||||
|
) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
|
||||||
match &self.error {
|
match &self.error {
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// NB. The ordering of cases in this match is very
|
// NB. The ordering of cases in this match is very
|
||||||
|
@ -153,7 +155,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||||
sub_placeholder: Option<Region<'tcx>>,
|
sub_placeholder: Option<Region<'tcx>>,
|
||||||
sup_placeholder: Option<Region<'tcx>>,
|
sup_placeholder: Option<Region<'tcx>>,
|
||||||
value_pairs: &ValuePairs<'tcx>,
|
value_pairs: &ValuePairs<'tcx>,
|
||||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
|
||||||
let (expected_substs, found_substs, trait_def_id) = match value_pairs {
|
let (expected_substs, found_substs, trait_def_id) = match value_pairs {
|
||||||
ValuePairs::TraitRefs(ExpectedFound { expected, found })
|
ValuePairs::TraitRefs(ExpectedFound { expected, found })
|
||||||
if expected.def_id == found.def_id =>
|
if expected.def_id == found.def_id =>
|
||||||
|
@ -201,7 +203,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||||
trait_def_id: DefId,
|
trait_def_id: DefId,
|
||||||
expected_substs: SubstsRef<'tcx>,
|
expected_substs: SubstsRef<'tcx>,
|
||||||
actual_substs: SubstsRef<'tcx>,
|
actual_substs: SubstsRef<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let span = cause.span(self.tcx());
|
let span = cause.span(self.tcx());
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"implementation of `{}` is not general enough",
|
"implementation of `{}` is not general enough",
|
||||||
|
@ -306,7 +308,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||||
/// due to the number of combinations we have to deal with.
|
/// due to the number of combinations we have to deal with.
|
||||||
fn explain_actual_impl_that_was_found(
|
fn explain_actual_impl_that_was_found(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
sub_placeholder: Option<Region<'tcx>>,
|
sub_placeholder: Option<Region<'tcx>>,
|
||||||
sup_placeholder: Option<Region<'tcx>>,
|
sup_placeholder: Option<Region<'tcx>>,
|
||||||
has_sub: Option<usize>,
|
has_sub: Option<usize>,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::infer::lexical_region_resolve::RegionResolutionError;
|
||||||
use crate::infer::{SubregionOrigin, TypeTrace};
|
use crate::infer::{SubregionOrigin, TypeTrace};
|
||||||
use crate::traits::{ObligationCauseCode, UnifyReceiverContext};
|
use crate::traits::{ObligationCauseCode, UnifyReceiverContext};
|
||||||
use rustc_data_structures::stable_set::FxHashSet;
|
use rustc_data_structures::stable_set::FxHashSet;
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
|
use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorReported};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::intravisit::{walk_ty, Visitor};
|
use rustc_hir::intravisit::{walk_ty, Visitor};
|
||||||
use rustc_hir::{self as hir, GenericBound, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind};
|
use rustc_hir::{self as hir, GenericBound, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind};
|
||||||
|
@ -286,7 +286,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
|
|
||||||
pub fn suggest_new_region_bound(
|
pub fn suggest_new_region_bound(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
fn_returns: Vec<&rustc_hir::Ty<'_>>,
|
fn_returns: Vec<&rustc_hir::Ty<'_>>,
|
||||||
lifetime_name: String,
|
lifetime_name: String,
|
||||||
arg: Option<String>,
|
arg: Option<String>,
|
||||||
|
@ -483,7 +483,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
/// `'static` obligation. Suggest relaxing that implicit bound.
|
/// `'static` obligation. Suggest relaxing that implicit bound.
|
||||||
fn find_impl_on_dyn_trait(
|
fn find_impl_on_dyn_trait(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
ty: Ty<'_>,
|
ty: Ty<'_>,
|
||||||
ctxt: &UnifyReceiverContext<'tcx>,
|
ctxt: &UnifyReceiverContext<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
@ -514,7 +514,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
|
|
||||||
fn suggest_constrain_dyn_trait_in_impl(
|
fn suggest_constrain_dyn_trait_in_impl(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
found_dids: &FxHashSet<DefId>,
|
found_dids: &FxHashSet<DefId>,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
self_ty: &hir::Ty<'_>,
|
self_ty: &hir::Ty<'_>,
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
use crate::infer::error_reporting::{note_and_explain_region, ObligationCauseExt};
|
use crate::infer::error_reporting::{note_and_explain_region, ObligationCauseExt};
|
||||||
use crate::infer::{self, InferCtxt, SubregionOrigin};
|
use crate::infer::{self, InferCtxt, SubregionOrigin};
|
||||||
use rustc_errors::{struct_span_err, DiagnosticBuilder};
|
use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_middle::traits::ObligationCauseCode;
|
use rustc_middle::traits::ObligationCauseCode;
|
||||||
use rustc_middle::ty::error::TypeError;
|
use rustc_middle::ty::error::TypeError;
|
||||||
use rustc_middle::ty::{self, Region};
|
use rustc_middle::ty::{self, Region};
|
||||||
|
|
||||||
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
pub(super) fn note_region_origin(
|
pub(super) fn note_region_origin(&self, err: &mut Diagnostic, origin: &SubregionOrigin<'tcx>) {
|
||||||
&self,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
origin: &SubregionOrigin<'tcx>,
|
|
||||||
) {
|
|
||||||
let mut label_or_note = |span, msg| {
|
let mut label_or_note = |span, msg| {
|
||||||
let sub_count = err.children.iter().filter(|d| d.span.is_dummy()).count();
|
let sub_count = err.children.iter().filter(|d| d.span.is_dummy()).count();
|
||||||
let expanded_sub_count = err.children.iter().filter(|d| !d.span.is_dummy()).count();
|
let expanded_sub_count = err.children.iter().filter(|d| !d.span.is_dummy()).count();
|
||||||
|
@ -113,7 +109,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
origin: SubregionOrigin<'tcx>,
|
origin: SubregionOrigin<'tcx>,
|
||||||
sub: Region<'tcx>,
|
sub: Region<'tcx>,
|
||||||
sup: Region<'tcx>,
|
sup: Region<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
match origin {
|
match origin {
|
||||||
infer::Subtype(box trace) => {
|
infer::Subtype(box trace) => {
|
||||||
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
|
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
|
||||||
|
@ -405,7 +401,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
placeholder_origin: SubregionOrigin<'tcx>,
|
placeholder_origin: SubregionOrigin<'tcx>,
|
||||||
sub: Region<'tcx>,
|
sub: Region<'tcx>,
|
||||||
sup: Region<'tcx>,
|
sup: Region<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
// I can't think how to do better than this right now. -nikomatsakis
|
// I can't think how to do better than this right now. -nikomatsakis
|
||||||
debug!(?placeholder_origin, ?sub, ?sup, "report_placeholder_failure");
|
debug!(?placeholder_origin, ?sub, ?sup, "report_placeholder_failure");
|
||||||
match placeholder_origin {
|
match placeholder_origin {
|
||||||
|
|
|
@ -14,7 +14,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_data_structures::undo_log::Rollback;
|
use rustc_data_structures::undo_log::Rollback;
|
||||||
use rustc_data_structures::unify as ut;
|
use rustc_data_structures::unify as ut;
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::{DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
|
use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
|
||||||
|
@ -1475,19 +1475,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
sp: Span,
|
sp: Span,
|
||||||
mk_diag: M,
|
mk_diag: M,
|
||||||
actual_ty: Ty<'tcx>,
|
actual_ty: Ty<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx>
|
) -> DiagnosticBuilder<'tcx, ErrorReported>
|
||||||
where
|
where
|
||||||
M: FnOnce(String) -> DiagnosticBuilder<'tcx>,
|
M: FnOnce(String) -> DiagnosticBuilder<'tcx, ErrorReported>,
|
||||||
{
|
{
|
||||||
let actual_ty = self.resolve_vars_if_possible(actual_ty);
|
let actual_ty = self.resolve_vars_if_possible(actual_ty);
|
||||||
debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty);
|
debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty);
|
||||||
|
|
||||||
|
let mut err = mk_diag(self.ty_to_string(actual_ty));
|
||||||
|
|
||||||
// Don't report an error if actual type is `Error`.
|
// Don't report an error if actual type is `Error`.
|
||||||
if actual_ty.references_error() {
|
if actual_ty.references_error() {
|
||||||
return self.tcx.sess.diagnostic().struct_dummy();
|
err.downgrade_to_delayed_bug();
|
||||||
}
|
}
|
||||||
|
|
||||||
mk_diag(self.ty_to_string(actual_ty))
|
err
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn report_mismatched_types(
|
pub fn report_mismatched_types(
|
||||||
|
@ -1496,7 +1498,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
actual: Ty<'tcx>,
|
actual: Ty<'tcx>,
|
||||||
err: TypeError<'tcx>,
|
err: TypeError<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let trace = TypeTrace::types(cause, true, expected, actual);
|
let trace = TypeTrace::types(cause, true, expected, actual);
|
||||||
self.report_and_explain_type_error(trace, &err)
|
self.report_and_explain_type_error(trace, &err)
|
||||||
}
|
}
|
||||||
|
@ -1507,7 +1509,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
expected: ty::Const<'tcx>,
|
expected: ty::Const<'tcx>,
|
||||||
actual: ty::Const<'tcx>,
|
actual: ty::Const<'tcx>,
|
||||||
err: TypeError<'tcx>,
|
err: TypeError<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let trace = TypeTrace::consts(cause, true, expected, actual);
|
let trace = TypeTrace::consts(cause, true, expected, actual);
|
||||||
self.report_and_explain_type_error(trace, &err)
|
self.report_and_explain_type_error(trace, &err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use super::ObjectSafetyViolation;
|
||||||
|
|
||||||
use crate::infer::InferCtxt;
|
use crate::infer::InferCtxt;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::{struct_span_err, DiagnosticBuilder};
|
use rustc_errors::{struct_span_err, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
@ -17,7 +17,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
impl_item_def_id: DefId,
|
impl_item_def_id: DefId,
|
||||||
trait_item_def_id: DefId,
|
trait_item_def_id: DefId,
|
||||||
requirement: &dyn fmt::Display,
|
requirement: &dyn fmt::Display,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let msg = "impl has stricter requirements than trait";
|
let msg = "impl has stricter requirements than trait";
|
||||||
let sp = self.tcx.sess.source_map().guess_head_span(error_span);
|
let sp = self.tcx.sess.source_map().guess_head_span(error_span);
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ pub fn report_object_safety_error<'tcx>(
|
||||||
span: Span,
|
span: Span,
|
||||||
trait_def_id: DefId,
|
trait_def_id: DefId,
|
||||||
violations: &[ObjectSafetyViolation],
|
violations: &[ObjectSafetyViolation],
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let trait_str = tcx.def_path_str(trait_def_id);
|
let trait_str = tcx.def_path_str(trait_def_id);
|
||||||
let trait_span = tcx.hir().get_if_local(trait_def_id).and_then(|node| match node {
|
let trait_span = tcx.hir().get_if_local(trait_def_id).and_then(|node| match node {
|
||||||
hir::Node::Item(item) => Some(item.ident.span),
|
hir::Node::Item(item) => Some(item.ident.span),
|
||||||
|
|
|
@ -102,7 +102,7 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String
|
||||||
}
|
}
|
||||||
|
|
||||||
match maybe_new_parser_from_source_str(&sess, filename, s.to_string()) {
|
match maybe_new_parser_from_source_str(&sess, filename, s.to_string()) {
|
||||||
Ok(mut parser) => match &mut parser.parse_meta_item() {
|
Ok(mut parser) => match parser.parse_meta_item() {
|
||||||
Ok(meta_item) if parser.token == token::Eof => {
|
Ok(meta_item) if parser.token == token::Eof => {
|
||||||
if meta_item.path.segments.len() != 1 {
|
if meta_item.path.segments.len() != 1 {
|
||||||
error!("argument key must be an identifier");
|
error!("argument key must be an identifier");
|
||||||
|
@ -121,7 +121,7 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String
|
||||||
Ok(..) => {}
|
Ok(..) => {}
|
||||||
Err(err) => err.cancel(),
|
Err(err) => err.cancel(),
|
||||||
},
|
},
|
||||||
Err(errs) => errs.into_iter().for_each(|mut err| err.cancel()),
|
Err(errs) => drop(errs),
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user tried to use a key="value" flag, but is missing the quotes, provide
|
// If the user tried to use a key="value" flag, but is missing the quotes, provide
|
||||||
|
@ -165,7 +165,7 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
|
||||||
}
|
}
|
||||||
|
|
||||||
match maybe_new_parser_from_source_str(&sess, filename, s.to_string()) {
|
match maybe_new_parser_from_source_str(&sess, filename, s.to_string()) {
|
||||||
Ok(mut parser) => match &mut parser.parse_meta_item() {
|
Ok(mut parser) => match parser.parse_meta_item() {
|
||||||
Ok(meta_item) if parser.token == token::Eof => {
|
Ok(meta_item) if parser.token == token::Eof => {
|
||||||
if let Some(args) = meta_item.meta_item_list() {
|
if let Some(args) = meta_item.meta_item_list() {
|
||||||
if meta_item.has_name(sym::names) {
|
if meta_item.has_name(sym::names) {
|
||||||
|
@ -214,7 +214,7 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
|
||||||
Ok(..) => {}
|
Ok(..) => {}
|
||||||
Err(err) => err.cancel(),
|
Err(err) => err.cancel(),
|
||||||
},
|
},
|
||||||
Err(errs) => errs.into_iter().for_each(|mut err| err.cancel()),
|
Err(errs) => drop(errs),
|
||||||
}
|
}
|
||||||
|
|
||||||
error!(
|
error!(
|
||||||
|
|
|
@ -31,7 +31,7 @@ use rustc_ast::{self as ast, *};
|
||||||
use rustc_ast_pretty::pprust::{self, expr_to_string};
|
use rustc_ast_pretty::pprust::{self, expr_to_string};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
|
use rustc_errors::{Applicability, Diagnostic, DiagnosticStyledString};
|
||||||
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
|
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
|
@ -1476,17 +1476,17 @@ impl TypeAliasBounds {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suggest_changing_assoc_types(ty: &hir::Ty<'_>, err: &mut DiagnosticBuilder<'_>) {
|
fn suggest_changing_assoc_types(ty: &hir::Ty<'_>, err: &mut Diagnostic) {
|
||||||
// Access to associates types should use `<T as Bound>::Assoc`, which does not need a
|
// Access to associates types should use `<T as Bound>::Assoc`, which does not need a
|
||||||
// bound. Let's see if this type does that.
|
// bound. Let's see if this type does that.
|
||||||
|
|
||||||
// We use a HIR visitor to walk the type.
|
// We use a HIR visitor to walk the type.
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
struct WalkAssocTypes<'a, 'db> {
|
struct WalkAssocTypes<'a> {
|
||||||
err: &'a mut DiagnosticBuilder<'db>,
|
err: &'a mut Diagnostic,
|
||||||
}
|
}
|
||||||
impl<'a, 'db, 'v> Visitor<'v> for WalkAssocTypes<'a, 'db> {
|
impl Visitor<'_> for WalkAssocTypes<'_> {
|
||||||
fn visit_qpath(&mut self, qpath: &'v hir::QPath<'v>, id: hir::HirId, span: Span) {
|
fn visit_qpath(&mut self, qpath: &hir::QPath<'_>, id: hir::HirId, span: Span) {
|
||||||
if TypeAliasBounds::is_type_variable_assoc(qpath) {
|
if TypeAliasBounds::is_type_variable_assoc(qpath) {
|
||||||
self.err.span_help(
|
self.err.span_help(
|
||||||
span,
|
span,
|
||||||
|
|
|
@ -319,7 +319,7 @@ impl LintStore {
|
||||||
) {
|
) {
|
||||||
let (tool_name, lint_name_only) = parse_lint_and_tool_name(lint_name);
|
let (tool_name, lint_name_only) = parse_lint_and_tool_name(lint_name);
|
||||||
if lint_name_only == crate::WARNINGS.name_lower() && level == Level::ForceWarn {
|
if lint_name_only == crate::WARNINGS.name_lower() && level == Level::ForceWarn {
|
||||||
return struct_span_err!(
|
struct_span_err!(
|
||||||
sess,
|
sess,
|
||||||
DUMMY_SP,
|
DUMMY_SP,
|
||||||
E0602,
|
E0602,
|
||||||
|
@ -327,6 +327,7 @@ impl LintStore {
|
||||||
crate::WARNINGS.name_lower()
|
crate::WARNINGS.name_lower()
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
let db = match self.check_lint_name(lint_name_only, tool_name, registered_tools) {
|
let db = match self.check_lint_name(lint_name_only, tool_name, registered_tools) {
|
||||||
CheckLintNameResult::Ok(_) => None,
|
CheckLintNameResult::Ok(_) => None,
|
||||||
|
@ -339,7 +340,7 @@ impl LintStore {
|
||||||
err.help(&format!("did you mean: `{}`", suggestion));
|
err.help(&format!("did you mean: `{}`", suggestion));
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(err)
|
Some(err.forget_guarantee())
|
||||||
}
|
}
|
||||||
CheckLintNameResult::Tool(result) => match result {
|
CheckLintNameResult::Tool(result) => match result {
|
||||||
Err((Some(_), new_name)) => Some(sess.struct_warn(&format!(
|
Err((Some(_), new_name)) => Some(sess.struct_warn(&format!(
|
||||||
|
@ -350,13 +351,16 @@ impl LintStore {
|
||||||
))),
|
))),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
CheckLintNameResult::NoTool => Some(struct_span_err!(
|
CheckLintNameResult::NoTool => Some(
|
||||||
|
struct_span_err!(
|
||||||
sess,
|
sess,
|
||||||
DUMMY_SP,
|
DUMMY_SP,
|
||||||
E0602,
|
E0602,
|
||||||
"unknown lint tool: `{}`",
|
"unknown lint tool: `{}`",
|
||||||
tool_name.unwrap()
|
tool_name.unwrap()
|
||||||
)),
|
)
|
||||||
|
.forget_guarantee(),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(mut db) = db {
|
if let Some(mut db) = db {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::late::unerased_lint_store;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
|
use rustc_errors::{struct_span_err, Applicability, Diagnostic};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::{intravisit, HirId};
|
use rustc_hir::{intravisit, HirId};
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
|
@ -150,29 +150,28 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||||
fcw_warning, specs, old_src, id_name
|
fcw_warning, specs, old_src, id_name
|
||||||
);
|
);
|
||||||
|
|
||||||
let decorate_diag_builder = |mut diag_builder: DiagnosticBuilder<'_>| {
|
let decorate_diag = |diag: &mut Diagnostic| {
|
||||||
diag_builder.span_label(src.span(), "overruled by previous forbid");
|
diag.span_label(src.span(), "overruled by previous forbid");
|
||||||
match old_src {
|
match old_src {
|
||||||
LintLevelSource::Default => {
|
LintLevelSource::Default => {
|
||||||
diag_builder.note(&format!(
|
diag.note(&format!(
|
||||||
"`forbid` lint level is the default for {}",
|
"`forbid` lint level is the default for {}",
|
||||||
id.to_string()
|
id.to_string()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
LintLevelSource::Node(_, forbid_source_span, reason) => {
|
LintLevelSource::Node(_, forbid_source_span, reason) => {
|
||||||
diag_builder.span_label(forbid_source_span, "`forbid` level set here");
|
diag.span_label(forbid_source_span, "`forbid` level set here");
|
||||||
if let Some(rationale) = reason {
|
if let Some(rationale) = reason {
|
||||||
diag_builder.note(rationale.as_str());
|
diag.note(rationale.as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LintLevelSource::CommandLine(_, _) => {
|
LintLevelSource::CommandLine(_, _) => {
|
||||||
diag_builder.note("`forbid` lint level was set on command line");
|
diag.note("`forbid` lint level was set on command line");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
diag_builder.emit();
|
|
||||||
};
|
};
|
||||||
if !fcw_warning {
|
if !fcw_warning {
|
||||||
let diag_builder = struct_span_err!(
|
let mut diag_builder = struct_span_err!(
|
||||||
self.sess,
|
self.sess,
|
||||||
src.span(),
|
src.span(),
|
||||||
E0453,
|
E0453,
|
||||||
|
@ -180,18 +179,20 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||||
level.as_str(),
|
level.as_str(),
|
||||||
src.name(),
|
src.name(),
|
||||||
);
|
);
|
||||||
decorate_diag_builder(diag_builder);
|
decorate_diag(&mut diag_builder);
|
||||||
|
diag_builder.emit();
|
||||||
} else {
|
} else {
|
||||||
self.struct_lint(
|
self.struct_lint(
|
||||||
FORBIDDEN_LINT_GROUPS,
|
FORBIDDEN_LINT_GROUPS,
|
||||||
Some(src.span().into()),
|
Some(src.span().into()),
|
||||||
|diag_builder| {
|
|diag_builder| {
|
||||||
let diag_builder = diag_builder.build(&format!(
|
let mut diag_builder = diag_builder.build(&format!(
|
||||||
"{}({}) incompatible with previous forbid",
|
"{}({}) incompatible with previous forbid",
|
||||||
level.as_str(),
|
level.as_str(),
|
||||||
src.name(),
|
src.name(),
|
||||||
));
|
));
|
||||||
decorate_diag_builder(diag_builder);
|
decorate_diag(&mut diag_builder);
|
||||||
|
diag_builder.emit();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,7 +232,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
|
||||||
fn into_diagnostic(
|
fn into_diagnostic(
|
||||||
self,
|
self,
|
||||||
#sess: &'__session_diagnostic_sess rustc_session::Session
|
#sess: &'__session_diagnostic_sess rustc_session::Session
|
||||||
) -> rustc_errors::DiagnosticBuilder<'__session_diagnostic_sess> {
|
) -> rustc_errors::DiagnosticBuilder<'__session_diagnostic_sess, rustc_errors::ErrorReported> {
|
||||||
#implementation
|
#implementation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,7 +243,9 @@ impl Collector<'_> {
|
||||||
if matches!(lib.kind, NativeLibKind::Framework { .. }) && !is_osx {
|
if matches!(lib.kind, NativeLibKind::Framework { .. }) && !is_osx {
|
||||||
let msg = "native frameworks are only available on macOS targets";
|
let msg = "native frameworks are only available on macOS targets";
|
||||||
match span {
|
match span {
|
||||||
Some(span) => struct_span_err!(self.tcx.sess, span, E0455, "{}", msg).emit(),
|
Some(span) => {
|
||||||
|
struct_span_err!(self.tcx.sess, span, E0455, "{}", msg).emit();
|
||||||
|
}
|
||||||
None => self.tcx.sess.err(msg),
|
None => self.tcx.sess.err(msg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::cmp;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_errors::{DiagnosticBuilder, DiagnosticId};
|
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId};
|
||||||
use rustc_hir::HirId;
|
use rustc_hir::HirId;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_query_system::ich::StableHashingContext;
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
|
@ -186,28 +186,28 @@ impl<'a> HashStable<StableHashingContext<'a>> for LintLevelMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LintDiagnosticBuilder<'a>(DiagnosticBuilder<'a>);
|
pub struct LintDiagnosticBuilder<'a>(DiagnosticBuilder<'a, ()>);
|
||||||
|
|
||||||
impl<'a> LintDiagnosticBuilder<'a> {
|
impl<'a> LintDiagnosticBuilder<'a> {
|
||||||
/// Return the inner DiagnosticBuilder, first setting the primary message to `msg`.
|
/// Return the inner DiagnosticBuilder, first setting the primary message to `msg`.
|
||||||
pub fn build(mut self, msg: &str) -> DiagnosticBuilder<'a> {
|
pub fn build(mut self, msg: &str) -> DiagnosticBuilder<'a, ()> {
|
||||||
self.0.set_primary_message(msg);
|
self.0.set_primary_message(msg);
|
||||||
self.0.set_is_lint();
|
self.0.set_is_lint();
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a LintDiagnosticBuilder from some existing DiagnosticBuilder.
|
/// Create a LintDiagnosticBuilder from some existing DiagnosticBuilder.
|
||||||
pub fn new(err: DiagnosticBuilder<'a>) -> LintDiagnosticBuilder<'a> {
|
pub fn new(err: DiagnosticBuilder<'a, ()>) -> LintDiagnosticBuilder<'a> {
|
||||||
LintDiagnosticBuilder(err)
|
LintDiagnosticBuilder(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn explain_lint_level_source<'s>(
|
pub fn explain_lint_level_source(
|
||||||
sess: &'s Session,
|
sess: &Session,
|
||||||
lint: &'static Lint,
|
lint: &'static Lint,
|
||||||
level: Level,
|
level: Level,
|
||||||
src: LintLevelSource,
|
src: LintLevelSource,
|
||||||
err: &mut DiagnosticBuilder<'s>,
|
err: &mut Diagnostic,
|
||||||
) {
|
) {
|
||||||
let name = lint.name_lower();
|
let name = lint.name_lower();
|
||||||
match src {
|
match src {
|
||||||
|
@ -314,10 +314,8 @@ pub fn struct_lint_level<'s, 'd>(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Level::Warn, Some(span)) => sess.struct_span_warn(span, ""),
|
(Level::Warn | Level::ForceWarn, Some(span)) => sess.struct_span_warn(span, ""),
|
||||||
(Level::Warn, None) => sess.struct_warn(""),
|
(Level::Warn | Level::ForceWarn, None) => sess.struct_warn(""),
|
||||||
(Level::ForceWarn, Some(span)) => sess.struct_span_force_warn(span, ""),
|
|
||||||
(Level::ForceWarn, None) => sess.struct_force_warn(""),
|
|
||||||
(Level::Deny | Level::Forbid, Some(span)) => {
|
(Level::Deny | Level::Forbid, Some(span)) => {
|
||||||
let mut builder = sess.diagnostic().struct_err_lint("");
|
let mut builder = sess.diagnostic().struct_err_lint("");
|
||||||
builder.set_span(span);
|
builder.set_span(span);
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::ty::{self, DefIdTree, TyCtxt};
|
||||||
use rustc_ast::NodeId;
|
use rustc_ast::NodeId;
|
||||||
use rustc_attr::{self as attr, ConstStability, Deprecation, Stability};
|
use rustc_attr::{self as attr, ConstStability, Deprecation, Stability};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, Diagnostic};
|
||||||
use rustc_feature::GateIssue;
|
use rustc_feature::GateIssue;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
|
@ -167,7 +167,7 @@ pub fn deprecation_in_effect(depr: &Deprecation) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deprecation_suggestion(
|
pub fn deprecation_suggestion(
|
||||||
diag: &mut DiagnosticBuilder<'_>,
|
diag: &mut Diagnostic,
|
||||||
kind: &str,
|
kind: &str,
|
||||||
suggestion: Option<Symbol>,
|
suggestion: Option<Symbol>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
|
|
@ -36,7 +36,10 @@ TrivialTypeFoldableAndLiftImpls! {
|
||||||
pub type EvalToAllocationRawResult<'tcx> = Result<ConstAlloc<'tcx>, ErrorHandled>;
|
pub type EvalToAllocationRawResult<'tcx> = Result<ConstAlloc<'tcx>, ErrorHandled>;
|
||||||
pub type EvalToConstValueResult<'tcx> = Result<ConstValue<'tcx>, ErrorHandled>;
|
pub type EvalToConstValueResult<'tcx> = Result<ConstValue<'tcx>, ErrorHandled>;
|
||||||
|
|
||||||
pub fn struct_error<'tcx>(tcx: TyCtxtAt<'tcx>, msg: &str) -> DiagnosticBuilder<'tcx> {
|
pub fn struct_error<'tcx>(
|
||||||
|
tcx: TyCtxtAt<'tcx>,
|
||||||
|
msg: &str,
|
||||||
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
struct_span_err!(tcx.sess, tcx.span, E0080, "{}", msg)
|
struct_span_err!(tcx.sess, tcx.span, E0080, "{}", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::ty::subst::SubstsRef;
|
||||||
use crate::ty::{self, AdtKind, Ty, TyCtxt};
|
use crate::ty::{self, AdtKind, Ty, TyCtxt};
|
||||||
|
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, Diagnostic};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
|
@ -841,7 +841,7 @@ impl ObjectSafetyViolation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn solution(&self, err: &mut DiagnosticBuilder<'_>) {
|
pub fn solution(&self, err: &mut Diagnostic) {
|
||||||
match *self {
|
match *self {
|
||||||
ObjectSafetyViolation::SizedSelf(_) | ObjectSafetyViolation::SupertraitSelf(_) => {}
|
ObjectSafetyViolation::SizedSelf(_) | ObjectSafetyViolation::SupertraitSelf(_) => {}
|
||||||
ObjectSafetyViolation::Method(
|
ObjectSafetyViolation::Method(
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::ty::{
|
||||||
ProjectionTy, Term, Ty, TyCtxt, TypeAndMut,
|
ProjectionTy, Term, Ty, TyCtxt, TypeAndMut,
|
||||||
};
|
};
|
||||||
|
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, Diagnostic};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::{QPath, TyKind, WhereBoundPredicate, WherePredicate};
|
use rustc_hir::{QPath, TyKind, WhereBoundPredicate, WherePredicate};
|
||||||
|
@ -129,7 +129,7 @@ impl<'tcx> Ty<'tcx> {
|
||||||
|
|
||||||
pub fn suggest_arbitrary_trait_bound(
|
pub fn suggest_arbitrary_trait_bound(
|
||||||
generics: &hir::Generics<'_>,
|
generics: &hir::Generics<'_>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
param_name: &str,
|
param_name: &str,
|
||||||
constraint: &str,
|
constraint: &str,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
@ -159,7 +159,7 @@ pub fn suggest_arbitrary_trait_bound(
|
||||||
|
|
||||||
fn suggest_removing_unsized_bound(
|
fn suggest_removing_unsized_bound(
|
||||||
generics: &hir::Generics<'_>,
|
generics: &hir::Generics<'_>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
param_name: &str,
|
param_name: &str,
|
||||||
param: &hir::GenericParam<'_>,
|
param: &hir::GenericParam<'_>,
|
||||||
def_id: Option<DefId>,
|
def_id: Option<DefId>,
|
||||||
|
@ -266,7 +266,7 @@ fn suggest_removing_unsized_bound(
|
||||||
pub fn suggest_constraining_type_param(
|
pub fn suggest_constraining_type_param(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
generics: &hir::Generics<'_>,
|
generics: &hir::Generics<'_>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
param_name: &str,
|
param_name: &str,
|
||||||
constraint: &str,
|
constraint: &str,
|
||||||
def_id: Option<DefId>,
|
def_id: Option<DefId>,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::ty::diagnostics::suggest_constraining_type_param;
|
||||||
use crate::ty::print::{FmtPrinter, Printer};
|
use crate::ty::print::{FmtPrinter, Printer};
|
||||||
use crate::ty::{self, BoundRegionKind, Region, Ty, TyCtxt};
|
use crate::ty::{self, BoundRegionKind, Region, Ty, TyCtxt};
|
||||||
use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect};
|
use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect};
|
||||||
use rustc_errors::{pluralize, DiagnosticBuilder};
|
use rustc_errors::{pluralize, Diagnostic};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
|
@ -347,7 +347,8 @@ impl<'tcx> Ty<'tcx> {
|
||||||
impl<'tcx> TyCtxt<'tcx> {
|
impl<'tcx> TyCtxt<'tcx> {
|
||||||
pub fn note_and_explain_type_err(
|
pub fn note_and_explain_type_err(
|
||||||
self,
|
self,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
// FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
|
||||||
|
db: &mut Diagnostic,
|
||||||
err: &TypeError<'tcx>,
|
err: &TypeError<'tcx>,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
|
@ -584,7 +585,8 @@ impl<T> Trait<T> for X {
|
||||||
|
|
||||||
fn suggest_constraint(
|
fn suggest_constraint(
|
||||||
self,
|
self,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
// FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
|
||||||
|
db: &mut Diagnostic,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
body_owner_def_id: DefId,
|
body_owner_def_id: DefId,
|
||||||
proj_ty: &ty::ProjectionTy<'tcx>,
|
proj_ty: &ty::ProjectionTy<'tcx>,
|
||||||
|
@ -671,7 +673,8 @@ impl<T> Trait<T> for X {
|
||||||
/// fn that returns the type.
|
/// fn that returns the type.
|
||||||
fn expected_projection(
|
fn expected_projection(
|
||||||
self,
|
self,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
// FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
|
||||||
|
db: &mut Diagnostic,
|
||||||
proj_ty: &ty::ProjectionTy<'tcx>,
|
proj_ty: &ty::ProjectionTy<'tcx>,
|
||||||
values: &ExpectedFound<Ty<'tcx>>,
|
values: &ExpectedFound<Ty<'tcx>>,
|
||||||
body_owner_def_id: DefId,
|
body_owner_def_id: DefId,
|
||||||
|
@ -766,7 +769,8 @@ fn foo(&self) -> Self::T { String::new() }
|
||||||
/// a return type. This can occur when dealing with `TryStream` (#71035).
|
/// a return type. This can occur when dealing with `TryStream` (#71035).
|
||||||
fn suggest_constraining_opaque_associated_type(
|
fn suggest_constraining_opaque_associated_type(
|
||||||
self,
|
self,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
// FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
|
||||||
|
db: &mut Diagnostic,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
proj_ty: &ty::ProjectionTy<'tcx>,
|
proj_ty: &ty::ProjectionTy<'tcx>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
|
@ -802,7 +806,8 @@ fn foo(&self) -> Self::T { String::new() }
|
||||||
|
|
||||||
fn point_at_methods_that_satisfy_associated_type(
|
fn point_at_methods_that_satisfy_associated_type(
|
||||||
self,
|
self,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
// FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
|
||||||
|
db: &mut Diagnostic,
|
||||||
assoc_container_id: DefId,
|
assoc_container_id: DefId,
|
||||||
current_method_ident: Option<Symbol>,
|
current_method_ident: Option<Symbol>,
|
||||||
proj_ty_item_def_id: DefId,
|
proj_ty_item_def_id: DefId,
|
||||||
|
@ -857,7 +862,8 @@ fn foo(&self) -> Self::T { String::new() }
|
||||||
|
|
||||||
fn point_at_associated_type(
|
fn point_at_associated_type(
|
||||||
self,
|
self,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
// FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
|
||||||
|
db: &mut Diagnostic,
|
||||||
body_owner_def_id: DefId,
|
body_owner_def_id: DefId,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
@ -921,7 +927,8 @@ fn foo(&self) -> Self::T { String::new() }
|
||||||
/// type is defined on a supertrait of the one present in the bounds.
|
/// type is defined on a supertrait of the one present in the bounds.
|
||||||
fn constrain_generic_bound_associated_type_structured_suggestion(
|
fn constrain_generic_bound_associated_type_structured_suggestion(
|
||||||
self,
|
self,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
// FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
|
||||||
|
db: &mut Diagnostic,
|
||||||
trait_ref: &ty::TraitRef<'tcx>,
|
trait_ref: &ty::TraitRef<'tcx>,
|
||||||
bounds: hir::GenericBounds<'_>,
|
bounds: hir::GenericBounds<'_>,
|
||||||
assoc: &ty::AssocItem,
|
assoc: &ty::AssocItem,
|
||||||
|
@ -958,7 +965,8 @@ fn foo(&self) -> Self::T { String::new() }
|
||||||
/// associated type to a given type `ty`.
|
/// associated type to a given type `ty`.
|
||||||
fn constrain_associated_type_structured_suggestion(
|
fn constrain_associated_type_structured_suggestion(
|
||||||
self,
|
self,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
// FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
|
||||||
|
db: &mut Diagnostic,
|
||||||
span: Span,
|
span: Span,
|
||||||
assoc: &ty::AssocItem,
|
assoc: &ty::AssocItem,
|
||||||
assoc_substs: &[ty::GenericArg<'tcx>],
|
assoc_substs: &[ty::GenericArg<'tcx>],
|
||||||
|
|
|
@ -6,7 +6,9 @@ use super::{PatCtxt, PatternError};
|
||||||
|
|
||||||
use rustc_arena::TypedArena;
|
use rustc_arena::TypedArena;
|
||||||
use rustc_ast::Mutability;
|
use rustc_ast::Mutability;
|
||||||
use rustc_errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder};
|
use rustc_errors::{
|
||||||
|
error_code, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorReported,
|
||||||
|
};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::*;
|
use rustc_hir::def::*;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
|
@ -36,7 +38,11 @@ crate fn check_match(tcx: TyCtxt<'_>, def_id: DefId) {
|
||||||
visitor.visit_body(tcx.hir().body(body_id));
|
visitor.visit_body(tcx.hir().body(body_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_e0004(sess: &Session, sp: Span, error_message: String) -> DiagnosticBuilder<'_> {
|
fn create_e0004(
|
||||||
|
sess: &Session,
|
||||||
|
sp: Span,
|
||||||
|
error_message: String,
|
||||||
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
struct_span_err!(sess, sp, E0004, "{}", &error_message)
|
struct_span_err!(sess, sp, E0004, "{}", &error_message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,12 +287,7 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
|
||||||
|
|
||||||
/// A path pattern was interpreted as a constant, not a new variable.
|
/// A path pattern was interpreted as a constant, not a new variable.
|
||||||
/// This caused an irrefutable match failure in e.g. `let`.
|
/// This caused an irrefutable match failure in e.g. `let`.
|
||||||
fn const_not_var(
|
fn const_not_var(err: &mut Diagnostic, tcx: TyCtxt<'_>, pat: &Pat<'_>, path: &hir::Path<'_>) {
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
tcx: TyCtxt<'_>,
|
|
||||||
pat: &Pat<'_>,
|
|
||||||
path: &hir::Path<'_>,
|
|
||||||
) {
|
|
||||||
let descr = path.res.descr();
|
let descr = path.res.descr();
|
||||||
err.span_label(
|
err.span_label(
|
||||||
pat.span,
|
pat.span,
|
||||||
|
@ -594,7 +595,7 @@ crate fn pattern_not_covered_label(
|
||||||
/// Point at the definition of non-covered `enum` variants.
|
/// Point at the definition of non-covered `enum` variants.
|
||||||
fn adt_defined_here<'p, 'tcx>(
|
fn adt_defined_here<'p, 'tcx>(
|
||||||
cx: &MatchCheckCtxt<'p, 'tcx>,
|
cx: &MatchCheckCtxt<'p, 'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
witnesses: &[DeconstructedPat<'p, 'tcx>],
|
witnesses: &[DeconstructedPat<'p, 'tcx>],
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl<'tcx> ConstMutationChecker<'_, 'tcx> {
|
||||||
place: &Place<'tcx>,
|
place: &Place<'tcx>,
|
||||||
const_item: DefId,
|
const_item: DefId,
|
||||||
location: Location,
|
location: Location,
|
||||||
decorate: impl for<'b> FnOnce(LintDiagnosticBuilder<'b>) -> DiagnosticBuilder<'b>,
|
decorate: impl for<'b> FnOnce(LintDiagnosticBuilder<'b>) -> DiagnosticBuilder<'b, ()>,
|
||||||
) {
|
) {
|
||||||
// Don't lint on borrowing/assigning when a dereference is involved.
|
// Don't lint on borrowing/assigning when a dereference is involved.
|
||||||
// If we 'leave' the temporary via a dereference, we must
|
// If we 'leave' the temporary via a dereference, we must
|
||||||
|
|
|
@ -3,7 +3,9 @@ use rustc_ast::ast::{self, AttrStyle};
|
||||||
use rustc_ast::token::{self, CommentKind, Token, TokenKind};
|
use rustc_ast::token::{self, CommentKind, Token, TokenKind};
|
||||||
use rustc_ast::tokenstream::{Spacing, TokenStream};
|
use rustc_ast::tokenstream::{Spacing, TokenStream};
|
||||||
use rustc_ast::util::unicode::contains_text_flow_control_chars;
|
use rustc_ast::util::unicode::contains_text_flow_control_chars;
|
||||||
use rustc_errors::{error_code, Applicability, DiagnosticBuilder, FatalError, PResult};
|
use rustc_errors::{
|
||||||
|
error_code, Applicability, DiagnosticBuilder, ErrorReported, FatalError, PResult,
|
||||||
|
};
|
||||||
use rustc_lexer::unescape::{self, Mode};
|
use rustc_lexer::unescape::{self, Mode};
|
||||||
use rustc_lexer::{Base, DocStyle, RawStrError};
|
use rustc_lexer::{Base, DocStyle, RawStrError};
|
||||||
use rustc_session::lint::builtin::{
|
use rustc_session::lint::builtin::{
|
||||||
|
@ -127,7 +129,7 @@ impl<'a> StringReader<'a> {
|
||||||
to_pos: BytePos,
|
to_pos: BytePos,
|
||||||
m: &str,
|
m: &str,
|
||||||
c: char,
|
c: char,
|
||||||
) -> DiagnosticBuilder<'a> {
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
self.sess
|
self.sess
|
||||||
.span_diagnostic
|
.span_diagnostic
|
||||||
.struct_span_fatal(self.mk_sp(from_pos, to_pos), &format!("{}: {}", m, escaped_char(c)))
|
.struct_span_fatal(self.mk_sp(from_pos, to_pos), &format!("{}: {}", m, escaped_char(c)))
|
||||||
|
|
|
@ -144,7 +144,7 @@ pub(crate) fn emit_unescape_error(
|
||||||
c.escape_default().to_string(),
|
c.escape_default().to_string(),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
)
|
)
|
||||||
.emit()
|
.emit();
|
||||||
}
|
}
|
||||||
EscapeError::BareCarriageReturn => {
|
EscapeError::BareCarriageReturn => {
|
||||||
let msg = if mode.in_double_quotes() {
|
let msg = if mode.in_double_quotes() {
|
||||||
|
@ -292,7 +292,8 @@ pub(crate) fn emit_unescape_error(
|
||||||
.span_label(span, "must have at most 6 hex digits")
|
.span_label(span, "must have at most 6 hex digits")
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
EscapeError::UnclosedUnicodeEscape => handler
|
EscapeError::UnclosedUnicodeEscape => {
|
||||||
|
handler
|
||||||
.struct_span_err(span, "unterminated unicode escape")
|
.struct_span_err(span, "unterminated unicode escape")
|
||||||
.span_label(span, "missing a closing `}`")
|
.span_label(span, "missing a closing `}`")
|
||||||
.span_suggestion_verbose(
|
.span_suggestion_verbose(
|
||||||
|
@ -301,7 +302,8 @@ pub(crate) fn emit_unescape_error(
|
||||||
"}".to_string(),
|
"}".to_string(),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
)
|
)
|
||||||
.emit(),
|
.emit();
|
||||||
|
}
|
||||||
EscapeError::NoBraceInUnicodeEscape => {
|
EscapeError::NoBraceInUnicodeEscape => {
|
||||||
let msg = "incorrect unicode escape sequence";
|
let msg = "incorrect unicode escape sequence";
|
||||||
let mut diag = handler.struct_span_err(span, msg);
|
let mut diag = handler.struct_span_err(span, msg);
|
||||||
|
@ -347,7 +349,7 @@ pub(crate) fn emit_unescape_error(
|
||||||
}
|
}
|
||||||
EscapeError::ZeroChars => {
|
EscapeError::ZeroChars => {
|
||||||
let msg = "empty character literal";
|
let msg = "empty character literal";
|
||||||
handler.struct_span_err(span, msg).span_label(span, msg).emit()
|
handler.struct_span_err(span, msg).span_label(span, msg).emit();
|
||||||
}
|
}
|
||||||
EscapeError::LoneSlash => {
|
EscapeError::LoneSlash => {
|
||||||
let msg = "invalid trailing slash in literal";
|
let msg = "invalid trailing slash in literal";
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use super::StringReader;
|
use super::StringReader;
|
||||||
use crate::token;
|
use crate::token;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, Diagnostic};
|
||||||
use rustc_span::{symbol::kw, BytePos, Pos, Span};
|
use rustc_span::{symbol::kw, BytePos, Pos, Span};
|
||||||
|
|
||||||
#[rustfmt::skip] // for line breaks
|
#[rustfmt::skip] // for line breaks
|
||||||
|
@ -336,7 +336,7 @@ pub(super) fn check_for_substitution<'a>(
|
||||||
reader: &StringReader<'a>,
|
reader: &StringReader<'a>,
|
||||||
pos: BytePos,
|
pos: BytePos,
|
||||||
ch: char,
|
ch: char,
|
||||||
err: &mut DiagnosticBuilder<'a>,
|
err: &mut Diagnostic,
|
||||||
) -> Option<token::TokenKind> {
|
) -> Option<token::TokenKind> {
|
||||||
let Some(&(_u_char, u_name, ascii_char)) = UNICODE_ARRAY.iter().find(|&&(c, _, _)| c == ch) else {
|
let Some(&(_u_char, u_name, ascii_char)) = UNICODE_ARRAY.iter().find(|&&(c, _, _)| c == ch) else {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use rustc_ast as ast;
|
||||||
use rustc_ast::attr;
|
use rustc_ast::attr;
|
||||||
use rustc_ast::token::{self, Nonterminal};
|
use rustc_ast::token::{self, Nonterminal};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_errors::{error_code, DiagnosticBuilder, PResult};
|
use rustc_errors::{error_code, Diagnostic, PResult};
|
||||||
use rustc_span::{sym, BytePos, Span};
|
use rustc_span::{sym, BytePos, Span};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
fn annotate_following_item_if_applicable(
|
fn annotate_following_item_if_applicable(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
span: Span,
|
span: Span,
|
||||||
attr_type: OuterAttributeType,
|
attr_type: OuterAttributeType,
|
||||||
) -> Option<Span> {
|
) -> Option<Span> {
|
||||||
|
@ -165,7 +165,7 @@ impl<'a> Parser<'a> {
|
||||||
loop {
|
loop {
|
||||||
// skip any other attributes, we want the item
|
// skip any other attributes, we want the item
|
||||||
if snapshot.token.kind == token::Pound {
|
if snapshot.token.kind == token::Pound {
|
||||||
if let Err(mut err) = snapshot.parse_attribute(InnerAttrPolicy::Permitted) {
|
if let Err(err) = snapshot.parse_attribute(InnerAttrPolicy::Permitted) {
|
||||||
err.cancel();
|
err.cancel();
|
||||||
return Some(replacement_span);
|
return Some(replacement_span);
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ impl<'a> Parser<'a> {
|
||||||
);
|
);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Err(mut item_err) => {
|
Err(item_err) => {
|
||||||
item_err.cancel();
|
item_err.cancel();
|
||||||
}
|
}
|
||||||
Ok(None) => {}
|
Ok(None) => {}
|
||||||
|
@ -412,12 +412,12 @@ impl<'a> Parser<'a> {
|
||||||
fn parse_meta_item_inner(&mut self) -> PResult<'a, ast::NestedMetaItem> {
|
fn parse_meta_item_inner(&mut self) -> PResult<'a, ast::NestedMetaItem> {
|
||||||
match self.parse_unsuffixed_lit() {
|
match self.parse_unsuffixed_lit() {
|
||||||
Ok(lit) => return Ok(ast::NestedMetaItem::Literal(lit)),
|
Ok(lit) => return Ok(ast::NestedMetaItem::Literal(lit)),
|
||||||
Err(ref mut err) => err.cancel(),
|
Err(err) => err.cancel(),
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.parse_meta_item() {
|
match self.parse_meta_item() {
|
||||||
Ok(mi) => return Ok(ast::NestedMetaItem::MetaItem(mi)),
|
Ok(mi) => return Ok(ast::NestedMetaItem::MetaItem(mi)),
|
||||||
Err(ref mut err) => err.cancel(),
|
Err(err) => err.cancel(),
|
||||||
}
|
}
|
||||||
|
|
||||||
let found = pprust::token_to_string(&self.token);
|
let found = pprust::token_to_string(&self.token);
|
||||||
|
|
|
@ -16,7 +16,7 @@ use rustc_ast::{
|
||||||
};
|
};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::{pluralize, struct_span_err};
|
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorReported};
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder, Handler, PResult};
|
use rustc_errors::{Applicability, DiagnosticBuilder, Handler, PResult};
|
||||||
use rustc_span::source_map::Spanned;
|
use rustc_span::source_map::Spanned;
|
||||||
use rustc_span::symbol::{kw, Ident};
|
use rustc_span::symbol::{kw, Ident};
|
||||||
|
@ -53,7 +53,11 @@ pub enum Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
fn span_err(self, sp: impl Into<MultiSpan>, handler: &Handler) -> DiagnosticBuilder<'_> {
|
fn span_err(
|
||||||
|
self,
|
||||||
|
sp: impl Into<MultiSpan>,
|
||||||
|
handler: &Handler,
|
||||||
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
match self {
|
match self {
|
||||||
Error::UselessDocComment => {
|
Error::UselessDocComment => {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
|
@ -151,11 +155,19 @@ impl AttemptLocalParseRecovery {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Parser<'a> {
|
impl<'a> Parser<'a> {
|
||||||
pub(super) fn span_err<S: Into<MultiSpan>>(&self, sp: S, err: Error) -> DiagnosticBuilder<'a> {
|
pub(super) fn span_err<S: Into<MultiSpan>>(
|
||||||
|
&self,
|
||||||
|
sp: S,
|
||||||
|
err: Error,
|
||||||
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
err.span_err(sp, self.diagnostic())
|
err.span_err(sp, self.diagnostic())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn struct_span_err<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> DiagnosticBuilder<'a> {
|
pub fn struct_span_err<S: Into<MultiSpan>>(
|
||||||
|
&self,
|
||||||
|
sp: S,
|
||||||
|
m: &str,
|
||||||
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
self.sess.span_diagnostic.struct_span_err(sp, m)
|
self.sess.span_diagnostic.struct_span_err(sp, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +183,7 @@ impl<'a> Parser<'a> {
|
||||||
self.sess.source_map().span_to_snippet(span)
|
self.sess.source_map().span_to_snippet(span)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn expected_ident_found(&self) -> DiagnosticBuilder<'a> {
|
pub(super) fn expected_ident_found(&self) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
let mut err = self.struct_span_err(
|
let mut err = self.struct_span_err(
|
||||||
self.token.span,
|
self.token.span,
|
||||||
&format!("expected identifier, found {}", super::token_descr(&self.token)),
|
&format!("expected identifier, found {}", super::token_descr(&self.token)),
|
||||||
|
@ -393,7 +405,7 @@ impl<'a> Parser<'a> {
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_too_many_raw_str_terminators(&mut self, err: &mut DiagnosticBuilder<'_>) -> bool {
|
fn check_too_many_raw_str_terminators(&mut self, err: &mut Diagnostic) -> bool {
|
||||||
match (&self.prev_token.kind, &self.token.kind) {
|
match (&self.prev_token.kind, &self.token.kind) {
|
||||||
(
|
(
|
||||||
TokenKind::Literal(Lit {
|
TokenKind::Literal(Lit {
|
||||||
|
@ -461,12 +473,12 @@ impl<'a> Parser<'a> {
|
||||||
tail.could_be_bare_literal = true;
|
tail.could_be_bare_literal = true;
|
||||||
Ok(tail)
|
Ok(tail)
|
||||||
}
|
}
|
||||||
(Err(mut err), Ok(tail)) => {
|
(Err(err), Ok(tail)) => {
|
||||||
// We have a block tail that contains a somehow valid type ascription expr.
|
// We have a block tail that contains a somehow valid type ascription expr.
|
||||||
err.cancel();
|
err.cancel();
|
||||||
Ok(tail)
|
Ok(tail)
|
||||||
}
|
}
|
||||||
(Err(mut snapshot_err), Err(err)) => {
|
(Err(snapshot_err), Err(err)) => {
|
||||||
// We don't know what went wrong, emit the normal error.
|
// We don't know what went wrong, emit the normal error.
|
||||||
snapshot_err.cancel();
|
snapshot_err.cancel();
|
||||||
self.consume_block(token::Brace, ConsumeClosingDelim::Yes);
|
self.consume_block(token::Brace, ConsumeClosingDelim::Yes);
|
||||||
|
@ -483,7 +495,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
pub fn maybe_annotate_with_ascription(
|
pub fn maybe_annotate_with_ascription(
|
||||||
&mut self,
|
&mut self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
maybe_expected_semicolon: bool,
|
maybe_expected_semicolon: bool,
|
||||||
) {
|
) {
|
||||||
if let Some((sp, likely_path)) = self.last_type_ascription.take() {
|
if let Some((sp, likely_path)) = self.last_type_ascription.take() {
|
||||||
|
@ -537,7 +549,7 @@ impl<'a> Parser<'a> {
|
||||||
/// Eats and discards tokens until one of `kets` is encountered. Respects token trees,
|
/// Eats and discards tokens until one of `kets` is encountered. Respects token trees,
|
||||||
/// passes through any errors encountered. Used for error recovery.
|
/// passes through any errors encountered. Used for error recovery.
|
||||||
pub(super) fn eat_to_tokens(&mut self, kets: &[&TokenKind]) {
|
pub(super) fn eat_to_tokens(&mut self, kets: &[&TokenKind]) {
|
||||||
if let Err(ref mut err) =
|
if let Err(err) =
|
||||||
self.parse_seq_to_before_tokens(kets, SeqSep::none(), TokenExpectType::Expect, |p| {
|
self.parse_seq_to_before_tokens(kets, SeqSep::none(), TokenExpectType::Expect, |p| {
|
||||||
Ok(p.parse_token_tree())
|
Ok(p.parse_token_tree())
|
||||||
})
|
})
|
||||||
|
@ -703,7 +715,7 @@ impl<'a> Parser<'a> {
|
||||||
*self = snapshot;
|
*self = snapshot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(mut err) => {
|
Err(err) => {
|
||||||
// We couldn't parse generic parameters, unlikely to be a turbofish. Rely on
|
// We couldn't parse generic parameters, unlikely to be a turbofish. Rely on
|
||||||
// generic parse error instead.
|
// generic parse error instead.
|
||||||
err.cancel();
|
err.cancel();
|
||||||
|
@ -717,7 +729,7 @@ impl<'a> Parser<'a> {
|
||||||
/// encounter a parse error when encountering the first `,`.
|
/// encounter a parse error when encountering the first `,`.
|
||||||
pub(super) fn check_mistyped_turbofish_with_multiple_type_params(
|
pub(super) fn check_mistyped_turbofish_with_multiple_type_params(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut e: DiagnosticBuilder<'a>,
|
mut e: DiagnosticBuilder<'a, ErrorReported>,
|
||||||
expr: &mut P<Expr>,
|
expr: &mut P<Expr>,
|
||||||
) -> PResult<'a, ()> {
|
) -> PResult<'a, ()> {
|
||||||
if let ExprKind::Binary(binop, _, _) = &expr.kind {
|
if let ExprKind::Binary(binop, _, _) = &expr.kind {
|
||||||
|
@ -744,14 +756,14 @@ impl<'a> Parser<'a> {
|
||||||
self.mk_expr_err(expr.span.to(self.prev_token.span));
|
self.mk_expr_err(expr.span.to(self.prev_token.span));
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
Err(mut err) => {
|
Err(err) => {
|
||||||
*expr = self.mk_expr_err(expr.span);
|
*expr = self.mk_expr_err(expr.span);
|
||||||
err.cancel();
|
err.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(mut err) => {
|
Err(err) => {
|
||||||
err.cancel();
|
err.cancel();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -767,7 +779,7 @@ impl<'a> Parser<'a> {
|
||||||
/// parenthesising the leftmost comparison.
|
/// parenthesising the leftmost comparison.
|
||||||
fn attempt_chained_comparison_suggestion(
|
fn attempt_chained_comparison_suggestion(
|
||||||
&mut self,
|
&mut self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
inner_op: &Expr,
|
inner_op: &Expr,
|
||||||
outer_op: &Spanned<AssocOp>,
|
outer_op: &Spanned<AssocOp>,
|
||||||
) -> bool /* advanced the cursor */ {
|
) -> bool /* advanced the cursor */ {
|
||||||
|
@ -821,7 +833,7 @@ impl<'a> Parser<'a> {
|
||||||
enclose(r1.span, r2.span);
|
enclose(r1.span, r2.span);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Err(mut expr_err) => {
|
Err(expr_err) => {
|
||||||
expr_err.cancel();
|
expr_err.cancel();
|
||||||
*self = snapshot;
|
*self = snapshot;
|
||||||
false
|
false
|
||||||
|
@ -838,7 +850,7 @@ impl<'a> Parser<'a> {
|
||||||
enclose(l1.span, r1.span);
|
enclose(l1.span, r1.span);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Err(mut expr_err) => {
|
Err(expr_err) => {
|
||||||
expr_err.cancel();
|
expr_err.cancel();
|
||||||
*self = snapshot;
|
*self = snapshot;
|
||||||
false
|
false
|
||||||
|
@ -890,7 +902,7 @@ impl<'a> Parser<'a> {
|
||||||
"comparison operators cannot be chained",
|
"comparison operators cannot be chained",
|
||||||
);
|
);
|
||||||
|
|
||||||
let suggest = |err: &mut DiagnosticBuilder<'_>| {
|
let suggest = |err: &mut Diagnostic| {
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
op.span.shrink_to_lo(),
|
op.span.shrink_to_lo(),
|
||||||
TURBOFISH_SUGGESTION_STR,
|
TURBOFISH_SUGGESTION_STR,
|
||||||
|
@ -938,7 +950,7 @@ impl<'a> Parser<'a> {
|
||||||
// `ExprKind::Err` placeholder.
|
// `ExprKind::Err` placeholder.
|
||||||
mk_err_expr(self, inner_op.span.to(self.prev_token.span))
|
mk_err_expr(self, inner_op.span.to(self.prev_token.span))
|
||||||
}
|
}
|
||||||
Err(mut expr_err) => {
|
Err(expr_err) => {
|
||||||
expr_err.cancel();
|
expr_err.cancel();
|
||||||
// Not entirely sure now, but we bubble the error up with the
|
// Not entirely sure now, but we bubble the error up with the
|
||||||
// suggestion.
|
// suggestion.
|
||||||
|
@ -1439,7 +1451,7 @@ impl<'a> Parser<'a> {
|
||||||
pub(super) fn recover_closing_delimiter(
|
pub(super) fn recover_closing_delimiter(
|
||||||
&mut self,
|
&mut self,
|
||||||
tokens: &[TokenKind],
|
tokens: &[TokenKind],
|
||||||
mut err: DiagnosticBuilder<'a>,
|
mut err: DiagnosticBuilder<'a, ErrorReported>,
|
||||||
) -> PResult<'a, bool> {
|
) -> PResult<'a, bool> {
|
||||||
let mut pos = None;
|
let mut pos = None;
|
||||||
// We want to use the last closing delim that would apply.
|
// We want to use the last closing delim that would apply.
|
||||||
|
@ -1637,7 +1649,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
pub(super) fn parameter_without_type(
|
pub(super) fn parameter_without_type(
|
||||||
&mut self,
|
&mut self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
pat: P<ast::Pat>,
|
pat: P<ast::Pat>,
|
||||||
require_name: bool,
|
require_name: bool,
|
||||||
first_param: bool,
|
first_param: bool,
|
||||||
|
@ -1810,7 +1822,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn expected_expression_found(&self) -> DiagnosticBuilder<'a> {
|
pub(super) fn expected_expression_found(&self) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
let (span, msg) = match (&self.token.kind, self.subparser_name) {
|
let (span, msg) = match (&self.token.kind, self.subparser_name) {
|
||||||
(&token::Eof, Some(origin)) => {
|
(&token::Eof, Some(origin)) => {
|
||||||
let sp = self.sess.source_map().next_point(self.prev_token.span);
|
let sp = self.sess.source_map().next_point(self.prev_token.span);
|
||||||
|
@ -1946,17 +1958,14 @@ impl<'a> Parser<'a> {
|
||||||
Ok(expr)
|
Ok(expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recover_const_param_decl(
|
fn recover_const_param_decl(&mut self, ty_generics: Option<&Generics>) -> Option<GenericArg> {
|
||||||
&mut self,
|
|
||||||
ty_generics: Option<&Generics>,
|
|
||||||
) -> PResult<'a, Option<GenericArg>> {
|
|
||||||
let snapshot = self.clone();
|
let snapshot = self.clone();
|
||||||
let param = match self.parse_const_param(vec![]) {
|
let param = match self.parse_const_param(vec![]) {
|
||||||
Ok(param) => param,
|
Ok(param) => param,
|
||||||
Err(mut err) => {
|
Err(err) => {
|
||||||
err.cancel();
|
err.cancel();
|
||||||
*self = snapshot;
|
*self = snapshot;
|
||||||
return Err(err);
|
return None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut err =
|
let mut err =
|
||||||
|
@ -1977,7 +1986,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
let value = self.mk_expr_err(param.span());
|
let value = self.mk_expr_err(param.span());
|
||||||
err.emit();
|
err.emit();
|
||||||
return Ok(Some(GenericArg::Const(AnonConst { id: ast::DUMMY_NODE_ID, value })));
|
Some(GenericArg::Const(AnonConst { id: ast::DUMMY_NODE_ID, value }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn recover_const_param_declaration(
|
pub fn recover_const_param_declaration(
|
||||||
|
@ -1985,8 +1994,8 @@ impl<'a> Parser<'a> {
|
||||||
ty_generics: Option<&Generics>,
|
ty_generics: Option<&Generics>,
|
||||||
) -> PResult<'a, Option<GenericArg>> {
|
) -> PResult<'a, Option<GenericArg>> {
|
||||||
// We have to check for a few different cases.
|
// We have to check for a few different cases.
|
||||||
if let Ok(arg) = self.recover_const_param_decl(ty_generics) {
|
if let Some(arg) = self.recover_const_param_decl(ty_generics) {
|
||||||
return Ok(arg);
|
return Ok(Some(arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We haven't consumed `const` yet.
|
// We haven't consumed `const` yet.
|
||||||
|
@ -2019,7 +2028,7 @@ impl<'a> Parser<'a> {
|
||||||
pub fn recover_const_arg(
|
pub fn recover_const_arg(
|
||||||
&mut self,
|
&mut self,
|
||||||
start: Span,
|
start: Span,
|
||||||
mut err: DiagnosticBuilder<'a>,
|
mut err: DiagnosticBuilder<'a, ErrorReported>,
|
||||||
) -> PResult<'a, GenericArg> {
|
) -> PResult<'a, GenericArg> {
|
||||||
let is_op = AssocOp::from_token(&self.token)
|
let is_op = AssocOp::from_token(&self.token)
|
||||||
.and_then(|op| {
|
.and_then(|op| {
|
||||||
|
@ -2085,7 +2094,7 @@ impl<'a> Parser<'a> {
|
||||||
return Ok(GenericArg::Const(AnonConst { id: ast::DUMMY_NODE_ID, value }));
|
return Ok(GenericArg::Const(AnonConst { id: ast::DUMMY_NODE_ID, value }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(mut err) => {
|
Err(err) => {
|
||||||
err.cancel();
|
err.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2099,7 +2108,7 @@ impl<'a> Parser<'a> {
|
||||||
pub(super) fn incorrect_move_async_order_found(
|
pub(super) fn incorrect_move_async_order_found(
|
||||||
&self,
|
&self,
|
||||||
move_async_span: Span,
|
move_async_span: Span,
|
||||||
) -> DiagnosticBuilder<'a> {
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
let mut err =
|
let mut err =
|
||||||
self.struct_span_err(move_async_span, "the order of `move` and `async` is incorrect");
|
self.struct_span_err(move_async_span, "the order of `move` and `async` is incorrect");
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
|
@ -2139,7 +2148,7 @@ impl<'a> Parser<'a> {
|
||||||
Err(mut err) => {
|
Err(mut err) => {
|
||||||
self.bump(); // Skip the `:`.
|
self.bump(); // Skip the `:`.
|
||||||
match self.parse_pat_no_top_alt(expected) {
|
match self.parse_pat_no_top_alt(expected) {
|
||||||
Err(mut inner_err) => {
|
Err(inner_err) => {
|
||||||
// Carry on as if we had not done anything, callers will emit a
|
// Carry on as if we had not done anything, callers will emit a
|
||||||
// reasonable error.
|
// reasonable error.
|
||||||
inner_err.cancel();
|
inner_err.cancel();
|
||||||
|
@ -2246,7 +2255,7 @@ impl<'a> Parser<'a> {
|
||||||
// suggestion-enhanced error here rather than choking on the comma later.
|
// suggestion-enhanced error here rather than choking on the comma later.
|
||||||
let comma_span = self.token.span;
|
let comma_span = self.token.span;
|
||||||
self.bump();
|
self.bump();
|
||||||
if let Err(mut err) = self.skip_pat_list() {
|
if let Err(err) = self.skip_pat_list() {
|
||||||
// We didn't expect this to work anyway; we just wanted to advance to the
|
// We didn't expect this to work anyway; we just wanted to advance to the
|
||||||
// end of the comma-sequence so we know the span to suggest parenthesizing.
|
// end of the comma-sequence so we know the span to suggest parenthesizing.
|
||||||
err.cancel();
|
err.cancel();
|
||||||
|
|
|
@ -17,7 +17,7 @@ use rustc_ast::{self as ast, AttrStyle, AttrVec, CaptureBy, ExprField, Lit, UnOp
|
||||||
use rustc_ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, MacCall, Param, Ty, TyKind};
|
use rustc_ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, MacCall, Param, Ty, TyKind};
|
||||||
use rustc_ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits};
|
use rustc_ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder, PResult};
|
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorReported, PResult};
|
||||||
use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP;
|
use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP;
|
||||||
use rustc_session::lint::BuiltinLintDiagnostics;
|
use rustc_session::lint::BuiltinLintDiagnostics;
|
||||||
use rustc_span::edition::LATEST_STABLE_EDITION;
|
use rustc_span::edition::LATEST_STABLE_EDITION;
|
||||||
|
@ -684,7 +684,7 @@ impl<'a> Parser<'a> {
|
||||||
let parser_snapshot_before_type = self.clone();
|
let parser_snapshot_before_type = self.clone();
|
||||||
let cast_expr = match self.parse_as_cast_ty() {
|
let cast_expr = match self.parse_as_cast_ty() {
|
||||||
Ok(rhs) => mk_expr(self, lhs, rhs),
|
Ok(rhs) => mk_expr(self, lhs, rhs),
|
||||||
Err(mut type_err) => {
|
Err(type_err) => {
|
||||||
// Rewind to before attempting to parse the type with generics, to recover
|
// Rewind to before attempting to parse the type with generics, to recover
|
||||||
// from situations like `x as usize < y` in which we first tried to parse
|
// from situations like `x as usize < y` in which we first tried to parse
|
||||||
// `usize < y` as a type with generic arguments.
|
// `usize < y` as a type with generic arguments.
|
||||||
|
@ -717,7 +717,7 @@ impl<'a> Parser<'a> {
|
||||||
.emit();
|
.emit();
|
||||||
return Ok(expr);
|
return Ok(expr);
|
||||||
}
|
}
|
||||||
Err(mut err) => {
|
Err(err) => {
|
||||||
err.cancel();
|
err.cancel();
|
||||||
*self = snapshot;
|
*self = snapshot;
|
||||||
}
|
}
|
||||||
|
@ -773,7 +773,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
expr
|
expr
|
||||||
}
|
}
|
||||||
Err(mut path_err) => {
|
Err(path_err) => {
|
||||||
// Couldn't parse as a path, return original error and parser state.
|
// Couldn't parse as a path, return original error and parser state.
|
||||||
path_err.cancel();
|
path_err.cancel();
|
||||||
*self = parser_snapshot_after_type;
|
*self = parser_snapshot_after_type;
|
||||||
|
@ -1127,7 +1127,7 @@ impl<'a> Parser<'a> {
|
||||||
snapshot: Option<(Self, ExprKind)>,
|
snapshot: Option<(Self, ExprKind)>,
|
||||||
) -> Option<P<Expr>> {
|
) -> Option<P<Expr>> {
|
||||||
match (seq.as_mut(), snapshot) {
|
match (seq.as_mut(), snapshot) {
|
||||||
(Err(ref mut err), Some((mut snapshot, ExprKind::Path(None, path)))) => {
|
(Err(err), Some((mut snapshot, ExprKind::Path(None, path)))) => {
|
||||||
let name = pprust::path_to_string(&path);
|
let name = pprust::path_to_string(&path);
|
||||||
snapshot.bump(); // `(`
|
snapshot.bump(); // `(`
|
||||||
match snapshot.parse_struct_fields(path, false, token::Paren) {
|
match snapshot.parse_struct_fields(path, false, token::Paren) {
|
||||||
|
@ -1138,11 +1138,12 @@ impl<'a> Parser<'a> {
|
||||||
let close_paren = self.prev_token.span;
|
let close_paren = self.prev_token.span;
|
||||||
let span = lo.to(self.prev_token.span);
|
let span = lo.to(self.prev_token.span);
|
||||||
if !fields.is_empty() {
|
if !fields.is_empty() {
|
||||||
err.cancel();
|
let replacement_err = self.struct_span_err(
|
||||||
let mut err = self.struct_span_err(
|
|
||||||
span,
|
span,
|
||||||
"invalid `struct` delimiters or `fn` call arguments",
|
"invalid `struct` delimiters or `fn` call arguments",
|
||||||
);
|
);
|
||||||
|
mem::replace(err, replacement_err).cancel();
|
||||||
|
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion(
|
||||||
&format!("if `{}` is a struct, use braces as delimiters", name),
|
&format!("if `{}` is a struct, use braces as delimiters", name),
|
||||||
vec![
|
vec![
|
||||||
|
@ -1166,7 +1167,9 @@ impl<'a> Parser<'a> {
|
||||||
return Some(self.mk_expr_err(span));
|
return Some(self.mk_expr_err(span));
|
||||||
}
|
}
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(mut err) => err.emit(),
|
Err(mut err) => {
|
||||||
|
err.emit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -1622,9 +1625,11 @@ impl<'a> Parser<'a> {
|
||||||
};
|
};
|
||||||
if let Some(expr) = expr {
|
if let Some(expr) = expr {
|
||||||
if matches!(expr.kind, ExprKind::Err) {
|
if matches!(expr.kind, ExprKind::Err) {
|
||||||
self.diagnostic()
|
let mut err = self
|
||||||
.delay_span_bug(self.token.span, &"invalid interpolated expression");
|
.diagnostic()
|
||||||
return self.diagnostic().struct_dummy();
|
.struct_span_err(self.token.span, &"invalid interpolated expression");
|
||||||
|
err.downgrade_to_delayed_bug();
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1816,6 +1821,7 @@ impl<'a> Parser<'a> {
|
||||||
err
|
err
|
||||||
} else {
|
} else {
|
||||||
self.struct_span_err(sp, &format!("suffixes on {} are invalid", kind))
|
self.struct_span_err(sp, &format!("suffixes on {} are invalid", kind))
|
||||||
|
.forget_guarantee()
|
||||||
};
|
};
|
||||||
err.span_label(sp, format!("invalid suffix `{}`", suf));
|
err.span_label(sp, format!("invalid suffix `{}`", suf));
|
||||||
err.emit();
|
err.emit();
|
||||||
|
@ -1876,7 +1882,7 @@ impl<'a> Parser<'a> {
|
||||||
*self = snapshot;
|
*self = snapshot;
|
||||||
Some(self.mk_expr_err(arr.span))
|
Some(self.mk_expr_err(arr.span))
|
||||||
}
|
}
|
||||||
Err(mut e) => {
|
Err(e) => {
|
||||||
e.cancel();
|
e.cancel();
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -2097,9 +2103,9 @@ impl<'a> Parser<'a> {
|
||||||
fn error_missing_if_then_block(
|
fn error_missing_if_then_block(
|
||||||
&self,
|
&self,
|
||||||
if_span: Span,
|
if_span: Span,
|
||||||
err: Option<DiagnosticBuilder<'a>>,
|
err: Option<DiagnosticBuilder<'a, ErrorReported>>,
|
||||||
binop_span: Option<Span>,
|
binop_span: Option<Span>,
|
||||||
) -> DiagnosticBuilder<'a> {
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
let msg = "this `if` expression has a condition, but no block";
|
let msg = "this `if` expression has a condition, but no block";
|
||||||
|
|
||||||
let mut err = if let Some(mut err) = err {
|
let mut err = if let Some(mut err) = err {
|
||||||
|
@ -2379,7 +2385,7 @@ impl<'a> Parser<'a> {
|
||||||
return Some(err(self, stmts));
|
return Some(err(self, stmts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(mut err) => {
|
Err(err) => {
|
||||||
err.cancel();
|
err.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2396,7 +2402,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
// We couldn't parse either yet another statement missing it's
|
// We couldn't parse either yet another statement missing it's
|
||||||
// enclosing block nor the next arm's pattern or closing brace.
|
// enclosing block nor the next arm's pattern or closing brace.
|
||||||
Err(mut stmt_err) => {
|
Err(stmt_err) => {
|
||||||
stmt_err.cancel();
|
stmt_err.cancel();
|
||||||
*self = start_snapshot;
|
*self = start_snapshot;
|
||||||
break;
|
break;
|
||||||
|
@ -2653,7 +2659,7 @@ impl<'a> Parser<'a> {
|
||||||
let mut base = ast::StructRest::None;
|
let mut base = ast::StructRest::None;
|
||||||
let mut recover_async = false;
|
let mut recover_async = false;
|
||||||
|
|
||||||
let mut async_block_err = |e: &mut DiagnosticBuilder<'_>, span: Span| {
|
let mut async_block_err = |e: &mut Diagnostic, span: Span| {
|
||||||
recover_async = true;
|
recover_async = true;
|
||||||
e.span_label(span, "`async` blocks are only allowed in Rust 2018 or later");
|
e.span_label(span, "`async` blocks are only allowed in Rust 2018 or later");
|
||||||
e.help(&format!("set `edition = \"{}\"` in `Cargo.toml`", LATEST_STABLE_EDITION));
|
e.help(&format!("set `edition = \"{}\"` in `Cargo.toml`", LATEST_STABLE_EDITION));
|
||||||
|
|
|
@ -130,7 +130,7 @@ impl<'a> Parser<'a> {
|
||||||
// FIXME - try to continue parsing other generics?
|
// FIXME - try to continue parsing other generics?
|
||||||
return Ok((None, TrailingToken::None));
|
return Ok((None, TrailingToken::None));
|
||||||
}
|
}
|
||||||
Err(mut err) => {
|
Err(err) => {
|
||||||
err.cancel();
|
err.cancel();
|
||||||
// FIXME - maybe we should overwrite 'self' outside of `collect_tokens`?
|
// FIXME - maybe we should overwrite 'self' outside of `collect_tokens`?
|
||||||
*this = snapshot;
|
*this = snapshot;
|
||||||
|
|
|
@ -13,7 +13,7 @@ use rustc_ast::{EnumDef, FieldDef, Generics, TraitRef, Ty, TyKind, Variant, Vari
|
||||||
use rustc_ast::{FnHeader, ForeignItem, Path, PathSegment, Visibility, VisibilityKind};
|
use rustc_ast::{FnHeader, ForeignItem, Path, PathSegment, Visibility, VisibilityKind};
|
||||||
use rustc_ast::{MacArgs, MacCall, MacDelimiter};
|
use rustc_ast::{MacArgs, MacCall, MacDelimiter};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_errors::{struct_span_err, Applicability, PResult, StashKey};
|
use rustc_errors::{struct_span_err, Applicability, ErrorReported, PResult, StashKey};
|
||||||
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
|
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
|
||||||
use rustc_span::lev_distance::lev_distance;
|
use rustc_span::lev_distance::lev_distance;
|
||||||
use rustc_span::source_map::{self, Span};
|
use rustc_span::source_map::{self, Span};
|
||||||
|
@ -801,7 +801,7 @@ impl<'a> Parser<'a> {
|
||||||
before_where_clause_span: Span,
|
before_where_clause_span: Span,
|
||||||
after_predicates: &[WherePredicate],
|
after_predicates: &[WherePredicate],
|
||||||
after_where_clause_span: Span,
|
after_where_clause_span: Span,
|
||||||
) {
|
) -> ErrorReported {
|
||||||
let mut err =
|
let mut err =
|
||||||
self.struct_span_err(after_where_clause_span, "where clause not allowed here");
|
self.struct_span_err(after_where_clause_span, "where clause not allowed here");
|
||||||
if !after_predicates.is_empty() {
|
if !after_predicates.is_empty() {
|
||||||
|
@ -1114,7 +1114,7 @@ impl<'a> Parser<'a> {
|
||||||
// Only try to recover if this is implementing a trait for a type
|
// Only try to recover if this is implementing a trait for a type
|
||||||
let mut impl_info = match self.parse_item_impl(attrs, defaultness) {
|
let mut impl_info = match self.parse_item_impl(attrs, defaultness) {
|
||||||
Ok(impl_info) => impl_info,
|
Ok(impl_info) => impl_info,
|
||||||
Err(mut recovery_error) => {
|
Err(recovery_error) => {
|
||||||
// Recovery failed, raise the "expected identifier" error
|
// Recovery failed, raise the "expected identifier" error
|
||||||
recovery_error.cancel();
|
recovery_error.cancel();
|
||||||
return Err(err);
|
return Err(err);
|
||||||
|
@ -1476,7 +1476,9 @@ impl<'a> Parser<'a> {
|
||||||
// after the comma
|
// after the comma
|
||||||
self.eat(&token::Comma);
|
self.eat(&token::Comma);
|
||||||
// `check_trailing_angle_brackets` already emitted a nicer error
|
// `check_trailing_angle_brackets` already emitted a nicer error
|
||||||
err.cancel();
|
// NOTE(eddyb) this was `.cancel()`, but `err`
|
||||||
|
// gets returned, so we can't fully defuse it.
|
||||||
|
err.downgrade_to_delayed_bug();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2073,7 +2075,7 @@ impl<'a> Parser<'a> {
|
||||||
if let Ok(snippet) = self.span_to_snippet(sp) {
|
if let Ok(snippet) = self.span_to_snippet(sp) {
|
||||||
let current_vis = match self.parse_visibility(FollowedByType::No) {
|
let current_vis = match self.parse_visibility(FollowedByType::No) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(mut d) => {
|
Err(d) => {
|
||||||
d.cancel();
|
d.cancel();
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
@ -2216,7 +2218,7 @@ impl<'a> Parser<'a> {
|
||||||
// If this is a C-variadic argument and we hit an error, return the error.
|
// If this is a C-variadic argument and we hit an error, return the error.
|
||||||
Err(err) if this.token == token::DotDotDot => return Err(err),
|
Err(err) if this.token == token::DotDotDot => return Err(err),
|
||||||
// Recover from attempting to parse the argument as a type without pattern.
|
// Recover from attempting to parse the argument as a type without pattern.
|
||||||
Err(mut err) => {
|
Err(err) => {
|
||||||
err.cancel();
|
err.cancel();
|
||||||
*this = parser_snapshot_before_ty;
|
*this = parser_snapshot_before_ty;
|
||||||
this.recover_arg_parse()?
|
this.recover_arg_parse()?
|
||||||
|
@ -2358,7 +2360,7 @@ impl<'a> Parser<'a> {
|
||||||
match self
|
match self
|
||||||
.parse_outer_attributes()
|
.parse_outer_attributes()
|
||||||
.and_then(|_| self.parse_self_param())
|
.and_then(|_| self.parse_self_param())
|
||||||
.map_err(|mut e| e.cancel())
|
.map_err(|e| e.cancel())
|
||||||
{
|
{
|
||||||
Ok(Some(_)) => "method",
|
Ok(Some(_)) => "method",
|
||||||
_ => "function",
|
_ => "function",
|
||||||
|
|
|
@ -32,7 +32,7 @@ use rustc_ast_pretty::pprust;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_errors::PResult;
|
use rustc_errors::PResult;
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, FatalError};
|
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported, FatalError};
|
||||||
use rustc_session::parse::ParseSess;
|
use rustc_session::parse::ParseSess;
|
||||||
use rustc_span::source_map::{MultiSpan, Span, DUMMY_SP};
|
use rustc_span::source_map::{MultiSpan, Span, DUMMY_SP};
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
|
@ -849,7 +849,7 @@ impl<'a> Parser<'a> {
|
||||||
v.push(t);
|
v.push(t);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Err(mut e) => {
|
Err(e) => {
|
||||||
// Parsing failed, therefore it must be something more serious
|
// Parsing failed, therefore it must be something more serious
|
||||||
// than just a missing separator.
|
// than just a missing separator.
|
||||||
expect_err.emit();
|
expect_err.emit();
|
||||||
|
@ -877,7 +877,7 @@ impl<'a> Parser<'a> {
|
||||||
fn recover_missing_braces_around_closure_body(
|
fn recover_missing_braces_around_closure_body(
|
||||||
&mut self,
|
&mut self,
|
||||||
closure_spans: ClosureSpans,
|
closure_spans: ClosureSpans,
|
||||||
mut expect_err: DiagnosticBuilder<'_>,
|
mut expect_err: DiagnosticBuilder<'_, ErrorReported>,
|
||||||
) -> PResult<'a, ()> {
|
) -> PResult<'a, ()> {
|
||||||
let initial_semicolon = self.token.span;
|
let initial_semicolon = self.token.span;
|
||||||
|
|
||||||
|
@ -1429,7 +1429,7 @@ impl<'a> Parser<'a> {
|
||||||
crate fn make_unclosed_delims_error(
|
crate fn make_unclosed_delims_error(
|
||||||
unmatched: UnmatchedBrace,
|
unmatched: UnmatchedBrace,
|
||||||
sess: &ParseSess,
|
sess: &ParseSess,
|
||||||
) -> Option<DiagnosticBuilder<'_>> {
|
) -> Option<DiagnosticBuilder<'_, ErrorReported>> {
|
||||||
// `None` here means an `Eof` was found. We already emit those errors elsewhere, we add them to
|
// `None` here means an `Eof` was found. We already emit those errors elsewhere, we add them to
|
||||||
// `unmatched_braces` only for error recovery in the `Parser`.
|
// `unmatched_braces` only for error recovery in the `Parser`.
|
||||||
let found_delim = unmatched.found_delim?;
|
let found_delim = unmatched.found_delim?;
|
||||||
|
|
|
@ -8,7 +8,7 @@ use rustc_ast::{
|
||||||
PatField, PatKind, Path, QSelf, RangeEnd, RangeSyntax,
|
PatField, PatKind, Path, QSelf, RangeEnd, RangeSyntax,
|
||||||
};
|
};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, PResult};
|
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported, PResult};
|
||||||
use rustc_span::source_map::{respan, Span, Spanned};
|
use rustc_span::source_map::{respan, Span, Spanned};
|
||||||
use rustc_span::symbol::{kw, sym, Ident};
|
use rustc_span::symbol::{kw, sym, Ident};
|
||||||
|
|
||||||
|
@ -655,7 +655,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
fn fatal_unexpected_non_pat(
|
fn fatal_unexpected_non_pat(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut err: DiagnosticBuilder<'a>,
|
err: DiagnosticBuilder<'a, ErrorReported>,
|
||||||
expected: Expected,
|
expected: Expected,
|
||||||
) -> PResult<'a, P<Pat>> {
|
) -> PResult<'a, P<Pat>> {
|
||||||
err.cancel();
|
err.cancel();
|
||||||
|
@ -722,7 +722,7 @@ impl<'a> Parser<'a> {
|
||||||
// Ensure the user doesn't receive unhelpful unexpected token errors
|
// Ensure the user doesn't receive unhelpful unexpected token errors
|
||||||
self.bump();
|
self.bump();
|
||||||
if self.is_pat_range_end_start(0) {
|
if self.is_pat_range_end_start(0) {
|
||||||
let _ = self.parse_pat_range_end().map_err(|mut e| e.cancel());
|
let _ = self.parse_pat_range_end().map_err(|e| e.cancel());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.error_inclusive_range_with_extra_equals(span_with_eq);
|
self.error_inclusive_range_with_extra_equals(span_with_eq);
|
||||||
|
@ -886,7 +886,7 @@ impl<'a> Parser<'a> {
|
||||||
let mut fields = Vec::new();
|
let mut fields = Vec::new();
|
||||||
let mut etc = false;
|
let mut etc = false;
|
||||||
let mut ate_comma = true;
|
let mut ate_comma = true;
|
||||||
let mut delayed_err: Option<DiagnosticBuilder<'a>> = None;
|
let mut delayed_err: Option<DiagnosticBuilder<'a, ErrorReported>> = None;
|
||||||
let mut etc_span = None;
|
let mut etc_span = None;
|
||||||
|
|
||||||
while self.token != token::CloseDelim(token::Brace) {
|
while self.token != token::CloseDelim(token::Brace) {
|
||||||
|
|
|
@ -394,7 +394,7 @@ impl<'a> Parser<'a> {
|
||||||
debug!("parse_generic_args_with_leading_angle_bracket_recovery: (snapshotting)");
|
debug!("parse_generic_args_with_leading_angle_bracket_recovery: (snapshotting)");
|
||||||
match self.parse_angle_args(ty_generics) {
|
match self.parse_angle_args(ty_generics) {
|
||||||
Ok(args) => Ok(args),
|
Ok(args) => Ok(args),
|
||||||
Err(mut e) if is_first_invocation && self.unmatched_angle_bracket_count > 0 => {
|
Err(e) if is_first_invocation && self.unmatched_angle_bracket_count > 0 => {
|
||||||
// Swap `self` with our backup of the parser state before attempting to parse
|
// Swap `self` with our backup of the parser state before attempting to parse
|
||||||
// generic arguments.
|
// generic arguments.
|
||||||
let snapshot = mem::replace(self, snapshot.unwrap());
|
let snapshot = mem::replace(self, snapshot.unwrap());
|
||||||
|
|
|
@ -18,7 +18,7 @@ use rustc_ast::{
|
||||||
};
|
};
|
||||||
use rustc_ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt};
|
use rustc_ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt};
|
||||||
use rustc_ast::{StmtKind, DUMMY_NODE_ID};
|
use rustc_ast::{StmtKind, DUMMY_NODE_ID};
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder, PResult};
|
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorReported, PResult};
|
||||||
use rustc_span::source_map::{BytePos, Span};
|
use rustc_span::source_map::{BytePos, Span};
|
||||||
use rustc_span::symbol::{kw, sym};
|
use rustc_span::symbol::{kw, sym};
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ impl<'a> Parser<'a> {
|
||||||
// extra noise.
|
// extra noise.
|
||||||
init
|
init
|
||||||
}
|
}
|
||||||
(Err(mut init_err), Some((snapshot, _, ty_err))) => {
|
(Err(init_err), Some((snapshot, _, ty_err))) => {
|
||||||
// init error, ty error
|
// init error, ty error
|
||||||
init_err.cancel();
|
init_err.cancel();
|
||||||
// Couldn't parse the type nor the initializer, only raise the type error and
|
// Couldn't parse the type nor the initializer, only raise the type error and
|
||||||
|
@ -414,7 +414,10 @@ impl<'a> Parser<'a> {
|
||||||
Ok(block)
|
Ok(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn error_block_no_opening_brace_msg(&mut self, msg: &str) -> DiagnosticBuilder<'a> {
|
fn error_block_no_opening_brace_msg(
|
||||||
|
&mut self,
|
||||||
|
msg: &str,
|
||||||
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
let sp = self.token.span;
|
let sp = self.token.span;
|
||||||
let mut e = self.struct_span_err(sp, msg);
|
let mut e = self.struct_span_err(sp, msg);
|
||||||
let do_not_suggest_help = self.token.is_keyword(kw::In) || self.token == token::Colon;
|
let do_not_suggest_help = self.token.is_keyword(kw::In) || self.token == token::Colon;
|
||||||
|
@ -449,7 +452,7 @@ impl<'a> Parser<'a> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(mut e) => {
|
Err(e) => {
|
||||||
self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore);
|
self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore);
|
||||||
e.cancel();
|
e.cancel();
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,7 +345,8 @@ impl<'a> Parser<'a> {
|
||||||
let lt_no_plus = self.check_lifetime() && !self.look_ahead(1, |t| t.is_like_plus());
|
let lt_no_plus = self.check_lifetime() && !self.look_ahead(1, |t| t.is_like_plus());
|
||||||
let bounds = self.parse_generic_bounds_common(allow_plus, None)?;
|
let bounds = self.parse_generic_bounds_common(allow_plus, None)?;
|
||||||
if lt_no_plus {
|
if lt_no_plus {
|
||||||
self.struct_span_err(lo, "lifetime in trait object type must be followed by `+`").emit()
|
self.struct_span_err(lo, "lifetime in trait object type must be followed by `+`")
|
||||||
|
.emit();
|
||||||
}
|
}
|
||||||
Ok(TyKind::TraitObject(bounds, TraitObjectSyntax::None))
|
Ok(TyKind::TraitObject(bounds, TraitObjectSyntax::None))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2095,7 +2095,7 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
|
||||||
rustc_errors::Applicability::MachineApplicable,
|
rustc_errors::Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
err.emit()
|
err.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,7 +219,9 @@ impl<'tcx> CheckConstVisitor<'tcx> {
|
||||||
required_gates.iter().copied().filter(|&g| !features.enabled(g)).collect();
|
required_gates.iter().copied().filter(|&g| !features.enabled(g)).collect();
|
||||||
|
|
||||||
match missing_gates.as_slice() {
|
match missing_gates.as_slice() {
|
||||||
[] => struct_span_err!(tcx.sess, span, E0744, "{}", msg).emit(),
|
[] => {
|
||||||
|
struct_span_err!(tcx.sess, span, E0744, "{}", msg).emit();
|
||||||
|
}
|
||||||
|
|
||||||
[missing_primary, ref missing_secondary @ ..] => {
|
[missing_primary, ref missing_secondary @ ..] => {
|
||||||
let mut err = feature_err(&tcx.sess.parse_sess, *missing_primary, span, &msg);
|
let mut err = feature_err(&tcx.sess.parse_sess, *missing_primary, span, &msg);
|
||||||
|
|
|
@ -118,7 +118,7 @@ impl<'tcx> ExprVisitor<'tcx> {
|
||||||
err.note(&format!("source type: `{}` ({})", from, skeleton_string(from, sk_from)))
|
err.note(&format!("source type: `{}` ({})", from, skeleton_string(from, sk_from)))
|
||||||
.note(&format!("target type: `{}` ({})", to, skeleton_string(to, sk_to)));
|
.note(&format!("target type: `{}` ({})", to, skeleton_string(to, sk_to)));
|
||||||
}
|
}
|
||||||
err.emit()
|
err.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_thin_ptr_ty(&self, ty: Ty<'tcx>) -> bool {
|
fn is_thin_ptr_ty(&self, ty: Ty<'tcx>) -> bool {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::query::caches::QueryCache;
|
||||||
use crate::query::{QueryCacheStore, QueryContext, QueryState};
|
use crate::query::{QueryCacheStore, QueryContext, QueryState};
|
||||||
|
|
||||||
use rustc_data_structures::fingerprint::Fingerprint;
|
use rustc_data_structures::fingerprint::Fingerprint;
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::{DiagnosticBuilder, ErrorReported};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ pub struct QueryVtable<CTX: QueryContext, K, V> {
|
||||||
|
|
||||||
pub compute: fn(CTX::DepContext, K) -> V,
|
pub compute: fn(CTX::DepContext, K) -> V,
|
||||||
pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
|
pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
|
||||||
pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_>) -> V,
|
pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_, ErrorReported>) -> V,
|
||||||
pub try_load_from_disk: Option<fn(CTX, SerializedDepNodeIndex) -> Option<V>>,
|
pub try_load_from_disk: Option<fn(CTX, SerializedDepNodeIndex) -> Option<V>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::query::{QueryContext, QueryStackFrame};
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, Handler, Level};
|
use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, ErrorReported, Handler, Level};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
|
@ -530,7 +530,7 @@ pub fn deadlock<CTX: QueryContext>(tcx: CTX, registry: &rayon_core::Registry) {
|
||||||
pub(crate) fn report_cycle<'a>(
|
pub(crate) fn report_cycle<'a>(
|
||||||
sess: &'a Session,
|
sess: &'a Session,
|
||||||
CycleError { usage, cycle: stack }: CycleError,
|
CycleError { usage, cycle: stack }: CycleError,
|
||||||
) -> DiagnosticBuilder<'a> {
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
assert!(!stack.is_empty());
|
assert!(!stack.is_empty());
|
||||||
|
|
||||||
let fix_span = |span: Span, query: &QueryStackFrame| {
|
let fix_span = |span: Span, query: &QueryStackFrame| {
|
||||||
|
|
|
@ -14,7 +14,7 @@ use rustc_data_structures::profiling::TimingGuard;
|
||||||
use rustc_data_structures::sharded::{get_shard_index_by_hash, Sharded};
|
use rustc_data_structures::sharded::{get_shard_index_by_hash, Sharded};
|
||||||
use rustc_data_structures::sync::{Lock, LockGuard};
|
use rustc_data_structures::sync::{Lock, LockGuard};
|
||||||
use rustc_data_structures::thin_vec::ThinVec;
|
use rustc_data_structures::thin_vec::ThinVec;
|
||||||
use rustc_errors::{DiagnosticBuilder, FatalError};
|
use rustc_errors::{DiagnosticBuilder, ErrorReported, FatalError};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
@ -143,7 +143,7 @@ where
|
||||||
fn mk_cycle<CTX, V, R>(
|
fn mk_cycle<CTX, V, R>(
|
||||||
tcx: CTX,
|
tcx: CTX,
|
||||||
error: CycleError,
|
error: CycleError,
|
||||||
handle_cycle_error: fn(CTX, DiagnosticBuilder<'_>) -> V,
|
handle_cycle_error: fn(CTX, DiagnosticBuilder<'_, ErrorReported>) -> V,
|
||||||
cache: &dyn crate::query::QueryStorage<Value = V, Stored = R>,
|
cache: &dyn crate::query::QueryStorage<Value = V, Stored = R>,
|
||||||
) -> R
|
) -> R
|
||||||
where
|
where
|
||||||
|
|
|
@ -1070,8 +1070,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let ill_formed =
|
let ill_formed = |span| {
|
||||||
|span| struct_span_err!(self.r.session, span, E0466, "bad macro import").emit();
|
struct_span_err!(self.r.session, span, E0466, "bad macro import").emit();
|
||||||
|
};
|
||||||
match attr.meta() {
|
match attr.meta() {
|
||||||
Some(meta) => match meta.kind {
|
Some(meta) => match meta.kind {
|
||||||
MetaItemKind::Word => {
|
MetaItemKind::Word => {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::ptr;
|
||||||
use rustc_ast::{self as ast, Path};
|
use rustc_ast::{self as ast, Path};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
|
use rustc_errors::{struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_feature::BUILTIN_ATTRIBUTES;
|
use rustc_feature::BUILTIN_ATTRIBUTES;
|
||||||
use rustc_hir::def::Namespace::{self, *};
|
use rustc_hir::def::Namespace::{self, *};
|
||||||
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind};
|
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind};
|
||||||
|
@ -110,7 +110,7 @@ impl<'a> Resolver<'a> {
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
resolution_error: ResolutionError<'_>,
|
resolution_error: ResolutionError<'_>,
|
||||||
) -> DiagnosticBuilder<'_> {
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
match resolution_error {
|
match resolution_error {
|
||||||
ResolutionError::GenericParamsFromOuterFunction(outer_res, has_generic_params) => {
|
ResolutionError::GenericParamsFromOuterFunction(outer_res, has_generic_params) => {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
|
@ -624,7 +624,10 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn report_vis_error(&self, vis_resolution_error: VisResolutionError<'_>) {
|
crate fn report_vis_error(
|
||||||
|
&self,
|
||||||
|
vis_resolution_error: VisResolutionError<'_>,
|
||||||
|
) -> ErrorReported {
|
||||||
match vis_resolution_error {
|
match vis_resolution_error {
|
||||||
VisResolutionError::Relative2018(span, path) => {
|
VisResolutionError::Relative2018(span, path) => {
|
||||||
let mut err = self.session.struct_span_err(
|
let mut err = self.session.struct_span_err(
|
||||||
|
@ -1031,7 +1034,7 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
crate fn unresolved_macro_suggestions(
|
crate fn unresolved_macro_suggestions(
|
||||||
&mut self,
|
&mut self,
|
||||||
err: &mut DiagnosticBuilder<'a>,
|
err: &mut Diagnostic,
|
||||||
macro_kind: MacroKind,
|
macro_kind: MacroKind,
|
||||||
parent_scope: &ParentScope<'a>,
|
parent_scope: &ParentScope<'a>,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
|
@ -1120,7 +1123,7 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
crate fn add_typo_suggestion(
|
crate fn add_typo_suggestion(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
suggestion: Option<TypoSuggestion>,
|
suggestion: Option<TypoSuggestion>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
@ -1817,7 +1820,7 @@ fn find_span_immediately_after_crate_name(
|
||||||
crate fn show_candidates(
|
crate fn show_candidates(
|
||||||
definitions: &rustc_hir::definitions::Definitions,
|
definitions: &rustc_hir::definitions::Definitions,
|
||||||
session: &Session,
|
session: &Session,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
// This is `None` if all placement locations are inside expansions
|
// This is `None` if all placement locations are inside expansions
|
||||||
use_placement_span: Option<Span>,
|
use_placement_span: Option<Span>,
|
||||||
candidates: &[ImportSuggestion],
|
candidates: &[ImportSuggestion],
|
||||||
|
|
|
@ -2001,13 +2001,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
// into a single one.
|
// into a single one.
|
||||||
let mut parent_err = this.r.into_struct_error(parent_err.span, parent_err.node);
|
let mut parent_err = this.r.into_struct_error(parent_err.span, parent_err.node);
|
||||||
|
|
||||||
parent_err.cancel();
|
|
||||||
|
|
||||||
err.message = take(&mut parent_err.message);
|
err.message = take(&mut parent_err.message);
|
||||||
err.code = take(&mut parent_err.code);
|
err.code = take(&mut parent_err.code);
|
||||||
err.children = take(&mut parent_err.children);
|
err.children = take(&mut parent_err.children);
|
||||||
|
|
||||||
drop(parent_err);
|
parent_err.cancel();
|
||||||
|
|
||||||
let def_id = this.parent_scope.module.nearest_parent_mod();
|
let def_id = this.parent_scope.module.nearest_parent_mod();
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,9 @@ use rustc_ast::{
|
||||||
};
|
};
|
||||||
use rustc_ast_pretty::pprust::path_segment_to_string;
|
use rustc_ast_pretty::pprust::path_segment_to_string;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
|
use rustc_errors::{
|
||||||
|
pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorReported,
|
||||||
|
};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::Namespace::{self, *};
|
use rustc_hir::def::Namespace::{self, *};
|
||||||
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind};
|
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind};
|
||||||
|
@ -133,7 +135,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
span: Span,
|
span: Span,
|
||||||
source: PathSource<'_>,
|
source: PathSource<'_>,
|
||||||
res: Option<Res>,
|
res: Option<Res>,
|
||||||
) -> (DiagnosticBuilder<'a>, Vec<ImportSuggestion>) {
|
) -> (DiagnosticBuilder<'a, ErrorReported>, Vec<ImportSuggestion>) {
|
||||||
let ident_span = path.last().map_or(span, |ident| ident.ident.span);
|
let ident_span = path.last().map_or(span, |ident| ident.ident.span);
|
||||||
let ns = source.namespace();
|
let ns = source.namespace();
|
||||||
let is_expected = &|res| source.is_expected(res);
|
let is_expected = &|res| source.is_expected(res);
|
||||||
|
@ -606,11 +608,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
(err, candidates)
|
(err, candidates)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detect_assoct_type_constraint_meant_as_path(
|
fn detect_assoct_type_constraint_meant_as_path(&self, base_span: Span, err: &mut Diagnostic) {
|
||||||
&self,
|
|
||||||
base_span: Span,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
) {
|
|
||||||
let Some(ty) = self.diagnostic_metadata.current_type_path else { return; };
|
let Some(ty) = self.diagnostic_metadata.current_type_path else { return; };
|
||||||
let TyKind::Path(_, path) = &ty.kind else { return; };
|
let TyKind::Path(_, path) = &ty.kind else { return; };
|
||||||
for segment in &path.segments {
|
for segment in &path.segments {
|
||||||
|
@ -675,11 +673,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given `where <T as Bar>::Baz: String`, suggest `where T: Bar<Baz = String>`.
|
/// Given `where <T as Bar>::Baz: String`, suggest `where T: Bar<Baz = String>`.
|
||||||
fn restrict_assoc_type_in_where_clause(
|
fn restrict_assoc_type_in_where_clause(&mut self, span: Span, err: &mut Diagnostic) -> bool {
|
||||||
&mut self,
|
|
||||||
span: Span,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
) -> bool {
|
|
||||||
// Detect that we are actually in a `where` predicate.
|
// Detect that we are actually in a `where` predicate.
|
||||||
let (bounded_ty, bounds, where_span) =
|
let (bounded_ty, bounds, where_span) =
|
||||||
if let Some(ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
|
if let Some(ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
|
||||||
|
@ -875,7 +869,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
/// Returns `true` if able to provide context-dependent help.
|
/// Returns `true` if able to provide context-dependent help.
|
||||||
fn smart_resolve_context_dependent_help(
|
fn smart_resolve_context_dependent_help(
|
||||||
&mut self,
|
&mut self,
|
||||||
err: &mut DiagnosticBuilder<'a>,
|
err: &mut Diagnostic,
|
||||||
span: Span,
|
span: Span,
|
||||||
source: PathSource<'_>,
|
source: PathSource<'_>,
|
||||||
res: Res,
|
res: Res,
|
||||||
|
@ -885,7 +879,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
let ns = source.namespace();
|
let ns = source.namespace();
|
||||||
let is_expected = &|res| source.is_expected(res);
|
let is_expected = &|res| source.is_expected(res);
|
||||||
|
|
||||||
let path_sep = |err: &mut DiagnosticBuilder<'_>, expr: &Expr| match expr.kind {
|
let path_sep = |err: &mut Diagnostic, expr: &Expr| match expr.kind {
|
||||||
ExprKind::Field(_, ident) => {
|
ExprKind::Field(_, ident) => {
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
|
@ -908,7 +902,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let find_span = |source: &PathSource<'_>, err: &mut DiagnosticBuilder<'_>| {
|
let find_span = |source: &PathSource<'_>, err: &mut Diagnostic| {
|
||||||
match source {
|
match source {
|
||||||
PathSource::Expr(Some(Expr { span, kind: ExprKind::Call(_, _), .. }))
|
PathSource::Expr(Some(Expr { span, kind: ExprKind::Call(_, _), .. }))
|
||||||
| PathSource::TupleStruct(span, _) => {
|
| PathSource::TupleStruct(span, _) => {
|
||||||
|
@ -1066,7 +1060,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
})
|
})
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
err.delay_as_bug();
|
err.downgrade_to_delayed_bug();
|
||||||
// We already suggested changing `:` into `::` during parsing.
|
// We already suggested changing `:` into `::` during parsing.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1435,7 +1429,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
start.to(sm.next_point(start))
|
start.to(sm.next_point(start))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_ascription_suggestion(&self, err: &mut DiagnosticBuilder<'_>, base_span: Span) -> bool {
|
fn type_ascription_suggestion(&self, err: &mut Diagnostic, base_span: Span) -> bool {
|
||||||
let sm = self.r.session.source_map();
|
let sm = self.r.session.source_map();
|
||||||
let base_snippet = sm.span_to_snippet(base_span);
|
let base_snippet = sm.span_to_snippet(base_span);
|
||||||
if let Some(&sp) = self.diagnostic_metadata.current_type_ascription.last() {
|
if let Some(&sp) = self.diagnostic_metadata.current_type_ascription.last() {
|
||||||
|
@ -1472,7 +1466,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.insert(colon_sp)
|
.insert(colon_sp)
|
||||||
{
|
{
|
||||||
err.delay_as_bug();
|
err.downgrade_to_delayed_bug();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Ok(base_snippet) = base_snippet {
|
if let Ok(base_snippet) = base_snippet {
|
||||||
|
@ -1577,7 +1571,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
/// Adds a suggestion for using an enum's variant when an enum is used instead.
|
/// Adds a suggestion for using an enum's variant when an enum is used instead.
|
||||||
fn suggest_using_enum_variant(
|
fn suggest_using_enum_variant(
|
||||||
&mut self,
|
&mut self,
|
||||||
err: &mut DiagnosticBuilder<'a>,
|
err: &mut Diagnostic,
|
||||||
source: PathSource<'_>,
|
source: PathSource<'_>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -1825,7 +1819,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
spans: Vec<Span>,
|
spans: Vec<Span>,
|
||||||
count: usize,
|
count: usize,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
self.tcx.sess,
|
self.tcx.sess,
|
||||||
spans,
|
spans,
|
||||||
|
@ -1910,7 +1904,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
||||||
/// Returns whether to add `'static` lifetime to the suggested lifetime list.
|
/// Returns whether to add `'static` lifetime to the suggested lifetime list.
|
||||||
crate fn report_elision_failure(
|
crate fn report_elision_failure(
|
||||||
&mut self,
|
&mut self,
|
||||||
db: &mut DiagnosticBuilder<'_>,
|
// FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
|
||||||
|
db: &mut Diagnostic,
|
||||||
params: &[ElisionFailureInfo],
|
params: &[ElisionFailureInfo],
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut m = String::new();
|
let mut m = String::new();
|
||||||
|
@ -2059,7 +2054,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
||||||
|
|
||||||
crate fn add_missing_lifetime_specifiers_label(
|
crate fn add_missing_lifetime_specifiers_label(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
mut spans_with_counts: Vec<(Span, usize)>,
|
mut spans_with_counts: Vec<(Span, usize)>,
|
||||||
lifetime_names: &FxHashSet<Symbol>,
|
lifetime_names: &FxHashSet<Symbol>,
|
||||||
lifetime_spans: Vec<Span>,
|
lifetime_spans: Vec<Span>,
|
||||||
|
@ -2090,7 +2085,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let suggest_existing =
|
let suggest_existing =
|
||||||
|err: &mut DiagnosticBuilder<'_>,
|
|err: &mut Diagnostic,
|
||||||
name: &str,
|
name: &str,
|
||||||
formatters: Vec<Option<Box<dyn Fn(&str) -> String>>>| {
|
formatters: Vec<Option<Box<dyn Fn(&str) -> String>>>| {
|
||||||
if let Some(MissingLifetimeSpot::HigherRanked { span: for_span, span_type }) =
|
if let Some(MissingLifetimeSpot::HigherRanked { span: for_span, span_type }) =
|
||||||
|
@ -2174,7 +2169,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
let suggest_new = |err: &mut DiagnosticBuilder<'_>, suggs: Vec<Option<String>>| {
|
let suggest_new = |err: &mut Diagnostic, suggs: Vec<Option<String>>| {
|
||||||
for missing in self.missing_named_lifetime_spots.iter().rev() {
|
for missing in self.missing_named_lifetime_spots.iter().rev() {
|
||||||
let mut introduce_suggestion = vec![];
|
let mut introduce_suggestion = vec![];
|
||||||
let msg;
|
let msg;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
use crate::late::diagnostics::{ForLifetimeSpanType, MissingLifetimeSpot};
|
use crate::late::diagnostics::{ForLifetimeSpanType, MissingLifetimeSpot};
|
||||||
use rustc_ast::walk_list;
|
use rustc_ast::walk_list;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
|
use rustc_errors::{struct_span_err, Applicability, Diagnostic};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::{DefIdMap, LocalDefId};
|
use rustc_hir::def_id::{DefIdMap, LocalDefId};
|
||||||
|
@ -1572,6 +1572,7 @@ fn signal_shadowing_problem(tcx: TyCtxt<'_>, name: Symbol, orig: Original, shado
|
||||||
name,
|
name,
|
||||||
orig.kind.desc()
|
orig.kind.desc()
|
||||||
)
|
)
|
||||||
|
.forget_guarantee()
|
||||||
} else {
|
} else {
|
||||||
// shadowing involving a label is only a warning, due to issues with
|
// shadowing involving a label is only a warning, due to issues with
|
||||||
// labels and lifetimes not being macro-hygienic.
|
// labels and lifetimes not being macro-hygienic.
|
||||||
|
@ -1873,7 +1874,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
// or from `fn rah<'a>(T<'a>)` to `fn rah(T<'_>)`
|
// or from `fn rah<'a>(T<'a>)` to `fn rah(T<'_>)`
|
||||||
fn suggest_eliding_single_use_lifetime(
|
fn suggest_eliding_single_use_lifetime(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
lifetime: &hir::Lifetime,
|
lifetime: &hir::Lifetime,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ use rustc_ast_pretty::pprust;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
||||||
use rustc_data_structures::intern::Interned;
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
|
use rustc_errors::{struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind};
|
use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind};
|
||||||
use rustc_hir::def::Namespace::*;
|
use rustc_hir::def::Namespace::*;
|
||||||
use rustc_hir::def::{self, CtorOf, DefKind, NonMacroAttrKind, PartialRes};
|
use rustc_hir::def::{self, CtorOf, DefKind, NonMacroAttrKind, PartialRes};
|
||||||
|
@ -713,7 +713,7 @@ struct PrivacyError<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UseError<'a> {
|
struct UseError<'a> {
|
||||||
err: DiagnosticBuilder<'a>,
|
err: DiagnosticBuilder<'a, ErrorReported>,
|
||||||
/// Candidates which user could `use` to access the missing type.
|
/// Candidates which user could `use` to access the missing type.
|
||||||
candidates: Vec<ImportSuggestion>,
|
candidates: Vec<ImportSuggestion>,
|
||||||
/// The `DefId` of the module to place the use-statements in.
|
/// The `DefId` of the module to place the use-statements in.
|
||||||
|
@ -3173,7 +3173,7 @@ impl<'a> Resolver<'a> {
|
||||||
/// ```
|
/// ```
|
||||||
fn add_suggestion_for_rename_of_use(
|
fn add_suggestion_for_rename_of_use(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
name: Symbol,
|
name: Symbol,
|
||||||
import: &Import<'_>,
|
import: &Import<'_>,
|
||||||
binding_span: Span,
|
binding_span: Span,
|
||||||
|
@ -3252,7 +3252,7 @@ impl<'a> Resolver<'a> {
|
||||||
/// as characters expected by span manipulations won't be present.
|
/// as characters expected by span manipulations won't be present.
|
||||||
fn add_suggestion_for_duplicate_nested_use(
|
fn add_suggestion_for_duplicate_nested_use(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
import: &Import<'_>,
|
import: &Import<'_>,
|
||||||
binding_span: Span,
|
binding_span: Span,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use rustc_ast::node_id::NodeId;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::sync::{Lock, Lrc};
|
use rustc_data_structures::sync::{Lock, Lrc};
|
||||||
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
|
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
|
||||||
use rustc_errors::{error_code, Applicability, DiagnosticBuilder};
|
use rustc_errors::{error_code, Applicability, Diagnostic, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
|
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::hygiene::ExpnId;
|
use rustc_span::hygiene::ExpnId;
|
||||||
|
@ -82,7 +82,7 @@ pub fn feature_err<'a>(
|
||||||
feature: Symbol,
|
feature: Symbol,
|
||||||
span: impl Into<MultiSpan>,
|
span: impl Into<MultiSpan>,
|
||||||
explain: &str,
|
explain: &str,
|
||||||
) -> DiagnosticBuilder<'a> {
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
feature_err_issue(sess, feature, span, GateIssue::Language, explain)
|
feature_err_issue(sess, feature, span, GateIssue::Language, explain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ pub fn feature_err_issue<'a>(
|
||||||
span: impl Into<MultiSpan>,
|
span: impl Into<MultiSpan>,
|
||||||
issue: GateIssue,
|
issue: GateIssue,
|
||||||
explain: &str,
|
explain: &str,
|
||||||
) -> DiagnosticBuilder<'a> {
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
let mut err = sess.span_diagnostic.struct_span_err_with_code(span, explain, error_code!(E0658));
|
let mut err = sess.span_diagnostic.struct_span_err_with_code(span, explain, error_code!(E0658));
|
||||||
|
|
||||||
if let Some(n) = find_feature_issue(feature, issue) {
|
if let Some(n) = find_feature_issue(feature, issue) {
|
||||||
|
@ -243,7 +243,7 @@ impl ParseSess {
|
||||||
|
|
||||||
/// Extend an error with a suggestion to wrap an expression with parentheses to allow the
|
/// Extend an error with a suggestion to wrap an expression with parentheses to allow the
|
||||||
/// parser to continue parsing the following operation as part of the same expression.
|
/// parser to continue parsing the following operation as part of the same expression.
|
||||||
pub fn expr_parentheses_needed(&self, err: &mut DiagnosticBuilder<'_>, span: Span) {
|
pub fn expr_parentheses_needed(&self, err: &mut Diagnostic, span: Span) {
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion(
|
||||||
"parentheses are required to parse this as an expression",
|
"parentheses are required to parse this as an expression",
|
||||||
vec![(span.shrink_to_lo(), "(".to_string()), (span.shrink_to_hi(), ")".to_string())],
|
vec![(span.shrink_to_lo(), "(".to_string()), (span.shrink_to_hi(), ")".to_string())],
|
||||||
|
|
|
@ -19,7 +19,7 @@ use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter;
|
||||||
use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
|
use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
|
||||||
use rustc_errors::json::JsonEmitter;
|
use rustc_errors::json::JsonEmitter;
|
||||||
use rustc_errors::registry::Registry;
|
use rustc_errors::registry::Registry;
|
||||||
use rustc_errors::{DiagnosticBuilder, DiagnosticId, ErrorReported};
|
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, ErrorReported};
|
||||||
use rustc_macros::HashStable_Generic;
|
use rustc_macros::HashStable_Generic;
|
||||||
pub use rustc_span::def_id::StableCrateId;
|
pub use rustc_span::def_id::StableCrateId;
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
|
@ -221,7 +221,7 @@ enum DiagnosticBuilderMethod {
|
||||||
pub trait SessionDiagnostic<'a> {
|
pub trait SessionDiagnostic<'a> {
|
||||||
/// Write out as a diagnostic out of `sess`.
|
/// Write out as a diagnostic out of `sess`.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn into_diagnostic(self, sess: &'a Session) -> DiagnosticBuilder<'a>;
|
fn into_diagnostic(self, sess: &'a Session) -> DiagnosticBuilder<'a, ErrorReported>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Diagnostic message ID, used by `Session.one_time_diagnostics` to avoid
|
/// Diagnostic message ID, used by `Session.one_time_diagnostics` to avoid
|
||||||
|
@ -303,37 +303,39 @@ impl Session {
|
||||||
self.crate_types.set(crate_types).expect("`crate_types` was initialized twice")
|
self.crate_types.set(crate_types).expect("`crate_types` was initialized twice")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn struct_span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_span_warn<S: Into<MultiSpan>>(
|
||||||
self.diagnostic().struct_span_warn(sp, msg)
|
|
||||||
}
|
|
||||||
pub fn struct_span_force_warn<S: Into<MultiSpan>>(
|
|
||||||
&self,
|
&self,
|
||||||
sp: S,
|
sp: S,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
) -> DiagnosticBuilder<'_> {
|
) -> DiagnosticBuilder<'_, ()> {
|
||||||
self.diagnostic().struct_span_force_warn(sp, msg)
|
self.diagnostic().struct_span_warn(sp, msg)
|
||||||
}
|
}
|
||||||
pub fn struct_span_warn_with_code<S: Into<MultiSpan>>(
|
pub fn struct_span_warn_with_code<S: Into<MultiSpan>>(
|
||||||
&self,
|
&self,
|
||||||
sp: S,
|
sp: S,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
code: DiagnosticId,
|
code: DiagnosticId,
|
||||||
) -> DiagnosticBuilder<'_> {
|
) -> DiagnosticBuilder<'_, ()> {
|
||||||
self.diagnostic().struct_span_warn_with_code(sp, msg, code)
|
self.diagnostic().struct_span_warn_with_code(sp, msg, code)
|
||||||
}
|
}
|
||||||
pub fn struct_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_warn(&self, msg: &str) -> DiagnosticBuilder<'_, ()> {
|
||||||
self.diagnostic().struct_warn(msg)
|
self.diagnostic().struct_warn(msg)
|
||||||
}
|
}
|
||||||
pub fn struct_force_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_span_allow<S: Into<MultiSpan>>(
|
||||||
self.diagnostic().struct_force_warn(msg)
|
&self,
|
||||||
}
|
sp: S,
|
||||||
pub fn struct_span_allow<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> {
|
msg: &str,
|
||||||
|
) -> DiagnosticBuilder<'_, ()> {
|
||||||
self.diagnostic().struct_span_allow(sp, msg)
|
self.diagnostic().struct_span_allow(sp, msg)
|
||||||
}
|
}
|
||||||
pub fn struct_allow(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_allow(&self, msg: &str) -> DiagnosticBuilder<'_, ()> {
|
||||||
self.diagnostic().struct_allow(msg)
|
self.diagnostic().struct_allow(msg)
|
||||||
}
|
}
|
||||||
pub fn struct_span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_span_err<S: Into<MultiSpan>>(
|
||||||
|
&self,
|
||||||
|
sp: S,
|
||||||
|
msg: &str,
|
||||||
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
self.diagnostic().struct_span_err(sp, msg)
|
self.diagnostic().struct_span_err(sp, msg)
|
||||||
}
|
}
|
||||||
pub fn struct_span_err_with_code<S: Into<MultiSpan>>(
|
pub fn struct_span_err_with_code<S: Into<MultiSpan>>(
|
||||||
|
@ -341,17 +343,25 @@ impl Session {
|
||||||
sp: S,
|
sp: S,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
code: DiagnosticId,
|
code: DiagnosticId,
|
||||||
) -> DiagnosticBuilder<'_> {
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
self.diagnostic().struct_span_err_with_code(sp, msg, code)
|
self.diagnostic().struct_span_err_with_code(sp, msg, code)
|
||||||
}
|
}
|
||||||
// FIXME: This method should be removed (every error should have an associated error code).
|
// FIXME: This method should be removed (every error should have an associated error code).
|
||||||
pub fn struct_err(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_err(&self, msg: &str) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
self.diagnostic().struct_err(msg)
|
self.diagnostic().struct_err(msg)
|
||||||
}
|
}
|
||||||
pub fn struct_err_with_code(&self, msg: &str, code: DiagnosticId) -> DiagnosticBuilder<'_> {
|
pub fn struct_err_with_code(
|
||||||
|
&self,
|
||||||
|
msg: &str,
|
||||||
|
code: DiagnosticId,
|
||||||
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
self.diagnostic().struct_err_with_code(msg, code)
|
self.diagnostic().struct_err_with_code(msg, code)
|
||||||
}
|
}
|
||||||
pub fn struct_span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_span_fatal<S: Into<MultiSpan>>(
|
||||||
|
&self,
|
||||||
|
sp: S,
|
||||||
|
msg: &str,
|
||||||
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
self.diagnostic().struct_span_fatal(sp, msg)
|
self.diagnostic().struct_span_fatal(sp, msg)
|
||||||
}
|
}
|
||||||
pub fn struct_span_fatal_with_code<S: Into<MultiSpan>>(
|
pub fn struct_span_fatal_with_code<S: Into<MultiSpan>>(
|
||||||
|
@ -359,10 +369,10 @@ impl Session {
|
||||||
sp: S,
|
sp: S,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
code: DiagnosticId,
|
code: DiagnosticId,
|
||||||
) -> DiagnosticBuilder<'_> {
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
self.diagnostic().struct_span_fatal_with_code(sp, msg, code)
|
self.diagnostic().struct_span_fatal_with_code(sp, msg, code)
|
||||||
}
|
}
|
||||||
pub fn struct_fatal(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_fatal(&self, msg: &str) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
self.diagnostic().struct_fatal(msg)
|
self.diagnostic().struct_fatal(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,7 +406,7 @@ impl Session {
|
||||||
pub fn err(&self, msg: &str) {
|
pub fn err(&self, msg: &str) {
|
||||||
self.diagnostic().err(msg)
|
self.diagnostic().err(msg)
|
||||||
}
|
}
|
||||||
pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) {
|
pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorReported {
|
||||||
err.into_diagnostic(self).emit()
|
err.into_diagnostic(self).emit()
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -467,7 +477,7 @@ impl Session {
|
||||||
pub fn span_note_without_error<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
|
pub fn span_note_without_error<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
|
||||||
self.diagnostic().span_note_without_error(sp, msg)
|
self.diagnostic().span_note_without_error(sp, msg)
|
||||||
}
|
}
|
||||||
pub fn struct_note_without_error(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
pub fn struct_note_without_error(&self, msg: &str) -> DiagnosticBuilder<'_, ()> {
|
||||||
self.diagnostic().struct_note_without_error(msg)
|
self.diagnostic().struct_note_without_error(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,9 +488,9 @@ impl Session {
|
||||||
|
|
||||||
/// Analogous to calling methods on the given `DiagnosticBuilder`, but
|
/// Analogous to calling methods on the given `DiagnosticBuilder`, but
|
||||||
/// deduplicates on lint ID, span (if any), and message for this `Session`
|
/// deduplicates on lint ID, span (if any), and message for this `Session`
|
||||||
fn diag_once<'a, 'b>(
|
fn diag_once(
|
||||||
&'a self,
|
&self,
|
||||||
diag_builder: &'b mut DiagnosticBuilder<'a>,
|
diag: &mut Diagnostic,
|
||||||
method: DiagnosticBuilderMethod,
|
method: DiagnosticBuilderMethod,
|
||||||
msg_id: DiagnosticMessageId,
|
msg_id: DiagnosticMessageId,
|
||||||
message: &str,
|
message: &str,
|
||||||
|
@ -491,39 +501,33 @@ impl Session {
|
||||||
if fresh {
|
if fresh {
|
||||||
match method {
|
match method {
|
||||||
DiagnosticBuilderMethod::Note => {
|
DiagnosticBuilderMethod::Note => {
|
||||||
diag_builder.note(message);
|
diag.note(message);
|
||||||
}
|
}
|
||||||
DiagnosticBuilderMethod::SpanNote => {
|
DiagnosticBuilderMethod::SpanNote => {
|
||||||
let span = span_maybe.expect("`span_note` needs a span");
|
let span = span_maybe.expect("`span_note` needs a span");
|
||||||
diag_builder.span_note(span, message);
|
diag.span_note(span, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn diag_span_note_once<'a, 'b>(
|
pub fn diag_span_note_once(
|
||||||
&'a self,
|
&self,
|
||||||
diag_builder: &'b mut DiagnosticBuilder<'a>,
|
diag: &mut Diagnostic,
|
||||||
msg_id: DiagnosticMessageId,
|
msg_id: DiagnosticMessageId,
|
||||||
span: Span,
|
span: Span,
|
||||||
message: &str,
|
message: &str,
|
||||||
) {
|
) {
|
||||||
self.diag_once(
|
self.diag_once(diag, DiagnosticBuilderMethod::SpanNote, msg_id, message, Some(span));
|
||||||
diag_builder,
|
|
||||||
DiagnosticBuilderMethod::SpanNote,
|
|
||||||
msg_id,
|
|
||||||
message,
|
|
||||||
Some(span),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn diag_note_once<'a, 'b>(
|
pub fn diag_note_once(
|
||||||
&'a self,
|
&self,
|
||||||
diag_builder: &'b mut DiagnosticBuilder<'a>,
|
diag: &mut Diagnostic,
|
||||||
msg_id: DiagnosticMessageId,
|
msg_id: DiagnosticMessageId,
|
||||||
message: &str,
|
message: &str,
|
||||||
) {
|
) {
|
||||||
self.diag_once(diag_builder, DiagnosticBuilderMethod::Note, msg_id, message, None);
|
self.diag_once(diag, DiagnosticBuilderMethod::Note, msg_id, message, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -14,6 +14,7 @@ use crate::traits::{
|
||||||
PredicateObligations, SelectionContext,
|
PredicateObligations, SelectionContext,
|
||||||
};
|
};
|
||||||
//use rustc_data_structures::fx::FxHashMap;
|
//use rustc_data_structures::fx::FxHashMap;
|
||||||
|
use rustc_errors::Diagnostic;
|
||||||
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
||||||
use rustc_hir::CRATE_HIR_ID;
|
use rustc_hir::CRATE_HIR_ID;
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
|
@ -50,7 +51,7 @@ pub struct OverlapResult<'tcx> {
|
||||||
pub involves_placeholder: bool,
|
pub involves_placeholder: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_placeholder_note(err: &mut rustc_errors::DiagnosticBuilder<'_>) {
|
pub fn add_placeholder_note(err: &mut Diagnostic) {
|
||||||
err.note(
|
err.note(
|
||||||
"this behavior recently changed as a result of a bug fix; \
|
"this behavior recently changed as a result of a bug fix; \
|
||||||
see rust-lang/rust#56105 for details",
|
see rust-lang/rust#56105 for details",
|
||||||
|
|
|
@ -12,7 +12,9 @@ use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCod
|
||||||
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
use crate::infer::{self, InferCtxt, TyCtxtInferExt};
|
use crate::infer::{self, InferCtxt, TyCtxtInferExt};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
|
use rustc_errors::{
|
||||||
|
pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorReported,
|
||||||
|
};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
|
@ -100,7 +102,7 @@ pub trait InferCtxtExt<'tcx> {
|
||||||
expected_args: Vec<ArgKind>,
|
expected_args: Vec<ArgKind>,
|
||||||
found_args: Vec<ArgKind>,
|
found_args: Vec<ArgKind>,
|
||||||
is_closure: bool,
|
is_closure: bool,
|
||||||
) -> DiagnosticBuilder<'tcx>;
|
) -> DiagnosticBuilder<'tcx, ErrorReported>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
|
@ -1017,7 +1019,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
expected_args: Vec<ArgKind>,
|
expected_args: Vec<ArgKind>,
|
||||||
found_args: Vec<ArgKind>,
|
found_args: Vec<ArgKind>,
|
||||||
is_closure: bool,
|
is_closure: bool,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
let kind = if is_closure { "closure" } else { "function" };
|
let kind = if is_closure { "closure" } else { "function" };
|
||||||
|
|
||||||
let args_str = |arguments: &[ArgKind], other: &[ArgKind]| {
|
let args_str = |arguments: &[ArgKind], other: &[ArgKind]| {
|
||||||
|
@ -1174,7 +1176,7 @@ trait InferCtxtPrivExt<'hir, 'tcx> {
|
||||||
fn report_similar_impl_candidates(
|
fn report_similar_impl_candidates(
|
||||||
&self,
|
&self,
|
||||||
impl_candidates: Vec<ImplCandidate<'tcx>>,
|
impl_candidates: Vec<ImplCandidate<'tcx>>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Gets the parent trait chain start
|
/// Gets the parent trait chain start
|
||||||
|
@ -1186,11 +1188,7 @@ trait InferCtxtPrivExt<'hir, 'tcx> {
|
||||||
/// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
|
/// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
|
||||||
/// with the same path as `trait_ref`, a help message about
|
/// with the same path as `trait_ref`, a help message about
|
||||||
/// a probable version mismatch is added to `err`
|
/// a probable version mismatch is added to `err`
|
||||||
fn note_version_mismatch(
|
fn note_version_mismatch(&self, err: &mut Diagnostic, trait_ref: &ty::PolyTraitRef<'tcx>);
|
||||||
&self,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
trait_ref: &ty::PolyTraitRef<'tcx>,
|
|
||||||
);
|
|
||||||
|
|
||||||
/// Creates a `PredicateObligation` with `new_self_ty` replacing the existing type in the
|
/// Creates a `PredicateObligation` with `new_self_ty` replacing the existing type in the
|
||||||
/// `trait_ref`.
|
/// `trait_ref`.
|
||||||
|
@ -1215,35 +1213,26 @@ trait InferCtxtPrivExt<'hir, 'tcx> {
|
||||||
pred: ty::PolyTraitRef<'tcx>,
|
pred: ty::PolyTraitRef<'tcx>,
|
||||||
) -> bool;
|
) -> bool;
|
||||||
|
|
||||||
fn note_obligation_cause(
|
fn note_obligation_cause(&self, err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>);
|
||||||
&self,
|
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
|
||||||
obligation: &PredicateObligation<'tcx>,
|
|
||||||
);
|
|
||||||
|
|
||||||
fn suggest_unsized_bound_if_applicable(
|
fn suggest_unsized_bound_if_applicable(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
err: &mut Diagnostic,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn annotate_source_of_ambiguity(
|
fn annotate_source_of_ambiguity(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
err: &mut Diagnostic,
|
||||||
impls: &[DefId],
|
impls: &[DefId],
|
||||||
predicate: ty::Predicate<'tcx>,
|
predicate: ty::Predicate<'tcx>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn maybe_suggest_unsized_generics(
|
fn maybe_suggest_unsized_generics(&self, err: &mut Diagnostic, span: Span, node: Node<'hir>);
|
||||||
&self,
|
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
|
||||||
span: Span,
|
|
||||||
node: Node<'hir>,
|
|
||||||
);
|
|
||||||
|
|
||||||
fn maybe_indirection_for_unsized(
|
fn maybe_indirection_for_unsized(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
err: &mut Diagnostic,
|
||||||
item: &'hir Item<'hir>,
|
item: &'hir Item<'hir>,
|
||||||
param: &'hir GenericParam<'hir>,
|
param: &'hir GenericParam<'hir>,
|
||||||
) -> bool;
|
) -> bool;
|
||||||
|
@ -1572,7 +1561,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
fn report_similar_impl_candidates(
|
fn report_similar_impl_candidates(
|
||||||
&self,
|
&self,
|
||||||
impl_candidates: Vec<ImplCandidate<'tcx>>,
|
impl_candidates: Vec<ImplCandidate<'tcx>>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
) {
|
) {
|
||||||
if impl_candidates.is_empty() {
|
if impl_candidates.is_empty() {
|
||||||
return;
|
return;
|
||||||
|
@ -1649,11 +1638,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
/// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
|
/// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
|
||||||
/// with the same path as `trait_ref`, a help message about
|
/// with the same path as `trait_ref`, a help message about
|
||||||
/// a probable version mismatch is added to `err`
|
/// a probable version mismatch is added to `err`
|
||||||
fn note_version_mismatch(
|
fn note_version_mismatch(&self, err: &mut Diagnostic, trait_ref: &ty::PolyTraitRef<'tcx>) {
|
||||||
&self,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
trait_ref: &ty::PolyTraitRef<'tcx>,
|
|
||||||
) {
|
|
||||||
let get_trait_impl = |trait_def_id| {
|
let get_trait_impl = |trait_def_id| {
|
||||||
self.tcx.find_map_relevant_impl(trait_def_id, trait_ref.skip_binder().self_ty(), Some)
|
self.tcx.find_map_relevant_impl(trait_def_id, trait_ref.skip_binder().self_ty(), Some)
|
||||||
};
|
};
|
||||||
|
@ -1944,7 +1929,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn annotate_source_of_ambiguity(
|
fn annotate_source_of_ambiguity(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
err: &mut Diagnostic,
|
||||||
impls: &[DefId],
|
impls: &[DefId],
|
||||||
predicate: ty::Predicate<'tcx>,
|
predicate: ty::Predicate<'tcx>,
|
||||||
) {
|
) {
|
||||||
|
@ -1977,7 +1962,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
// Avoid complaining about other inference issues for expressions like
|
// Avoid complaining about other inference issues for expressions like
|
||||||
// `42 >> 1`, where the types are still `{integer}`, but we want to
|
// `42 >> 1`, where the types are still `{integer}`, but we want to
|
||||||
// Do we need `trait_ref.skip_binder().self_ty().is_numeric() &&` too?
|
// Do we need `trait_ref.skip_binder().self_ty().is_numeric() &&` too?
|
||||||
err.cancel();
|
// NOTE(eddyb) this was `.cancel()`, but `err`
|
||||||
|
// is borrowed, so we can't fully defuse it.
|
||||||
|
err.downgrade_to_delayed_bug();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let post = if post.len() > 4 {
|
let post = if post.len() > 4 {
|
||||||
|
@ -2088,11 +2075,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn note_obligation_cause(
|
fn note_obligation_cause(&self, err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>) {
|
||||||
&self,
|
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
|
||||||
obligation: &PredicateObligation<'tcx>,
|
|
||||||
) {
|
|
||||||
// First, attempt to add note to this error with an async-await-specific
|
// First, attempt to add note to this error with an async-await-specific
|
||||||
// message, and fall back to regular note otherwise.
|
// message, and fall back to regular note otherwise.
|
||||||
if !self.maybe_note_obligation_cause_for_async_await(err, obligation) {
|
if !self.maybe_note_obligation_cause_for_async_await(err, obligation) {
|
||||||
|
@ -2110,7 +2093,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn suggest_unsized_bound_if_applicable(
|
fn suggest_unsized_bound_if_applicable(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
err: &mut Diagnostic,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
) {
|
) {
|
||||||
let (pred, item_def_id, span) = match (
|
let (pred, item_def_id, span) = match (
|
||||||
|
@ -2139,7 +2122,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn maybe_suggest_unsized_generics<'hir>(
|
fn maybe_suggest_unsized_generics<'hir>(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
err: &mut Diagnostic,
|
||||||
span: Span,
|
span: Span,
|
||||||
node: Node<'hir>,
|
node: Node<'hir>,
|
||||||
) {
|
) {
|
||||||
|
@ -2206,7 +2189,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn maybe_indirection_for_unsized<'hir>(
|
fn maybe_indirection_for_unsized<'hir>(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
err: &mut Diagnostic,
|
||||||
item: &'hir Item<'hir>,
|
item: &'hir Item<'hir>,
|
||||||
param: &'hir GenericParam<'hir>,
|
param: &'hir GenericParam<'hir>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
|
|
@ -10,7 +10,8 @@ use crate::traits::normalize_projection_type;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
error_code, pluralize, struct_span_err, Applicability, DiagnosticBuilder, Style,
|
error_code, pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder,
|
||||||
|
ErrorReported, Style,
|
||||||
};
|
};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
|
@ -47,7 +48,7 @@ pub enum GeneratorInteriorOrUpvar {
|
||||||
pub trait InferCtxtExt<'tcx> {
|
pub trait InferCtxtExt<'tcx> {
|
||||||
fn suggest_restricting_param_bound(
|
fn suggest_restricting_param_bound(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
body_id: hir::HirId,
|
body_id: hir::HirId,
|
||||||
);
|
);
|
||||||
|
@ -55,28 +56,23 @@ pub trait InferCtxtExt<'tcx> {
|
||||||
fn suggest_dereferences(
|
fn suggest_dereferences(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
err: &mut Diagnostic,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn get_closure_name(
|
fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<String>;
|
||||||
&self,
|
|
||||||
def_id: DefId,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
msg: &str,
|
|
||||||
) -> Option<String>;
|
|
||||||
|
|
||||||
fn suggest_fn_call(
|
fn suggest_fn_call(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn suggest_add_reference_to_arg(
|
fn suggest_add_reference_to_arg(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
has_custom_message: bool,
|
has_custom_message: bool,
|
||||||
) -> bool;
|
) -> bool;
|
||||||
|
@ -84,27 +80,23 @@ pub trait InferCtxtExt<'tcx> {
|
||||||
fn suggest_remove_reference(
|
fn suggest_remove_reference(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn suggest_remove_await(
|
fn suggest_remove_await(&self, obligation: &PredicateObligation<'tcx>, err: &mut Diagnostic);
|
||||||
&self,
|
|
||||||
obligation: &PredicateObligation<'tcx>,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
);
|
|
||||||
|
|
||||||
fn suggest_change_mut(
|
fn suggest_change_mut(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn suggest_semicolon_removal(
|
fn suggest_semicolon_removal(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
span: Span,
|
span: Span,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
);
|
);
|
||||||
|
@ -113,7 +105,7 @@ pub trait InferCtxtExt<'tcx> {
|
||||||
|
|
||||||
fn suggest_impl_trait(
|
fn suggest_impl_trait(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
span: Span,
|
span: Span,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
|
@ -121,7 +113,7 @@ pub trait InferCtxtExt<'tcx> {
|
||||||
|
|
||||||
fn point_at_returns_when_relevant(
|
fn point_at_returns_when_relevant(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -131,11 +123,11 @@ pub trait InferCtxtExt<'tcx> {
|
||||||
found_span: Option<Span>,
|
found_span: Option<Span>,
|
||||||
expected_ref: ty::PolyTraitRef<'tcx>,
|
expected_ref: ty::PolyTraitRef<'tcx>,
|
||||||
found: ty::PolyTraitRef<'tcx>,
|
found: ty::PolyTraitRef<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx>;
|
) -> DiagnosticBuilder<'tcx, ErrorReported>;
|
||||||
|
|
||||||
fn suggest_fully_qualified_path(
|
fn suggest_fully_qualified_path(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
span: Span,
|
span: Span,
|
||||||
trait_ref: DefId,
|
trait_ref: DefId,
|
||||||
|
@ -143,13 +135,13 @@ pub trait InferCtxtExt<'tcx> {
|
||||||
|
|
||||||
fn maybe_note_obligation_cause_for_async_await(
|
fn maybe_note_obligation_cause_for_async_await(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
) -> bool;
|
) -> bool;
|
||||||
|
|
||||||
fn note_obligation_cause_for_async_await(
|
fn note_obligation_cause_for_async_await(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
interior_or_upvar_span: GeneratorInteriorOrUpvar,
|
interior_or_upvar_span: GeneratorInteriorOrUpvar,
|
||||||
interior_extra_info: Option<(Option<Span>, Span, Option<hir::HirId>, Option<Span>)>,
|
interior_extra_info: Option<(Option<Span>, Span, Option<hir::HirId>, Option<Span>)>,
|
||||||
inner_generator_body: Option<&hir::Body<'tcx>>,
|
inner_generator_body: Option<&hir::Body<'tcx>>,
|
||||||
|
@ -163,7 +155,7 @@ pub trait InferCtxtExt<'tcx> {
|
||||||
|
|
||||||
fn note_obligation_cause_code<T>(
|
fn note_obligation_cause_code<T>(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
predicate: &T,
|
predicate: &T,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
cause_code: &ObligationCauseCode<'tcx>,
|
cause_code: &ObligationCauseCode<'tcx>,
|
||||||
|
@ -172,12 +164,12 @@ pub trait InferCtxtExt<'tcx> {
|
||||||
) where
|
) where
|
||||||
T: fmt::Display;
|
T: fmt::Display;
|
||||||
|
|
||||||
fn suggest_new_overflow_limit(&self, err: &mut DiagnosticBuilder<'_>);
|
fn suggest_new_overflow_limit(&self, err: &mut Diagnostic);
|
||||||
|
|
||||||
/// Suggest to await before try: future? => future.await?
|
/// Suggest to await before try: future? => future.await?
|
||||||
fn suggest_await_before_try(
|
fn suggest_await_before_try(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -202,7 +194,7 @@ fn suggest_restriction<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
generics: &hir::Generics<'tcx>,
|
generics: &hir::Generics<'tcx>,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
fn_sig: Option<&hir::FnSig<'_>>,
|
fn_sig: Option<&hir::FnSig<'_>>,
|
||||||
projection: Option<&ty::ProjectionTy<'_>>,
|
projection: Option<&ty::ProjectionTy<'_>>,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
|
@ -329,7 +321,7 @@ fn suggest_restriction<'tcx>(
|
||||||
impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
fn suggest_restricting_param_bound(
|
fn suggest_restricting_param_bound(
|
||||||
&self,
|
&self,
|
||||||
mut err: &mut DiagnosticBuilder<'_>,
|
mut err: &mut Diagnostic,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
body_id: hir::HirId,
|
body_id: hir::HirId,
|
||||||
) {
|
) {
|
||||||
|
@ -493,7 +485,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
fn suggest_dereferences(
|
fn suggest_dereferences(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'tcx>,
|
err: &mut Diagnostic,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) {
|
) {
|
||||||
// It only make sense when suggesting dereferences for arguments
|
// It only make sense when suggesting dereferences for arguments
|
||||||
|
@ -549,14 +541,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
/// Given a closure's `DefId`, return the given name of the closure.
|
/// Given a closure's `DefId`, return the given name of the closure.
|
||||||
///
|
///
|
||||||
/// This doesn't account for reassignments, but it's only used for suggestions.
|
/// This doesn't account for reassignments, but it's only used for suggestions.
|
||||||
fn get_closure_name(
|
fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<String> {
|
||||||
&self,
|
let get_name = |err: &mut Diagnostic, kind: &hir::PatKind<'_>| -> Option<String> {
|
||||||
def_id: DefId,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
msg: &str,
|
|
||||||
) -> Option<String> {
|
|
||||||
let get_name =
|
|
||||||
|err: &mut DiagnosticBuilder<'_>, kind: &hir::PatKind<'_>| -> Option<String> {
|
|
||||||
// Get the local name of this closure. This can be inaccurate because
|
// Get the local name of this closure. This can be inaccurate because
|
||||||
// of the possibility of reassignment, but this should be good enough.
|
// of the possibility of reassignment, but this should be good enough.
|
||||||
match &kind {
|
match &kind {
|
||||||
|
@ -590,7 +576,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
fn suggest_fn_call(
|
fn suggest_fn_call(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) {
|
) {
|
||||||
let self_ty = match trait_pred.self_ty().no_bound_vars() {
|
let self_ty = match trait_pred.self_ty().no_bound_vars() {
|
||||||
|
@ -683,7 +669,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
fn suggest_add_reference_to_arg(
|
fn suggest_add_reference_to_arg(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
poly_trait_pred: ty::PolyTraitPredicate<'tcx>,
|
poly_trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
has_custom_message: bool,
|
has_custom_message: bool,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
@ -817,7 +803,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
fn suggest_remove_reference(
|
fn suggest_remove_reference(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) {
|
) {
|
||||||
let span = obligation.cause.span;
|
let span = obligation.cause.span;
|
||||||
|
@ -874,11 +860,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suggest_remove_await(
|
fn suggest_remove_await(&self, obligation: &PredicateObligation<'tcx>, err: &mut Diagnostic) {
|
||||||
&self,
|
|
||||||
obligation: &PredicateObligation<'tcx>,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
) {
|
|
||||||
let span = obligation.cause.span;
|
let span = obligation.cause.span;
|
||||||
|
|
||||||
if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code().peel_derives() {
|
if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code().peel_derives() {
|
||||||
|
@ -936,7 +918,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
fn suggest_change_mut(
|
fn suggest_change_mut(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) {
|
) {
|
||||||
let points_at_arg = matches!(
|
let points_at_arg = matches!(
|
||||||
|
@ -1012,7 +994,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
fn suggest_semicolon_removal(
|
fn suggest_semicolon_removal(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
span: Span,
|
span: Span,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) {
|
) {
|
||||||
|
@ -1063,7 +1045,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
/// emitted.
|
/// emitted.
|
||||||
fn suggest_impl_trait(
|
fn suggest_impl_trait(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
span: Span,
|
span: Span,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
|
@ -1256,7 +1238,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn point_at_returns_when_relevant(
|
fn point_at_returns_when_relevant(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
) {
|
) {
|
||||||
match obligation.cause.code().peel_derives() {
|
match obligation.cause.code().peel_derives() {
|
||||||
|
@ -1290,7 +1272,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
found_span: Option<Span>,
|
found_span: Option<Span>,
|
||||||
expected_ref: ty::PolyTraitRef<'tcx>,
|
expected_ref: ty::PolyTraitRef<'tcx>,
|
||||||
found: ty::PolyTraitRef<'tcx>,
|
found: ty::PolyTraitRef<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx> {
|
) -> DiagnosticBuilder<'tcx, ErrorReported> {
|
||||||
crate fn build_fn_sig_string<'tcx>(
|
crate fn build_fn_sig_string<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||||
|
@ -1345,7 +1327,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn suggest_fully_qualified_path(
|
fn suggest_fully_qualified_path(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
span: Span,
|
span: Span,
|
||||||
trait_ref: DefId,
|
trait_ref: DefId,
|
||||||
|
@ -1411,7 +1393,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
/// Returns `true` if an async-await specific note was added to the diagnostic.
|
/// Returns `true` if an async-await specific note was added to the diagnostic.
|
||||||
fn maybe_note_obligation_cause_for_async_await(
|
fn maybe_note_obligation_cause_for_async_await(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -1639,7 +1621,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
/// `maybe_note_obligation_cause_for_async_await`'s documentation comment.
|
/// `maybe_note_obligation_cause_for_async_await`'s documentation comment.
|
||||||
fn note_obligation_cause_for_async_await(
|
fn note_obligation_cause_for_async_await(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
interior_or_upvar_span: GeneratorInteriorOrUpvar,
|
interior_or_upvar_span: GeneratorInteriorOrUpvar,
|
||||||
interior_extra_info: Option<(Option<Span>, Span, Option<hir::HirId>, Option<Span>)>,
|
interior_extra_info: Option<(Option<Span>, Span, Option<hir::HirId>, Option<Span>)>,
|
||||||
inner_generator_body: Option<&hir::Body<'tcx>>,
|
inner_generator_body: Option<&hir::Body<'tcx>>,
|
||||||
|
@ -1896,7 +1878,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn note_obligation_cause_code<T>(
|
fn note_obligation_cause_code<T>(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
predicate: &T,
|
predicate: &T,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
cause_code: &ObligationCauseCode<'tcx>,
|
cause_code: &ObligationCauseCode<'tcx>,
|
||||||
|
@ -2133,7 +2115,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
|
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
|
||||||
let ty = parent_trait_ref.skip_binder().self_ty();
|
let ty = parent_trait_ref.skip_binder().self_ty();
|
||||||
if parent_trait_ref.references_error() {
|
if parent_trait_ref.references_error() {
|
||||||
err.cancel();
|
// NOTE(eddyb) this was `.cancel()`, but `err`
|
||||||
|
// is borrowed, so we can't fully defuse it.
|
||||||
|
err.downgrade_to_delayed_bug();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2412,7 +2396,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suggest_new_overflow_limit(&self, err: &mut DiagnosticBuilder<'_>) {
|
fn suggest_new_overflow_limit(&self, err: &mut Diagnostic) {
|
||||||
let suggested_limit = match self.tcx.recursion_limit() {
|
let suggested_limit = match self.tcx.recursion_limit() {
|
||||||
Limit(0) => Limit(2),
|
Limit(0) => Limit(2),
|
||||||
limit => limit * 2,
|
limit => limit * 2,
|
||||||
|
@ -2427,7 +2411,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn suggest_await_before_try(
|
fn suggest_await_before_try(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -2615,7 +2599,7 @@ impl NextTypeParamName for &[hir::GenericParam<'_>] {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suggest_trait_object_return_type_alternatives(
|
fn suggest_trait_object_return_type_alternatives(
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
ret_ty: Span,
|
ret_ty: Span,
|
||||||
trait_obj: &str,
|
trait_obj: &str,
|
||||||
is_object_safe: bool,
|
is_object_safe: bool,
|
||||||
|
|
|
@ -29,7 +29,7 @@ use crate::traits::project::ProjectionCacheKeyExt;
|
||||||
use crate::traits::ProjectionCacheKey;
|
use crate::traits::ProjectionCacheKey;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_errors::ErrorReported;
|
use rustc_errors::{Diagnostic, ErrorReported};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_infer::infer::LateBoundRegionConversionTime;
|
use rustc_infer::infer::LateBoundRegionConversionTime;
|
||||||
|
@ -64,7 +64,7 @@ pub enum IntercrateAmbiguityCause {
|
||||||
impl IntercrateAmbiguityCause {
|
impl IntercrateAmbiguityCause {
|
||||||
/// Emits notes when the overlap is caused by complex intercrate ambiguities.
|
/// Emits notes when the overlap is caused by complex intercrate ambiguities.
|
||||||
/// See #23980 for details.
|
/// See #23980 for details.
|
||||||
pub fn add_intercrate_ambiguity_hint(&self, err: &mut rustc_errors::DiagnosticBuilder<'_>) {
|
pub fn add_intercrate_ambiguity_hint(&self, err: &mut Diagnostic) {
|
||||||
err.note(&self.intercrate_ambiguity_hint());
|
err.note(&self.intercrate_ambiguity_hint());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -450,7 +450,7 @@ fn report_conflicting_impls(
|
||||||
sg.has_errored = true;
|
sg.has_errored = true;
|
||||||
if overlap.with_impl.is_local() || !tcx.orphan_check_crate(()).contains(&impl_def_id) {
|
if overlap.with_impl.is_local() || !tcx.orphan_check_crate(()).contains(&impl_def_id) {
|
||||||
let err = struct_span_err!(tcx.sess, impl_span, E0119, "");
|
let err = struct_span_err!(tcx.sess, impl_span, E0119, "");
|
||||||
decorate(LintDiagnosticBuilder::new(err));
|
decorate(LintDiagnosticBuilder::new(err.forget_guarantee()));
|
||||||
} else {
|
} else {
|
||||||
tcx.sess.delay_span_bug(impl_span, "impl should have failed the orphan check");
|
tcx.sess.delay_span_bug(impl_span, "impl should have failed the orphan check");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::Diagnostic;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use smallvec::smallvec;
|
use smallvec::smallvec;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
@ -43,12 +43,7 @@ impl<'tcx> TraitAliasExpansionInfo<'tcx> {
|
||||||
|
|
||||||
/// Adds diagnostic labels to `diag` for the expansion path of a trait through all intermediate
|
/// Adds diagnostic labels to `diag` for the expansion path of a trait through all intermediate
|
||||||
/// trait aliases.
|
/// trait aliases.
|
||||||
pub fn label_with_exp_info(
|
pub fn label_with_exp_info(&self, diag: &mut Diagnostic, top_label: &str, use_desc: &str) {
|
||||||
&self,
|
|
||||||
diag: &mut DiagnosticBuilder<'_>,
|
|
||||||
top_label: &str,
|
|
||||||
use_desc: &str,
|
|
||||||
) {
|
|
||||||
diag.span_label(self.top().1, top_label);
|
diag.span_label(self.top().1, top_label);
|
||||||
if self.path.len() > 1 {
|
if self.path.len() > 1 {
|
||||||
for (_, sp) in self.path.iter().rev().skip(1).take(self.path.len() - 2) {
|
for (_, sp) in self.path.iter().rev().skip(1).take(self.path.len() - 2) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::astconv::{
|
||||||
use crate::errors::AssocTypeBindingNotAllowed;
|
use crate::errors::AssocTypeBindingNotAllowed;
|
||||||
use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs};
|
use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs};
|
||||||
use rustc_ast::ast::ParamKindOrd;
|
use rustc_ast::ast::ParamKindOrd;
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
|
use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorReported};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
|
@ -49,7 +49,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let add_braces_suggestion = |arg: &GenericArg<'_>, err: &mut DiagnosticBuilder<'_>| {
|
let add_braces_suggestion = |arg: &GenericArg<'_>, err: &mut Diagnostic| {
|
||||||
let suggestions = vec![
|
let suggestions = vec![
|
||||||
(arg.span().shrink_to_lo(), String::from("{ ")),
|
(arg.span().shrink_to_lo(), String::from("{ ")),
|
||||||
(arg.span().shrink_to_hi(), String::from(" }")),
|
(arg.span().shrink_to_hi(), String::from(" }")),
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::middle::resolve_lifetime as rl;
|
||||||
use crate::require_c_abi_if_c_variadic;
|
use crate::require_c_abi_if_c_variadic;
|
||||||
use rustc_ast::TraitObjectSyntax;
|
use rustc_ast::TraitObjectSyntax;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_errors::{struct_span_err, Applicability, ErrorReported, FatalError};
|
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported, FatalError};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
|
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
|
@ -2618,7 +2618,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
&self,
|
&self,
|
||||||
constrained_regions: FxHashSet<ty::BoundRegionKind>,
|
constrained_regions: FxHashSet<ty::BoundRegionKind>,
|
||||||
referenced_regions: FxHashSet<ty::BoundRegionKind>,
|
referenced_regions: FxHashSet<ty::BoundRegionKind>,
|
||||||
generate_err: impl Fn(&str) -> rustc_errors::DiagnosticBuilder<'tcx>,
|
generate_err: impl Fn(&str) -> DiagnosticBuilder<'tcx, ErrorReported>,
|
||||||
) {
|
) {
|
||||||
for br in referenced_regions.difference(&constrained_regions) {
|
for br in referenced_regions.difference(&constrained_regions) {
|
||||||
let br_name = match *br {
|
let br_name = match *br {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::check::coercion::{AsCoercionSite, CoerceMany};
|
use crate::check::coercion::{AsCoercionSite, CoerceMany};
|
||||||
use crate::check::{Diverges, Expectation, FnCtxt, Needs};
|
use crate::check::{Diverges, Expectation, FnCtxt, Needs};
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, Diagnostic};
|
||||||
use rustc_hir::{self as hir, ExprKind};
|
use rustc_hir::{self as hir, ExprKind};
|
||||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
use rustc_infer::traits::Obligation;
|
use rustc_infer::traits::Obligation;
|
||||||
|
@ -132,7 +132,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
&cause,
|
&cause,
|
||||||
Some(&arm.body),
|
Some(&arm.body),
|
||||||
arm_ty,
|
arm_ty,
|
||||||
Some(&mut |err: &mut DiagnosticBuilder<'_>| {
|
Some(&mut |err: &mut Diagnostic| {
|
||||||
let can_coerce_to_return_ty = match self.ret_coercion.as_ref() {
|
let can_coerce_to_return_ty = match self.ret_coercion.as_ref() {
|
||||||
Some(ret_coercion) if self.in_tail_expr => {
|
Some(ret_coercion) if self.in_tail_expr => {
|
||||||
let ret_ty = ret_coercion.borrow().expected_ty();
|
let ret_ty = ret_coercion.borrow().expected_ty();
|
||||||
|
|
|
@ -2,7 +2,7 @@ use super::method::MethodCallee;
|
||||||
use super::{Expectation, FnCtxt, TupleArgumentsFlag};
|
use super::{Expectation, FnCtxt, TupleArgumentsFlag};
|
||||||
use crate::type_error_struct;
|
use crate::type_error_struct;
|
||||||
|
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
|
use rustc_errors::{struct_span_err, Applicability, Diagnostic};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{Namespace, Res};
|
use rustc_hir::def::{Namespace, Res};
|
||||||
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
||||||
|
@ -277,7 +277,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// likely intention is to call the closure, suggest `(||{})()`. (#55851)
|
/// likely intention is to call the closure, suggest `(||{})()`. (#55851)
|
||||||
fn identify_bad_closure_def_and_call(
|
fn identify_bad_closure_def_and_call(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'a>,
|
err: &mut Diagnostic,
|
||||||
hir_id: hir::HirId,
|
hir_id: hir::HirId,
|
||||||
callee_node: &hir::ExprKind<'_>,
|
callee_node: &hir::ExprKind<'_>,
|
||||||
callee_span: Span,
|
callee_span: Span,
|
||||||
|
@ -304,7 +304,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// likely intention is to create an array containing tuples.
|
/// likely intention is to create an array containing tuples.
|
||||||
fn maybe_suggest_bad_array_definition(
|
fn maybe_suggest_bad_array_definition(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'a>,
|
err: &mut Diagnostic,
|
||||||
call_expr: &'tcx hir::Expr<'tcx>,
|
call_expr: &'tcx hir::Expr<'tcx>,
|
||||||
callee_expr: &'tcx hir::Expr<'tcx>,
|
callee_expr: &'tcx hir::Expr<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
|
|
@ -179,7 +179,7 @@ fn make_invalid_casting_error<'a, 'tcx>(
|
||||||
expr_ty: Ty<'tcx>,
|
expr_ty: Ty<'tcx>,
|
||||||
cast_ty: Ty<'tcx>,
|
cast_ty: Ty<'tcx>,
|
||||||
fcx: &FnCtxt<'a, 'tcx>,
|
fcx: &FnCtxt<'a, 'tcx>,
|
||||||
) -> DiagnosticBuilder<'a> {
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
type_error_struct!(
|
type_error_struct!(
|
||||||
sess,
|
sess,
|
||||||
span,
|
span,
|
||||||
|
|
|
@ -37,14 +37,16 @@ pub fn check_wf_new(tcx: TyCtxt<'_>) {
|
||||||
pub(super) fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
|
pub(super) fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
|
||||||
match tcx.sess.target.is_abi_supported(abi) {
|
match tcx.sess.target.is_abi_supported(abi) {
|
||||||
Some(true) => (),
|
Some(true) => (),
|
||||||
Some(false) => struct_span_err!(
|
Some(false) => {
|
||||||
|
struct_span_err!(
|
||||||
tcx.sess,
|
tcx.sess,
|
||||||
span,
|
span,
|
||||||
E0570,
|
E0570,
|
||||||
"`{}` is not a supported ABI for the current target",
|
"`{}` is not a supported ABI for the current target",
|
||||||
abi
|
abi
|
||||||
)
|
)
|
||||||
.emit(),
|
.emit();
|
||||||
|
}
|
||||||
None => {
|
None => {
|
||||||
tcx.struct_span_lint_hir(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
|
tcx.struct_span_lint_hir(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
|
||||||
lint.build("use of calling convention not supported on this target").emit()
|
lint.build("use of calling convention not supported on this target").emit()
|
||||||
|
@ -60,7 +62,7 @@ pub(super) fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Ab
|
||||||
E0781,
|
E0781,
|
||||||
"the `\"C-cmse-nonsecure-call\"` ABI is only allowed on function pointers"
|
"the `\"C-cmse-nonsecure-call\"` ABI is only allowed on function pointers"
|
||||||
)
|
)
|
||||||
.emit()
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
use crate::astconv::AstConv;
|
use crate::astconv::AstConv;
|
||||||
use crate::check::FnCtxt;
|
use crate::check::FnCtxt;
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
|
use rustc_errors::{struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
|
@ -1307,7 +1307,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
||||||
&mut self,
|
&mut self,
|
||||||
fcx: &FnCtxt<'a, 'tcx>,
|
fcx: &FnCtxt<'a, 'tcx>,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
augment_error: &mut dyn FnMut(&mut DiagnosticBuilder<'_>),
|
augment_error: &mut dyn FnMut(&mut Diagnostic),
|
||||||
label_unit_as_expected: bool,
|
label_unit_as_expected: bool,
|
||||||
) {
|
) {
|
||||||
self.coerce_inner(
|
self.coerce_inner(
|
||||||
|
@ -1330,7 +1330,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
expression: Option<&'tcx hir::Expr<'tcx>>,
|
expression: Option<&'tcx hir::Expr<'tcx>>,
|
||||||
mut expression_ty: Ty<'tcx>,
|
mut expression_ty: Ty<'tcx>,
|
||||||
augment_error: Option<&mut dyn FnMut(&mut DiagnosticBuilder<'_>)>,
|
augment_error: Option<&mut dyn FnMut(&mut Diagnostic)>,
|
||||||
label_expression_as_expected: bool,
|
label_expression_as_expected: bool,
|
||||||
) {
|
) {
|
||||||
// Incorporate whatever type inference information we have
|
// Incorporate whatever type inference information we have
|
||||||
|
@ -1520,7 +1520,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
||||||
fcx: &FnCtxt<'a, 'tcx>,
|
fcx: &FnCtxt<'a, 'tcx>,
|
||||||
id: hir::HirId,
|
id: hir::HirId,
|
||||||
expression: Option<(&'tcx hir::Expr<'tcx>, hir::HirId)>,
|
expression: Option<(&'tcx hir::Expr<'tcx>, hir::HirId)>,
|
||||||
) -> DiagnosticBuilder<'a> {
|
) -> DiagnosticBuilder<'a, ErrorReported> {
|
||||||
let mut err = fcx.report_mismatched_types(cause, expected, found, ty_err);
|
let mut err = fcx.report_mismatched_types(cause, expected, found, ty_err);
|
||||||
|
|
||||||
let mut pointing_at_return_type = false;
|
let mut pointing_at_return_type = false;
|
||||||
|
@ -1603,7 +1603,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
||||||
|
|
||||||
fn add_impl_trait_explanation<'a>(
|
fn add_impl_trait_explanation<'a>(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'a>,
|
err: &mut Diagnostic,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
fcx: &FnCtxt<'a, 'tcx>,
|
fcx: &FnCtxt<'a, 'tcx>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use rustc_trait_selection::infer::InferCtxtExt as _;
|
||||||
use rustc_trait_selection::traits::ObligationCause;
|
use rustc_trait_selection::traits::ObligationCause;
|
||||||
|
|
||||||
use rustc_ast::util::parser::PREC_POSTFIX;
|
use rustc_ast::util::parser::PREC_POSTFIX;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorReported};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_hir::{is_range_literal, Node};
|
use rustc_hir::{is_range_literal, Node};
|
||||||
|
@ -23,7 +23,7 @@ use std::iter;
|
||||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
pub fn emit_coerce_suggestions(
|
pub fn emit_coerce_suggestions(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &hir::Expr<'tcx>,
|
expr: &hir::Expr<'tcx>,
|
||||||
expr_ty: Ty<'tcx>,
|
expr_ty: Ty<'tcx>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
|
@ -57,7 +57,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
sp: Span,
|
sp: Span,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
actual: Ty<'tcx>,
|
actual: Ty<'tcx>,
|
||||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
|
||||||
self.demand_suptype_with_origin(&self.misc(sp), expected, actual)
|
self.demand_suptype_with_origin(&self.misc(sp), expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
actual: Ty<'tcx>,
|
actual: Ty<'tcx>,
|
||||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
|
||||||
match self.at(cause, self.param_env).sup(expected, actual) {
|
match self.at(cause, self.param_env).sup(expected, actual) {
|
||||||
Ok(InferOk { obligations, value: () }) => {
|
Ok(InferOk { obligations, value: () }) => {
|
||||||
self.register_predicates(obligations);
|
self.register_predicates(obligations);
|
||||||
|
@ -88,7 +88,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
sp: Span,
|
sp: Span,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
actual: Ty<'tcx>,
|
actual: Ty<'tcx>,
|
||||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
|
||||||
self.demand_eqtype_with_origin(&self.misc(sp), expected, actual)
|
self.demand_eqtype_with_origin(&self.misc(sp), expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
actual: Ty<'tcx>,
|
actual: Ty<'tcx>,
|
||||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
|
||||||
match self.at(cause, self.param_env).eq(expected, actual) {
|
match self.at(cause, self.param_env).eq(expected, actual) {
|
||||||
Ok(InferOk { obligations, value: () }) => {
|
Ok(InferOk { obligations, value: () }) => {
|
||||||
self.register_predicates(obligations);
|
self.register_predicates(obligations);
|
||||||
|
@ -134,7 +134,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>,
|
expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>,
|
||||||
allow_two_phase: AllowTwoPhase,
|
allow_two_phase: AllowTwoPhase,
|
||||||
) -> (Ty<'tcx>, Option<DiagnosticBuilder<'tcx>>) {
|
) -> (Ty<'tcx>, Option<DiagnosticBuilder<'tcx, ErrorReported>>) {
|
||||||
let expected = self.resolve_vars_with_obligations(expected);
|
let expected = self.resolve_vars_with_obligations(expected);
|
||||||
|
|
||||||
let e = match self.try_coerce(expr, checked_ty, expected, allow_two_phase, None) {
|
let e = match self.try_coerce(expr, checked_ty, expected, allow_two_phase, None) {
|
||||||
|
@ -155,7 +155,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn annotate_expected_due_to_let_ty(
|
fn annotate_expected_due_to_let_ty(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &hir::Expr<'_>,
|
expr: &hir::Expr<'_>,
|
||||||
error: TypeError<'_>,
|
error: TypeError<'_>,
|
||||||
) {
|
) {
|
||||||
|
@ -251,7 +251,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
if !lhs.is_syntactic_place_expr() {
|
if !lhs.is_syntactic_place_expr() {
|
||||||
// We already emitted E0070 "invalid left-hand side of assignment", so we
|
// We already emitted E0070 "invalid left-hand side of assignment", so we
|
||||||
// silence this.
|
// silence this.
|
||||||
err.delay_as_bug();
|
err.downgrade_to_delayed_bug();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -262,7 +262,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// sole field is of the found type, suggest such variants. (Issue #42764)
|
/// sole field is of the found type, suggest such variants. (Issue #42764)
|
||||||
fn suggest_compatible_variants(
|
fn suggest_compatible_variants(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &hir::Expr<'_>,
|
expr: &hir::Expr<'_>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
expr_ty: Ty<'tcx>,
|
expr_ty: Ty<'tcx>,
|
||||||
|
@ -899,7 +899,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
pub fn check_for_cast(
|
pub fn check_for_cast(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &hir::Expr<'_>,
|
expr: &hir::Expr<'_>,
|
||||||
checked_ty: Ty<'tcx>,
|
checked_ty: Ty<'tcx>,
|
||||||
expected_ty: Ty<'tcx>,
|
expected_ty: Ty<'tcx>,
|
||||||
|
@ -1039,7 +1039,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id);
|
let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id);
|
||||||
|
|
||||||
let suggest_fallible_into_or_lhs_from =
|
let suggest_fallible_into_or_lhs_from =
|
||||||
|err: &mut DiagnosticBuilder<'_>, exp_to_found_is_fallible: bool| {
|
|err: &mut Diagnostic, exp_to_found_is_fallible: bool| {
|
||||||
// If we know the expression the expected type is derived from, we might be able
|
// If we know the expression the expected type is derived from, we might be able
|
||||||
// to suggest a widening conversion rather than a narrowing one (which may
|
// to suggest a widening conversion rather than a narrowing one (which may
|
||||||
// panic). For example, given x: u8 and y: u32, if we know the span of "x",
|
// panic). For example, given x: u8 and y: u32, if we know the span of "x",
|
||||||
|
@ -1083,7 +1083,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let suggest_to_change_suffix_or_into =
|
let suggest_to_change_suffix_or_into =
|
||||||
|err: &mut DiagnosticBuilder<'_>,
|
|err: &mut Diagnostic,
|
||||||
found_to_exp_is_fallible: bool,
|
found_to_exp_is_fallible: bool,
|
||||||
exp_to_found_is_fallible: bool| {
|
exp_to_found_is_fallible: bool| {
|
||||||
let exp_is_lhs =
|
let exp_is_lhs =
|
||||||
|
@ -1282,11 +1282,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report the type inferred by the return statement.
|
// Report the type inferred by the return statement.
|
||||||
fn report_closure_inferred_return_type(
|
fn report_closure_inferred_return_type(&self, err: &mut Diagnostic, expected: Ty<'tcx>) {
|
||||||
&self,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
expected: Ty<'tcx>,
|
|
||||||
) {
|
|
||||||
if let Some(sp) = self.ret_coercion_span.get() {
|
if let Some(sp) = self.ret_coercion_span.get() {
|
||||||
// If the closure has an explicit return type annotation, or if
|
// If the closure has an explicit return type annotation, or if
|
||||||
// the closure's return type has been inferred from outside
|
// the closure's return type has been inferred from outside
|
||||||
|
|
|
@ -25,6 +25,7 @@ use crate::errors::{AddressOfTemporaryTaken, ReturnStmtOutsideOfFnBody, StructEx
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
|
use rustc_errors::Diagnostic;
|
||||||
use rustc_errors::ErrorReported;
|
use rustc_errors::ErrorReported;
|
||||||
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId};
|
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
@ -60,7 +61,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
extend_err: impl Fn(&mut DiagnosticBuilder<'_>),
|
extend_err: impl Fn(&mut Diagnostic),
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
self.check_expr_meets_expectation_or_error(expr, ExpectHasType(expected), extend_err)
|
self.check_expr_meets_expectation_or_error(expr, ExpectHasType(expected), extend_err)
|
||||||
}
|
}
|
||||||
|
@ -69,7 +70,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
expected: Expectation<'tcx>,
|
expected: Expectation<'tcx>,
|
||||||
extend_err: impl Fn(&mut DiagnosticBuilder<'_>),
|
extend_err: impl Fn(&mut Diagnostic),
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
let expected_ty = expected.to_option(&self).unwrap_or(self.tcx.types.bool);
|
let expected_ty = expected.to_option(&self).unwrap_or(self.tcx.types.bool);
|
||||||
let mut ty = self.check_expr_with_expectation(expr, expected);
|
let mut ty = self.check_expr_with_expectation(expr, expected);
|
||||||
|
@ -485,7 +486,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
.map_or(false, |x| x.iter().any(|adj| matches!(adj.kind, Adjust::Deref(_))))
|
.map_or(false, |x| x.iter().any(|adj| matches!(adj.kind, Adjust::Deref(_))))
|
||||||
});
|
});
|
||||||
if !is_named {
|
if !is_named {
|
||||||
self.tcx.sess.emit_err(AddressOfTemporaryTaken { span: oprnd.span })
|
self.tcx.sess.emit_err(AddressOfTemporaryTaken { span: oprnd.span });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1469,14 +1470,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.register_predicates(obligations)
|
self.register_predicates(obligations)
|
||||||
}
|
}
|
||||||
// FIXME: Need better diagnostics for `FieldMisMatch` error
|
// FIXME: Need better diagnostics for `FieldMisMatch` error
|
||||||
Err(_) => self
|
Err(_) => {
|
||||||
.report_mismatched_types(
|
self.report_mismatched_types(
|
||||||
&cause,
|
&cause,
|
||||||
target_ty,
|
target_ty,
|
||||||
fru_ty,
|
fru_ty,
|
||||||
FieldMisMatch(variant.name, ident.name),
|
FieldMisMatch(variant.name, ident.name),
|
||||||
)
|
)
|
||||||
.emit(),
|
.emit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fru_ty
|
fru_ty
|
||||||
|
@ -1484,22 +1486,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return self
|
self.report_mismatched_types(
|
||||||
.report_mismatched_types(
|
|
||||||
&self.misc(base_expr.span),
|
&self.misc(base_expr.span),
|
||||||
adt_ty,
|
adt_ty,
|
||||||
base_ty,
|
base_ty,
|
||||||
Sorts(ExpectedFound::new(true, adt_ty, base_ty)),
|
Sorts(ExpectedFound::new(true, adt_ty, base_ty)),
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return self
|
self.tcx
|
||||||
.tcx
|
|
||||||
.sess
|
.sess
|
||||||
.emit_err(FunctionalRecordUpdateOnNonStruct { span: base_expr.span });
|
.emit_err(FunctionalRecordUpdateOnNonStruct { span: base_expr.span });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1528,10 +1530,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
_ => {
|
_ => {
|
||||||
return self
|
self.tcx
|
||||||
.tcx
|
|
||||||
.sess
|
.sess
|
||||||
.emit_err(FunctionalRecordUpdateOnNonStruct { span: base_expr.span });
|
.emit_err(FunctionalRecordUpdateOnNonStruct { span: base_expr.span });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1923,7 +1925,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn suggest_await_on_field_access(
|
fn suggest_await_on_field_access(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
field_ident: Ident,
|
field_ident: Ident,
|
||||||
base: &'tcx hir::Expr<'tcx>,
|
base: &'tcx hir::Expr<'tcx>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
|
@ -2123,7 +2125,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
err.emit();
|
err.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn point_at_param_definition(&self, err: &mut DiagnosticBuilder<'_>, param: ty::ParamTy) {
|
fn point_at_param_definition(&self, err: &mut Diagnostic, param: ty::ParamTy) {
|
||||||
let generics = self.tcx.generics_of(self.body_id.owner.to_def_id());
|
let generics = self.tcx.generics_of(self.body_id.owner.to_def_id());
|
||||||
let generic_param = generics.type_param(¶m, self.tcx);
|
let generic_param = generics.type_param(¶m, self.tcx);
|
||||||
if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind {
|
if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind {
|
||||||
|
@ -2142,7 +2144,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn suggest_fields_on_recordish(
|
fn suggest_fields_on_recordish(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
def: &'tcx ty::AdtDef,
|
def: &'tcx ty::AdtDef,
|
||||||
field: Ident,
|
field: Ident,
|
||||||
access_span: Span,
|
access_span: Span,
|
||||||
|
@ -2171,7 +2173,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn maybe_suggest_array_indexing(
|
fn maybe_suggest_array_indexing(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &hir::Expr<'_>,
|
expr: &hir::Expr<'_>,
|
||||||
base: &hir::Expr<'_>,
|
base: &hir::Expr<'_>,
|
||||||
field: Ident,
|
field: Ident,
|
||||||
|
@ -2195,7 +2197,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn suggest_first_deref_field(
|
fn suggest_first_deref_field(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &hir::Expr<'_>,
|
expr: &hir::Expr<'_>,
|
||||||
base: &hir::Expr<'_>,
|
base: &hir::Expr<'_>,
|
||||||
field: Ident,
|
field: Ident,
|
||||||
|
@ -2212,7 +2214,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
field: Ident,
|
field: Ident,
|
||||||
expr_t: Ty<'tcx>,
|
expr_t: Ty<'tcx>,
|
||||||
id: HirId,
|
id: HirId,
|
||||||
) -> DiagnosticBuilder<'_> {
|
) -> DiagnosticBuilder<'_, ErrorReported> {
|
||||||
let span = field.span;
|
let span = field.span;
|
||||||
debug!("no_such_field_err(span: {:?}, field: {:?}, expr_t: {:?})", span, field, expr_t);
|
debug!("no_such_field_err(span: {:?}, field: {:?}, expr_t: {:?})", span, field, expr_t);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::check::{BreakableCtxt, Diverges, Expectation, FnCtxt, LocalTy};
|
||||||
|
|
||||||
use rustc_data_structures::captures::Captures;
|
use rustc_data_structures::captures::Captures;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorReported};
|
use rustc_errors::{Applicability, Diagnostic, ErrorReported};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorOf, DefKind, Res};
|
use rustc_hir::def::{CtorOf, DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
|
@ -953,7 +953,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
pub(in super::super) fn note_internal_mutation_in_method(
|
pub(in super::super) fn note_internal_mutation_in_method(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &hir::Expr<'_>,
|
expr: &hir::Expr<'_>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
|
@ -998,7 +998,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
pub(in super::super) fn note_need_for_fn_pointer(
|
pub(in super::super) fn note_need_for_fn_pointer(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::check::{
|
||||||
|
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId};
|
use rustc_errors::{Applicability, Diagnostic, DiagnosticId};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorOf, DefKind, Res};
|
use rustc_hir::def::{CtorOf, DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
|
@ -460,7 +460,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
fn variadic_error<'tcx>(sess: &Session, span: Span, ty: Ty<'tcx>, cast_ty: &str) {
|
fn variadic_error<'tcx>(sess: &Session, span: Span, ty: Ty<'tcx>, cast_ty: &str) {
|
||||||
use crate::structured_errors::MissingCastForVariadicArg;
|
use crate::structured_errors::MissingCastForVariadicArg;
|
||||||
|
|
||||||
MissingCastForVariadicArg { sess, span, ty, cast_ty }.diagnostic().emit()
|
MissingCastForVariadicArg { sess, span, ty, cast_ty }.diagnostic().emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
for arg in provided_args.iter().skip(expected_arg_count) {
|
for arg in provided_args.iter().skip(expected_arg_count) {
|
||||||
|
@ -837,7 +837,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
kind: hir::ExprKind::Loop(_, _, hir::LoopSource::While, _),
|
kind: hir::ExprKind::Loop(_, _, hir::LoopSource::While, _),
|
||||||
..
|
..
|
||||||
})) => {
|
})) => {
|
||||||
err.delay_as_bug();
|
err.downgrade_to_delayed_bug();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -890,7 +890,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
blk: &'tcx hir::Block<'tcx>,
|
blk: &'tcx hir::Block<'tcx>,
|
||||||
expected_ty: Ty<'tcx>,
|
expected_ty: Ty<'tcx>,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
) {
|
) {
|
||||||
if let Some((span_semi, boxed)) = self.could_remove_semicolon(blk, expected_ty) {
|
if let Some((span_semi, boxed)) = self.could_remove_semicolon(blk, expected_ty) {
|
||||||
if let StatementAsExpression::NeedsBoxing = boxed {
|
if let StatementAsExpression::NeedsBoxing = boxed {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::astconv::AstConv;
|
||||||
use rustc_ast::util::parser::ExprPrecedence;
|
use rustc_ast::util::parser::ExprPrecedence;
|
||||||
use rustc_span::{self, MultiSpan, Span};
|
use rustc_span::{self, MultiSpan, Span};
|
||||||
|
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, Diagnostic};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorOf, DefKind};
|
use rustc_hir::def::{CtorOf, DefKind};
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
|
@ -22,11 +22,7 @@ use rustc_middle::ty::subst::GenericArgKind;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
pub(in super::super) fn suggest_semicolon_at_end(
|
pub(in super::super) fn suggest_semicolon_at_end(&self, span: Span, err: &mut Diagnostic) {
|
||||||
&self,
|
|
||||||
span: Span,
|
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
|
||||||
) {
|
|
||||||
err.span_suggestion_short(
|
err.span_suggestion_short(
|
||||||
span.shrink_to_hi(),
|
span.shrink_to_hi(),
|
||||||
"consider using a semicolon here",
|
"consider using a semicolon here",
|
||||||
|
@ -42,7 +38,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// - Possible missing return type if the return type is the default, and not `fn main()`.
|
/// - Possible missing return type if the return type is the default, and not `fn main()`.
|
||||||
pub fn suggest_mismatched_types_on_tail(
|
pub fn suggest_mismatched_types_on_tail(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
|
@ -81,7 +77,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// ```
|
/// ```
|
||||||
fn suggest_fn_call(
|
fn suggest_fn_call(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &hir::Expr<'_>,
|
expr: &hir::Expr<'_>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
|
@ -211,7 +207,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
pub fn suggest_deref_ref_or_into(
|
pub fn suggest_deref_ref_or_into(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &hir::Expr<'tcx>,
|
expr: &hir::Expr<'tcx>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
|
@ -312,7 +308,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// in the heap by calling `Box::new()`.
|
/// in the heap by calling `Box::new()`.
|
||||||
pub(in super::super) fn suggest_boxing_when_appropriate(
|
pub(in super::super) fn suggest_boxing_when_appropriate(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &hir::Expr<'_>,
|
expr: &hir::Expr<'_>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
|
@ -347,7 +343,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// suggest a non-capturing closure
|
/// suggest a non-capturing closure
|
||||||
pub(in super::super) fn suggest_no_capture_closure(
|
pub(in super::super) fn suggest_no_capture_closure(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
) {
|
) {
|
||||||
|
@ -382,7 +378,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
#[instrument(skip(self, err))]
|
#[instrument(skip(self, err))]
|
||||||
pub(in super::super) fn suggest_calling_boxed_future_when_appropriate(
|
pub(in super::super) fn suggest_calling_boxed_future_when_appropriate(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &hir::Expr<'_>,
|
expr: &hir::Expr<'_>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
|
@ -477,7 +473,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// it suggests adding a semicolon.
|
/// it suggests adding a semicolon.
|
||||||
fn suggest_missing_semicolon(
|
fn suggest_missing_semicolon(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expression: &'tcx hir::Expr<'tcx>,
|
expression: &'tcx hir::Expr<'tcx>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
) {
|
) {
|
||||||
|
@ -518,7 +514,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// type.
|
/// type.
|
||||||
pub(in super::super) fn suggest_missing_return_type(
|
pub(in super::super) fn suggest_missing_return_type(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
fn_decl: &hir::FnDecl<'_>,
|
fn_decl: &hir::FnDecl<'_>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
|
@ -580,7 +576,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// ```
|
/// ```
|
||||||
fn try_suggest_return_impl_trait(
|
fn try_suggest_return_impl_trait(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
fn_id: hir::HirId,
|
fn_id: hir::HirId,
|
||||||
|
@ -681,7 +677,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
pub(in super::super) fn suggest_missing_break_or_return_expr(
|
pub(in super::super) fn suggest_missing_break_or_return_expr(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
fn_decl: &hir::FnDecl<'_>,
|
fn_decl: &hir::FnDecl<'_>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
|
@ -751,7 +747,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
pub(in super::super) fn suggest_missing_parentheses(
|
pub(in super::super) fn suggest_missing_parentheses(
|
||||||
&self,
|
&self,
|
||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut Diagnostic,
|
||||||
expr: &hir::Expr<'_>,
|
expr: &hir::Expr<'_>,
|
||||||
) {
|
) {
|
||||||
let sp = self.tcx.sess.source_map().start_point(expr.span);
|
let sp = self.tcx.sess.source_map().start_point(expr.span);
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue