Skip to content

Rollup of 7 pull requests #127526

New issue

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

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

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
90cbd0b
impl FusedIterator and a size hint for the error sources iter
Sky9x Jun 28, 2024
d9ed923
Use verbose style when suggesting changing `const` with `let`
estebank Jul 5, 2024
ab56dfd
Account for `let foo = expr`; to suggest `const foo: Ty = expr;`
estebank Jul 8, 2024
321eba5
Update f16/f128 FIXMEs that needed (NEG_)INFINITY
tgross35 Jul 8, 2024
ec662e7
`#[doc(alias)]`'s doc: say that ASCII spaces are allowed
ShE3py Jul 8, 2024
96a7916
Update a f16/f128 FIXME to be more accurate
tgross35 Jul 8, 2024
7097dbc
exhaustively destructure external constraints
lcnr Jul 9, 2024
e38109d
use `update_parent_goal` for lazy updates
lcnr Jul 9, 2024
fd9a925
Automatically taint when reporting errors from ItemCtxt
oli-obk Jul 5, 2024
aece064
Remove HirTyLowerer::set_tainted_by_errors, since it is now redundant
oli-obk Jul 5, 2024
dd175fe
cycle_participants to nested_goals
lcnr Jul 9, 2024
7af825f
Split out overflow handling into its own module
compiler-errors Jul 8, 2024
cd68a28
Move some stuff into the ambiguity and suggestion modules
compiler-errors Jul 8, 2024
bbbff80
Split out fulfillment error reporting a bit more
compiler-errors Jul 8, 2024
6e5f0fe
Rollup merge of #127091 - Sky9x:fused-error-sources-iter, r=dtolnay
matthiaskrgr Jul 9, 2024
2765d5c
Rollup merge of #127358 - oli-obk:taint_itemctxt, r=fmease
matthiaskrgr Jul 9, 2024
3cbf0a9
Rollup merge of #127382 - estebank:const-let, r=compiler-errors
matthiaskrgr Jul 9, 2024
16ed243
Rollup merge of #127484 - ShE3py:rustdoc-doc-alias-whitespace-doc, r=…
matthiaskrgr Jul 9, 2024
889f133
Rollup merge of #127495 - compiler-errors:more-trait-error-reworking,…
matthiaskrgr Jul 9, 2024
2db1e7a
Rollup merge of #127496 - tgross35:f16-f128-pattern-fixme, r=Nadrieril
matthiaskrgr Jul 9, 2024
705ff01
Rollup merge of #127508 - lcnr:search-graph-prep, r=compiler-errors
matthiaskrgr Jul 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Automatically taint when reporting errors from ItemCtxt
  • Loading branch information
oli-obk committed Jul 9, 2024
commit fd9a92542cb85bf8a0d3948f26a8d81fbd16093c
8 changes: 7 additions & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use rustc_ast::Recovered;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::unord::UnordMap;
use rustc_errors::{struct_span_code_err, Applicability, Diag, ErrorGuaranteed, StashKey, E0228};
use rustc_errors::{
struct_span_code_err, Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, StashKey, E0228,
};
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{self, walk_generics, Visitor};
Expand Down Expand Up @@ -370,6 +372,10 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
self.tcx
}

fn dcx(&self) -> DiagCtxtHandle<'_> {
self.tcx.dcx().taintable_handle(&self.tainted_by_errors)
}

fn item_def_id(&self) -> LocalDefId {
self.item_def_id
}
Expand Down
39 changes: 20 additions & 19 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}

