Skip to content

Commit bedd7da

Browse files
committed
Auto merge of #41846 - frewsxcv:rollup, r=frewsxcv
Rollup of 8 pull requests - Successful merges: #41293, #41520, #41827, #41828, #41833, #41836, #41838, #41842 - Failed merges:
2 parents f1140a3 + f21209f commit bedd7da

29 files changed

+381
-59
lines changed

src/Cargo.lock

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/doc/rustc-ux-guidelines.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
% Rustc UX guidelines
22

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

88
## Error, Warning, Help, Note Messages
99

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

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

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

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

2727
* Write in plain simple English. If your message, when shown on a – possibly

src/librustc/ty/subst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'tcx> fmt::Debug for Kind<'tcx> {
102102
} else if let Some(r) = self.as_region() {
103103
write!(f, "{:?}", r)
104104
} else {
105-
write!(f, "<unknwon @ {:p}>", self.ptr.get() as *const ())
105+
write!(f, "<unknown @ {:p}>", self.ptr.get() as *const ())
106106
}
107107
}
108108
}

src/librustc_errors/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,14 @@ impl Handler {
388388
pub fn span_note_without_error<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
389389
self.emit(&sp.into(), msg, Note);
390390
}
391+
pub fn span_note_diag<'a>(&'a self,
392+
sp: Span,
393+
msg: &str)
394+
-> DiagnosticBuilder<'a> {
395+
let mut db = DiagnosticBuilder::new(self, Note, msg);
396+
db.set_span(sp);
397+
db
398+
}
391399
pub fn span_unimpl<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
392400
self.span_bug(sp, &format!("unimplemented {}", msg));
393401
}

src/librustc_lint/builtin.rs

+76
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,82 @@ impl EarlyLintPass for DeprecatedAttr {
692692
}
693693
}
694694

695+
declare_lint! {
696+
pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
697+
Warn,
698+
"floating-point literals cannot be used in patterns"
699+
}
700+
701+
/// Checks for floating point literals in patterns.
702+
#[derive(Clone)]
703+
pub struct IllegalFloatLiteralPattern;
704+
705+
impl LintPass for IllegalFloatLiteralPattern {
706+
fn get_lints(&self) -> LintArray {
707+
lint_array!(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN)
708+
}
709+
}
710+
711+
fn fl_lit_check_expr(cx: &EarlyContext, expr: &ast::Expr) {
712+
use self::ast::{ExprKind, LitKind};
713+
match expr.node {
714+
ExprKind::Lit(ref l) => {
715+
match l.node {
716+
LitKind::FloatUnsuffixed(..) |
717+
LitKind::Float(..) => {
718+
cx.span_lint(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
719+
l.span,
720+
"floating-point literals cannot be used in patterns");
721+
error!("span mc spanspam");
722+
},
723+
_ => (),
724+
}
725+
}
726+
// These may occur in patterns
727+
// and can maybe contain float literals
728+
ExprKind::Unary(_, ref f) => fl_lit_check_expr(cx, f),
729+
// These may occur in patterns
730+
// and can't contain float literals
731+
ExprKind::Path(..) => (),
732+
// If something unhandled is encountered, we need to expand the
733+
// search or ignore more ExprKinds.
734+
_ => span_bug!(expr.span, "Unhandled expression {:?} in float lit pattern lint",
735+
expr.node),
736+
}
737+
}
738+
739+
impl EarlyLintPass for IllegalFloatLiteralPattern {
740+
fn check_pat(&mut self, cx: &EarlyContext, pat: &ast::Pat) {
741+
use self::ast::PatKind;
742+
pat.walk(&mut |p| {
743+
match p.node {
744+
// Wildcard patterns and paths are uninteresting for the lint
745+
PatKind::Wild |
746+
PatKind::Path(..) => (),
747+
748+
// The walk logic recurses inside these
749+
PatKind::Ident(..) |
750+
PatKind::Struct(..) |
751+
PatKind::Tuple(..) |
752+
PatKind::TupleStruct(..) |
753+
PatKind::Ref(..) |
754+
PatKind::Box(..) |
755+
PatKind::Slice(..) => (),
756+
757+
// Extract the expressions and check them
758+
PatKind::Lit(ref e) => fl_lit_check_expr(cx, e),
759+
PatKind::Range(ref st, ref en, _) => {
760+
fl_lit_check_expr(cx, st);
761+
fl_lit_check_expr(cx, en);
762+
},
763+
764+
PatKind::Mac(_) => bug!("lint must run post-expansion"),
765+
}
766+
true
767+
});
768+
}
769+
}
770+
695771
declare_lint! {
696772
pub UNCONDITIONAL_RECURSION,
697773
Warn,

src/librustc_lint/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
113113
UnusedParens,
114114
UnusedImportBraces,
115115
AnonymousParameters,
116+
IllegalFloatLiteralPattern,
116117
);
117118

118119
add_early_builtin_with_new!(sess,
@@ -201,6 +202,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
201202
id: LintId::of(ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN),
202203
reference: "issue #36890 <https://github.com/rust-lang/rust/issues/36890>",
203204
},
205+
FutureIncompatibleInfo {
206+
id: LintId::of(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN),
207+
reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
208+
},
204209
FutureIncompatibleInfo {
205210
id: LintId::of(ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN),
206211
reference: "issue #36891 <https://github.com/rust-lang/rust/issues/36891>",

src/librustc_save_analysis/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ rustc = { path = "../librustc" }
1414
rustc_typeck = { path = "../librustc_typeck" }
1515
syntax = { path = "../libsyntax" }
1616
syntax_pos = { path = "../libsyntax_pos" }
17-
rls-data = "0.1"
18-
rls-span = "0.1"
17+
rls-data = "0.3"
18+
rls-span = "0.4"
1919
# FIXME(#40527) should move rustc serialize out of tree
2020
rustc-serialize = "0.3"

src/librustc_typeck/check/closure.rs

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
126126
(sig, kind)
127127
}
128128
ty::TyInfer(ty::TyVar(vid)) => self.deduce_expectations_from_obligations(vid),
129+
ty::TyFnPtr(sig) => (Some(sig.skip_binder().clone()), Some(ty::ClosureKind::Fn)),
129130
_ => (None, None),
130131
}
131132
}

