8000 Rollup of 12 pull requests by Centril · Pull Request #59428 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 12 pull requests #59428

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

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7fb1c22
promoted is still left in 2 places
Mar 16, 2019
a837b8a
cleaner code as per review
Mar 17, 2019
23c87a1
fixed all compilation errors
Mar 18, 2019
ac6ab65
adjust MaybeUninit API to discussions
RalfJung Mar 18, 2019
776407e
tidy checks
Mar 19, 2019
9374efa
fix some uses I missed
RalfJung Mar 19, 2019
8829dda
remove visit_static from librustc::mir
Mar 20, 2019
72f8d4e
Add no_hash to query macro and move some queries over
Zoxc Mar 20, 2019
b440041
Allow itertools
Zoxc Mar 20, 2019
d060e7d
Add no_force to query macro and move some queries over
Zoxc Mar 20, 2019
52374a6
Add anon to query macro and move a query over
Zoxc Mar 20, 2019
4d0a1e4
Add eval_always to query macro and move a query over
Zoxc Mar 20, 2019
75677c4
Fix whitespace
Zoxc Mar 20, 2019
71dfb01
Update build instructions in README.md
ewk Mar 21, 2019
cf2f1bb
review fixes
Mar 20, 2019
48af718
Expand `impl FromIterator for Option` doc to include example of early…
pnkfelix Mar 20, 2019
d5a61c0
Expand `impl FromIterator for Result` doc to include examples of `Err…
pnkfelix Mar 20, 2019
b34a71b
add suggestions to trim_{left,right} deprecations
euclio Mar 22, 2019
37cfeb2
Add/rename checked_duration_since tests
faern Mar 22, 2019
d56b1fd
Make duration_since use checked_duration_since
faern Mar 22, 2019
1ccad16
Update sys::time impls to have checked_sub_instant
faern Mar 22, 2019
8ba1a97
Expand suggestions for type ascription parse errors
estebank Mar 13, 2019
b1a6c32
Tweak labels
estebank Mar 13, 2019
72a3089
Only suggest let assignment for type ascription if we find an equals …
estebank Mar 13, 2019
81b876b
Hide "type ascription is experimental error" unless it's the only one
estebank Mar 13, 2019
44a086e
Review comment
estebank Mar 20, 2019
d72ef21
Reword type ascription note to reduce verbosity
estebank Mar 23, 2019
752544b
adding mir::StaticKind enum for static and promoted
Mar 23, 2019
fb93f10
code review fixes
Mar 24, 2019
8d7c2bb
replace redundant note in deprecation warning
euclio Mar 24, 2019
f5d6b3a
Moves test::black_box to core::hint
gnzlbg Mar 21, 2019
f244383
Remove dupplicated config
gnzlbg Mar 25, 2019
6315221
Update src/libcore/option.rs
killercup Mar 25, 2019
cfa76c4
black_box should inhibit optimizations on platforms without inline as…
gnzlbg Mar 25, 2019
0e83e96
add missing braces
pnkfelix Mar 25, 2019
0bb36a2
Clarify `{Ord,f32,f64}::clamp` docs a little
tbu- Mar 25, 2019
24db517
black_box should use inline assembly on wasm32
gnzlbg Mar 25, 2019
28c602a
Utilize `?` instead of `return None`.
frewsxcv Mar 25, 2019
3e7a5fd
Rollup merge of #59150 - estebank:type-ascription, r=varkor
Centril Mar 26, 2019
01af178
Rollup merge of #59232 - saleemjaffer:mir_place_refactor, r=oli-obk
Centril Mar 26, 2019
e061309
Rollup merge of #59284 - RalfJung:maybe-uninit, r=sfackler
Centril Mar 26, 2019
205d20a
Rollup merge of #59315 - Zoxc:move-query, r=oli-obk
Centril Mar 26, 2019
7b70515
Rollup merge of #59334 - ewk:readme, r=Mark-Simulacrum
Centril Mar 26, 2019
f9ae15f
Rollup merge of #59336 - gnzlbg:hint_black_box, r=alexcrichton
Centril Mar 26, 2019
ea51c8b
Rollup merge of #59362 - pnkfelix:demo-from-iterator-short-circuiting…
Centril Mar 26, 2019
cb15da7
Rollup merge of #59372 - euclio:rename-trim, r=rkruppe
Centril Mar 26, 2019
8aa161b
Rollup merge of #59374 - faern:simplify-checked-duration-since, r=she…
Centril Mar 26, 2019
e5f4755
Rollup merge of #59389 - euclio:deprecated-suggestion, r=varkor
Centril Mar 26, 2019
25f3ae9
Rollup merge of #59410 - tbu-:pr_doc_clarifyclamp, r=joshtriplett
Centril Mar 26, 2019
5059a9a
Rollup merge of #59419 - frewsxcv:frewsxcv-qu, r=varkor
Centril Mar 26, 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
64 changes: 57 additions & 7 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3262,32 +3262,82 @@ impl<'a> Resolver<'a> {
resolution
}

fn type_ascription_suggestion(&self,
err: &mut DiagnosticBuilder<'_>,
base_span: Span) {
/// Only used in a specific case of type ascription suggestions
#[doc(hidden)]
fn get_colon_suggestion_span(&self, start: Span) -> Span {
let cm = self.session.source_map();
start.to(cm.next_point(start))
}

fn type_ascription_suggestion(
&self,
err: &mut DiagnosticBuilder<'_>,
base_span: Span,
) {
debug!("type_ascription_suggetion {:?}", base_span);
let cm = self.session.source_map();
let base_snippet = cm.span_to_snippet(base_span);
debug!("self.current_type_ascription {:?}", self.current_type_ascription);
if let Some(sp) = self.current_type_ascription.last() {
let mut sp = *sp;
loop {
// Try to find the `:`; bail on first non-':' / non-whitespace.
sp = cm.next_point(sp);
if let Ok(snippet) = cm.span_to_snippet(sp.to(cm.next_point(sp))) {
debug!("snippet {:?}", snippet);
let line_sp = cm.lookup_char_pos(sp.hi()).line;
let line_base_sp = cm.lookup_char_pos(base_span.lo()).line;
debug!("{:?} {:?}", line_sp, line_base_sp);
if snippet == ":" {
err.span_label(base_span,
"expecting a type here because of type ascription");
let mut show_label = true;
if line_sp != line_base_sp {
err.span_suggestion_short(
sp,
"did you mean to use `;` here instead?",
";".to_string(),
Applicability::MaybeIncorrect,
);
} else {
let colon_sp = self.get_colon_suggestion_span(sp);
let after_colon_sp = self.get_colon_suggestion_span(
colon_sp.shrink_to_hi(),
);
if !cm.span_to_snippet(after_colon_sp).map(|s| s == " ")
.unwrap_or(false)
{
err.span_suggestion(
colon_sp,
"maybe you meant to write a path separator here",
"::".to_string(),
Applicability::MaybeIncorrect,
);
show_label = false;
}
if let Ok(base_snippet) = base_snippet {
let mut sp = after_colon_sp;
for _ in 0..100 {
// Try to find an assignment
sp = cm.next_point(sp);
let snippet = cm.span_to_snippet(sp.to(cm.next_point(sp)));
match snippet {
Ok(ref x) if x.as_str() == "=" => {
err.span_suggestion(
base_span,
"maybe you meant to write an assignment here",
format!("let {}", base_snippet),
Applicability::MaybeIncorrect,
);
show_label = false;
break;
}
Ok(ref x) if x.as_str() == "\n" => break,
Err(_) => break,
Ok(_) => {}
}
}
}
}
if show_label {
err.span_label(base_span,
"expecting a type here because of type ascription");
}
break;
} else if !snippet.trim().is_empty() {
Expand Down
8 changes: 6 additions & 2 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1836,8 +1836,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX);
}
ast::ExprKind::Type(..) => {
gate_feature_post!(&self, type_ascription, e.span,
"type ascription is experimental");
// To avoid noise about type ascription in common syntax errors, only emit if it
// is the *only* error.
if self.context.parse_sess.span_diagnostic.err_count() == 0 {
gate_feature_post!(&self, type_ascription, e.span,
"type ascription is experimental");
}
}
ast::ExprKind::ObsoleteInPlace(..) => {
// these get a hard error in ast-validation
Expand Down
75 changes: 62 additions & 13 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3538,22 +3538,19 @@ impl<'a> Parser<'a> {
lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Cast)?;
continue
} else if op == AssocOp::Colon {
let maybe_path = self.could_ascription_be_path(&lhs.node);
let next_sp = self.span;

lhs = match self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Type) {
Ok(lhs) => lhs,
Err(mut err) => {
err.span_label(self.span,
"expecting a type here because of type ascription");
let cm = self.sess.source_map();
let cur_pos = cm.lookup_char_pos(self.span.lo());
let op_pos = cm.lookup_char_pos(cur_op_span.hi());
if cur_pos.line != op_pos.line {
err.span_suggestion(
cur_op_span,
"try using a semicolon",
";".to_string(),
Applicability::MaybeIncorrect // speculative
);
}
self.bad_type_ascription(
&mut err,
lhs_span,
cur_op_span,
next_sp,
maybe_path,
);
return Err(err);
}
};
Expand Down Expand Up @@ -3658,6 +3655,58 @@ impl<'a> Parser<'a> {
Ok(lhs)
}

fn could_ascription_be_path(&self, node: &ast::ExprKind) -> bool {
self.token.is_ident() &&
if let ast::ExprKind::Path(..) = node { true } else { false } &&
!self.token.is_reserved_ident() && // v `foo:bar(baz)`
self.look_ahead(1, |t| t == &token::OpenDelim(token::Paren)) ||
self.look_ahead(1, |t| t == &token::Lt) && // `foo:bar<baz`
self.look_ahead(2, |t| t.is_ident()) ||
self.look_ahead(1, |t| t == &token::Colon) && // `foo:bar:baz`
self.look_ahead(2, |t| t.is_ident()) ||
self.look_ahead(1, |t| t == &token::ModSep) && // `foo:bar::baz`
self.look_ahead(2, |t| t.is_ident())
}

fn bad_type_ascription(
&self,
err: &mut DiagnosticBuilder<'a>,
lhs_span: Span,
cur_op_span: Span,
next_sp: Span,
maybe_path: bool,
) {
err.span_label(self.span, "expecting a type here because of type ascription");
let cm = self.sess.source_map();
let next_pos = cm.lookup_char_pos(next_sp.lo());
let op_pos = cm.lookup_char_pos(cur_op_span.hi());
if op_pos.line != next_pos.line {
err.span_suggestion(
cur_op_span,
"try using a semicolon",
";".to_string(),
Applicability::MaybeIncorrect,
);
} else {
if maybe_path {
err.span_suggestion(
cur_op_span,
"maybe you meant to write a path separator here",
"::".to_string(),
Applicability::MaybeIncorrect,
);
} else {
err.note("type ascription is a nightly-only feature that lets \
you annotate an expression with a type: `<expr>: <type>`");
err.span_note(
lhs_span,
"this expression expects an ascribed type after the colon",
);
err.help("this might be indicative of a syntax error elsewhere");
}
}
}

fn parse_assoc_op_cast(&mut self, lhs: P<Expr>, lhs_span: Span,
expr_kind: fn(P<Expr>, P<Ty>) -> ExprKind)
-> PResult<'a, P<Expr>> {
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/error-codes/E0423.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ error: expected type, found `1`
|
LL | if let S { x: _x, y: 2 } = S { x: 1, y: 2 } { println!("Ok"); }
| ^ expecting a type here because of type ascription
|
= note: type ascription is a nightly-only feature that lets you annotate an expression with a type: `<expr>: <type>`
note: this expression expects an ascribed type after the colon
--> $DIR/E0423.rs:12:36
|
LL | if let S { x: _x, y: 2 } = S { x: 1, y: 2 } { println!("Ok"); }
| ^
= help: this might be indicative of a syntax error elsewhere

error: expected expression, found `==`
--> $DIR/E0423.rs:15:13
Expand All @@ -15,6 +23,14 @@ error: expected type, found `0`
|
LL | for _ in std::ops::Range { start: 0, end: 10 } {}
| ^ expecting a type here because of type ascription
|
= note: type ascription is a nightly-only feature that lets you annotate an expression with a type: `<expr>: <type>`
note: this expression expects an ascribed type after the colon
--> $DIR/E0423.rs:21:32
|
LL | for _ in std::ops::Range { start: 0, end: 10 } {}
| ^^^^^
= help: this might be indicative of a syntax error elsewhere

error[E0423]: expected function, found struct `Foo`
--> $DIR/E0423.rs:4:13
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/issues/issue-22644.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ error: expected type, found `4`
|
LL | println!("{}", a: &mut 4);
| ^ expecting a type here because of type ascription
|
= note: type ascription is a nightly-only feature that lets you annotate an expression with a type: `<expr>: <type>`
note: this expression expects an ascribed type after the colon
--> $DIR/issue-22644.rs:34:20
|
LL | println!("{}", a: &mut 4);
| ^
= help: this might be indicative of a syntax error elsewhere

error: aborting due to 9 previous errors

10 changes: 10 additions & 0 deletions src/test/ui/issues/issue-34255-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
enum Test {
Drill {
field: i32,
}
}

fn main() {
Test::Drill(field: 42);
//~^ ERROR expected type, found
}
16 changes: 16 additions & 0 deletions src/test/ui/issues/issue-34255-1.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: expected type, found `42`
--> $DIR/issue-34255-1.rs:8:24
|
LL | Test::Drill(field: 42);
| ^^ expecting a type here because of type ascription
|
= note: type ascription is a nightly-only feature that lets you annotate an expression with a type: `<expr>: <type>`
note: this expression expects an ascribed type after the colon
--> $DIR/issue-34255-1.rs:8:17
|
LL | Test::Drill(field: 42);
| ^^^^^
= help: this might be indicative of a syntax error elsewhere

error: aborting due to previous error

8 changes: 8 additions & 0 deletions src/test/ui/lifetime_starts_expressions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ error: expected type, found keyword `loop`
|
LL | loop { break 'label: loop { break 'label 42; }; }
| ^^^^ expecting a type here because of type ascription
|
= note: type ascription is a nightly-only feature that lets you annotate an expression with a type: `<expr>: <type>`
note: this expression expects an ascribed type after the colon
--> $DIR/lifetime_starts_expressions.rs:6:12
|
LL | loop { break 'label: loop { break 'label 42; }; }
| ^^^^^^^^^^^^
= help: this might be indicative of a syntax error elsewhere

error: aborting due to 2 previous errors

8 changes: 8 additions & 0 deletions src/test/ui/parser/struct-literal-in-for.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ error: expected type, found `3`
|
LL | x: 3
| ^ expecting a type here because of type ascription
|
= note: type ascription is a nightly-only feature that lets you annotate an expression with a type: `<expr>: <type>`
note: this expression expects an ascribed type after the colon
--> $DIR/struct-literal-in-for.rs:13:9
|
LL | x: 3
| ^
= help: this might be indicative of a syntax error elsewhere

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `{`
--> $DIR/struct-literal-in-for.rs:14:12
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/parser/struct-literal-in-if.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ error: expected type, found `3`
|
LL | x: 3
| ^ expecting a type here because of type ascription
|
= note: type ascription is a nightly-only feature that lets you annotate an expression with a type: `<expr>: <type>`
note: this expression expects an ascribed type after the colon
--> $DIR/struct-literal-in-if.rs:13:9
|
LL | x: 3
| ^
= help: this might be indicative of a syntax error elsewhere

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `{`
--> $DIR/struct-literal-in-if.rs:14:12
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/parser/struct-literal-in-while.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ error: expected type, found `3`
|
LL | x: 3
| ^ expecting a type here because of type ascription
|
= note: type ascription is a nightly-only feature that lets you annotate an expression with a type: `<expr>: <type>`
note: this expression expects an ascribed type after the colon
--> $DIR/struct-literal-in-while.rs:13:9
|
LL | x: 3
| ^
= help: this might be indicative of a syntax error elsewhere

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `{`
--> $DIR/struct-literal-in-while.rs:14:12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ error: expected type, found `3`
|
LL | x: 3
| ^ expecting a type here because of type ascription
|
= note: type ascription is a nightly-only feature that lets you annotate an expression with a type: `<expr>: <type>`
note: this expression expects an ascribed type after the colon
--> $DIR/struct-literal-restrictions-in-lamda.rs:13:9
|
LL | x: 3
| ^
= help: this might be indicative of a syntax error elsewhere

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `{`
--> $DIR/struct-literal-restrictions-in-lamda.rs:14:12
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/suggestions/type-ascription-instead-of-let.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn fun(x: i32) -> i32 { x }

fn main() {
let closure_annotated = |value: i32| -> i32 {
temp: i32 = fun(5i32);
//~^ ERROR cannot find value `temp` in this scope
temp + value + 1
//~^ ERROR cannot find value `temp` in this scope
};
}
18 changes: 18 additions & 0 deletions src/test/ui/suggestions/type-ascription-instead-of-let.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0425]: cannot find value `temp` in this scope
--> $DIR/type-ascription-instead-of-let.rs:5:9
|
LL | temp: i32 = fun(5i32);
| ^^^^
| |
| not found in this scope
| help: maybe you meant to write an assignment here: `let temp`

error[E0425]: cannot find value `temp` in this scope
--> $DIR/type-ascription-instead-of-let.rs:7:9
|
LL | temp + value + 1
| ^^^^ not found in this scope

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.
4 changes: 4 additions & 0 deletions src/test/ui/suggestions/type-ascription-instead-of-method.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
Box:new("foo".to_string())
//~^ ERROR expected type, found
}
10 changes: 10 additions & 0 deletions src/test/ui/suggestions/type-ascription-instead-of-method.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: expected type, found `"foo"`
--> $DIR/type-ascription-instead-of-method.rs:2:13
|
LL | Box:new("foo".to_string())
| - ^^^^^ expecting a type here because of type ascription
| |
| help: maybe you meant to write a path separator here: `::`

error: aborting due to previous error

5 changes: 5 additions & 0 deletions src/test/ui/suggestions/type-ascription-instead-of-path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
std:io::stdin();
//~^ ERROR failed to resolve: use of undeclared type or module `io`
//~| ERROR expected value, found module
}
Loading
0