Skip to content

Commit 13738b0

Browse files
committed
Auto merge of #135151 - matthiaskrgr:rollup-2vy1hwl, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #135111 (Add doc aliases for `libm` and IEEE names) - #135129 (triagebot: label `src/doc/rustc-dev-guide` changes with `A-rustc-dev-guide`) - #135132 (dev guide ping group and set adhoc reviewers to compiler) - #135145 (Mention `unnameable_types` in `unreachable_pub` documentation.) - #135147 (A few borrowck tweaks to improve 2024 edition migration lints) - #135150 (move footnote to ordinary comment) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fd98df8 + c5c05c2 commit 13738b0

File tree

16 files changed

+108
-57
lines changed

16 files changed

+108
-57
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+34
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_middle::mir::{
1717
};
1818
use rustc_middle::ty::adjustment::PointerCoercion;
1919
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
20+
use rustc_middle::util::CallKind;
2021
use rustc_span::{DesugaringKind, Span, Symbol, kw, sym};
2122
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
2223
use tracing::{debug, instrument};
@@ -635,6 +636,39 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
635636
// Used in a closure.
636637
(LaterUseKind::ClosureCapture, capture_kind_span, Some(path_span))
637638
}
639+
// In the case that the borrowed value (probably a temporary)
640+
// overlaps with the method's receiver, then point at the method.
641+
UseSpans::FnSelfUse {
642+
var_span: span,
643+
kind: CallKind::Normal { desugaring: None, .. },
644+
..
645+
} if span
646+
.overlaps(self.body.local_decls[borrow.assigned_place.local].source_info.span) =>
647+
{
648+
if let TerminatorKind::Call { func, call_source: CallSource::Normal, .. } =
649+
&self.body.basic_blocks[location.block].terminator().kind
650+
{
651+
// Just point to the function, to reduce the chance of overlapping spans.
652+
let function_span = match func {
653+
Operand::Constant(c) => c.span,
654+
Operand::Copy(place) | Operand::Move(place) => {
655+
if let Some(l) = place.as_local() {
656+
let local_decl = &self.body.local_decls[l];
657+
if self.local_names[l].is_none() {
658+
local_decl.source_info.span
659+
} else {
660+
span
661+
}
662+
} else {
663+
span
664+
}
665+
}
666+
};
667+
(LaterUseKind::Call, function_span, None)
668+
} else {
669+
(LaterUseKind::Other, span, None)
670+
}
671+
}
638672
UseSpans::PatUse(span)
639673
| UseSpans::OtherUse(span)
640674
| UseSpans::FnSelfUse { var_span: span, .. } => {

compiler/rustc_borrowck/src/diagnostics/mod.rs

-9
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,6 @@ impl UseSpans<'_> {
661661
UseSpans::ClosureUse { args_span: span, .. }
662662
| UseSpans::PatUse(span)
663663
| UseSpans::OtherUse(span) => span,
664-
UseSpans::FnSelfUse { fn_call_span, kind: CallKind::DerefCoercion { .. }, .. } => {
665-
fn_call_span
666-
}
667664
UseSpans::FnSelfUse { var_span, .. } => var_span,
668665
}
669666
}
@@ -674,9 +671,6 @@ impl UseSpans<'_> {
674671
UseSpans::ClosureUse { path_span: span, .. }
675672
| UseSpans::PatUse(span)
676673
| UseSpans::OtherUse(span) => span,
677-
UseSpans::FnSelfUse { fn_call_span, kind: CallKind::DerefCoercion { .. }, .. } => {
678-
fn_call_span
679-
}
680674
UseSpans::FnSelfUse { var_span, .. } => var_span,
681675
}
682676
}
@@ -687,9 +681,6 @@ impl UseSpans<'_> {
687681
UseSpans::ClosureUse { capture_kind_span: span, .. }
688682
| UseSpans::PatUse(span)
689683
| UseSpans::OtherUse(span) => span,
690-
UseSpans::FnSelfUse { fn_call_span, kind: CallKind::DerefCoercion { .. }, .. } => {
691-
fn_call_span
692-
}
693684
UseSpans::FnSelfUse { var_span, .. } => var_span,
694685
}
695686
}

