Skip to content

Commit eb01d0f

Browse files
committed
Auto merge of #51037 - pietroalbini:beta-backports, r=pietroalbini
[beta] Process backports Merged and approved: * #50812: Fix issue #50811 (`NaN > NaN` was true). * #50879: Fix naming conventions for new lints * #51011: rustdoc: hide macro export statements from docs * #51051: prohibit turbofish in impl Trait methods * #51052: restore emplacement syntax (obsolete) * #51146: typeck: Do not pass the field check on field error * #51235: remove notion of Implicit derefs from mem-cat r? @ghost
2 parents fe75e44 + 724cfd8 commit eb01d0f

Some content is hidden

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

61 files changed

+529
-166
lines changed

src/doc/rustc/src/lints/listing/allowed-by-default.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ To fix it, do as the help message suggests:
6464

6565
```rust
6666
#![feature(dyn_trait)]
67-
#![deny(bare_trait_object)]
67+
#![deny(bare_trait_objects)]
6868

6969
trait Trait { }
7070

src/librustc/hir/lowering.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -2932,7 +2932,10 @@ impl<'a> LoweringContext<'a> {
29322932
fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
29332933
let kind = match e.node {
29342934
ExprKind::Box(ref inner) => hir::ExprBox(P(self.lower_expr(inner))),
2935-
2935+
ExprKind::ObsoleteInPlace(..) => {
2936+
self.sess.abort_if_errors();
2937+
span_bug!(e.span, "encountered ObsoleteInPlace expr during lowering");
2938+
}
29362939
ExprKind::Array(ref exprs) => {
29372940
hir::ExprArray(exprs.iter().map(|x| self.lower_expr(x)).collect())
29382941
}
@@ -4122,7 +4125,7 @@ impl<'a> LoweringContext<'a> {
41224125

41234126
fn maybe_lint_bare_trait(&self, span: Span, id: NodeId, is_global: bool) {
41244127
self.sess.buffer_lint_with_diagnostic(
4125-
builtin::BARE_TRAIT_OBJECT,
4128+
builtin::BARE_TRAIT_OBJECTS,
41264129
id,
41274130
span,
41284131
"trait objects without an explicit `dyn` are deprecated",

src/librustc/lint/builtin.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ declare_lint! {
231231
}
232232

233233
declare_lint! {
234-
pub SINGLE_USE_LIFETIME,
234+
pub SINGLE_USE_LIFETIMES,
235235
Allow,
236236
"detects single use lifetimes"
237237
}
@@ -243,19 +243,19 @@ declare_lint! {
243243
}
244244

245245
declare_lint! {
246-
pub ELIDED_LIFETIME_IN_PATH,
246+
pub ELIDED_LIFETIMES_IN_PATHS,
247247
Allow,
248248
"hidden lifetime parameters are deprecated, try `Foo<'_>`"
249249
}
250250

251251
declare_lint! {
252-
pub BARE_TRAIT_OBJECT,
252+
pub BARE_TRAIT_OBJECTS,
253253
Allow,
254254
"suggest using `dyn Trait` for trait objects"
255255
}
256256

257257
declare_lint! {
258-
pub ABSOLUTE_PATH_STARTING_WITH_MODULE,
258+
pub ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
259259
Allow,
260260
"fully qualified paths that start with a module name \
261261
instead of `crate`, `self`, or an extern crate name"
@@ -268,7 +268,7 @@ declare_lint! {
268268
}
269269

270270
declare_lint! {
271-
pub UNSTABLE_NAME_COLLISION,
271+
pub UNSTABLE_NAME_COLLISIONS,
272272
Warn,
273273
"detects name collision with an existing but unstable method"
274274
}
@@ -317,12 +317,12 @@ impl LintPass for HardwiredLints {
317317
DEPRECATED,
318318
UNUSED_UNSAFE,
319319
UNUSED_MUT,
320-
SINGLE_USE_LIFETIME,
320+
SINGLE_USE_LIFETIMES,
321321
TYVAR_BEHIND_RAW_POINTER,
322-
ELIDED_LIFETIME_IN_PATH,
323-
BARE_TRAIT_OBJECT,
324-
ABSOLUTE_PATH_STARTING_WITH_MODULE,
325-
UNSTABLE_NAME_COLLISION,
322+
ELIDED_LIFETIMES_IN_PATHS,
323+
BARE_TRAIT_OBJECTS,
324+
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
325+
UNSTABLE_NAME_COLLISIONS,
326326
)
327327
}
328328
}

