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

relaxing a non-Sized bounds is a hard-warning #135809

Closed
lcnr opened this issue Jan 21, 2025 · 4 comments · Fixed by #135841
Closed

relaxing a non-Sized bounds is a hard-warning #135809

lcnr opened this issue Jan 21, 2025 · 4 comments · Fixed by #135841
Labels
C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Jan 21, 2025

let mut seen_sized_unbound = false;
for unbound in unbounds {
if let Some(sized_def_id) = sized_def_id
&& unbound.trait_ref.path.res == Res::Def(DefKind::Trait, sized_def_id)
{
seen_sized_unbound = true;
continue;
}
// There was a `?Trait` bound, but it was not `?Sized`; warn.
self.dcx().span_warn(
unbound.span,
"relaxing a default bound only does something for `?Sized`; \
all other traits are not bound by default",
);
}

fn foo() -> impl ?Send {}
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
 --> src/lib.rs:1:18
  |
1 | fn foo() -> impl ?Send {}
  |                  ^^^^^

This should either be a (future-compat) lint or a hard-error.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 21, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Jan 21, 2025

this warning exists since pre 1.0 🤔

@fmease fmease added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Jan 21, 2025
@jieyouxu jieyouxu added C-bug Category: This is a bug. C-discussion Category: Discussion or questions that doesn't represent real issues. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. C-discussion Category: Discussion or questions that doesn't represent real issues. labels Jan 23, 2025
@theemathas
Copy link
Contributor

This code compiles. Is it supposed to?

trait Generic<T> {}
trait Huh {
    type Assoc;
}
pub fn f<T: ?Generic<<T as Huh>::Assoc>>() {}

@theemathas
Copy link
Contributor

Clearly this isn't supposed to compile, right?

trait Generic<const N: usize> {}

pub fn f<T: ?Generic<{ panic!() }>>() {}

@lcnr
Copy link
Contributor Author

lcnr commented Jan 30, 2025

This code compiles. Is it supposed to?

Clearly this isn't supposed to compile, right?

I don't think they should, which is why I opened this issue. We should move all of these to a hard error

jhpratt added a commit to jhpratt/rust that referenced this issue Feb 13, 2025
…ler-errors

Reject `?Trait` bounds in various places where we unconditionally warned since 1.0

fixes rust-lang#135730
fixes rust-lang#135809

Also a breaking change, so let's see what crater says.

This has been an unconditional warning since *before* 1.0
@bors bors closed this as completed in 6b9b0a0 Feb 13, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 13, 2025
Rollup merge of rust-lang#135841 - oli-obk:push-qxlnokwrkkym, r=compiler-errors

Reject `?Trait` bounds in various places where we unconditionally warned since 1.0

fixes rust-lang#135730
fixes rust-lang#135809

Also a breaking change, so let's see what crater says.

This has been an unconditional warning since *before* 1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants