Skip to content

Commit 2748a9f

Browse files
committed
Auto merge of #65209 - Centril:rollup-tzc0j87, r=Centril
Rollup of 8 pull requests Successful merges: - #64404 (Add long error explanation for E0495) - #64918 (Add long error explanation for E0551) - #65102 (Disable stack probe when thread sanitizer is enabled) - #65120 (Correctly estimate the required space for string in `StyledBuffer::prepend`) - #65145 (When suggesting assoc function with type params, include turbofish) - #65162 (Remove loaded_from_cache map from DepGraph) - #65176 (Remove query-related macros) - #65179 (Add long error explanation for E0567) Failed merges: r? @ghost
2 parents 3fa9554 + 3246ab2 commit 2748a9f

File tree

60 files changed

+266
-91
lines changed

Some content is hidden

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

60 files changed

+266
-91
lines changed

src/librustc/dep_graph/graph.rs

-23
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ struct DepGraphData {
7575
previous_work_products: FxHashMap<WorkProductId, WorkProduct>,
7676

7777
dep_node_debug: Lock<FxHashMap<DepNode, String>>,
78-
79-
// Used for testing, only populated when -Zquery-dep-graph is specified.
80-
loaded_from_cache: Lock<FxHashMap<DepNodeIndex, bool>>,
8178
}
8279

8380
pub fn hash_result<R>(hcx: &mut StableHashingContext<'_>, result: &R) -> Option<Fingerprint>
@@ -104,7 +101,6 @@ impl DepGraph {
104101
emitting_diagnostics_cond_var: Condvar::new(),
105102
previous: prev_graph,
106103
colors: DepNodeColorMap::new(prev_graph_node_count),
107-
loaded_from_cache: Default::default(),
108104
})),
109105
}
110106
}
@@ -874,25 +870,6 @@ impl DepGraph {
874870
}
875871
}
876872
}
877-
878-
pub fn mark_loaded_from_cache(&self, dep_node_index: DepNodeIndex, state: bool) {
879-
debug!("mark_loaded_from_cache({:?}, {})",
880-
self.data.as_ref().unwrap().current.borrow().data[dep_node_index].node,
881-
state);
882-
883-
self.data
884-
.as_ref()
885-
.unwrap()
886-
.loaded_from_cache
887-
.borrow_mut()
888-
.insert(dep_node_index, state);
889-
}
890-
891-
pub fn was_loaded_from_cache(&self, dep_node: &DepNode) -> Option<bool> {
892-
let data = self.data.as_ref().unwrap();
893-
let dep_node_index = data.current.borrow().node_to_node_index[dep_node];
894-
data.loaded_from_cache.borrow().get(&dep_node_index).cloned()
895-
}
896873
}
897874

898875
/// A "work product" is an intermediate result that we save into the

src/librustc/error_codes.rs

+41-2
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,47 @@ where
15201520
```
15211521
"##,
15221522

1523+
E0495: r##"
1524+
A lifetime cannot be determined in the given situation.
1525+
1526+
Erroneous code example:
1527+
1528+
```compile_fail,E0495
1529+
fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
1530+
match (&t,) { // error!
1531+
((u,),) => u,
1532+
}
1533+
}
1534+
1535+
let y = Box::new((42,));
1536+
let x = transmute_lifetime(&y);
1537+
```
1538+
1539+
In this code, you have two ways to solve this issue:
1540+
1. Enforce that `'a` lives at least as long as `'b`.
1541+
2. Use the same lifetime requirement for both input and output values.
1542+
1543+
So for the first solution, you can do it by replacing `'a` with `'a: 'b`:
1544+
1545+
```
1546+
fn transmute_lifetime<'a: 'b, 'b, T>(t: &'a (T,)) -> &'b T {
1547+
match (&t,) { // ok!
1548+
((u,),) => u,
1549+
}
1550+
}
1551+
```
1552+
1553+
In the second you can do it by simply removing `'b` so they both use `'a`:
1554+
1555+
```
1556+
fn transmute_lifetime<'a, T>(t: &'a (T,)) -> &'a T {
1557+
match (&t,) { // ok!
1558+
((u,),) => u,
1559+
}
1560+
}
1561+
```
1562+
"##,
1563+
15231564
E0496: r##"
15241565
A lifetime name is shadowing another lifetime name. Erroneous code example:
15251566
@@ -2116,8 +2157,6 @@ rejected in your own crates.
21162157
E0488, // lifetime of variable does not enclose its declaration
21172158
E0489, // type/lifetime parameter not in scope here
21182159
E0490, // a value of type `..` is borrowed for too long
2119-
E0495, // cannot infer an appropriate lifetime due to conflicting
2120-
// requirements
21212160
E0623, // lifetime mismatch where both parameters are anonymous regions
21222161
E0628, // generators cannot have explicit parameters
21232162
E0631, // type mismatch in closure arguments

