Skip to content

Commit 25a2c13

Browse files
committed
Auto merge of #82249 - JohnTitor:rollup-3jbqija, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #82055 (Add diagnostics for specific cases for const/type mismatch err) - #82155 (Use !Sync std::lazy::OnceCell in usefulness checking) - #82202 (add specs for riscv32/riscv64 musl targets) - #82203 (Move some tests to more reasonable directories - 4) - #82211 (make `suggest_setup` help messages better) - #82212 (Remove redundant rustc_data_structures path component) - #82240 (remove useless ?s (clippy::needless_question_marks)) - #82243 (Add more intra-doc links to std::io) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d1462d8 + 21283da commit 25a2c13

File tree

76 files changed

+209
-77
lines changed

Some content is hidden

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

76 files changed

+209
-77
lines changed

compiler/rustc_infer/src/infer/canonical/query_response.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
507507

508508
// Unify the original value for each variable with the value
509509
// taken from `query_response` (after applying `result_subst`).
510-
Ok(self.unify_canonical_vars(
511-
cause,
512-
param_env,
513-
original_values,
514-
substituted_query_response,
515-
)?)
510+
self.unify_canonical_vars(cause, param_env, original_values, substituted_query_response)
516511
}
517512

518513
/// Converts the region constraints resulting from a query into an

compiler/rustc_middle/src/ty/codec.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for SubstsRef<'tcx> {
253253
fn decode(decoder: &mut D) -> Result<Self, D::Error> {
254254
let len = decoder.read_usize()?;
255255
let tcx = decoder.tcx();
256-
Ok(tcx.mk_substs((0..len).map(|_| Decodable::decode(decoder)))?)
256+
tcx.mk_substs((0..len).map(|_| Decodable::decode(decoder)))
257257
}
258258
}
259259

@@ -314,7 +314,7 @@ impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::AdtDef {
314314
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List<Ty<'tcx>> {
315315
fn decode(decoder: &mut D) -> Result<&'tcx Self, D::Error> {
316316
let len = decoder.read_usize()?;
317-
Ok(decoder.tcx().mk_type_list((0..len).map(|_| Decodable::decode(decoder)))?)
317+
decoder.tcx().mk_type_list((0..len).map(|_| Decodable::decode(decoder)))
318318
}
319319
}
320320

@@ -323,9 +323,7 @@ impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D>
323323
{
324324
fn decode(decoder: &mut D) -> Result<&'tcx Self, D::Error> {
325325
let len = decoder.read_usize()?;
326-
Ok(decoder
327-
.tcx()
328-
.mk_poly_existential_predicates((0..len).map(|_| Decodable::decode(decoder)))?)
326+
decoder.tcx().mk_poly_existential_predicates((0..len).map(|_| Decodable::decode(decoder)))
329327
}
330328
}
331329

compiler/rustc_middle/src/ty/print/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ pub trait PrettyPrinter<'tcx>:
607607
return Ok(self);
608608
}
609609

610-
return Ok(with_no_queries(|| {
610+
return with_no_queries(|| {
611611
let def_key = self.tcx().def_key(def_id);
612612
if let Some(name) = def_key.disambiguated_data.data.get_opt_name() {
613613
p!(write("{}", name));
@@ -649,7 +649,7 @@ pub trait PrettyPrinter<'tcx>:
649649
p!(" Sized");
650650
}
651651
Ok(self)
652-
})?);
652+
});
653653
}
654654
ty::Str => p!("str"),
655655
ty::Generator(did, substs, movability) => {

compiler/rustc_middle/src/ty/relate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub fn relate_substs<R: TypeRelation<'tcx>>(
154154
relation.relate_with_variance(variance, a, b)
155155
});
156156

157-
Ok(tcx.mk_substs(params)?)
157+
tcx.mk_substs(params)
158158
}
159159

160160
impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
@@ -647,7 +647,7 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::Binder<ty::ExistentialPredicate<'
647647
_ => Err(TypeError::ExistentialMismatch(expected_found(relation, a, b))),
648648
}
649649
});
650-
Ok(tcx.mk_poly_existential_predicates(v)?)
650+
tcx.mk_poly_existential_predicates(v)
651651
}
652652
}
653653

compiler/rustc_mir/src/interpret/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
118118
.get_raw(vtable_slot.alloc_id)?
119119
.read_ptr_sized(self, vtable_slot)?
120120
.check_init()?;
121-
Ok(self.memory.get_fn(fn_ptr)?)
121+
self.memory.get_fn(fn_ptr)
122122
}
123123