src/librustc_typeck/check/method/confirm.rs

+31-17
Original file line numberDiff line numberDiff line change
@@ -433,22 +433,11 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
433433
for (i, &expr) in exprs.iter().rev().enumerate() {
434434
debug!("convert_lvalue_derefs_to_mutable: i={} expr={:?}", i, expr);
435435

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

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

503492
let method = self.try_overloaded_lvalue_op(
504493
expr.span, None, base_ty, arg_tys, PreferMutLvalue, op);
505-
let ok = method.expect("re-trying op failed");
494+
let ok = match method {
495+
Some(method) => method,
496+
None => return self.tcx.sess.delay_span_bug(expr.span, "re-trying op failed")
497+
};
506498
let method = self.register_infer_ok_obligations(ok);
507499
debug!("convert_lvalue_op_to_mutable: method={:?}", method);
508500
self.tables.borrow_mut().method_map.insert(method_call, method);
501+
502+
// Convert the autoref in the base expr to mutable with the correct
503+
// region and mutability.
504+
if let Some(&mut Adjustment {
505+
ref mut target, kind: Adjust::DerefRef {
506+
autoref: Some(AutoBorrow::Ref(ref mut r, ref mut mutbl)), ..
507+
}
508+
}) = self.tables.borrow_mut().adjustments.get_mut(&base_expr.id) {
509+
debug!("convert_lvalue_op_to_mutable: converting autoref of {:?}", target);
510+
511+
// extract method return type, which will be &mut T;
512+
// all LB regions should have been instantiated during method lookup
513+
let method_sig = self.tcx.no_late_bound_regions(&method.ty.fn_sig()).unwrap();
514+
515+
*target = method_sig.inputs()[0];
516+
if let ty::TyRef(r_, mt) = target.sty {
517+
*r = r_;
518+
*mutbl = mt.mutbl;
519+
} else {
520+
span_bug!(expr.span, "input to lvalue op is not a ref?");
521+
}
522+
}
509523
}
510524

511525
///////////////////////////////////////////////////////////////////////////

src/libsyntax/ext/base.rs

+12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use ptr::P;
2424
use symbol::Symbol;
2525
use util::small_vector::SmallVector;
2626

27+
use std::collections::HashMap;
2728
use std::path::PathBuf;
2829
use std::rc::Rc;
2930
use std::default::Default;
@@ -643,6 +644,7 @@ pub struct ExtCtxt<'a> {
643644
pub resolver: &'a mut Resolver,
644645
pub resolve_err_count: usize,
645646
pub current_expansion: ExpansionData,
647+
pub expansions: HashMap<Span, Vec<String>>,
646648
}
647649

648650
impl<'a> ExtCtxt<'a> {
@@ -662,6 +664,7 @@ impl<'a> ExtCtxt<'a> {
662664
module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }),
663665
directory_ownership: DirectoryOwnership::Owned,
664666
},
667+
expansions: HashMap::new(),
665668
}
666669
}
667670

@@ -765,6 +768,15 @@ impl<'a> ExtCtxt<'a> {
765768
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
766769
self.parse_sess.span_diagnostic.span_bug(sp, msg);
767770
}
771+
pub fn trace_macros_diag(&self) {
772+
for (sp, notes) in self.expansions.iter() {
773+
let mut db = self.parse_sess.span_diagnostic.span_note_diag(*sp, &"trace_macro");
774+
for note in notes {
775+
db.note(&note);
776+
}
777+
db.emit();
778+
}
779+
}
768780
pub fn bug(&self, msg: &str) -> ! {
769781
self.parse_sess.span_diagnostic.bug(msg);
770782
}

src/libsyntax/ext/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
231231
},
232232
_ => unreachable!(),
233233
};
234-
234+
self.cx.trace_macros_diag();
235235
krate
236236
}
237237

src/libsyntax/ext/tt/macro_rules.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use symbol::Symbol;
2727
use tokenstream::{TokenStream, TokenTree};
2828

2929
use std::cell::RefCell;
30-
use std::collections::{HashMap};
31-
use std::collections::hash_map::{Entry};
30+
use std::collections::HashMap;
31+
use std::collections::hash_map::Entry;
3232
use std::rc::Rc;
3333

3434
pub struct ParserAnyMacro<'a> {
@@ -85,15 +85,17 @@ impl TTMacroExpander for MacroRulesMacroExpander {
8585
}
8686

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

99101
// Which arm's failure should we report? (the one furthest along)

src/libsyntax/parse/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ impl<'a> StringReader<'a> {
504504
self.bump();
505505

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

510510
while !self.is_eof() {

src/test/compile-fail/closure-no-fn.rs renamed to src/test/compile-fail/closure-no-fn-1.rs

-6
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,4 @@ fn main() {
1515
let mut a = 0u8;
1616
let foo: fn(u8) -> u8 = |v: u8| { a += v; a };
1717
//~^ ERROR mismatched types
18-
let b = 0u8;
19-
let bar: fn() -> u8 = || { b };
20-
//~^ ERROR mismatched types
21-
let baz: fn() -> u8 = || { b } as fn() -> u8;
22-
//~^ ERROR mismatched types
23-
//~^^ ERROR non-scalar cast
2418
}

0 commit comments

Comments
 (0)