src/librustc/lint/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
505505
"this was previously accepted by the compiler but is being phased out; \
506506
it will become a hard error";
507507

508-
let explanation = if lint_id == LintId::of(::lint::builtin::UNSTABLE_NAME_COLLISION) {
508+
let explanation = if lint_id == LintId::of(::lint::builtin::UNSTABLE_NAME_COLLISIONS) {
509509
"once this method is added to the standard library, \
510510
the ambiguity may cause an error or change in behavior!"
511511
.to_owned()

src/librustc/middle/expr_use_visitor.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -837,17 +837,24 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
837837
/// established up front, e.g. via `determine_pat_move_mode` (see
838838
/// also `walk_irrefutable_pat` for patterns that stand alone).
839839
fn walk_pat(&mut self, cmt_discr: mc::cmt<'tcx>, pat: &hir::Pat, match_mode: MatchMode) {
840-
debug!("walk_pat cmt_discr={:?} pat={:?}", cmt_discr, pat);
840+
debug!("walk_pat(cmt_discr={:?}, pat={:?})", cmt_discr, pat);
841841

842842
let ExprUseVisitor { ref mc, ref mut delegate, param_env } = *self;
843843
return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |cmt_pat, pat| {
844844
if let PatKind::Binding(_, canonical_id, ..) = pat.node {
845-
debug!("binding cmt_pat={:?} pat={:?} match_mode={:?}", cmt_pat, pat, match_mode);
845+
debug!(
846+
"walk_pat: binding cmt_pat={:?} pat={:?} match_mode={:?}",
847+
cmt_pat,
848+
pat,
849+
match_mode,
850+
);
846851
let bm = *mc.tables.pat_binding_modes().get(pat.hir_id)
847852
.expect("missing binding mode");
853+
debug!("walk_pat: pat.hir_id={:?} bm={:?}", pat.hir_id, bm);
848854

849855
// pat_ty: the type of the binding being produced.
850856
let pat_ty = return_if_err!(mc.node_ty(pat.hir_id));
857+
debug!("walk_pat: pat_ty={:?}", pat_ty);
851858

852859
// Each match binding is effectively an assignment to the
853860
// binding being produced.

src/librustc/middle/mem_categorization.rs

+45-45
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub enum Categorization<'tcx> {
9595
StaticItem,
9696
Upvar(Upvar), // upvar referenced by closure env
9797
Local(ast::NodeId), // local variable
98-
Deref(cmt<'tcx>, PointerKind<'tcx>), // deref of a ptr
98+
Deref(cmt<'tcx>, PointerKind<'tcx>), // deref of a ptr
9999
Interior(cmt<'tcx>, InteriorKind), // something interior: field, tuple, etc
100100
Downcast(cmt<'tcx>, DefId), // selects a particular enum variant (*1)
101101

@@ -120,9 +120,6 @@ pub enum PointerKind<'tcx> {
120120

121121
/// `*T`
122122
UnsafePtr(hir::Mutability),
123-
124-
/// Implicit deref of the `&T` that results from an overloaded index `[]`.
125-
Implicit(ty::BorrowKind, ty::Region<'tcx>),
126123
}
127124

128125
// We use the term "interior" to mean "something reachable from the
@@ -172,6 +169,7 @@ pub enum MutabilityCategory {
172169
pub enum Note {
173170
NoteClosureEnv(ty::UpvarId), // Deref through closure env
174171
NoteUpvarRef(ty::UpvarId), // Deref through by-ref upvar
172+
NoteIndex, // Deref as part of desugaring `x[]` into its two components
175173
NoteNone // Nothing special
176174
}
177175

@@ -231,8 +229,7 @@ impl<'tcx> cmt_<'tcx> {
231229

232230
pub fn immutability_blame(&self) -> Option<ImmutabilityBlame<'tcx>> {
233231
match self.cat {
234-
Categorization::Deref(ref base_cmt, BorrowedPtr(ty::ImmBorrow, _)) |
235-
Categorization::Deref(ref base_cmt, Implicit(ty::ImmBorrow, _)) => {
232+
Categorization::Deref(ref base_cmt, BorrowedPtr(ty::ImmBorrow, _)) => {
236233
// try to figure out where the immutable reference came from
237234
match base_cmt.cat {
238235
Categorization::Local(node_id) =>
@@ -328,7 +325,7 @@ impl MutabilityCategory {
328325
Unique => {
329326
base_mutbl.inherit()
330327
}
331-
BorrowedPtr(borrow_kind, _) | Implicit(borrow_kind, _) => {
328+
BorrowedPtr(borrow_kind, _) => {
332329
MutabilityCategory::from_borrow_kind(borrow_kind)
333330
}
334331
UnsafePtr(m) => {
@@ -617,7 +614,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
617614
} else {
618615
previous()?
619616
});
620-
self.cat_deref(expr, base, false)
617+
self.cat_deref(expr, base, NoteNone)
621618
}
622619

623620
adjustment::Adjust::NeverToAny |
@@ -640,10 +637,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
640637
match expr.node {
641638
hir::ExprUnary(hir::UnDeref, ref e_base) => {
642639
if self.tables.is_method_call(expr) {
643-
self.cat_overloaded_place(expr, e_base, false)
640+
self.cat_overloaded_place(expr, e_base, NoteNone)
644641
} else {
645642
let base_cmt = Rc::new(self.cat_expr(&e_base)?);
646-
self.cat_deref(expr, base_cmt, false)
643+
self.cat_deref(expr, base_cmt, NoteNone)
647644
}
648645
}
649646

@@ -664,7 +661,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
664661
// The call to index() returns a `&T` value, which
665662
// is an rvalue. That is what we will be
666663
// dereferencing.
667-
self.cat_overloaded_place(expr, base, true)
664+
self.cat_overloaded_place(expr, base, NoteIndex)
668665
} else {
669666
let base_cmt = Rc::new(self.cat_expr(&base)?);
670667
self.cat_index(expr, base_cmt, expr_ty, InteriorOffsetKind::Index)
@@ -998,12 +995,18 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
998995
ret
999996
}
1000997

1001-
fn cat_overloaded_place(&self,
1002-
expr: &hir::Expr,
1003-
base: &hir::Expr,
1004-
implicit: bool)
1005-
-> McResult<cmt_<'tcx>> {
1006-
debug!("cat_overloaded_place: implicit={}", implicit);
998+
fn cat_overloaded_place(
999+
&self,
1000+
expr: &hir::Expr,
1001+
base: &hir::Expr,
1002+
note: Note,
1003+
) -> McResult<cmt_<'tcx>> {
1004+
debug!(
1005+
"cat_overloaded_place(expr={:?}, base={:?}, note={:?})",
1006+
expr,
1007+
base,
1008+
note,
1009+
);
10071010

10081011
// Reconstruct the output assuming it's a reference with the
10091012
// same region and mutability as the receiver. This holds for
@@ -1023,14 +1026,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10231026
});
10241027

10251028
let base_cmt = Rc::new(self.cat_rvalue_node(expr.id, expr.span, ref_ty));
1026-
self.cat_deref(expr, base_cmt, implicit)
1029+
self.cat_deref(expr, base_cmt, note)
10271030
}
10281031

1029-
pub fn cat_deref<N:ast_node>(&self,
1030-
node: &N,
1031-
base_cmt: cmt<'tcx>,
1032-
implicit: bool)
1033-
-> McResult<cmt_<'tcx>> {
1032+
pub fn cat_deref(
1033+
&self,
1034+
node: &impl ast_node,
1035+
base_cmt: cmt<'tcx>,
1036+
note: Note,
1037+
) -> McResult<cmt_<'tcx>> {
10341038
debug!("cat_deref: base_cmt={:?}", base_cmt);
10351039

10361040
let base_cmt_ty = base_cmt.ty;
@@ -1048,7 +1052,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10481052
ty::TyRawPtr(ref mt) => UnsafePtr(mt.mutbl),
10491053
ty::TyRef(r, mt) => {
10501054
let bk = ty::BorrowKind::from_mutbl(mt.mutbl);
1051-
if implicit { Implicit(bk, r) } else { BorrowedPtr(bk, r) }
1055+
BorrowedPtr(bk, r)
10521056
}
10531057
ref ty => bug!("unexpected type in cat_deref: {:?}", ty)
10541058
};
@@ -1059,7 +1063,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10591063
mutbl: MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr),
10601064
cat: Categorization::Deref(base_cmt, ptr),
10611065
ty: deref_ty,
1062-
note: NoteNone
1066+
note: note,
10631067
};
10641068
debug!("cat_deref ret {:?}", ret);
10651069
Ok(ret)
@@ -1192,7 +1196,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
11921196
// step out of sync again. So you'll see below that we always
11931197
// get the type of the *subpattern* and use that.
11941198

1195-
debug!("cat_pattern: {:?} cmt={:?}", pat, cmt);
1199+
debug!("cat_pattern(pat={:?}, cmt={:?})", pat, cmt);
11961200

11971201
// If (pattern) adjustments are active for this pattern, adjust the `cmt` correspondingly.
11981202
// `cmt`s are constructed differently from patterns. For example, in
@@ -1230,10 +1234,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12301234
.pat_adjustments()
12311235
.get(pat.hir_id)
12321236
.map(|v| v.len())
1233-
.unwrap_or(0) {
1234-
cmt = Rc::new(self.cat_deref(pat, cmt, true /* implicit */)?);
1237+
.unwrap_or(0)
1238+
{
1239+
debug!("cat_pattern: applying adjustment to cmt={:?}", cmt);
1240+
cmt = Rc::new(self.cat_deref(pat, cmt, NoteNone)?);
12351241
}
12361242
let cmt = cmt; // lose mutability
1243+
debug!("cat_pattern: applied adjustment derefs to get cmt={:?}", cmt);
12371244

12381245
// Invoke the callback, but only now, after the `cmt` has adjusted.
12391246
//
@@ -1329,7 +1336,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
13291336
// box p1, &p1, &mut p1. we can ignore the mutability of
13301337
// PatKind::Ref since that information is already contained
13311338
// in the type.
1332-
let subcmt = Rc::new(self.cat_deref(pat, cmt, false)?);
1339+
let subcmt = Rc::new(self.cat_deref(pat, cmt, NoteNone)?);
13331340
self.cat_pattern_(subcmt, &subpat, op)?;
13341341
}
13351342

@@ -1390,7 +1397,6 @@ impl<'tcx> cmt_<'tcx> {
13901397
Categorization::Local(..) |
13911398
Categorization::Deref(_, UnsafePtr(..)) |
13921399
Categorization::Deref(_, BorrowedPtr(..)) |
1393-
Categorization::Deref(_, Implicit(..)) |
13941400
Categorization::Upvar(..) => {
13951401
(*self).clone()
13961402
}
@@ -1410,9 +1416,7 @@ impl<'tcx> cmt_<'tcx> {
14101416

14111417
match self.cat {
14121418
Categorization::Deref(ref b, BorrowedPtr(ty::MutBorrow, _)) |
1413-
Categorization::Deref(ref b, Implicit(ty::MutBorrow, _)) |
14141419
Categorization::Deref(ref b, BorrowedPtr(ty::UniqueImmBorrow, _)) |
1415-
Categorization::Deref(ref b, Implicit(ty::UniqueImmBorrow, _)) |
14161420
Categorization::Deref(ref b, Unique) |
14171421
Categorization::Downcast(ref b, _) |
14181422
Categorization::Interior(ref b, _) => {
@@ -1435,8 +1439,7 @@ impl<'tcx> cmt_<'tcx> {
14351439
}
14361440
}
14371441

1438-
Categorization::Deref(_, BorrowedPtr(ty::ImmBorrow, _)) |
1439-
Categorization::Deref(_, Implicit(ty::ImmBorrow, _)) => {
1442+
Categorization::Deref(_, BorrowedPtr(ty::ImmBorrow, _)) => {
14401443
FreelyAliasable(AliasableBorrowed)
14411444
}
14421445
}
@@ -1459,7 +1462,7 @@ impl<'tcx> cmt_<'tcx> {
14591462
_ => bug!()
14601463
})
14611464
}
1462-
NoteNone => None
1465+
NoteIndex | NoteNone => None
14631466
}
14641467
}
14651468

@@ -1486,17 +1489,17 @@ impl<'tcx> cmt_<'tcx> {
14861489
Some(_) => bug!(),
14871490
None => {
14881491
match pk {
1489-
Implicit(..) => {
1490-
format!("indexed content")
1491-
}
14921492
Unique => {
14931493
format!("`Box` content")
14941494
}
14951495
UnsafePtr(..) => {
14961496
format!("dereference of raw pointer")
14971497
}
14981498
BorrowedPtr(..) => {
1499-
format!("borrowed content")
1499+
match self.note {
1500+
NoteIndex => format!("indexed content"),
1501+
_ => format!("borrowed content"),
1502+
}
15001503
}
15011504
}
15021505
}
@@ -1524,12 +1527,9 @@ impl<'tcx> cmt_<'tcx> {
15241527
pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
15251528
match ptr {
15261529
Unique => "Box",
1527-
BorrowedPtr(ty::ImmBorrow, _) |
1528-
Implicit(ty::ImmBorrow, _) => "&",
1529-
BorrowedPtr(ty::MutBorrow, _) |
1530-
Implicit(ty::MutBorrow, _) => "&mut",
1531-
BorrowedPtr(ty::UniqueImmBorrow, _) |
1532-
Implicit(ty::UniqueImmBorrow, _) => "&unique",
1530+
BorrowedPtr(ty::ImmBorrow, _) => "&",
1531+
BorrowedPtr(ty::MutBorrow, _) => "&mut",
1532+
BorrowedPtr(ty::UniqueImmBorrow, _) => "&unique",
15331533
UnsafePtr(_) => "*",
15341534
}
15351535
}

src/librustc/middle/resolve_lifetime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
12901290

12911291
this.tcx
12921292
.struct_span_lint_node(
1293-
lint::builtin::SINGLE_USE_LIFETIME,
1293+
lint::builtin::SINGLE_USE_LIFETIMES,
12941294
id,
12951295
span,
12961296
&format!(
@@ -1901,7 +1901,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
19011901
if deprecated {
19021902
self.tcx
19031903
.struct_span_lint_node(
1904-
lint::builtin::ELIDED_LIFETIME_IN_PATH,
1904+
lint::builtin::ELIDED_LIFETIMES_IN_PATHS,
19051905
id,
19061906
span,
19071907
&format!("hidden lifetime parameters are deprecated, try `Foo<'_>`"),

0 commit comments

Comments
 (0)