124124
/// Returns the drop fn instance as well as the actual dynamic type.

compiler/rustc_mir/src/util/generic_graphviz.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::io::{self, Write};
66
pub struct GraphvizWriter<
77
'a,
88
G: graph::DirectedGraph + graph::WithSuccessors + graph::WithStartNode + graph::WithNumNodes,
9-
NodeContentFn: Fn(<G as rustc_data_structures::graph::DirectedGraph>::Node) -> Vec<String>,
10-
EdgeLabelsFn: Fn(<G as rustc_data_structures::graph::DirectedGraph>::Node) -> Vec<String>,
9+
NodeContentFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>,
10+
EdgeLabelsFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>,
1111
> {
1212
graph: &'a G,
1313
is_subgraph: bool,
@@ -20,8 +20,8 @@ pub struct GraphvizWriter<
2020
impl<
2121
'a,
2222
G: graph::DirectedGraph + graph::WithSuccessors + graph::WithStartNode + graph::WithNumNodes,
23-
NodeContentFn: Fn(<G as rustc_data_structures::graph::DirectedGraph>::Node) -> Vec<String>,
24-
EdgeLabelsFn: Fn(<G as rustc_data_structures::graph::DirectedGraph>::Node) -> Vec<String>,
23+
NodeContentFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>,
24+
EdgeLabelsFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>,
2525
> GraphvizWriter<'a, G, NodeContentFn, EdgeLabelsFn>
2626
{
2727
pub fn new(

compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ use super::{PatternFoldable, PatternFolder};
289289

290290
use rustc_data_structures::captures::Captures;
291291
use rustc_data_structures::fx::FxHashMap;
292-
use rustc_data_structures::sync::OnceCell;
293292

294293
use rustc_arena::TypedArena;
295294
use rustc_hir::def_id::DefId;
@@ -300,6 +299,7 @@ use rustc_span::Span;
300299
use smallvec::{smallvec, SmallVec};
301300
use std::fmt;
302301
use std::iter::{FromIterator, IntoIterator};
302+
use std::lazy::OnceCell;
303303

304304
crate struct MatchCheckCtxt<'a, 'tcx> {
305305
crate tcx: TyCtxt<'tcx>,

compiler/rustc_target/src/spec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -783,9 +783,11 @@ supported_targets! {
783783
("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),
784784
("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf),
785785
("riscv32gc-unknown-linux-gnu", riscv32gc_unknown_linux_gnu),
786+
("riscv32gc-unknown-linux-musl", riscv32gc_unknown_linux_musl),
786787
("riscv64imac-unknown-none-elf", riscv64imac_unknown_none_elf),
787788
("riscv64gc-unknown-none-elf", riscv64gc_unknown_none_elf),
788789
("riscv64gc-unknown-linux-gnu", riscv64gc_unknown_linux_gnu),
790+
("riscv64gc-unknown-linux-musl", riscv64gc_unknown_linux_musl),
789791

790792
("aarch64-unknown-none", aarch64_unknown_none),
791793
("aarch64-unknown-none-softfloat", aarch64_unknown_none_softfloat),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::spec::{CodeModel, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
Target {
5+
llvm_target: "riscv32-unknown-linux-musl".to_string(),
6+
pointer_width: 32,
7+
data_layout: "e-m:e-p:32:32-i64:64-n32-S128".to_string(),
8+
arch: "riscv32".to_string(),
9+
options: TargetOptions {
10+
unsupported_abis: super::riscv_base::unsupported_abis(),
11+
code_model: Some(CodeModel::Medium),
12+
cpu: "generic-rv32".to_string(),
13+
features: "+m,+a,+f,+d,+c".to_string(),
14+
llvm_abiname: "ilp32d".to_string(),
15+
max_atomic_width: Some(32),
16+
..super::linux_musl_base::opts()
17+
},
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::spec::{CodeModel, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
Target {
5+
llvm_target: "riscv64-unknown-linux-musl".to_string(),
6+
pointer_width: 64,
7+
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".to_string(),
8+
arch: "riscv64".to_string(),
9+
options: TargetOptions {
10+
unsupported_abis: super::riscv_base::unsupported_abis(),
11+
code_model: Some(CodeModel::Medium),
12+
cpu: "generic-rv64".to_string(),
13+
features: "+m,+a,+f,+d,+c".to_string(),
14+
llvm_abiname: "lp64d".to_string(),
15+
max_atomic_width: Some(64),
16+
..super::linux_musl_base::opts()
17+
},
18+
}
19+
}

compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ where
4343
info!("fully_perform({:?})", self);
4444
}
4545

46-
scrape_region_constraints(infcx, || Ok((self.closure)(infcx)?))
46+
scrape_region_constraints(infcx, || (self.closure)(infcx))
4747
}
4848
}
4949

compiler/rustc_typeck/src/astconv/generics.rs

+50-15
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use crate::astconv::{
66
use crate::errors::AssocTypeBindingNotAllowed;
77
use crate::structured_errors::{StructuredDiagnostic, WrongNumberOfGenericArgs};
88
use rustc_ast::ast::ParamKindOrd;
9-
use rustc_errors::{struct_span_err, Applicability, ErrorReported};
9+
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
1010
use rustc_hir as hir;
11+
use rustc_hir::def::{DefKind, Res};
1112
use rustc_hir::def_id::DefId;
1213
use rustc_hir::GenericArg;
1314
use rustc_middle::ty::{
@@ -43,23 +44,57 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
4344
}
4445
}
4546

47+
let add_braces_suggestion = |arg: &GenericArg<'_>, err: &mut DiagnosticBuilder<'_>| {
48+
let suggestions = vec![
49+
(arg.span().shrink_to_lo(), String::from("{ ")),
50+
(arg.span().shrink_to_hi(), String::from(" }")),
51+
];
52+
err.multipart_suggestion(
53+
"if this generic argument was intended as a const parameter, \
54+
surround it with braces",
55+
suggestions,
56+
Applicability::MaybeIncorrect,
57+
);
58+
};
59+
4660
// Specific suggestion set for diagnostics
4761
match (arg, &param.kind) {
4862
(
49-
GenericArg::Type(hir::Ty { kind: hir::TyKind::Path { .. }, .. }),
50-
GenericParamDefKind::Const { .. },
51-
) => {
52-
let suggestions = vec![
53-
(arg.span().shrink_to_lo(), String::from("{ ")),
54-
(arg.span().shrink_to_hi(), String::from(" }")),
55-
];
56-
err.multipart_suggestion(
57-
"if this generic argument was intended as a const parameter, \
58-
try surrounding it with braces:",
59-
suggestions,
60-
Applicability::MaybeIncorrect,
61-
);
62-
}
63+
GenericArg::Type(hir::Ty {
64+
kind: hir::TyKind::Path(rustc_hir::QPath::Resolved(_, path)),
65+
..
66+
}),
67+
GenericParamDefKind::Const,
68+
) => match path.res {
69+
Res::Err => {
70+
add_braces_suggestion(arg, &mut err);
71+
err.set_primary_message(
72+
"unresolved item provided when a constant was expected",
73+
)
74+
.emit();
75+
return;
76+
}
77+
Res::Def(DefKind::TyParam, src_def_id) => {
78+
if let Some(param_local_id) = param.def_id.as_local() {
79+
let param_hir_id = tcx.hir().local_def_id_to_hir_id(param_local_id);
80+
let param_name = tcx.hir().ty_param_name(param_hir_id);
81+
let param_type = tcx.type_of(param.def_id);
82+
if param_type.is_suggestable() {
83+
err.span_suggestion(
84+
tcx.def_span(src_def_id),
85+
"consider changing this type paramater to a `const`-generic",
86+
format!("const {}: {}", param_name, param_type),
87+
Applicability::MaybeIncorrect,
88+
);
89+
};
90+
}
91+
}
92+
_ => add_braces_suggestion(arg, &mut err),
93+
},
94+
(
95+
GenericArg::Type(hir::Ty { kind: hir::TyKind::Path(_), .. }),
96+
GenericParamDefKind::Const,
97+
) => add_braces_suggestion(arg, &mut err),
6398
(
6499
GenericArg::Type(hir::Ty { kind: hir::TyKind::Array(_, len), .. }),
65100
GenericParamDefKind::Const { .. },

compiler/rustc_typeck/src/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11411141
let trait_def_ids: FxHashSet<DefId> = param
11421142
.bounds
11431143
.iter()
1144-
.filter_map(|bound| Some(bound.trait_ref()?.trait_def_id()?))
1144+
.filter_map(|bound| bound.trait_ref()?.trait_def_id())
11451145
.collect();
11461146
if !candidates.iter().any(|t| trait_def_ids.contains(&t.def_id)) {
11471147
err.span_suggestions(

library/std/src/io/stdio.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ pub struct Stdin {
231231
inner: &'static Mutex<BufReader<StdinRaw>>,
232232
}
233233

234-
/// A locked reference to the `Stdin` handle.
234+
/// A locked reference to the [`Stdin`] handle.
235235
///
236236
/// This handle implements both the [`Read`] and [`BufRead`] traits, and
237237
/// is constructed via the [`Stdin::lock`] method.
@@ -494,7 +494,7 @@ pub struct Stdout {
494494
inner: Pin<&'static ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>>,
495495
}
496496

497-
/// A locked reference to the `Stdout` handle.
497+
/// A locked reference to the [`Stdout`] handle.
498498
///
499499
/// This handle implements the [`Write`] trait, and is constructed via
500500
/// the [`Stdout::lock`] method.
@@ -708,9 +708,9 @@ pub struct Stderr {
708708
inner: Pin<&'static ReentrantMutex<RefCell<StderrRaw>>>,
709709
}
710710

711-
/// A locked reference to the `Stderr` handle.
711+
/// A locked reference to the [`Stderr`] handle.
712712
///
713-
/// This handle implements the `Write` trait and is constructed via
713+
/// This handle implements the [`Write`] trait and is constructed via
714714
/// the [`Stderr::lock`] method.
715715
///
716716
/// ### Note: Windows Portability Consideration

src/bootstrap/bin/main.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ fn main() {
2222
let suggest_setup = !config.config.exists() && !matches!(config.cmd, Subcommand::Setup { .. });
2323
if suggest_setup {
2424
println!("warning: you have not made a `config.toml`");
25-
println!("help: consider running `x.py setup` or copying `config.toml.example`");
25+
println!(
26+
"help: consider running `./x.py setup` or copying `config.toml.example` by running \
27+
`cp config.toml.example config.toml`"
28+
);
2629
} else if let Some(suggestion) = &changelog_suggestion {
2730
println!("{}", suggestion);
2831
}
@@ -31,7 +34,10 @@ fn main() {
3134

3235
if suggest_setup {
3336
println!("warning: you have not made a `config.toml`");
34-
println!("help: consider running `x.py setup` or copying `config.toml.example`");
37+
println!(
38+
"help: consider running `./x.py setup` or copying `config.toml.example` by running \
39+
`cp config.toml.example config.toml`"
40+
);
3541
} else if let Some(suggestion) = &changelog_suggestion {
3642
println!("{}", suggestion);
3743
}

src/doc/rustc/src/platform-support.md

+2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ target | std | host | notes
204204
`powerpc64-unknown-linux-musl` | ? | |
205205
`powerpc64-wrs-vxworks` | ? | |
206206
`powerpc64le-unknown-linux-musl` | ? | |
207+
`riscv64gc-unknown-linux-musl` | | | RISC-V Linux (kernel 4.20, musl 1.2.0)
207208
`riscv32gc-unknown-linux-gnu` | | | RISC-V Linux (kernel 5.4, glibc 2.33)
209+
`riscv32gc-unknown-linux-musl` | | | RISC-V Linux (kernel 5.4, musl + RISCV32 support patches)
208210
`sparc-unknown-linux-gnu` | ✓ | | 32-bit SPARC Linux
209211
`sparc64-unknown-netbsd` | ✓ | ✓ | NetBSD/sparc64
210212
`sparc64-unknown-openbsd` | ? | |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/test/ui/const-generics/const-param-shadowing.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0747]: type provided when a constant was expected
44
LL | fn test<const N: usize>() -> Foo<N> {
55
| ^
66
|
7-
help: if this generic argument was intended as a const parameter, try surrounding it with braces:
7+
help: if this generic argument was intended as a const parameter, surround it with braces
88
|
99
LL | fn test<const N: usize>() -> Foo<{ N }> {
1010
| ^ ^
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![crate_type="lib"]
2+
#![feature(min_const_generics)]
3+
#![allow(incomplete_features)]
4+
5+
struct A<const N: u8>;
6+
trait Foo {}
7+
impl Foo for A<N> {}
8+
//~^ ERROR cannot find type
9+
//~| unresolved item provided when a constant
10+
11+
struct B<const N: u8>;
12+
impl<N> Foo for B<N> {}
13+
//~^ ERROR type provided when a constant
14+
15+
struct C<const C: u8, const N: u8>;
16+
impl<const N: u8> Foo for C<N, T> {}
17+
//~^ ERROR cannot find type
18+
//~| unresolved item provided when a constant

0 commit comments

Comments
 (0)