Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #57747

Merged
merged 27 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
284f0d3
Document that `-C opt-level=0` implies `-C debug-assertions`.
daxpedda Dec 26, 2018
11b0fa2
docs(rustc): Link to the book's source in rustc
phansch Dec 30, 2018
6bae4a7
Fix unused_assignments false positive
sinkuu Jan 3, 2019
069b0c4
Cleanup
sinkuu Jan 3, 2019
c120199
Show suggestion to use .char().nth() and link to The Book on unimplem…
folex Jan 5, 2019
f4ded5b
Add a regression test for mutating a non-mut #[thread_local]
mjbshaw Dec 24, 2018
e5e9867
Pass a default value when unwrapping a span
Jan 15, 2019
93b5536
use structured macro and path resolve suggestions
euclio Jan 15, 2019
ae4b14e
Use `Lit` rather than `P<Lit>` in `hir::ExprKind`.
nnethercote Jan 16, 2019
dc45528
Remove `hir::Label`.
nnethercote Jan 16, 2019
193809e
Add regression test to close #53787
Jan 16, 2019
3f0a75d
Remove trailing whitespace
Jan 16, 2019
0edc5c9
Fix error template
Jan 16, 2019
1e3f475
Add test for linking non-existent static library
Jan 17, 2019
e3ba6ed
Fix suggestions given mulitple bad lifetimes
dlrobertson Jan 17, 2019
ec3c5b0
Use structured suggestion to surround struct literal with parenthesis
estebank Jan 18, 2019
b9cb5db
Rollup merge of #57107 - mjbshaw:thread_local_test, r=nikomatsakis
Centril Jan 18, 2019
04a2cbd
Rollup merge of #57132 - daxpedda:master, r=steveklabnik
Centril Jan 18, 2019
bb683b9
Rollup merge of #57212 - phansch:improve_rustc_book_contributing, r=s…
Centril Jan 18, 2019
0dd4bfa
Rollup merge of #57302 - sinkuu:unused_assignments_fp, r=estebank
Centril Jan 18, 2019
49c74e4
Rollup merge of #57350 - folex:master, r=estebank
Centril Jan 18, 2019
f63e3d2
Rollup merge of #57635 - euclio:path-separators, r=michaelwoerister
Centril Jan 18, 2019
d2300af
Rollup merge of #57650 - AB1908:master, r=petrochenkov
Centril Jan 18, 2019
0eb4bdc
Rollup merge of #57657 - AB1908:regression-test-case, r=nikomatsakis
Centril Jan 18, 2019
857d27f
Rollup merge of #57658 - nnethercote:rm-hir-P-Lit, r=michaelwoerister
Centril Jan 18, 2019
42accf0
Rollup merge of #57720 - dlrobertson:fix_57521, r=estebank
Centril Jan 18, 2019
2a830e4
Rollup merge of #57725 - estebank:parens, r=michaelwoerister
Centril Jan 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doc/rustc/src/codegen-options/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ This flag lets you control debug information:

This flag lets you control the optimization level.

* `0`: no optimizations
* `0`: no optimizations, also turn on `cfg(debug_assertions)`.
* `1`: basic optimizations
* `2`: some optimizations
* `3`: all optimizations
Expand Down
8 changes: 7 additions & 1 deletion src/doc/rustc/src/contributing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Contributing to rustc

We'd love to have your help improving `rustc`! To that end, we've written [a
whole book](https://rust-lang.github.io/rustc-guide/) on its
whole book][rustc_guide] on its
internals, how it works, and how to get started working on it. To learn
more, you'll want to check that out.

If you would like to contribute to _this_ book, you can find its source in the
rustc source at [src/doc/rustc][rustc_book].