src/librustc/ty/query/plumbing.rs

+13-40
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,6 @@ impl<'tcx> TyCtxt<'tcx> {
489489
self.incremental_verify_ich::<Q>(&result, dep_node, dep_node_index);
490490
}
491491

492-
if unlikely!(self.sess.opts.debugging_opts.query_dep_graph) {
493-
self.dep_graph.mark_loaded_from_cache(dep_node_index, true);
494-
}
495-
496492
result
497493
}
498494

@@ -570,10 +566,6 @@ impl<'tcx> TyCtxt<'tcx> {
570566
drop(prof_timer);
571567
profq_msg!(self, ProfileQueriesMsg::ProviderEnd);
572568

573-
if unlikely!(self.sess.opts.debugging_opts.query_dep_graph) {
574-
self.dep_graph.mark_loaded_from_cache(dep_node_index, false);
575-
}
576-
577569
if unlikely!(!diagnostics.is_empty()) {
578570
if dep_node.kind != crate::dep_graph::DepKind::Null {
579571
self.queries.on_disk_cache
@@ -1191,37 +1183,6 @@ pub fn force_from_dep_node(tcx: TyCtxt<'_>, dep_node: &DepNode) -> bool {
11911183
return false
11921184
}
11931185

1194-
macro_rules! def_id {
1195-
() => {
1196-
if let Some(def_id) = dep_node.extract_def_id(tcx) {
1197-
def_id
1198-
} else {
1199-
// Return from the whole function.
1200-
return false
1201-
}
1202-
}
1203-
};
1204-
1205-
macro_rules! krate {
1206-
() => { (def_id!()).krate }
1207-
};
1208-
1209-
macro_rules! force_ex {
1210-
($tcx:expr, $query:ident, $key:expr) => {
1211-
{
1212-
$tcx.force_query::<crate::ty::query::queries::$query<'_>>(
1213-
$key,
1214-
DUMMY_SP,
1215-
*dep_node
1216-
);
1217-
}
1218-
}
1219-
};
1220-
1221-
macro_rules! force {
1222-
($query:ident, $key:expr) => { force_ex!(tcx, $query, $key) }
1223-
};
1224-
12251186
rustc_dep_node_force!([dep_node, tcx]
12261187
// These are inputs that are expected to be pre-allocated and that
12271188
// should therefore always be red or green already.
@@ -1240,7 +1201,19 @@ pub fn force_from_dep_node(tcx: TyCtxt<'_>, dep_node: &DepNode) -> bool {
12401201
bug!("force_from_dep_node: encountered {:?}", dep_node)
12411202
}
12421203

1243-
DepKind::Analysis => { force!(analysis, krate!()); }
1204+
DepKind::Analysis => {
1205+
let def_id = if let Some(def_id) = dep_node.extract_def_id(tcx) {
1206+
def_id
1207+
} else {
1208+
// Return from the whole function.
1209+
return false
1210+
};
1211+
tcx.force_query::<crate::ty::query::queries::analysis<'_>>(
1212+
def_id.krate,
1213+
DUMMY_SP,
1214+
*dep_node
1215+
);
1216+
}
12441217
);
12451218

12461219
true

src/librustc_codegen_llvm/attributes.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ pub fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
9696
}
9797

