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 11 pull requests #77589

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
492826a
Add a note about the panic behavior of math operations on time objects
poliorcetics Sep 5, 2020
a6ff925
Reduce boilerplate with the matches! macro
LingMan Sep 21, 2020
b4e77d2
rewrite old test so that its attributes are consistent with what we w…
pnkfelix Jun 15, 2020
9601724
Avoid unchecked casts in net parser
tamird Oct 4, 2020
f78a7ad
Inline "eof" methods
tamird Oct 4, 2020
afa2a67
Prevent forbid from being ignored if overriden at the same level.
pnkfelix Jun 15, 2020
5ab1967
Remove extra indirection in LitKind::ByteStr
rschoon Sep 17, 2020
62f7712
Change clippy's Constant back to refcount clone byte strings
rschoon Oct 4, 2020
b205436
Allow anyone to set regression labels
camelid Oct 4, 2020
afe83d4
Rename bootstrap/defaults/{config.toml.PROFILE => config.PROFILE.toml}
thomcc Oct 5, 2020
5388eb4
Add changelog entry mentioning the renamed profile files
thomcc Oct 5, 2020
daf48b8
inliner: use caller param_env
lcnr Oct 5, 2020
b1ce619
Add missing examples for MaybeUninit
GuillaumeGomez Sep 26, 2020
9704911
Use matches! for core::char methods
pickfire Oct 5, 2020
35192ff
Fix span for unicode escape suggestion.
ehuss Oct 5, 2020
7c2dd01
Rollup merge of #76388 - poliorcetics:system-time-document-panic, r=K…
jonas-schievink Oct 5, 2020
886e030
Rollup merge of #76995 - LingMan:middle_matches, r=varkor
jonas-schievink Oct 5, 2020
01d45ec
Rollup merge of #77228 - GuillaumeGomez:maybeuninit-examples, r=pickfire
jonas-schievink Oct 5, 2020
5b97a70
Rollup merge of #77528 - tamird:avoid-cast-net-parser, r=dtolnay
jonas-schievink Oct 5, 2020
8f33841
Rollup merge of #77534 - Mark-Simulacrum:issue-70819-disallow-overrid…
jonas-schievink Oct 5, 2020
2e185c7
Rollup merge of #77555 - camelid:patch-8, r=Mark-Simulacrum
jonas-schievink Oct 5, 2020
5b56541
Rollup merge of #77558 - thomcc:defaults-toml-extension, r=jyn514
jonas-schievink Oct 5, 2020
04d9ae4
Rollup merge of #77560 - rschoon:fix-litkind-rc-bytebuf, r=lcnr
jonas-schievink Oct 5, 2020
6d1cc0d
Rollup merge of #77568 - lcnr:mir-inline-def-id, r=ecstatic-morse
jonas-schievink Oct 5, 2020
6fbda95
Rollup merge of #77571 - pickfire:patch-6, r=cramertj
jonas-schievink Oct 5, 2020
7af4959
Rollup merge of #77587 - ehuss:unicode-escape-span, r=ecstatic-morse
jonas-schievink Oct 5, 2020
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 compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ pub enum LitKind {
/// A string literal (`"foo"`).
Str(Symbol, StrStyle),
/// A byte string (`b"foo"`).
ByteStr(Lrc<Vec<u8>>),
ByteStr(Lrc<[u8]>),
/// A byte char (`b'f'`).
Byte(u8),
/// A character literal (`'a'`).
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_ast/src/util/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::ast::{self, Lit, LitKind};
use crate::token::{self, Token};
use crate::tokenstream::TokenTree;

use rustc_data_structures::sync::Lrc;
use rustc_lexer::unescape::{unescape_byte, unescape_char};
use rustc_lexer::unescape::{unescape_byte_literal, unescape_literal, Mode};
use rustc_span::symbol::{kw, sym, Symbol};
Expand Down Expand Up @@ -108,7 +107,7 @@ impl LitKind {
});
error?;
buf.shrink_to_fit();
LitKind::ByteStr(Lrc::new(buf))
LitKind::ByteStr(buf.into())
}
token::ByteStrRaw(_) => {
let s = symbol.as_str();
Expand All @@ -128,7 +127,7 @@ impl LitKind {
symbol.to_string().into_bytes()
};

LitKind::ByteStr(Lrc::new(bytes))
LitKind::ByteStr(bytes.into())
}
token::Err => LitKind::Err(symbol),
})
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_builtin_macros/src/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use rustc_span::{self, Pos, Span};
use smallvec::SmallVec;
use std::rc::Rc;

use rustc_data_structures::sync::Lrc;

