Skip to content

Commit 5ded394

Browse files
committed
Auto merge of #77606 - JohnTitor:rollup-7rgahdt, r=JohnTitor
Rollup of 13 pull requests Successful merges: - #76388 (Add a note about the panic behavior of math operations on time objects) - #76855 (Revamp rustdoc docs about documentation using `cfg`) - #76995 (Reduce boilerplate with the matches! macro) - #77228 (Add missing examples for MaybeUninit) - #77528 (Avoid unchecked casts in net parser) - #77534 (Disallow overriding forbid in same scope) - #77555 (Allow anyone to set regression labels) - #77558 (Rename bootstrap/defaults/{config.toml.PROFILE => config.PROFILE.toml}) - #77559 (Fix rustdoc warnings about invalid Rust syntax) - #77560 (Fix LitKind's byte buffer to use refcounted slice) - #77573 (Hint doc use convert::identity relative link) - #77587 (Fix span for unicode escape suggestion.) - #77591 (Record `expansion_that_defined` into crate metadata) Failed merges: r? `@ghost`
2 parents a1dfd24 + 552933b commit 5ded394

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+512
-386
lines changed

compiler/rustc_ast/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ pub enum LitKind {
16061606
/// A string literal (`"foo"`).
16071607
Str(Symbol, StrStyle),
16081608
/// A byte string (`b"foo"`).
1609-
ByteStr(Lrc<Vec<u8>>),
1609+
ByteStr(Lrc<[u8]>),
16101610
/// A byte char (`b'f'`).
16111611
Byte(u8),
16121612
/// A character literal (`'a'`).

compiler/rustc_ast/src/util/literal.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::ast::{self, Lit, LitKind};
44
use crate::token::{self, Token};
55
use crate::tokenstream::TokenTree;
66

7-
use rustc_data_structures::sync::Lrc;
87
use rustc_lexer::unescape::{unescape_byte, unescape_char};
98
use rustc_lexer::unescape::{unescape_byte_literal, unescape_literal, Mode};
109
use rustc_span::symbol::{kw, sym, Symbol};
@@ -108,7 +107,7 @@ impl LitKind {
108107
});
109108
error?;
110109
buf.shrink_to_fit();
111-
LitKind::ByteStr(Lrc::new(buf))
110+
LitKind::ByteStr(buf.into())
112111
}
113112
token::ByteStrRaw(_) => {
114113
let s = symbol.as_str();
@@ -128,7 +127,7 @@ impl LitKind {
128127
symbol.to_string().into_bytes()
129128
};
130129

131-
LitKind::ByteStr(Lrc::new(bytes))
130+
LitKind::ByteStr(bytes.into())
132131
}
133132
token::Err => LitKind::Err(symbol),
134133
})

compiler/rustc_builtin_macros/src/source_util.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use rustc_span::{self, Pos, Span};
1313
use smallvec::SmallVec;
1414
use std::rc::Rc;
1515

