Skip to content

Commit 3b272bf

Browse files
authored
Auto merge of #36303 - jonathandturner:rollup, r=jonathandturner
Rollup of 8 pull requests - Successful merges: #36121, #36128, #36241, #36243, #36263, #36267, #36273, #36298 - Failed merges:
2 parents 923bac4 + 20cce24 commit 3b272bf

File tree

19 files changed

+155
-97
lines changed

19 files changed

+155
-97
lines changed

CONTRIBUTING.md

+13
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ Some common make targets are:
151151
command above as we only build the stage1 compiler, not the entire thing).
152152
You can also leave off the `-rpass` to run all stage1 test types.
153153
- `make check-stage1-coretest` - Run stage1 tests in `libcore`.
154+
- `make tidy` - Check that the source code is in compliance with Rust's style
155+
guidelines. There is no official document describing Rust's full guidelines
156+
as of yet, but basic rules like 4 spaces for indentation and no more than 99
157+
characters in a single line should be kept in mind when writing code.
154158

155159
## Pull Requests
156160

@@ -177,6 +181,15 @@ you’re adding something to the standard library, try
177181

178182
This will not rebuild the compiler, but will run the tests.
179183

184+
Please make sure your pull request is in compliance with Rust's style
185+
guidelines by running
186+
187+
$ make tidy
188+
189+
Make this check before every pull request (and every new commit in a pull
190+
request) ; you can add [git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)
191+
before every push to make sure you never forget to make this check.
192+
180193
All pull requests are reviewed by another person. We have a bot,
181194
@rust-highfive, that will automatically assign a random person to review your
182195
request.

src/doc/nomicon/safe-unsafe-meaning.md

-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ can therefore be trusted. You can use `unsafe` on a trait implementation
2626
to declare that the implementation of that trait has adhered to whatever
2727
contracts the trait's documentation requires.
2828

29-
There is also the `#[unsafe_no_drop_flag]` attribute, which exists for
30-
historic reasons and is being phased out. See the section on [drop flags]
31-
for details.
32-
3329
The standard library has a number of unsafe functions, including:
3430

3531
* `slice::get_unchecked`, which performs unchecked indexing, allowing

src/doc/reference.md

-10
Original file line numberDiff line numberDiff line change
@@ -2059,10 +2059,6 @@ macro scope.
20592059
outside of its dynamic extent), and thus this attribute has the word
20602060
"unsafe" in its name. To use this, the
20612061
`unsafe_destructor_blind_to_params` feature gate must be enabled.
2062-
- `unsafe_no_drop_flag` - on structs, remove the flag that prevents
2063-
destructors from being run twice. Destructors might be run multiple times on
2064-
the same object with this attribute. To use this, the `unsafe_no_drop_flag` feature
2065-
gate must be enabled.
20662062
- `doc` - Doc comments such as `/// foo` are equivalent to `#[doc = "foo"]`.
20672063
- `rustc_on_unimplemented` - Write a custom note to be shown along with the error
20682064
when the trait is found to be unimplemented on a type.
@@ -2458,12 +2454,6 @@ The currently implemented features of the reference compiler are:
24582454
* `unboxed_closures` - Rust's new closure design, which is currently a work in
24592455
progress feature with many known bugs.
24602456

2461-
* `unsafe_no_drop_flag` - Allows use of the `#[unsafe_no_drop_flag]` attribute,
2462-
which removes hidden flag added to a type that
2463-
implements the `Drop` trait. The design for the
2464-
`Drop` flag is subject to change, and this feature
2465-
may be removed in the future.
2466-
24672457
* `unmarked_api` - Allows use of items within a `#![staged_api]` crate
24682458
which have not been marked with a stability marker.
24692459
Such items should not be allowed by the compiler to exist,

