Skip to content

Commit 5bdadf5

Browse files
committed
Require TAITs to be mentioned in the signatures of functions that register hidden types for them
1 parent 25b5af1 commit 5bdadf5

File tree

68 files changed

+789
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+789
-179
lines changed

compiler/rustc_error_messages/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ fn register_functions(bundle: &mut FluentBundle) {
226226
pub type LazyFallbackBundle = Lrc<Lazy<FluentBundle, impl FnOnce() -> FluentBundle>>;
227227

228228
/// Return the default `FluentBundle` with standard "en-US" diagnostic messages.
229-
#[instrument(level = "trace")]
229+
#[instrument(level = "trace", skip(resources))]
230230
pub fn fallback_fluent_bundle(
231231
resources: Vec<&'static str>,
232232
with_directionality_markers: bool,
@@ -242,7 +242,6 @@ pub fn fallback_fluent_bundle(
242242
for resource in resources {
243243
let resource = FluentResource::try_new(resource.to_string())
244244
.expect("failed to parse fallback fluent resource");
245-
trace!(?resource);
246245
fallback_bundle.add_resource_overriding(resource);
247246
}
248247

compiler/rustc_hir_analysis/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ hir_analysis_static_specialize = cannot specialize on `'static` lifetime
239239
240240
hir_analysis_substs_on_overridden_impl = could not resolve substs on overridden impl
241241
242+
hir_analysis_tait_forward_compat = item constrains opaque type that is not in its signature
243+
.note = this item must have the opaque type in its signature in order to be able to register hidden types
244+
242245
hir_analysis_target_feature_on_main = `main` function is not allowed to have `#[target_feature]`
243246
244247
hir_analysis_too_large_static = extern static is too large for the current architecture

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_middle::hir::nested_filter;
66
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
77
use rustc_span::DUMMY_SP;
88

9-
use crate::errors::UnconstrainedOpaqueType;
9+
use crate::errors::{TaitForwardCompat, UnconstrainedOpaqueType};
1010

1111
/// Checks "defining uses" of opaque `impl Trait` types to ensure that they meet the restrictions
1212
/// laid for "higher-order pattern unification".
@@ -138,6 +138,15 @@ impl TaitConstraintLocator<'_> {
138138
continue;
139139
}
140140
constrained = true;
141+
if !self.tcx.opaque_types_defined_by(item_def_id).contains(&self.def_id) {
142+
self.tcx.sess.emit_err(TaitForwardCompat {
143+
span: hidden_type.span,
144+
item_span: self
145+
.tcx
146+
.def_ident_span(item_def_id)
147+
.unwrap_or_else(|| self.tcx.def_span(item_def_id)),
148+
});
149+
}
141150
let concrete_type =
142151
self.tcx.erase_regions(hidden_type.remap_generic_params_to_declaration_params(
143152
opaque_type_key,

compiler/rustc_hir_analysis/src/errors.rs

+10
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ pub struct UnconstrainedOpaqueType {
184184
pub what: &'static str,
185185
}
186186

187+
#[derive(Diagnostic)]
188+
#[diag(hir_analysis_tait_forward_compat)]
189+
#[note]
190+
pub struct TaitForwardCompat {
191+
#[primary_span]
192+
pub span: Span,
193+
#[note]
194+
pub item_span: Span,
195+
}
196+
187197
pub struct MissingTypeParams {
188198
pub span: Span,
189199
pub def_span: Span,

compiler/rustc_hir_typeck/src/inherited.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'tcx> Inherited<'tcx> {
8080
let infcx = tcx
8181
.infer_ctxt()
8282
.ignoring_regions()
83-
.with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id))
83+
.with_opaque_type_inference(DefiningAnchor::Bind(def_id))
8484
.build();
8585
let typeck_results = RefCell::new(ty::TypeckResults::new(hir_owner));
8686

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<T> Trait<T> for X {
257257
);
258258
}
259259
}
260-
(ty::Alias(ty::Opaque, alias), _) | (_, ty::Alias(ty::Opaque, alias)) if alias.def_id.is_local() && matches!(tcx.def_kind(body_owner_def_id), DefKind::AssocFn | DefKind::AssocConst) => {
260+
(ty::Alias(ty::Opaque, alias), _) | (_, ty::Alias(ty::Opaque, alias)) if alias.def_id.is_local() && matches!(tcx.def_kind(body_owner_def_id), DefKind::Fn | DefKind::Static(_) | DefKind::Const | DefKind::AssocFn | DefKind::AssocConst) => {
261261
if tcx.is_type_alias_impl_trait(alias.def_id) {
262262
if !tcx.opaque_types_defined_by(body_owner_def_id.expect_local()).contains(&alias.def_id.expect_local()) {
263263
let sp = tcx.def_ident_span(body_owner_def_id).unwrap_or_else(|| tcx.def_span(body_owner_def_id));

compiler/rustc_trait_selection/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod fulfill;
1212
pub mod misc;
1313
mod object_safety;
1414
pub mod outlives_bounds;
15-
mod project;
15+
pub mod project;
1616
pub mod query;
1717
#[cfg_attr(not(bootstrap), allow(hidden_glob_reexports))]
1818
mod select;

0 commit comments

Comments
 (0)