Skip to content

Commit

Permalink
Auto merge of #41846 - frewsxcv:rollup, r=frewsxcv
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

- Successful merges: #41293, #41520, #41827, #41828, #41833, #41836, #41838, #41842
- Failed merges:
  • Loading branch information
bors committed May 9, 2017
2 parents f1140a3 + f21209f commit bedd7da
Show file tree
Hide file tree
Showing 29 changed files with 381 additions and 59 deletions.
14 changes: 7 additions & 7 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/doc/rustc-ux-guidelines.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
% Rustc UX guidelines

Don't forget the user. Whether human or another program, such as an IDE, a
good user experience with the compiler goes a long way into making developer
lives better. We don't want users to be baffled by compiler output or
good user experience with the compiler goes a long way toward making developers'
lives better. We do not want users to be baffled by compiler output or
learn arcane patterns to compile their program.

## Error, Warning, Help, Note Messages

When the compiler detects a problem, it can emit either an error, warning,
note, or help message.
When the compiler detects a problem, it can emit one of the following: an error, a warning,
a note, or a help message.

An `error` is emitted when the compiler detects a problem that makes it unable
to compile the program, either because the program is invalid or the
Expand All @@ -17,11 +17,11 @@ An `error` is emitted when the compiler detects a problem that makes it unable
A `warning` is emitted when the compiler detects something odd about a
program. For instance, dead code and unused `Result` values.

A `help` is emitted following either an `error` or `warning` giving extra
A `help` message is emitted following an `error` or `warning` to give additional
information to the user about how to solve their problem.

A `note` is for identifying additional circumstances and parts of the code
that lead to a warning or error. For example, the borrow checker will note any
A `note` is emitted to identify additional circumstances and parts of the code
that caused the warning or error. For example, the borrow checker will note any
previous conflicting borrows.

* Write in plain simple English. If your message, when shown on a – possibly
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<'tcx> fmt::Debug for Kind<'tcx> {
} else if let Some(r) = self.as_region() {
write!(f, "{:?}", r)
} else {
write!(f, "<unknwon @ {:p}>", self.ptr.get() as *const ())
write!(f, "<unknown @ {:p}>", self.ptr.get() as *const ())
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,14 @@ impl Handler {
pub fn span_note_without_error<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
self.emit(&sp.into(), msg, Note);
}
pub fn span_note_diag<'a>(&'a self,
sp: Span,
msg: &str)
-> DiagnosticBuilder<'a> {
let mut db = DiagnosticBuilder::new(self, Note, msg);
db.set_span(sp);
db
}
pub fn span_unimpl<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
self.span_bug(sp, &format!("unimplemented {}", msg));
}
Expand Down
76 changes: 76 additions & 0 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,82 @@ impl EarlyLintPass for DeprecatedAttr {
}
}

declare_lint! {
pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
Warn,
"floating-point literals cannot be used in patterns"
}

/// Checks for floating point literals in patterns.
#[derive(Clone)]
pub struct IllegalFloatLiteralPattern;

impl LintPass for IllegalFloatLiteralPattern {
fn get_lints(&self) -> LintArray {
lint_array!(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN)
}
}

fn fl_lit_check_expr(cx: &EarlyContext, expr: &ast::Expr) {
use self::ast::{ExprKind, LitKind};
match expr.node {
ExprKind::Lit(ref l) => {
match l.node {
LitKind::FloatUnsuffixed(..) |
LitKind::Float(..) => {
cx.span_lint(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
l.span,
"floating-point literals cannot be used in patterns");
error!("span mc spanspam");
},
_ => (),
}
}
// These may occur in patterns
// and can maybe contain float literals
ExprKind::Unary(_, ref f) => fl_lit_check_expr(cx, f),
// These may occur in patterns
// and can't contain float literals
ExprKind::Path(..) => (),
// If something unhandled is encountered, we need to expand the
// search or ignore more ExprKinds.
_ => span_bug!(expr.span, "Unhandled expression {:?} in float lit pattern lint",
expr.node),
}
}

