Skip to content

Commit d767ee1

Browse files
committedAug 15, 2018
Auto merge of #53400 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 8 pull requests Successful merges: - #52453 (improve diagnostics for tests with custom return values) - #53271 (use ? to simplify `TransitiveRelation.maybe_map`) - #53279 (Extend documentation of `rustc_on_unimplemented`) - #53342 (fix error for unsized packed struct field) - #53344 (Add doc examples for std::alloc::{alloc,alloc_zeroed}.) - #53368 (Ignore test that fails on stage1) - #53388 (Fix links' color) - #53396 (Fix since of Iterator::flatten to be a proper semver) Failed merges: r? @ghost
2 parents d679b57 + b9a51ce commit d767ee1

File tree

17 files changed

+205
-57
lines changed

17 files changed

+205
-57
lines changed
 

‎src/Cargo.lock

+10-4
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,11 @@ name = "mac"
12261226
version = "0.1.1"
12271227
source = "registry+https://github.com/rust-lang/crates.io-index"
12281228

1229+
[[package]]
1230+
name = "macro-utils"
1231+
version = "0.1.2"
1232+
source = "registry+https://github.com/rust-lang/crates.io-index"
1233+
12291234
[[package]]
12301235
name = "maplit"
12311236
version = "1.0.1"
@@ -1303,10 +1308,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
13031308

13041309
[[package]]
13051310
name = "minifier"
1306-
version = "0.0.14"
1311+
version = "0.0.19"
13071312
source = "registry+https://github.com/rust-lang/crates.io-index"
13081313
dependencies = [
1309-
"regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
1314+
"macro-utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
13101315
]
13111316

13121317
[[package]]
@@ -2451,7 +2456,7 @@ dependencies = [
24512456
name = "rustdoc"
24522457
version = "0.0.0"
24532458
dependencies = [
2454-
"minifier 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
2459+
"minifier 0.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
24552460
"pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
24562461
"tempfile 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
24572462
]
@@ -3218,14 +3223,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
32183223
"checksum log_settings 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19af41f0565d7c19b2058153ad0b42d4d5ce89ec4dbf06ed6741114a8b63e7cd"
32193224
"checksum lzma-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d1eaa027402541975218bb0eec67d6b0412f6233af96e0d096d31dbdfd22e614"
32203225
"checksum mac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
3226+
"checksum macro-utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2c4deaccc2ead6a28c16c0ba82f07d52b6475397415ce40876e559b0b0ea510"
32213227
"checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43"
32223228
"checksum markup5ever 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfedc97d5a503e96816d10fedcd5b42f760b2e525ce2f7ec71f6a41780548475"
32233229
"checksum matches 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "835511bab37c34c47da5cb44844bea2cfde0236db0b506f90ea4224482c9774a"
32243230
"checksum mdbook 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "90b5a8d7e341ceee5db3882a06078d42661ddcfa2b3687319cc5da76ec4e782f"
32253231
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
32263232
"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff"
32273233
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
3228-
"checksum minifier 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "78cb57f9a385530d60f2d67f6e108050b478b7a0ffd0bb9c350803e1356535dd"
3234+
"checksum minifier 0.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "9908ed7c62f990c21ab41fdca53a864a3ada0da69d8729c4de727b397e27bc11"
32293235
"checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4"
32303236
"checksum miow 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9224c91f82b3c47cf53dcf78dfaa20d6888fbcc5d272d5f2fcdf8a697f3c987d"
32313237
"checksum new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0cdc457076c78ab54d5e0d6fa7c47981757f1e34dc39ff92787f217dede586c4"

‎src/doc/unstable-book/src/language-features/on-unimplemented.md

+95-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ The tracking issue for this feature is: [#29628]
88

99
The `on_unimplemented` feature provides the `#[rustc_on_unimplemented]`
1010
attribute, which allows trait definitions to add specialized notes to error
11-
messages when an implementation was expected but not found.
11+
messages when an implementation was expected but not found. You can refer
12+
to the trait's generic arguments by name and to the resolved type using
13+
`Self`.
1214

1315
For example:
1416

@@ -41,7 +43,98 @@ error[E0277]: the trait bound `&[{integer}]: MyIterator<char>` is not satisfied
4143
|
4244
= help: the trait `MyIterator<char>` is not implemented for `&[{integer}]`
4345
= note: required by `iterate_chars`
46+
```
47+
48+
`on_unimplemented` also supports advanced filtering for better targeting
49+
of messages, as well as modifying specific parts of the error message. You
50+
target the text of:
51+
52+
- the main error message (`message`)
53+
- the label (`label`)
54+
- an extra note (`note`)
55+
56+
For example, the following attribute
57+
58+
```rust,compile_fail
59+
#[rustc_on_unimplemented(
60+
message="message",
61+
label="label",
62+
note="note"
63+
)]
64+
trait MyIterator<A> {
65+
fn next(&mut self) -> A;
66+
}
67+
```
68+
69+
Would generate the following output:
70+
71+
```text
72+
error[E0277]: message
73+
--> <anon>:14:5
74+
|
75+
14 | iterate_chars(&[1, 2, 3][..]);
76+
| ^^^^^^^^^^^^^ label
77+
|
78+
= note: note
79+
= help: the trait `MyIterator<char>` is not implemented for `&[{integer}]`
80+
= note: required by `iterate_chars`
81+
```
82+
83+
To allow more targeted error messages, it is possible to filter the
84+
application of these fields based on a variety of attributes when using
85+
`on`:
4486

45-
error: aborting due to previous error
87+
- `crate_local`: whether the code causing the trait bound to not be
88+
fulfilled is part of the user's crate. This is used to avoid suggesting
89+
code changes that would require modifying a dependency.
90+
- Any of the generic arguments that can be substituted in the text can be
91+
referred by name as well for filtering, like `Rhs="i32"`, except for
92+
`Self`.
93+
- `_Self`: to filter only on a particular calculated trait resolution, like
94+
`Self="std::iter::Iterator<char>"`. This is needed because `Self` is a
95+
keyword which cannot appear in attributes.
96+
- `direct`: user-specified rather than derived obligation.
97+
- `from_method`: usable both as boolean (whether the flag is present, like
98+
`crate_local`) or matching against a particular method. Currently used
99+
for `try`.
100+
- `from_desugaring`: usable both as boolean (whether the flag is present)
101+
or matching against a particular desugaring.
102+
103+
For example, the `Iterator` trait can be annotated in the following way:
104+
105+
```rust,compile_fail
106+
#[rustc_on_unimplemented(
107+
on(
108+
_Self="&str",
109+
note="call `.chars()` or `.as_bytes()` on `{Self}"
110+
),
111+
message="`{Self}` is not an iterator",
112+
label="`{Self}` is not an iterator",
113+
note="maybe try calling `.iter()` or a similar method"
114+
)]
115+
pub trait Iterator {}
46116
```
47117

118+
Which would produce the following outputs:
119+
120+
```text
121+
error[E0277]: `Foo` is not an iterator
122+
--> src/main.rs:4:16
123+
|
124+
4 | for foo in Foo {}
125+
| ^^^ `Foo` is not an iterator
126+
|
127+
= note: maybe try calling `.iter()` or a similar method
128+
= help: the trait `std::iter::Iterator` is not implemented for `Foo`
129+
= note: required by `std::iter::IntoIterator::into_iter`
130+
131+
error[E0277]: `&str` is not an iterator
132+
--> src/main.rs:5:16
133+
|
134+
5 | for foo in "" {}
135+
| ^^ `&str` is not an iterator
136+
|
137+
= note: call `.chars()` or `.bytes() on `&str`
138+
= help: the trait `std::iter::Iterator` is not implemented for `&str`
139+
= note: required by `std::iter::IntoIterator::into_iter`
140+
```

‎src/liballoc/alloc.rs

+31
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ pub struct Global;
5656
/// # Safety
5757
///
5858
/// See [`GlobalAlloc::alloc`].
59+
///
60+
/// # Examples
61+
///
62+
/// ```
63+
/// use std::alloc::{alloc, dealloc, Layout};
64+
///
65+
/// unsafe {
66+
/// let layout = Layout::new::<u16>();
67+
/// let ptr = alloc(layout);
68+
///
69+
/// *(ptr as *mut u16) = 42;
70+
/// assert_eq!(*(ptr as *mut u16), 42);
71+
///
72+
/// dealloc(ptr, layout);
73+
/// }
74+
/// ```
5975
#[stable(feature = "global_alloc", since = "1.28.0")]
6076
#[inline]
6177
pub unsafe fn alloc(layout: Layout) -> *mut u8 {
@@ -110,6 +126,21 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
110126
/// # Safety
111127
///
112128
/// See [`GlobalAlloc::alloc_zeroed`].
129+
///
130+
/// # Examples
131+
///
132+
/// ```
133+
/// use std::alloc::{alloc_zeroed, dealloc, Layout};
134+
///
135+
/// unsafe {
136+
/// let layout = Layout::new::<u16>();
137+
/// let ptr = alloc_zeroed(layout);
138+
///
139+
/// assert_eq!(*(ptr as *mut u16), 0);
140+
///
141+
/// dealloc(ptr, layout);
142+
/// }
143+
/// ```
113144
#[stable(feature = "global_alloc", since = "1.28.0")]
114145
#[inline]
115146
pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {

‎src/libcore/iter/iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ pub trait Iterator {
11101110
///
11111111
/// [`flat_map()`]: #method.flat_map
11121112
#[inline]
1113-
#[stable(feature = "iterator_flatten", since = "1.29")]
1113+
#[stable(feature = "iterator_flatten", since = "1.29.0")]
11141114
fn flatten(self) -> Flatten<Self>
11151115
where Self: Sized, Self::Item: IntoIterator {
11161116
Flatten { inner: flatten_compat(self) }

‎src/libcore/iter/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2577,13 +2577,13 @@ impl<I, U, F> FusedIterator for FlatMap<I, U, F>
25772577
/// [`flatten`]: trait.Iterator.html#method.flatten
25782578
/// [`Iterator`]: trait.Iterator.html
25792579
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
2580-
#[stable(feature = "iterator_flatten", since = "1.29")]
2580+
#[stable(feature = "iterator_flatten", since = "1.29.0")]
25812581
pub struct Flatten<I: Iterator>
25822582
where I::Item: IntoIterator {
25832583
inner: FlattenCompat<I, <I::Item as IntoIterator>::IntoIter>,
25842584
}
25852585

2586-
#[stable(feature = "iterator_flatten", since = "1.29")]
2586+
#[stable(feature = "iterator_flatten", since = "1.29.0")]
25872587
impl<I, U> fmt::Debug for Flatten<I>
25882588
where I: Iterator + fmt::Debug, U: Iterator + fmt::Debug,
25892589
I::Item: IntoIterator<IntoIter = U, Item = U::Item>,
@@ -2593,15 +2593,15 @@ impl<I, U> fmt::Debug for Flatten<I>
25932593
}
25942594
}
25952595

2596-
#[stable(feature = "iterator_flatten", since = "1.29")]
2596+
#[stable(feature = "iterator_flatten", since = "1.29.0")]
25972597
impl<I, U> Clone for Flatten<I>
25982598
where I: Iterator + Clone, U: Iterator + Clone,
25992599
I::Item: IntoIterator<IntoIter = U, Item = U::Item>,
26002600
{
26012601
fn clone(&self) -> Self { Flatten { inner: self.inner.clone() } }
26022602
}
26032603

2604-
#[stable(feature = "iterator_flatten", since = "1.29")]
2604+
#[stable(feature = "iterator_flatten", since = "1.29.0")]
26052605
impl<I, U> Iterator for Flatten<I>
26062606
where I: Iterator, U: Iterator,
26072607
I::Item: IntoIterator<IntoIter = U, Item = U::Item>
@@ -2629,7 +2629,7 @@ impl<I, U> Iterator for Flatten<I>
26292629
}
26302630
}
26312631

2632-
#[stable(feature = "iterator_flatten", since = "1.29")]
2632+
#[stable(feature = "iterator_flatten", since = "1.29.0")]
26332633
impl<I, U> DoubleEndedIterator for Flatten<I>
26342634
where I: DoubleEndedIterator, U: DoubleEndedIterator,
26352635
I::Item: IntoIterator<IntoIter = U, Item = U::Item>
@@ -2652,7 +2652,7 @@ impl<I, U> DoubleEndedIterator for Flatten<I>
26522652
}
26532653
}
26542654

2655-
#[stable(feature = "iterator_flatten", since = "1.29")]
2655+
#[stable(feature = "iterator_flatten", since = "1.29.0")]
26562656
impl<I, U> FusedIterator for Flatten<I>
26572657
where I: FusedIterator, U: Iterator,
26582658
I::Item: IntoIterator<IntoIter = U, Item = U::Item> {}

‎src/librustc/traits/error_reporting.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1472,11 +1472,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14721472
ObligationCauseCode::StructInitializerSized => {
14731473
err.note("structs must have a statically known size to be initialized");
14741474
}
1475-
ObligationCauseCode::FieldSized(ref item) => {
1475+
ObligationCauseCode::FieldSized { adt_kind: ref item, last } => {
14761476
match *item {
14771477
AdtKind::Struct => {
1478-
err.note("only the last field of a struct may have a dynamically \
1479-
sized type");
1478+
if last {
1479+
err.note("the last field of a packed struct may only have a \
1480+
dynamically sized type if it does not need drop to be run");
1481+
} else {
1482+
err.note("only the last field of a struct may have a dynamically \
1483+
sized type");
1484+
}
14801485
}
14811486
AdtKind::Union => {
14821487
err.note("no field of a union may have a dynamically sized type");

‎src/librustc/traits/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ pub enum ObligationCauseCode<'tcx> {
192192
/// [T,..n] --> T must be Copy
193193
RepeatVec,
194194

195-
/// Types of fields (other than the last) in a struct must be sized.
196-
FieldSized(AdtKind),
195+
/// Types of fields (other than the last, except for packed structs) in a struct must be sized.
196+
FieldSized { adt_kind: AdtKind, last: bool },
197197

198198
/// Constant expressions must be sized.
199199
ConstSized,

‎src/librustc/traits/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
206206
super::SizedReturnType => Some(super::SizedReturnType),
207207
super::SizedYieldType => Some(super::SizedYieldType),
208208
super::RepeatVec => Some(super::RepeatVec),
209-
super::FieldSized(item) => Some(super::FieldSized(item)),
209+
super::FieldSized { adt_kind, last } => Some(super::FieldSized { adt_kind, last }),
210210
super::ConstSized => Some(super::ConstSized),
211211
super::SharedStatic => Some(super::SharedStatic),
212212
super::BuiltinDerivedObligation(ref cause) => {

‎src/librustc_data_structures/transitive_relation.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,7 @@ impl<T: Clone + Debug + Eq + Hash> TransitiveRelation<T> {
9797
{
9898
let mut result = TransitiveRelation::new();
9999
for edge in &self.edges {
100-
f(&self.elements[edge.source.0]).and_then(|source| {
101-
f(&self.elements[edge.target.0]).and_then(|target| {
102-
result.add(source, target);
103-
Some(())
104-
})
105-
})?;
100+
result.add(f(&self.elements[edge.source.0])?, f(&self.elements[edge.target.0])?);
106101
}
107102
Some(result)
108103
}

‎src/librustc_typeck/check/wfcheck.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -258,25 +258,35 @@ fn check_type_defn<'a, 'tcx, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
258258
ty.needs_drop(fcx_tcx, fcx_tcx.param_env(def_id))
259259
}
260260
};
261-
let unsized_len = if
261+
let all_sized =
262262
all_sized ||
263263
variant.fields.is_empty() ||
264-
needs_drop_copy()
265-
{
264+
needs_drop_copy();
265+
let unsized_len = if all_sized {
266266
0
267267
} else {
268268
1
269269
};
270-
for field in &variant.fields[..variant.fields.len() - unsized_len] {
270+
for (idx, field) in variant.fields[..variant.fields.len() - unsized_len]
271+
.iter()
272+
.enumerate()
273+
{
274+
let last = idx == variant.fields.len() - 1;
271275
fcx.register_bound(
272276
field.ty,
273277
fcx.tcx.require_lang_item(lang_items::SizedTraitLangItem),
274-
traits::ObligationCause::new(field.span,
275-
fcx.body_id,
276-
traits::FieldSized(match item.node.adt_kind() {
277-
Some(i) => i,
278-
None => bug!(),
279-
})));
278+
traits::ObligationCause::new(
279+
field.span,
280+
fcx.body_id,
281+
traits::FieldSized {
282+
adt_kind: match item.node.adt_kind() {
283+
Some(i) => i,
284+
None => bug!(),
285+
},
286+
last
287+
}
288+
)
289+
);
280290
}
281291

282292
// All field types must be well-formed.

‎src/librustdoc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ path = "lib.rs"
99

1010
[dependencies]
1111
pulldown-cmark = { version = "0.1.2", default-features = false }
12-
minifier = "0.0.14"
12+
minifier = "0.0.19"
1313
tempfile = "3"

‎src/librustdoc/html/static/themes/dark.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ a {
165165
color: #ddd;
166166
}
167167

168-
.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow), .docblock-short
169-
a:not(.srclink):not(.test-arrow), .stability a {
168+
.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow),
169+
.docblock-short a:not(.srclink):not(.test-arrow), .stability a {
170170
color: #D2991D;
171171
}
172172

‎src/librustdoc/html/static/themes/light.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ a {
165165
color: #000;
166166
}
167167

168-
.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow), .docblock-short
169-
a:not(.srclink):not(.test-arrow), .stability a {
168+
.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow),
169+
.docblock-short a:not(.srclink):not(.test-arrow), .stability a {
170170
color: #3873AD;
171171
}
172172

0 commit comments

Comments
 (0)
Please sign in to comment.