// These macros all relate to the file system; they either return
// the column/row/filename of the expression, or they include
// a given file into the current one.
Expand Down Expand Up @@ -216,7 +214,7 @@ pub fn expand_include_bytes(
}
};
match cx.source_map().load_binary_file(&file) {
Ok(bytes) => base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes)))),
Ok(bytes) => base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(bytes.into()))),
Err(e) => {
cx.span_err(sp, &format!("couldn't read {}: {}", file.display(), e));
DummyResult::any(sp)
Expand Down
47 changes: 43 additions & 4 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_hir::{intravisit, HirId};
use rustc_middle::hir::map::Map;
use rustc_middle::lint::LevelSource;
use rustc_middle::lint::LintDiagnosticBuilder;
use rustc_middle::lint::{struct_lint_level, LintLevelMap, LintLevelSets, LintSet, LintSource};
use rustc_middle::ty::query::Providers;
Expand Down Expand Up @@ -95,6 +96,44 @@ impl<'s> LintLevelsBuilder<'s> {
self.sets.list.push(LintSet::CommandLine { specs });
}

/// Attempts to insert the `id` to `level_src` map entry. If unsuccessful
/// (e.g. if a forbid was already inserted on the same scope), then emits a
/// diagnostic with no change to `specs`.
fn insert_spec(
&mut self,
specs: &mut FxHashMap<LintId, LevelSource>,
id: LintId,
(level, src): LevelSource,
) {
if let Some((old_level, old_src)) = specs.get(&id) {
if old_level == &Level::Forbid && level != Level::Forbid {
let mut diag_builder = struct_span_err!(
self.sess,
src.span(),
E0453,
"{}({}) incompatible with previous forbid in same scope",
level.as_str(),
src.name(),
);
match *old_src {
LintSource::Default => {}
LintSource::Node(_, forbid_source_span, reason) => {
diag_builder.span_label(forbid_source_span, "`forbid` level set here");
if let Some(rationale) = reason {
diag_builder.note(&rationale.as_str());
}
}
LintSource::CommandLine(_) => {
diag_builder.note("`forbid` lint level was set on command line");
}
}
diag_builder.emit();
return;
}
}
specs.insert(id, (level, src));
}

/// Pushes a list of AST lint attributes onto this context.
///
/// This function will return a `BuilderPush` object which should be passed
Expand All @@ -109,7 +148,7 @@ impl<'s> LintLevelsBuilder<'s> {
/// `#[allow]`
///
/// Don't forget to call `pop`!
pub fn push(
pub(crate) fn push(
&mut self,
attrs: &[ast::Attribute],
store: &LintStore,
Expand Down Expand Up @@ -221,7 +260,7 @@ impl<'s> LintLevelsBuilder<'s> {
let src = LintSource::Node(name, li.span(), reason);
for &id in ids {
self.check_gated_lint(id, attr.span);
specs.insert(id, (level, src));
self.insert_spec(&mut specs, id, (level, src));
}
}

Expand All @@ -235,7 +274,7 @@ impl<'s> LintLevelsBuilder<'s> {
reason,
);
for id in ids {
specs.insert(*id, (level, src));
self.insert_spec(&mut specs, *id, (level, src));
}
}
Err((Some(ids), new_lint_name)) => {
Expand Down Expand Up @@ -272,7 +311,7 @@ impl<'s> LintLevelsBuilder<'s> {
reason,
);
for id in ids {
specs.insert(*id, (level, src));
self.insert_spec(&mut specs, *id, (level, src));
}
}
Err((None, _)) => {
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,15 +535,15 @@ impl<'hir> Map<'hir> {
Some(Node::Binding(_)) => (),
_ => return false,
}
match self.find(self.get_parent_node(id)) {
matches!(
self.find(self.get_parent_node(id)),
Some(
Node::Item(_)
| Node::TraitItem(_)
| Node::ImplItem(_)
| Node::Expr(Expr { kind: ExprKind::Closure(..), .. }),
) => true,
_ => false,
}
)
)
}

/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
Expand All @@ -554,10 +554,10 @@ impl<'hir> Map<'hir> {

/// Whether `hir_id` corresponds to a `mod` or a crate.
pub fn is_hir_id_module(&self, hir_id: HirId) -> bool {
match self.get_entry(hir_id).node {
Node::Item(Item { kind: ItemKind::Mod(_), .. }) | Node::Crate(..) => true,
_ => false,
}
matches!(
self.get_entry(hir_id).node,
Node::Item(Item { kind: ItemKind::Mod(_), .. }) | Node::Crate(..)
)
}

/// Retrieves the `HirId` for `id`'s enclosing method, unless there's a
Expand Down
20 changes: 19 additions & 1 deletion compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_session::lint::{builtin, Level, Lint, LintId};
use rustc_session::{DiagnosticMessageId, Session};
use rustc_span::hygiene::MacroKind;
use rustc_span::source_map::{DesugaringKind, ExpnKind, MultiSpan};
use rustc_span::{Span, Symbol};
use rustc_span::{symbol, Span, Symbol, DUMMY_SP};

/// How a lint level was set.
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
Expand All @@ -25,6 +25,24 @@ pub enum LintSource {
CommandLine(Symbol),
}

impl LintSource {
pub fn name(&self) -> Symbol {
match *self {
LintSource::Default => symbol::kw::Default,
LintSource::Node(name, _, _) => name,
LintSource::CommandLine(name) => name,
}
}

pub fn span(&self) -> Span {
match *self {
LintSource::Default => DUMMY_SP,
LintSource::Node(_, span, _) => span,
LintSource::CommandLine(_) => DUMMY_SP,
}
}
}

pub type LevelSource = (Level, LintSource);

pub struct LintLevelSets {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,10 @@ impl<'tcx> TyCtxt<'tcx> {
// `main as fn() == main as fn()` is false, while `let x = main as fn(); x == x` is true.
// However, formatting code relies on function identity (see #58320), so we only do
// this for generic functions. Lifetime parameters are ignored.
let is_generic = instance.substs.into_iter().any(|kind| match kind.unpack() {
GenericArgKind::Lifetime(_) => false,
_ => true,
});
let is_generic = instance
.substs
.into_iter()
.any(|kind| !matches!(kind.unpack(), GenericArgKind::Lifetime(_)));
if is_generic {
// Get a fresh ID.
let mut alloc_map = self.alloc_map.lock();
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_middle/src/mir/interpret/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,19 +445,13 @@ impl<'tcx, Tag> Scalar<Tag> {
/// Do not call this method! Dispatch based on the type instead.
#[inline]
pub fn is_bits(self) -> bool {
match self {
Scalar::Raw { .. } => true,
_ => false,
}
matches!(self, Scalar::Raw { .. })
}

/// Do not call this method! Dispatch based on the type instead.
#[inline]
pub fn is_ptr(self) -> bool {
match self {
Scalar::Ptr(_) => true,
_ => false,
}
matches!(self, Scalar::Ptr(_))
}

pub fn to_bool(self) -> InterpResult<'tcx, bool> {
Expand Down
73 changes: 31 additions & 42 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,67 +971,59 @@ impl<'tcx> LocalDecl<'tcx> {
/// - `let x = ...`,
/// - or `match ... { C(x) => ... }`
pub fn can_be_made_mutable(&self) -> bool {
match self.local_info {
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(VarBindingForm {
binding_mode: ty::BindingMode::BindByValue(_),
opt_ty_info: _,
opt_match_place: _,
pat_span: _,
})))) => true,

Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(
ImplicitSelfKind::Imm,
)))) => true,

_ => false,
}
matches!(
self.local_info,
Some(box LocalInfo::User(ClearCrossCrate::Set(
BindingForm::Var(VarBindingForm {
binding_mode: ty::BindingMode::BindByValue(_),
opt_ty_info: _,
opt_match_place: _,
pat_span: _,
})
| BindingForm::ImplicitSelf(ImplicitSelfKind::Imm),
)))
)
}

/// Returns `true` if local is definitely not a `ref ident` or
/// `ref mut ident` binding. (Such bindings cannot be made into
/// mutable bindings, but the inverse does not necessarily hold).
pub fn is_nonref_binding(&self) -> bool {
match self.local_info {
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(VarBindingForm {
binding_mode: ty::BindingMode::BindByValue(_),
opt_ty_info: _,
opt_match_place: _,
pat_span: _,
})))) => true,

Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(_)))) => true,