if unbounds.len() > 1 {
tcx.dcx().emit_err(errors::MultipleRelaxedDefaultBounds {
self.dcx().emit_err(errors::MultipleRelaxedDefaultBounds {
spans: unbounds.iter().map(|ptr| ptr.span).collect(),
});
}
Expand All @@ -90,7 +90,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
continue;
}
// There was a `?Trait` bound, but it was not `?Sized`; warn.
tcx.dcx().span_warn(
self.dcx().span_warn(
unbound.span,
"relaxing a default bound only does something for `?Sized`; \
all other traits are not bound by default",
Expand Down Expand Up @@ -310,7 +310,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
duplicates
.entry(assoc_item.def_id)
.and_modify(|prev_span| {
tcx.dcx().emit_err(errors::ValueOfAssociatedStructAlreadySpecified {
self.dcx().emit_err(errors::ValueOfAssociatedStructAlreadySpecified {
span: constraint.span,
prev_span: *prev_span,
item_name: constraint.ident,
Expand Down Expand Up @@ -338,7 +338,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
.into(),
ty::GenericParamDefKind::Type { .. } => {
let guar = *emitted_bad_param_err.get_or_insert_with(|| {
tcx.dcx().emit_err(
self.dcx().emit_err(
crate::errors::ReturnTypeNotationIllegalParam::Type {
span: path_span,
param_span: tcx.def_span(param.def_id),
Expand All @@ -349,7 +349,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}
ty::GenericParamDefKind::Const { .. } => {
let guar = *emitted_bad_param_err.get_or_insert_with(|| {
tcx.dcx().emit_err(
self.dcx().emit_err(
crate::errors::ReturnTypeNotationIllegalParam::Const {
span: path_span,
param_span: tcx.def_span(param.def_id),
Expand All @@ -371,7 +371,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
{
alias_ty.into()
} else {
return Err(tcx.dcx().emit_err(crate::errors::ReturnTypeNotationOnNonRpitit {
return Err(self.dcx().emit_err(crate::errors::ReturnTypeNotationOnNonRpitit {
span: constraint.span,
ty: tcx.liberate_late_bound_regions(assoc_item.def_id, output),
fn_span: tcx.hir().span_if_local(assoc_item.def_id),
Expand Down Expand Up @@ -417,7 +417,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let ty = alias_term
.map_bound(|alias| tcx.type_of(alias.def_id).instantiate(tcx, alias.args));
let ty =
check_assoc_const_binding_type(tcx, constraint.ident, ty, constraint.hir_id);
check_assoc_const_binding_type(self, constraint.ident, ty, constraint.hir_id);
tcx.feed_anon_const_type(anon_const.def_id, ty::EarlyBinder::bind(ty));
}

Expand All @@ -426,7 +426,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {

match constraint.kind {
hir::AssocItemConstraintKind::Equality { .. } if let ty::AssocKind::Fn = assoc_kind => {
return Err(tcx.dcx().emit_err(crate::errors::ReturnTypeNotationEqualityBound {
return Err(self.dcx().emit_err(crate::errors::ReturnTypeNotationEqualityBound {
span: constraint.span,
}));
}
Expand Down Expand Up @@ -462,7 +462,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
late_bound_in_term,
|br_name| {
struct_span_code_err!(
tcx.dcx(),
self.dcx(),
constraint.span,
E0582,
"binding for associated type `{}` references {}, \
Expand Down Expand Up @@ -519,7 +519,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
///
/// [^1]: <https://github.com/rust-lang/project-const-generics/issues/28>.
fn check_assoc_const_binding_type<'tcx>(
tcx: TyCtxt<'tcx>,
cx: &dyn HirTyLowerer<'tcx>,
assoc_const: Ident,
ty: ty::Binder<'tcx, Ty<'tcx>>,
hir_id: hir::HirId,
Expand All @@ -536,13 +536,14 @@ fn check_assoc_const_binding_type<'tcx>(
}

let mut collector = GenericParamAndBoundVarCollector {
tcx,
cx,
params: Default::default(),
vars: Default::default(),
depth: ty::INNERMOST,
};
let mut guar = ty.visit_with(&mut collector).break_value();

let tcx = cx.tcx();
let ty_note = ty
.make_suggestable(tcx, false, None)
.map(|ty| crate::errors::TyOfAssocConstBindingNote { assoc_const, ty });
Expand All @@ -556,7 +557,7 @@ fn check_assoc_const_binding_type<'tcx>(
for index in collector.params {
let param = generics.param_at(index as _, tcx);
let is_self_param = param.name == rustc_span::symbol::kw::SelfUpper;
guar.get_or_insert(tcx.dcx().emit_err(crate::errors::ParamInTyOfAssocConstBinding {
guar.get_or_insert(cx.dcx().emit_err(crate::errors::ParamInTyOfAssocConstBinding {
span: assoc_const.span,
assoc_const,
param_name: param.name,
Expand All @@ -574,7 +575,7 @@ fn check_assoc_const_binding_type<'tcx>(
}));
}
for (var_def_id, var_name) in collector.vars {
guar.get_or_insert(tcx.dcx().emit_err(
guar.get_or_insert(cx.dcx().emit_err(
crate::errors::EscapingBoundVarInTyOfAssocConstBinding {
span: assoc_const.span,
assoc_const,
Expand All @@ -590,14 +591,14 @@ fn check_assoc_const_binding_type<'tcx>(
Ty::new_error(tcx, guar)
}

struct GenericParamAndBoundVarCollector<'tcx> {
tcx: TyCtxt<'tcx>,
struct GenericParamAndBoundVarCollector<'a, 'tcx> {
cx: &'a dyn HirTyLowerer<'tcx>,
params: FxIndexSet<u32>,
vars: FxIndexSet<(DefId, Symbol)>,
depth: ty::DebruijnIndex,
}

impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'tcx> {
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'_, 'tcx> {
type Result = ControlFlow<ErrorGuaranteed>;

fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(
Expand All @@ -620,7 +621,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'tcx>
ty::BoundTyKind::Param(def_id, name) => (def_id, name),
ty::BoundTyKind::Anon => {
let reported = self
.tcx
.cx
.dcx()
.delayed_bug(format!("unexpected anon bound ty: {:?}", bt.var));
return ControlFlow::Break(reported);
Expand All @@ -643,7 +644,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'tcx>
ty::BrNamed(def_id, name) => (def_id, name),
ty::BrAnon | ty::BrEnv => {
let guar = self
.tcx
.cx
.dcx()
.delayed_bug(format!("unexpected bound region kind: {:?}", br.kind));
return ControlFlow::Break(guar);
Expand All @@ -661,7 +662,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'tcx>
self.params.insert(param.index);
}
ty::ConstKind::Bound(db, ty::BoundVar { .. }) if db >= self.depth => {
let guar = self.tcx.dcx().delayed_bug("unexpected escaping late-bound const var");
let guar = self.cx.dcx().delayed_bug("unexpected escaping late-bound const var");
return ControlFlow::Break(guar);
}
_ if ct.has_param() || ct.has_bound_vars() => return ct.super_visit_with(self),
Expand Down
43 changes: 21 additions & 22 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
return;
}

self.tcx().dcx().emit_err(MissingTypeParams {
self.dcx().emit_err(MissingTypeParams {
span,
def_span: self.tcx().def_span(def_id),
span_snippet: self.tcx().sess.source_map().span_to_snippet(span).ok(),
Expand Down Expand Up @@ -109,7 +109,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {

if is_impl {
let trait_name = self.tcx().def_path_str(trait_def_id);
self.tcx().dcx().emit_err(ManualImplementation { span, trait_name });
self.dcx().emit_err(ManualImplementation { span, trait_name });
}
}

Expand Down Expand Up @@ -156,7 +156,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {

if is_dummy {
err.label = Some(errors::AssocItemNotFoundLabel::NotFound { span });
return tcx.dcx().emit_err(err);
return self.dcx().emit_err(err);
}

let all_candidate_names: Vec<_> = all_candidates()
Expand All @@ -174,7 +174,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
assoc_kind: assoc_kind_str,
suggested_name,
});
return tcx.dcx().emit_err(err);
return self.dcx().emit_err(err);
}

// If we didn't find a good item in the supertraits (or couldn't get
Expand Down Expand Up @@ -239,10 +239,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
assoc_kind: assoc_kind_str,
suggested_name,
});
return tcx.dcx().emit_err(err);
return self.dcx().emit_err(err);
}

let mut err = tcx.dcx().create_err(err);
let mut err = self.dcx().create_err(err);
if suggest_constraining_type_param(
tcx,
generics,
Expand All @@ -264,7 +264,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}
return err.emit();
}
return tcx.dcx().emit_err(err);
return self.dcx().emit_err(err);
}
}

Expand All @@ -291,7 +291,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
err.label = Some(errors::AssocItemNotFoundLabel::NotFound { span: assoc_name.span });
}

tcx.dcx().emit_err(err)
self.dcx().emit_err(err)
}

fn complain_about_assoc_kind_mismatch(
Expand Down Expand Up @@ -347,7 +347,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
(ident.span, None, assoc_kind, assoc_item.kind)
};

tcx.dcx().emit_err(errors::AssocKindMismatch {
self.dcx().emit_err(errors::AssocKindMismatch {
span,
expected: super::assoc_kind_str(expected),
got: super::assoc_kind_str(got),
Expand All @@ -366,8 +366,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
traits: &[String],
name: Symbol,
) -> ErrorGuaranteed {
let mut err =
struct_span_code_err!(self.tcx().dcx(), span, E0223, "ambiguous associated type");
let mut err = struct_span_code_err!(self.dcx(), span, E0223, "ambiguous associated type");
if self
.tcx()
.resolutions(())
Expand Down Expand Up @@ -475,7 +474,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
span: Span,
) -> ErrorGuaranteed {
let mut err = struct_span_code_err!(
self.tcx().dcx(),
self.dcx(),
name.span,
E0034,
"multiple applicable items in scope"
Expand Down Expand Up @@ -576,7 +575,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
};

let mut err = struct_span_code_err!(
tcx.dcx(),
self.dcx(),
name.span,
E0220,
"associated type `{name}` not found for `{self_ty}` in the current scope"
Expand Down Expand Up @@ -662,7 +661,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
bounds.sort();
bounds.dedup();

let mut err = tcx.dcx().struct_span_err(
let mut err = self.dcx().struct_span_err(
name.span,
format!("the associated type `{name}` exists for `{self_ty}`, but its trait bounds were not satisfied")
);
Expand Down Expand Up @@ -829,7 +828,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {

trait_bound_spans.sort();
let mut err = struct_span_code_err!(
tcx.dcx(),
self.dcx(),
trait_bound_spans,
E0191,
"the value of the associated type{} {} must be specified",
Expand Down Expand Up @@ -1012,7 +1011,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
.next()
{
let reported =
struct_span_code_err!(tcx.dcx(), span, E0223, "ambiguous associated type")
struct_span_code_err!(self.dcx(), span, E0223, "ambiguous associated type")
.with_span_suggestion_verbose(
ident2.span.to(ident3.span),
format!("there is an associated function with a similar name: `{name}`"),
Expand Down Expand Up @@ -1120,7 +1119,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let last_span = *arg_spans.last().unwrap();
let span: MultiSpan = arg_spans.into();
let mut err = struct_span_code_err!(
self.tcx().dcx(),
self.dcx(),
span,
E0109,
"{kind} arguments are not allowed on {this_type}",
Expand All @@ -1139,11 +1138,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
&self,
regular_traits: &Vec<TraitAliasExpansionInfo<'_>>,
) -> ErrorGuaranteed {
let tcx = self.tcx();
let first_trait = &regular_traits[0];
let additional_trait = &regular_traits[1];
let mut err = struct_span_code_err!(
tcx.dcx(),
self.dcx(),
additional_trait.bottom().1,
E0225,
"only auto traits can be used as additional traits in a trait object"
Expand Down Expand Up @@ -1186,19 +1184,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
.find(|&trait_ref| tcx.is_trait_alias(trait_ref))
.map(|trait_ref| tcx.def_span(trait_ref));
let reported =
tcx.dcx().emit_err(TraitObjectDeclaredWithNoTraits { span, trait_alias_span });
self.dcx().emit_err(TraitObjectDeclaredWithNoTraits { span, trait_alias_span });
self.set_tainted_by_errors(reported);
reported
}
}

/// Emit an error for the given associated item constraint.
pub fn prohibit_assoc_item_constraint(
tcx: TyCtxt<'_>,
cx: &dyn HirTyLowerer<'_>,
constraint: &hir::AssocItemConstraint<'_>,
segment: Option<(DefId, &hir::PathSegment<'_>, Span)>,
) -> ErrorGuaranteed {
let mut err = tcx.dcx().create_err(AssocItemConstraintsNotAllowedHere {
let tcx = cx.tcx();
let mut err = cx.dcx().create_err(AssocItemConstraintsNotAllowedHere {
span: constraint.span,
fn_trait_expansion: if let Some((_, segment, span)) = segment
&& segment.args().parenthesized == hir::GenericArgsParentheses::ParenSugar
Expand Down
Loading