Skip to content

Commit 8ea62f6

Browse files
committed
Auto merge of rust-lang#106588 - JohnTitor:rollup-4z80tjx, r=JohnTitor
Rollup of 8 pull requests Successful merges: - rust-lang#103104 (Stabilize `main_separator_str`) - rust-lang#106410 (Suggest `mut self: &mut Self` for `?Sized` impls) - rust-lang#106457 (Adjust comments about pre-push.sh hook) - rust-lang#106546 (jsondoclint: Check local items in `paths` are also in `index`.) - rust-lang#106557 (Add some UI tests and reword error-code docs) - rust-lang#106562 (Clarify examples for `VecDeque::get/get_mut`) - rust-lang#106580 (remove unreachable error code `E0313`) - rust-lang#106581 (Do not emit wrong E0308 suggestion for closure mismatch) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2afe585 + 789ebdc commit 8ea62f6

File tree

22 files changed

+268
-94
lines changed

22 files changed

+268
-94
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,20 +344,25 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
344344
} else {
345345
err.span_help(source_info.span, "try removing `&mut` here");
346346
}
347-
} else if decl.mutability == Mutability::Not
348-
&& !matches!(
347+
} else if decl.mutability == Mutability::Not {
348+
if matches!(
349349
decl.local_info,
350350
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(
351351
hir::ImplicitSelfKind::MutRef
352-
))))
353-
)
354-
{
355-
err.span_suggestion_verbose(
356-
decl.source_info.span.shrink_to_lo(),
357-
"consider making the binding mutable",
358-
"mut ",
359-
Applicability::MachineApplicable,
360-
);
352+
),)))
353+
) {
354+
err.note(
355+
"as `Self` may be unsized, this call attempts to take `&mut &mut self`",
356+
);
357+
err.note("however, `&mut self` expands to `self: &mut Self`, therefore `self` cannot be borrowed mutably");
358+
} else {
359+
err.span_suggestion_verbose(
360+
decl.source_info.span.shrink_to_lo(),
361+
"consider making the binding mutable",
362+
"mut ",
363+
Applicability::MachineApplicable,
364+
);
365+
};
361366
}
362367
}
363368

compiler/rustc_error_codes/src/error_codes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,7 @@ E0791: include_str!("./error_codes/E0791.md"),
579579
// E0300, // unexpanded macro
580580
// E0304, // expected signed integer constant
581581
// E0305, // expected constant
582-
E0313, // lifetime of borrowed pointer outlives lifetime of captured
583-
// variable
582+
// E0313, // removed: found unreachable
584583
// E0314, // closure outlives stack frame
585584
// E0315, // cannot invoke closure outside of its lifetime
586585
// E0319, // trait impls for defaulted traits allowed just for structs/enums
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
A constant item was initialized with something that is not a constant
2-
expression.
1+
A non-`const` function was called in a `const` context.
32

43
Erroneous code example:
54

