Require TAITs to be mentioned in the signatures of functions that register hidden types for them
This commit is contained in:
parent
921f669749
commit
4c99872efe
70 changed files with 796 additions and 184 deletions
|
@ -6,7 +6,7 @@ use rustc_middle::hir::nested_filter;
|
|||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_span::DUMMY_SP;
|
||||
|
||||
use crate::errors::UnconstrainedOpaqueType;
|
||||
use crate::errors::{TaitForwardCompat, UnconstrainedOpaqueType};
|
||||
|
||||
/// Checks "defining uses" of opaque `impl Trait` types to ensure that they meet the restrictions
|
||||
/// laid for "higher-order pattern unification".
|
||||
|
@ -139,6 +139,15 @@ impl TaitConstraintLocator<'_> {
|
|||
continue;
|
||||
}
|
||||
constrained = true;
|
||||
if !self.tcx.opaque_types_defined_by(item_def_id).contains(&self.def_id) {
|
||||
self.tcx.sess.emit_err(TaitForwardCompat {
|
||||
span: hidden_type.span,
|
||||
item_span: self
|
||||
.tcx
|
||||
.def_ident_span(item_def_id)
|
||||
.unwrap_or_else(|| self.tcx.def_span(item_def_id)),
|
||||
});
|
||||
}
|
||||
let concrete_type =
|
||||
self.tcx.erase_regions(hidden_type.remap_generic_params_to_declaration_params(
|
||||
opaque_type_key,
|
||||
|
|
|
@ -184,6 +184,16 @@ pub struct UnconstrainedOpaqueType {
|
|||
pub what: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(hir_analysis_tait_forward_compat)]
|
||||
#[note]
|
||||
pub struct TaitForwardCompat {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[note]
|
||||
pub item_span: Span,
|
||||
}
|
||||
|
||||
pub struct MissingTypeParams {
|
||||
pub span: Span,
|
||||
pub def_span: Span,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue