Skip to content

Commit b92a41c

Browse files
committed
Auto merge of rust-lang#110636 - matthiaskrgr:rollup-faa33c6, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#110365 (ship tools with sysroot) - rust-lang#110555 (Substitute missing trait items suggestion correctly) - rust-lang#110578 (fix(error): normalize whitespace during msg_to_buffer) - rust-lang#110597 (remove unused ftl messages) - rust-lang#110611 (Add regression test for rust-lang#46506) - rust-lang#110618 (Track if EvalCtxt has been tainted, make sure it can't be used to make query responses after) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 77778e0 + 77de5f0 commit b92a41c

25 files changed

+210
-84
lines changed

compiler/rustc_errors/src/emitter.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,7 @@ impl EmitterWriter {
13361336
// see?
13371337
for (text, style) in msg.iter() {
13381338
let text = self.translate_message(text, args).map_err(Report::new).unwrap();
1339+
let text = &normalize_whitespace(&text);
13391340
let lines = text.split('\n').collect::<Vec<_>>();
13401341
if lines.len() > 1 {
13411342
for (i, line) in lines.iter().enumerate() {

compiler/rustc_hir_analysis/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ fn check_impl_items_against_trait<'tcx>(
863863
if !missing_items.is_empty() {
864864
let full_impl_span =
865865
tcx.hir().span_with_body(tcx.hir().local_def_id_to_hir_id(impl_id));
866-
missing_items_err(tcx, tcx.def_span(impl_id), &missing_items, full_impl_span);
866+
missing_items_err(tcx, impl_id, &missing_items, full_impl_span);
867867
}
868868

869869
if let Some(missing_items) = must_implement_one_of {

compiler/rustc_hir_analysis/src/check/mod.rs

+31-10
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn report_forbidden_specialization(tcx: TyCtxt<'_>, impl_item: DefId, parent_imp
198198

199199
fn missing_items_err(
200200
tcx: TyCtxt<'_>,
201-
impl_span: Span,
201+
impl_def_id: LocalDefId,
202202
missing_items: &[ty::AssocItem],
203203
full_impl_span: Span,
204204
) {
@@ -211,6 +211,7 @@ fn missing_items_err(
211211
.collect::<Vec<_>>()
212212
.join("`, `");
213213

214+
let impl_span = tcx.def_span(impl_def_id);
214215
let mut err = struct_span_err!(
215216
tcx.sess,
216217
impl_span,
@@ -229,7 +230,11 @@ fn missing_items_err(
229230
tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(|| String::new());
230231

231232
for &trait_item in missing_items {
232-
let snippet = suggestion_signature(trait_item, tcx);
233+
let snippet = suggestion_signature(
234+
tcx,
235+
trait_item,
236+
tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity(),
237+
);
233238
let code = format!("{}{}\n{}", padding, snippet, padding);
234239
let msg = format!("implement the missing item: `{snippet}`");
235240
let appl = Applicability::HasPlaceholders;
@@ -301,11 +306,11 @@ fn default_body_is_unstable(
301306
/// Re-sugar `ty::GenericPredicates` in a way suitable to be used in structured suggestions.
302307
fn bounds_from_generic_predicates<'tcx>(
303308
tcx: TyCtxt<'tcx>,
304-
predicates: ty::GenericPredicates<'tcx>,
309+
predicates: impl IntoIterator<Item = (ty::Predicate<'tcx>, Span)>,
305310
) -> (String, String) {
306311
let mut types: FxHashMap<Ty<'tcx>, Vec<DefId>> = FxHashMap::default();
307312
let mut projections = vec![];
308-
for (predicate, _) in predicates.predicates {
313+
for (predicate, _) in predicates {
309314
debug!("predicate {:?}", predicate);
310315
let bound_predicate = predicate.kind();
311316
match bound_predicate.skip_binder() {
@@ -367,7 +372,7 @@ fn fn_sig_suggestion<'tcx>(
367372
tcx: TyCtxt<'tcx>,
368373
sig: ty::FnSig<'tcx>,
369374
ident: Ident,
370-
predicates: ty::GenericPredicates<'tcx>,
375+
predicates: impl IntoIterator<Item = (ty::Predicate<'tcx>, Span)>,
371376
assoc: ty::AssocItem,
372377
) -> String {
373378
let args = sig
@@ -436,7 +441,17 @@ pub fn ty_kind_suggestion(ty: Ty<'_>) -> Option<&'static str> {
436441
/// Return placeholder code for the given associated item.
437442
/// Similar to `ty::AssocItem::suggestion`, but appropriate for use as the code snippet of a
438443
/// structured suggestion.
439-
fn suggestion_signature(assoc: ty::AssocItem, tcx: TyCtxt<'_>) -> String {
444+
fn suggestion_signature<'tcx>(
445+
tcx: TyCtxt<'tcx>,
446+
assoc: ty::AssocItem,
447+
impl_trait_ref: ty::TraitRef<'tcx>,
448+
) -> String {
449+
let substs = ty::InternalSubsts::identity_for_item(tcx, assoc.def_id).rebase_onto(
450+
tcx,
451+
assoc.container_id(tcx),
452+
impl_trait_ref.with_self_ty(tcx, tcx.types.self_param).substs,
453+
);
454+
440455
match assoc.kind {
441456
ty::AssocKind::Fn => {
442457
// We skip the binder here because the binder would deanonymize all
@@ -445,16 +460,22 @@ fn suggestion_signature(assoc: ty::AssocItem, tcx: TyCtxt<'_>) -> String {
445460
// regions just fine, showing `fn(&MyType)`.
446461
fn_sig_suggestion(
447462
tcx,
448-
tcx.fn_sig(assoc.def_id).subst_identity().skip_binder(),
463+
tcx.fn_sig(assoc.def_id).subst(tcx, substs).skip_binder(),
449464
assoc.ident(tcx),
450-
tcx.predicates_of(assoc.def_id),
465+
tcx.predicates_of(assoc.def_id).instantiate_own(tcx, substs),
451466
assoc,
452467
)
453468
}
454-
ty::AssocKind::Type => format!("type {} = Type;", assoc.name),
469+
ty::AssocKind::Type => {
470+
let (generics, where_clauses) = bounds_from_generic_predicates(
471+
tcx,
472+
tcx.predicates_of(assoc.def_id).instantiate_own(tcx, substs),
473+
);
474+
format!("type {}{generics} = /* Type */{where_clauses};", assoc.name)
475+
}
455476
ty::AssocKind::Const => {
456477
let ty = tcx.type_of(assoc.def_id).subst_identity();
457-
let val = ty_kind_suggestion(ty).unwrap_or("value");
478+
let val = ty_kind_suggestion(ty).unwrap_or("todo!()");
458479
format!("const {}: {} = {};", assoc.name, ty, val)
459480
}
460481
}

compiler/rustc_hir_typeck/messages.ftl

-15
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,6 @@ hir_typeck_field_multiply_specified_in_initializer =
33
.label = used more than once
44
.previous_use_label = first use of `{$ident}`
55
6-
hir_typeck_copy_impl_on_type_with_dtor =
7-
the trait `Copy` cannot be implemented for this type; the type has a destructor
8-
.label = `Copy` not allowed on types with destructors
9-
10-
hir_typeck_multiple_relaxed_default_bounds =
11-
type parameter has more than one relaxed default bound, only one is supported
12-
13-
hir_typeck_copy_impl_on_non_adt =
14-
the trait `Copy` cannot be implemented for this type
15-
.label = type is not a structure or enumeration
16-
17-
hir_typeck_trait_object_declared_with_no_traits =
18-
at least one trait is required for an object type
19-
.alias_span = this alias does not contain a trait
20-
216
hir_typeck_functional_record_update_on_non_struct =
227
functional record update syntax requires a struct
238

compiler/rustc_trait_selection/src/solve/eval_ctxt.rs

+15
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ pub struct EvalCtxt<'a, 'tcx> {
5757
pub(super) search_graph: &'a mut SearchGraph<'tcx>,
5858

5959
pub(super) nested_goals: NestedGoals<'tcx>,
60+
61+
// Has this `EvalCtxt` errored out with `NoSolution` in `try_evaluate_added_goals`?
62+
//
63+
// If so, then it can no longer be used to make a canonical query response,
64+
// since subsequent calls to `try_evaluate_added_goals` have possibly dropped
65+
// ambiguous goals. Instead, a probe needs to be introduced somewhere in the
66+
// evaluation code.
67+
tainted: Result<(), NoSolution>,
6068
}
6169

6270
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@@ -121,6 +129,7 @@ impl<'tcx> InferCtxtEvalExt<'tcx> for InferCtxt<'tcx> {
121129
max_input_universe: ty::UniverseIndex::ROOT,
122130
var_values: CanonicalVarValues::dummy(),
123131
nested_goals: NestedGoals::new(),
132+
tainted: Ok(()),
124133
};
125134
let result = ecx.evaluate_goal(IsNormalizesToHack::No, goal);
126135

@@ -172,6 +181,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
172181
max_input_universe: canonical_goal.max_universe,
173182
search_graph,
174183
nested_goals: NestedGoals::new(),
184+
tainted: Ok(()),
175185
};
176186
ecx.compute_goal(goal)
177187
})
@@ -391,6 +401,10 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
391401
},
392402
);
393403

404+
if response.is_err() {
405+
self.tainted = Err(NoSolution);
406+
}
407+
394408
self.nested_goals = goals;
395409
response
396410
}
@@ -404,6 +418,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
404418
max_input_universe: self.max_input_universe,
405419
search_graph: self.search_graph,
406420
nested_goals: self.nested_goals.clone(),
421+
tainted: self.tainted,
407422
};
408423
self.infcx.probe(|_| f(&mut ecx))
409424
}

compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
5151
certainty: Certainty,
5252
) -> QueryResult<'tcx> {
5353
let goals_certainty = self.try_evaluate_added_goals()?;
54+
assert_eq!(
55+
self.tainted,
56+
Ok(()),
57+
"EvalCtxt is tainted -- nested goals may have been dropped in a \
58+
previous call to `try_evaluate_added_goals!`"
59+
);
60+
5461
let certainty = certainty.unify_with(goals_certainty);
5562

5663
let external_constraints = self.compute_external_query_constraints()?;

src/bootstrap/compile.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,6 @@ impl Step for Sysroot {
13281328
true
13291329
}
13301330
});
1331-
return INTERNER.intern_path(sysroot);
13321331
}
13331332

13341333
// Symlink the source root into the same location inside the sysroot,

src/bootstrap/tool.rs

+27-6
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ macro_rules! tool_extended {
748748
stable = $stable:expr
749749
$(,tool_std = $tool_std:literal)?
750750
$(,allow_features = $allow_features:expr)?
751+
$(,add_bins_to_sysroot = $add_bins_to_sysroot:expr)?
751752
;)+) => {
752753
$(
753754
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -790,7 +791,7 @@ macro_rules! tool_extended {
790791

791792
#[allow(unused_mut)]
792793
fn run(mut $sel, $builder: &Builder<'_>) -> Option<PathBuf> {
793-
$builder.ensure(ToolBuild {
794+
let tool = $builder.ensure(ToolBuild {
794795
compiler: $sel.compiler,
795796
target: $sel.target,
796797
tool: $tool_name,
@@ -800,7 +801,27 @@ macro_rules! tool_extended {
800801
is_optional_tool: true,
801802
source_type: SourceType::InTree,
802803
allow_features: concat!($($allow_features)*),
803-
})
804+
})?;
805+
806+
if (false $(|| !$add_bins_to_sysroot.is_empty())?) && $sel.compiler.stage > 0 {
807+
let bindir = $builder.sysroot($sel.compiler).join("bin");
808+
t!(fs::create_dir_all(&bindir));
809+
810+
#[allow(unused_variables)]
811+
let tools_out = $builder
812+
.cargo_out($sel.compiler, Mode::ToolRustc, $sel.target);
813+
814+
$(for add_bin in $add_bins_to_sysroot {
815+
let bin_source = tools_out.join(exe(add_bin, $sel.target));
816+
let bin_destination = bindir.join(exe(add_bin, $sel.compiler.host));
817+
$builder.copy(&bin_source, &bin_destination);
818+
})?
819+
820+
let tool = bindir.join(exe($tool_name, $sel.compiler.host));
821+
Some(tool)
822+
} else {
823+
Some(tool)
824+
}
804825
}
805826
}
806827
)+
@@ -814,15 +835,15 @@ macro_rules! tool_extended {
814835
tool_extended!((self, builder),
815836
Cargofmt, "src/tools/rustfmt", "cargo-fmt", stable=true;
816837
CargoClippy, "src/tools/clippy", "cargo-clippy", stable=true;
817-
Clippy, "src/tools/clippy", "clippy-driver", stable=true;
818-
Miri, "src/tools/miri", "miri", stable=false;
819-
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", stable=true;
838+
Clippy, "src/tools/clippy", "clippy-driver", stable=true, add_bins_to_sysroot = ["clippy-driver", "cargo-clippy"];
839+
Miri, "src/tools/miri", "miri", stable=false, add_bins_to_sysroot = ["miri"];
840+
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", stable=true, add_bins_to_sysroot = ["cargo-miri"];
820841
// FIXME: tool_std is not quite right, we shouldn't allow nightly features.
821842
// But `builder.cargo` doesn't know how to handle ToolBootstrap in stages other than 0,
822843
// and this is close enough for now.
823844
Rls, "src/tools/rls", "rls", stable=true, tool_std=true;
824845
RustDemangler, "src/tools/rust-demangler", "rust-demangler", stable=false, tool_std=true;
825-
Rustfmt, "src/tools/rustfmt", "rustfmt", stable=true;
846+
Rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, add_bins_to_sysroot = ["rustfmt", "cargo-fmt"];
826847
);
827848

828849
impl<'a> Builder<'a> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This is a regression test for <https://github.com/rust-lang/rust/issues/46506>.
2+
// This test ensures that if public re-exported is re-exported, it won't be inlined.
3+
4+
#![crate_name = "foo"]
5+
6+
// @has 'foo/associations/index.html'
7+
// @count - '//*[@id="main-content"]/*[@class="small-section-header"]' 1
8+
// @has - '//*[@id="main-content"]/*[@class="small-section-header"]' 'Traits'
9+
// @has - '//*[@id="main-content"]//a[@href="trait.GroupedBy.html"]' 'GroupedBy'
10+
// @has 'foo/associations/trait.GroupedBy.html'
11+
pub mod associations {
12+
mod belongs_to {
13+
pub trait GroupedBy {}
14+
}
15+
pub use self::belongs_to::GroupedBy;
16+
}
17+
18+
// @has 'foo/prelude/index.html'
19+
// @count - '//*[@id="main-content"]/*[@class="small-section-header"]' 1
20+
// @has - '//*[@id="main-content"]/*[@class="small-section-header"]' 'Re-exports'
21+
// @has - '//*[@id="main-content"]//*[@id="reexport.GroupedBy"]' 'pub use associations::GroupedBy;'
22+
pub mod prelude {
23+
pub use associations::GroupedBy;
24+
}

tests/ui/async-await/issue-74047.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0046]: not all trait items implemented, missing: `Error`, `try_from`
44
LL | impl TryFrom<OtherStream> for MyStream {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Error`, `try_from` in implementation
66
|
7-
= help: implement the missing item: `type Error = Type;`
8-
= help: implement the missing item: `fn try_from(_: T) -> Result<Self, <Self as TryFrom<T>>::Error> { todo!() }`
7+
= help: implement the missing item: `type Error = /* Type */;`
8+
= help: implement the missing item: `fn try_from(_: OtherStream) -> Result<Self, <Self as TryFrom<OtherStream>>::Error> { todo!() }`
99

1010
error: aborting due to previous error
1111

tests/ui/extenv/issue-110547.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compile-flags: -C debug-assertions
2+
3+
fn main() {
4+
env!{"\t"}; //~ ERROR not defined at compile time
5+
env!("\t"); //~ ERROR not defined at compile time
6+
env!("\u{2069}"); //~ ERROR not defined at compile time
7+
}

tests/ui/extenv/issue-110547.stderr

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error: environment variable ` ` not defined at compile time
2+
--> $DIR/issue-110547.rs:4:5
3+
|
4+
LL | env!{"\t"};
5+
| ^^^^^^^^^^
6+
|
7+
= help: use `std::env::var(" ")` to read the variable at run time
8+
= note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)
9+
10+
error: environment variable ` ` not defined at compile time
11+
--> $DIR/issue-110547.rs:5:5
12+
|
13+
LL | env!("\t");
14+
| ^^^^^^^^^^
15+
|
16+
= help: use `std::env::var(" ")` to read the variable at run time
17+
= note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)
18+
19+
error: environment variable `` not defined at compile time
20+
--> $DIR/issue-110547.rs:6:5
21+
|
22+
LL | env!("\u{2069}");
23+
| ^^^^^^^^^^^^^^^^
24+
|
25+
= help: use `std::env::var("")` to read the variable at run time
26+
= note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)
27+
28+
error: aborting due to 3 previous errors
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub trait Foo {
2+
type Gat<T>
3+
where
4+
T: std::fmt::Display;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// aux-build:missing-item-sugg.rs
2+
3+
extern crate missing_item_sugg;
4+
5+
struct Local;
6+
impl missing_item_sugg::Foo for Local {
7+
//~^ ERROR not all trait items implemented, missing: `Gat`
8+
}
9+
//~^ HELP implement the missing item: `type Gat<T> = /* Type */ where T: std::fmt::Display;`
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0046]: not all trait items implemented, missing: `Gat`
2+
--> $DIR/missing-item-sugg.rs:6:1
3+
|
4+
LL | impl missing_item_sugg::Foo for Local {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Gat` in implementation
6+
|
7+
= help: implement the missing item: `type Gat<T> = /* Type */ where T: std::fmt::Display;`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0046`.

tests/ui/issues/issue-3344.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0046]: not all trait items implemented, missing: `partial_cmp`
44
LL | impl PartialOrd for Thing {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^ missing `partial_cmp` in implementation
66
|
7-
= help: implement the missing item: `fn partial_cmp(&self, _: &Rhs) -> Option<std::cmp::Ordering> { todo!() }`
7+
= help: implement the missing item: `fn partial_cmp(&self, _: &Thing) -> Option<std::cmp::Ordering> { todo!() }`
88

99
error: aborting due to previous error
1010

tests/ui/missing/missing-items/m2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | impl m1::X for X {
55
| ^^^^^^^^^^^^^^^^ missing `CONSTANT`, `Type`, `method`, `method2`, `method3`, `method4`, `method5` in implementation
66
|
77
= help: implement the missing item: `const CONSTANT: u32 = 42;`
8-
= help: implement the missing item: `type Type = Type;`
8+
= help: implement the missing item: `type Type = /* Type */;`
99
= help: implement the missing item: `fn method(&self, _: String) -> <Self as m1::X>::Type { todo!() }`
1010
= help: implement the missing item: `fn method2(self: Box<Self>, _: String) -> <Self as m1::X>::Type { todo!() }`
1111
= help: implement the missing item: `fn method3(_: &Self, _: String) -> <Self as m1::X>::Type { todo!() }`

0 commit comments

Comments
 (0)