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 5 pull requests #61234

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
725199c
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 2, 2019
7b4bc69
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 2, 2019
705d75e
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 2, 2019
4c4dbb1
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 2, 2019
3449fa9
Merge branch 'master' into issue_57128_improve_miri_error_reporting_i…
LooMaclin Apr 2, 2019
2a738bb
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 8, 2019
980db98
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 8, 2019
e5b6fab
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 8, 2019
11464e7
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 8, 2019
32ba4bd
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 8, 2019
9147e26
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 9, 2019
30a9626
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 10, 2019
0d97ad3
Update src/librustc/mir/interpret/allocation.rs
RalfJung Apr 16, 2019
15d50de
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 18, 2019
a54e3cc
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 18, 2019
fc7ffa6
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 23, 2019
b1c829b
Improve miri's error reporting in check_in_alloc
LooMaclin Apr 23, 2019
941ca6f
Clarify docs for unreachable! macro
blkerby May 23, 2019
27c7537
Remove phrase "instead of a panic!"
blkerby May 23, 2019
609ffa1
Reword malformed attribute input diagnostics
estebank May 22, 2019
ffd0dc7
Improve miri's error reporting in check_in_alloc
LooMaclin May 26, 2019
9e643e6
Improve miri's error reporting in check_in_alloc
LooMaclin May 26, 2019
5c5f08a
Use .await syntax instead of await!
diwic May 27, 2019
d6ca34c
Use `Symbol` more in lint APIs
oli-obk May 14, 2019
cea81b0
Rollup merge of #59627 - LooMaclin:issue_57128_improve_miri_error_rep…
Centril May 27, 2019
32d9b74
Rollup merge of #60827 - oli-obk:late_symbol, r=nnethercote
Centril May 27, 2019
b2cca1b
Rollup merge of #61084 - blkerby:unreachable_doc, r=KodrAus
Centril May 27, 2019
e3b66d6
Rollup merge of #61140 - estebank:attr-diagnostics, r=michaelwoerister
Centril May 27, 2019
88115b9
Rollup merge of #61227 - diwic:patch-2, r=Centril
Centril May 27, 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/libcore/future/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::task::{Context, Poll};
/// task.
///
/// When using a future, you generally won't call `poll` directly, but instead
/// `await!` the value.
/// `.await` the value.
#[doc(spotlight)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
#[stable(feature = "futures_api", since = "1.36.0")]
Expand Down
7 changes: 4 additions & 3 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,10 @@ macro_rules! writeln {
/// * Iterators that dynamically terminate.
///
/// If the determination that the code is unreachable proves incorrect, the
/// program immediately terminates with a [`panic!`]. The function [`unreachable_unchecked`],
/// which belongs to the [`std::hint`] module, informs the compiler to
/// optimize the code out of the release version entirely.
/// program immediately terminates with a [`panic!`].
///
/// The unsafe counterpart of this macro is the [`unreachable_unchecked`] function, which
/// will cause undefined behavior if the code is reached.
///
/// [`panic!`]: ../std/macro.panic.html
/// [`unreachable_unchecked`]: ../std/hint/fn.unreachable_unchecked.html
Expand Down
34 changes: 17 additions & 17 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,35 +759,35 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
/// # Examples
///
/// ```rust,ignore (no context or def id available)
/// if cx.match_def_path(def_id, &["core", "option", "Option"]) {
/// if cx.match_def_path(def_id, &[sym::core, sym::option, sym::Option]) {
/// // The given `def_id` is that of an `Option` type
/// }
/// ```
pub fn match_def_path(&self, def_id: DefId, path: &[&str]) -> bool {
pub fn match_def_path(&self, def_id: DefId, path: &[Symbol]) -> bool {
let names = self.get_def_path(def_id);

names.len() == path.len() && names.into_iter().zip(path.iter()).all(|(a, &b)| *a == *b)
names.len() == path.len() && names.into_iter().zip(path.iter()).all(|(a, &b)| a == b)
}

/// Gets the absolute path of `def_id` as a vector of `&str`.
/// Gets the absolute path of `def_id` as a vector of `Symbol`.
///
/// # Examples
///
/// ```rust,ignore (no context or def id available)
/// let def_path = cx.get_def_path(def_id);
/// if let &["core", "option", "Option"] = &def_path[..] {
/// if let &[sym::core, sym::option, sym::Option] = &def_path[..] {
/// // The given `def_id` is that of an `Option` type
/// }
/// ```
pub fn get_def_path(&self, def_id: DefId) -> Vec<LocalInternedString> {
pub fn get_def_path(&self, def_id: DefId) -> Vec<Symbol> {
pub struct AbsolutePathPrinter<'a, 'tcx> {
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
}

impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
type Error = !;

type Path = Vec<LocalInternedString>;
type Path = Vec<Symbol>;
type Region = ();
type Type = ();
type DynExistential = ();
Expand Down Expand Up @@ -820,14 +820,14 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
}

fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
Ok(vec![self.tcx.original_crate_name(cnum).as_str()])
Ok(vec![self.tcx.original_crate_name(cnum)])
}

fn path_qualified(
self,
self_ty: Ty<'tcx>,
trait_ref: Option<ty::TraitRef<'tcx>>,
) -> Result<Self::Path, Self::Error> {
) -> Result<Self::Path, Self::Error> {
if trait_ref.is_none() {
if let ty::Adt(def, substs) = self_ty.sty {
return self.print_def_path(def.did, substs);
Expand All @@ -836,8 +836,8 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {

// This shouldn't ever be needed, but just in case:
Ok(vec![match trait_ref {
Some(trait_ref) => LocalInternedString::intern(&format!("{:?}", trait_ref)),
None => LocalInternedString::intern(&format!("<{}>", self_ty)),
Some(trait_ref) => Symbol::intern(&format!("{:?}", trait_ref)),
None => Symbol::intern(&format!("<{}>", self_ty)),
}])
}

Expand All @@ -847,16 +847,16 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
_disambiguated_data: &DisambiguatedDefPathData,
self_ty: Ty<'tcx>,
trait_ref: Option<ty::TraitRef<'tcx>>,
) -> Result<Self::Path, Self::Error> {
) -> Result<Self::Path, Self::Error> {
let mut path = print_prefix(self)?;

// This shouldn't ever be needed, but just in case:
path.push(match trait_ref {
Some(trait_ref) => {
LocalInternedString::intern(&format!("<impl {} for {}>", trait_ref,
Symbol::intern(&format!("<impl {} for {}>", trait_ref,
self_ty))
},
None => LocalInternedString::intern(&format!("<impl {}>", self_ty)),
None => Symbol::intern(&format!("<impl {}>", self_ty)),
});

Ok(path)
Expand All @@ -866,7 +866,7 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
self,
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
disambiguated_data: &DisambiguatedDefPathData,
) -> Result<Self::Path, Self::Error> {
) -> Result<Self::Path, Self::Error> {
let mut path = print_prefix(self)?;

// Skip `::{{constructor}}` on tuple/unit structs.
Expand All @@ -875,15 +875,15 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
_ => {}
}

path.push(disambiguated_data.data.as_interned_str().as_str());
path.push(disambiguated_data.data.as_interned_str().as_symbol());
Ok(path)
}

fn path_generic_args(
self,
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
_args: &[Kind<'tcx>],
) -> Result<Self::Path, Self::Error> {
) -> Result<Self::Path, Self::Error> {
print_prefix(self)
}
}
Expand Down
26 changes: 16 additions & 10 deletions src/librustc/lint/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::lint::{
use errors::Applicability;
use rustc_data_structures::fx::FxHashMap;
use syntax::ast::Ident;
use syntax::symbol::{sym, Symbol};

declare_lint! {
pub DEFAULT_HASH_TYPES,
Expand All @@ -16,14 +17,16 @@ declare_lint! {
}

pub struct DefaultHashTypes {
map: FxHashMap<String, String>,
map: FxHashMap<Symbol, Symbol>,
}

impl DefaultHashTypes {
// we are allowed to use `HashMap` and `HashSet` as identifiers for implementing the lint itself
#[allow(internal)]
pub fn new() -> Self {
let mut map = FxHashMap::default();
map.insert("HashMap".to_string(), "FxHashMap".to_string());
map.insert("HashSet".to_string(), "FxHashSet".to_string());
map.insert(sym::HashMap, sym::FxHashMap);
map.insert(sym::HashSet, sym::FxHashSet);
Self { map }
}
}
Expand All @@ -32,11 +35,10 @@ impl_lint_pass!(DefaultHashTypes => [DEFAULT_HASH_TYPES]);

impl EarlyLintPass for DefaultHashTypes {
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: Ident) {
let ident_string = ident.to_string();
if let Some(replace) = self.map.get(&ident_string) {
if let Some(replace) = self.map.get(&ident.name) {
let msg = format!(
"Prefer {} over {}, it has better performance",
replace, ident_string
replace, ident
);
let mut db = cx.struct_span_lint(DEFAULT_HASH_TYPES, ident.span, &msg);
db.span_suggestion(
Expand Down Expand Up @@ -169,25 +171,29 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
}

fn lint_ty_kind_usage(cx: &LateContext<'_, '_>, segment: &PathSegment) -> bool {
if segment.ident.as_str() == "TyKind" {
if segment.ident.name == sym::TyKind {
if let Some(res) = segment.res {
if let Some(did) = res.opt_def_id() {
return cx.match_def_path(did, &["rustc", "ty", "sty", "TyKind"]);
return cx.match_def_path(did, TYKIND_PATH);
}
}
}

false
}

const TYKIND_PATH: &[Symbol] = &[sym::rustc, sym::ty, sym::sty, sym::TyKind];
const TY_PATH: &[Symbol] = &[sym::rustc, sym::ty, sym::Ty];
const TYCTXT_PATH: &[Symbol] = &[sym::rustc, sym::ty, sym::context, sym::TyCtxt];

fn is_ty_or_ty_ctxt(cx: &LateContext<'_, '_>, ty: &Ty) -> Option<String> {
match &ty.node {
TyKind::Path(qpath) => {
if let QPath::Resolved(_, path) = qpath {
let did = path.res.opt_def_id()?;
if cx.match_def_path(did, &["rustc", "ty", "Ty"]) {
if cx.match_def_path(did, TY_PATH) {
return Some(format!("Ty{}", gen_args(path.segments.last().unwrap())));
} else if cx.match_def_path(did, &["rustc", "ty", "context", "TyCtxt"]) {
} else if cx.match_def_path(did, TYCTXT_PATH) {
return Some(format!("TyCtxt{}", gen_args(path.segments.last().unwrap())));
}
}
Expand Down
33 changes: 20 additions & 13 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<'a> LintLevelsBuilder<'a> {
let store = self.sess.lint_store.borrow();
let sess = self.sess;
let bad_attr = |span| {
struct_span_err!(sess, span, E0452, "malformed lint attribute")
struct_span_err!(sess, span, E0452, "malformed lint attribute input")
};
for attr in attrs {
let level = match Level::from_symbol(attr.name_or_empty()) {
Expand Down Expand Up @@ -238,18 +238,20 @@ impl<'a> LintLevelsBuilder<'a> {
}
reason = Some(rationale);
} else {
let mut err = bad_attr(name_value.span);
err.help("reason must be a string literal");
err.emit();
bad_attr(name_value.span)
.span_label(name_value.span, "reason must be a string literal")
.emit();
}
} else {
let mut err = bad_attr(item.span);
err.emit();
bad_attr(item.span)
.span_label(item.span, "bad attribute argument")
.emit();
}
},
ast::MetaItemKind::List(_) => {
let mut err = bad_attr(item.span);
err.emit();
bad_attr(item.span)
.span_label(item.span, "bad attribute argument")
.emit();
}
}
}
Expand All @@ -258,14 +260,20 @@ impl<'a> LintLevelsBuilder<'a> {
let meta_item = match li.meta_item() {
Some(meta_item) if meta_item.is_word() => meta_item,
_ => {
let mut err = bad_attr(li.span());
let sp = li.span();
let mut err = bad_attr(sp);
let mut add_label = true;
if let Some(item) = li.meta_item() {
if let ast::MetaItemKind::NameValue(_) = item.node {
if item.path == sym::reason {
err.help("reason in lint attribute must come last");
err.span_label(sp, "reason in lint attribute must come last");
add_label = false;
}
}
}
if add_label {
err.span_label(sp, "bad attribute argument");
}
err.emit();
continue;
}
Expand Down Expand Up @@ -318,15 +326,14 @@ impl<'a> LintLevelsBuilder<'a> {
Also `cfg_attr(cargo-clippy)` won't be necessary anymore",
name
);
let mut err = lint::struct_lint_level(
lint::struct_lint_level(
self.sess,
lint,
lvl,
src,
Some(li.span().into()),
&msg,
);
err.span_suggestion(
).span_suggestion(
li.span(),
"change it to",
new_lint_name.to_string(),
Expand Down
39 changes: 32 additions & 7 deletions src/librustc/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::{

use crate::ty::layout::{Size, Align};
use syntax::ast::Mutability;
use std::iter;
use std::{iter, fmt::{self, Display}};
use crate::mir;
use std::ops::{Deref, DerefMut};
use rustc_data_structures::sorted_map::SortedMap;
Expand All @@ -22,6 +22,28 @@ pub enum InboundsCheck {
MaybeDead,
}

/// Used by `check_in_alloc` to indicate context of check
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)]
pub enum CheckInAllocMsg {
MemoryAccessTest,
NullPointerTest,
PointerArithmeticTest,
InboundsTest,
}

impl Display for CheckInAllocMsg {
/// When this is printed as an error the context looks like this
/// "{test name} failed: pointer must be in-bounds at offset..."
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", match *self {
CheckInAllocMsg::MemoryAccessTest => "Memory access",
CheckInAllocMsg::NullPointerTest => "Null pointer test",
CheckInAllocMsg::PointerArithmeticTest => "Pointer arithmetic",
CheckInAllocMsg::InboundsTest => "Inbounds test",
})
}
}

#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
pub struct Allocation<Tag=(),Extra=()> {
/// The actual bytes of the allocation.
Expand Down Expand Up @@ -131,9 +153,10 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
fn check_bounds_ptr(
&self,
ptr: Pointer<Tag>,
msg: CheckInAllocMsg,
) -> EvalResult<'tcx> {
let allocation_size = self.bytes.len() as u64;
ptr.check_in_alloc(Size::from_bytes(allocation_size), InboundsCheck::Live)
ptr.check_in_alloc(Size::from_bytes(allocation_size), msg)
}

/// Checks if the memory range beginning at `ptr` and of size `Size` is "in-bounds".
Expand All @@ -143,9 +166,10 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
cx: &impl HasDataLayout,
ptr: Pointer<Tag>,
size: Size,
msg: CheckInAllocMsg,
) -> EvalResult<'tcx> {
// if ptr.offset is in bounds, then so is ptr (because offset checks for overflow)
self.check_bounds_ptr(ptr.offset(size, cx)?)
self.check_bounds_ptr(ptr.offset(size, cx)?, msg)
}
}

Expand All @@ -164,9 +188,10 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
ptr: Pointer<Tag>,
size: Size,
check_defined_and_ptr: bool,
msg: CheckInAllocMsg,
) -> EvalResult<'tcx, &[u8]>
{
self.check_bounds(cx, ptr, size)?;
self.check_bounds(cx, ptr, size, msg)?;

if check_defined_and_ptr {
self.check_defined(ptr, size)?;
Expand All @@ -192,7 +217,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
size: Size,
) -> EvalResult<'tcx, &[u8]>
{
self.get_bytes_internal(cx, ptr, size, true)
self.get_bytes_internal(cx, ptr, size, true, CheckInAllocMsg::MemoryAccessTest)
}

/// It is the caller's responsibility to handle undefined and pointer bytes.
Expand All @@ -205,7 +230,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
size: Size,
) -> EvalResult<'tcx, &[u8]>
{
self.get_bytes_internal(cx, ptr, size, false)
self.get_bytes_internal(cx, ptr, size, false, CheckInAllocMsg::MemoryAccessTest)
}

/// Just calling this already marks everything as defined and removes relocations,
Expand All @@ -218,7 +243,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
) -> EvalResult<'tcx, &mut [u8]>
{
assert_ne!(size.bytes(), 0, "0-sized accesses should never even get a `Pointer`");
self.check_bounds(cx, ptr, size)?;
self.check_bounds(cx, ptr, size, CheckInAllocMsg::MemoryAccessTest)?;

self.mark_definedness(ptr, size, true)?;
self.clear_relocations(cx, ptr, size)?;
Expand Down
Loading