Skip to content

Commit 7acce37

Browse files
committed
Auto merge of #42964 - arielb1:rollup, r=arielb1
Rollup of 12 pull requests - Successful merges: #42219, #42831, #42832, #42884, #42886, #42901, #42919, #42920, #42946, #42953, #42955, #42958 - Failed merges:
2 parents dc2003b + d3329d7 commit 7acce37

30 files changed

+492
-188
lines changed

.travis.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,22 @@ before_script:
171171
if [[ "$SKIP_BUILD" == true ]]; then
172172
export RUN_SCRIPT="echo 'skipping, not a full build'";
173173
else
174-
RUN_SCRIPT="stamp src/ci/init_repo.sh . $HOME/rustsrc";
174+
RUN_SCRIPT="src/ci/init_repo.sh . $HOME/rustsrc";
175175
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
176-
export RUN_SCRIPT="$RUN_SCRIPT && stamp src/ci/run.sh";
176+
export RUN_SCRIPT="$RUN_SCRIPT && src/ci/run.sh";
177177
else
178-
export RUN_SCRIPT="$RUN_SCRIPT && stamp src/ci/docker/run.sh $IMAGE";
178+
export RUN_SCRIPT="$RUN_SCRIPT && src/ci/docker/run.sh $IMAGE";
179179
fi
180180
fi
181181
182+
# Log time information from this machine and an external machine for insight into possible
183+
# clock drift. Timezones don't matter since relative deltas give all the necessary info.
182184
script:
183-
- sh -x -c "$RUN_SCRIPT"
185+
- >
186+
date && curl -s --head https://google.com | grep ^Date: | sed 's/Date: //g'
187+
- stamp sh -x -c "$RUN_SCRIPT"
188+
- >
189+
date && curl -s --head https://google.com | grep ^Date: | sed 's/Date: //g'
184190
185191
after_success:
186192
- >

