Skip to content

Commit abaeb2a

Browse files
authored
Unrolled build for rust-lang#124717
Rollup merge of rust-lang#124717 - compiler-errors:do-not-recomment-next-solver, r=lcnr Implement `do_not_recommend` in the new solver Put the test into `diagnostic_namespace` test folder even though it's not in the diagnostic namespace, because it should be soon. r? lcnr cc `@weiznich`
2 parents d568423 + b335994 commit abaeb2a

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
518518
// RFC 2397
519519
gated!(
520520
do_not_recommend, Normal, template!(Word), WarnFollowing,
521-
EncodeCrossCrate::No, experimental!(do_not_recommend)
521+
EncodeCrossCrate::Yes, experimental!(do_not_recommend)
522522
),
523523

524524
// `#[cfi_encoding = ""]`

compiler/rustc_trait_selection/src/solve/fulfill.rs

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_infer::traits::{
1111
};
1212
use rustc_middle::ty::error::{ExpectedFound, TypeError};
1313
use rustc_middle::ty::{self, TyCtxt};
14+
use rustc_span::symbol::sym;
1415

1516
use super::eval_ctxt::GenerateProofTree;
1617
use super::inspect::{ProofTreeInferCtxtExt, ProofTreeVisitor};
@@ -320,6 +321,14 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
320321
return ControlFlow::Break(self.obligation.clone());
321322
};
322323

324+
// Don't walk into impls that have `do_not_recommend`.
325+
if let ProbeKind::TraitCandidate { source: CandidateSource::Impl(impl_def_id), result: _ } =
326+
candidate.kind()
327+
&& goal.infcx().tcx.has_attr(impl_def_id, sym::do_not_recommend)
328+
{
329+
return ControlFlow::Break(self.obligation.clone());
330+
}
331+
323332
// FIXME: Could we extract a trait ref from a projection here too?
324333
// FIXME: Also, what about considering >1 layer up the stack? May be necessary
325334
// for normalizes-to.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0277]: the trait bound `*mut (): Foo` is not satisfied
2+
--> $DIR/simple.rs:19:17
3+
|
4+
LL | needs_foo::<*mut ()>();
5+
| ^^^^^^^ the trait `Send` is not implemented for `*mut ()`, which is required by `*mut (): Foo`
6+
|
7+
note: required for `*mut ()` to implement `Foo`
8+
--> $DIR/simple.rs:10:9
9+
|
10+
LL | impl<T> Foo for T where T: Send {}
11+
| ^^^ ^ ---- unsatisfied trait bound introduced here
12+
note: required by a bound in `needs_foo`
13+
--> $DIR/simple.rs:14:17
14+
|
15+
LL | fn needs_foo<T: Foo>() {}
16+
| ^^^ required by this bound in `needs_foo`
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `*mut (): Foo` is not satisfied
2+
--> $DIR/simple.rs:19:17
3+
|
4+
LL | needs_foo::<*mut ()>();
5+
| ^^^^^^^ the trait `Foo` is not implemented for `*mut ()`
6+
|
7+
note: required by a bound in `needs_foo`
8+
--> $DIR/simple.rs:14:17
9+
|
10+
LL | fn needs_foo<T: Foo>() {}
11+
| ^^^ required by this bound in `needs_foo`
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
4+
5+
#![feature(do_not_recommend)]
6+
7+
trait Foo {}
8+
9+
#[do_not_recommend]
10+
impl<T> Foo for T where T: Send {}
11+
//[current]~^ NOTE required for `*mut ()` to implement `Foo`
12+
//[current]~| NOTE unsatisfied trait bound introduced here
13+
14+
fn needs_foo<T: Foo>() {}
15+
//~^ NOTE required by a bound in `needs_foo`
16+
//~| NOTE required by this bound in `needs_foo`
17+
18+
fn main() {
19+
needs_foo::<*mut ()>();
20+
//~^ ERROR the trait bound `*mut (): Foo` is not satisfied
21+
//[current]~| NOTE the trait `Send` is not implemented for `*mut ()`
22+
//[next]~| NOTE the trait `Foo` is not implemented for `*mut ()`
23+
}

0 commit comments

Comments
 (0)