Skip to content

Commit 05a8060

Browse files
Make rustdoc tests use always applicable negative auto impls
1 parent 3d62b27 commit 05a8060

8 files changed

+102
-62
lines changed

Diff for: compiler/rustc_hir_analysis/src/check/always_applicable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn ensure_impl_params_and_item_params_correspond<'tcx>(
140140
return Ok(());
141141
};
142142

143-
let drop_impl_span = tcx.def_span(impl_def_id);
143+
let impl_span = tcx.def_span(impl_def_id);
144144
let item_span = tcx.def_span(adt_def_id);
145145
let self_descr = tcx.def_descr(adt_def_id);
146146
let polarity = match tcx.impl_polarity(impl_def_id) {
@@ -151,7 +151,7 @@ fn ensure_impl_params_and_item_params_correspond<'tcx>(
151151
.item_name(tcx.trait_id_of_impl(impl_def_id.to_def_id()).expect("expected impl of trait"));
152152
let mut err = struct_span_code_err!(
153153
tcx.dcx(),
154-
drop_impl_span,
154+
impl_span,
155155
E0366,
156156
"`{polarity}{trait_name}` impls cannot be specialized",
157157
);

Diff for: tests/rustdoc/impl-parts-crosscrate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
extern crate rustdoc_impl_parts_crosscrate;
77

8-
pub struct Bar<T> { t: T }
8+
pub struct Bar<T: Copy + Send> { t: T }
99

1010
// The output file is html embedded in javascript, so the html tags
1111
// aren't stripped by the processing script and we can't check for the

Diff for: tests/rustdoc/impl-parts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
pub auto trait AnAutoTrait {}
55

6-
pub struct Foo<T> { field: T }
6+
pub struct Foo<T: Clone + Sync> { field: T }
77

88
//@ has impl_parts/struct.Foo.html '//*[@class="impl"]//h3[@class="code-header"]' \
99
// "impl<T> !AnAutoTrait for Foo<T>where T: Sync + Clone,"

Diff for: tests/ui/coherence/coherence-overlap-negative-impls.rs

-42
This file was deleted.

Diff for: tests/ui/coherence/coherence-overlap-negative-impls.stderr

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![feature(auto_traits, negative_impls)]
2+
3+
auto trait Foo {}
4+
5+
struct AdditionalLt<'a, T>(&'a (), T);
6+
impl<'a, T: 'a> !Foo for AdditionalLt<'a, T> {}
7+
//~^ ERROR `!Foo` impl requires `T: 'a` but the struct it is implemented for does not
8+
9+
struct AdditionalBound<T>(T);
10+
trait Bound {}
11+
impl<T: Bound> !Foo for AdditionalBound<T> {}
12+
//~^ ERROR `!Foo` impl requires `T: Bound` but the struct it is implemented for does not
13+
14+
struct TwoParam<T, U>(T, U);
15+
impl<T> !Foo for TwoParam<T, T> {}
16+
//~^ ERROR `!Foo` impls cannot be specialized
17+
18+
struct ConcreteParam<T>(T);
19+
impl !Foo for ConcreteParam<i32> {}
20+
//~^ ERROR `!Foo` impls cannot be specialized
21+
22+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error[E0367]: `!Foo` impl requires `T: 'a` but the struct it is implemented for does not
2+
--> $DIR/negated-auto-traits-validity-error.rs:6:13
3+
|
4+
LL | impl<'a, T: 'a> !Foo for AdditionalLt<'a, T> {}
5+
| ^^
6+
|
7+
note: the implementor must specify the same requirement
8+
--> $DIR/negated-auto-traits-validity-error.rs:5:1
9+
|
10+
LL | struct AdditionalLt<'a, T>(&'a (), T);
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error[E0367]: `!Foo` impl requires `T: Bound` but the struct it is implemented for does not
14+
--> $DIR/negated-auto-traits-validity-error.rs:11:9
15+
|
16+
LL | impl<T: Bound> !Foo for AdditionalBound<T> {}
17+
| ^^^^^
18+
|
19+
note: the implementor must specify the same requirement
20+
--> $DIR/negated-auto-traits-validity-error.rs:9:1
21+
|
22+
LL | struct AdditionalBound<T>(T);
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error[E0366]: `!Foo` impls cannot be specialized
26+
--> $DIR/negated-auto-traits-validity-error.rs:15:1
27+
|
28+
LL | impl<T> !Foo for TwoParam<T, T> {}
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
|
31+
= note: `T` is mentioned multiple times
32+
note: use the same sequence of generic lifetime, type and const parameters as the struct definition
33+
--> $DIR/negated-auto-traits-validity-error.rs:14:1
34+
|
35+
LL | struct TwoParam<T, U>(T, U);
36+
| ^^^^^^^^^^^^^^^^^^^^^
37+
38+
error[E0366]: `!Foo` impls cannot be specialized
39+
--> $DIR/negated-auto-traits-validity-error.rs:19:1
40+
|
41+
LL | impl !Foo for ConcreteParam<i32> {}
42+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
43+
|
44+
= note: `i32` is not a generic parameter
45+
note: use the same sequence of generic lifetime, type and const parameters as the struct definition
46+
--> $DIR/negated-auto-traits-validity-error.rs:18:1
47+
|
48+
LL | struct ConcreteParam<T>(T);
49+
| ^^^^^^^^^^^^^^^^^^^^^^^
50+
51+
error: aborting due to 4 previous errors
52+
53+
Some errors have detailed explanations: E0366, E0367.
54+
For more information about an error, try `rustc --explain E0366`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ check-pass
2+
3+
#![feature(auto_traits, negative_impls)]
4+
5+
auto trait Foo {}
6+
auto trait Bar {}
7+
8+
struct NeedsOutlives<'a, T>(&'a T);
9+
10+
impl<'a, T: 'a> !Foo for NeedsOutlives<'a, T> {}
11+
12+
// Leaving out the lifetime bound
13+
impl<'a, T> !Bar for NeedsOutlives<'a, T> {}
14+
15+
struct NeedsSend<T: Send>(T);
16+
17+
impl<T: Send> !Foo for NeedsSend<T> {}
18+
19+
// Leaving off the trait bound
20+
impl<T> !Bar for NeedsSend<T> {}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)