compiler/rustc_hir_analysis/src/impl_wf_check.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,7 @@ pub(crate) fn enforce_impl_lifetime_params_are_constrained(
128128
for param in &impl_generics.own_params {
129129
match param.kind {
130130
ty::GenericParamDefKind::Lifetime => {
131-
let param_lt = cgp::Parameter::from(param.to_early_bound_region_data());
132-
if lifetimes_in_associated_types.contains(&param_lt) // (*)
133-
&& !input_parameters.contains(&param_lt)
134-
{
135-
let mut diag = tcx.dcx().create_err(UnconstrainedGenericParameter {
136-
span: tcx.def_span(param.def_id),
137-
param_name: param.name,
138-
param_def_kind: tcx.def_descr(param.def_id),
139-
const_param_note: false,
140-
const_param_note2: false,
141-
});
142-
diag.code(E0207);
143-
res = Err(diag.emit());
144-
}
145-
// (*) This is a horrible concession to reality. I think it'd be
131+
// This is a horrible concession to reality. I think it'd be
146132
// better to just ban unconstrained lifetimes outright, but in
147133
// practice people do non-hygienic macros like:
148134
//
@@ -160,6 +146,20 @@ pub(crate) fn enforce_impl_lifetime_params_are_constrained(
160146
// permit those, so long as the lifetimes aren't used in
161147
// associated types. I believe this is sound, because lifetimes
162148
// used elsewhere are not projected back out.
149+
let param_lt = cgp::Parameter::from(param.to_early_bound_region_data());
150+
if lifetimes_in_associated_types.contains(&param_lt)
151+
&& !input_parameters.contains(&param_lt)
152+
{
153+
let mut diag = tcx.dcx().create_err(UnconstrainedGenericParameter {
154+
span: tcx.def_span(param.def_id),
155+
param_name: param.name,
156+
param_def_kind: tcx.def_descr(param.def_id),
157+
const_param_note: false,
158+
const_param_note2: false,
159+
});
160+
diag.code(E0207);
161+
res = Err(diag.emit());
162+
}
163163
}
164164
ty::GenericParamDefKind::Type { .. } | ty::GenericParamDefKind::Const { .. } => {
165165
// Enforced in `enforce_impl_non_lifetime_params_are_constrained`.

compiler/rustc_lint/src/builtin.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1244,8 +1244,8 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
12441244

12451245
declare_lint! {
12461246
/// The `unreachable_pub` lint triggers for `pub` items not reachable from other crates - that
1247-
/// means neither directly accessible, nor reexported, nor leaked through things like return
1248-
/// types.
1247+
/// means neither directly accessible, nor reexported (with `pub use`), nor leaked through
1248+
/// things like return types (which the [`unnameable_types`] lint can detect if desired).
12491249
///
12501250
/// ### Example
12511251
///
@@ -1272,8 +1272,10 @@ declare_lint! {
12721272
/// intent that the item is only visible within its own crate.
12731273
///
12741274
/// This lint is "allow" by default because it will trigger for a large
1275-
/// amount existing Rust code, and has some false-positives. Eventually it
1275+
/// amount of existing Rust code, and has some false-positives. Eventually it
12761276
/// is desired for this to become warn-by-default.
1277+
///
1278+
/// [`unnameable_types`]: #unnameable-types
12771279
pub UNREACHABLE_PUB,
12781280
Allow,
12791281
"`pub` items not reachable from crate root"

compiler/rustc_lint_defs/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4362,7 +4362,7 @@ declare_lint! {
43624362
/// ### Explanation
43634363
///
43644364
/// It is often expected that if you can obtain an object of type `T`, then
4365-
/// you can name the type `T` as well, this lint attempts to enforce this rule.
4365+
/// you can name the type `T` as well; this lint attempts to enforce this rule.
43664366
/// The recommended action is to either reexport the type properly to make it nameable,
43674367
/// or document that users are not supposed to be able to name it for one reason or another.
43684368
///

compiler/rustc_middle/src/util/find_self_call.rs

+22-19
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,29 @@ pub fn find_self_call<'tcx>(
1717
debug!("find_self_call(local={:?}): terminator={:?}", local, body[block].terminator);
1818
if let Some(Terminator { kind: TerminatorKind::Call { func, args, .. }, .. }) =
1919
&body[block].terminator
20+
&& let Operand::Constant(box ConstOperand { const_, .. }) = func
21+
&& let ty::FnDef(def_id, fn_args) = *const_.ty().kind()
22+
&& let Some(ty::AssocItem { fn_has_self_parameter: true, .. }) =
23+
tcx.opt_associated_item(def_id)
24+
&& let [Spanned { node: Operand::Move(self_place) | Operand::Copy(self_place), .. }, ..] =
25+
**args
2026
{
21-
debug!("find_self_call: func={:?}", func);
22-
if let Operand::Constant(box ConstOperand { const_, .. }) = func {
23-
if let ty::FnDef(def_id, fn_args) = *const_.ty().kind() {
24-
if let Some(ty::AssocItem { fn_has_self_parameter: true, .. }) =
25-
tcx.opt_associated_item(def_id)
26-
{
27-
debug!("find_self_call: args={:?}", fn_args);
28-
if let [
29-
Spanned {
30-
node: Operand::Move(self_place) | Operand::Copy(self_place), ..
31-
},
32-
..,
33-
] = **args
34-
{
35-
if self_place.as_local() == Some(local) {
36-
return Some((def_id, fn_args));
37-
}
38-
}
39-
}
27+
if self_place.as_local() == Some(local) {
28+
return Some((def_id, fn_args));
29+
}
30+
31+
// Handle the case where `self_place` gets reborrowed.
32+
// This happens when the receiver is `&T`.
33+
for stmt in &body[block].statements {
34+
if let StatementKind::Assign(box (place, rvalue)) = &stmt.kind
35+
&& let Some(reborrow_local) = place.as_local()
36+
&& self_place.as_local() == Some(reborrow_local)
37+
&& let Rvalue::Ref(_, _, deref_place) = rvalue
38+
&& let PlaceRef { local: deref_local, projection: [ProjectionElem::Deref] } =
39+
deref_place.as_ref()
40+
&& deref_local == local
41+
{
42+
return Some((def_id, fn_args));
4043
}
4144
}
4245
}

library/std/src/f128.rs

+2
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ impl f128 {
227227
/// ```
228228
#[inline]
229229
#[rustc_allow_incoherent_impl]
230+
#[doc(alias = "fmaf128", alias = "fusedMultiplyAdd")]
230231
#[unstable(feature = "f128", issue = "116909")]
231232
#[must_use = "method returns a new number and does not mutate the original value"]
232233
pub fn mul_add(self, a: f128, b: f128) -> f128 {
@@ -384,6 +385,7 @@ impl f128 {
384385
/// # }
385386
/// ```
386387
#[inline]
388+
#[doc(alias = "squareRoot")]
387389
#[rustc_allow_incoherent_impl]
388390
#[unstable(feature = "f128", issue = "116909")]
389391
#[must_use = "method returns a new number and does not mutate the original value"]

library/std/src/f16.rs

+2
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ impl f16 {
228228
#[inline]
229229
#[rustc_allow_incoherent_impl]
230230
#[unstable(feature = "f16", issue = "116909")]
231+
#[doc(alias = "fmaf16", alias = "fusedMultiplyAdd")]
231232
#[must_use = "method returns a new number and does not mutate the original value"]
232233
pub fn mul_add(self, a: f16, b: f16) -> f16 {
233234
unsafe { intrinsics::fmaf16(self, a, b) }
@@ -384,6 +385,7 @@ impl f16 {
384385
/// # }
385386
/// ```
386387
#[inline]
388+
#[doc(alias = "squareRoot")]
387389
#[rustc_allow_incoherent_impl]
388390
#[unstable(feature = "f16", issue = "116909")]
389391
#[must_use = "method returns a new number and does not mutate the original value"]

library/std/src/f32.rs

+2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ impl f32 {
210210
/// assert_eq!(one_plus_eps * one_minus_eps + minus_one, 0.0);
211211
/// ```
212212
#[rustc_allow_incoherent_impl]
213+
#[doc(alias = "fmaf", alias = "fusedMultiplyAdd")]
213214
#[must_use = "method returns a new number and does not mutate the original value"]
214215
#[stable(feature = "rust1", since = "1.0.0")]
215216
#[inline]
@@ -360,6 +361,7 @@ impl f32 {
360361
/// assert!(negative.sqrt().is_nan());
361362
/// assert!(negative_zero.sqrt() == negative_zero);
362363
/// ```
364+
#[doc(alias = "squareRoot")]
363365
#[rustc_allow_incoherent_impl]
364366
#[must_use = "method returns a new number and does not mutate the original value"]
365367
#[stable(feature = "rust1", since = "1.0.0")]

library/std/src/f64.rs

+2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ impl f64 {
210210
/// assert_eq!(one_plus_eps * one_minus_eps + minus_one, 0.0);
211211
/// ```
212212
#[rustc_allow_incoherent_impl]
213+
#[doc(alias = "fma", alias = "fusedMultiplyAdd")]
213214
#[must_use = "method returns a new number and does not mutate the original value"]
214215
#[stable(feature = "rust1", since = "1.0.0")]
215216
#[inline]
@@ -360,6 +361,7 @@ impl f64 {
360361
/// assert!(negative.sqrt().is_nan());
361362
/// assert!(negative_zero.sqrt() == negative_zero);
362363
/// ```
364+
#[doc(alias = "squareRoot")]
363365
#[rustc_allow_incoherent_impl]
364366
#[must_use = "method returns a new number and does not mutate the original value"]
365367
#[stable(feature = "rust1", since = "1.0.0")]

tests/ui/lifetimes/tail-expr-in-nested-expr.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ error[E0716]: temporary value dropped while borrowed
22
--> $DIR/tail-expr-in-nested-expr.rs:4:15
33
|
44
LL | let _ = { String::new().as_str() }.len();
5-
| ^^^^^^^^^^^^^---------
5+
| ^^^^^^^^^^^^^ - --- borrow later used by call
66
| | |
77
| | temporary value is freed at the end of this statement
88
| creates a temporary value which is freed while still in use
9-
| borrow later used here
109
|
1110
= note: consider using a `let` binding to create a longer lived value
1211

tests/ui/lint/lint-const-item-mutation.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,15 @@ warning: taking a mutable reference to a `const` item
7575
--> $DIR/lint-const-item-mutation.rs:42:5
7676
|
7777
LL | (&mut MY_STRUCT).use_mut();
78-
| ^^^^^^^^^^^^^^^^
78+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
7979
|
8080
= note: each usage of a `const` item creates a new temporary
8181
= note: the mutable reference will refer to this temporary, not the original `const` item
82+
note: mutable reference created due to call to this method
83+
--> $DIR/lint-const-item-mutation.rs:9:5
84+
|
85+
LL | fn use_mut(&mut self) {}
86+
| ^^^^^^^^^^^^^^^^^^^^^
8287
note: `const` item defined here
8388
--> $DIR/lint-const-item-mutation.rs:27:1
8489
|

tests/ui/moves/move-deref-coercion.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0382]: borrow of partially moved value: `val`
44
LL | let _val = val.first;
55
| --------- value partially moved here
66
LL | val.inner;
7-
| ^^^^^^^^^ value borrowed here after partial move
7+
| ^^^ value borrowed here after partial move
88
|
99
= note: partial move occurs because `val.first` has type `NotCopy`, which does not implement the `Copy` trait
1010
= note: borrow occurs due to deref coercion to `NotCopy`
@@ -20,7 +20,7 @@ error[E0382]: borrow of partially moved value: `val`
2020
LL | let _val = val.first;
2121
| --------- value partially moved here
2222
LL | val.inner_method();
23-
| ^^^^^^^^^^^^^^^^^^ value borrowed here after partial move
23+
| ^^^ value borrowed here after partial move
2424
|
2525
= note: partial move occurs because `val.first` has type `NotCopy`, which does not implement the `Copy` trait
2626
= note: borrow occurs due to deref coercion to `NotCopy`

tests/ui/no-capture-arc.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0382]: borrow of moved value: `arc_v`
2-
--> $DIR/no-capture-arc.rs:14:16
2+
--> $DIR/no-capture-arc.rs:14:18
33
|
44
LL | let arc_v = Arc::new(v);
55
| ----- move occurs because `arc_v` has type `Arc<Vec<i32>>`, which does not implement the `Copy` trait
@@ -10,7 +10,7 @@ LL | assert_eq!((*arc_v)[3], 4);
1010
| ----- variable moved due to use in closure
1111
...
1212
LL | assert_eq!((*arc_v)[2], 3);
13-
| ^^^^^^^^ value borrowed here after move
13+
| ^^^^^ value borrowed here after move
1414
|
1515
= note: borrow occurs due to deref coercion to `Vec<i32>`
1616

tests/ui/no-reuse-move-arc.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0382]: borrow of moved value: `arc_v`
2-
--> $DIR/no-reuse-move-arc.rs:12:16
2+
--> $DIR/no-reuse-move-arc.rs:12:18
33
|
44
LL | let arc_v = Arc::new(v);
55
| ----- move occurs because `arc_v` has type `Arc<Vec<i32>>`, which does not implement the `Copy` trait
@@ -10,7 +10,7 @@ LL | assert_eq!((*arc_v)[3], 4);
1010
| ----- variable moved due to use in closure
1111
...
1212
LL | assert_eq!((*arc_v)[2], 3);
13-
| ^^^^^^^^ value borrowed here after move
13+
| ^^^^^ value borrowed here after move
1414
|
1515
= note: borrow occurs due to deref coercion to `Vec<i32>`
1616

triagebot.toml

+10-1
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,11 @@ trigger_files = [
498498
"src/tools/compiletest"
499499
]
500500

501+
[autolabel."A-rustc-dev-guide"]
502+
trigger_files = [
503+
"src/doc/rustc-dev-guide",
504+
]
505+
501506
[notify-zulip."I-prioritize"]
502507
zulip_stream = 245100 # #t-compiler/wg-prioritization/alerts
503508
topic = "#{number} {title}"
@@ -990,6 +995,10 @@ https://github.com/rust-lang/reference/blob/HEAD/src/identifiers.md.
990995
"""
991996
cc = ["@ehuss"]
992997

998+
[mentions."src/doc/rustc-dev-guide"]
999+
message = "The rustc-dev-guide subtree was changed. If this PR *only* touches the dev guide consider submitting a PR directly to [rust-lang/rustc-dev-guide](https://github.com/rust-lang/rustc-dev-guide/pulls) otherwise thank you for updating the dev guide with your changes."
1000+
cc = ["@BoxyUwU", "@jieyouxu", "@kobzol"]
1001+
9931002
[assign]
9941003
warn_non_default_branch.enable = true
9951004
contributing_url = "https://rustc-dev-guide.rust-lang.org/getting-started.html"
@@ -1208,7 +1217,7 @@ project-exploit-mitigations = [
12081217
"/src/doc/nomicon" = ["@ehuss"]
12091218
"/src/doc/reference" = ["@ehuss"]
12101219
"/src/doc/rust-by-example" = ["@ehuss"]
1211-
"/src/doc/rustc-dev-guide" = ["@kobzol", "@jieyouxu"]
1220+
"/src/doc/rustc-dev-guide" = ["compiler"]
12121221
"/src/doc/rustdoc" = ["rustdoc"]
12131222
"/src/doc/style-guide" = ["style-team"]
12141223
"/src/etc" = ["@Mark-Simulacrum"]

0 commit comments

Comments
 (0)