src/libcollections/btree/map.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ use self::Entry::*;
5656
/// however, performance is excellent.
5757
///
5858
/// It is a logic error for a key to be modified in such a way that the key's ordering relative to
59-
/// any other key, as determined by the `Ord` trait, changes while it is in the map. This is
60-
/// normally only possible through `Cell`, `RefCell`, global state, I/O, or unsafe code.
59+
/// any other key, as determined by the [`Ord`] trait, changes while it is in the map. This is
60+
/// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code.
61+
///
62+
/// [`Ord`]: ../../std/cmp/trait.Ord.html
63+
/// [`Cell`]: ../../std/cell/struct.Cell.html
64+
/// [`RefCell`]: ../../std/cell/struct.RefCell.html
6165
///
6266
/// # Examples
6367
///
@@ -2020,7 +2024,7 @@ impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
20202024
self.key
20212025
}
20222026

2023-
/// Sets the value of the entry with the VacantEntry's key,
2027+
/// Sets the value of the entry with the `VacantEntry`'s key,
20242028
/// and returns a mutable reference to it.
20252029
///
20262030
/// # Examples
@@ -2192,7 +2196,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
21922196
self.handle.into_kv_mut().1
21932197
}
21942198

2195-
/// Sets the value of the entry with the OccupiedEntry's key,
2199+
/// Sets the value of the entry with the `OccupiedEntry`'s key,
21962200
/// and returns the entry's old value.
21972201
///
21982202
/// # Examples

