Skip to content

Commit f1b506a

Browse files
committed
Auto merge of #53607 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 10 pull requests Successful merges: - #53418 (Mark some suggestions as MachineApplicable) - #53431 (Moved some feature gate ui tests to correct location) - #53442 (Update version of rls-data used with save-analysis) - #53504 (Set applicability for more suggestions.) - #53541 (Fix missing impl trait display as ret type) - #53544 (Point at the trait argument when using unboxed closure) - #53558 (Normalize source line and column numbers.) - #53562 (Lament the invincibility of the Turbofish) - #53574 (Suggest direct raw-pointer dereference) - #53585 (Remove super old comment on function that parses items) Failed merges: - #53472 (Use FxHash{Map,Set} instead of the default Hash{Map,Set} everywhere in rustc.) - #53563 (use String::new() instead of String::from(""), "".to_string(), "".to_owned() or "".into()) r? @ghost
2 parents b75b047 + f012b4c commit f1b506a

29 files changed

+391
-147
lines changed

Diff for: src/Cargo.lock

+11-1
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,15 @@ dependencies = [
18581858
"serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
18591859
]
18601860

1861+
[[package]]
1862+
name = "rls-data"
1863+
version = "0.18.0"
1864+
source = "registry+https://github.com/rust-lang/crates.io-index"
1865+
dependencies = [
1866+
"rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
1867+
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
1868+
]
1869+
18611870
[[package]]
18621871
name = "rls-rustc"
18631872
version = "0.5.0"
@@ -2382,7 +2391,7 @@ name = "rustc_save_analysis"
23822391
version = "0.0.0"
23832392
dependencies = [
23842393
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
2385-
"rls-data 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
2394+
"rls-data 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
23862395
"rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
23872396
"rustc 0.0.0",
23882397
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3286,6 +3295,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
32863295
"checksum rls-analysis 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96f84d303dcbe1c1bdd41b10867d3399c38fbdac32c4e3645cdb6dbd7f82db1d"
32873296
"checksum rls-blacklist 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e4a9cc2545ccb7e05b355bfe047b8039a6ec12270d5f3c996b766b340a50f7d2"
32883297
"checksum rls-data 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3dd20763e1c60ae8945384c8a8fa4ac44f8afa7b0a817511f5e8927e5d24f988"
3298+
"checksum rls-data 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f81e838ecff6830ed33c2907fd236f38d441c206e983a2aa29fbce99295fab9"
32893299
"checksum rls-rustc 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9dba7390427aefa953608429701e3665192ca810ba8ae09301e001b7c7bed0"
32903300
"checksum rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d7c7046dc6a92f2ae02ed302746db4382e75131b9ce20ce967259f6b5867a6a"
32913301
"checksum rls-vfs 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ecbc8541b4c341d6271eae10f869dd9d36db871afe184f5b6f9bffbd6ed0373f"

Diff for: src/libcore/ptr.rs

+30
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,21 @@ impl<T: ?Sized> *const T {
582582
/// }
583583
/// }
584584
/// ```
585+
///
586+
/// # Null-unchecked version
587+
///
588+
/// If you are sure the pointer can never be null and are looking for some kind of
589+
/// `as_ref_unchecked` that returns the `&T` instead of `Option<&T>, know that you can
590+
/// dereference the pointer directly.
591+
///
592+
/// ```
593+
/// let ptr: *const u8 = &10u8 as *const u8;
594+
///
595+
/// unsafe {
596+
/// let val_back = &*ptr;
597+
/// println!("We got back the value: {}!", val_back);
598+
/// }
599+
/// ```
585600
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
586601
#[inline]
587602
pub unsafe fn as_ref<'a>(self) -> Option<&'a T> {
@@ -1303,6 +1318,21 @@ impl<T: ?Sized> *mut T {
13031318
/// }
13041319
/// }
13051320
/// ```
1321+
///
1322+
/// # Null-unchecked version
1323+
///
1324+
/// If you are sure the pointer can never be null and are looking for some kind of
1325+
/// `as_ref_unchecked` that returns the `&T` instead of `Option<&T>, know that you can
1326+
/// dereference the pointer directly.
1327+
///
1328+
/// ```
1329+
/// let ptr: *mut u8 = &mut 10u8 as *mut u8;
1330+
///
1331+
/// unsafe {
1332+
/// let val_back = &*ptr;
1333+
/// println!("We got back the value: {}!", val_back);
1334+
/// }
1335+
/// ```
13061336
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
13071337
#[inline]
13081338
pub unsafe fn as_ref<'a>(self) -> Option<&'a T> {

Diff for: src/librustc_borrowck/borrowck/gather_loans/move_error.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::ty;
1717
use rustc_mir::util::borrowck_errors::{BorrowckErrors, Origin};
1818
use syntax::ast;
1919
use syntax_pos;
20-
use errors::DiagnosticBuilder;
20+
use errors::{DiagnosticBuilder, Applicability};
2121
use borrowck::gather_loans::gather_moves::PatternSource;
2222

2323
pub struct MoveErrorCollector<'tcx> {
@@ -80,9 +80,12 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &[MoveErr
8080
let initializer =
8181
e.init.as_ref().expect("should have an initializer to get an error");
8282
if let Ok(snippet) = bccx.tcx.sess.source_map().span_to_snippet(initializer.span) {
83-
err.span_suggestion(initializer.span,
84-
"consider using a reference instead",
85-
format!("&{}", snippet));
83+
err.span_suggestion_with_applicability(
84+
initializer.span,
85+
"consider using a reference instead",
86+
format!("&{}", snippet),
87+
Applicability::MaybeIncorrect // using a reference may not be the right fix
88+
);
8689
}
8790
}
8891
_ => {

Diff for: src/librustc_borrowck/borrowck/unused.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc::hir::{self, HirId};
1313
use rustc::lint::builtin::UNUSED_MUT;
1414
use rustc::ty;
1515
use rustc::util::nodemap::{FxHashMap, FxHashSet};
16+
use errors::Applicability;
1617
use std::slice;
1718
use syntax::ptr::P;
1819

@@ -83,7 +84,11 @@ impl<'a, 'tcx> UnusedMutCx<'a, 'tcx> {
8384
hir_id,
8485
span,
8586
"variable does not need to be mutable")
86-
.span_suggestion_short(mut_span, "remove this `mut`", "".to_owned())
87+
.span_suggestion_short_with_applicability(
88+
mut_span,
89+
"remove this `mut`",
90+
"".to_owned(),
91+
Applicability::MachineApplicable)
8792
.emit();
8893
}
8994
}

Diff for: src/librustc_mir/borrow_check/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc::mir::{Terminator, TerminatorKind};
2424
use rustc::ty::query::Providers;
2525
use rustc::ty::{self, ParamEnv, TyCtxt, Ty};
2626

27-
use rustc_errors::{Diagnostic, DiagnosticBuilder, Level};
27+
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, Level};
2828
use rustc_data_structures::graph::dominators::Dominators;
2929
use rustc_data_structures::fx::FxHashSet;
3030
use rustc_data_structures::indexed_set::IdxSetBuf;
@@ -324,7 +324,11 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
324324
span,
325325
"variable does not need to be mutable",
326326
);
327-
err.span_suggestion_short(mut_span, "remove this `mut`", "".to_owned());
327+
err.span_suggestion_short_with_applicability(
328+
mut_span,
329+
"remove this `mut`",
330+
"".to_owned(),
331+
Applicability::MachineApplicable);
328332

329333
err.buffer(&mut mbcx.errors_buffer);
330334
}

Diff for: src/librustc_passes/ast_validation.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use syntax::symbol::keywords;
2525
use syntax::visit::{self, Visitor};
2626
use syntax_pos::Span;
2727
use errors;
28+
use errors::Applicability;
2829

2930
struct AstValidator<'a> {
3031
session: &'a Session,
@@ -185,11 +186,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
185186
);
186187
match val.node {
187188
ExprKind::Lit(ref v) if v.node.is_numeric() => {
188-
err.span_suggestion(
189+
err.span_suggestion_with_applicability(
189190
place.span.between(val.span),
190191
"if you meant to write a comparison against a negative value, add a \
191192
space in between `<` and `-`",
192193
"< -".to_string(),
194+
Applicability::MaybeIncorrect
193195
);
194196
}
195197
_ => {}

Diff for: src/librustc_resolve/macros.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use syntax::symbol::{Symbol, keywords};
3838
use syntax::tokenstream::{TokenStream, TokenTree, Delimited};
3939
use syntax::util::lev_distance::find_best_match_for_name;
4040
use syntax_pos::{Span, DUMMY_SP};
41+
use errors::Applicability;
4142

4243
use std::cell::Cell;
4344
use std::mem;
@@ -938,9 +939,19 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
938939
if let Some(suggestion) = suggestion {
939940
if suggestion != name {
940941
if let MacroKind::Bang = kind {
941-
err.span_suggestion(span, "you could try the macro", suggestion.to_string());
942+
err.span_suggestion_with_applicability(
943+
span,
944+
"you could try the macro",
945+
suggestion.to_string(),
946+
Applicability::MaybeIncorrect
947+
);
942948
} else {
943-
err.span_suggestion(span, "try", suggestion.to_string());
949+
err.span_suggestion_with_applicability(
950+
span,
951+
"try",
952+
suggestion.to_string(),
953+
Applicability::MaybeIncorrect
954+
);
944955
}
945956
} else {
946957
err.help("have you added the `#[macro_use]` on the module/import?");
@@ -1065,10 +1076,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
10651076
if let Some(span) = span {
10661077
let found_use = if found_use { "" } else { "\n" };
10671078
self.session.struct_span_err(err.use_span, err.warn_msg)
1068-
.span_suggestion(
1079+
.span_suggestion_with_applicability(
10691080
span,
10701081
"instead, import the procedural macro like any other item",
10711082
format!("use {}::{};{}", err.crate_name, err.name, found_use),
1083+
Applicability::MachineApplicable
10721084
).emit();
10731085
} else {
10741086
self.session.struct_span_err(err.use_span, err.warn_msg)

Diff for: src/librustc_save_analysis/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rustc_target = { path = "../librustc_target" }
1616
rustc_typeck = { path = "../librustc_typeck" }
1717
syntax = { path = "../libsyntax" }
1818
syntax_pos = { path = "../libsyntax_pos" }
19-
rls-data = "0.16"
19+
rls-data = "0.18"
2020
rls-span = "0.4"
2121
# FIXME(#40527) should move rustc serialize out of tree
2222
rustc-serialize = "0.3"

Diff for: src/librustc_typeck/check/callee.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoB
2020
use rustc_target::spec::abi;
2121
use syntax::ast::Ident;
2222
use syntax_pos::Span;
23+
use errors::Applicability;
2324

2425
use rustc::hir;
2526

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

236237
if let Some(ref path) = unit_variant {
237-
err.span_suggestion(call_expr.span,
238-
&format!("`{}` is a unit variant, you need to write it \
239-
without the parenthesis", path),
240-
path.to_string());
238+
err.span_suggestion_with_applicability(
239+
call_expr.span,
240+
&format!("`{}` is a unit variant, you need to write it \
241+
without the parenthesis", path),
242+
path.to_string(),
243+
Applicability::MachineApplicable
244+
);
241245
}
242246

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

0 commit comments

Comments
 (0)