[rustc_guide]: https://rust-lang.github.io/rustc-guide/
[rustc_book]: https://github.com/rust-lang/rust/tree/master/src/doc/rustc
30 changes: 30 additions & 0 deletions src/libcore/ops/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@
/// ```
#[lang = "index"]
#[rustc_on_unimplemented(
on(
_Self="&str",
note="you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
),
on(
_Self="str",
note="you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
),
on(
_Self="std::string::String",
note="you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
),
message="the type `{Self}` cannot be indexed by `{Idx}`",
label="`{Self}` cannot be indexed by `{Idx}`",
)]
Expand Down Expand Up @@ -141,6 +156,21 @@ pub trait Index<Idx: ?Sized> {
/// ```
#[lang = "index_mut"]
#[rustc_on_unimplemented(
on(
_Self="&str",
note="you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
),
on(
_Self="str",
note="you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
),
on(
_Self="std::string::String",
note="you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
),
message="the type `{Self}` cannot be mutably indexed by `{Idx}`",
label="`{Self}` cannot be mutably indexed by `{Idx}`",
)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3775,7 +3775,7 @@ impl<'a> LoweringContext<'a> {
let ohs = P(self.lower_expr(ohs));
hir::ExprKind::Unary(op, ohs)
}
ExprKind::Lit(ref l) => hir::ExprKind::Lit(P((*l).clone())),
ExprKind::Lit(ref l) => hir::ExprKind::Lit((*l).clone()),
ExprKind::Cast(ref expr, ref ty) => {
let expr = P(self.lower_expr(expr));
hir::ExprKind::Cast(expr, self.lower_ty(ty, ImplTraitContext::disallowed()))
Expand Down
15 changes: 2 additions & 13 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use syntax_pos::{Span, DUMMY_SP, symbol::InternedString};
use syntax::source_map::{self, Spanned};
use rustc_target::spec::abi::Abi;
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, DUMMY_NODE_ID, AsmDialect};
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy};
use syntax::ast::{Attribute, Label, Lit, StrStyle, FloatTy, IntTy, UintTy};
use syntax::attr::InlineAttr;
use syntax::ext::hygiene::SyntaxContext;
use syntax::ptr::P;
Expand Down Expand Up @@ -142,17 +142,6 @@ pub const DUMMY_HIR_ID: HirId = HirId {

pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX;

#[derive(Clone, RustcEncodable, RustcDecodable, Copy)]
pub struct Label {
pub ident: Ident,
}

impl fmt::Debug for Label {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "label({:?})", self.ident)
}
}