src/librustc/hir/check_attr.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ struct CheckAttrVisitor<'a> {
4242
impl<'a> CheckAttrVisitor<'a> {
4343
fn check_inline(&self, attr: &ast::Attribute, target: Target) {
4444
if target != Target::Fn {
45-
span_err!(self.sess, attr.span, E0518, "attribute should be applied to function");
45+
struct_span_err!(self.sess, attr.span, E0518, "attribute should be applied to function")
46+
.span_label(attr.span, &format!("requires a function"))
47+
.emit();
4648
}
4749
}
4850

@@ -56,18 +58,20 @@ impl<'a> CheckAttrVisitor<'a> {
5658

5759
let mut conflicting_reprs = 0;
5860
for word in words {
61+
5962
let name = match word.name() {
6063
Some(word) => word,
6164
None => continue,
6265
};
6366

64-
let message = match &*name {
67+
let (message, label) = match &*name {
6568
"C" => {
6669
conflicting_reprs += 1;
6770
if target != Target::Struct &&
6871
target != Target::Union &&
6972
target != Target::Enum {
70-
"attribute should be applied to struct, enum or union"
73+
("attribute should be applied to struct, enum or union",
74+
"a struct, enum or union")
7175
} else {
7276
continue
7377
}
@@ -77,15 +81,17 @@ impl<'a> CheckAttrVisitor<'a> {
7781
// can be used to modify another repr hint
7882
if target != Target::Struct &&
7983
target != Target::Union {
80-
"attribute should be applied to struct or union"
84+
("attribute should be applied to struct or union",
85+
"a struct or union")
8186
} else {
8287
continue
8388
}
8489
}
8590
"simd" => {
8691
conflicting_reprs += 1;
8792
if target != Target::Struct {
88-
"attribute should be applied to struct"
93+
("attribute should be applied to struct",
94+
"a struct")
8995
} else {
9096
continue
9197
}
@@ -95,15 +101,17 @@ impl<'a> CheckAttrVisitor<'a> {
95101
"isize" | "usize" => {
96102
conflicting_reprs += 1;
97103
if target != Target::Enum {
98-
"attribute should be applied to enum"
104+
("attribute should be applied to enum",
105+
"an enum")
99106
} else {
100107
continue
101108
}
102109
}
103110
_ => continue,
104111
};
105-
106-
span_err!(self.sess, attr.span, E0517, "{}", message);
112+
struct_span_err!(self.sess, attr.span, E0517, "{}", message)
113+
.span_label(attr.span, &format!("requires {}", label))
114+
.emit();
107115
}
108116
if conflicting_reprs > 1 {
109117
span_warn!(self.sess, attr.span, E0566,

src/librustc_typeck/astconv.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1769,8 +1769,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
17691769
}
17701770
}
17711771
hir::TyTypeof(ref _e) => {
1772-
span_err!(tcx.sess, ast_ty.span, E0516,
1773-
"`typeof` is a reserved keyword but unimplemented");
1772+
struct_span_err!(tcx.sess, ast_ty.span, E0516,
1773+
"`typeof` is a reserved keyword but unimplemented")
1774+
.span_label(ast_ty.span, &format!("reserved keyword"))
1775+
.emit();
1776+
17741777
tcx.types.err
17751778
}
17761779
hir::TyInfer => {

src/librustc_typeck/check/_match.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
233233
let min_len = before.len() + after.len();
234234
if slice.is_none() {
235235
if min_len != size {
236-
span_err!(tcx.sess, pat.span, E0527,
237-
"pattern requires {} elements but array has {}",
238-
min_len, size);
236+
struct_span_err!(
237+
tcx.sess, pat.span, E0527,
238+
"pattern requires {} elements but array has {}",
239+
min_len, size)
240+
.span_label(pat.span, &format!("expected {} elements",size))
241+
.emit();
239242
}
240243
(inner_ty, tcx.types.err)
241244
} else if let Some(rest) = size.checked_sub(min_len) {

src/librustc_typeck/check/mod.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ use syntax::parse::token::{self, InternedString, keywords};
118118
use syntax::ptr::P;
119119
use syntax::util::lev_distance::find_best_match_for_name;
120120
use syntax_pos::{self, Span};
121-
use errors::DiagnosticBuilder;
122121

123122
use rustc::hir::intravisit::{self, Visitor};
124123
use rustc::hir::{self, PatKind};
@@ -2959,7 +2958,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
29592958
}, expr_t);
29602959
match expr_t.sty {
29612960
ty::TyStruct(def, _) | ty::TyUnion(def, _) => {
2962-
Self::suggest_field_names(&mut err, def.struct_variant(), field, vec![]);
2961+
if let Some(suggested_field_name) =
2962+
Self::suggest_field_name(def.struct_variant(), field, vec![]) {
2963+
err.span_help(field.span,
2964+
&format!("did you mean `{}`?", suggested_field_name));
2965+
};
29632966
}
29642967
ty::TyRawPtr(..) => {
29652968
err.note(&format!("`{0}` is a native pointer; perhaps you need to deref with \
@@ -2972,11 +2975,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
29722975
}
29732976
}
29742977

2975-
// displays hints about the closest matches in field names
2976-
fn suggest_field_names(err: &mut DiagnosticBuilder,
2977-
variant: ty::VariantDef<'tcx>,
2978-
field: &Spanned<ast::Name>,
2979-
skip : Vec<InternedString>) {
2978+
// Return an hint about the closest match in field names
2979+
fn suggest_field_name(variant: ty::VariantDef<'tcx>,
2980+
field: &Spanned<ast::Name>,
2981+
skip : Vec<InternedString>)
2982+
-> Option<InternedString> {
29802983
let name = field.node.as_str();
29812984
let names = variant.fields.iter().filter_map(|field| {
29822985
// ignore already set fields and private fields from non-local crates
@@ -2989,10 +2992,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
29892992
});
29902993

29912994
// only find fits with at least one matching letter
2992-
if let Some(name) = find_best_match_for_name(names, &name, Some(name.len())) {
2993-
err.span_help(field.span,
2994-
&format!("did you mean `{}`?", name));
2995-
}
2995+
find_best_match_for_name(names, &name, Some(name.len()))
29962996
}
29972997

29982998
// Check tuple index expressions
@@ -3086,7 +3086,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
30863086
ty);
30873087
// prevent all specified fields from being suggested
30883088
let skip_fields = skip_fields.iter().map(|ref x| x.name.node.as_str());
3089-
Self::suggest_field_names(&mut err, variant, &field.name, skip_fields.collect());
3089+
if let Some(field_name) = Self::suggest_field_name(variant,
3090+
&field.name,
3091+
skip_fields.collect()) {
3092+
err.span_label(field.name.span,&format!("did you mean `{}`?",field_name));
3093+
};
30903094
err.emit();
30913095
}
30923096

0 commit comments

Comments
 (0)