Skip to content

Commit b802da1

Browse files
authored
Unrolled build for rust-lang#131701
Rollup merge of rust-lang#131701 - compiler-errors:negative-bounds-on-unimplemented, r=lcnr Don't report `on_unimplemented` message for negative traits Kinda useless change but it was affecting my ability to read error messages when experimenting with negative bounds.
2 parents a0c2aba + 5a8405a commit b802da1

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
960960
continue;
961961
}
962962
unimplemented_traits.entry(p.trait_ref.def_id).or_insert((
963-
predicate.kind().rebind(p.trait_ref),
963+
predicate.kind().rebind(p),
964964
Obligation {
965965
cause: cause.clone(),
966966
param_env: self.param_env,

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
202202
notes,
203203
parent_label,
204204
append_const_msg,
205-
} = self.on_unimplemented_note(main_trait_ref, o, &mut long_ty_file);
205+
} = self.on_unimplemented_note(main_trait_predicate, o, &mut long_ty_file);
206206

207207
let have_alt_message = message.is_some() || label.is_some();
208208
let is_try_conversion = self.is_try_conversion(span, main_trait_ref.def_id());

compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_macros::LintDiagnostic;
1010
use rustc_middle::bug;
1111
use rustc_middle::ty::print::PrintTraitRefExt as _;
12-
use rustc_middle::ty::{self, GenericArgsRef, GenericParamDefKind, TyCtxt};
12+
use rustc_middle::ty::{self, GenericArgsRef, GenericParamDefKind, ToPolyTraitRef, TyCtxt};
1313
use rustc_parse_format::{ParseMode, Parser, Piece, Position};
1414
use rustc_session::lint::builtin::UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES;
1515
use rustc_span::Span;
@@ -108,14 +108,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
108108

109109
pub fn on_unimplemented_note(
110110
&self,
111-
trait_ref: ty::PolyTraitRef<'tcx>,
111+
trait_pred: ty::PolyTraitPredicate<'tcx>,
112112
obligation: &PredicateObligation<'tcx>,
113113
long_ty_file: &mut Option<PathBuf>,
114114
) -> OnUnimplementedNote {
115+
if trait_pred.polarity() != ty::PredicatePolarity::Positive {
116+
return OnUnimplementedNote::default();
117+
}
118+
115119
let (def_id, args) = self
116-
.impl_similar_to(trait_ref, obligation)
117-
.unwrap_or_else(|| (trait_ref.def_id(), trait_ref.skip_binder().args));
118-
let trait_ref = trait_ref.skip_binder();
120+
.impl_similar_to(trait_pred.to_poly_trait_ref(), obligation)
121+
.unwrap_or_else(|| (trait_pred.def_id(), trait_pred.skip_binder().trait_ref.args));
122+
let trait_pred = trait_pred.skip_binder();
119123

120124
let mut flags = vec![];
121125
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): HIR is not present for RPITITs,
@@ -144,13 +148,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
144148
flags.push((sym::cause, Some("MainFunctionType".to_string())));
145149
}
146150

147-
flags.push((sym::Trait, Some(trait_ref.print_trait_sugared().to_string())));
151+
flags.push((sym::Trait, Some(trait_pred.trait_ref.print_trait_sugared().to_string())));
148152

149153
// Add all types without trimmed paths or visible paths, ensuring they end up with
150154
// their "canonical" def path.
151155
ty::print::with_no_trimmed_paths!(ty::print::with_no_visible_paths!({
152156
let generics = self.tcx.generics_of(def_id);
153-
let self_ty = trait_ref.self_ty();
157+
let self_ty = trait_pred.self_ty();
154158
// This is also included through the generics list as `Self`,
155159
// but the parser won't allow you to use it
156160
flags.push((sym::_Self, Some(self_ty.to_string())));
@@ -266,7 +270,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
266270
}));
267271

268272
if let Ok(Some(command)) = OnUnimplementedDirective::of_item(self.tcx, def_id) {
269-
command.evaluate(self.tcx, trait_ref, &flags, long_ty_file)
273+
command.evaluate(self.tcx, trait_pred.trait_ref, &flags, long_ty_file)
270274
} else {
271275
OnUnimplementedNote::default()
272276
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(negative_bounds)]
2+
3+
#[diagnostic::on_unimplemented(message = "this ain't fooing")]
4+
trait Foo {}
5+
struct NotFoo;
6+
7+
fn hello() -> impl !Foo {
8+
//~^ ERROR the trait bound `NotFoo: !Foo` is not satisfied
9+
NotFoo
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0277]: the trait bound `NotFoo: !Foo` is not satisfied
2+
--> $DIR/on-unimplemented.rs:7:15
3+
|
4+
LL | fn hello() -> impl !Foo {
5+
| ^^^^^^^^^ the trait bound `NotFoo: !Foo` is not satisfied
6+
LL |
7+
LL | NotFoo
8+
| ------ return type was inferred to be `NotFoo` here
9+
|
10+
help: this trait has no implementations, consider adding one
11+
--> $DIR/on-unimplemented.rs:4:1
12+
|
13+
LL | trait Foo {}
14+
| ^^^^^^^^^
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)