Skip to content

Commit 7e2733b

Browse files
committed
Auto merge of rust-lang#98752 - matthiaskrgr:rollup-uwimznc, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#98610 (fix `emit_inference_failure_err` ICE) - rust-lang#98640 (Let rust-analyzer ship on stable, non-preview) - rust-lang#98686 (add ice test for 46511) - rust-lang#98727 (rustdoc: filter '_ lifetimes from ty::PolyTraitRef) - rust-lang#98729 (clarify that ExactSizeIterator::len returns the remaining length) - rust-lang#98733 (Request to be notified of MIR changes) - rust-lang#98734 (Update RELEASES.md) - rust-lang#98745 (Add a `--build-dir` flag to rustbuild) - rust-lang#98749 (Add macro_rules! rustdoc change to 1.62 relnotes) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents acdcdfb + 18d4228 commit 7e2733b

23 files changed

+200
-25
lines changed

RELEASES.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Language
55
--------
66

77
- [Stabilize `#[derive(Default)]` on enums with a `#[default]` variant][94457]
8-
- [Stop validating some checks in dead code after functions with uninhabited return types][93313]
8+
- [Teach flow sensitive checks that visibly uninhabited call expressions never return][93313]
99
- [Fix constants not getting dropped if part of a diverging expression][94775]
1010
- [Support unit struct/enum variant in destructuring assignment][95380]
1111
- [Remove mutable_borrow_reservation_conflict lint and allow the code pattern][96268]
@@ -75,6 +75,7 @@ Compatibility Notes
7575
- `cargo test` now passes `--target` to `rustdoc` if the specified target is
7676
the same as the host target.
7777
[#10594](https://github.com/rust-lang/cargo/pull/10594)
78+
- [rustdoc: doctests are now run on unexported `macro_rules!` macros, matching other private items][96630]
7879
- [rustdoc: Remove .woff font files][96279]
7980
- [Enforce Copy bounds for repeat elements while considering lifetimes][95819]
8081

@@ -109,6 +110,7 @@ and related tools.
109110
[96393]: https://github.com/rust-lang/rust/pull/96393/
110111
[96436]: https://github.com/rust-lang/rust/pull/96436/
111112
[96557]: https://github.com/rust-lang/rust/pull/96557/
113+
[96630]: https://github.com/rust-lang/rust/pull/96630/
112114

113115
[`bool::then_some`]: https://doc.rust-lang.org/stable/std/primitive.bool.html#method.then_some
114116
[`f32::total_cmp`]: https://doc.rust-lang.org/stable/std/primitive.f32.html#method.total_cmp

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

+17-6
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
334334
let mut local_visitor = FindInferSourceVisitor::new(&self, typeck_results, arg);
335335
if let Some(body_id) = body_id {
336336
let expr = self.tcx.hir().expect_expr(body_id.hir_id);
337-
debug!(?expr);
338337
local_visitor.visit_expr(expr);
339338
}
340339

@@ -550,6 +549,7 @@ impl<'tcx> InferSourceKind<'tcx> {
550549
}
551550
}
552551

552+
#[derive(Debug)]
553553
struct InsertableGenericArgs<'tcx> {
554554
insert_span: Span,
555555
substs: SubstsRef<'tcx>,
@@ -735,10 +735,20 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
735735
return self.path_inferred_subst_iter(expr.hir_id, substs, path);
736736
}
737737
}
738-
hir::ExprKind::Struct(path, _, _) => {
738+
// FIXME(#98711): Ideally we would also deal with type relative
739+
// paths here, even if that is quite rare.
740+
//
741+
// See the `need_type_info/expr-struct-type-relative-gat.rs` test
742+
// for an example where that would be needed.
743+
//
744+
// However, the `type_dependent_def_id` for `Self::Output` in an
745+
// impl is currently the `DefId` of `Output` in the trait definition
746+
// which makes this somewhat difficult and prevents us from just
747+
// using `self.path_inferred_subst_iter` here.
748+
hir::ExprKind::Struct(&hir::QPath::Resolved(_self_ty, path), _, _) => {
739749
if let Some(ty) = self.opt_node_type(expr.hir_id) {
740750
if let ty::Adt(_, substs) = ty.kind() {
741-
return self.path_inferred_subst_iter(expr.hir_id, substs, path);
751+
return Box::new(self.resolved_path_inferred_subst_iter(path, substs));
742752
}
743753
}
744754
}
@@ -945,6 +955,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
945955
intravisit::walk_body(self, body);
946956
}
947957

