Skip to content

Commit 4845d98

Browse files
authored
Unrolled build for rust-lang#130311
Rollup merge of rust-lang#130311 - heiseish:issue-70849-fix, r=fmease (fix) conflicting negative impl marker ## Context This MR fixes the error message for conflicting negative trait impls by adding the corresponding the polarity marker to the trait name. ## Issues - closes rust-lang#70849 r​? `@fmease`
2 parents f9567d0 + b0db3a7 commit 4845d98

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Opti
344344

345345
write!(
346346
w,
347-
" {} for {}",
347+
" {}{} for {}",
348+
tcx.impl_polarity(impl_def_id).as_str(),
348349
trait_ref.print_only_trait_path(),
349350
tcx.type_of(impl_def_id).instantiate_identity()
350351
)

compiler/rustc_type_ir/src/predicate.rs

+11
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ impl fmt::Display for ImplPolarity {
196196
}
197197
}
198198

199+
impl ImplPolarity {
200+
/// The polarity marker in front of the impl trait ref if applicable.
201+
pub fn as_str(self) -> &'static str {
202+
match self {
203+
Self::Positive => "",
204+
Self::Negative => "!",
205+
Self::Reservation => "",
206+
}
207+
}
208+
}
209+
199210
/// Polarity for a trait predicate. May either be negative or positive.
200211
/// Distinguished from [`ImplPolarity`] since we never compute goals with
201212
/// "reservation" level.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(negative_impls)]
2+
//@ edition: 2021
3+
// Test to ensure we are printing the polarity of the impl trait ref
4+
// when printing out conflicting trait impls
5+
6+
struct MyType;
7+
8+
impl !Clone for &mut MyType {}
9+
//~^ ERROR conflicting implementations of trait `Clone` for type `&mut MyType`
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0119]: conflicting implementations of trait `Clone` for type `&mut MyType`
2+
--> $DIR/coherence-conflicting-repeated-negative-trait-impl-70849.rs:8:1
3+
|
4+
LL | impl !Clone for &mut MyType {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: conflicting implementation in crate `core`:
8+
- impl<T> !Clone for &mut T
9+
where T: ?Sized;
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)