Auto merge of #127358 - oli-obk:taint_itemctxt, r=fmease
Automatically taint when reporting errors from ItemCtxt This isn't very robust yet, as you need to use `itemctxt.dcx()` instead of `tcx.dcx()` for it to take effect, but it's at least more convenient than sprinkling `set_tainted_by_errors` calls in individual places. based on https://github.com/rust-lang/rust/pull/127357 r? `@fmease`
This commit is contained in:
commit
7d640b670e
@ -18,7 +18,9 @@ use rustc_ast::Recovered;
|
|||||||
use rustc_data_structures::captures::Captures;
|
use rustc_data_structures::captures::Captures;
|
||||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
||||||
use rustc_data_structures::unord::UnordMap;
|
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::DefKind;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir::intravisit::{self, walk_generics, Visitor};
|
use rustc_hir::intravisit::{self, walk_generics, Visitor};
|
||||||
@ -161,7 +163,7 @@ pub struct CollectItemTypesVisitor<'tcx> {
|
|||||||
/// and suggest adding type parameters in the appropriate place, taking into consideration any and
|
/// and suggest adding type parameters in the appropriate place, taking into consideration any and
|
||||||
/// all already existing generic type parameters to avoid suggesting a name that is already in use.
|
/// all already existing generic type parameters to avoid suggesting a name that is already in use.
|
||||||
pub(crate) fn placeholder_type_error<'tcx>(
|
pub(crate) fn placeholder_type_error<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
cx: &dyn HirTyLowerer<'tcx>,
|
||||||
generics: Option<&hir::Generics<'_>>,
|
generics: Option<&hir::Generics<'_>>,
|
||||||
placeholder_types: Vec<Span>,
|
placeholder_types: Vec<Span>,
|
||||||
suggest: bool,
|
suggest: bool,
|
||||||
@ -172,21 +174,21 @@ pub(crate) fn placeholder_type_error<'tcx>(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
placeholder_type_error_diag(tcx, generics, placeholder_types, vec![], suggest, hir_ty, kind)
|
placeholder_type_error_diag(cx, generics, placeholder_types, vec![], suggest, hir_ty, kind)
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn placeholder_type_error_diag<'tcx>(
|
pub(crate) fn placeholder_type_error_diag<'cx, 'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
cx: &'cx dyn HirTyLowerer<'tcx>,
|
||||||
generics: Option<&hir::Generics<'_>>,
|
generics: Option<&hir::Generics<'_>>,
|
||||||
placeholder_types: Vec<Span>,
|
placeholder_types: Vec<Span>,
|
||||||
additional_spans: Vec<Span>,
|
additional_spans: Vec<Span>,
|
||||||
suggest: bool,
|
suggest: bool,
|
||||||
hir_ty: Option<&hir::Ty<'_>>,
|
hir_ty: Option<&hir::Ty<'_>>,
|
||||||
kind: &'static str,
|
kind: &'static str,
|
||||||
) -> Diag<'tcx> {
|
) -> Diag<'cx> {
|
||||||
if placeholder_types.is_empty() {
|
if placeholder_types.is_empty() {
|
||||||
return bad_placeholder(tcx, additional_spans, kind);
|
return bad_placeholder(cx, additional_spans, kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
let params = generics.map(|g| g.params).unwrap_or_default();
|
let params = generics.map(|g| g.params).unwrap_or_default();
|
||||||
@ -210,7 +212,7 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut err =
|
let mut err =
|
||||||
bad_placeholder(tcx, placeholder_types.into_iter().chain(additional_spans).collect(), kind);
|
bad_placeholder(cx, placeholder_types.into_iter().chain(additional_spans).collect(), kind);
|
||||||
|
|
||||||
// Suggest, but only if it is not a function in const or static
|
// Suggest, but only if it is not a function in const or static
|
||||||
if suggest {
|
if suggest {
|
||||||
@ -224,7 +226,7 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
|
|||||||
|
|
||||||
// Check if parent is const or static
|
// Check if parent is const or static
|
||||||
is_const_or_static = matches!(
|
is_const_or_static = matches!(
|
||||||
tcx.parent_hir_node(hir_ty.hir_id),
|
cx.tcx().parent_hir_node(hir_ty.hir_id),
|
||||||
Node::Item(&hir::Item {
|
Node::Item(&hir::Item {
|
||||||
kind: hir::ItemKind::Const(..) | hir::ItemKind::Static(..),
|
kind: hir::ItemKind::Const(..) | hir::ItemKind::Static(..),
|
||||||
..
|
..
|
||||||
@ -267,7 +269,16 @@ fn reject_placeholder_type_signatures_in_item<'tcx>(
|
|||||||
let mut visitor = HirPlaceholderCollector::default();
|
let mut visitor = HirPlaceholderCollector::default();
|
||||||
visitor.visit_item(item);
|
visitor.visit_item(item);
|
||||||
|
|
||||||
placeholder_type_error(tcx, Some(generics), visitor.0, suggest, None, item.kind.descr());
|
let icx = ItemCtxt::new(tcx, item.owner_id.def_id);
|
||||||
|
|
||||||
|
placeholder_type_error(
|
||||||
|
icx.lowerer(),
|
||||||
|
Some(generics),
|
||||||
|
visitor.0,
|
||||||
|
suggest,
|
||||||
|
None,
|
||||||
|
item.kind.descr(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
||||||
@ -329,15 +340,15 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Utility types and common code for the above passes.
|
// Utility types and common code for the above passes.
|
||||||
|
|
||||||
fn bad_placeholder<'tcx>(
|
fn bad_placeholder<'cx, 'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
cx: &'cx dyn HirTyLowerer<'tcx>,
|
||||||
mut spans: Vec<Span>,
|
mut spans: Vec<Span>,
|
||||||
kind: &'static str,
|
kind: &'static str,
|
||||||
) -> Diag<'tcx> {
|
) -> Diag<'cx> {
|
||||||
let kind = if kind.ends_with('s') { format!("{kind}es") } else { format!("{kind}s") };
|
let kind = if kind.ends_with('s') { format!("{kind}es") } else { format!("{kind}s") };
|
||||||
|
|
||||||
spans.sort();
|
spans.sort();
|
||||||
tcx.dcx().create_err(errors::PlaceholderNotAllowedItemSignatures { spans, kind })
|
cx.dcx().create_err(errors::PlaceholderNotAllowedItemSignatures { spans, kind })
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ItemCtxt<'tcx> {
|
impl<'tcx> ItemCtxt<'tcx> {
|
||||||
@ -370,6 +381,10 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||||||
self.tcx
|
self.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dcx(&self) -> DiagCtxtHandle<'_> {
|
||||||
|
self.tcx.dcx().taintable_handle(&self.tainted_by_errors)
|
||||||
|
}
|
||||||
|
|
||||||
fn item_def_id(&self) -> LocalDefId {
|
fn item_def_id(&self) -> LocalDefId {
|
||||||
self.item_def_id
|
self.item_def_id
|
||||||
}
|
}
|
||||||
@ -377,14 +392,13 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||||||
fn re_infer(&self, span: Span, reason: RegionInferReason<'_>) -> ty::Region<'tcx> {
|
fn re_infer(&self, span: Span, reason: RegionInferReason<'_>) -> ty::Region<'tcx> {
|
||||||
if let RegionInferReason::BorrowedObjectLifetimeDefault = reason {
|
if let RegionInferReason::BorrowedObjectLifetimeDefault = reason {
|
||||||
let e = struct_span_code_err!(
|
let e = struct_span_code_err!(
|
||||||
self.tcx().dcx(),
|
self.dcx(),
|
||||||
span,
|
span,
|
||||||
E0228,
|
E0228,
|
||||||
"the lifetime bound for this object type cannot be deduced \
|
"the lifetime bound for this object type cannot be deduced \
|
||||||
from context; please supply an explicit bound"
|
from context; please supply an explicit bound"
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
self.set_tainted_by_errors(e);
|
|
||||||
ty::Region::new_error(self.tcx(), e)
|
ty::Region::new_error(self.tcx(), e)
|
||||||
} else {
|
} else {
|
||||||
// This indicates an illegal lifetime in a non-assoc-trait position
|
// This indicates an illegal lifetime in a non-assoc-trait position
|
||||||
@ -509,10 +523,6 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_tainted_by_errors(&self, err: ErrorGuaranteed) {
|
|
||||||
self.tainted_by_errors.set(Some(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn lower_fn_sig(
|
fn lower_fn_sig(
|
||||||
&self,
|
&self,
|
||||||
decl: &hir::FnDecl<'tcx>,
|
decl: &hir::FnDecl<'tcx>,
|
||||||
@ -570,7 +580,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||||||
// `ident_span` to not emit an error twice when we have `fn foo(_: fn() -> _)`.
|
// `ident_span` to not emit an error twice when we have `fn foo(_: fn() -> _)`.
|
||||||
|
|
||||||
let mut diag = crate::collect::placeholder_type_error_diag(
|
let mut diag = crate::collect::placeholder_type_error_diag(
|
||||||
tcx,
|
self,
|
||||||
generics,
|
generics,
|
||||||
visitor.0,
|
visitor.0,
|
||||||
infer_replacements.iter().map(|(s, _)| *s).collect(),
|
infer_replacements.iter().map(|(s, _)| *s).collect(),
|
||||||
@ -590,7 +600,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.set_tainted_by_errors(diag.emit());
|
diag.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
(input_tys, output_ty)
|
(input_tys, output_ty)
|
||||||
@ -639,6 +649,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
|||||||
let it = tcx.hir().item(item_id);
|
let it = tcx.hir().item(item_id);
|
||||||
debug!(item = %it.ident, id = %it.hir_id());
|
debug!(item = %it.ident, id = %it.hir_id());
|
||||||
let def_id = item_id.owner_id.def_id;
|
let def_id = item_id.owner_id.def_id;
|
||||||
|
let icx = ItemCtxt::new(tcx, def_id);
|
||||||
|
|
||||||
match &it.kind {
|
match &it.kind {
|
||||||
// These don't define types.
|
// These don't define types.
|
||||||
@ -663,7 +674,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
|||||||
let mut visitor = HirPlaceholderCollector::default();
|
let mut visitor = HirPlaceholderCollector::default();
|
||||||
visitor.visit_foreign_item(item);
|
visitor.visit_foreign_item(item);
|
||||||
placeholder_type_error(
|
placeholder_type_error(
|
||||||
tcx,
|
icx.lowerer(),
|
||||||
None,
|
None,
|
||||||
visitor.0,
|
visitor.0,
|
||||||
false,
|
false,
|
||||||
@ -742,7 +753,14 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
|||||||
if !ty.is_suggestable_infer_ty() {
|
if !ty.is_suggestable_infer_ty() {
|
||||||
let mut visitor = HirPlaceholderCollector::default();
|
let mut visitor = HirPlaceholderCollector::default();
|
||||||
visitor.visit_item(it);
|
visitor.visit_item(it);
|
||||||
placeholder_type_error(tcx, None, visitor.0, false, None, it.kind.descr());
|
placeholder_type_error(
|
||||||
|
icx.lowerer(),
|
||||||
|
None,
|
||||||
|
visitor.0,
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
it.kind.descr(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -760,6 +778,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
|||||||
let trait_item = tcx.hir().trait_item(trait_item_id);
|
let trait_item = tcx.hir().trait_item(trait_item_id);
|
||||||
let def_id = trait_item_id.owner_id;
|
let def_id = trait_item_id.owner_id;
|
||||||
tcx.ensure().generics_of(def_id);
|
tcx.ensure().generics_of(def_id);
|
||||||
|
let icx = ItemCtxt::new(tcx, def_id.def_id);
|
||||||
|
|
||||||
match trait_item.kind {
|
match trait_item.kind {
|
||||||
hir::TraitItemKind::Fn(..) => {
|
hir::TraitItemKind::Fn(..) => {
|
||||||
@ -776,7 +795,14 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
|||||||
// Account for `const C: _;`.
|
// Account for `const C: _;`.
|
||||||
let mut visitor = HirPlaceholderCollector::default();
|
let mut visitor = HirPlaceholderCollector::default();
|
||||||
visitor.visit_trait_item(trait_item);
|
visitor.visit_trait_item(trait_item);
|
||||||
placeholder_type_error(tcx, None, visitor.0, false, None, "associated constant");
|
placeholder_type_error(
|
||||||
|
icx.lowerer(),
|
||||||
|
None,
|
||||||
|
visitor.0,
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
"associated constant",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -787,7 +813,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
|||||||
// Account for `type T = _;`.
|
// Account for `type T = _;`.
|
||||||
let mut visitor = HirPlaceholderCollector::default();
|
let mut visitor = HirPlaceholderCollector::default();
|
||||||
visitor.visit_trait_item(trait_item);
|
visitor.visit_trait_item(trait_item);
|
||||||
placeholder_type_error(tcx, None, visitor.0, false, None, "associated type");
|
placeholder_type_error(icx.lowerer(), None, visitor.0, false, None, "associated type");
|
||||||
}
|
}
|
||||||
|
|
||||||
hir::TraitItemKind::Type(_, None) => {
|
hir::TraitItemKind::Type(_, None) => {
|
||||||
@ -798,7 +824,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
|||||||
let mut visitor = HirPlaceholderCollector::default();
|
let mut visitor = HirPlaceholderCollector::default();
|
||||||
visitor.visit_trait_item(trait_item);
|
visitor.visit_trait_item(trait_item);
|
||||||
|
|
||||||
placeholder_type_error(tcx, None, visitor.0, false, None, "associated type");
|
placeholder_type_error(icx.lowerer(), None, visitor.0, false, None, "associated type");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -811,6 +837,7 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
|
|||||||
tcx.ensure().type_of(def_id);
|
tcx.ensure().type_of(def_id);
|
||||||
tcx.ensure().predicates_of(def_id);
|
tcx.ensure().predicates_of(def_id);
|
||||||
let impl_item = tcx.hir().impl_item(impl_item_id);
|
let impl_item = tcx.hir().impl_item(impl_item_id);
|
||||||
|
let icx = ItemCtxt::new(tcx, def_id.def_id);
|
||||||
match impl_item.kind {
|
match impl_item.kind {
|
||||||
hir::ImplItemKind::Fn(..) => {
|
hir::ImplItemKind::Fn(..) => {
|
||||||
tcx.ensure().codegen_fn_attrs(def_id);
|
tcx.ensure().codegen_fn_attrs(def_id);
|
||||||
@ -821,14 +848,21 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
|
|||||||
let mut visitor = HirPlaceholderCollector::default();
|
let mut visitor = HirPlaceholderCollector::default();
|
||||||
visitor.visit_impl_item(impl_item);
|
visitor.visit_impl_item(impl_item);
|
||||||
|
|
||||||
placeholder_type_error(tcx, None, visitor.0, false, None, "associated type");
|
placeholder_type_error(icx.lowerer(), None, visitor.0, false, None, "associated type");
|
||||||
}
|
}
|
||||||
hir::ImplItemKind::Const(ty, _) => {
|
hir::ImplItemKind::Const(ty, _) => {
|
||||||
// Account for `const T: _ = ..;`
|
// Account for `const T: _ = ..;`
|
||||||
if !ty.is_suggestable_infer_ty() {
|
if !ty.is_suggestable_infer_ty() {
|
||||||
let mut visitor = HirPlaceholderCollector::default();
|
let mut visitor = HirPlaceholderCollector::default();
|
||||||
visitor.visit_impl_item(impl_item);
|
visitor.visit_impl_item(impl_item);
|
||||||
placeholder_type_error(tcx, None, visitor.0, false, None, "associated constant");
|
placeholder_type_error(
|
||||||
|
icx.lowerer(),
|
||||||
|
None,
|
||||||
|
visitor.0,
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
"associated constant",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1385,7 +1419,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
|
|||||||
..
|
..
|
||||||
})
|
})
|
||||||
| Item(hir::Item { kind: ItemKind::Fn(sig, generics, _), .. }) => {
|
| Item(hir::Item { kind: ItemKind::Fn(sig, generics, _), .. }) => {
|
||||||
infer_return_ty_for_fn_sig(tcx, sig, generics, def_id, &icx)
|
infer_return_ty_for_fn_sig(sig, generics, def_id, &icx)
|
||||||
}
|
}
|
||||||
|
|
||||||
ImplItem(hir::ImplItem { kind: ImplItemKind::Fn(sig, _), generics, .. }) => {
|
ImplItem(hir::ImplItem { kind: ImplItemKind::Fn(sig, _), generics, .. }) => {
|
||||||
@ -1402,7 +1436,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
|
|||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
infer_return_ty_for_fn_sig(tcx, sig, generics, def_id, &icx)
|
infer_return_ty_for_fn_sig(sig, generics, def_id, &icx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1455,12 +1489,12 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn infer_return_ty_for_fn_sig<'tcx>(
|
fn infer_return_ty_for_fn_sig<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
sig: &hir::FnSig<'tcx>,
|
sig: &hir::FnSig<'tcx>,
|
||||||
generics: &hir::Generics<'_>,
|
generics: &hir::Generics<'_>,
|
||||||
def_id: LocalDefId,
|
def_id: LocalDefId,
|
||||||
icx: &ItemCtxt<'tcx>,
|
icx: &ItemCtxt<'tcx>,
|
||||||
) -> ty::PolyFnSig<'tcx> {
|
) -> ty::PolyFnSig<'tcx> {
|
||||||
|
let tcx = icx.tcx;
|
||||||
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
||||||
|
|
||||||
match sig.decl.output.get_infer_ret_ty() {
|
match sig.decl.output.get_infer_ret_ty() {
|
||||||
@ -1492,7 +1526,7 @@ fn infer_return_ty_for_fn_sig<'tcx>(
|
|||||||
let mut visitor = HirPlaceholderCollector::default();
|
let mut visitor = HirPlaceholderCollector::default();
|
||||||
visitor.visit_ty(ty);
|
visitor.visit_ty(ty);
|
||||||
|
|
||||||
let mut diag = bad_placeholder(tcx, visitor.0, "return type");
|
let mut diag = bad_placeholder(icx.lowerer(), visitor.0, "return type");
|
||||||
let ret_ty = fn_sig.output();
|
let ret_ty = fn_sig.output();
|
||||||
// Don't leak types into signatures unless they're nameable!
|
// Don't leak types into signatures unless they're nameable!
|
||||||
// For example, if a function returns itself, we don't want that
|
// For example, if a function returns itself, we don't want that
|
||||||
|
@ -12,6 +12,7 @@ use rustc_span::symbol::Ident;
|
|||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
|
|
||||||
use crate::errors::TypeofReservedKeywordUsed;
|
use crate::errors::TypeofReservedKeywordUsed;
|
||||||
|
use crate::hir_ty_lowering::HirTyLowerer;
|
||||||
|
|
||||||
use super::bad_placeholder;
|
use super::bad_placeholder;
|
||||||
use super::ItemCtxt;
|
use super::ItemCtxt;
|
||||||
@ -357,7 +358,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
|
|||||||
.and_then(|body_id| {
|
.and_then(|body_id| {
|
||||||
ty.is_suggestable_infer_ty().then(|| {
|
ty.is_suggestable_infer_ty().then(|| {
|
||||||
infer_placeholder_type(
|
infer_placeholder_type(
|
||||||
tcx,
|
icx.lowerer(),
|
||||||
def_id,
|
def_id,
|
||||||
body_id,
|
body_id,
|
||||||
ty.span,
|
ty.span,
|
||||||
@ -381,7 +382,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
|
|||||||
ImplItemKind::Const(ty, body_id) => {
|
ImplItemKind::Const(ty, body_id) => {
|
||||||
if ty.is_suggestable_infer_ty() {
|
if ty.is_suggestable_infer_ty() {
|
||||||
infer_placeholder_type(
|
infer_placeholder_type(
|
||||||
tcx,
|
icx.lowerer(),
|
||||||
def_id,
|
def_id,
|
||||||
body_id,
|
body_id,
|
||||||
ty.span,
|
ty.span,
|
||||||
@ -405,7 +406,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
|
|||||||
ItemKind::Static(ty, .., body_id) => {
|
ItemKind::Static(ty, .., body_id) => {
|
||||||
if ty.is_suggestable_infer_ty() {
|
if ty.is_suggestable_infer_ty() {
|
||||||
infer_placeholder_type(
|
infer_placeholder_type(
|
||||||
tcx,
|
icx.lowerer(),
|
||||||
def_id,
|
def_id,
|
||||||
body_id,
|
body_id,
|
||||||
ty.span,
|
ty.span,
|
||||||
@ -418,7 +419,14 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
|
|||||||
}
|
}
|
||||||
ItemKind::Const(ty, _, body_id) => {
|
ItemKind::Const(ty, _, body_id) => {
|
||||||
if ty.is_suggestable_infer_ty() {
|
if ty.is_suggestable_infer_ty() {
|
||||||
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident, "constant")
|
infer_placeholder_type(
|
||||||
|
icx.lowerer(),
|
||||||
|
def_id,
|
||||||
|
body_id,
|
||||||
|
ty.span,
|
||||||
|
item.ident,
|
||||||
|
"constant",
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
icx.lower_ty(ty)
|
icx.lower_ty(ty)
|
||||||
}
|
}
|
||||||
@ -559,21 +567,22 @@ pub(super) fn type_of_opaque(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn infer_placeholder_type<'a>(
|
fn infer_placeholder_type<'tcx>(
|
||||||
tcx: TyCtxt<'a>,
|
cx: &dyn HirTyLowerer<'tcx>,
|
||||||
def_id: LocalDefId,
|
def_id: LocalDefId,
|
||||||
body_id: hir::BodyId,
|
body_id: hir::BodyId,
|
||||||
span: Span,
|
span: Span,
|
||||||
item_ident: Ident,
|
item_ident: Ident,
|
||||||
kind: &'static str,
|
kind: &'static str,
|
||||||
) -> Ty<'a> {
|
) -> Ty<'tcx> {
|
||||||
|
let tcx = cx.tcx();
|
||||||
let ty = tcx.diagnostic_only_typeck(def_id).node_type(body_id.hir_id);
|
let ty = tcx.diagnostic_only_typeck(def_id).node_type(body_id.hir_id);
|
||||||
|
|
||||||
// If this came from a free `const` or `static mut?` item,
|
// If this came from a free `const` or `static mut?` item,
|
||||||
// then the user may have written e.g. `const A = 42;`.
|
// then the user may have written e.g. `const A = 42;`.
|
||||||
// In this case, the parser has stashed a diagnostic for
|
// In this case, the parser has stashed a diagnostic for
|
||||||
// us to improve in typeck so we do that now.
|
// us to improve in typeck so we do that now.
|
||||||
let guar = tcx
|
let guar = cx
|
||||||
.dcx()
|
.dcx()
|
||||||
.try_steal_modify_and_emit_err(span, StashKey::ItemNoType, |err| {
|
.try_steal_modify_and_emit_err(span, StashKey::ItemNoType, |err| {
|
||||||
if !ty.references_error() {
|
if !ty.references_error() {
|
||||||
@ -602,7 +611,7 @@ fn infer_placeholder_type<'a>(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
let mut diag = bad_placeholder(tcx, vec![span], kind);
|
let mut diag = bad_placeholder(cx, vec![span], kind);
|
||||||
|
|
||||||
if !ty.references_error() {
|
if !ty.references_error() {
|
||||||
if let Some(ty) = ty.make_suggestable(tcx, false, None) {
|
if let Some(ty) = ty.make_suggestable(tcx, false, None) {
|
||||||
|
@ -76,7 +76,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if unbounds.len() > 1 {
|
if unbounds.len() > 1 {
|
||||||
tcx.dcx().emit_err(errors::MultipleRelaxedDefaultBounds {
|
self.dcx().emit_err(errors::MultipleRelaxedDefaultBounds {
|
||||||
spans: unbounds.iter().map(|ptr| ptr.span).collect(),
|
spans: unbounds.iter().map(|ptr| ptr.span).collect(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// There was a `?Trait` bound, but it was not `?Sized`; warn.
|
// There was a `?Trait` bound, but it was not `?Sized`; warn.
|
||||||
tcx.dcx().span_warn(
|
self.dcx().span_warn(
|
||||||
unbound.span,
|
unbound.span,
|
||||||
"relaxing a default bound only does something for `?Sized`; \
|
"relaxing a default bound only does something for `?Sized`; \
|
||||||
all other traits are not bound by default",
|
all other traits are not bound by default",
|
||||||
@ -310,7 +310,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
duplicates
|
duplicates
|
||||||
.entry(assoc_item.def_id)
|
.entry(assoc_item.def_id)
|
||||||
.and_modify(|prev_span| {
|
.and_modify(|prev_span| {
|
||||||
tcx.dcx().emit_err(errors::ValueOfAssociatedStructAlreadySpecified {
|
self.dcx().emit_err(errors::ValueOfAssociatedStructAlreadySpecified {
|
||||||
span: constraint.span,
|
span: constraint.span,
|
||||||
prev_span: *prev_span,
|
prev_span: *prev_span,
|
||||||
item_name: constraint.ident,
|
item_name: constraint.ident,
|
||||||
@ -338,7 +338,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
.into(),
|
.into(),
|
||||||
ty::GenericParamDefKind::Type { .. } => {
|
ty::GenericParamDefKind::Type { .. } => {
|
||||||
let guar = *emitted_bad_param_err.get_or_insert_with(|| {
|
let guar = *emitted_bad_param_err.get_or_insert_with(|| {
|
||||||
tcx.dcx().emit_err(
|
self.dcx().emit_err(
|
||||||
crate::errors::ReturnTypeNotationIllegalParam::Type {
|
crate::errors::ReturnTypeNotationIllegalParam::Type {
|
||||||
span: path_span,
|
span: path_span,
|
||||||
param_span: tcx.def_span(param.def_id),
|
param_span: tcx.def_span(param.def_id),
|
||||||
@ -349,7 +349,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
}
|
}
|
||||||
ty::GenericParamDefKind::Const { .. } => {
|
ty::GenericParamDefKind::Const { .. } => {
|
||||||
let guar = *emitted_bad_param_err.get_or_insert_with(|| {
|
let guar = *emitted_bad_param_err.get_or_insert_with(|| {
|
||||||
tcx.dcx().emit_err(
|
self.dcx().emit_err(
|
||||||
crate::errors::ReturnTypeNotationIllegalParam::Const {
|
crate::errors::ReturnTypeNotationIllegalParam::Const {
|
||||||
span: path_span,
|
span: path_span,
|
||||||
param_span: tcx.def_span(param.def_id),
|
param_span: tcx.def_span(param.def_id),
|
||||||
@ -371,7 +371,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
{
|
{
|
||||||
alias_ty.into()
|
alias_ty.into()
|
||||||
} else {
|
} else {
|
||||||
return Err(tcx.dcx().emit_err(crate::errors::ReturnTypeNotationOnNonRpitit {
|
return Err(self.dcx().emit_err(crate::errors::ReturnTypeNotationOnNonRpitit {
|
||||||
span: constraint.span,
|
span: constraint.span,
|
||||||
ty: tcx.liberate_late_bound_regions(assoc_item.def_id, output),
|
ty: tcx.liberate_late_bound_regions(assoc_item.def_id, output),
|
||||||
fn_span: tcx.hir().span_if_local(assoc_item.def_id),
|
fn_span: tcx.hir().span_if_local(assoc_item.def_id),
|
||||||
@ -417,7 +417,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
let ty = alias_term
|
let ty = alias_term
|
||||||
.map_bound(|alias| tcx.type_of(alias.def_id).instantiate(tcx, alias.args));
|
.map_bound(|alias| tcx.type_of(alias.def_id).instantiate(tcx, alias.args));
|
||||||
let ty =
|
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));
|
tcx.feed_anon_const_type(anon_const.def_id, ty::EarlyBinder::bind(ty));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,7 +426,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
|
|
||||||
match constraint.kind {
|
match constraint.kind {
|
||||||
hir::AssocItemConstraintKind::Equality { .. } if let ty::AssocKind::Fn = assoc_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,
|
span: constraint.span,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -462,7 +462,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
late_bound_in_term,
|
late_bound_in_term,
|
||||||
|br_name| {
|
|br_name| {
|
||||||
struct_span_code_err!(
|
struct_span_code_err!(
|
||||||
tcx.dcx(),
|
self.dcx(),
|
||||||
constraint.span,
|
constraint.span,
|
||||||
E0582,
|
E0582,
|
||||||
"binding for associated type `{}` references {}, \
|
"binding for associated type `{}` references {}, \
|
||||||
@ -519,7 +519,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
///
|
///
|
||||||
/// [^1]: <https://github.com/rust-lang/project-const-generics/issues/28>.
|
/// [^1]: <https://github.com/rust-lang/project-const-generics/issues/28>.
|
||||||
fn check_assoc_const_binding_type<'tcx>(
|
fn check_assoc_const_binding_type<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
cx: &dyn HirTyLowerer<'tcx>,
|
||||||
assoc_const: Ident,
|
assoc_const: Ident,
|
||||||
ty: ty::Binder<'tcx, Ty<'tcx>>,
|
ty: ty::Binder<'tcx, Ty<'tcx>>,
|
||||||
hir_id: hir::HirId,
|
hir_id: hir::HirId,
|
||||||
@ -536,13 +536,14 @@ fn check_assoc_const_binding_type<'tcx>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut collector = GenericParamAndBoundVarCollector {
|
let mut collector = GenericParamAndBoundVarCollector {
|
||||||
tcx,
|
cx,
|
||||||
params: Default::default(),
|
params: Default::default(),
|
||||||
vars: Default::default(),
|
vars: Default::default(),
|
||||||
depth: ty::INNERMOST,
|
depth: ty::INNERMOST,
|
||||||
};
|
};
|
||||||
let mut guar = ty.visit_with(&mut collector).break_value();
|
let mut guar = ty.visit_with(&mut collector).break_value();
|
||||||
|
|
||||||
|
let tcx = cx.tcx();
|
||||||
let ty_note = ty
|
let ty_note = ty
|
||||||
.make_suggestable(tcx, false, None)
|
.make_suggestable(tcx, false, None)
|
||||||
.map(|ty| crate::errors::TyOfAssocConstBindingNote { assoc_const, ty });
|
.map(|ty| crate::errors::TyOfAssocConstBindingNote { assoc_const, ty });
|
||||||
@ -556,7 +557,7 @@ fn check_assoc_const_binding_type<'tcx>(
|
|||||||
for index in collector.params {
|
for index in collector.params {
|
||||||
let param = generics.param_at(index as _, tcx);
|
let param = generics.param_at(index as _, tcx);
|
||||||
let is_self_param = param.name == rustc_span::symbol::kw::SelfUpper;
|
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,
|
span: assoc_const.span,
|
||||||
assoc_const,
|
assoc_const,
|
||||||
param_name: param.name,
|
param_name: param.name,
|
||||||
@ -574,7 +575,7 @@ fn check_assoc_const_binding_type<'tcx>(
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
for (var_def_id, var_name) in collector.vars {
|
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 {
|
crate::errors::EscapingBoundVarInTyOfAssocConstBinding {
|
||||||
span: assoc_const.span,
|
span: assoc_const.span,
|
||||||
assoc_const,
|
assoc_const,
|
||||||
@ -590,14 +591,14 @@ fn check_assoc_const_binding_type<'tcx>(
|
|||||||
Ty::new_error(tcx, guar)
|
Ty::new_error(tcx, guar)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GenericParamAndBoundVarCollector<'tcx> {
|
struct GenericParamAndBoundVarCollector<'a, 'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
cx: &'a dyn HirTyLowerer<'tcx>,
|
||||||
params: FxIndexSet<u32>,
|
params: FxIndexSet<u32>,
|
||||||
vars: FxIndexSet<(DefId, Symbol)>,
|
vars: FxIndexSet<(DefId, Symbol)>,
|
||||||
depth: ty::DebruijnIndex,
|
depth: ty::DebruijnIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'tcx> {
|
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'_, 'tcx> {
|
||||||
type Result = ControlFlow<ErrorGuaranteed>;
|
type Result = ControlFlow<ErrorGuaranteed>;
|
||||||
|
|
||||||
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(
|
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(
|
||||||
@ -620,7 +621,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'tcx>
|
|||||||
ty::BoundTyKind::Param(def_id, name) => (def_id, name),
|
ty::BoundTyKind::Param(def_id, name) => (def_id, name),
|
||||||
ty::BoundTyKind::Anon => {
|
ty::BoundTyKind::Anon => {
|
||||||
let reported = self
|
let reported = self
|
||||||
.tcx
|
.cx
|
||||||
.dcx()
|
.dcx()
|
||||||
.delayed_bug(format!("unexpected anon bound ty: {:?}", bt.var));
|
.delayed_bug(format!("unexpected anon bound ty: {:?}", bt.var));
|
||||||
return ControlFlow::Break(reported);
|
return ControlFlow::Break(reported);
|
||||||
@ -643,7 +644,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'tcx>
|
|||||||
ty::BrNamed(def_id, name) => (def_id, name),
|
ty::BrNamed(def_id, name) => (def_id, name),
|
||||||
ty::BrAnon | ty::BrEnv => {
|
ty::BrAnon | ty::BrEnv => {
|
||||||
let guar = self
|
let guar = self
|
||||||
.tcx
|
.cx
|
||||||
.dcx()
|
.dcx()
|
||||||
.delayed_bug(format!("unexpected bound region kind: {:?}", br.kind));
|
.delayed_bug(format!("unexpected bound region kind: {:?}", br.kind));
|
||||||
return ControlFlow::Break(guar);
|
return ControlFlow::Break(guar);
|
||||||
@ -661,7 +662,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'tcx>
|
|||||||
self.params.insert(param.index);
|
self.params.insert(param.index);
|
||||||
}
|
}
|
||||||
ty::ConstKind::Bound(db, ty::BoundVar { .. }) if db >= self.depth => {
|
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);
|
return ControlFlow::Break(guar);
|
||||||
}
|
}
|
||||||
_ if ct.has_param() || ct.has_bound_vars() => return ct.super_visit_with(self),
|
_ if ct.has_param() || ct.has_bound_vars() => return ct.super_visit_with(self),
|
||||||
|
@ -46,7 +46,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.tcx().dcx().emit_err(MissingTypeParams {
|
self.dcx().emit_err(MissingTypeParams {
|
||||||
span,
|
span,
|
||||||
def_span: self.tcx().def_span(def_id),
|
def_span: self.tcx().def_span(def_id),
|
||||||
span_snippet: self.tcx().sess.source_map().span_to_snippet(span).ok(),
|
span_snippet: self.tcx().sess.source_map().span_to_snippet(span).ok(),
|
||||||
@ -109,7 +109,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
|
|
||||||
if is_impl {
|
if is_impl {
|
||||||
let trait_name = self.tcx().def_path_str(trait_def_id);
|
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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
|
|
||||||
if is_dummy {
|
if is_dummy {
|
||||||
err.label = Some(errors::AssocItemNotFoundLabel::NotFound { span });
|
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()
|
let all_candidate_names: Vec<_> = all_candidates()
|
||||||
@ -174,7 +174,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
assoc_kind: assoc_kind_str,
|
assoc_kind: assoc_kind_str,
|
||||||
suggested_name,
|
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
|
// If we didn't find a good item in the supertraits (or couldn't get
|
||||||
@ -239,10 +239,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
assoc_kind: assoc_kind_str,
|
assoc_kind: assoc_kind_str,
|
||||||
suggested_name,
|
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(
|
if suggest_constraining_type_param(
|
||||||
tcx,
|
tcx,
|
||||||
generics,
|
generics,
|
||||||
@ -264,7 +264,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
}
|
}
|
||||||
return err.emit();
|
return err.emit();
|
||||||
}
|
}
|
||||||
return tcx.dcx().emit_err(err);
|
return self.dcx().emit_err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,7 +291,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
err.label = Some(errors::AssocItemNotFoundLabel::NotFound { span: assoc_name.span });
|
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(
|
fn complain_about_assoc_kind_mismatch(
|
||||||
@ -347,7 +347,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
(ident.span, None, assoc_kind, assoc_item.kind)
|
(ident.span, None, assoc_kind, assoc_item.kind)
|
||||||
};
|
};
|
||||||
|
|
||||||
tcx.dcx().emit_err(errors::AssocKindMismatch {
|
self.dcx().emit_err(errors::AssocKindMismatch {
|
||||||
span,
|
span,
|
||||||
expected: super::assoc_kind_str(expected),
|
expected: super::assoc_kind_str(expected),
|
||||||
got: super::assoc_kind_str(got),
|
got: super::assoc_kind_str(got),
|
||||||
@ -366,8 +366,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
traits: &[String],
|
traits: &[String],
|
||||||
name: Symbol,
|
name: Symbol,
|
||||||
) -> ErrorGuaranteed {
|
) -> ErrorGuaranteed {
|
||||||
let mut err =
|
let mut err = struct_span_code_err!(self.dcx(), span, E0223, "ambiguous associated type");
|
||||||
struct_span_code_err!(self.tcx().dcx(), span, E0223, "ambiguous associated type");
|
|
||||||
if self
|
if self
|
||||||
.tcx()
|
.tcx()
|
||||||
.resolutions(())
|
.resolutions(())
|
||||||
@ -463,9 +462,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let reported = err.emit();
|
err.emit()
|
||||||
self.set_tainted_by_errors(reported);
|
|
||||||
reported
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn complain_about_ambiguous_inherent_assoc_ty(
|
pub(crate) fn complain_about_ambiguous_inherent_assoc_ty(
|
||||||
@ -475,16 +472,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
span: Span,
|
span: Span,
|
||||||
) -> ErrorGuaranteed {
|
) -> ErrorGuaranteed {
|
||||||
let mut err = struct_span_code_err!(
|
let mut err = struct_span_code_err!(
|
||||||
self.tcx().dcx(),
|
self.dcx(),
|
||||||
name.span,
|
name.span,
|
||||||
E0034,
|
E0034,
|
||||||
"multiple applicable items in scope"
|
"multiple applicable items in scope"
|
||||||
);
|
);
|
||||||
err.span_label(name.span, format!("multiple `{name}` found"));
|
err.span_label(name.span, format!("multiple `{name}` found"));
|
||||||
self.note_ambiguous_inherent_assoc_ty(&mut err, candidates, span);
|
self.note_ambiguous_inherent_assoc_ty(&mut err, candidates, span);
|
||||||
let reported = err.emit();
|
err.emit()
|
||||||
self.set_tainted_by_errors(reported);
|
|
||||||
reported
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(fmease): Heavily adapted from `rustc_hir_typeck::method::suggest`. Deduplicate.
|
// FIXME(fmease): Heavily adapted from `rustc_hir_typeck::method::suggest`. Deduplicate.
|
||||||
@ -576,7 +571,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut err = struct_span_code_err!(
|
let mut err = struct_span_code_err!(
|
||||||
tcx.dcx(),
|
self.dcx(),
|
||||||
name.span,
|
name.span,
|
||||||
E0220,
|
E0220,
|
||||||
"associated type `{name}` not found for `{self_ty}` in the current scope"
|
"associated type `{name}` not found for `{self_ty}` in the current scope"
|
||||||
@ -662,7 +657,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
bounds.sort();
|
bounds.sort();
|
||||||
bounds.dedup();
|
bounds.dedup();
|
||||||
|
|
||||||
let mut err = tcx.dcx().struct_span_err(
|
let mut err = self.dcx().struct_span_err(
|
||||||
name.span,
|
name.span,
|
||||||
format!("the associated type `{name}` exists for `{self_ty}`, but its trait bounds were not satisfied")
|
format!("the associated type `{name}` exists for `{self_ty}`, but its trait bounds were not satisfied")
|
||||||
);
|
);
|
||||||
@ -829,7 +824,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
|
|
||||||
trait_bound_spans.sort();
|
trait_bound_spans.sort();
|
||||||
let mut err = struct_span_code_err!(
|
let mut err = struct_span_code_err!(
|
||||||
tcx.dcx(),
|
self.dcx(),
|
||||||
trait_bound_spans,
|
trait_bound_spans,
|
||||||
E0191,
|
E0191,
|
||||||
"the value of the associated type{} {} must be specified",
|
"the value of the associated type{} {} must be specified",
|
||||||
@ -974,7 +969,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.set_tainted_by_errors(err.emit());
|
err.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// On ambiguous associated type, look for an associated function whose name matches the
|
/// On ambiguous associated type, look for an associated function whose name matches the
|
||||||
@ -1011,17 +1006,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
.filter_by_name_unhygienic(Symbol::intern(&name))
|
.filter_by_name_unhygienic(Symbol::intern(&name))
|
||||||
.next()
|
.next()
|
||||||
{
|
{
|
||||||
let reported =
|
Err(struct_span_code_err!(self.dcx(), span, E0223, "ambiguous associated type")
|
||||||
struct_span_code_err!(tcx.dcx(), span, E0223, "ambiguous associated type")
|
.with_span_suggestion_verbose(
|
||||||
.with_span_suggestion_verbose(
|
ident2.span.to(ident3.span),
|
||||||
ident2.span.to(ident3.span),
|
format!("there is an associated function with a similar name: `{name}`"),
|
||||||
format!("there is an associated function with a similar name: `{name}`"),
|
name,
|
||||||
name,
|
Applicability::MaybeIncorrect,
|
||||||
Applicability::MaybeIncorrect,
|
)
|
||||||
)
|
.emit())
|
||||||
.emit();
|
|
||||||
self.set_tainted_by_errors(reported);
|
|
||||||
Err(reported)
|
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1120,7 +1112,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
let last_span = *arg_spans.last().unwrap();
|
let last_span = *arg_spans.last().unwrap();
|
||||||
let span: MultiSpan = arg_spans.into();
|
let span: MultiSpan = arg_spans.into();
|
||||||
let mut err = struct_span_code_err!(
|
let mut err = struct_span_code_err!(
|
||||||
self.tcx().dcx(),
|
self.dcx(),
|
||||||
span,
|
span,
|
||||||
E0109,
|
E0109,
|
||||||
"{kind} arguments are not allowed on {this_type}",
|
"{kind} arguments are not allowed on {this_type}",
|
||||||
@ -1130,20 +1122,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
err.span_label(span, format!("not allowed on {what}"));
|
err.span_label(span, format!("not allowed on {what}"));
|
||||||
}
|
}
|
||||||
generics_args_err_extend(self.tcx(), segments, &mut err, err_extend);
|
generics_args_err_extend(self.tcx(), segments, &mut err, err_extend);
|
||||||
let reported = err.emit();
|
err.emit()
|
||||||
self.set_tainted_by_errors(reported);
|
|
||||||
reported
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn report_trait_object_addition_traits_error(
|
pub fn report_trait_object_addition_traits_error(
|
||||||
&self,
|
&self,
|
||||||
regular_traits: &Vec<TraitAliasExpansionInfo<'_>>,
|
regular_traits: &Vec<TraitAliasExpansionInfo<'_>>,
|
||||||
) -> ErrorGuaranteed {
|
) -> ErrorGuaranteed {
|
||||||
let tcx = self.tcx();
|
|
||||||
let first_trait = ®ular_traits[0];
|
let first_trait = ®ular_traits[0];
|
||||||
let additional_trait = ®ular_traits[1];
|
let additional_trait = ®ular_traits[1];
|
||||||
let mut err = struct_span_code_err!(
|
let mut err = struct_span_code_err!(
|
||||||
tcx.dcx(),
|
self.dcx(),
|
||||||
additional_trait.bottom().1,
|
additional_trait.bottom().1,
|
||||||
E0225,
|
E0225,
|
||||||
"only auto traits can be used as additional traits in a trait object"
|
"only auto traits can be used as additional traits in a trait object"
|
||||||
@ -1169,9 +1158,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
for more information on them, visit \
|
for more information on them, visit \
|
||||||
<https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>",
|
<https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>",
|
||||||
);
|
);
|
||||||
let reported = err.emit();
|
err.emit()
|
||||||
self.set_tainted_by_errors(reported);
|
|
||||||
reported
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn report_trait_object_with_no_traits_error(
|
pub fn report_trait_object_with_no_traits_error(
|
||||||
@ -1185,20 +1172,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
.map(|&(trait_ref, _)| trait_ref.def_id())
|
.map(|&(trait_ref, _)| trait_ref.def_id())
|
||||||
.find(|&trait_ref| tcx.is_trait_alias(trait_ref))
|
.find(|&trait_ref| tcx.is_trait_alias(trait_ref))
|
||||||
.map(|trait_ref| tcx.def_span(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.
|
/// Emit an error for the given associated item constraint.
|
||||||
pub fn prohibit_assoc_item_constraint(
|
pub fn prohibit_assoc_item_constraint(
|
||||||
tcx: TyCtxt<'_>,
|
cx: &dyn HirTyLowerer<'_>,
|
||||||
constraint: &hir::AssocItemConstraint<'_>,
|
constraint: &hir::AssocItemConstraint<'_>,
|
||||||
segment: Option<(DefId, &hir::PathSegment<'_>, Span)>,
|
segment: Option<(DefId, &hir::PathSegment<'_>, Span)>,
|
||||||
) -> ErrorGuaranteed {
|
) -> ErrorGuaranteed {
|
||||||
let mut err = tcx.dcx().create_err(AssocItemConstraintsNotAllowedHere {
|
let tcx = cx.tcx();
|
||||||
|
let mut err = cx.dcx().create_err(AssocItemConstraintsNotAllowedHere {
|
||||||
span: constraint.span,
|
span: constraint.span,
|
||||||
fn_trait_expansion: if let Some((_, segment, span)) = segment
|
fn_trait_expansion: if let Some((_, segment, span)) = segment
|
||||||
&& segment.args().parenthesized == hir::GenericArgsParentheses::ParenSugar
|
&& segment.args().parenthesized == hir::GenericArgsParentheses::ParenSugar
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use super::IsMethodCall;
|
use super::{HirTyLowerer, IsMethodCall};
|
||||||
use crate::errors::wrong_number_of_generic_args::{GenericArgsInfo, WrongNumberOfGenericArgs};
|
use crate::errors::wrong_number_of_generic_args::{GenericArgsInfo, WrongNumberOfGenericArgs};
|
||||||
use crate::hir_ty_lowering::{
|
use crate::hir_ty_lowering::{
|
||||||
errors::prohibit_assoc_item_constraint, ExplicitLateBound, GenericArgCountMismatch,
|
errors::prohibit_assoc_item_constraint, ExplicitLateBound, GenericArgCountMismatch,
|
||||||
@ -13,7 +13,7 @@ use rustc_hir::def::{DefKind, Res};
|
|||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::GenericArg;
|
use rustc_hir::GenericArg;
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, GenericArgsRef, GenericParamDef, GenericParamDefKind, IsSuggestable, Ty, TyCtxt,
|
self, GenericArgsRef, GenericParamDef, GenericParamDefKind, IsSuggestable, Ty,
|
||||||
};
|
};
|
||||||
use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS;
|
use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS;
|
||||||
use rustc_span::symbol::{kw, sym};
|
use rustc_span::symbol::{kw, sym};
|
||||||
@ -22,15 +22,16 @@ use smallvec::SmallVec;
|
|||||||
/// Report an error that a generic argument did not match the generic parameter that was
|
/// Report an error that a generic argument did not match the generic parameter that was
|
||||||
/// expected.
|
/// expected.
|
||||||
fn generic_arg_mismatch_err(
|
fn generic_arg_mismatch_err(
|
||||||
tcx: TyCtxt<'_>,
|
cx: &dyn HirTyLowerer<'_>,
|
||||||
arg: &GenericArg<'_>,
|
arg: &GenericArg<'_>,
|
||||||
param: &GenericParamDef,
|
param: &GenericParamDef,
|
||||||
possible_ordering_error: bool,
|
possible_ordering_error: bool,
|
||||||
help: Option<String>,
|
help: Option<String>,
|
||||||
) -> ErrorGuaranteed {
|
) -> ErrorGuaranteed {
|
||||||
|
let tcx = cx.tcx();
|
||||||
let sess = tcx.sess;
|
let sess = tcx.sess;
|
||||||
let mut err = struct_span_code_err!(
|
let mut err = struct_span_code_err!(
|
||||||
tcx.dcx(),
|
cx.dcx(),
|
||||||
arg.span(),
|
arg.span(),
|
||||||
E0747,
|
E0747,
|
||||||
"{} provided when a {} was expected",
|
"{} provided when a {} was expected",
|
||||||
@ -171,7 +172,7 @@ fn generic_arg_mismatch_err(
|
|||||||
/// - `inferred_kind`: if no parameter was provided, and inference
|
/// - `inferred_kind`: if no parameter was provided, and inference
|
||||||
/// is enabled, then creates a suitable inference variable.
|
/// is enabled, then creates a suitable inference variable.
|
||||||
pub fn lower_generic_args<'tcx: 'a, 'a>(
|
pub fn lower_generic_args<'tcx: 'a, 'a>(
|
||||||
tcx: TyCtxt<'tcx>,
|
cx: &dyn HirTyLowerer<'tcx>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
parent_args: &[ty::GenericArg<'tcx>],
|
parent_args: &[ty::GenericArg<'tcx>],
|
||||||
has_self: bool,
|
has_self: bool,
|
||||||
@ -179,6 +180,7 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
|
|||||||
arg_count: &GenericArgCountResult,
|
arg_count: &GenericArgCountResult,
|
||||||
ctx: &mut impl GenericArgsLowerer<'a, 'tcx>,
|
ctx: &mut impl GenericArgsLowerer<'a, 'tcx>,
|
||||||
) -> GenericArgsRef<'tcx> {
|
) -> GenericArgsRef<'tcx> {
|
||||||
|
let tcx = cx.tcx();
|
||||||
// Collect the segments of the path; we need to instantiate arguments
|
// Collect the segments of the path; we need to instantiate arguments
|
||||||
// for parameters throughout the entire path (wherever there are
|
// for parameters throughout the entire path (wherever there are
|
||||||
// generic parameters).
|
// generic parameters).
|
||||||
@ -326,7 +328,7 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
|
|||||||
param_types_present.dedup();
|
param_types_present.dedup();
|
||||||
|
|
||||||
generic_arg_mismatch_err(
|
generic_arg_mismatch_err(
|
||||||
tcx,
|
cx,
|
||||||
arg,
|
arg,
|
||||||
param,
|
param,
|
||||||
!args_iter.clone().is_sorted_by_key(|arg| arg.to_ord()),
|
!args_iter.clone().is_sorted_by_key(|arg| arg.to_ord()),
|
||||||
@ -381,7 +383,7 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
|
|||||||
assert_eq!(kind, "lifetime");
|
assert_eq!(kind, "lifetime");
|
||||||
let (provided_arg, param) =
|
let (provided_arg, param) =
|
||||||
force_infer_lt.expect("lifetimes ought to have been inferred");
|
force_infer_lt.expect("lifetimes ought to have been inferred");
|
||||||
generic_arg_mismatch_err(tcx, provided_arg, param, false, None);
|
generic_arg_mismatch_err(cx, provided_arg, param, false, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -405,7 +407,7 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
|
|||||||
/// Checks that the correct number of generic arguments have been provided.
|
/// Checks that the correct number of generic arguments have been provided.
|
||||||
/// Used specifically for function calls.
|
/// Used specifically for function calls.
|
||||||
pub fn check_generic_arg_count_for_call(
|
pub fn check_generic_arg_count_for_call(
|
||||||
tcx: TyCtxt<'_>,
|
cx: &dyn HirTyLowerer<'_>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
generics: &ty::Generics,
|
generics: &ty::Generics,
|
||||||
seg: &hir::PathSegment<'_>,
|
seg: &hir::PathSegment<'_>,
|
||||||
@ -416,14 +418,14 @@ pub fn check_generic_arg_count_for_call(
|
|||||||
IsMethodCall::No => GenericArgPosition::Value,
|
IsMethodCall::No => GenericArgPosition::Value,
|
||||||
};
|
};
|
||||||
let has_self = generics.parent.is_none() && generics.has_self;
|
let has_self = generics.parent.is_none() && generics.has_self;
|
||||||
check_generic_arg_count(tcx, def_id, seg, generics, gen_pos, has_self)
|
check_generic_arg_count(cx, def_id, seg, generics, gen_pos, has_self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks that the correct number of generic arguments have been provided.
|
/// Checks that the correct number of generic arguments have been provided.
|
||||||
/// This is used both for datatypes and function calls.
|
/// This is used both for datatypes and function calls.
|
||||||
#[instrument(skip(tcx, gen_pos), level = "debug")]
|
#[instrument(skip(cx, gen_pos), level = "debug")]
|
||||||
pub(crate) fn check_generic_arg_count(
|
pub(crate) fn check_generic_arg_count(
|
||||||
tcx: TyCtxt<'_>,
|
cx: &dyn HirTyLowerer<'_>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
seg: &hir::PathSegment<'_>,
|
seg: &hir::PathSegment<'_>,
|
||||||
gen_params: &ty::Generics,
|
gen_params: &ty::Generics,
|
||||||
@ -456,11 +458,11 @@ pub(crate) fn check_generic_arg_count(
|
|||||||
if gen_pos != GenericArgPosition::Type
|
if gen_pos != GenericArgPosition::Type
|
||||||
&& let Some(c) = gen_args.constraints.first()
|
&& let Some(c) = gen_args.constraints.first()
|
||||||
{
|
{
|
||||||
prohibit_assoc_item_constraint(tcx, c, None);
|
prohibit_assoc_item_constraint(cx, c, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let explicit_late_bound =
|
let explicit_late_bound =
|
||||||
prohibit_explicit_late_bound_lifetimes(tcx, gen_params, gen_args, gen_pos);
|
prohibit_explicit_late_bound_lifetimes(cx, gen_params, gen_args, gen_pos);
|
||||||
|
|
||||||
let mut invalid_args = vec![];
|
let mut invalid_args = vec![];
|
||||||
|
|
||||||
@ -486,8 +488,8 @@ pub(crate) fn check_generic_arg_count(
|
|||||||
GenericArgsInfo::MissingLifetimes { num_missing_args }
|
GenericArgsInfo::MissingLifetimes { num_missing_args }
|
||||||
};
|
};
|
||||||
|
|
||||||
let reported = tcx.dcx().emit_err(WrongNumberOfGenericArgs::new(
|
let reported = cx.dcx().emit_err(WrongNumberOfGenericArgs::new(
|
||||||
tcx,
|
cx.tcx(),
|
||||||
gen_args_info,
|
gen_args_info,
|
||||||
seg,
|
seg,
|
||||||
gen_params,
|
gen_params,
|
||||||
@ -571,9 +573,9 @@ pub(crate) fn check_generic_arg_count(
|
|||||||
debug!(?gen_args_info);
|
debug!(?gen_args_info);
|
||||||
|
|
||||||
let reported = gen_args.has_err().unwrap_or_else(|| {
|
let reported = gen_args.has_err().unwrap_or_else(|| {
|
||||||
tcx.dcx()
|
cx.dcx()
|
||||||
.create_err(WrongNumberOfGenericArgs::new(
|
.create_err(WrongNumberOfGenericArgs::new(
|
||||||
tcx,
|
cx.tcx(),
|
||||||
gen_args_info,
|
gen_args_info,
|
||||||
seg,
|
seg,
|
||||||
gen_params,
|
gen_params,
|
||||||
@ -621,7 +623,7 @@ pub(crate) fn check_generic_arg_count(
|
|||||||
/// Prohibits explicit lifetime arguments if late-bound lifetime parameters
|
/// Prohibits explicit lifetime arguments if late-bound lifetime parameters
|
||||||
/// are present. This is used both for datatypes and function calls.
|
/// are present. This is used both for datatypes and function calls.
|
||||||
pub(crate) fn prohibit_explicit_late_bound_lifetimes(
|
pub(crate) fn prohibit_explicit_late_bound_lifetimes(
|
||||||
tcx: TyCtxt<'_>,
|
cx: &dyn HirTyLowerer<'_>,
|
||||||
def: &ty::Generics,
|
def: &ty::Generics,
|
||||||
args: &hir::GenericArgs<'_>,
|
args: &hir::GenericArgs<'_>,
|
||||||
position: GenericArgPosition,
|
position: GenericArgPosition,
|
||||||
@ -642,13 +644,13 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
|
|||||||
if position == GenericArgPosition::Value
|
if position == GenericArgPosition::Value
|
||||||
&& args.num_lifetime_params() != param_counts.lifetimes
|
&& args.num_lifetime_params() != param_counts.lifetimes
|
||||||
{
|
{
|
||||||
struct_span_code_err!(tcx.dcx(), span, E0794, "{}", msg)
|
struct_span_code_err!(cx.dcx(), span, E0794, "{}", msg)
|
||||||
.with_span_note(span_late, note)
|
.with_span_note(span_late, note)
|
||||||
.emit();
|
.emit();
|
||||||
} else {
|
} else {
|
||||||
let mut multispan = MultiSpan::from_span(span);
|
let mut multispan = MultiSpan::from_span(span);
|
||||||
multispan.push_span_label(span_late, note);
|
multispan.push_span_label(span_late, note);
|
||||||
tcx.node_span_lint(
|
cx.tcx().node_span_lint(
|
||||||
LATE_BOUND_LIFETIME_ARGUMENTS,
|
LATE_BOUND_LIFETIME_ARGUMENTS,
|
||||||
args.args[0].hir_id(),
|
args.args[0].hir_id(),
|
||||||
multispan,
|
multispan,
|
||||||
|
@ -60,7 +60,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
let msg = "trait objects must include the `dyn` keyword";
|
let msg = "trait objects must include the `dyn` keyword";
|
||||||
let label = "add `dyn` keyword before this trait";
|
let label = "add `dyn` keyword before this trait";
|
||||||
let mut diag =
|
let mut diag =
|
||||||
rustc_errors::struct_span_code_err!(tcx.dcx(), self_ty.span, E0782, "{}", msg);
|
rustc_errors::struct_span_code_err!(self.dcx(), self_ty.span, E0782, "{}", msg);
|
||||||
if self_ty.span.can_be_used_for_suggestions()
|
if self_ty.span.can_be_used_for_suggestions()
|
||||||
&& !self.maybe_suggest_impl_trait(self_ty, &mut diag)
|
&& !self.maybe_suggest_impl_trait(self_ty, &mut diag)
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,8 @@ use crate::require_c_abi_if_c_variadic;
|
|||||||
use rustc_ast::TraitObjectSyntax;
|
use rustc_ast::TraitObjectSyntax;
|
||||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
codes::*, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, FatalError,
|
codes::*, struct_span_code_err, Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed,
|
||||||
|
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};
|
||||||
@ -102,6 +103,8 @@ pub enum RegionInferReason<'a> {
|
|||||||
pub trait HirTyLowerer<'tcx> {
|
pub trait HirTyLowerer<'tcx> {
|
||||||
fn tcx(&self) -> TyCtxt<'tcx>;
|
fn tcx(&self) -> TyCtxt<'tcx>;
|
||||||
|
|
||||||
|
fn dcx(&self) -> DiagCtxtHandle<'_>;
|
||||||
|
|
||||||
/// Returns the [`LocalDefId`] of the overarching item whose constituents get lowered.
|
/// Returns the [`LocalDefId`] of the overarching item whose constituents get lowered.
|
||||||
fn item_def_id(&self) -> LocalDefId;
|
fn item_def_id(&self) -> LocalDefId;
|
||||||
|
|
||||||
@ -177,12 +180,6 @@ pub trait HirTyLowerer<'tcx> {
|
|||||||
/// The inference context of the lowering context if applicable.
|
/// The inference context of the lowering context if applicable.
|
||||||
fn infcx(&self) -> Option<&InferCtxt<'tcx>>;
|
fn infcx(&self) -> Option<&InferCtxt<'tcx>>;
|
||||||
|
|
||||||
/// Taint the context with errors.
|
|
||||||
///
|
|
||||||
/// Invoke this when you encounter an error from some prior pass like name resolution.
|
|
||||||
/// This is used to help suppress derived errors typeck might otherwise report.
|
|
||||||
fn set_tainted_by_errors(&self, e: ErrorGuaranteed);
|
|
||||||
|
|
||||||
/// Convenience method for coercing the lowering context into a trait object type.
|
/// Convenience method for coercing the lowering context into a trait object type.
|
||||||
///
|
///
|
||||||
/// Most lowering routines are defined on the trait object type directly
|
/// Most lowering routines are defined on the trait object type directly
|
||||||
@ -323,7 +320,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
ty::BoundConstness::NotConst,
|
ty::BoundConstness::NotConst,
|
||||||
);
|
);
|
||||||
if let Some(c) = item_segment.args().constraints.first() {
|
if let Some(c) = item_segment.args().constraints.first() {
|
||||||
prohibit_assoc_item_constraint(self.tcx(), c, Some((def_id, item_segment, span)));
|
prohibit_assoc_item_constraint(self, c, Some((def_id, item_segment, span)));
|
||||||
}
|
}
|
||||||
args
|
args
|
||||||
}
|
}
|
||||||
@ -394,7 +391,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut arg_count = check_generic_arg_count(
|
let mut arg_count = check_generic_arg_count(
|
||||||
tcx,
|
self,
|
||||||
def_id,
|
def_id,
|
||||||
segment,
|
segment,
|
||||||
generics,
|
generics,
|
||||||
@ -402,10 +399,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
self_ty.is_some(),
|
self_ty.is_some(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Err(err) = &arg_count.correct {
|
|
||||||
self.set_tainted_by_errors(err.reported);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip processing if type has no generic parameters.
|
// Skip processing if type has no generic parameters.
|
||||||
// Traits always have `Self` as a generic parameter, which means they will not return early
|
// Traits always have `Self` as a generic parameter, which means they will not return early
|
||||||
// here and so associated item constraints will be handled regardless of whether there are
|
// here and so associated item constraints will be handled regardless of whether there are
|
||||||
@ -562,11 +555,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
&& generics.has_self
|
&& generics.has_self
|
||||||
&& !tcx.is_const_trait(def_id)
|
&& !tcx.is_const_trait(def_id)
|
||||||
{
|
{
|
||||||
let reported = tcx.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
|
let reported = self.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
|
||||||
span,
|
span,
|
||||||
modifier: constness.as_str(),
|
modifier: constness.as_str(),
|
||||||
});
|
});
|
||||||
self.set_tainted_by_errors(reported);
|
|
||||||
arg_count.correct = Err(GenericArgCountMismatch { reported, invalid_args: vec![] });
|
arg_count.correct = Err(GenericArgCountMismatch { reported, invalid_args: vec![] });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,7 +571,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
incorrect_args: &arg_count.correct,
|
incorrect_args: &arg_count.correct,
|
||||||
};
|
};
|
||||||
let args = lower_generic_args(
|
let args = lower_generic_args(
|
||||||
tcx,
|
self,
|
||||||
def_id,
|
def_id,
|
||||||
parent_args,
|
parent_args,
|
||||||
self_ty.is_some(),
|
self_ty.is_some(),
|
||||||
@ -609,7 +601,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
ty::BoundConstness::NotConst,
|
ty::BoundConstness::NotConst,
|
||||||
);
|
);
|
||||||
if let Some(c) = item_segment.args().constraints.first() {
|
if let Some(c) = item_segment.args().constraints.first() {
|
||||||
prohibit_assoc_item_constraint(self.tcx(), c, Some((item_def_id, item_segment, span)));
|
prohibit_assoc_item_constraint(self, c, Some((item_def_id, item_segment, span)));
|
||||||
}
|
}
|
||||||
args
|
args
|
||||||
}
|
}
|
||||||
@ -715,7 +707,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
// would not be well-formed!
|
// would not be well-formed!
|
||||||
if polarity != ty::PredicatePolarity::Positive {
|
if polarity != ty::PredicatePolarity::Positive {
|
||||||
assert!(
|
assert!(
|
||||||
self.tcx().dcx().has_errors().is_some(),
|
self.dcx().has_errors().is_some(),
|
||||||
"negative trait bounds should not have assoc item constraints",
|
"negative trait bounds should not have assoc item constraints",
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
@ -761,11 +753,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
constness,
|
constness,
|
||||||
);
|
);
|
||||||
if let Some(c) = trait_segment.args().constraints.first() {
|
if let Some(c) = trait_segment.args().constraints.first() {
|
||||||
prohibit_assoc_item_constraint(
|
prohibit_assoc_item_constraint(self, c, Some((trait_def_id, trait_segment, span)));
|
||||||
self.tcx(),
|
|
||||||
c,
|
|
||||||
Some((trait_def_id, trait_segment, span)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
ty::TraitRef::new_from_args(self.tcx(), trait_def_id, generic_args)
|
ty::TraitRef::new_from_args(self.tcx(), trait_def_id, generic_args)
|
||||||
}
|
}
|
||||||
@ -877,7 +865,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
span,
|
span,
|
||||||
constraint,
|
constraint,
|
||||||
);
|
);
|
||||||
self.set_tainted_by_errors(reported);
|
|
||||||
return Err(reported);
|
return Err(reported);
|
||||||
};
|
};
|
||||||
debug!(?bound);
|
debug!(?bound);
|
||||||
@ -887,7 +874,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
|
|
||||||
let assoc_kind_str = assoc_kind_str(assoc_kind);
|
let assoc_kind_str = assoc_kind_str(assoc_kind);
|
||||||
let ty_param_name = &ty_param_name.to_string();
|
let ty_param_name = &ty_param_name.to_string();
|
||||||
let mut err = tcx.dcx().create_err(crate::errors::AmbiguousAssocItem {
|
let mut err = self.dcx().create_err(crate::errors::AmbiguousAssocItem {
|
||||||
span,
|
span,
|
||||||
assoc_kind: assoc_kind_str,
|
assoc_kind: assoc_kind_str,
|
||||||
assoc_name,
|
assoc_name,
|
||||||
@ -960,7 +947,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
let reported = err.emit();
|
let reported = err.emit();
|
||||||
self.set_tainted_by_errors(reported);
|
|
||||||
if !where_bounds.is_empty() {
|
if !where_bounds.is_empty() {
|
||||||
return Err(reported);
|
return Err(reported);
|
||||||
}
|
}
|
||||||
@ -1059,7 +1045,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
// trait reference.
|
// trait reference.
|
||||||
let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) else {
|
let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) else {
|
||||||
// A cycle error occurred, most likely.
|
// A cycle error occurred, most likely.
|
||||||
tcx.dcx().span_bug(span, "expected cycle error");
|
self.dcx().span_bug(span, "expected cycle error");
|
||||||
};
|
};
|
||||||
|
|
||||||
self.probe_single_bound_for_assoc_item(
|
self.probe_single_bound_for_assoc_item(
|
||||||
@ -1089,10 +1075,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
let reported = if variant_resolution.is_some() {
|
let reported = if variant_resolution.is_some() {
|
||||||
// Variant in type position
|
// Variant in type position
|
||||||
let msg = format!("expected type, found variant `{assoc_ident}`");
|
let msg = format!("expected type, found variant `{assoc_ident}`");
|
||||||
tcx.dcx().span_err(span, msg)
|
self.dcx().span_err(span, msg)
|
||||||
} else if qself_ty.is_enum() {
|
} else if qself_ty.is_enum() {
|
||||||
let mut err = struct_span_code_err!(
|
let mut err = struct_span_code_err!(
|
||||||
tcx.dcx(),
|
self.dcx(),
|
||||||
assoc_ident.span,
|
assoc_ident.span,
|
||||||
E0599,
|
E0599,
|
||||||
"no variant named `{}` found for enum `{}`",
|
"no variant named `{}` found for enum `{}`",
|
||||||
@ -1133,7 +1119,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
} else if let ty::Alias(ty::Opaque, alias_ty) = qself_ty.kind() {
|
} else if let ty::Alias(ty::Opaque, alias_ty) = qself_ty.kind() {
|
||||||
// `<impl Trait as OtherTrait>::Assoc` makes no sense.
|
// `<impl Trait as OtherTrait>::Assoc` makes no sense.
|
||||||
struct_span_code_err!(
|
struct_span_code_err!(
|
||||||
tcx.dcx(),
|
self.dcx(),
|
||||||
tcx.def_span(alias_ty.def_id),
|
tcx.def_span(alias_ty.def_id),
|
||||||
E0667,
|
E0667,
|
||||||
"`impl Trait` is not allowed in path parameters"
|
"`impl Trait` is not allowed in path parameters"
|
||||||
@ -1153,7 +1139,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
assoc_ident.name,
|
assoc_ident.name,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
self.set_tainted_by_errors(reported);
|
|
||||||
return Err(reported);
|
return Err(reported);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -1404,13 +1389,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
|
|
||||||
if !tcx.visibility(item_def_id).is_accessible_from(scope, tcx) {
|
if !tcx.visibility(item_def_id).is_accessible_from(scope, tcx) {
|
||||||
let reported = tcx.dcx().emit_err(crate::errors::AssocItemIsPrivate {
|
self.dcx().emit_err(crate::errors::AssocItemIsPrivate {
|
||||||
span,
|
span,
|
||||||
kind: tcx.def_descr(item_def_id),
|
kind: tcx.def_descr(item_def_id),
|
||||||
name: ident,
|
name: ident,
|
||||||
defined_here_label: tcx.def_span(item_def_id),
|
defined_here_label: tcx.def_span(item_def_id),
|
||||||
});
|
});
|
||||||
self.set_tainted_by_errors(reported);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tcx.check_stability(item_def_id, Some(block), span, None);
|
tcx.check_stability(item_def_id, Some(block), span, None);
|
||||||
@ -1564,7 +1548,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
for segment in segments {
|
for segment in segments {
|
||||||
// Only emit the first error to avoid overloading the user with error messages.
|
// Only emit the first error to avoid overloading the user with error messages.
|
||||||
if let Some(c) = segment.args().constraints.first() {
|
if let Some(c) = segment.args().constraints.first() {
|
||||||
return Err(prohibit_assoc_item_constraint(self.tcx(), c, None));
|
return Err(prohibit_assoc_item_constraint(self, c, None));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1824,7 +1808,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
// `AlwaysApplicable` impl needs a `T: ?Sized` bound for
|
// `AlwaysApplicable` impl needs a `T: ?Sized` bound for
|
||||||
// this to compile if we were to normalize here.
|
// this to compile if we were to normalize here.
|
||||||
if forbid_generic && ty.has_param() {
|
if forbid_generic && ty.has_param() {
|
||||||
let mut err = tcx.dcx().struct_span_err(
|
let mut err = self.dcx().struct_span_err(
|
||||||
path.span,
|
path.span,
|
||||||
"generic `Self` types are currently not permitted in anonymous constants",
|
"generic `Self` types are currently not permitted in anonymous constants",
|
||||||
);
|
);
|
||||||
@ -1836,7 +1820,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
err.span_note(impl_.self_ty.span, "not a concrete type");
|
err.span_note(impl_.self_ty.span, "not a concrete type");
|
||||||
}
|
}
|
||||||
let reported = err.emit();
|
let reported = err.emit();
|
||||||
self.set_tainted_by_errors(reported);
|
|
||||||
Ty::new_error(tcx, reported)
|
Ty::new_error(tcx, reported)
|
||||||
} else {
|
} else {
|
||||||
ty
|
ty
|
||||||
@ -1877,7 +1860,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
.tcx()
|
.tcx()
|
||||||
.dcx()
|
.dcx()
|
||||||
.span_delayed_bug(path.span, "path with `Res::Err` but no error emitted");
|
.span_delayed_bug(path.span, "path with `Res::Err` but no error emitted");
|
||||||
self.set_tainted_by_errors(e);
|
|
||||||
Ty::new_error(self.tcx(), e)
|
Ty::new_error(self.tcx(), e)
|
||||||
}
|
}
|
||||||
Res::Def(..) => {
|
Res::Def(..) => {
|
||||||
@ -1888,7 +1870,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
);
|
);
|
||||||
Ty::new_error(
|
Ty::new_error(
|
||||||
self.tcx(),
|
self.tcx(),
|
||||||
self.tcx().dcx().span_delayed_bug(span, "incorrect resolution for `Self`"),
|
self.dcx().span_delayed_bug(span, "incorrect resolution for `Self`"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_ => span_bug!(span, "unexpected resolution: {:?}", path.res),
|
_ => span_bug!(span, "unexpected resolution: {:?}", path.res),
|
||||||
@ -1961,7 +1943,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
let sig_span = self.tcx().def_span(sig_id);
|
let sig_span = self.tcx().def_span(sig_id);
|
||||||
let mut try_emit = |descr| {
|
let mut try_emit = |descr| {
|
||||||
if emit {
|
if emit {
|
||||||
self.tcx().dcx().emit_err(crate::errors::NotSupportedDelegation {
|
self.dcx().emit_err(crate::errors::NotSupportedDelegation {
|
||||||
span,
|
span,
|
||||||
descr,
|
descr,
|
||||||
callee_span: sig_span,
|
callee_span: sig_span,
|
||||||
@ -2011,8 +1993,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
if self.check_delegation_constraints(sig_id, span, idx == hir::InferDelegationKind::Output)
|
if self.check_delegation_constraints(sig_id, span, idx == hir::InferDelegationKind::Output)
|
||||||
{
|
{
|
||||||
let e = self.tcx().dcx().span_delayed_bug(span, "not supported delegation case");
|
let e = self.dcx().span_delayed_bug(span, "not supported delegation case");
|
||||||
self.set_tainted_by_errors(e);
|
|
||||||
return Ty::new_error(self.tcx(), e);
|
return Ty::new_error(self.tcx(), e);
|
||||||
};
|
};
|
||||||
let sig = self.tcx().fn_sig(sig_id);
|
let sig = self.tcx().fn_sig(sig_id);
|
||||||
@ -2177,7 +2158,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
let ty = self.lower_ty(ty);
|
let ty = self.lower_ty(ty);
|
||||||
let pat_ty = match pat.kind {
|
let pat_ty = match pat.kind {
|
||||||
hir::PatKind::Wild => {
|
hir::PatKind::Wild => {
|
||||||
let err = tcx.dcx().emit_err(WildPatTy { span: pat.span });
|
let err = self.dcx().emit_err(WildPatTy { span: pat.span });
|
||||||
Ty::new_error(tcx, err)
|
Ty::new_error(tcx, err)
|
||||||
}
|
}
|
||||||
hir::PatKind::Range(start, end, include_end) => {
|
hir::PatKind::Range(start, end, include_end) => {
|
||||||
@ -2357,7 +2338,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
|
|
||||||
self.validate_late_bound_regions(late_bound_in_args, late_bound_in_ret, |br_name| {
|
self.validate_late_bound_regions(late_bound_in_args, late_bound_in_ret, |br_name| {
|
||||||
struct_span_code_err!(
|
struct_span_code_err!(
|
||||||
tcx.dcx(),
|
self.dcx(),
|
||||||
decl.output.span(),
|
decl.output.span(),
|
||||||
E0581,
|
E0581,
|
||||||
"return type references {}, which is not constrained by the fn input types",
|
"return type references {}, which is not constrained by the fn input types",
|
||||||
@ -2408,11 +2389,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self, generate_err))]
|
#[instrument(level = "trace", skip(self, generate_err))]
|
||||||
fn validate_late_bound_regions(
|
fn validate_late_bound_regions<'cx>(
|
||||||
&self,
|
&'cx 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) -> Diag<'tcx>,
|
generate_err: impl Fn(&str) -> Diag<'cx>,
|
||||||
) {
|
) {
|
||||||
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 {
|
||||||
@ -2437,7 +2418,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
err.note("consider introducing a named lifetime parameter");
|
err.note("consider introducing a named lifetime parameter");
|
||||||
}
|
}
|
||||||
|
|
||||||
self.set_tainted_by_errors(err.emit());
|
err.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2478,7 +2459,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
// error.
|
// error.
|
||||||
let r = derived_region_bounds[0];
|
let r = derived_region_bounds[0];
|
||||||
if derived_region_bounds[1..].iter().any(|r1| r != *r1) {
|
if derived_region_bounds[1..].iter().any(|r1| r != *r1) {
|
||||||
self.set_tainted_by_errors(tcx.dcx().emit_err(AmbiguousLifetimeBound { span }));
|
self.dcx().emit_err(AmbiguousLifetimeBound { span });
|
||||||
}
|
}
|
||||||
Some(r)
|
Some(r)
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
Ty::new_misc_error(tcx).into()
|
Ty::new_misc_error(tcx).into()
|
||||||
} else if arg.walk().any(|arg| arg == dummy_self.into()) {
|
} else if arg.walk().any(|arg| arg == dummy_self.into()) {
|
||||||
references_self = true;
|
references_self = true;
|
||||||
let guar = tcx.dcx().span_delayed_bug(
|
let guar = self.dcx().span_delayed_bug(
|
||||||
span,
|
span,
|
||||||
"trait object trait bounds reference `Self`",
|
"trait object trait bounds reference `Self`",
|
||||||
);
|
);
|
||||||
@ -262,8 +262,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
|
|
||||||
if references_self {
|
if references_self {
|
||||||
let def_id = i.bottom().0.def_id();
|
let def_id = i.bottom().0.def_id();
|
||||||
let reported = struct_span_code_err!(
|
struct_span_code_err!(
|
||||||
tcx.dcx(),
|
self.dcx(),
|
||||||
i.bottom().1,
|
i.bottom().1,
|
||||||
E0038,
|
E0038,
|
||||||
"the {} `{}` cannot be made into an object",
|
"the {} `{}` cannot be made into an object",
|
||||||
@ -275,7 +275,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
.error_msg(),
|
.error_msg(),
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
self.set_tainted_by_errors(reported);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::ExistentialTraitRef { def_id: trait_ref.def_id, args }
|
ty::ExistentialTraitRef { def_id: trait_ref.def_id, args }
|
||||||
|
@ -1139,7 +1139,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// parameter's value explicitly, so we have to do some error-
|
// parameter's value explicitly, so we have to do some error-
|
||||||
// checking here.
|
// checking here.
|
||||||
let arg_count =
|
let arg_count =
|
||||||
check_generic_arg_count_for_call(tcx, def_id, generics, seg, IsMethodCall::No);
|
check_generic_arg_count_for_call(self, def_id, generics, seg, IsMethodCall::No);
|
||||||
|
|
||||||
if let ExplicitLateBound::Yes = arg_count.explicit_late_bound {
|
if let ExplicitLateBound::Yes = arg_count.explicit_late_bound {
|
||||||
explicit_late_bound = ExplicitLateBound::Yes;
|
explicit_late_bound = ExplicitLateBound::Yes;
|
||||||
@ -1375,7 +1375,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
let args_raw = self_ctor_args.unwrap_or_else(|| {
|
let args_raw = self_ctor_args.unwrap_or_else(|| {
|
||||||
lower_generic_args(
|
lower_generic_args(
|
||||||
tcx,
|
self,
|
||||||
def_id,
|
def_id,
|
||||||
&[],
|
&[],
|
||||||
has_self,
|
has_self,
|
||||||
|
@ -5,7 +5,7 @@ mod checks;
|
|||||||
mod inspect_obligations;
|
mod inspect_obligations;
|
||||||
mod suggestions;
|
mod suggestions;
|
||||||
|
|
||||||
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed};
|
use rustc_errors::DiagCtxtHandle;
|
||||||
|
|
||||||
use crate::coercion::DynamicCoerceMany;
|
use crate::coercion::DynamicCoerceMany;
|
||||||
use crate::fallback::DivergingFallbackBehavior;
|
use crate::fallback::DivergingFallbackBehavior;
|
||||||
@ -217,6 +217,10 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
|
|||||||
self.tcx
|
self.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dcx(&self) -> DiagCtxtHandle<'_> {
|
||||||
|
self.root_ctxt.dcx()
|
||||||
|
}
|
||||||
|
|
||||||
fn item_def_id(&self) -> LocalDefId {
|
fn item_def_id(&self) -> LocalDefId {
|
||||||
self.body_id
|
self.body_id
|
||||||
}
|
}
|
||||||
@ -338,10 +342,6 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
|
|||||||
Some(&self.infcx)
|
Some(&self.infcx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_tainted_by_errors(&self, e: ErrorGuaranteed) {
|
|
||||||
self.infcx.set_tainted_by_errors(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn lower_fn_sig(
|
fn lower_fn_sig(
|
||||||
&self,
|
&self,
|
||||||
decl: &rustc_hir::FnDecl<'tcx>,
|
decl: &rustc_hir::FnDecl<'tcx>,
|
||||||
|
@ -354,7 +354,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
|||||||
let generics = self.tcx.generics_of(pick.item.def_id);
|
let generics = self.tcx.generics_of(pick.item.def_id);
|
||||||
|
|
||||||
let arg_count_correct = check_generic_arg_count_for_call(
|
let arg_count_correct = check_generic_arg_count_for_call(
|
||||||
self.tcx,
|
self.fcx,
|
||||||
pick.item.def_id,
|
pick.item.def_id,
|
||||||
generics,
|
generics,
|
||||||
seg,
|
seg,
|
||||||
@ -425,7 +425,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let args = lower_generic_args(
|
let args = lower_generic_args(
|
||||||
self.tcx,
|
self.fcx,
|
||||||
pick.item.def_id,
|
pick.item.def_id,
|
||||||
parent_args,
|
parent_args,
|
||||||
false,
|
false,
|
||||||
|
@ -7,11 +7,12 @@ trait Foo {
|
|||||||
|
|
||||||
impl Foo for isize {
|
impl Foo for isize {
|
||||||
type A = usize;
|
type A = usize;
|
||||||
fn bar() -> isize { 42 }
|
fn bar() -> isize {
|
||||||
|
42
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x: isize = Foo::<A = usize>::bar();
|
let x: isize = Foo::<A = usize>::bar();
|
||||||
//~^ ERROR associated item constraints are not allowed here
|
//~^ ERROR associated item constraints are not allowed here
|
||||||
//~| ERROR cannot call
|
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,9 @@
|
|||||||
error[E0229]: associated item constraints are not allowed here
|
error[E0229]: associated item constraints are not allowed here
|
||||||
--> $DIR/associated-types-eq-expr-path.rs:14:26
|
--> $DIR/associated-types-eq-expr-path.rs:16:26
|
||||||
|
|
|
|
||||||
LL | let x: isize = Foo::<A = usize>::bar();
|
LL | let x: isize = Foo::<A = usize>::bar();
|
||||||
| ^^^^^^^^^ associated item constraint not allowed here
|
| ^^^^^^^^^ associated item constraint not allowed here
|
||||||
|
|
||||||
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
|
error: aborting due to 1 previous error
|
||||||
--> $DIR/associated-types-eq-expr-path.rs:14:20
|
|
||||||
|
|
|
||||||
LL | fn bar() -> isize;
|
|
||||||
| ------------------ `Foo::bar` defined here
|
|
||||||
...
|
|
||||||
LL | let x: isize = Foo::<A = usize>::bar();
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
|
|
||||||
|
|
|
||||||
help: use the fully-qualified path to the only available implementation
|
|
||||||
|
|
|
||||||
LL - let x: isize = Foo::<A = usize>::bar();
|
|
||||||
LL + let x: isize = <isize as Foo<A = usize>>::bar();
|
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
For more information about this error, try `rustc --explain E0229`.
|
||||||
|
|
||||||
Some errors have detailed explanations: E0229, E0790.
|
|
||||||
For more information about an error, try `rustc --explain E0229`.
|
|
||||||
|
@ -8,7 +8,6 @@ fn foo<T: Trait>() {
|
|||||||
bar::<<T as Trait>::ASSOC>();
|
bar::<<T as Trait>::ASSOC>();
|
||||||
//~^ ERROR: expected associated type, found associated constant `Trait::ASSOC`
|
//~^ ERROR: expected associated type, found associated constant `Trait::ASSOC`
|
||||||
//~| ERROR: unresolved item provided when a constant was expected
|
//~| ERROR: unresolved item provided when a constant was expected
|
||||||
//~| ERROR type annotations needed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -15,19 +15,7 @@ help: if this generic argument was intended as a const parameter, surround it wi
|
|||||||
LL | bar::<{ <T as Trait>::ASSOC }>();
|
LL | bar::<{ <T as Trait>::ASSOC }>();
|
||||||
| + +
|
| + +
|
||||||
|
|
||||||
error[E0284]: type annotations needed
|
error: aborting due to 2 previous errors
|
||||||
--> $DIR/assoc_const_as_type_argument.rs:8:5
|
|
||||||
|
|
|
||||||
LL | bar::<<T as Trait>::ASSOC>();
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar`
|
|
||||||
|
|
|
||||||
note: required by a const generic parameter in `bar`
|
|
||||||
--> $DIR/assoc_const_as_type_argument.rs:5:8
|
|
||||||
|
|
|
||||||
LL | fn bar<const N: usize>() {}
|
|
||||||
| ^^^^^^^^^^^^^^ required by this const generic parameter in `bar`
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
Some errors have detailed explanations: E0575, E0747.
|
||||||
|
For more information about an error, try `rustc --explain E0575`.
|
||||||
Some errors have detailed explanations: E0284, E0575, E0747.
|
|
||||||
For more information about an error, try `rustc --explain E0284`.
|
|
||||||
|
@ -17,7 +17,7 @@ LL | let _: [u8; bar::<N>()];
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:19:23
|
--> $DIR/const-arg-in-const-arg.rs:18:23
|
||||||
|
|
|
|
||||||
LL | let _: [u8; faz::<'a>(&())];
|
LL | let _: [u8; faz::<'a>(&())];
|
||||||
| ^^ cannot perform const operation using `'a`
|
| ^^ cannot perform const operation using `'a`
|
||||||
@ -26,7 +26,7 @@ LL | let _: [u8; faz::<'a>(&())];
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:21:23
|
--> $DIR/const-arg-in-const-arg.rs:20:23
|
||||||
|
|
|
|
||||||
LL | let _: [u8; baz::<'a>(&())];
|
LL | let _: [u8; baz::<'a>(&())];
|
||||||
| ^^ cannot perform const operation using `'a`
|
| ^^ cannot perform const operation using `'a`
|
||||||
@ -35,7 +35,7 @@ LL | let _: [u8; baz::<'a>(&())];
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:22:23
|
--> $DIR/const-arg-in-const-arg.rs:21:23
|
||||||
|
|
|
|
||||||
LL | let _: [u8; faz::<'b>(&())];
|
LL | let _: [u8; faz::<'b>(&())];
|
||||||
| ^^ cannot perform const operation using `'b`
|
| ^^ cannot perform const operation using `'b`
|
||||||
@ -44,7 +44,7 @@ LL | let _: [u8; faz::<'b>(&())];
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:24:23
|
--> $DIR/const-arg-in-const-arg.rs:23:23
|
||||||
|
|
|
|
||||||
LL | let _: [u8; baz::<'b>(&())];
|
LL | let _: [u8; baz::<'b>(&())];
|
||||||
| ^^ cannot perform const operation using `'b`
|
| ^^ cannot perform const operation using `'b`
|
||||||
@ -53,7 +53,7 @@ LL | let _: [u8; baz::<'b>(&())];
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:27:23
|
--> $DIR/const-arg-in-const-arg.rs:26:23
|
||||||
|
|
|
|
||||||
LL | let _ = [0; bar::<N>()];
|
LL | let _ = [0; bar::<N>()];
|
||||||
| ^ cannot perform const operation using `N`
|
| ^ cannot perform const operation using `N`
|
||||||
@ -62,7 +62,7 @@ LL | let _ = [0; bar::<N>()];
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:30:23
|
--> $DIR/const-arg-in-const-arg.rs:28:23
|
||||||
|
|
|
|
||||||
LL | let _ = [0; faz::<'a>(&())];
|
LL | let _ = [0; faz::<'a>(&())];
|
||||||
| ^^ cannot perform const operation using `'a`
|
| ^^ cannot perform const operation using `'a`
|
||||||
@ -71,7 +71,7 @@ LL | let _ = [0; faz::<'a>(&())];
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:32:23
|
--> $DIR/const-arg-in-const-arg.rs:30:23
|
||||||
|
|
|
|
||||||
LL | let _ = [0; baz::<'a>(&())];
|
LL | let _ = [0; baz::<'a>(&())];
|
||||||
| ^^ cannot perform const operation using `'a`
|
| ^^ cannot perform const operation using `'a`
|
||||||
@ -80,7 +80,7 @@ LL | let _ = [0; baz::<'a>(&())];
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:33:23
|
--> $DIR/const-arg-in-const-arg.rs:31:23
|
||||||
|
|
|
|
||||||
LL | let _ = [0; faz::<'b>(&())];
|
LL | let _ = [0; faz::<'b>(&())];
|
||||||
| ^^ cannot perform const operation using `'b`
|
| ^^ cannot perform const operation using `'b`
|
||||||
@ -89,7 +89,7 @@ LL | let _ = [0; faz::<'b>(&())];
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:35:23
|
--> $DIR/const-arg-in-const-arg.rs:33:23
|
||||||
|
|
|
|
||||||
LL | let _ = [0; baz::<'b>(&())];
|
LL | let _ = [0; baz::<'b>(&())];
|
||||||
| ^^ cannot perform const operation using `'b`
|
| ^^ cannot perform const operation using `'b`
|
||||||
@ -98,7 +98,7 @@ LL | let _ = [0; baz::<'b>(&())];
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:36:24
|
--> $DIR/const-arg-in-const-arg.rs:34:24
|
||||||
|
|
|
|
||||||
LL | let _: Foo<{ foo::<T>() }>;
|
LL | let _: Foo<{ foo::<T>() }>;
|
||||||
| ^ cannot perform const operation using `T`
|
| ^ cannot perform const operation using `T`
|
||||||
@ -107,7 +107,7 @@ LL | let _: Foo<{ foo::<T>() }>;
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:37:24
|
--> $DIR/const-arg-in-const-arg.rs:35:24
|
||||||
|
|
|
|
||||||
LL | let _: Foo<{ bar::<N>() }>;
|
LL | let _: Foo<{ bar::<N>() }>;
|
||||||
| ^ cannot perform const operation using `N`
|
| ^ cannot perform const operation using `N`
|
||||||
@ -116,7 +116,7 @@ LL | let _: Foo<{ bar::<N>() }>;
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:40:24
|
--> $DIR/const-arg-in-const-arg.rs:37:24
|
||||||
|
|
|
|
||||||
LL | let _: Foo<{ faz::<'a>(&()) }>;
|
LL | let _: Foo<{ faz::<'a>(&()) }>;
|
||||||
| ^^ cannot perform const operation using `'a`
|
| ^^ cannot perform const operation using `'a`
|
||||||
@ -125,7 +125,7 @@ LL | let _: Foo<{ faz::<'a>(&()) }>;
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:42:24
|
--> $DIR/const-arg-in-const-arg.rs:39:24
|
||||||
|
|
|
|
||||||
LL | let _: Foo<{ baz::<'a>(&()) }>;
|
LL | let _: Foo<{ baz::<'a>(&()) }>;
|
||||||
| ^^ cannot perform const operation using `'a`
|
| ^^ cannot perform const operation using `'a`
|
||||||
@ -134,7 +134,7 @@ LL | let _: Foo<{ baz::<'a>(&()) }>;
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:43:24
|
--> $DIR/const-arg-in-const-arg.rs:40:24
|
||||||
|
|
|
|
||||||
LL | let _: Foo<{ faz::<'b>(&()) }>;
|
LL | let _: Foo<{ faz::<'b>(&()) }>;
|
||||||
| ^^ cannot perform const operation using `'b`
|
| ^^ cannot perform const operation using `'b`
|
||||||
@ -143,7 +143,7 @@ LL | let _: Foo<{ faz::<'b>(&()) }>;
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:45:24
|
--> $DIR/const-arg-in-const-arg.rs:42:24
|
||||||
|
|
|
|
||||||
LL | let _: Foo<{ baz::<'b>(&()) }>;
|
LL | let _: Foo<{ baz::<'b>(&()) }>;
|
||||||
| ^^ cannot perform const operation using `'b`
|
| ^^ cannot perform const operation using `'b`
|
||||||
@ -152,7 +152,7 @@ LL | let _: Foo<{ baz::<'b>(&()) }>;
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:46:27
|
--> $DIR/const-arg-in-const-arg.rs:43:27
|
||||||
|
|
|
|
||||||
LL | let _ = Foo::<{ foo::<T>() }>;
|
LL | let _ = Foo::<{ foo::<T>() }>;
|
||||||
| ^ cannot perform const operation using `T`
|
| ^ cannot perform const operation using `T`
|
||||||
@ -161,7 +161,7 @@ LL | let _ = Foo::<{ foo::<T>() }>;
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:47:27
|
--> $DIR/const-arg-in-const-arg.rs:44:27
|
||||||
|
|
|
|
||||||
LL | let _ = Foo::<{ bar::<N>() }>;
|
LL | let _ = Foo::<{ bar::<N>() }>;
|
||||||
| ^ cannot perform const operation using `N`
|
| ^ cannot perform const operation using `N`
|
||||||
@ -170,7 +170,7 @@ LL | let _ = Foo::<{ bar::<N>() }>;
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:50:27
|
--> $DIR/const-arg-in-const-arg.rs:46:27
|
||||||
|
|
|
|
||||||
LL | let _ = Foo::<{ faz::<'a>(&()) }>;
|
LL | let _ = Foo::<{ faz::<'a>(&()) }>;
|
||||||
| ^^ cannot perform const operation using `'a`
|
| ^^ cannot perform const operation using `'a`
|
||||||
@ -179,7 +179,7 @@ LL | let _ = Foo::<{ faz::<'a>(&()) }>;
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:52:27
|
--> $DIR/const-arg-in-const-arg.rs:48:27
|
||||||
|
|
|
|
||||||
LL | let _ = Foo::<{ baz::<'a>(&()) }>;
|
LL | let _ = Foo::<{ baz::<'a>(&()) }>;
|
||||||
| ^^ cannot perform const operation using `'a`
|
| ^^ cannot perform const operation using `'a`
|
||||||
@ -188,7 +188,7 @@ LL | let _ = Foo::<{ baz::<'a>(&()) }>;
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:53:27
|
--> $DIR/const-arg-in-const-arg.rs:49:27
|
||||||
|
|
|
|
||||||
LL | let _ = Foo::<{ faz::<'b>(&()) }>;
|
LL | let _ = Foo::<{ faz::<'b>(&()) }>;
|
||||||
| ^^ cannot perform const operation using `'b`
|
| ^^ cannot perform const operation using `'b`
|
||||||
@ -197,7 +197,7 @@ LL | let _ = Foo::<{ faz::<'b>(&()) }>;
|
|||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/const-arg-in-const-arg.rs:55:27
|
--> $DIR/const-arg-in-const-arg.rs:51:27
|
||||||
|
|
|
|
||||||
LL | let _ = Foo::<{ baz::<'b>(&()) }>;
|
LL | let _ = Foo::<{ baz::<'b>(&()) }>;
|
||||||
| ^^ cannot perform const operation using `'b`
|
| ^^ cannot perform const operation using `'b`
|
||||||
@ -216,20 +216,8 @@ help: if this generic argument was intended as a const parameter, surround it wi
|
|||||||
LL | let _: [u8; bar::<{ N }>()];
|
LL | let _: [u8; bar::<{ N }>()];
|
||||||
| + +
|
| + +
|
||||||
|
|
||||||
error[E0284]: type annotations needed
|
|
||||||
--> $DIR/const-arg-in-const-arg.rs:16:17
|
|
||||||
|
|
|
||||||
LL | let _: [u8; bar::<N>()];
|
|
||||||
| ^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar`
|
|
||||||
|
|
|
||||||
note: required by a const generic parameter in `bar`
|
|
||||||
--> $DIR/const-arg-in-const-arg.rs:9:14
|
|
||||||
|
|
|
||||||
LL | const fn bar<const N: usize>() -> usize { N }
|
|
||||||
| ^^^^^^^^^^^^^^ required by this const generic parameter in `bar`
|
|
||||||
|
|
||||||
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
||||||
--> $DIR/const-arg-in-const-arg.rs:19:23
|
--> $DIR/const-arg-in-const-arg.rs:18:23
|
||||||
|
|
|
|
||||||
LL | let _: [u8; faz::<'a>(&())];
|
LL | let _: [u8; faz::<'a>(&())];
|
||||||
| ^^
|
| ^^
|
||||||
@ -241,7 +229,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
|
|||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
||||||
--> $DIR/const-arg-in-const-arg.rs:22:23
|
--> $DIR/const-arg-in-const-arg.rs:21:23
|
||||||
|
|
|
|
||||||
LL | let _: [u8; faz::<'b>(&())];
|
LL | let _: [u8; faz::<'b>(&())];
|
||||||
| ^^
|
| ^^
|
||||||
@ -253,7 +241,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
|
|||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error[E0747]: unresolved item provided when a constant was expected
|
error[E0747]: unresolved item provided when a constant was expected
|
||||||
--> $DIR/const-arg-in-const-arg.rs:37:24
|
--> $DIR/const-arg-in-const-arg.rs:35:24
|
||||||
|
|
|
|
||||||
LL | let _: Foo<{ bar::<N>() }>;
|
LL | let _: Foo<{ bar::<N>() }>;
|
||||||
| ^
|
| ^
|
||||||
@ -263,20 +251,8 @@ help: if this generic argument was intended as a const parameter, surround it wi
|
|||||||
LL | let _: Foo<{ bar::<{ N }>() }>;
|
LL | let _: Foo<{ bar::<{ N }>() }>;
|
||||||
| + +
|
| + +
|
||||||
|
|
||||||
error[E0284]: type annotations needed
|
|
||||||
--> $DIR/const-arg-in-const-arg.rs:37:18
|
|
||||||
|
|
|
||||||
LL | let _: Foo<{ bar::<N>() }>;
|
|
||||||
| ^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar`
|
|
||||||
|
|
|
||||||
note: required by a const generic parameter in `bar`
|
|
||||||
--> $DIR/const-arg-in-const-arg.rs:9:14
|
|
||||||
|
|
|
||||||
LL | const fn bar<const N: usize>() -> usize { N }
|
|
||||||
| ^^^^^^^^^^^^^^ required by this const generic parameter in `bar`
|
|
||||||
|
|
||||||
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
||||||
--> $DIR/const-arg-in-const-arg.rs:40:24
|
--> $DIR/const-arg-in-const-arg.rs:37:24
|
||||||
|
|
|
|
||||||
LL | let _: Foo<{ faz::<'a>(&()) }>;
|
LL | let _: Foo<{ faz::<'a>(&()) }>;
|
||||||
| ^^
|
| ^^
|
||||||
@ -288,7 +264,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
|
|||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
||||||
--> $DIR/const-arg-in-const-arg.rs:43:24
|
--> $DIR/const-arg-in-const-arg.rs:40:24
|
||||||
|
|
|
|
||||||
LL | let _: Foo<{ faz::<'b>(&()) }>;
|
LL | let _: Foo<{ faz::<'b>(&()) }>;
|
||||||
| ^^
|
| ^^
|
||||||
@ -300,7 +276,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
|
|||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error: constant expression depends on a generic parameter
|
error: constant expression depends on a generic parameter
|
||||||
--> $DIR/const-arg-in-const-arg.rs:26:17
|
--> $DIR/const-arg-in-const-arg.rs:25:17
|
||||||
|
|
|
|
||||||
LL | let _ = [0; foo::<T>()];
|
LL | let _ = [0; foo::<T>()];
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
@ -308,7 +284,7 @@ LL | let _ = [0; foo::<T>()];
|
|||||||
= note: this may fail depending on what value the parameter takes
|
= note: this may fail depending on what value the parameter takes
|
||||||
|
|
||||||
error[E0747]: unresolved item provided when a constant was expected
|
error[E0747]: unresolved item provided when a constant was expected
|
||||||
--> $DIR/const-arg-in-const-arg.rs:27:23
|
--> $DIR/const-arg-in-const-arg.rs:26:23
|
||||||
|
|
|
|
||||||
LL | let _ = [0; bar::<N>()];
|
LL | let _ = [0; bar::<N>()];
|
||||||
| ^
|
| ^
|
||||||
@ -318,20 +294,8 @@ help: if this generic argument was intended as a const parameter, surround it wi
|
|||||||
LL | let _ = [0; bar::<{ N }>()];
|
LL | let _ = [0; bar::<{ N }>()];
|
||||||
| + +
|
| + +
|
||||||
|
|
||||||
error[E0284]: type annotations needed
|
|
||||||
--> $DIR/const-arg-in-const-arg.rs:27:17
|
|
||||||
|
|
|
||||||
LL | let _ = [0; bar::<N>()];
|
|
||||||
| ^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar`
|
|
||||||
|
|
|
||||||
note: required by a const generic parameter in `bar`
|
|
||||||
--> $DIR/const-arg-in-const-arg.rs:9:14
|
|
||||||
|
|
|
||||||
LL | const fn bar<const N: usize>() -> usize { N }
|
|
||||||
| ^^^^^^^^^^^^^^ required by this const generic parameter in `bar`
|
|
||||||
|
|
||||||
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
||||||
--> $DIR/const-arg-in-const-arg.rs:30:23
|
--> $DIR/const-arg-in-const-arg.rs:28:23
|
||||||
|
|
|
|
||||||
LL | let _ = [0; faz::<'a>(&())];
|
LL | let _ = [0; faz::<'a>(&())];
|
||||||
| ^^
|
| ^^
|
||||||
@ -343,7 +307,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
|
|||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
||||||
--> $DIR/const-arg-in-const-arg.rs:33:23
|
--> $DIR/const-arg-in-const-arg.rs:31:23
|
||||||
|
|
|
|
||||||
LL | let _ = [0; faz::<'b>(&())];
|
LL | let _ = [0; faz::<'b>(&())];
|
||||||
| ^^
|
| ^^
|
||||||
@ -355,7 +319,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
|
|||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error[E0747]: unresolved item provided when a constant was expected
|
error[E0747]: unresolved item provided when a constant was expected
|
||||||
--> $DIR/const-arg-in-const-arg.rs:47:27
|
--> $DIR/const-arg-in-const-arg.rs:44:27
|
||||||
|
|
|
|
||||||
LL | let _ = Foo::<{ bar::<N>() }>;
|
LL | let _ = Foo::<{ bar::<N>() }>;
|
||||||
| ^
|
| ^
|
||||||
@ -365,20 +329,8 @@ help: if this generic argument was intended as a const parameter, surround it wi
|
|||||||
LL | let _ = Foo::<{ bar::<{ N }>() }>;
|
LL | let _ = Foo::<{ bar::<{ N }>() }>;
|
||||||
| + +
|
| + +
|
||||||
|
|
||||||
error[E0284]: type annotations needed
|
|
||||||
--> $DIR/const-arg-in-const-arg.rs:47:21
|
|
||||||
|
|
|
||||||
LL | let _ = Foo::<{ bar::<N>() }>;
|
|
||||||
| ^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar`
|
|
||||||
|
|
|
||||||
note: required by a const generic parameter in `bar`
|
|
||||||
--> $DIR/const-arg-in-const-arg.rs:9:14
|
|
||||||
|
|
|
||||||
LL | const fn bar<const N: usize>() -> usize { N }
|
|
||||||
| ^^^^^^^^^^^^^^ required by this const generic parameter in `bar`
|
|
||||||
|
|
||||||
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
||||||
--> $DIR/const-arg-in-const-arg.rs:50:27
|
--> $DIR/const-arg-in-const-arg.rs:46:27
|
||||||
|
|
|
|
||||||
LL | let _ = Foo::<{ faz::<'a>(&()) }>;
|
LL | let _ = Foo::<{ faz::<'a>(&()) }>;
|
||||||
| ^^
|
| ^^
|
||||||
@ -390,7 +342,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
|
|||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
|
||||||
--> $DIR/const-arg-in-const-arg.rs:53:27
|
--> $DIR/const-arg-in-const-arg.rs:49:27
|
||||||
|
|
|
|
||||||
LL | let _ = Foo::<{ faz::<'b>(&()) }>;
|
LL | let _ = Foo::<{ faz::<'b>(&()) }>;
|
||||||
| ^^
|
| ^^
|
||||||
@ -401,7 +353,7 @@ note: the late bound lifetime parameter is introduced here
|
|||||||
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
|
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
|
||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error: aborting due to 40 previous errors
|
error: aborting due to 36 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0284, E0747, E0794.
|
Some errors have detailed explanations: E0747, E0794.
|
||||||
For more information about an error, try `rustc --explain E0284`.
|
For more information about an error, try `rustc --explain E0747`.
|
||||||
|
@ -15,7 +15,6 @@ fn test<'a, 'b, T, const N: usize>() where &'b (): Sized {
|
|||||||
let _: [u8; foo::<T>()]; //[min]~ ERROR generic parameters may not
|
let _: [u8; foo::<T>()]; //[min]~ ERROR generic parameters may not
|
||||||
let _: [u8; bar::<N>()]; //[min]~ ERROR generic parameters may not
|
let _: [u8; bar::<N>()]; //[min]~ ERROR generic parameters may not
|
||||||
//[min]~^ ERROR unresolved item provided when a constant was expected
|
//[min]~^ ERROR unresolved item provided when a constant was expected
|
||||||
//[min]~| ERROR type annotations needed
|
|
||||||
let _: [u8; faz::<'a>(&())]; //[min]~ ERROR generic parameters may not
|
let _: [u8; faz::<'a>(&())]; //[min]~ ERROR generic parameters may not
|
||||||
//[min]~^ ERROR cannot specify lifetime arguments
|
//[min]~^ ERROR cannot specify lifetime arguments
|
||||||
let _: [u8; baz::<'a>(&())]; //[min]~ ERROR generic parameters may not
|
let _: [u8; baz::<'a>(&())]; //[min]~ ERROR generic parameters may not
|
||||||
@ -26,7 +25,6 @@ fn test<'a, 'b, T, const N: usize>() where &'b (): Sized {
|
|||||||
let _ = [0; foo::<T>()]; //[min]~ ERROR constant expression depends on a generic parameter
|
let _ = [0; foo::<T>()]; //[min]~ ERROR constant expression depends on a generic parameter
|
||||||
let _ = [0; bar::<N>()]; //[min]~ ERROR generic parameters may not
|
let _ = [0; bar::<N>()]; //[min]~ ERROR generic parameters may not
|
||||||
//[min]~^ ERROR unresolved item provided when a constant was expected
|
//[min]~^ ERROR unresolved item provided when a constant was expected
|
||||||
//[min]~| ERROR type annotations needed
|
|
||||||
let _ = [0; faz::<'a>(&())]; //[min]~ ERROR generic parameters may not
|
let _ = [0; faz::<'a>(&())]; //[min]~ ERROR generic parameters may not
|
||||||
//[min]~^ ERROR cannot specify lifetime arguments
|
//[min]~^ ERROR cannot specify lifetime arguments
|
||||||
let _ = [0; baz::<'a>(&())]; //[min]~ ERROR generic parameters may not
|
let _ = [0; baz::<'a>(&())]; //[min]~ ERROR generic parameters may not
|
||||||
@ -36,7 +34,6 @@ fn test<'a, 'b, T, const N: usize>() where &'b (): Sized {
|
|||||||
let _: Foo<{ foo::<T>() }>; //[min]~ ERROR generic parameters may not
|
let _: Foo<{ foo::<T>() }>; //[min]~ ERROR generic parameters may not
|
||||||
let _: Foo<{ bar::<N>() }>; //[min]~ ERROR generic parameters may not
|
let _: Foo<{ bar::<N>() }>; //[min]~ ERROR generic parameters may not
|
||||||
//[min]~^ ERROR unresolved item provided when a constant was expected
|
//[min]~^ ERROR unresolved item provided when a constant was expected
|
||||||
//[min]~| ERROR type annotations needed
|
|
||||||
let _: Foo<{ faz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not
|
let _: Foo<{ faz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not
|
||||||
//[min]~^ ERROR cannot specify lifetime arguments
|
//[min]~^ ERROR cannot specify lifetime arguments
|
||||||
let _: Foo<{ baz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not
|
let _: Foo<{ baz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not
|
||||||
@ -46,7 +43,6 @@ fn test<'a, 'b, T, const N: usize>() where &'b (): Sized {
|
|||||||
let _ = Foo::<{ foo::<T>() }>; //[min]~ ERROR generic parameters may not
|
let _ = Foo::<{ foo::<T>() }>; //[min]~ ERROR generic parameters may not
|
||||||
let _ = Foo::<{ bar::<N>() }>; //[min]~ ERROR generic parameters may not
|
let _ = Foo::<{ bar::<N>() }>; //[min]~ ERROR generic parameters may not
|
||||||
//[min]~^ ERROR unresolved item provided when a constant was expected
|
//[min]~^ ERROR unresolved item provided when a constant was expected
|
||||||
//[min]~| ERROR type annotations needed
|
|
||||||
let _ = Foo::<{ faz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not
|
let _ = Foo::<{ faz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not
|
||||||
//[min]~^ ERROR cannot specify lifetime arguments
|
//[min]~^ ERROR cannot specify lifetime arguments
|
||||||
let _ = Foo::<{ baz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not
|
let _ = Foo::<{ baz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not
|
||||||
|
@ -30,31 +30,7 @@ help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
|
|||||||
LL + #![feature(generic_arg_infer)]
|
LL + #![feature(generic_arg_infer)]
|
||||||
|
|
|
|
||||||
|
|
||||||
error[E0284]: type annotations needed
|
error: aborting due to 3 previous errors
|
||||||
--> $DIR/issue-62878.rs:10:5
|
|
||||||
|
|
|
||||||
LL | foo::<_, { [1] }>();
|
|
||||||
| ^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `foo`
|
|
||||||
|
|
|
||||||
note: required by a const generic parameter in `foo`
|
|
||||||
--> $DIR/issue-62878.rs:5:8
|
|
||||||
|
|
|
||||||
LL | fn foo<const N: usize, const A: [u8; N]>() {}
|
|
||||||
| ^^^^^^^^^^^^^^ required by this const generic parameter in `foo`
|
|
||||||
|
|
||||||
error[E0284]: type annotations needed
|
Some errors have detailed explanations: E0747, E0770.
|
||||||
--> $DIR/issue-62878.rs:10:5
|
For more information about an error, try `rustc --explain E0747`.
|
||||||
|
|
|
||||||
LL | foo::<_, { [1] }>();
|
|
||||||
| ^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `A` declared on the function `foo`
|
|
||||||
|
|
|
||||||
note: required by a const generic parameter in `foo`
|
|
||||||
--> $DIR/issue-62878.rs:5:24
|
|
||||||
|
|
|
||||||
LL | fn foo<const N: usize, const A: [u8; N]>() {}
|
|
||||||
| ^^^^^^^^^^^^^^^^ required by this const generic parameter in `foo`
|
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
|
||||||
|
|
||||||
Some errors have detailed explanations: E0284, E0747, E0770.
|
|
||||||
For more information about an error, try `rustc --explain E0284`.
|
|
||||||
|
@ -9,6 +9,4 @@ fn foo<const N: usize, const A: [u8; N]>() {}
|
|||||||
fn main() {
|
fn main() {
|
||||||
foo::<_, { [1] }>();
|
foo::<_, { [1] }>();
|
||||||
//[min]~^ ERROR: type provided when a constant was expected
|
//[min]~^ ERROR: type provided when a constant was expected
|
||||||
//[min]~| ERROR type annotations needed
|
|
||||||
//[min]~| ERROR type annotations needed
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ fn b() {
|
|||||||
//~^ ERROR expected trait, found constant `BAR`
|
//~^ ERROR expected trait, found constant `BAR`
|
||||||
//~| ERROR expected trait, found constant `BAR`
|
//~| ERROR expected trait, found constant `BAR`
|
||||||
//~| ERROR type provided when a constant was expected
|
//~| ERROR type provided when a constant was expected
|
||||||
//~| ERROR type annotations needed
|
|
||||||
}
|
}
|
||||||
fn c() {
|
fn c() {
|
||||||
foo::<3 + 3>(); //~ ERROR expressions must be enclosed in braces
|
foo::<3 + 3>(); //~ ERROR expressions must be enclosed in braces
|
||||||
|
@ -10,7 +10,7 @@ LL | foo::<{ BAR + 3 }>();
|
|||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: expressions must be enclosed in braces to be used as const generic arguments
|
error: expressions must be enclosed in braces to be used as const generic arguments
|
||||||
--> $DIR/const-expression-suggest-missing-braces.rs:18:11
|
--> $DIR/const-expression-suggest-missing-braces.rs:17:11
|
||||||
|
|
|
|
||||||
LL | foo::<3 + 3>();
|
LL | foo::<3 + 3>();
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
@ -21,7 +21,7 @@ LL | foo::<{ 3 + 3 }>();
|
|||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: expected one of `,` or `>`, found `-`
|
error: expected one of `,` or `>`, found `-`
|
||||||
--> $DIR/const-expression-suggest-missing-braces.rs:21:15
|
--> $DIR/const-expression-suggest-missing-braces.rs:20:15
|
||||||
|
|
|
|
||||||
LL | foo::<BAR - 3>();
|
LL | foo::<BAR - 3>();
|
||||||
| ^ expected one of `,` or `>`
|
| ^ expected one of `,` or `>`
|
||||||
@ -32,7 +32,7 @@ LL | foo::<{ BAR - 3 }>();
|
|||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: expected one of `,` or `>`, found `-`
|
error: expected one of `,` or `>`, found `-`
|
||||||
--> $DIR/const-expression-suggest-missing-braces.rs:24:15
|
--> $DIR/const-expression-suggest-missing-braces.rs:23:15
|
||||||
|
|
|
|
||||||
LL | foo::<BAR - BAR>();
|
LL | foo::<BAR - BAR>();
|
||||||
| ^ expected one of `,` or `>`
|
| ^ expected one of `,` or `>`
|
||||||
@ -43,7 +43,7 @@ LL | foo::<{ BAR - BAR }>();
|
|||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: expressions must be enclosed in braces to be used as const generic arguments
|
error: expressions must be enclosed in braces to be used as const generic arguments
|
||||||
--> $DIR/const-expression-suggest-missing-braces.rs:27:11
|
--> $DIR/const-expression-suggest-missing-braces.rs:26:11
|
||||||
|
|
|
|
||||||
LL | foo::<100 - BAR>();
|
LL | foo::<100 - BAR>();
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
@ -54,7 +54,7 @@ LL | foo::<{ 100 - BAR }>();
|
|||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: expected one of `,` or `>`, found `(`
|
error: expected one of `,` or `>`, found `(`
|
||||||
--> $DIR/const-expression-suggest-missing-braces.rs:30:19
|
--> $DIR/const-expression-suggest-missing-braces.rs:29:19
|
||||||
|
|
|
|
||||||
LL | foo::<bar<i32>()>();
|
LL | foo::<bar<i32>()>();
|
||||||
| ^ expected one of `,` or `>`
|
| ^ expected one of `,` or `>`
|
||||||
@ -65,7 +65,7 @@ LL | foo::<{ bar<i32>() }>();
|
|||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: expected one of `,` or `>`, found `(`
|
error: expected one of `,` or `>`, found `(`
|
||||||
--> $DIR/const-expression-suggest-missing-braces.rs:33:21
|
--> $DIR/const-expression-suggest-missing-braces.rs:32:21
|
||||||
|
|
|
|
||||||
LL | foo::<bar::<i32>()>();
|
LL | foo::<bar::<i32>()>();
|
||||||
| ^ expected one of `,` or `>`
|
| ^ expected one of `,` or `>`
|
||||||
@ -76,7 +76,7 @@ LL | foo::<{ bar::<i32>() }>();
|
|||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: expected one of `,` or `>`, found `(`
|
error: expected one of `,` or `>`, found `(`
|
||||||
--> $DIR/const-expression-suggest-missing-braces.rs:36:21
|
--> $DIR/const-expression-suggest-missing-braces.rs:35:21
|
||||||
|
|
|
|
||||||
LL | foo::<bar::<i32>() + BAR>();
|
LL | foo::<bar::<i32>() + BAR>();
|
||||||
| ^ expected one of `,` or `>`
|
| ^ expected one of `,` or `>`
|
||||||
@ -87,7 +87,7 @@ LL | foo::<{ bar::<i32>() + BAR }>();
|
|||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: expected one of `,` or `>`, found `(`
|
error: expected one of `,` or `>`, found `(`
|
||||||
--> $DIR/const-expression-suggest-missing-braces.rs:39:21
|
--> $DIR/const-expression-suggest-missing-braces.rs:38:21
|
||||||
|
|
|
|
||||||
LL | foo::<bar::<i32>() - BAR>();
|
LL | foo::<bar::<i32>() - BAR>();
|
||||||
| ^ expected one of `,` or `>`
|
| ^ expected one of `,` or `>`
|
||||||
@ -98,7 +98,7 @@ LL | foo::<{ bar::<i32>() - BAR }>();
|
|||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: expected one of `,` or `>`, found `-`
|
error: expected one of `,` or `>`, found `-`
|
||||||
--> $DIR/const-expression-suggest-missing-braces.rs:42:15
|
--> $DIR/const-expression-suggest-missing-braces.rs:41:15
|
||||||
|
|
|
|
||||||
LL | foo::<BAR - bar::<i32>()>();
|
LL | foo::<BAR - bar::<i32>()>();
|
||||||
| ^ expected one of `,` or `>`
|
| ^ expected one of `,` or `>`
|
||||||
@ -109,7 +109,7 @@ LL | foo::<{ BAR - bar::<i32>() }>();
|
|||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: expected one of `,` or `>`, found `-`
|
error: expected one of `,` or `>`, found `-`
|
||||||
--> $DIR/const-expression-suggest-missing-braces.rs:45:15
|
--> $DIR/const-expression-suggest-missing-braces.rs:44:15
|
||||||
|
|
|
|
||||||
LL | foo::<BAR - bar::<i32>()>();
|
LL | foo::<BAR - bar::<i32>()>();
|
||||||
| ^ expected one of `,` or `>`
|
| ^ expected one of `,` or `>`
|
||||||
@ -137,19 +137,7 @@ error[E0747]: type provided when a constant was expected
|
|||||||
LL | foo::<BAR + BAR>();
|
LL | foo::<BAR + BAR>();
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
||||||
error[E0284]: type annotations needed
|
error: aborting due to 14 previous errors
|
||||||
--> $DIR/const-expression-suggest-missing-braces.rs:11:5
|
|
||||||
|
|
|
||||||
LL | foo::<BAR + BAR>();
|
|
||||||
| ^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the function `foo`
|
|
||||||
|
|
|
||||||
note: required by a const generic parameter in `foo`
|
|
||||||
--> $DIR/const-expression-suggest-missing-braces.rs:1:8
|
|
||||||
|
|
|
||||||
LL | fn foo<const C: usize>() {}
|
|
||||||
| ^^^^^^^^^^^^^^ required by this const generic parameter in `foo`
|
|
||||||
|
|
||||||
error: aborting due to 15 previous errors
|
Some errors have detailed explanations: E0404, E0747.
|
||||||
|
For more information about an error, try `rustc --explain E0404`.
|
||||||
Some errors have detailed explanations: E0284, E0404, E0747.
|
|
||||||
For more information about an error, try `rustc --explain E0284`.
|
|
||||||
|
@ -16,7 +16,6 @@ fn make_marker() -> impl Marker<gimme_a_const!(marker)> {
|
|||||||
//~| ERROR: type provided when a constant was expected
|
//~| ERROR: type provided when a constant was expected
|
||||||
Example::<gimme_a_const!(marker)>
|
Example::<gimme_a_const!(marker)>
|
||||||
//~^ ERROR: type provided when a constant was expected
|
//~^ ERROR: type provided when a constant was expected
|
||||||
//~| ERROR type annotations needed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_marker(_: impl Marker<{
|
fn from_marker(_: impl Marker<{
|
||||||
@ -37,10 +36,8 @@ fn main() {
|
|||||||
|
|
||||||
let _fail = Example::<external_macro!()>;
|
let _fail = Example::<external_macro!()>;
|
||||||
//~^ ERROR: type provided when a constant
|
//~^ ERROR: type provided when a constant
|
||||||
//~| ERROR type annotations needed
|
|
||||||
|
|
||||||
let _fail = Example::<gimme_a_const!()>;
|
let _fail = Example::<gimme_a_const!()>;
|
||||||
//~^ ERROR unexpected end of macro invocation
|
//~^ ERROR unexpected end of macro invocation
|
||||||
//~| ERROR: type provided when a constant was expected
|
//~| ERROR: type provided when a constant was expected
|
||||||
//~| ERROR type annotations needed
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error: expected type, found `{`
|
error: expected type, found `{`
|
||||||
--> $DIR/macro-fail.rs:31:27
|
--> $DIR/macro-fail.rs:30:27
|
||||||
|
|
|
|
||||||
LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> {
|
LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> {
|
||||||
| ----------------------
|
| ----------------------
|
||||||
@ -13,7 +13,7 @@ LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }}
|
|||||||
= note: this error originates in the macro `gimme_a_const` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `gimme_a_const` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: expected type, found `{`
|
error: expected type, found `{`
|
||||||
--> $DIR/macro-fail.rs:31:27
|
--> $DIR/macro-fail.rs:30:27
|
||||||
|
|
|
|
||||||
LL | Example::<gimme_a_const!(marker)>
|
LL | Example::<gimme_a_const!(marker)>
|
||||||
| ----------------------
|
| ----------------------
|
||||||
@ -41,7 +41,7 @@ LL | let _fail = Example::<external_macro!()>;
|
|||||||
= note: this error originates in the macro `external_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `external_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: unexpected end of macro invocation
|
error: unexpected end of macro invocation
|
||||||
--> $DIR/macro-fail.rs:42:25
|
--> $DIR/macro-fail.rs:40:25
|
||||||
|
|
|
|
||||||
LL | macro_rules! gimme_a_const {
|
LL | macro_rules! gimme_a_const {
|
||||||
| -------------------------- when calling this macro
|
| -------------------------- when calling this macro
|
||||||
@ -50,7 +50,7 @@ LL | let _fail = Example::<gimme_a_const!()>;
|
|||||||
| ^^^^^^^^^^^^^^^^ missing tokens in macro arguments
|
| ^^^^^^^^^^^^^^^^ missing tokens in macro arguments
|
||||||
|
|
|
|
||||||
note: while trying to match meta-variable `$rusty:ident`
|
note: while trying to match meta-variable `$rusty:ident`
|
||||||
--> $DIR/macro-fail.rs:31:8
|
--> $DIR/macro-fail.rs:30:8
|
||||||
|
|
|
|
||||||
LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }}
|
LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }}
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
@ -75,63 +75,18 @@ error[E0747]: type provided when a constant was expected
|
|||||||
LL | Example::<gimme_a_const!(marker)>
|
LL | Example::<gimme_a_const!(marker)>
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0284]: type annotations needed
|
|
||||||
--> $DIR/macro-fail.rs:17:3
|
|
||||||
|
|
|
||||||
LL | Example::<gimme_a_const!(marker)>
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the struct `Example`
|
|
||||||
|
|
|
||||||
note: required by a const generic parameter in `Example`
|
|
||||||
--> $DIR/macro-fail.rs:1:16
|
|
||||||
|
|
|
||||||
LL | struct Example<const N: usize>;
|
|
||||||
| ^^^^^^^^^^^^^^ required by this const generic parameter in `Example`
|
|
||||||
|
|
||||||
error[E0747]: type provided when a constant was expected
|
error[E0747]: type provided when a constant was expected
|
||||||
--> $DIR/macro-fail.rs:38:25
|
--> $DIR/macro-fail.rs:37:25
|
||||||
|
|
|
|
||||||
LL | let _fail = Example::<external_macro!()>;
|
LL | let _fail = Example::<external_macro!()>;
|
||||||
| ^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0747]: type provided when a constant was expected
|
error[E0747]: type provided when a constant was expected
|
||||||
--> $DIR/macro-fail.rs:42:25
|
--> $DIR/macro-fail.rs:40:25
|
||||||
|
|
|
|
||||||
LL | let _fail = Example::<gimme_a_const!()>;
|
LL | let _fail = Example::<gimme_a_const!()>;
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0284]: type annotations needed for `Example<_>`
|
error: aborting due to 9 previous errors
|
||||||
--> $DIR/macro-fail.rs:38:7
|
|
||||||
|
|
|
||||||
LL | let _fail = Example::<external_macro!()>;
|
|
||||||
| ^^^^^ ---------------------------- type must be known at this point
|
|
||||||
|
|
|
||||||
note: required by a const generic parameter in `Example`
|
|
||||||
--> $DIR/macro-fail.rs:1:16
|
|
||||||
|
|
|
||||||
LL | struct Example<const N: usize>;
|
|
||||||
| ^^^^^^^^^^^^^^ required by this const generic parameter in `Example`
|
|
||||||
help: consider giving `_fail` an explicit type, where the value of const parameter `N` is specified
|
|
||||||
|
|
|
||||||
LL | let _fail: Example<N> = Example::<external_macro!()>;
|
|
||||||
| ++++++++++++
|
|
||||||
|
|
||||||
error[E0284]: type annotations needed for `Example<_>`
|
For more information about this error, try `rustc --explain E0747`.
|
||||||
--> $DIR/macro-fail.rs:42:7
|
|
||||||
|
|
|
||||||
LL | let _fail = Example::<gimme_a_const!()>;
|
|
||||||
| ^^^^^ --------------------------- type must be known at this point
|
|
||||||
|
|
|
||||||
note: required by a const generic parameter in `Example`
|
|
||||||
--> $DIR/macro-fail.rs:1:16
|
|
||||||
|
|
|
||||||
LL | struct Example<const N: usize>;
|
|
||||||
| ^^^^^^^^^^^^^^ required by this const generic parameter in `Example`
|
|
||||||
help: consider giving `_fail` an explicit type, where the value of const parameter `N` is specified
|
|
||||||
|
|
|
||||||
LL | let _fail: Example<N> = Example::<gimme_a_const!()>;
|
|
||||||
| ++++++++++++
|
|
||||||
|
|
||||||
error: aborting due to 12 previous errors
|
|
||||||
|
|
||||||
Some errors have detailed explanations: E0284, E0747.
|
|
||||||
For more information about an error, try `rustc --explain E0284`.
|
|
||||||
|
@ -5,8 +5,6 @@ fn example<const N: usize>() {}
|
|||||||
fn other() {
|
fn other() {
|
||||||
example::<[usize; 3]>();
|
example::<[usize; 3]>();
|
||||||
//~^ ERROR type provided when a const
|
//~^ ERROR type provided when a const
|
||||||
//~| ERROR type annotations needed
|
|
||||||
example::<[usize; 4 + 5]>();
|
example::<[usize; 4 + 5]>();
|
||||||
//~^ ERROR type provided when a const
|
//~^ ERROR type provided when a const
|
||||||
//~| ERROR type annotations needed
|
|
||||||
}
|
}
|
||||||
|
@ -5,36 +5,11 @@ LL | example::<[usize; 3]>();
|
|||||||
| ^^^^^^^^^^ help: array type provided where a `usize` was expected, try: `{ 3 }`
|
| ^^^^^^^^^^ help: array type provided where a `usize` was expected, try: `{ 3 }`
|
||||||
|
|
||||||
error[E0747]: type provided when a constant was expected
|
error[E0747]: type provided when a constant was expected
|
||||||
--> $DIR/suggest_const_for_array.rs:9:15
|
--> $DIR/suggest_const_for_array.rs:8:15
|
||||||
|
|
|
|
||||||
LL | example::<[usize; 4 + 5]>();
|
LL | example::<[usize; 4 + 5]>();
|
||||||
| ^^^^^^^^^^^^^^ help: array type provided where a `usize` was expected, try: `{ 4 + 5 }`
|
| ^^^^^^^^^^^^^^ help: array type provided where a `usize` was expected, try: `{ 4 + 5 }`
|
||||||
|
|
||||||
error[E0284]: type annotations needed
|
error: aborting due to 2 previous errors
|
||||||
--> $DIR/suggest_const_for_array.rs:6:5
|
|
||||||
|
|
|
||||||
LL | example::<[usize; 3]>();
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `example`
|
|
||||||
|
|
|
||||||
note: required by a const generic parameter in `example`
|
|
||||||
--> $DIR/suggest_const_for_array.rs:3:12
|
|
||||||
|
|
|
||||||
LL | fn example<const N: usize>() {}
|
|
||||||
| ^^^^^^^^^^^^^^ required by this const generic parameter in `example`
|
|
||||||
|
|
||||||
error[E0284]: type annotations needed
|
For more information about this error, try `rustc --explain E0747`.
|
||||||
--> $DIR/suggest_const_for_array.rs:9:5
|
|
||||||
|
|
|
||||||
LL | example::<[usize; 4 + 5]>();
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `example`
|
|
||||||
|
|
|
||||||
note: required by a const generic parameter in `example`
|
|
||||||
--> $DIR/suggest_const_for_array.rs:3:12
|
|
||||||
|
|
|
||||||
LL | fn example<const N: usize>() {}
|
|
||||||
| ^^^^^^^^^^^^^^ required by this const generic parameter in `example`
|
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
|
||||||
|
|
||||||
Some errors have detailed explanations: E0284, E0747.
|
|
||||||
For more information about an error, try `rustc --explain E0284`.
|
|
||||||
|
@ -3,5 +3,4 @@ fn foo<U>() {}
|
|||||||
fn main() {
|
fn main() {
|
||||||
foo::<main>()
|
foo::<main>()
|
||||||
//~^ ERROR constant provided when a type was expected
|
//~^ ERROR constant provided when a type was expected
|
||||||
//~| ERROR type annotations needed
|
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,6 @@ LL | foo::<main>()
|
|||||||
= help: `main` is a function item, not a type
|
= help: `main` is a function item, not a type
|
||||||
= help: function item types cannot be named directly
|
= help: function item types cannot be named directly
|
||||||
|
|
||||||
error[E0282]: type annotations needed
|
error: aborting due to 1 previous error
|
||||||
--> $DIR/generic-function-item-where-type.rs:4:5
|
|
||||||
|
|
|
||||||
LL | foo::<main>()
|
|
||||||
| ^^^^^^^^^^^ cannot infer type of the type parameter `U` declared on the function `foo`
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
For more information about this error, try `rustc --explain E0747`.
|
||||||
|
|
||||||
Some errors have detailed explanations: E0282, E0747.
|
|
||||||
For more information about an error, try `rustc --explain E0282`.
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user