958+
#[instrument(level = "debug", skip(self))]
948959
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
949960
let tcx = self.infcx.tcx;
950961
match expr.kind {
@@ -959,9 +970,9 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
959970
_ => intravisit::walk_expr(self, expr),
960971
}
961972

962-
for InsertableGenericArgs { insert_span, substs, generics_def_id, def_id } in
963-
self.expr_inferred_subst_iter(expr)
964-
{
973+
for args in self.expr_inferred_subst_iter(expr) {
974+
debug!(?args);
975+
let InsertableGenericArgs { insert_span, substs, generics_def_id, def_id } = args;
965976
let generics = tcx.generics_of(generics_def_id);
966977
if let Some(argument_index) =
967978
generics.own_substs(substs).iter().position(|&arg| self.generic_arg_is_target(arg))

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
156156
self.typeck_results.borrow_mut().field_indices_mut().insert(hir_id, index);
157157
}
158158

159+
#[instrument(level = "debug", skip(self))]
159160
pub(in super::super) fn write_resolution(
160161
&self,
161162
hir_id: hir::HirId,
@@ -164,8 +165,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
164165
self.typeck_results.borrow_mut().type_dependent_defs_mut().insert(hir_id, r);
165166
}
166167

168+
#[instrument(level = "debug", skip(self))]
167169
pub fn write_method_call(&self, hir_id: hir::HirId, method: MethodCallee<'tcx>) {
168-
debug!("write_method_call(hir_id={:?}, method={:?})", hir_id, method);
169170
self.write_resolution(hir_id, Ok((DefKind::AssocFn, method.def_id)));
170171
self.write_substs(hir_id, method.substs);
171172

library/core/src/iter/traits/exact_size.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@
6666
///
6767
/// // And now we can use it!
6868
///
69-
/// let counter = Counter::new();
69+
/// let mut counter = Counter::new();
7070
///
7171
/// assert_eq!(5, counter.len());
72+
/// let _ = counter.next();
73+
/// assert_eq!(4, counter.len());
7274
/// ```
7375
#[stable(feature = "rust1", since = "1.0.0")]
7476
pub trait ExactSizeIterator: Iterator {
75-
/// Returns the exact length of the iterator.
77+
/// Returns the exact remaining length of the iterator.
7678
///
7779
/// The implementation ensures that the iterator will return exactly `len()`
7880
/// more times a [`Some(T)`] value, before returning [`None`].
@@ -93,9 +95,11 @@ pub trait ExactSizeIterator: Iterator {
9395
///
9496
/// ```
9597
/// // a finite range knows exactly how many times it will iterate
96-
/// let five = 0..5;
98+
/// let mut range = 0..5;
9799
///
98-
/// assert_eq!(5, five.len());
100+
/// assert_eq!(5, range.len());
101+
/// let _ = range.next();
102+
/// assert_eq!(4, range.len());
99103
/// ```
100104
#[inline]
101105
#[stable(feature = "rust1", since = "1.0.0")]

library/core/src/iter/traits/iterator.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,11 @@ pub trait Iterator {
177177
///
178178
/// ```
179179
/// let a = [1, 2, 3];
180-
/// let iter = a.iter();
180+
/// let mut iter = a.iter();
181181
///
182182
/// assert_eq!((3, Some(3)), iter.size_hint());
183+
/// let _ = iter.next();
184+
/// assert_eq!((2, Some(2)), iter.size_hint());
183185
/// ```
184186
///
185187
/// A more complex example:

src/bootstrap/bootstrap.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ def bootstrap(help_triggered):
866866

867867
parser = argparse.ArgumentParser(description='Build rust')
868868
parser.add_argument('--config')
869+
parser.add_argument('--build-dir')
869870
parser.add_argument('--build')
870871
parser.add_argument('--color', choices=['always', 'never', 'auto'])
871872
parser.add_argument('--clean', action='store_true')
@@ -915,7 +916,7 @@ def bootstrap(help_triggered):
915916

916917
build.check_vendored_status()
917918

918-
build_dir = build.get_toml('build-dir', 'build') or 'build'
919+
build_dir = args.build_dir or build.get_toml('build-dir', 'build') or 'build'
919920
build.build_dir = os.path.abspath(build_dir)
920921

921922
with open(os.path.join(build.rust_root, "src", "stage0.json")) as f:

src/bootstrap/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ impl Config {
857857
let build = toml.build.unwrap_or_default();
858858

859859
set(&mut config.initial_rustc, build.rustc.map(PathBuf::from));
860-
set(&mut config.out, build.build_dir.map(PathBuf::from));
860+
set(&mut config.out, flags.build_dir.or_else(|| build.build_dir.map(PathBuf::from)));
861861
// NOTE: Bootstrap spawns various commands with different working directories.
862862
// To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
863863
if !config.out.is_absolute() {

src/bootstrap/dist.rs

-6
Original file line numberDiff line numberDiff line change
@@ -1044,12 +1044,6 @@ impl Step for RustAnalyzer {
10441044
}
10451045

10461046
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1047-
// This prevents rust-analyzer from being built for "dist" or "install"
1048-
// on the stable/beta channels. It is a nightly-only tool and should
1049-
// not be included.
1050-
if !builder.build.unstable_features() {
1051-
return None;
1052-
}
10531047
let compiler = self.compiler;
10541048
let target = self.target;
10551049

src/bootstrap/flags.rs

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub struct Flags {
5151
pub host: Option<Vec<TargetSelection>>,
5252
pub target: Option<Vec<TargetSelection>>,
5353
pub config: Option<PathBuf>,
54+
pub build_dir: Option<PathBuf>,
5455
pub jobs: Option<u32>,
5556
pub cmd: Subcommand,
5657
pub incremental: bool,
@@ -174,6 +175,12 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
174175
opts.optflagmulti("v", "verbose", "use verbose output (-vv for very verbose)");
175176
opts.optflag("i", "incremental", "use incremental compilation");
176177
opts.optopt("", "config", "TOML configuration file for build", "FILE");
178+
opts.optopt(
179+
"",
180+
"build-dir",
181+
"Build directory, overrides `build.build-dir` in `config.toml`",
182+
"DIR",
183+
);
177184
opts.optopt("", "build", "build target of the stage0 compiler", "BUILD");
178185
opts.optmulti("", "host", "host targets to build", "HOST");
179186
opts.optmulti("", "target", "target targets to build", "TARGET");
@@ -649,6 +656,7 @@ Arguments:
649656
None
650657
},
651658
config: matches.opt_str("config").map(PathBuf::from),
659+
build_dir: matches.opt_str("build-dir").map(PathBuf::from),
652660
jobs: matches.opt_str("jobs").map(|j| j.parse().expect("`jobs` should be a number")),
653661
cmd,
654662
incremental: matches.opt_present("incremental"),

src/bootstrap/tool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ tool_extended!((self, builder),
780780
// and this is close enough for now.
781781
RustDemangler, rust_demangler, "src/tools/rust-demangler", "rust-demangler", stable=false, in_tree=true, tool_std=true, {};
782782
Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, in_tree=true, {};
783-
RustAnalyzer, rust_analyzer, "src/tools/rust-analyzer/crates/rust-analyzer", "rust-analyzer", stable=false, submodule="rust-analyzer", {};
783+
RustAnalyzer, rust_analyzer, "src/tools/rust-analyzer/crates/rust-analyzer", "rust-analyzer", stable=true, submodule="rust-analyzer", {};
784784
);
785785

786786
impl<'a> Builder<'a> {

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn clean_poly_trait_ref_with_bindings<'tcx>(
167167
.collect_referenced_late_bound_regions(&poly_trait_ref)
168168
.into_iter()
169169
.filter_map(|br| match br {
170-
ty::BrNamed(_, name) => Some(GenericParamDef {
170+
ty::BrNamed(_, name) if name != kw::UnderscoreLifetime => Some(GenericParamDef {
171171
name,
172172
kind: GenericParamDefKind::Lifetime { outlives: vec![] },
173173
}),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// When reexporting this function, make sure the anonymous lifetimes are not rendered.
2+
///
3+
/// https://github.com/rust-lang/rust/issues/98697
4+
pub fn repro<F>()
5+
where
6+
F: Fn(&str),
7+
{
8+
unimplemented!()
9+
}

src/test/rustdoc/issue-98697.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// aux-build:issue-98697-reexport-with-anonymous-lifetime.rs
2+
// ignore-cross-compile
3+
4+
// When reexporting a function with a HRTB with anonymous lifetimes,
5+
// make sure the anonymous lifetimes are not rendered.
6+
//
7+
// https://github.com/rust-lang/rust/issues/98697
8+
9+
extern crate issue_98697_reexport_with_anonymous_lifetime;
10+
11+
// @has issue_98697/fn.repro.html '//pre[@class="rust fn"]/code' 'fn repro<F>() where F: Fn(&str)'
12+
// @!has issue_98697/fn.repro.html '//pre[@class="rust fn"]/code' 'for<'
13+
pub use issue_98697_reexport_with_anonymous_lifetime::repro;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// check-fail
2+
3+
struct Foo<'a> //~ ERROR parameter `'a` is never used [E0392]
4+
{
5+
_a: [u8; std::mem::size_of::<&'a mut u8>()] //~ ERROR a non-static lifetime is not allowed in a `const`
6+
}
7+
8+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0658]: a non-static lifetime is not allowed in a `const`
2+
--> $DIR/issue-46511.rs:5:35
3+
|
4+
LL | _a: [u8; std::mem::size_of::<&'a mut u8>()]
5+
| ^^
6+
|
7+
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
8+
= help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable
9+
10+
error[E0392]: parameter `'a` is never used
11+
--> $DIR/issue-46511.rs:3:12
12+
|
13+
LL | struct Foo<'a>
14+
| ^^ unused parameter
15+
|
16+
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`
17+
18+
error: aborting due to 2 previous errors
19+
20+
Some errors have detailed explanations: E0392, E0658.
21+
For more information about an error, try `rustc --explain E0392`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
trait Foo {
2+
type Output;
3+
4+
fn baz() -> Self::Output;
5+
}
6+
7+
fn needs_infer<T>() {}
8+
9+
enum Bar {
10+
Variant {}
11+
}
12+
13+
impl Foo for u8 {
14+
type Output = Bar;
15+
fn baz() -> Self::Output {
16+
needs_infer(); //~ ERROR type annotations needed
17+
Self::Output::Variant {}
18+
}
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/expr-struct-type-relative-enum.rs:16:9
3+
|
4+
LL | needs_infer();
5+
| ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `needs_infer`
6+
|
7+
help: consider specifying the generic argument
8+
|
9+
LL | needs_infer::<T>();
10+
| +++++
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0282`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(generic_associated_types)]
2+
3+
trait Foo {
4+
type Output<T>;
5+
6+
fn baz();
7+
}
8+
9+
enum Bar<T> {
10+
Simple {},
11+
Generic(T),
12+
}
13+
14+
impl Foo for u8 {
15+
type Output<T> = Bar<T>;
16+
fn baz() {
17+
Self::Output::Simple {}; //~ ERROR type annotations needed
18+
}
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/expr-struct-type-relative-gat.rs:17:9
3+
|
4+
LL | Self::Output::Simple {};
5+
| ^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the associated type `Output`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0282`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// regression test for #98598
2+
3+
trait Foo {
4+
type Output;
5+
6+
fn baz() -> Self::Output;
7+
}
8+
9+
fn needs_infer<T>() {}
10+
11+
struct Bar {}
12+
13+
impl Foo for u8 {
14+
type Output = Bar;
15+
fn baz() -> Self::Output {
16+
needs_infer(); //~ ERROR type annotations needed
17+
Self::Output {}
18+
}
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/expr-struct-type-relative.rs:16:9
3+
|
4+
LL | needs_infer();
5+
| ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `needs_infer`
6+
|
7+
help: consider specifying the generic argument
8+
|
9+
LL | needs_infer::<T>();
10+
| +++++
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)