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 10 pull requests #53607

Merged
merged 20 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e665715
Mark some suggestions as MachineApplicable
ekse Aug 16, 2018
9511ffe
Moved some feature gate ui tests to correct location
alexreg Aug 16, 2018
a50f29a
Update version of rls-data used with save-analysis
staktrace Aug 17, 2018
5a23a0d
Set applicability for more suggestions.
ekse Aug 19, 2018
05d19fb
Point at the trait argument when using unboxed closure
estebank Aug 20, 2018
6e24868
Normalize source line and column numbers.
davidtwco Aug 21, 2018
18f41e5
Suggest direct raw-pointer dereference
vorner Aug 21, 2018
e67bba8
Fix missing impl trait display as ret type
GuillaumeGomez Aug 20, 2018
cf1b6d6
Remove super old comment on function that parses items
dtolnay Aug 22, 2018
3d5fef6
Lament the invincibility of the Turbofish
varkor Aug 21, 2018
8255f9e
Rollup merge of #53418 - ekse:suggestions-applicability, r=estebank
GuillaumeGomez Aug 22, 2018
da86fbd
Rollup merge of #53431 - alexreg:move-feature-gate-tests, r=cramertj
GuillaumeGomez Aug 22, 2018
55d9823
Rollup merge of #53442 - staktrace:rlsbump, r=nrc
GuillaumeGomez Aug 22, 2018
4fa4bb5
Rollup merge of #53504 - ekse:suggestions-applicability-2, r=estebank
GuillaumeGomez Aug 22, 2018
3d8e760
Rollup merge of #53541 - GuillaumeGomez:fix-impl-trait-ret-type, r=ol…
GuillaumeGomez Aug 22, 2018
e53a575
Rollup merge of #53544 - estebank:issue-53534, r=varkor
GuillaumeGomez Aug 22, 2018
95bdc65
Rollup merge of #53558 - davidtwco:issue-53547, r=estebank
GuillaumeGomez Aug 22, 2018
ef4b2ed
Rollup merge of #53562 - varkor:bastion-of-the-turbofish, r=nagisa
GuillaumeGomez Aug 22, 2018
4f78a2d
Rollup merge of #53574 - vorner:ptr_as_ref_unchecked, r=Mark-Simulacrum
GuillaumeGomez Aug 22, 2018
f012b4c
Rollup merge of #53585 - dtolnay:comment, r=Mark-Simulacrum
GuillaumeGomez Aug 22, 2018
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
12 changes: 11 additions & 1 deletion src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,15 @@ dependencies = [
"serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "rls-data"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "rls-rustc"
version = "0.5.0"
Expand Down Expand Up @@ -2382,7 +2391,7 @@ name = "rustc_save_analysis"
version = "0.0.0"
dependencies = [
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rls-data 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rls-data 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc 0.0.0",
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -3286,6 +3295,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rls-analysis 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96f84d303dcbe1c1bdd41b10867d3399c38fbdac32c4e3645cdb6dbd7f82db1d"
"checksum rls-blacklist 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e4a9cc2545ccb7e05b355bfe047b8039a6ec12270d5f3c996b766b340a50f7d2"
"checksum rls-data 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3dd20763e1c60ae8945384c8a8fa4ac44f8afa7b0a817511f5e8927e5d24f988"
"checksum rls-data 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f81e838ecff6830ed33c2907fd236f38d441c206e983a2aa29fbce99295fab9"
"checksum rls-rustc 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9dba7390427aefa953608429701e3665192ca810ba8ae09301e001b7c7bed0"
"checksum rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d7c7046dc6a92f2ae02ed302746db4382e75131b9ce20ce967259f6b5867a6a"
"checksum rls-vfs 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ecbc8541b4c341d6271eae10f869dd9d36db871afe184f5b6f9bffbd6ed0373f"
Expand Down
30 changes: 30 additions & 0 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,21 @@ impl<T: ?Sized> *const T {
/// }
/// }
/// ```
///
/// # Null-unchecked version
///
/// If you are sure the pointer can never be null and are looking for some kind of
/// `as_ref_unchecked` that returns the `&T` instead of `Option<&T>, know that you can
/// dereference the pointer directly.
///
/// ```
/// let ptr: *const u8 = &10u8 as *const u8;
///
/// unsafe {
/// let val_back = &*ptr;
/// println!("We got back the value: {}!", val_back);
/// }
/// ```
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
#[inline]
pub unsafe fn as_ref<'a>(self) -> Option<&'a T> {
Expand Down Expand Up @@ -1303,6 +1318,21 @@ impl<T: ?Sized> *mut T {
/// }
/// }
/// ```
///
/// # Null-unchecked version
///
/// If you are sure the pointer can never be null and are looking for some kind of
/// `as_ref_unchecked` that returns the `&T` instead of `Option<&T>, know that you can
/// dereference the pointer directly.
///
/// ```
/// let ptr: *mut u8 = &mut 10u8 as *mut u8;
///
/// unsafe {
/// let val_back = &*ptr;
/// println!("We got back the value: {}!", val_back);
/// }
/// ```
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
#[inline]
pub unsafe fn as_ref<'a>(self) -> Option<&'a T> {
Expand Down
11 changes: 7 additions & 4 deletions src/librustc_borrowck/borrowck/gather_loans/move_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc::ty;
use rustc_mir::util::borrowck_errors::{BorrowckErrors, Origin};
use syntax::ast;
use syntax_pos;
use errors::DiagnosticBuilder;
use errors::{DiagnosticBuilder, Applicability};
use borrowck::gather_loans::gather_moves::PatternSource;

pub struct MoveErrorCollector<'tcx> {
Expand Down Expand Up @@ -80,9 +80,12 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &[MoveErr
let initializer =
e.init.as_ref().expect("should have an initializer to get an error");
if let Ok(snippet) = bccx.tcx.sess.source_map().span_to_snippet(initializer.span) {
err.span_suggestion(initializer.span,
"consider using a reference instead",
format!("&{}", snippet));
err.span_suggestion_with_applicability(
initializer.span,
"consider using a reference instead",
format!("&{}", snippet),
Applicability::MaybeIncorrect // using a reference may not be the right fix
);
}
}
_ => {
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_borrowck/borrowck/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rustc::hir::{self, HirId};
use rustc::lint::builtin::UNUSED_MUT;
use rustc::ty;
use rustc::util::nodemap::{FxHashMap, FxHashSet};
use errors::Applicability;
use std::slice;
use syntax::ptr::P;

Expand Down Expand Up @@ -83,7 +84,11 @@ impl<'a, 'tcx> UnusedMutCx<'a, 'tcx> {
hir_id,
span,
"variable does not need to be mutable")
.span_suggestion_short(mut_span, "remove this `mut`", "".to_owned())
.span_suggestion_short_with_applicability(
mut_span,
"remove this `mut`",
"".to_owned(),
Applicability::MachineApplicable)
.emit();
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rustc::mir::{Terminator, TerminatorKind};
use rustc::ty::query::Providers;
use rustc::ty::{self, ParamEnv, TyCtxt, Ty};

use rustc_errors::{Diagnostic, DiagnosticBuilder, Level};
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, Level};
use rustc_data_structures::graph::dominators::Dominators;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::indexed_set::IdxSetBuf;
Expand Down Expand Up @@ -324,7 +324,11 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
span,
"variable does not need to be mutable",
);
err.span_suggestion_short(mut_span, "remove this `mut`", "".to_owned());
err.span_suggestion_short_with_applicability(
mut_span,
"remove this `mut`",
"".to_owned(),
Applicability::MachineApplicable);

err.buffer(&mut mbcx.errors_buffer);
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use syntax::symbol::keywords;
use syntax::visit::{self, Visitor};
use syntax_pos::Span;
use errors;
use errors::Applicability;

struct AstValidator<'a> {
session: &'a Session,
Expand Down Expand Up @@ -185,11 +186,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
);
match val.node {
ExprKind::Lit(ref v) if v.node.is_numeric() => {
err.span_suggestion(
err.span_suggestion_with_applicability(
place.span.between(val.span),
"if you meant to write a comparison against a negative value, add a \
space in between `<` and `-`",
"< -".to_string(),
Applicability::MaybeIncorrect
);
}
_ => {}
Expand Down
18 changes: 15 additions & 3 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use syntax::symbol::{Symbol, keywords};
use syntax::tokenstream::{TokenStream, TokenTree, Delimited};
use syntax::util::lev_distance::find_best_match_for_name;
use syntax_pos::{Span, DUMMY_SP};
use errors::Applicability;

use std::cell::Cell;
use std::mem;
Expand Down Expand Up @@ -938,9 +939,19 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
if let Some(suggestion) = suggestion {
if suggestion != name {
if let MacroKind::Bang = kind {
err.span_suggestion(span, "you could try the macro", suggestion.to_string());
err.span_suggestion_with_applicability(
span,
"you could try the macro",
suggestion.to_string(),
Applicability::MaybeIncorrect
);
} else {
err.span_suggestion(span, "try", suggestion.to_string());
err.span_suggestion_with_applicability(
span,
"try",
suggestion.to_string(),
Applicability::MaybeIncorrect
);
}
} else {
err.help("have you added the `#[macro_use]` on the module/import?");
Expand Down Expand Up @@ -1065,10 +1076,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
if let Some(span) = span {
let found_use = if found_use { "" } else { "\n" };
self.session.struct_span_err(err.use_span, err.warn_msg)
.span_suggestion(
.span_suggestion_with_applicability(
span,
"instead, import the procedural macro like any other item",
format!("use {}::{};{}", err.crate_name, err.name, found_use),
Applicability::MachineApplicable
).emit();
} else {
self.session.struct_span_err(err.use_span, err.warn_msg)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rustc_target = { path = "../librustc_target" }
rustc_typeck = { path = "../librustc_typeck" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
rls-data = "0.16"
rls-data = "0.18"
rls-span = "0.4"
# FIXME(#40527) should move rustc serialize out of tree
rustc-serialize = "0.3"
12 changes: 8 additions & 4 deletions src/librustc_typeck/check/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoB
use rustc_target::spec::abi;
use syntax::ast::Ident;
use syntax_pos::Span;
use errors::Applicability;

use rustc::hir;

Expand Down Expand Up @@ -234,10 +235,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
err.span_label(call_expr.span, "not a function");

if let Some(ref path) = unit_variant {
err.span_suggestion(call_expr.span,
&format!("`{}` is a unit variant, you need to write it \
without the parenthesis", path),
path.to_string());
err.span_suggestion_with_applicability(
call_expr.span,
&format!("`{}` is a unit variant, you need to write it \
without the parenthesis", path),
path.to_string(),
Applicability::MachineApplicable
);
}

if let hir::ExprKind::Call(ref expr, _) = call_expr.node {
Expand Down
Loading