9898
// Currently stack probes seem somewhat incompatible with the address
99-
// sanitizer. With asan we're already protected from stack overflow anyway
100-
// so we don't really need stack probes regardless.
101-
if let Some(Sanitizer::Address) = cx.sess().opts.debugging_opts.sanitizer {
102-
return
99+
// sanitizer and thread sanitizer. With asan we're already protected from
100+
// stack overflow anyway so we don't really need stack probes regardless.
101+
match cx.sess().opts.debugging_opts.sanitizer {
102+
Some(Sanitizer::Address) |
103+
Some(Sanitizer::Thread) => return,
104+
_ => {},
103105
}
104106

105107
// probestack doesn't play nice either with `-C profile-generate`.

src/librustc_errors/styled_buffer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl StyledBuffer {
111111

112112
pub fn prepend(&mut self, line: usize, string: &str, style: Style) {
113113
self.ensure_lines(line);
114-
let string_len = string.len();
114+
let string_len = string.chars().count();
115115

116116
// Push the old content over to make room for new content
117117
for _ in 0..string_len {

src/librustc_macros/src/query.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,11 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
495495
dep_node_force_stream.extend(quote! {
496496
DepKind::#name => {
497497
if let Some(key) = RecoverKey::recover($tcx, $dep_node) {
498-
force_ex!($tcx, #name, key);
498+
$tcx.force_query::<crate::ty::query::queries::#name<'_>>(
499+
key,
500+
DUMMY_SP,
501+
*$dep_node
502+
);
499503
} else {
500504
return false;
501505
}

src/librustc_passes/error_codes.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,34 @@ type A3 = fn(i16); // ok!
314314
```
315315
"##,
316316

317+
E0567: r##"
318+
Generics have been used on an auto trait.
319+
320+
Erroneous code example:
321+
322+
```compile_fail,E0567
323+
#![feature(optin_builtin_traits)]
324+
325+
auto trait Generic<T> {} // error!
326+
327+
fn main() {}
328+
```
329+
330+
Since an auto trait is implemented on all existing types, the
331+
compiler would not be able to infer the types of the trait's generic
332+
parameters.
333+
334+
To fix this issue, just remove the generics:
335+
336+
```
337+
#![feature(optin_builtin_traits)]
338+
339+
auto trait Generic {} // ok!
340+
341+
fn main() {}
342+
```
343+
"##,
344+
317345
E0571: r##"
318346
A `break` statement with an argument appeared in a non-`loop` loop.
319347
@@ -531,7 +559,6 @@ Switch to the Rust 2018 edition to use `async fn`.
531559
;
532560
E0226, // only a single explicit lifetime bound is permitted
533561
E0472, // asm! is unsupported on this target
534-
E0567, // auto traits can not have generic parameters
535562
E0568, // auto traits can not have super traits
536563
E0666, // nested `impl Trait` is illegal
537564
E0667, // `impl Trait` in projections

src/librustc_typeck/check/method/suggest.rs

+36-8
Original file line numberDiff line numberDiff line change
@@ -461,16 +461,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
461461
err.span_label(span, "this is an associated function, not a method");
462462
}
463463
if static_sources.len() == 1 {
464+
let ty_str = if let Some(CandidateSource::ImplSource(
465+
impl_did,
466+
)) = static_sources.get(0) {
467+
// When the "method" is resolved through dereferencing, we really want the
468+
// original type that has the associated function for accurate suggestions.
469+
// (#61411)
470+
let ty = self.impl_self_ty(span, *impl_did).ty;
471+
match (&ty.peel_refs().kind, &actual.peel_refs().kind) {
472+
(ty::Adt(def, _), ty::Adt(def_actual, _)) if def == def_actual => {
473+
// Use `actual` as it will have more `substs` filled in.
474+
self.ty_to_value_string(actual.peel_refs())
475+
}
476+
_ => self.ty_to_value_string(ty.peel_refs()),
477+
}
478+
} else {
479+
self.ty_to_value_string(actual.peel_refs())
480+
};
464481
if let SelfSource::MethodCall(expr) = source {
465-
err.span_suggestion(expr.span.to(span),
466-
"use associated function syntax instead",
467-
format!("{}::{}",
468-
self.ty_to_string(actual),
469-
item_name),
470-
Applicability::MachineApplicable);
482+
err.span_suggestion(
483+
expr.span.to(span),
484+
"use associated function syntax instead",
485+
format!("{}::{}", ty_str, item_name),
486+
Applicability::MachineApplicable,
487+
);
471488
} else {
472-
err.help(&format!("try with `{}::{}`",
473-
self.ty_to_string(actual), item_name));
489+
err.help(&format!(
490+
"try with `{}::{}`",
491+
ty_str,
492+
item_name,
493+
));
474494
}
475495

476496
report_candidates(span, &mut err, static_sources);
@@ -586,6 +606,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
586606
None
587607
}
588608

609+
/// Print out the type for use in value namespace.
610+
fn ty_to_value_string(&self, ty: Ty<'tcx>) -> String {
611+
match ty.kind {
612+
ty::Adt(def, substs) => format!("{}", ty::Instance::new(def.did, substs)),
613+
_ => self.ty_to_string(ty),
614+
}
615+
}
616+
589617
fn suggest_use_candidates(&self,
590618
err: &mut DiagnosticBuilder<'_>,
591619
mut msg: String,

src/libsyntax/error_codes.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,25 @@ fn the_banished() {} // ok!
163163
```
164164
"##,
165165

166+
E0551: r##"
167+
An invalid meta-item was used inside an attribute.
168+
169+
Erroneous code example:
170+
171+
```compile_fail,E0551
172+
#[deprecated(note)] // error!
173+
fn i_am_deprecated() {}
174+
```
175+
176+
Meta items are the key-value pairs inside of an attribute. To fix this issue,
177+
you need to give a value to the `note` key. Example:
178+
179+
```
180+
#[deprecated(note = "because")] // ok!
181+
fn i_am_deprecated() {}
182+
```
183+
"##,
184+
166185
E0552: r##"
167186
A unrecognized representation attribute was used.
168187
@@ -473,7 +492,6 @@ features in the `-Z allow_features` flag.
473492
// rustc_deprecated attribute must be paired with either stable or unstable
474493
// attribute
475494
E0549,
476-
E0551, // incorrect meta item
477495
E0553, // multiple rustc_const_unstable attributes
478496
// E0555, // replaced with a generic attribute input check
479497
E0584, // file for module `..` found at both .. and ..

src/test/ui/associated-types/cache/project-fn-ret-contravariant.transmute.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ LL | bar(foo, x)
2323

2424
error: aborting due to previous error
2525

26+
For more information about this error, try `rustc --explain E0495`.

src/test/ui/associated-types/cache/project-fn-ret-invariant.transmute.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ LL | fn baz<'a,'b>(x: Type<'a>) -> Type<'static> {
1919

2020
error: aborting due to previous error
2121

22+
For more information about this error, try `rustc --explain E0495`.

src/test/ui/auto-trait-validation.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ LL | auto trait MyTrait { fn foo() {} }
1818

1919
error: aborting due to 3 previous errors
2020

21-
For more information about this error, try `rustc --explain E0380`.
21+
Some errors have detailed explanations: E0380, E0567.
22+
For more information about an error, try `rustc --explain E0380`.

src/test/ui/c-variadic/variadic-ffi-4.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,5 @@ LL | | }
209209

210210
error: aborting due to 8 previous errors
211211

212-
For more information about this error, try `rustc --explain E0308`.
212+
Some errors have detailed explanations: E0308, E0495.
213+
For more information about an error, try `rustc --explain E0308`.

src/test/ui/deprecation/deprecation-sanity.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ LL | #[deprecated(since = "a", since = "b", note = "c")]
5454

5555
error: aborting due to 9 previous errors
5656

57-
Some errors have detailed explanations: E0538, E0541, E0550, E0565.
57+
Some errors have detailed explanations: E0538, E0541, E0550, E0551, E0565.
5858
For more information about an error, try `rustc --explain E0538`.

src/test/ui/error-codes/E0621-does-not-trigger-for-closures.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ LL | invoke(&x, |a, b| if a > b { a } else { b });
2727

2828
error: aborting due to previous error
2929

30+
For more information about this error, try `rustc --explain E0495`.

src/test/ui/impl-header-lifetime-elision/dyn-trait.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
1919

2020
error: aborting due to previous error
2121

22+
For more information about this error, try `rustc --explain E0495`.

0 commit comments

Comments
 (0)