impl EarlyLintPass for IllegalFloatLiteralPattern {
fn check_pat(&mut self, cx: &EarlyContext, pat: &ast::Pat) {
use self::ast::PatKind;
pat.walk(&mut |p| {
match p.node {
// Wildcard patterns and paths are uninteresting for the lint
PatKind::Wild |
PatKind::Path(..) => (),

// The walk logic recurses inside these
PatKind::Ident(..) |
PatKind::Struct(..) |
PatKind::Tuple(..) |
PatKind::TupleStruct(..) |
PatKind::Ref(..) |
PatKind::Box(..) |
PatKind::Slice(..) => (),

// Extract the expressions and check them
PatKind::Lit(ref e) => fl_lit_check_expr(cx, e),
PatKind::Range(ref st, ref en, _) => {
fl_lit_check_expr(cx, st);
fl_lit_check_expr(cx, en);
},

PatKind::Mac(_) => bug!("lint must run post-expansion"),
}
true
});
}
}

declare_lint! {
pub UNCONDITIONAL_RECURSION,
Warn,
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
UnusedParens,
UnusedImportBraces,
AnonymousParameters,
IllegalFloatLiteralPattern,
);

add_early_builtin_with_new!(sess,
Expand Down Expand Up @@ -201,6 +202,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
id: LintId::of(ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN),
reference: "issue #36890 <https://github.com/rust-lang/rust/issues/36890>",
},
FutureIncompatibleInfo {
id: LintId::of(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN),
reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
},
FutureIncompatibleInfo {
id: LintId::of(ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN),
reference: "issue #36891 <https://github.com/rust-lang/rust/issues/36891>",
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_save_analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rustc = { path = "../librustc" }
rustc_typeck = { path = "../librustc_typeck" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
rls-data = "0.1"
rls-span = "0.1"
rls-data = "0.3"
rls-span = "0.4"
# FIXME(#40527) should move rustc serialize out of tree
rustc-serialize = "0.3"
1 change: 1 addition & 0 deletions src/librustc_typeck/check/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
(sig, kind)
}
ty::TyInfer(ty::TyVar(vid)) => self.deduce_expectations_from_obligations(vid),
ty::TyFnPtr(sig) => (Some(sig.skip_binder().clone()), Some(ty::ClosureKind::Fn)),
_ => (None, None),
}
}
Expand Down
48 changes: 31 additions & 17 deletions src/librustc_typeck/check/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,22 +433,11 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
for (i, &expr) in exprs.iter().rev().enumerate() {
debug!("convert_lvalue_derefs_to_mutable: i={} expr={:?}", i, expr);

// Fix up the adjustment.
let autoderefs = match self.tables.borrow_mut().adjustments.get_mut(&expr.id) {
Some(&mut Adjustment {
kind: Adjust::DerefRef { autoderefs, ref mut autoref, .. }, ref mut target
}) => {
if let &mut Some(AutoBorrow::Ref(_, ref mut mutbl)) = autoref {
*mutbl = hir::Mutability::MutMutable;
*target = match target.sty {
ty::TyRef(r, ty::TypeAndMut { ty, .. }) =>
self.tcx.mk_ref(r, ty::TypeAndMut { ty, mutbl: *mutbl }),
_ => span_bug!(expr.span, "AutoBorrow::Ref resulted in non-ref {:?}",
target)
};
}
autoderefs
}
// Fix up the autoderefs. Autorefs can only occur immediately preceding
// overloaded lvalue ops, and will be fixed by them in order to get
// the correct region.
let autoderefs = match self.tables.borrow().adjustments.get(&expr.id) {
Some(&Adjustment { kind: Adjust::DerefRef { autoderefs, .. }, .. }) => autoderefs,
Some(_) | None => 0
};

Expand Down Expand Up @@ -502,10 +491,35 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {

let method = self.try_overloaded_lvalue_op(
expr.span, None, base_ty, arg_tys, PreferMutLvalue, op);
let ok = method.expect("re-trying op failed");
let ok = match method {
Some(method) => method,
None => return self.tcx.sess.delay_span_bug(expr.span, "re-trying op failed")
};
let method = self.register_infer_ok_obligations(ok);
debug!("convert_lvalue_op_to_mutable: method={:?}", method);
self.tables.borrow_mut().method_map.insert(method_call, method);

// Convert the autoref in the base expr to mutable with the correct
// region and mutability.
if let Some(&mut Adjustment {
ref mut target, kind: Adjust::DerefRef {
autoref: Some(AutoBorrow::Ref(ref mut r, ref mut mutbl)), ..
}
}) = self.tables.borrow_mut().adjustments.get_mut(&base_expr.id) {
debug!("convert_lvalue_op_to_mutable: converting autoref of {:?}", target);

// extract method return type, which will be &mut T;
// all LB regions should have been instantiated during method lookup
let method_sig = self.tcx.no_late_bound_regions(&method.ty.fn_sig()).unwrap();

*target = method_sig.inputs()[0];
if let ty::TyRef(r_, mt) = target.sty {
*r = r_;
*mutbl = mt.mutbl;
} else {
span_bug!(expr.span, "input to lvalue op is not a ref?");
}
}
}

///////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 12 additions & 0 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use ptr::P;
use symbol::Symbol;
use util::small_vector::SmallVector;

use std::collections::HashMap;
use std::path::PathBuf;
use std::rc::Rc;
use std::default::Default;
Expand Down Expand Up @@ -643,6 +644,7 @@ pub struct ExtCtxt<'a> {
pub resolver: &'a mut Resolver,
pub resolve_err_count: usize,
pub current_expansion: ExpansionData,
pub expansions: HashMap<Span, Vec<String>>,
}

impl<'a> ExtCtxt<'a> {
Expand All @@ -662,6 +664,7 @@ impl<'a> ExtCtxt<'a> {
module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }),
directory_ownership: DirectoryOwnership::Owned,
},
expansions: HashMap::new(),
}
}

