Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Reconstify Add #120381

Merged
merged 3 commits into from
Feb 8, 2024
Merged
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
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl<'tcx, T> IsSuggestable<'tcx> for T
where
T: TypeVisitable<TyCtxt<'tcx>> + TypeFoldable<TyCtxt<'tcx>>,
{
#[tracing::instrument(level = "debug", skip(tcx))]
fn is_suggestable(self, tcx: TyCtxt<'tcx>, infer_suggestable: bool) -> bool {
self.visit_with(&mut IsSuggestableVisitor { tcx, infer_suggestable }).is_continue()
}
Expand Down Expand Up @@ -533,6 +534,9 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
match c.kind() {
ConstKind::Infer(InferConst::Var(_)) if self.infer_suggestable => {}

// effect variables are always suggestable, because they are not visible
ConstKind::Infer(InferConst::EffectVar(_)) => {}

ConstKind::Infer(..)
| ConstKind::Bound(..)
| ConstKind::Placeholder(..)
Expand Down
4 changes: 3 additions & 1 deletion library/core/src/ops/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
append_const_msg
)]
#[doc(alias = "+")]
#[const_trait]
pub trait Add<Rhs = Self> {
/// The resulting type after applying the `+` operator.
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -94,7 +95,8 @@ pub trait Add<Rhs = Self> {
macro_rules! add_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
impl Add for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const Add for $t {
type Output = $t;

#[inline]
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/suggestions/invalid-bin-op.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ help: consider annotating `S<T>` with `#[derive(PartialEq)]`
LL + #[derive(PartialEq)]
LL | struct S<T>(T);
|
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
LL | pub fn foo<T>(s: S<T>, t: S<T>) where S<T>: PartialEq {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being suggested now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was removed in a const-traits PR: d464dd0#diff-a4f9511c26556adec6fac6f4073f446a12e9c9c883b0fd5ae672956caa5836c9 in #118661. This has been suggested before PartialEq gained the effect param, and adding the effect param in that commit made PartialEq not suggestable (which this PR makes it suggestable again)

| +++++++++++++++++++++

error: aborting due to 1 previous error

Expand Down
26 changes: 13 additions & 13 deletions tests/ui/ufcs/ufcs-qpath-self-mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ LL | <i32 as Add<u32>>::add(1, 2);
<&'a i32 as Add<i32>>
<&i32 as Add<&i32>>

error[E0277]: cannot add `u32` to `i32`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine that this error message is duplicated imo.

--> $DIR/ufcs-qpath-self-mismatch.rs:4:5
|
LL | <i32 as Add<u32>>::add(1, 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `i32 + u32`
|
= help: the trait `Add<u32>` is not implemented for `i32`
= help: the following other types implement trait `Add<Rhs>`:
<i32 as Add>
<i32 as Add<&i32>>
<&'a i32 as Add<i32>>
<&i32 as Add<&i32>>

error[E0308]: mismatched types
--> $DIR/ufcs-qpath-self-mismatch.rs:7:28
|
Expand Down Expand Up @@ -55,19 +68,6 @@ help: change the type of the numeric literal from `u32` to `i32`
LL | <i32 as Add<i32>>::add(1, 2i32);
| ~~~

error[E0277]: cannot add `u32` to `i32`
--> $DIR/ufcs-qpath-self-mismatch.rs:4:5
|
LL | <i32 as Add<u32>>::add(1, 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `i32 + u32`
|
= help: the trait `Add<u32>` is not implemented for `i32`
= help: the following other types implement trait `Add<Rhs>`:
<i32 as Add>
<i32 as Add<&i32>>
<&'a i32 as Add<i32>>
<&i32 as Add<&i32>>

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0277, E0308.
Expand Down
Loading