#[derive(Clone, RustcEncodable, RustcDecodable, Copy)]
pub struct Lifetime {
pub id: NodeId,
Expand Down Expand Up @@ -1466,7 +1455,7 @@ pub enum ExprKind {
/// A unary operation (For example: `!x`, `*x`)
Unary(UnOp, P<Expr>),
/// A literal (For example: `1`, `"foo"`)
Lit(P<Lit>),
Lit(Lit),
/// A cast (`foo as f64`)
Cast(P<Expr>, P<Ty>),
Type(P<Expr>, P<Ty>),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl_stable_hash_for!(enum hir::LifetimeName {
Error,
});

impl_stable_hash_for!(struct hir::Label {
impl_stable_hash_for!(struct ast::Label {
ident
});

Expand Down
29 changes: 6 additions & 23 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,17 +911,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}

fn compute(&mut self, body: &hir::Expr) -> LiveNode {
// if there is a `break` or `again` at the top level, then it's
// effectively a return---this only occurs in `for` loops,
// where the body is really a closure.

debug!("compute: using id for body, {}", self.ir.tcx.hir().node_to_pretty_string(body.id));

let exit_ln = self.s.exit_ln;

self.break_ln.insert(body.id, exit_ln);
self.cont_ln.insert(body.id, exit_ln);

// the fallthrough exit is only for those cases where we do not
// explicitly return:
let s = self.s;
Expand Down Expand Up @@ -1024,19 +1015,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_expr(&e, succ)
}

hir::ExprKind::Closure(.., blk_id, _, _) => {
hir::ExprKind::Closure(..) => {
debug!("{} is an ExprKind::Closure",
self.ir.tcx.hir().node_to_pretty_string(expr.id));

// The next-node for a break is the successor of the entire
// loop. The next-node for a continue is the top of this loop.
let node = self.live_node(expr.hir_id, expr.span);

let break_ln = succ;
let cont_ln = node;
self.break_ln.insert(blk_id.node_id, break_ln);
self.cont_ln.insert(blk_id.node_id, cont_ln);

// the construction of a closure itself is not important,
// but we have to consider the closed over variables.
let caps = self.ir.capture_info_map.get(&expr.id).cloned().unwrap_or_else(||
Expand Down Expand Up @@ -1407,15 +1389,16 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
debug!("propagate_through_loop: using id for loop body {} {}",
expr.id, self.ir.tcx.hir().node_to_pretty_string(body.id));

let break_ln = succ;
let cont_ln = ln;
self.break_ln.insert(expr.id, break_ln);
self.cont_ln.insert(expr.id, cont_ln);

self.break_ln.insert(expr.id, succ);

let cond_ln = match kind {
LoopLoop => ln,
WhileLoop(ref cond) => self.propagate_through_expr(&cond, ln),
};

self.cont_ln.insert(expr.id, cond_ln);

let body_ln = self.propagate_through_block(body, cond_ln);

// repeat until fixed point is reached:
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ impl CodeSuggestion {
if let Some(line) = line_opt {
if let Some(lo) = line.char_indices().map(|(i, _)| i).nth(lo) {
let hi_opt = hi_opt.and_then(|hi| line.char_indices().map(|(i, _)| i).nth(hi));
buf.push_str(match hi_opt {
Some(hi) => &line[lo..hi],
None => &line[lo..],
});
match hi_opt {
Some(hi) if hi > lo => buf.push_str(&line[lo..hi]),
Some(_) => (),
None => buf.push_str(&line[lo..]),
}
}
if let None = hi_opt {
buf.push('\n');
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl<'a, 'tcx> Collector<'a, 'tcx> {
!self.tcx.features().static_nobundle {
feature_gate::emit_feature_err(&self.tcx.sess.parse_sess,
"static_nobundle",
span.unwrap(),
span.unwrap_or_else(|| syntax_pos::DUMMY_SP),
GateIssue::Language,
"kind=\"static-nobundle\" is feature gated");
}
Expand Down
66 changes: 56 additions & 10 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3318,7 +3318,12 @@ impl<'a> Resolver<'a> {
if let Some(def) = def {
match (def, source) {
(Def::Macro(..), _) => {
err.span_label(span, format!("did you mean `{}!(...)`?", path_str));
err.span_suggestion_with_applicability(
span,
"use `!` to invoke the macro",
format!("{}!", path_str),
Applicability::MaybeIncorrect,
);
return (err, candidates);
}
(Def::TyAlias(..), PathSource::Trait(_)) => {
Expand All @@ -3330,13 +3335,22 @@ impl<'a> Resolver<'a> {
}
(Def::Mod(..), PathSource::Expr(Some(parent))) => match parent.node {
ExprKind::Field(_, ident) => {
err.span_label(parent.span, format!("did you mean `{}::{}`?",
path_str, ident));
err.span_suggestion_with_applicability(
parent.span,
"use the path separator to refer to an item",
format!("{}::{}", path_str, ident),
Applicability::MaybeIncorrect,
);
return (err, candidates);
}
ExprKind::MethodCall(ref segment, ..) => {
err.span_label(parent.span, format!("did you mean `{}::{}(...)`?",
path_str, segment.ident));
let span = parent.span.with_hi(segment.ident.span.hi());
err.span_suggestion_with_applicability(
span,
"use the path separator to refer to an item",
format!("{}::{}", path_str, segment.ident),
Applicability::MaybeIncorrect,
);
return (err, candidates);
}
_ => {}
Expand Down Expand Up @@ -3387,6 +3401,29 @@ impl<'a> Resolver<'a> {
Ok(ref snippet) if snippet == "{" => true,
_ => false,
};
// In case this could be a struct literal that needs to be surrounded
// by parenthesis, find the appropriate span.
let mut i = 0;
let mut closing_brace = None;
loop {
sp = sm.next_point(sp);
match sm.span_to_snippet(sp) {
Ok(ref snippet) => {
if snippet == "}" {
let sp = span.to(sp);
if let Ok(snippet) = sm.span_to_snippet(sp) {
closing_brace = Some((sp, snippet));
}
break;
}
}
_ => break,
}
i += 1;
if i > 100 { // The bigger the span the more likely we're
break; // incorrect. Bound it to 100 chars long.
}
}
match source {
PathSource::Expr(Some(parent)) => {
match parent.node {
Expand All @@ -3413,11 +3450,20 @@ impl<'a> Resolver<'a> {
}
},
PathSource::Expr(None) if followed_by_brace == true => {
err.span_label(
span,
format!("did you mean `({} {{ /* fields */ }})`?",
path_str),
);
if let Some((sp, snippet)) = closing_brace {
err.span_suggestion_with_applicability(
sp,
"surround the struct literal with parenthesis",
format!("({})", snippet),
Applicability::MaybeIncorrect,
);
} else {
err.span_label(
span,
format!("did you mean `({} {{ /* fields */ }})`?",
path_str),
);
}
return (err, candidates);
},
_ => {
Expand Down
21 changes: 6 additions & 15 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5234,22 +5234,13 @@ impl<'a> Parser<'a> {
kind: ast::GenericParamKind::Lifetime,
});
if let Some(sp) = seen_ty_param {
let param_span = self.prev_span;
let ate_comma = self.eat(&token::Comma);
let remove_sp = if ate_comma {
param_span.until(self.span)
} else {
last_comma_span.unwrap_or(param_span).to(param_span)
};
bad_lifetime_pos.push(param_span);

if let Ok(snippet) = self.sess.source_map().span_to_snippet(param_span) {
let remove_sp = last_comma_span.unwrap_or(self.prev_span).to(self.prev_span);
bad_lifetime_pos.push(self.prev_span);
if let Ok(snippet) = self.sess.source_map().span_to_snippet(self.prev_span) {
suggestions.push((remove_sp, String::new()));
suggestions.push((sp.shrink_to_lo(), format!("{}, ", snippet)));
}
if ate_comma {
last_comma_span = Some(self.prev_span);
continue
suggestions.push((
sp.shrink_to_lo(),
format!("{}, ", snippet)));
}
}
} else if self.check_ident() {
Expand Down
12 changes: 9 additions & 3 deletions src/test/ui/error-codes/E0423.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,25 @@ error[E0423]: expected value, found struct `S`
--> $DIR/E0423.rs:12:32
|
LL | if let S { x: _x, y: 2 } = S { x: 1, y: 2 } { println!("Ok"); }
| ^ did you mean `(S { /* fields */ })`?
| ^---------------
| |
| help: surround the struct literal with parenthesis: `(S { x: 1, y: 2 })`

error[E0423]: expected value, found struct `T`
--> $DIR/E0423.rs:15:8
|
LL | if T {} == T {} { println!("Ok"); }
| ^ did you mean `(T { /* fields */ })`?
| ^---
| |
| help: surround the struct literal with parenthesis: `(T {})`

error[E0423]: expected value, found struct `std::ops::Range`
--> $DIR/E0423.rs:21:14
|
LL | for _ in std::ops::Range { start: 0, end: 10 } {}
| ^^^^^^^^^^^^^^^ did you mean `(std::ops::Range { /* fields */ })`?
| ^^^^^^^^^^^^^^^----------------------
| |
| help: surround the struct literal with parenthesis: `(std::ops::Range { start: 0, end: 10 })`

error: aborting due to 7 previous errors

Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/feature-gate/feature-gate-static-nobundle-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//~ ERROR kind="static-nobundle" is feature gated
// Test the behavior of rustc when non-existent library is statically linked

// compile-flags: -l static-nobundle=nonexistent

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error[E0658]: kind="static-nobundle" is feature gated (see issue #37403)
|
= help: add #![feature(static_nobundle)] to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
23 changes: 23 additions & 0 deletions src/test/ui/issue-53787-inline-assembler-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Regression test for Issue #53787: Fix ICE when creating a label in inline assembler with macros.

#![feature(asm)]

macro_rules! fake_jump {
($id:expr) => {
unsafe {
asm!(
"
jmp $0
lea eax, [ebx]
xor eax, 0xDEADBEEF
retn
$0:
"::"0"($id)::"volatile", "intel");
}
};
}

fn main() {
fake_jump!("FirstFunc"); //~ ERROR invalid value for constraint in inline assembly
println!("Hello, world!");
}
Loading