Expand Down Expand Up @@ -765,6 +768,15 @@ impl<'a> ExtCtxt<'a> {
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
self.parse_sess.span_diagnostic.span_bug(sp, msg);
}
pub fn trace_macros_diag(&self) {
for (sp, notes) in self.expansions.iter() {
let mut db = self.parse_sess.span_diagnostic.span_note_diag(*sp, &"trace_macro");
for note in notes {
db.note(&note);
}
db.emit();
}
}
pub fn bug(&self, msg: &str) -> ! {
self.parse_sess.span_diagnostic.bug(msg);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
},
_ => unreachable!(),
};

self.cx.trace_macros_diag();
krate
}

Expand Down
10 changes: 6 additions & 4 deletions src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use symbol::Symbol;
use tokenstream::{TokenStream, TokenTree};

use std::cell::RefCell;
use std::collections::{HashMap};
use std::collections::hash_map::{Entry};
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use std::rc::Rc;

pub struct ParserAnyMacro<'a> {
Expand Down Expand Up @@ -85,15 +85,17 @@ impl TTMacroExpander for MacroRulesMacroExpander {
}

/// Given `lhses` and `rhses`, this is the new macro we create
fn generic_extension<'cx>(cx: &'cx ExtCtxt,
fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
sp: Span,
name: ast::Ident,
arg: TokenStream,
lhses: &[quoted::TokenTree],
rhses: &[quoted::TokenTree])
-> Box<MacResult+'cx> {
if cx.trace_macros() {
println!("{}! {{ {} }}", name, arg);
let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp);
let mut values: &mut Vec<String> = cx.expansions.entry(sp).or_insert(vec![]);
values.push(format!("expands to `{}! {{ {} }}`", name, arg));
}

// Which arm's failure should we report? (the one furthest along)
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ impl<'a> StringReader<'a> {
self.bump();

// line comments starting with "///" or "//!" are doc-comments
let doc_comment = self.ch_is('/') || self.ch_is('!');
let doc_comment = (self.ch_is('/') && !self.nextch_is('/')) || self.ch_is('!');
let start_bpos = self.pos - BytePos(2);

while !self.is_eof() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@ fn main() {
let mut a = 0u8;
let foo: fn(u8) -> u8 = |v: u8| { a += v; a };
//~^ ERROR mismatched types
let b = 0u8;
let bar: fn() -> u8 = || { b };
//~^ ERROR mismatched types
let baz: fn() -> u8 = || { b } as fn() -> u8;
//~^ ERROR mismatched types
//~^^ ERROR non-scalar cast
}
Loading

0 comments on commit bedd7da

Please sign in to comment.