@@ -8,26 +7,20 @@ fn create_some() -> Option<u8> {
87
Some(1)
98
}
109
11-
const FOO: Option<u8> = create_some(); // error!
10+
// error: cannot call non-const fn `create_some` in constants
11+
const FOO: Option<u8> = create_some();
1212
```
1313

14-
The only functions that can be called in static or constant expressions are
15-
`const` functions, and struct/enum constructors.
14+
All functions used in a `const` context (constant or static expression) must
15+
be marked `const`.
1616

1717
To fix this error, you can declare `create_some` as a constant function:
1818

1919
```
20-
const fn create_some() -> Option<u8> { // declared as a const function
20+
// declared as a `const` function:
21+
const fn create_some() -> Option<u8> {
2122
Some(1)
2223
}
2324
24-
const FOO: Option<u8> = create_some(); // ok!
25-
26-
// These are also working:
27-
struct Bar {
28-
x: u8,
29-
}
30-
31-
const OTHER_FOO: Option<u8> = Some(1);
32-
const BAR: Bar = Bar {x: 1};
25+
const FOO: Option<u8> = create_some(); // no error!
3326
```

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13791379
}
13801380
}
13811381
// If we've reached our target type with just removing `&`, then just print now.
1382-
if steps == 0 {
1382+
if steps == 0 && !remove.trim().is_empty() {
13831383
return Some((
13841384
prefix_span,
13851385
format!("consider removing the `{}`", remove.trim()),
@@ -1438,6 +1438,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14381438
} else {
14391439
(prefix_span, format!("{}{}", prefix, "*".repeat(steps)))
14401440
};
1441+
if suggestion.trim().is_empty() {
1442+
return None;
1443+
}
14411444

14421445
return Some((
14431446
span,

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore-tidy-filelength
21
//! Error Reporting Code for the inference engine
32
//!
43
//! Because of the way inference, and in particular region inference,

compiler/rustc_infer/src/infer/error_reporting/note.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2525
infer::Reborrow(span) => {
2626
RegionOriginNote::Plain { span, msg: fluent::infer_reborrow }.add_to_diagnostic(err)
2727
}
28-
infer::ReborrowUpvar(span, ref upvar_id) => {
29-
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
30-
RegionOriginNote::WithName {
31-
span,
32-
msg: fluent::infer_reborrow,
33-
name: &var_name.to_string(),
34-
continues: false,
35-
}
36-
.add_to_diagnostic(err);
37-
}
3828
infer::RelateObjectBound(span) => {
3929
RegionOriginNote::Plain { span, msg: fluent::infer_relate_object_bound }
4030
.add_to_diagnostic(err);
@@ -162,33 +152,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
162152
);
163153
err
164154
}
165-
infer::ReborrowUpvar(span, ref upvar_id) => {
166-
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
167-
let mut err = struct_span_err!(
168-
self.tcx.sess,
169-
span,
170-
E0313,
171-
"lifetime of borrowed pointer outlives lifetime of captured variable `{}`...",
172-
var_name
173-
);
174-
note_and_explain_region(
175-
self.tcx,
176-
&mut err,
177-
"...the borrowed pointer is valid for ",
178-
sub,
179-
"...",
180-
None,
181-
);
182-
note_and_explain_region(
183-
self.tcx,
184-
&mut err,
185-
&format!("...but `{}` is only valid for ", var_name),
186-
sup,
187-
"",
188-
None,
189-
);
190-
err
191-
}
192155
infer::RelateObjectBound(span) => {
193156
let mut err = struct_span_err!(
194157
self.tcx.sess,

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,6 @@ pub enum SubregionOrigin<'tcx> {
409409
/// Creating a pointer `b` to contents of another reference
410410
Reborrow(Span),
411411

412-
/// Creating a pointer `b` to contents of an upvar
413-
ReborrowUpvar(Span, ty::UpvarId),
414-
415412
/// Data with type `Ty<'tcx>` was borrowed
416413
DataBorrowed(Ty<'tcx>, Span),
417414

@@ -1954,7 +1951,6 @@ impl<'tcx> SubregionOrigin<'tcx> {
19541951
RelateParamBound(a, ..) => a,
19551952
RelateRegionParamBound(a) => a,
19561953
Reborrow(a) => a,
1957-
ReborrowUpvar(a, _) => a,
19581954
DataBorrowed(_, a) => a,
19591955
ReferenceOutlivesReferent(_, a) => a,
19601956
CompareImplItemObligation { span, .. } => span,

library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
636636
/// buf.push_back(3);
637637
/// buf.push_back(4);
638638
/// buf.push_back(5);
639+
/// buf.push_back(6);
639640
/// assert_eq!(buf.get(1), Some(&4));
640641
/// ```
641642
#[stable(feature = "rust1", since = "1.0.0")]
@@ -661,10 +662,11 @@ impl<T, A: Allocator> VecDeque<T, A> {
661662
/// buf.push_back(3);
662663
/// buf.push_back(4);
663664
/// buf.push_back(5);
665+
/// buf.push_back(6);
666+
/// assert_eq!(buf[1], 4);
664667
/// if let Some(elem) = buf.get_mut(1) {
665668
/// *elem = 7;
666669
/// }
667-
///
668670
/// assert_eq!(buf[1], 7);
669671
/// ```
670672
#[stable(feature = "rust1", since = "1.0.0")]

library/std/src/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ pub const MAIN_SEPARATOR: char = crate::sys::path::MAIN_SEP;
271271
/// The primary separator of path components for the current platform.
272272
///
273273
/// For example, `/` on Unix and `\` on Windows.
274-
#[unstable(feature = "main_separator_str", issue = "94071")]
274+
#[stable(feature = "main_separator_str", since = "CURRENT_RUSTC_VERSION")]
275275
pub const MAIN_SEPARATOR_STR: &str = crate::sys::path::MAIN_SEP_STR;
276276

277277
////////////////////////////////////////////////////////////////////////////////

src/bootstrap/setup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ pub fn interactive_path() -> io::Result<Profile> {
351351
Ok(template)
352352
}
353353

354-
// install a git hook to automatically run tidy --bless, if they want
354+
// install a git hook to automatically run tidy, if they want
355355
fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
356356
let git = t!(config.git().args(&["rev-parse", "--git-common-dir"]).output().map(|output| {
357357
assert!(output.status.success(), "failed to run `git`");
@@ -367,7 +367,7 @@ fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
367367
println!();
368368
println!(
369369
"Rust's CI will automatically fail if it doesn't pass `tidy`, the internal tool for ensuring code quality.
370-
If you'd like, x.py can install a git hook for you that will automatically run `tidy --bless` before
370+
If you'd like, x.py can install a git hook for you that will automatically run `test tidy` before
371371
pushing your code to ensure your code is up to par. If you decide later that this behavior is
372372
undesirable, simply delete the `pre-push` file from .git/hooks."
373373
);

0 commit comments

Comments
 (0)