16-
use rustc_data_structures::sync::Lrc;
17-
1816
// These macros all relate to the file system; they either return
1917
// the column/row/filename of the expression, or they include
2018
// a given file into the current one.
@@ -216,7 +214,7 @@ pub fn expand_include_bytes(
216214
}
217215
};
218216
match cx.source_map().load_binary_file(&file) {
219-
Ok(bytes) => base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes)))),
217+
Ok(bytes) => base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(bytes.into()))),
220218
Err(e) => {
221219
cx.span_err(sp, &format!("couldn't read {}: {}", file.display(), e));
222220
DummyResult::any(sp)

compiler/rustc_lint/src/levels.rs

+43-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_hir as hir;
1010
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
1111
use rustc_hir::{intravisit, HirId};
1212
use rustc_middle::hir::map::Map;
13+
use rustc_middle::lint::LevelSource;
1314
use rustc_middle::lint::LintDiagnosticBuilder;
1415
use rustc_middle::lint::{struct_lint_level, LintLevelMap, LintLevelSets, LintSet, LintSource};
1516
use rustc_middle::ty::query::Providers;
@@ -95,6 +96,44 @@ impl<'s> LintLevelsBuilder<'s> {
9596
self.sets.list.push(LintSet::CommandLine { specs });
9697
}
9798

99+
/// Attempts to insert the `id` to `level_src` map entry. If unsuccessful
100+
/// (e.g. if a forbid was already inserted on the same scope), then emits a
101+
/// diagnostic with no change to `specs`.
102+
fn insert_spec(
103+
&mut self,
104+
specs: &mut FxHashMap<LintId, LevelSource>,
105+
id: LintId,
106+
(level, src): LevelSource,
107+
) {
108+
if let Some((old_level, old_src)) = specs.get(&id) {
109+
if old_level == &Level::Forbid && level != Level::Forbid {
110+
let mut diag_builder = struct_span_err!(
111+
self.sess,
112+
src.span(),
113+
E0453,
114+
"{}({}) incompatible with previous forbid in same scope",
115+
level.as_str(),
116+
src.name(),
117+
);
118+
match *old_src {
119+
LintSource::Default => {}
120+
LintSource::Node(_, forbid_source_span, reason) => {
121+
diag_builder.span_label(forbid_source_span, "`forbid` level set here");
122+
if let Some(rationale) = reason {
123+
diag_builder.note(&rationale.as_str());
124+
}
125+
}
126+
LintSource::CommandLine(_) => {
127+
diag_builder.note("`forbid` lint level was set on command line");
128+
}
129+
}
130+
diag_builder.emit();
131+
return;
132+
}
133+
}
134+
specs.insert(id, (level, src));
135+
}
136+
98137
/// Pushes a list of AST lint attributes onto this context.
99138
///
100139
/// This function will return a `BuilderPush` object which should be passed
@@ -109,7 +148,7 @@ impl<'s> LintLevelsBuilder<'s> {
109148
/// `#[allow]`
110149
///
111150
/// Don't forget to call `pop`!
112-
pub fn push(
151+
pub(crate) fn push(
113152
&mut self,
114153
attrs: &[ast::Attribute],
115154
store: &LintStore,
@@ -221,7 +260,7 @@ impl<'s> LintLevelsBuilder<'s> {
221260
let src = LintSource::Node(name, li.span(), reason);
222261
for &id in ids {
223262
self.check_gated_lint(id, attr.span);
224-
specs.insert(id, (level, src));
263+
self.insert_spec(&mut specs, id, (level, src));
225264
}
226265
}
227266

@@ -235,7 +274,7 @@ impl<'s> LintLevelsBuilder<'s> {
235274
reason,
236275
);
237276
for id in ids {
238-
specs.insert(*id, (level, src));
277+
self.insert_spec(&mut specs, *id, (level, src));
239278
}
240279
}
241280
Err((Some(ids), new_lint_name)) => {
@@ -272,7 +311,7 @@ impl<'s> LintLevelsBuilder<'s> {
272311
reason,
273312
);
274313
for id in ids {
275-
specs.insert(*id, (level, src));
314+
self.insert_spec(&mut specs, *id, (level, src));
276315
}
277316
}
278317
Err((None, _)) => {

compiler/rustc_metadata/src/rmeta/decoder.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10111011
self.root.tables.impl_trait_ref.get(self, id).map(|tr| tr.decode((self, tcx)))
10121012
}
10131013

1014+
fn get_expn_that_defined(&self, id: DefIndex, sess: &Session) -> ExpnId {
1015+
self.root.tables.expn_that_defined.get(self, id).unwrap().decode((self, sess))
1016+
}
1017+
10141018
/// Iterates over all the stability attributes in the given crate.
10151019
fn get_lib_features(&self, tcx: TyCtxt<'tcx>) -> &'tcx [(Symbol, Option<Symbol>)] {
10161020
// FIXME: For a proc macro crate, not sure whether we should return the "host"

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
238238
}
239239

240240
crate_extern_paths => { cdata.source().paths().cloned().collect() }
241+
expn_that_defined => { cdata.get_expn_that_defined(def_id.index, tcx.sess) }
241242
}
242243

243244
pub fn provide(providers: &mut Providers) {

compiler/rustc_metadata/src/rmeta/encoder.rs

+4
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ impl EncodeContext<'a, 'tcx> {
747747
ty::Visibility::from_hir(enum_vis, enum_id, self.tcx));
748748
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
749749
record!(self.tables.attributes[def_id] <- &self.tcx.get_attrs(def_id)[..]);
750+
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
750751
record!(self.tables.children[def_id] <- variant.fields.iter().map(|f| {
751752
assert!(f.did.is_local());
752753
f.did.index
@@ -883,6 +884,7 @@ impl EncodeContext<'a, 'tcx> {
883884
record!(self.tables.visibility[def_id] <- field.vis);
884885
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
885886
record!(self.tables.attributes[def_id] <- variant_data.fields()[field_index].attrs);
887+
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
886888
self.encode_ident_span(def_id, field.ident);
887889
self.encode_stability(def_id);
888890
self.encode_deprecation(def_id);
@@ -924,6 +926,7 @@ impl EncodeContext<'a, 'tcx> {
924926
record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr));
925927
record!(self.tables.visibility[def_id] <- ctor_vis);
926928
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
929+
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
927930
self.encode_stability(def_id);
928931
self.encode_deprecation(def_id);
929932
self.encode_item_type(def_id);
@@ -1339,6 +1342,7 @@ impl EncodeContext<'a, 'tcx> {
13391342
ty::Visibility::from_hir(&item.vis, item.hir_id, tcx));
13401343
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
13411344
record!(self.tables.attributes[def_id] <- item.attrs);
1345+
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
13421346
// FIXME(eddyb) there should be a nicer way to do this.
13431347
match item.kind {
13441348
hir::ItemKind::ForeignMod(ref fm) => record!(self.tables.children[def_id] <-

compiler/rustc_metadata/src/rmeta/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ define_tables! {
294294
variances: Table<DefIndex, Lazy<[ty::Variance]>>,
295295
generics: Table<DefIndex, Lazy<ty::Generics>>,
296296
explicit_predicates: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
297+
expn_that_defined: Table<DefIndex, Lazy<ExpnId>>,
297298
// FIXME(eddyb) this would ideally be `Lazy<[...]>` but `ty::Predicate`
298299
// doesn't handle shorthands in its own (de)serialization impls,
299300
// as it's an `enum` for which we want to derive (de)serialization,

compiler/rustc_middle/src/hir/map/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -535,15 +535,15 @@ impl<'hir> Map<'hir> {
535535
Some(Node::Binding(_)) => (),
536536
_ => return false,
537537
}
538-
match self.find(self.get_parent_node(id)) {
538+
matches!(
539+
self.find(self.get_parent_node(id)),
539540
Some(
540541
Node::Item(_)
541542
| Node::TraitItem(_)
542543
| Node::ImplItem(_)
543544
| Node::Expr(Expr { kind: ExprKind::Closure(..), .. }),
544-
) => true,
545-
_ => false,
546-
}
545+
)
546+
)
547547
}
548548

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

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

563563
/// Retrieves the `HirId` for `id`'s enclosing method, unless there's a

compiler/rustc_middle/src/lint.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_session::lint::{builtin, Level, Lint, LintId};
99
use rustc_session::{DiagnosticMessageId, Session};
1010
use rustc_span::hygiene::MacroKind;
1111
use rustc_span::source_map::{DesugaringKind, ExpnKind, MultiSpan};
12-
use rustc_span::{Span, Symbol};
12+
use rustc_span::{symbol, Span, Symbol, DUMMY_SP};
1313

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

28+
impl LintSource {
29+
pub fn name(&self) -> Symbol {
30+
match *self {
31+
LintSource::Default => symbol::kw::Default,
32+
LintSource::Node(name, _, _) => name,
33+
LintSource::CommandLine(name) => name,
34+
}
35+
}
36+
37+
pub fn span(&self) -> Span {
38+
match *self {
39+
LintSource::Default => DUMMY_SP,
40+
LintSource::Node(_, span, _) => span,
41+
LintSource::CommandLine(_) => DUMMY_SP,
42+
}
43+
}
44+
}
45+
2846
pub type LevelSource = (Level, LintSource);
2947

3048
pub struct LintLevelSets {

compiler/rustc_middle/src/mir/interpret/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,10 @@ impl<'tcx> TyCtxt<'tcx> {
486486
// `main as fn() == main as fn()` is false, while `let x = main as fn(); x == x` is true.
487487
// However, formatting code relies on function identity (see #58320), so we only do
488488
// this for generic functions. Lifetime parameters are ignored.
489-
let is_generic = instance.substs.into_iter().any(|kind| match kind.unpack() {
490-
GenericArgKind::Lifetime(_) => false,
491-
_ => true,
492-
});
489+
let is_generic = instance
490+
.substs
491+
.into_iter()
492+
.any(|kind| !matches!(kind.unpack(), GenericArgKind::Lifetime(_)));
493493
if is_generic {
494494
// Get a fresh ID.
495495
let mut alloc_map = self.alloc_map.lock();

compiler/rustc_middle/src/mir/interpret/value.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -445,19 +445,13 @@ impl<'tcx, Tag> Scalar<Tag> {
445445
/// Do not call this method! Dispatch based on the type instead.
446446
#[inline]
447447
pub fn is_bits(self) -> bool {
448-
match self {
449-
Scalar::Raw { .. } => true,
450-
_ => false,
451-
}
448+
matches!(self, Scalar::Raw { .. })
452449
}
453450

454451
/// Do not call this method! Dispatch based on the type instead.
455452
#[inline]
456453
pub fn is_ptr(self) -> bool {
457-
match self {
458-
Scalar::Ptr(_) => true,
459-
_ => false,
460-
}
454+
matches!(self, Scalar::Ptr(_))
461455
}
462456

463457
pub fn to_bool(self) -> InterpResult<'tcx, bool> {

0 commit comments

Comments
 (0)