_ => false,
}
matches!(
self.local_info,
Some(box LocalInfo::User(ClearCrossCrate::Set(
BindingForm::Var(VarBindingForm {
binding_mode: ty::BindingMode::BindByValue(_),
opt_ty_info: _,
opt_match_place: _,
pat_span: _,
})
| BindingForm::ImplicitSelf(_),
)))
)
}

/// Returns `true` if this variable is a named variable or function
/// parameter declared by the user.
#[inline]
pub fn is_user_variable(&self) -> bool {
match self.local_info {
Some(box LocalInfo::User(_)) => true,
_ => false,
}
matches!(self.local_info, Some(box LocalInfo::User(_)))
}

/// Returns `true` if this is a reference to a variable bound in a `match`
/// expression that is used to access said variable for the guard of the
/// match arm.
pub fn is_ref_for_guard(&self) -> bool {
match self.local_info {
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::RefForGuard))) => true,
_ => false,
}
matches!(
self.local_info,
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::RefForGuard)))
)
}

/// Returns `Some` if this is a reference to a static item that is used to
/// access that static
pub fn is_ref_to_static(&self) -> bool {
match self.local_info {
Some(box LocalInfo::StaticRef { .. }) => true,
_ => false,
}
matches!(self.local_info, Some(box LocalInfo::StaticRef { .. }))
}

/// Returns `Some` if this is a reference to a static item that is used to
Expand Down Expand Up @@ -2164,10 +2156,7 @@ pub enum BinOp {
impl BinOp {
pub fn is_checkable(self) -> bool {
use self::BinOp::*;
match self {
Add | Sub | Mul | Shl | Shr => true,
_ => false,
}
matches!(self, Add | Sub | Mul | Shl | Shr)
}
}

Expand Down
Loading