Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions compiler/rustc_attr_ir/src/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1615,9 +1615,6 @@ pub enum AttributeKind {
/// Represents `#[rustc_regions]`
RustcRegions,

/// Represents `#[rustc_reservation_impl]`
RustcReservationImpl(Symbol),

/// Represents `#[rustc_scalable_vector(N)]`
RustcScalableVector {
/// The base multiple of lanes that are in a scalable vector, if provided. `element_count`
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_attr_ir/src/encode_cross_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ impl AttributeKind {
RustcPubTransparent(..) => Yes,
RustcReallocator => No,
RustcRegions => No,
RustcReservationImpl(..) => Yes,
RustcScalableVector { .. } => Yes,
RustcShouldNotBeCalledOnConstItems => Yes,
RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate
Expand Down
17 changes: 0 additions & 17 deletions compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,23 +1102,6 @@ impl NoArgsAttributeParser for RustcStrictCoherenceParser {
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcStrictCoherence;
}

pub(crate) struct RustcReservationImplParser;

impl SingleAttributeParser for RustcReservationImplParser {
const PATH: &[Symbol] = &[sym::rustc_reservation_impl];
const ALLOWED_TARGETS: AllowedTargets<'_> =
AllowedTargets::AllowList(&[Allow(Target::Impl { of_trait: true })]);
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "reservation message");
const STABILITY: AttributeStability = unstable!(rustc_attrs);

fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
let nv = cx.expect_name_value(args, cx.attr_span, None)?;
let value_str = cx.expect_string_literal(nv)?;

Some(AttributeKind::RustcReservationImpl(value_str))
}
}

pub(crate) struct PreludeImportParser;

impl NoArgsAttributeParser for PreludeImportParser {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ attribute_parsers!(
Single<RustcNeverTypeOptionsParser>,
Single<RustcObjcClassParser>,
Single<RustcObjcSelectorParser>,
Single<RustcReservationImplParser>,
Single<RustcScalableVectorParser>,
Single<RustcSimdMonomorphizeLaneLimitParser>,
Single<RustcSkipDuringMethodDispatchParser>,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
sym::prelude_import,
sym::rustc_paren_sugar,
sym::rustc_inherit_overflow_checks,
sym::rustc_reservation_impl,
sym::rustc_test_entrypoint_marker,
sym::rustc_test_marker,
sym::rustc_allow_lifetime_dependent_specialization,
Expand Down
11 changes: 3 additions & 8 deletions compiler/rustc_hir_analysis/src/check/always_applicable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ pub(crate) fn check_drop_impl(
match tcx.impl_polarity(drop_impl_did) {
ty::ImplPolarity::Positive => {}
ty::ImplPolarity::Negative => {
return Err(tcx.dcx().emit_err(diagnostics::DropImplPolarity::Negative {
span: tcx.def_span(drop_impl_did),
}));
}
ty::ImplPolarity::Reservation => {
return Err(tcx.dcx().emit_err(diagnostics::DropImplPolarity::Reservation {
return Err(tcx.dcx().emit_err(diagnostics::NegativeDropImplPolarity {
span: tcx.def_span(drop_impl_did),
}));
}
Expand Down Expand Up @@ -153,7 +148,7 @@ fn ensure_impl_params_and_item_params_correspond<'tcx>(
let item_span = tcx.def_span(adt_def_id);
let self_descr = tcx.def_descr(adt_def_id);
let polarity = match tcx.impl_polarity(impl_def_id) {
ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => "",
ty::ImplPolarity::Positive => "",
ty::ImplPolarity::Negative => "!",
};
let trait_name = tcx.item_name(tcx.impl_trait_id(impl_def_id.to_def_id()));
Expand Down Expand Up @@ -265,7 +260,7 @@ fn ensure_impl_predicates_are_implied_by_item_defn<'tcx>(
let impl_span = tcx.def_span(impl_def_id.to_def_id());
let trait_name = tcx.item_name(tcx.impl_trait_id(impl_def_id.to_def_id()));
let polarity = match tcx.impl_polarity(impl_def_id) {
ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => "",
ty::ImplPolarity::Positive => "",
ty::ImplPolarity::Negative => "!",
};
// Take the param-env of the adt and instantiate the args that show up in
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ fn check_impl_items_against_trait<'tcx>(

// Negative impls are not expected to have any items
match impl_trait_header.polarity {
ty::ImplPolarity::Reservation | ty::ImplPolarity::Positive => {}
ty::ImplPolarity::Positive => {}
ty::ImplPolarity::Negative => {
if let [first_item_ref, ..] = *impl_item_refs {
let first_item_span = tcx.def_span(first_item_ref);
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,6 @@ pub(super) fn check_item<'tcx>(
.emit());
}
}
ty::ImplPolarity::Reservation => {
// FIXME: what amount of WF checking do we need for reservation impls?
}
}
} else {
res = res.and(check_impl(tcx, item, impl_));
Expand Down Expand Up @@ -1309,9 +1306,6 @@ fn check_impl<'tcx>(
enter_wf_checking_ctxt(tcx, item.owner_id.def_id, |wfcx| {
match impl_.of_trait {
Some(of_trait) => {
// `#[rustc_reservation_impl]` impls are not real impls and
// therefore don't need to be WF (the trait's `Self: Trait` predicate
// won't hold).
let trait_ref = tcx.impl_trait_ref(item.owner_id).instantiate_identity();
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in
// case other `Foo` impls are incoherent.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E

let param_env = tcx.param_env(impl_did);

if let ty::ImplPolarity::Negative | ty::ImplPolarity::Reservation = header.polarity {
if let ty::ImplPolarity::Negative = header.polarity {
return Ok(());
}

Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_hir_analysis/src/coherence/unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(super) fn check_item(
};

match (trait_def_safety, unsafe_attr, trait_header.safety, trait_header.polarity) {
(Safety::Safe, None, Safety::Unsafe, Positive | Reservation) => {
(Safety::Safe, None, Safety::Unsafe, Positive) => {
let span = tcx.def_span(def_id);
return Err(struct_span_code_err!(
tcx.dcx(),
Expand All @@ -52,7 +52,7 @@ pub(super) fn check_item(
.emit());
}

(Safety::Unsafe, _, Safety::Safe, Positive | Reservation) => {
(Safety::Unsafe, _, Safety::Safe, Positive) => {
let span = tcx.def_span(def_id);
return Err(struct_span_code_err!(
tcx.dcx(),
Expand Down Expand Up @@ -86,7 +86,7 @@ pub(super) fn check_item(
.emit());
}

(Safety::Safe, Some(attr_name), Safety::Safe, Positive | Reservation) => {
(Safety::Safe, Some(attr_name), Safety::Safe, Positive) => {
let span = tcx.def_span(def_id);
return Err(struct_span_code_err!(
tcx.dcx(),
Expand Down Expand Up @@ -116,8 +116,8 @@ pub(super) fn check_item(
Ok(())
}
(_, _, Safety::Safe, Negative)
| (Safety::Unsafe, _, Safety::Unsafe, Positive | Reservation)
| (Safety::Safe, Some(_), Safety::Unsafe, Positive | Reservation)
| (Safety::Unsafe, _, Safety::Unsafe, Positive)
| (Safety::Safe, Some(_), Safety::Unsafe, Positive)
| (Safety::Safe, None, Safety::Safe, _) => Ok(()),
}
}
25 changes: 4 additions & 21 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,6 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::ImplTraitHeader
.of_trait
.unwrap_or_else(|| panic!("expected impl trait, found inherent impl on {def_id:?}"));
let selfty = tcx.type_of(def_id).instantiate_identity().skip_norm_wip();
let is_rustc_reservation = find_attr!(tcx, def_id, RustcReservationImpl(..));

check_impl_constness(tcx, impl_.constness, &of_trait.trait_ref);

Expand All @@ -1419,7 +1418,7 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::ImplTraitHeader
ty::ImplTraitHeader {
trait_ref: ty::EarlyBinder::bind(tcx, trait_ref),
safety: of_trait.safety,
polarity: polarity_of_impl(tcx, of_trait, is_rustc_reservation),
polarity: polarity_of_impl(of_trait),
constness: impl_.constness,
}
}
Expand Down Expand Up @@ -1466,26 +1465,10 @@ fn check_impl_constness(
});
}

fn polarity_of_impl(
tcx: TyCtxt<'_>,
of_trait: &hir::TraitImplHeader<'_>,
is_rustc_reservation: bool,
) -> ty::ImplPolarity {
fn polarity_of_impl(of_trait: &hir::TraitImplHeader<'_>) -> ty::ImplPolarity {
match of_trait.polarity {
hir::ImplPolarity::Negative(span) => {
if is_rustc_reservation {
let span = span.to(of_trait.trait_ref.path.span);
tcx.dcx().span_err(span, "reservation impls can't be negative");
}
ty::ImplPolarity::Negative
}
hir::ImplPolarity::Positive => {
if is_rustc_reservation {
ty::ImplPolarity::Reservation
} else {
ty::ImplPolarity::Positive
}
}
hir::ImplPolarity::Negative(_) => ty::ImplPolarity::Negative,
hir::ImplPolarity::Positive => ty::ImplPolarity::Positive,
}
}

Expand Down
15 changes: 4 additions & 11 deletions compiler/rustc_hir_analysis/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,17 +1074,10 @@ pub(crate) struct StaticSpecialize {
}

#[derive(Diagnostic)]
pub(crate) enum DropImplPolarity {
#[diag("negative `Drop` impls are not supported")]
Negative {
#[primary_span]
span: Span,
},
#[diag("reservation `Drop` impls are not supported")]
Reservation {
#[primary_span]
span: Span,
},
#[diag("negative `Drop` impls are not supported")]
pub(crate) struct NegativeDropImplPolarity {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1904,10 +1904,6 @@ impl<'tcx> TyCtxt<'tcx> {
}

match (impl1.polarity, impl2.polarity) {
(ImplPolarity::Reservation, _) | (_, ImplPolarity::Reservation) => {
// `#[rustc_reservation_impl]` impls don't overlap with anything
return Some(ImplOverlapKind::Permitted { marker: false });
}
(ImplPolarity::Positive, ImplPolarity::Negative)
| (ImplPolarity::Negative, ImplPolarity::Positive) => {
// `impl AutoTrait for Type` + `impl !AutoTrait for Type`
Expand Down
45 changes: 17 additions & 28 deletions compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ where
goal: Goal<I, Self>,
goal_trait_ref: ty::TraitRef<I>,
impl_def_id: I::ImplId,
then: impl FnOnce(&mut EvalCtxt<'_, D>, Certainty) -> QueryResultOrRerunNonErased<I>,
then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResultOrRerunNonErased<I>,
) -> Result<Candidate<I>, NoSolutionOrRerunNonErased>;

/// If the predicate contained an error, we want to avoid emitting unnecessary trait
Expand Down Expand Up @@ -553,13 +553,9 @@ where
let cx = self.cx();
let goal_trait_ref = goal.predicate.trait_ref(cx);
cx.for_each_relevant_impl(goal_trait_ref, |impl_def_id| -> Result<_, _> {
match G::consider_impl_candidate(
self,
goal,
goal_trait_ref,
impl_def_id,
|ecx, certainty| ecx.evaluate_added_goals_and_make_canonical_response(certainty),
)
match G::consider_impl_candidate(self, goal, goal_trait_ref, impl_def_id, |ecx| {
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
})
.map_err_to_rerun()?
{
Ok(candidate) => {
Expand Down Expand Up @@ -1186,26 +1182,19 @@ where
return Ok(());
}

match G::consider_impl_candidate(
self,
goal,
goal_trait_ref,
impl_def_id,
|ecx, certainty| {
if ecx.shallow_resolve(self_ty).is_ty_var() {
// We force the certainty of impl candidates to be `Maybe`.
let certainty = certainty.and(Certainty::AMBIGUOUS);
ecx.evaluate_added_goals_and_make_canonical_response(certainty)
} else {
// We don't want to use impls if they constrain the opaque.
//
// FIXME(trait-system-refactor-initiative#229): This isn't
// perfect yet as it still allows us to incorrectly constrain
// other inference variables.
Err(NoSolution.into())
}
},
)
match G::consider_impl_candidate(self, goal, goal_trait_ref, impl_def_id, |ecx| {
if ecx.shallow_resolve(self_ty).is_ty_var() {
// We force the certainty of impl candidates to be `Maybe`.
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
} else {
// We don't want to use impls if they constrain the opaque.
//
// FIXME(trait-system-refactor-initiative#229): This isn't
// perfect yet as it still allows us to incorrectly constrain
// other inference variables.
Err(NoSolution.into())
}
})
.map_err_to_rerun()?
{
Ok(candidate) => candidates.push(candidate),
Expand Down
16 changes: 4 additions & 12 deletions compiler/rustc_next_trait_solver/src/solve/effect_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ where
goal: Goal<I, Self>,
goal_trait_ref: ty::TraitRef<I>,
impl_def_id: I::ImplId,
then: impl FnOnce(&mut EvalCtxt<'_, D>, Certainty) -> QueryResultOrRerunNonErased<I>,
then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResultOrRerunNonErased<I>,
) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
let cx = ecx.cx();

Expand All @@ -149,17 +149,9 @@ where
return Err(NoSolution.into());
}

let impl_polarity = cx.impl_polarity(impl_def_id);
let certainty = match impl_polarity {
match cx.impl_polarity(impl_def_id) {
ty::ImplPolarity::Negative => return Err(NoSolution.into()),
ty::ImplPolarity::Reservation => {
if ecx.typing_mode().is_coherence() {
Certainty::AMBIGUOUS
} else {
return Err(NoSolution.into());
}
}
ty::ImplPolarity::Positive => Certainty::Yes,
ty::ImplPolarity::Positive => (),
};

if !cx.impl_is_const(impl_def_id) {
Expand Down Expand Up @@ -193,7 +185,7 @@ where
});
ecx.add_goals(GoalSource::ImplWhereBound, const_conditions)?;

then(ecx, certainty)
then(ecx)
})
}

Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ where
goal: Goal<I, NormalizesTo<I>>,
goal_trait_ref: ty::TraitRef<I>,
impl_def_id: I::ImplId,
then: impl FnOnce(&mut EvalCtxt<'_, D>, Certainty) -> QueryResultOrRerunNonErased<I>,
then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResultOrRerunNonErased<I>,
) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
let cx = ecx.cx();

Expand All @@ -271,9 +271,6 @@ where
let impl_polarity = cx.impl_polarity(impl_def_id);
match impl_polarity {
ty::ImplPolarity::Negative => return Err(NoSolution.into()),
ty::ImplPolarity::Reservation => {
unimplemented!("reservation impl for trait with assoc item: {:?}", goal)
}
ty::ImplPolarity::Positive => {}
};

Expand Down Expand Up @@ -382,10 +379,10 @@ where
// This is not the case here and we only prefer adding an ambiguous
// nested goal for consistency.
ecx.add_goal(GoalSource::Misc, goal.with(cx, PredicateKind::Ambiguous))?;
return then(ecx, Certainty::Yes);
return then(ecx);
} else {
ecx.instantiate_normalizes_to_as_rigid(goal)?;
return then(ecx, Certainty::Yes);
return then(ecx);
}
} else {
return error_response(ecx, cx.delay_bug("missing item"));
Expand Down
Loading
Loading