File tree 4 files changed +67
-0
lines changed
compiler/rustc_trait_selection/src/solve
tests/ui/diagnostic_namespace/do_not_recommend
4 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ use rustc_infer::traits::{
11
11
} ;
12
12
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
13
13
use rustc_middle:: ty:: { self , TyCtxt } ;
14
+ use rustc_span:: symbol:: sym;
14
15
15
16
use super :: eval_ctxt:: GenerateProofTree ;
16
17
use super :: inspect:: { ProofTreeInferCtxtExt , ProofTreeVisitor } ;
@@ -320,6 +321,14 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
320
321
return ControlFlow :: Break ( self . obligation . clone ( ) ) ;
321
322
} ;
322
323
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
+
323
332
// FIXME: Could we extract a trait ref from a projection here too?
324
333
// FIXME: Also, what about considering >1 layer up the stack? May be necessary
325
334
// for normalizes-to.
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments