Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 17841cc

Browse files
committedApr 30, 2018
Auto merge of #50345 - kennytm:rollup, r=kennytm
Rollup of 7 pull requests Successful merges: - #50233 (Make `Vec::new` a `const fn`) - #50312 (Add more links in panic docs) - #50316 (Fix some broken links in docs.) - #50325 (Add a few more tests for proc macro feature gating) - #50327 (Display correct unused field suggestion for nested struct patterns) - #50330 (check that #[used] is used only on statics) - #50344 (Update Cargo to 2018-04-28 122fd5be5201913d42e219e132d6569493583bca) Failed merges:
2 parents 4745092 + 6166f20 commit 17841cc

File tree

18 files changed

+277
-57
lines changed

18 files changed

+277
-57
lines changed
 

‎src/liballoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
#![feature(pointer_methods)]
125125
#![feature(inclusive_range_fields)]
126126
#![cfg_attr(stage0, feature(generic_param_attrs))]
127+
#![feature(rustc_const_unstable)]
127128

128129
#![cfg_attr(not(test), feature(fn_traits, i128))]
129130
#![cfg_attr(test, feature(test))]

‎src/liballoc/raw_vec.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@ pub struct RawVec<T, A: Alloc = Global> {
5656
impl<T, A: Alloc> RawVec<T, A> {
5757
/// Like `new` but parameterized over the choice of allocator for
5858
/// the returned RawVec.
59-
pub fn new_in(a: A) -> Self {
59+
pub const fn new_in(a: A) -> Self {
6060
// !0 is usize::MAX. This branch should be stripped at compile time.
61-
let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
61+
// FIXME(mark-i-m): use this line when `if`s are allowed in `const`
62+
//let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
6263

6364
// Unique::empty() doubles as "unallocated" and "zero-sized allocation"
6465
RawVec {
6566
ptr: Unique::empty(),
66-
cap,
67+
// FIXME(mark-i-m): use `cap` when ifs are allowed in const
68+
cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
6769
a,
6870
}
6971
}
@@ -120,7 +122,7 @@ impl<T> RawVec<T, Global> {
120122
/// RawVec with capacity 0. If T has 0 size, then it makes a
121123
/// RawVec with capacity `usize::MAX`. Useful for implementing
122124
/// delayed allocation.
123-
pub fn new() -> Self {
125+
pub const fn new() -> Self {
124126
Self::new_in(Global)
125127
}
126128

‎src/liballoc/vec.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ impl<T> Vec<T> {
322322
/// ```
323323
#[inline]
324324
#[stable(feature = "rust1", since = "1.0.0")]
325-
pub fn new() -> Vec<T> {
325+
#[rustc_const_unstable(feature = "const_vec_new")]
326+
pub const fn new() -> Vec<T> {
326327
Vec {
327328
buf: RawVec::new(),
328329
len: 0,

‎src/libcore/iter/iterator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,8 @@ pub trait Iterator {
10941094
/// `flatten()` a three-dimensional array the result will be
10951095
/// two-dimensional and not one-dimensional. To get a one-dimensional
10961096
/// structure, you have to `flatten()` again.
1097+
///
1098+
/// [`flat_map()`]: #method.flat_map
10971099
#[inline]
10981100
#[unstable(feature = "iterator_flatten", issue = "48213")]
10991101
fn flatten(self) -> Flatten<Self>

‎src/libcore/marker.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,8 @@ unsafe impl<'a, T: ?Sized> Freeze for &'a mut T {}
602602
/// `Pin` pointer.
603603
///
604604
/// This trait is automatically implemented for almost every type.
605+
///
606+
/// [`Pin`]: ../mem/struct.Pin.html
605607
#[unstable(feature = "pin", issue = "49150")]
606608
pub unsafe auto trait Unpin {}
607609

‎src/libcore/ptr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,10 +2552,9 @@ impl<T: Sized> Unique<T> {
25522552
/// This is useful for initializing types which lazily allocate, like
25532553
/// `Vec::new` does.
25542554
// FIXME: rename to dangling() to match NonNull?
2555-
pub fn empty() -> Self {
2555+
pub const fn empty() -> Self {
25562556
unsafe {
2557-
let ptr = mem::align_of::<T>() as *mut T;
2558-
Unique::new_unchecked(ptr)
2557+
Unique::new_unchecked(mem::align_of::<T>() as *mut T)
25592558
}
25602559
}
25612560
}

‎src/librustc/hir/check_attr.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ enum Target {
3131
Expression,
3232
Statement,
3333
Closure,
34+
Static,
3435
Other,
3536
}
3637

@@ -43,6 +44,7 @@ impl Target {
4344
hir::ItemEnum(..) => Target::Enum,
4445
hir::ItemConst(..) => Target::Const,
4546
hir::ItemForeignMod(..) => Target::ForeignMod,
47+
hir::ItemStatic(..) => Target::Static,
4648
_ => Target::Other,
4749
}
4850
}
@@ -102,6 +104,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
102104
}
103105

104106
self.check_repr(item, target);
107+
self.check_used(item, target);
105108
}
106109

107110
/// Check if an `#[inline]` is applied to a function or a closure.
@@ -305,6 +308,15 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
305308
}
306309
}
307310
}
311+
312+
fn check_used(&self, item: &hir::Item, target: Target) {
313+
for attr in &item.attrs {
314+
if attr.name().map(|name| name == "used").unwrap_or(false) && target != Target::Static {
315+
self.tcx.sess
316+
.span_err(attr.span, "attribute must be applied to a `static` variable");
317+
}
318+
}
319+
}
308320
}
309321

310322
impl<'a, 'tcx> Visitor<'tcx> for CheckAttrVisitor<'a, 'tcx> {

‎src/librustc/middle/liveness.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ use ty::{self, TyCtxt};
111111
use lint;
112112
use util::nodemap::{NodeMap, NodeSet};
113113

114+
use std::collections::VecDeque;
114115
use std::{fmt, usize};
115116
use std::io::prelude::*;
116117
use std::io;
@@ -412,18 +413,43 @@ fn visit_local<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, local: &'tcx hir::Local) {
412413
}
413414

414415
fn visit_arm<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, arm: &'tcx hir::Arm) {
415-
for pat in &arm.pats {
416-
// for struct patterns, take note of which fields used shorthand (`x` rather than `x: x`)
416+
for mut pat in &arm.pats {
417+
// For struct patterns, take note of which fields used shorthand
418+
// (`x` rather than `x: x`).
417419
//
418-
// FIXME: according to the rust-lang-nursery/rustc-guide book, `NodeId`s are to be phased
419-
// out in favor of `HirId`s; however, we need to match the signature of `each_binding`,
420-
// which uses `NodeIds`.
420+
// FIXME: according to the rust-lang-nursery/rustc-guide book, `NodeId`s are to be
421+
// phased out in favor of `HirId`s; however, we need to match the signature of
422+
// `each_binding`, which uses `NodeIds`.
421423
let mut shorthand_field_ids = NodeSet();
422-
if let hir::PatKind::Struct(_, ref fields, _) = pat.node {
423-
for field in fields {
424-
if field.node.is_shorthand {
425-
shorthand_field_ids.insert(field.node.pat.id);
424+
let mut pats = VecDeque::new();
425+
pats.push_back(pat);
426+
while let Some(pat) = pats.pop_front() {
427+
use hir::PatKind::*;
428+
match pat.node {
429+
Binding(_, _, _, ref inner_pat) => {
430+
pats.extend(inner_pat.iter());
426431
}
432+
Struct(_, ref fields, _) => {
433+
for field in fields {
434+
if field.node.is_shorthand {
435+
shorthand_field_ids.insert(field.node.pat.id);
436+
}
437+
}
438+
}
439+
Ref(ref inner_pat, _) |
440+
Box(ref inner_pat) => {
441+
pats.push_back(inner_pat);
442+
}
443+
TupleStruct(_, ref inner_pats, _) |
444+
Tuple(ref inner_pats, _) => {
445+
pats.extend(inner_pats.iter());
446+
}
447+
Slice(ref pre_pats, ref inner_pat, ref post_pats) => {
448+
pats.extend(pre_pats.iter());
449+
pats.extend(inner_pat.iter());
450+
pats.extend(post_pats.iter());
451+
}
452+
_ => {}
427453
}
428454
}
429455

‎src/libstd/collections/hash/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl TaggedHashUintPtr {
7979
///
8080
/// Essential invariants of this structure:
8181
///
82-
/// - if t.hashes[i] == EMPTY_BUCKET, then `Bucket::at_index(&t, i).raw`
82+
/// - if `t.hashes[i] == EMPTY_BUCKET`, then `Bucket::at_index(&t, i).raw`
8383
/// points to 'undefined' contents. Don't read from it. This invariant is
8484
/// enforced outside this module with the `EmptyBucket`, `FullBucket`,
8585
/// and `SafeHash` types.

‎src/libstd/ffi/c_str.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,7 @@ impl CStr {
11181118
///
11191119
/// [`Cow`]: ../borrow/enum.Cow.html
11201120
/// [`Borrowed`]: ../borrow/enum.Cow.html#variant.Borrowed
1121+
/// [`Owned`]: ../borrow/enum.Cow.html#variant.Owned
11211122
/// [`str`]: ../primitive.str.html
11221123
/// [`String`]: ../string/struct.String.html
11231124
///

‎src/libstd/panic.rs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ pub use core::panic::{PanicInfo, Location};
3131
/// A marker trait which represents "panic safe" types in Rust.
3232
///
3333
/// This trait is implemented by default for many types and behaves similarly in
34-
/// terms of inference of implementation to the `Send` and `Sync` traits. The
35-
/// purpose of this trait is to encode what types are safe to cross a `catch_unwind`
34+
/// terms of inference of implementation to the [`Send`] and [`Sync`] traits. The
35+
/// purpose of this trait is to encode what types are safe to cross a [`catch_unwind`]
3636
/// boundary with no fear of unwind safety.
3737
///
38+
/// [`Send`]: ../marker/trait.Send.html
39+
/// [`Sync`]: ../marker/trait.Sync.html
40+
/// [`catch_unwind`]: ./fn.catch_unwind.html
41+
///
3842
/// ## What is unwind safety?
3943
///
4044
/// In Rust a function can "return" early if it either panics or calls a
@@ -95,12 +99,13 @@ pub use core::panic::{PanicInfo, Location};
9599
///
96100
/// ## When should `UnwindSafe` be used?
97101
///
98-
/// Is not intended that most types or functions need to worry about this trait.
99-
/// It is only used as a bound on the `catch_unwind` function and as mentioned above,
100-
/// the lack of `unsafe` means it is mostly an advisory. The `AssertUnwindSafe`
101-
/// wrapper struct in this module can be used to force this trait to be
102-
/// implemented for any closed over variables passed to the `catch_unwind` function
103-
/// (more on this below).
102+
/// It is not intended that most types or functions need to worry about this trait.
103+
/// It is only used as a bound on the `catch_unwind` function and as mentioned
104+
/// above, the lack of `unsafe` means it is mostly an advisory. The
105+
/// [`AssertUnwindSafe`] wrapper struct can be used to force this trait to be
106+
/// implemented for any closed over variables passed to `catch_unwind`.
107+
///
108+
/// [`AssertUnwindSafe`]: ./struct.AssertUnwindSafe.html
104109
#[stable(feature = "catch_unwind", since = "1.9.0")]
105110
#[rustc_on_unimplemented = "the type {Self} may not be safely transferred \
106111
across an unwind boundary"]
@@ -109,11 +114,14 @@ pub auto trait UnwindSafe {}
109114
/// A marker trait representing types where a shared reference is considered
110115
/// unwind safe.
111116
///
112-
/// This trait is namely not implemented by `UnsafeCell`, the root of all
117+
/// This trait is namely not implemented by [`UnsafeCell`], the root of all
113118
/// interior mutability.
114119
///
115120
/// This is a "helper marker trait" used to provide impl blocks for the
116-
/// `UnwindSafe` trait, for more information see that documentation.
121+
/// [`UnwindSafe`] trait, for more information see that documentation.
122+
///
123+
/// [`UnsafeCell`]: ../cell/struct.UnsafeCell.html
124+
/// [`UnwindSafe`]: ./trait.UnwindSafe.html
117125
#[stable(feature = "catch_unwind", since = "1.9.0")]
118126
#[rustc_on_unimplemented = "the type {Self} may contain interior mutability \
119127
and a reference may not be safely transferrable \
@@ -122,14 +130,15 @@ pub auto trait RefUnwindSafe {}
122130

123131
/// A simple wrapper around a type to assert that it is unwind safe.
124132
///
125-
/// When using `catch_unwind` it may be the case that some of the closed over
133+
/// When using [`catch_unwind`] it may be the case that some of the closed over
126134
/// variables are not unwind safe. For example if `&mut T` is captured the
127135
/// compiler will generate a warning indicating that it is not unwind safe. It
128136
/// may not be the case, however, that this is actually a problem due to the
129-
/// specific usage of `catch_unwind` if unwind safety is specifically taken into
137+
/// specific usage of [`catch_unwind`] if unwind safety is specifically taken into
130138
/// account. This wrapper struct is useful for a quick and lightweight
131139
/// annotation that a variable is indeed unwind safe.
132140
///
141+
/// [`catch_unwind`]: ./fn.catch_unwind.html
133142
/// # Examples
134143
///
135144
/// One way to use `AssertUnwindSafe` is to assert that the entire closure
@@ -318,18 +327,22 @@ impl<T: fmt::Debug> fmt::Debug for AssertUnwindSafe<T> {
318327
/// panic and allowing a graceful handling of the error.
319328
///
320329
/// It is **not** recommended to use this function for a general try/catch
321-
/// mechanism. The `Result` type is more appropriate to use for functions that
330+
/// mechanism. The [`Result`] type is more appropriate to use for functions that
322331
/// can fail on a regular basis. Additionally, this function is not guaranteed
323332
/// to catch all panics, see the "Notes" section below.
324333
///
325-
/// The closure provided is required to adhere to the `UnwindSafe` trait to ensure
334+
/// [`Result`]: ../result/enum.Result.html
335+
///
336+
/// The closure provided is required to adhere to the [`UnwindSafe`] trait to ensure
326337
/// that all captured variables are safe to cross this boundary. The purpose of
327338
/// this bound is to encode the concept of [exception safety][rfc] in the type
328339
/// system. Most usage of this function should not need to worry about this
329340
/// bound as programs are naturally unwind safe without `unsafe` code. If it
330-
/// becomes a problem the associated `AssertUnwindSafe` wrapper type in this
331-
/// module can be used to quickly assert that the usage here is indeed unwind
332-
/// safe.
341+
/// becomes a problem the [`AssertUnwindSafe`] wrapper struct can be used to quickly
342+
/// assert that the usage here is indeed unwind safe.
343+
///
344+
/// [`AssertUnwindSafe`]: ./struct.AssertUnwindSafe.html
345+
/// [`UnwindSafe`]: ./trait.UnwindSafe.html
333346
///
334347
/// [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1236-stabilize-catch-panic.md
335348
///
@@ -364,9 +377,11 @@ pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
364377

365378
/// Triggers a panic without invoking the panic hook.
366379
///
367-
/// This is designed to be used in conjunction with `catch_unwind` to, for
380+
/// This is designed to be used in conjunction with [`catch_unwind`] to, for
368381
/// example, carry a panic across a layer of C code.
369382
///
383+
/// [`catch_unwind`]: ./fn.catch_unwind.html
384+
///
370385
/// # Notes
371386
///
372387
/// Note that panics in Rust are not always implemented via unwinding, but they

‎src/libstd/panicking.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ static mut HOOK: Hook = Hook::Default;
7676
/// is invoked. As such, the hook will run with both the aborting and unwinding
7777
/// runtimes. The default hook prints a message to standard error and generates
7878
/// a backtrace if requested, but this behavior can be customized with the
79-
/// `set_hook` and `take_hook` functions.
79+
/// `set_hook` and [`take_hook`] functions.
80+
///
81+
/// [`take_hook`]: ./fn.take_hook.html
8082
///
8183
/// The hook is provided with a `PanicInfo` struct which contains information
8284
/// about the origin of the panic, including the payload passed to `panic!` and
@@ -121,6 +123,10 @@ pub fn set_hook(hook: Box<Fn(&PanicInfo) + 'static + Sync + Send>) {
121123

122124
/// Unregisters the current panic hook, returning it.
123125
///
126+
/// *See also the function [`set_hook`].*
127+
///
128+
/// [`set_hook`]: ./fn.set_hook.html
129+
///
124130
/// If no custom hook is registered, the default hook will be returned.
125131
///
126132
/// # Panics

‎src/test/compile-fail-fulldeps/proc-macro/proc-macro-gates.rs

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,17 @@ use foo::*;
2424
#[foo::a] //~ ERROR: paths of length greater than one
2525
fn _test() {}
2626

27+
fn _test_inner() {
28+
#![a] // OK
29+
}
30+
2731
#[a] //~ ERROR: custom attributes cannot be applied to modules
2832
mod _test2 {}
2933

34+
mod _test2_inner {
35+
#![a] //~ ERROR: custom attributes cannot be applied to modules
36+
}
37+
3038
#[a = y] //~ ERROR: must only be followed by a delimiter token
3139
fn _test3() {}
3240

@@ -36,19 +44,40 @@ fn _test4() {}
3644
#[a () = ] //~ ERROR: must only be followed by a delimiter token
3745
fn _test5() {}
3846

39-
fn main() {
47+
fn attrs() {
48+
// Statement, item
49+
#[a] // OK
50+
struct S;
51+
52+
// Statement, macro
53+
#[a] //~ ERROR: custom attributes cannot be applied to statements
54+
println!();
55+
56+
// Statement, semi
57+
#[a] //~ ERROR: custom attributes cannot be applied to statements
58+
S;
59+
60+
// Statement, local
4061
#[a] //~ ERROR: custom attributes cannot be applied to statements
4162
let _x = 2;
42-
let _x = #[a] 2;
43-
//~^ ERROR: custom attributes cannot be applied to expressions
44-
45-
let _x: m!(u32) = 3;
46-
//~^ ERROR: procedural macros cannot be expanded to types
47-
if let m!(Some(_x)) = Some(3) {
48-
//~^ ERROR: procedural macros cannot be expanded to patterns
49-
}
50-
let _x = m!(3);
51-
//~^ ERROR: procedural macros cannot be expanded to expressions
52-
m!(let _x = 3;);
53-
//~^ ERROR: procedural macros cannot be expanded to statements
63+
64+
// Expr
65+
let _x = #[a] 2; //~ ERROR: custom attributes cannot be applied to expressions
66+
67+
// Opt expr
68+
let _x = [#[a] 2]; //~ ERROR: custom attributes cannot be applied to expressions
69+
70+
// Expr macro
71+
let _x = #[a] println!(); //~ ERROR: custom attributes cannot be applied to expressions
72+
}
73+
74+
fn main() {
75+
let _x: m!(u32) = 3; //~ ERROR: procedural macros cannot be expanded to types
76+
if let m!(Some(_x)) = Some(3) {} //~ ERROR: procedural macros cannot be expanded to patterns
77+
78+
m!(struct S;); //~ ERROR: procedural macros cannot be expanded to statements
79+
m!(let _x = 3;); //~ ERROR: procedural macros cannot be expanded to statements
80+
81+
let _x = m!(3); //~ ERROR: procedural macros cannot be expanded to expressions
82+
let _x = [m!(3)]; //~ ERROR: procedural macros cannot be expanded to expressions
5483
}

‎src/test/compile-fail/used.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(used)]
12+
13+
#[used]
14+
static FOO: u32 = 0; // OK
15+
16+
#[used] //~ ERROR attribute must be applied to a `static` variable
17+
fn foo() {}
18+
19+
#[used] //~ ERROR attribute must be applied to a `static` variable
20+
struct Foo {}
21+
22+
#[used] //~ ERROR attribute must be applied to a `static` variable
23+
trait Bar {}
24+
25+
#[used] //~ ERROR attribute must be applied to a `static` variable
26+
impl Bar for Foo {}
27+
28+
fn main() {}

‎src/test/run-pass/vec-const-new.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that Vec::new() can be used for constants
12+
13+
#![feature(const_vec_new)]
14+
15+
const MY_VEC: Vec<usize> = Vec::new();
16+
17+
pub fn main() {}

‎src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// compile-pass
1212

13+
#![feature(box_syntax)]
14+
#![feature(box_patterns)]
1315
#![warn(unused)] // UI tests pass `-A unused` (#43896)
1416

1517
struct SoulHistory {
@@ -18,6 +20,13 @@ struct SoulHistory {
1820
endless_and_singing: bool
1921
}
2022

23+
#[derive(Clone, Copy)]
24+
enum Large {
25+
Suit { case: () }
26+
}
27+
28+
struct Tuple(Large, ());
29+
2130
fn main() {
2231
let i_think_continually = 2;
2332
let who_from_the_womb_remembered = SoulHistory {
@@ -31,4 +40,38 @@ fn main() {
3140
endless_and_singing: true } = who_from_the_womb_remembered {
3241
hours_are_suns = false;
3342
}
43+
44+
let bag = Large::Suit {
45+
case: ()
46+
};
47+
48+
// Plain struct
49+
match bag {
50+
Large::Suit { case } => {}
51+
};
52+
53+
// Referenced struct
54+
match &bag {
55+
&Large::Suit { case } => {}
56+
};
57+
58+
// Boxed struct
59+
match box bag {
60+
box Large::Suit { case } => {}
61+
};
62+
63+
// Tuple with struct
64+
match (bag,) {
65+
(Large::Suit { case },) => {}
66+
};
67+
68+
// Slice with struct
69+
match [bag] {
70+
[Large::Suit { case }] => {}
71+
};
72+
73+
// Tuple struct with struct
74+
match Tuple(bag, ()) {
75+
Tuple(Large::Suit { case }, ()) => {}
76+
};
3477
}
Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,76 @@
11
warning: unused variable: `i_think_continually`
2-
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:22:9
2+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:31:9
33
|
44
LL | let i_think_continually = 2;
55
| ^^^^^^^^^^^^^^^^^^^ help: consider using `_i_think_continually` instead
66
|
77
note: lint level defined here
8-
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:13:9
8+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:15:9
99
|
1010
LL | #![warn(unused)] // UI tests pass `-A unused` (#43896)
1111
| ^^^^^^
1212
= note: #[warn(unused_variables)] implied by #[warn(unused)]
1313

1414
warning: unused variable: `corridors_of_light`
15-
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:29:26
15+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:38:26
1616
|
1717
LL | if let SoulHistory { corridors_of_light,
1818
| ^^^^^^^^^^^^^^^^^^ help: try ignoring the field: `corridors_of_light: _`
1919

2020
warning: variable `hours_are_suns` is assigned to, but never used
21-
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:30:26
21+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:39:26
2222
|
2323
LL | mut hours_are_suns,
2424
| ^^^^^^^^^^^^^^^^^^
2525
|
2626
= note: consider using `_hours_are_suns` instead
2727

2828
warning: value assigned to `hours_are_suns` is never read
29-
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:32:9
29+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:41:9
3030
|
3131
LL | hours_are_suns = false;
3232
| ^^^^^^^^^^^^^^
3333
|
3434
note: lint level defined here
35-
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:13:9
35+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:15:9
3636
|
3737
LL | #![warn(unused)] // UI tests pass `-A unused` (#43896)
3838
| ^^^^^^
3939
= note: #[warn(unused_assignments)] implied by #[warn(unused)]
4040

41+
warning: unused variable: `case`
42+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:50:23
43+
|
44+
LL | Large::Suit { case } => {}
45+
| ^^^^ help: try ignoring the field: `case: _`
46+
47+
warning: unused variable: `case`
48+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:55:24
49+
|
50+
LL | &Large::Suit { case } => {}
51+
| ^^^^ help: try ignoring the field: `case: _`
52+
53+
warning: unused variable: `case`
54+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:60:27
55+
|
56+
LL | box Large::Suit { case } => {}
57+
| ^^^^ help: try ignoring the field: `case: _`
58+
59+
warning: unused variable: `case`
60+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:65:24
61+
|
62+
LL | (Large::Suit { case },) => {}
63+
| ^^^^ help: try ignoring the field: `case: _`
64+
65+
warning: unused variable: `case`
66+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:70:24
67+
|
68+
LL | [Large::Suit { case }] => {}
69+
| ^^^^ help: try ignoring the field: `case: _`
70+
71+
warning: unused variable: `case`
72+
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:75:29
73+
|
74+
LL | Tuple(Large::Suit { case }, ()) => {}
75+
| ^^^^ help: try ignoring the field: `case: _`
76+

‎src/tools/cargo

Submodule cargo updated 75 files

0 commit comments

Comments
 (0)
Please sign in to comment.