src/doc/unstable-book/src/language-features/compile-error.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The tracking issue for this feature is: [#40872]
44

5-
[#29599]: https://github.com/rust-lang/rust/issues/40872
5+
[#40872]: https://github.com/rust-lang/rust/issues/40872
66

77
------------------------
88

src/liballoc/allocator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ pub unsafe trait Alloc {
873873
{
874874
let k = Layout::new::<T>();
875875
if k.size() > 0 {
876-
unsafe { self.alloc(k).map(|p|Unique::new(*p as *mut T)) }
876+
unsafe { self.alloc(k).map(|p| Unique::new(p as *mut T)) }
877877
} else {
878878
Err(AllocErr::invalid_input("zero-sized type invalid for alloc_one"))
879879
}

src/liballoc/fmt.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,10 @@ pub use core::fmt::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};
498498

499499
use string;
500500

501-
/// The format function takes a precompiled format string and a list of
502-
/// arguments, to return the resulting formatted string.
501+
/// The `format` function takes an `Arguments` struct and returns the resulting
502+
/// formatted string.
503503
///
504-
/// # Arguments
505-
///
506-
/// * args - a structure of arguments generated via the `format_args!` macro.
504+
/// The `Arguments` instance can be created with the `format_args!` macro.
507505
///
508506
/// # Examples
509507
///

src/libcore/cmp.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,9 @@ impl<T: Ord> Ord for Reverse<T> {
379379
///
380380
/// ## Derivable
381381
///
382-
/// This trait can be used with `#[derive]`. When `derive`d, it will produce a lexicographic
383-
/// ordering based on the top-to-bottom declaration order of the struct's members.
382+
/// This trait can be used with `#[derive]`. When `derive`d on structs, it will produce a
383+
/// lexicographic ordering based on the top-to-bottom declaration order of the struct's members.
384+
/// When `derive`d on enums, variants are ordered by their top-to-bottom declaration order.
384385
///
385386
/// ## How can I implement `Ord`?
386387
///
@@ -512,8 +513,9 @@ impl PartialOrd for Ordering {
512513
///
513514
/// ## Derivable
514515
///
515-
/// This trait can be used with `#[derive]`. When `derive`d, it will produce a lexicographic
516-
/// ordering based on the top-to-bottom declaration order of the struct's members.
516+
/// This trait can be used with `#[derive]`. When `derive`d on structs, it will produce a
517+
/// lexicographic ordering based on the top-to-bottom declaration order of the struct's members.
518+
/// When `derive`d on enums, variants are ordered by their top-to-bottom declaration order.
517519
///
518520
/// ## How can I implement `PartialOrd`?
519521
///

src/libcore/fmt/mod.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -897,14 +897,11 @@ pub trait UpperExp {
897897
fn fmt(&self, f: &mut Formatter) -> Result;
898898
}
899899

900-
/// The `write` function takes an output stream, a precompiled format string,
901-
/// and a list of arguments. The arguments will be formatted according to the
902-
/// specified format string into the output stream provided.
900+
/// The `write` function takes an output stream, and an `Arguments` struct
901+
/// that can be precompiled with the `format_args!` macro.
903902
///
904-
/// # Arguments
905-
///
906-
/// * output - the buffer to write output to
907-
/// * args - the precompiled arguments generated by `format_args!`
903+
/// The arguments will be formatted according to the specified format string
904+
/// into the output stream provided.
908905
///
909906
/// # Examples
910907
///

src/librustc/lint/context.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session,
510510
}
511511

512512
let name = lint.name_lower();
513-
let mut def = None;
514513

515514
// Except for possible note details, forbid behaves like deny.
516515
let effective_level = if level == Forbid { Deny } else { level };
@@ -525,7 +524,8 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session,
525524

526525
match source {
527526
Default => {
528-
err.note(&format!("#[{}({})] on by default", level.as_str(), name));
527+
sess.diag_note_once(&mut err, lint,
528+
&format!("#[{}({})] on by default", level.as_str(), name));
529529
},
530530
CommandLine(lint_flag_val) => {
531531
let flag = match level {
@@ -534,20 +534,24 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session,
534534
};
535535
let hyphen_case_lint_name = name.replace("_", "-");
536536
if lint_flag_val.as_str() == name {
537-
err.note(&format!("requested on the command line with `{} {}`",
538-
flag, hyphen_case_lint_name));
537+
sess.diag_note_once(&mut err, lint,
538+
&format!("requested on the command line with `{} {}`",
539+
flag, hyphen_case_lint_name));
539540
} else {
540541
let hyphen_case_flag_val = lint_flag_val.as_str().replace("_", "-");
541-
err.note(&format!("`{} {}` implied by `{} {}`",
542-
flag, hyphen_case_lint_name, flag, hyphen_case_flag_val));
542+
sess.diag_note_once(&mut err, lint,
543+
&format!("`{} {}` implied by `{} {}`",
544+
flag, hyphen_case_lint_name, flag,
545+
hyphen_case_flag_val));
543546
}
544547
},
545548
Node(lint_attr_name, src) => {
546-
def = Some(src);
549+
sess.diag_span_note_once(&mut err, lint, src, "lint level defined here");
547550
if lint_attr_name.as_str() != name {
548551
let level_str = level.as_str();
549-
err.note(&format!("#[{}({})] implied by #[{}({})]",
550-
level_str, name, level_str, lint_attr_name));
552+
sess.diag_note_once(&mut err, lint,
553+
&format!("#[{}({})] implied by #[{}({})]",
554+
level_str, name, level_str, lint_attr_name));
551555
}
552556
}
553557
}
@@ -563,10 +567,6 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session,
563567
err.note(&citation);
564568
}
565569

566-
if let Some(span) = def {
567-
sess.diag_span_note_once(&mut err, lint, span, "lint level defined here");
568-
}
569-
570570
err
571571
}
572572

src/librustc/session/mod.rs

+43-17
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ pub struct Session {
7979
pub working_dir: (String, bool),
8080
pub lint_store: RefCell<lint::LintStore>,
8181
pub lints: RefCell<lint::LintTable>,
82-
/// Set of (LintId, span, message) tuples tracking lint (sub)diagnostics
83-
/// that have been set once, but should not be set again, in order to avoid
84-
/// redundantly verbose output (Issue #24690).
85-
pub one_time_diagnostics: RefCell<FxHashSet<(lint::LintId, Span, String)>>,
82+
/// Set of (LintId, Option<Span>, message) tuples tracking lint
83+
/// (sub)diagnostics that have been set once, but should not be set again,
84+
/// in order to avoid redundantly verbose output (Issue #24690).
85+
pub one_time_diagnostics: RefCell<FxHashSet<(lint::LintId, Option<Span>, String)>>,
8686
pub plugin_llvm_passes: RefCell<Vec<String>>,
8787
pub plugin_attributes: RefCell<Vec<(String, AttributeType)>>,
8888
pub crate_types: RefCell<Vec<config::CrateType>>,
@@ -157,6 +157,13 @@ pub struct PerfStats {
157157
pub decode_def_path_tables_time: Cell<Duration>,
158158
}
159159

160+
/// Enum to support dispatch of one-time diagnostics (in Session.diag_once)
161+
enum DiagnosticBuilderMethod {
162+
Note,
163+
SpanNote,
164+
// add more variants as needed to support one-time diagnostics
165+
}
166+
160167
impl Session {
161168
pub fn local_crate_disambiguator(&self) -> Symbol {
162169
*self.crate_disambiguator.borrow()
@@ -329,34 +336,53 @@ impl Session {
329336
&self.parse_sess.span_diagnostic
330337
}
331338

332-
/// Analogous to calling `.span_note` on the given DiagnosticBuilder, but
333-
/// deduplicates on lint ID, span, and message for this `Session` if we're
334-
/// not outputting in JSON mode.
335-
//
336-
// FIXME: if the need arises for one-time diagnostics other than
337-
// `span_note`, we almost certainly want to generalize this
338-
// "check/insert-into the one-time diagnostics map, then set message if
339-
// it's not already there" code to accomodate all of them
340-
pub fn diag_span_note_once<'a, 'b>(&'a self,
341-
diag_builder: &'b mut DiagnosticBuilder<'a>,
342-
lint: &'static lint::Lint, span: Span, message: &str) {
339+
/// Analogous to calling methods on the given `DiagnosticBuilder`, but
340+
/// deduplicates on lint ID, span (if any), and message for this `Session`
341+
/// if we're not outputting in JSON mode.
342+
fn diag_once<'a, 'b>(&'a self,
343+
diag_builder: &'b mut DiagnosticBuilder<'a>,
344+
method: DiagnosticBuilderMethod,
345+
lint: &'static lint::Lint, message: &str, span: Option<Span>) {
346+
let mut do_method = || {
347+
match method {
348+
DiagnosticBuilderMethod::Note => {
349+
diag_builder.note(message);
350+
},
351+
DiagnosticBuilderMethod::SpanNote => {
352+
diag_builder.span_note(span.expect("span_note expects a span"), message);
353+
}
354+
}
355+
};
356+
343357
match self.opts.error_format {
344358
// when outputting JSON for tool consumption, the tool might want
345359
// the duplicates
346360
config::ErrorOutputType::Json => {
347-
diag_builder.span_note(span, &message);
361+
do_method()
348362
},
349363
_ => {
350364
let lint_id = lint::LintId::of(lint);
351365
let id_span_message = (lint_id, span, message.to_owned());
352366
let fresh = self.one_time_diagnostics.borrow_mut().insert(id_span_message);
353367
if fresh {
354-
diag_builder.span_note(span, &message);
368+
do_method()
355369
}
356370
}
357371
}
358372
}
359373

374+
pub fn diag_span_note_once<'a, 'b>(&'a self,
375+
diag_builder: &'b mut DiagnosticBuilder<'a>,
376+
lint: &'static lint::Lint, span: Span, message: &str) {
377+
self.diag_once(diag_builder, DiagnosticBuilderMethod::SpanNote, lint, message, Some(span));
378+
}
379+
380+
pub fn diag_note_once<'a, 'b>(&'a self,
381+
diag_builder: &'b mut DiagnosticBuilder<'a>,
382+
lint: &'static lint::Lint, message: &str) {
383+
self.diag_once(diag_builder, DiagnosticBuilderMethod::Note, lint, message, None);
384+
}
385+
360386
pub fn codemap<'a>(&'a self) -> &'a codemap::CodeMap {
361387
self.parse_sess.codemap()
362388
}

src/librustc_lint/builtin.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,9 @@ fn fl_lit_check_expr(cx: &EarlyContext, expr: &ast::Expr) {
684684
// These may occur in patterns
685685
// and can maybe contain float literals
686686
ExprKind::Unary(_, ref f) => fl_lit_check_expr(cx, f),
687-
// These may occur in patterns
688-
// and can't contain float literals
689-
ExprKind::Path(..) => (),
690-
// If something unhandled is encountered, we need to expand the
691-
// search or ignore more ExprKinds.
692-
_ => span_bug!(expr.span, "Unhandled expression {:?} in float lit pattern lint",
693-
expr.node),
687+
// Other kinds of exprs can't occur in patterns so we don't have to check them
688+
// (ast_validation will emit an error if they occur)
689+
_ => (),
694690
}
695691
}
696692

src/librustc_passes/ast_validation.rs

+26
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ impl<'a> AstValidator<'a> {
9393
}
9494
}
9595
}
96+
97+
/// matches '-' lit | lit (cf. parser::Parser::parse_pat_literal_maybe_minus)
98+
fn check_expr_within_pat(&self, expr: &Expr) {
99+
match expr.node {
100+
ExprKind::Lit(..) | ExprKind::Path(..) => {}
101+
ExprKind::Unary(UnOp::Neg, ref inner)
102+
if match inner.node { ExprKind::Lit(_) => true, _ => false } => {}
103+
_ => self.err_handler().span_err(expr.span, "arbitrary expressions aren't allowed \
104+
in patterns")
105+
}
106+
}
96107
}
97108

98109
impl<'a> Visitor<'a> for AstValidator<'a> {
@@ -308,6 +319,21 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
308319
}
309320
visit::walk_generics(self, g)
310321
}
322+
323+
fn visit_pat(&mut self, pat: &'a Pat) {
324+
match pat.node {
325+
PatKind::Lit(ref expr) => {
326+
self.check_expr_within_pat(expr);
327+
}
328+
PatKind::Range(ref start, ref end, _) => {
329+
self.check_expr_within_pat(start);
330+
self.check_expr_within_pat(end);
331+
}
332+
_ => {}
333+
}
334+
335+
visit::walk_pat(self, pat)
336+
}
311337
}
312338

313339
pub fn check_crate(session: &Session, krate: &Crate) {

0 commit comments

Comments
 (0)