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 9 pull requests #66978

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5a9b704
Improve comments about NodeStates.
nnethercote Nov 12, 2019
c45fc6b
Give two functions clearer names.
nnethercote Nov 14, 2019
c874789
remove dependency from libhermit
stlankes Nov 25, 2019
45aadf7
add `enclosing_scope` param to `rustc_on_unimplmented`
basil-cow Nov 22, 2019
1d0c015
added enclosing_scope attr to Try trait and fixed ui tests accordingly
basil-cow Nov 24, 2019
71abce1
document match and move keywords
DevinR528 Nov 30, 2019
b67d6c7
add example to move
DevinR528 Nov 30, 2019
44f3bee
add docs for move and match keywords
DevinR528 Nov 30, 2019
d5a4c62
remove trailing whitespace
DevinR528 Nov 30, 2019
c69be48
fix doc compile fail
DevinR528 Nov 30, 2019
7c3befc
add ";" for let = match
DevinR528 Nov 30, 2019
e4b2cb8
Add support for RISC-V 64-bit GNU/Linux
msizanoen1 Nov 23, 2019
930a0a2
Update libc
msizanoen1 Nov 30, 2019
a725a15
Miri core engine: use throw_ub instead of throw_panic
RalfJung Dec 1, 2019
15f159a
fix compile-fail tests
RalfJung Dec 1, 2019
ac57e1b
Remove ord lang item
CAD97 Dec 1, 2019
e638f7c
add grammer fixes
DevinR528 Dec 2, 2019
fe67196
Don't build the same matrix twice
Nadrieril Nov 3, 2019
21af89d
`UsefulWithWitness` always carries some witnesses
Nadrieril Nov 27, 2019
e6aa962
Simplify lifetimes by allocating patterns on the arena
Nadrieril Nov 28, 2019
00ccadf
Add some tests
Nadrieril Nov 29, 2019
5c7bd52
Lint for redundant branches in or-patterns
Nadrieril Nov 28, 2019
a476af2
Correct error on partially unreachable or-pat in `if let`
Nadrieril Nov 29, 2019
ef087d9
Move recently changed tests to the correct file
Nadrieril Nov 29, 2019
1c1bec2
Remove top-level or-pattern hack
Nadrieril Nov 29, 2019
a81804b
syntax: Introduce a struct `MacArgs` for macro arguments
petrochenkov Nov 30, 2019
0fac567
syntax: Remove redundant span from `ast::Mac`
petrochenkov Dec 1, 2019
1a496f3
syntax: Use `ast::MacArgs` for attributes
petrochenkov Dec 1, 2019
5378955
syntax: Use `ast::MacArgs` for macro definitions
petrochenkov Dec 1, 2019
cf71538
syntax: Optimize conversion `AttrItem` -> `MetaItem` by avoiding `out…
petrochenkov Dec 1, 2019
498737c
Address review comments
petrochenkov Dec 2, 2019
4cbab2b
Rollup merge of #66405 - nnethercote:tweak-ObligForest-NodeStates, r=…
Centril Dec 3, 2019
4b6ceb1
Rollup merge of #66651 - Areredify:on-unimplemented-scope, r=davidtwco
Centril Dec 3, 2019
98db3e7
Rollup merge of #66730 - hermitcore:master, r=alexcrichton
Centril Dec 3, 2019
e8b36c6
Rollup merge of #66899 - msizanoen1:riscv-std, r=alexcrichton
Centril Dec 3, 2019
2f09deb
Rollup merge of #66904 - DevinR528:keyword-doc, r=Dylan-DPC
Centril Dec 3, 2019
c1190d4
Rollup merge of #66927 - RalfJung:engines-dont-panic, r=oli-obk
Centril Dec 3, 2019
a7e51b5
Rollup merge of #66935 - petrochenkov:attrtok2, r=Centril
Centril Dec 3, 2019
29e5b0a
Rollup merge of #66941 - CAD97:nord, r=Dylan-DPC
Centril Dec 3, 2019
cc3b75a
Rollup merge of #66967 - Nadrieril:remove-or-pat-hack, r=varkor
Centril Dec 3, 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
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1821,9 +1821,9 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"

[[package]]
name = "libc"
version = "0.2.64"
version = "0.2.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74dfca3d9957906e8d1e6a0b641dc9a59848e793f1da2165889fd4f62d10d79c"
checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
1 change: 0 additions & 1 deletion src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ impl<T: Ord> Ord for Reverse<T> {
/// }
/// }
/// ```
#[lang = "ord"]
#[doc(alias = "<")]
#[doc(alias = ">")]
#[doc(alias = "<=")]
Expand Down
7 changes: 4 additions & 3 deletions src/libcore/ops/try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
/// extracting those success or failure values from an existing instance and
/// creating a new instance from a success or failure value.
#[unstable(feature = "try_trait", issue = "42327")]
#[rustc_on_unimplemented(
#[cfg_attr(not(bootstrap), rustc_on_unimplemented(
on(all(
any(from_method="from_error", from_method="from_ok"),
from_desugaring="QuestionMark"),
message="the `?` operator can only be used in {ItemContext} \
that returns `Result` or `Option` \
(or another type that implements `{Try}`)",
label="cannot use the `?` operator in {ItemContext} that returns `{Self}`"),
label="cannot use the `?` operator in {ItemContext} that returns `{Self}`",
enclosing_scope="this function should return `Result` or `Option` to accept `?`"),
on(all(from_method="into_result", from_desugaring="QuestionMark"),
message="the `?` operator can only be applied to values \
that implement `{Try}`",
label="the `?` operator cannot be applied to type `{Self}`")
)]
))]
#[doc(alias = "?")]
pub trait Try {
/// The type of this value when viewed as successful.
Expand Down
3 changes: 3 additions & 0 deletions src/libpanic_unwind/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ const UNWIND_DATA_REG: (i32, i32) = (24, 25); // I0, I1
#[cfg(target_arch = "hexagon")]
const UNWIND_DATA_REG: (i32, i32) = (0, 1); // R0, R1

#[cfg(target_arch = "riscv64")]
const UNWIND_DATA_REG: (i32, i32) = (10, 11); // x10, x11

// The following code is based on GCC's C and C++ personality routines. For reference, see:
// https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/libsupc++/eh_personality.cc
// https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c
Expand Down
12 changes: 11 additions & 1 deletion src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ impl<'a> LoweringContext<'a> {
AttrKind::Normal(ref item) => {
AttrKind::Normal(AttrItem {
path: item.path.clone(),
tokens: self.lower_token_stream(item.tokens.clone()),
args: self.lower_mac_args(&item.args),
})
}
AttrKind::DocComment(comment) => AttrKind::DocComment(comment)
Expand All @@ -1017,6 +1017,16 @@ impl<'a> LoweringContext<'a> {
}
}

fn lower_mac_args(&mut self, args: &MacArgs) -> MacArgs {
match *args {
MacArgs::Empty => MacArgs::Empty,
MacArgs::Delimited(dspan, delim, ref tokens) =>
MacArgs::Delimited(dspan, delim, self.lower_token_stream(tokens.clone())),
MacArgs::Eq(eq_span, ref tokens) =>
MacArgs::Eq(eq_span, self.lower_token_stream(tokens.clone())),
}
}

fn lower_token_stream(&mut self, tokens: TokenStream) -> TokenStream {
tokens
.into_trees()
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl LoweringContext<'_> {

if let ItemKind::MacroDef(ref def) = i.kind {
if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) {
let body = self.lower_token_stream(def.stream());
let body = self.lower_token_stream(def.body.inner_tokens());
let hir_id = self.lower_node_id(i.id);
self.exported_macros.push(hir::MacroDef {
name: ident.name,
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ language_item_table! {
// Don't be fooled by the naming here: this lang item denotes `PartialEq`, not `Eq`.
EqTraitLangItem, "eq", eq_trait, Target::Trait;
PartialOrdTraitLangItem, "partial_ord", partial_ord_trait, Target::Trait;
OrdTraitLangItem, "ord", ord_trait, Target::Trait;

// A number of panic-related lang items. The `panic` item corresponds to
// divide-by-zero and various panic cases with `match`. The
Expand Down
21 changes: 19 additions & 2 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ pub enum UndefinedBehaviorInfo {
Unreachable,
/// An enum discriminant was set to a value which was outside the range of valid values.
InvalidDiscriminant(ScalarMaybeUndef),
/// A slice/array index projection went out-of-bounds.
BoundsCheckFailed { len: u64, index: u64 },
/// Something was divided by 0 (x / 0).
DivisionByZero,
/// Something was "remainded" by 0 (x % 0).
RemainderByZero,
/// Overflowing inbounds pointer arithmetic.
PointerArithOverflow,
}

impl fmt::Debug for UndefinedBehaviorInfo {
Expand All @@ -379,9 +387,18 @@ impl fmt::Debug for UndefinedBehaviorInfo {
Ub(msg) | UbExperimental(msg) =>
write!(f, "{}", msg),
Unreachable =>
write!(f, "entered unreachable code"),
write!(f, "entering unreachable code"),
InvalidDiscriminant(val) =>
write!(f, "encountered invalid enum discriminant {}", val),
write!(f, "encountering invalid enum discriminant {}", val),
BoundsCheckFailed { ref len, ref index } =>
write!(f, "indexing out of bounds: the len is {:?} but the index is {:?}",
len, index),
DivisionByZero =>
write!(f, "dividing by zero"),
RemainderByZero =>
write!(f, "calculating the remainder with a divisor of zero"),
PointerArithOverflow =>
write!(f, "overflowing in-bounds pointer arithmetic"),
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::{AllocId, InterpResult};

use crate::mir;
use crate::ty::layout::{self, HasDataLayout, Size};

use rustc_macros::HashStable;
Expand Down Expand Up @@ -88,13 +87,13 @@ pub trait PointerArithmetic: layout::HasDataLayout {
#[inline]
fn offset<'tcx>(&self, val: u64, i: u64) -> InterpResult<'tcx, u64> {
let (res, over) = self.overflowing_offset(val, i);
if over { throw_panic!(Overflow(mir::BinOp::Add)) } else { Ok(res) }
if over { throw_ub!(PointerArithOverflow) } else { Ok(res) }
}

#[inline]
fn signed_offset<'tcx>(&self, val: u64, i: i64) -> InterpResult<'tcx, u64> {
let (res, over) = self.overflowing_signed_offset(val, i128::from(i));
if over { throw_panic!(Overflow(mir::BinOp::Add)) } else { Ok(res) }
if over { throw_ub!(PointerArithOverflow) } else { Ok(res) }
}
}

Expand Down
17 changes: 16 additions & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
) {
command.evaluate(self.tcx, trait_ref, &flags[..])
} else {
OnUnimplementedNote::empty()
OnUnimplementedNote::default()
}
}

Expand Down Expand Up @@ -697,6 +697,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
fallback_has_occurred: bool,
points_at_arg: bool,
) {
let tcx = self.tcx;
let span = obligation.cause.span;

let mut err = match *error {
Expand Down Expand Up @@ -732,6 +733,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
message,
label,
note,
enclosing_scope,
} = self.on_unimplemented_note(trait_ref, obligation);
let have_alt_message = message.is_some() || label.is_some();
let is_try = self.tcx.sess.source_map().span_to_snippet(span)
Expand Down Expand Up @@ -798,6 +800,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// If it has a custom `#[rustc_on_unimplemented]` note, let's display it
err.note(s.as_str());
}
if let Some(ref s) = enclosing_scope {
let enclosing_scope_span = tcx.def_span(
tcx.hir()
.opt_local_def_id(obligation.cause.body_id)
.unwrap_or_else(|| {
tcx.hir().body_owner_def_id(hir::BodyId {
hir_id: obligation.cause.body_id,
})
}),
);

err.span_label(enclosing_scope_span, s.as_str());
}

self.suggest_borrow_on_unsized_slice(&obligation.cause.code, &mut err);
self.suggest_fn_call(&obligation, &mut err, &trait_ref, points_at_arg);
Expand Down
46 changes: 33 additions & 13 deletions src/librustc/traits/on_unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ pub struct OnUnimplementedDirective {
pub message: Option<OnUnimplementedFormatString>,
pub label: Option<OnUnimplementedFormatString>,
pub note: Option<OnUnimplementedFormatString>,
pub enclosing_scope: Option<OnUnimplementedFormatString>,
}

#[derive(Default)]
pub struct OnUnimplementedNote {
pub message: Option<String>,
pub label: Option<String>,
pub note: Option<String>,
}

impl OnUnimplementedNote {
pub fn empty() -> Self {
OnUnimplementedNote { message: None, label: None, note: None }
}
pub enclosing_scope: Option<String>,
}

fn parse_error(
Expand Down Expand Up @@ -85,24 +82,33 @@ impl<'tcx> OnUnimplementedDirective {
let mut message = None;
let mut label = None;
let mut note = None;
let mut enclosing_scope = None;
let mut subcommands = vec![];

let parse_value = |value_str| {
OnUnimplementedFormatString::try_parse(tcx, trait_def_id, value_str, span)
.map(Some)
};

for item in item_iter {
if item.check_name(sym::message) && message.is_none() {
if let Some(message_) = item.value_str() {
message = Some(OnUnimplementedFormatString::try_parse(
tcx, trait_def_id, message_, span)?);
message = parse_value(message_)?;
continue;
}
} else if item.check_name(sym::label) && label.is_none() {
if let Some(label_) = item.value_str() {
label = Some(OnUnimplementedFormatString::try_parse(
tcx, trait_def_id, label_, span)?);
label = parse_value(label_)?;
continue;
}
} else if item.check_name(sym::note) && note.is_none() {
if let Some(note_) = item.value_str() {
note = Some(OnUnimplementedFormatString::try_parse(
tcx, trait_def_id, note_, span)?);
note = parse_value(note_)?;
continue;
}
} else if item.check_name(sym::enclosing_scope) && enclosing_scope.is_none() {
if let Some(enclosing_scope_) = item.value_str() {
enclosing_scope = parse_value(enclosing_scope_)?;
continue;
}
} else if item.check_name(sym::on) && is_root &&
Expand Down Expand Up @@ -130,7 +136,14 @@ impl<'tcx> OnUnimplementedDirective {
if errored {
Err(ErrorReported)
} else {
Ok(OnUnimplementedDirective { condition, message, label, subcommands, note })
Ok(OnUnimplementedDirective {
condition,
subcommands,
message,
label,
note,
enclosing_scope
})
}
}

Expand All @@ -157,6 +170,7 @@ impl<'tcx> OnUnimplementedDirective {
label: Some(OnUnimplementedFormatString::try_parse(
tcx, trait_def_id, value, attr.span)?),
note: None,
enclosing_scope: None,
}))
} else {
return Err(ErrorReported);
Expand All @@ -174,6 +188,7 @@ impl<'tcx> OnUnimplementedDirective {
let mut message = None;
let mut label = None;
let mut note = None;
let mut enclosing_scope = None;
info!("evaluate({:?}, trait_ref={:?}, options={:?})", self, trait_ref, options);

for command in self.subcommands.iter().chain(Some(self)).rev() {
Expand Down Expand Up @@ -202,6 +217,10 @@ impl<'tcx> OnUnimplementedDirective {
if let Some(ref note_) = command.note {
note = Some(note_.clone());
}

if let Some(ref enclosing_scope_) = command.enclosing_scope {
enclosing_scope = Some(enclosing_scope_.clone());
}
}

let options: FxHashMap<Symbol, String> = options.into_iter()
Expand All @@ -211,6 +230,7 @@ impl<'tcx> OnUnimplementedDirective {
label: label.map(|l| l.format(tcx, trait_ref, &options)),
message: message.map(|m| m.format(tcx, trait_ref, &options)),
note: note.map(|n| n.format(tcx, trait_ref, &options)),
enclosing_scope: enclosing_scope.map(|e_s| e_s.format(tcx, trait_ref, &options)),
}
}
}
Expand Down
Loading