Skip to content

Commit 0d8b334

Browse files
committed
Auto merge of #123945 - GuillaumeGomez:rollup-14x3enh, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - #120900 (std: use `stream_position` where applicable) - #123373 (skip Codegen{GCC,Cranelift} when using CI rustc) - #123618 (Discard overflow obligations in `impl_may_apply`) - #123905 (rustdoc: check redundant explicit links with correct itemid) - #123915 (improve documentation slightly regarding some pointer methods) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 29b1207 + 32be7b7 commit 0d8b334

File tree

11 files changed

+124
-52
lines changed

11 files changed

+124
-52
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_infer::traits::{Obligation, ObligationCause, PolyTraitObligation};
55
use rustc_middle::ty;
66
use rustc_span::{Span, DUMMY_SP};
77

8+
use crate::traits::query::evaluate_obligation::InferCtxtExt;
89
use crate::traits::ObligationCtxt;
910

1011
#[derive(Debug)]
@@ -52,10 +53,21 @@ pub fn compute_applicable_impls_for_diagnostics<'tcx>(
5253
_ => return false,
5354
}
5455

55-
let impl_predicates = tcx.predicates_of(impl_def_id).instantiate(tcx, impl_args);
56-
ocx.register_obligations(impl_predicates.predicates.iter().map(|&predicate| {
57-
Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate)
58-
}));
56+
let obligations = tcx
57+
.predicates_of(impl_def_id)
58+
.instantiate(tcx, impl_args)
59+
.into_iter()
60+
.map(|(predicate, _)| {
61+
Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate)
62+
})
63+
// Kinda hacky, but let's just throw away obligations that overflow.
64+
// This may reduce the accuracy of this check (if the obligation guides
65+
// inference or it actually resulted in error after others are processed)
66+
// ... but this is diagnostics code.
67+
.filter(|obligation| {
68+
infcx.next_trait_solver() || infcx.evaluate_obligation(obligation).is_ok()
69+
});
70+
ocx.register_obligations(obligations);
5971

6072
ocx.select_where_possible().is_empty()
6173
})

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2399,12 +2399,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
23992399
if ambiguities.len() > 5 {
24002400
let infcx = self.infcx;
24012401
if !ambiguities.iter().all(|option| match option {
2402-
DefId(did) => infcx.fresh_args_for_item(DUMMY_SP, *did).is_empty(),
2402+
DefId(did) => infcx.tcx.generics_of(*did).count() == 0,
24032403
ParamEnv(_) => true,
24042404
}) {
24052405
// If not all are blanket impls, we filter blanked impls out.
24062406
ambiguities.retain(|option| match option {
2407-
DefId(did) => infcx.fresh_args_for_item(DUMMY_SP, *did).is_empty(),
2407+
DefId(did) => infcx.tcx.generics_of(*did).count() == 0,
24082408
ParamEnv(_) => true,
24092409
});
24102410
}

library/core/src/ptr/mut_ptr.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,8 @@ impl<T: ?Sized> *mut T {
464464
/// let ptr: *mut u32 = s.as_mut_ptr();
465465
///
466466
/// unsafe {
467-
/// println!("{}", *ptr.offset(1));
468-
/// println!("{}", *ptr.offset(2));
467+
/// assert_eq!(2, *ptr.offset(1));
468+
/// assert_eq!(3, *ptr.offset(2));
469469
/// }
470470
/// ```
471471
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1027,8 +1027,8 @@ impl<T: ?Sized> *mut T {
10271027
/// let ptr: *const u8 = s.as_ptr();
10281028
///
10291029
/// unsafe {
1030-
/// println!("{}", *ptr.add(1) as char);
1031-
/// println!("{}", *ptr.add(2) as char);
1030+
/// assert_eq!('2', *ptr.add(1) as char);
1031+
/// assert_eq!('3', *ptr.add(2) as char);
10321032
/// }
10331033
/// ```
10341034
#[stable(feature = "pointer_methods", since = "1.26.0")]
@@ -1111,8 +1111,8 @@ impl<T: ?Sized> *mut T {
11111111
///
11121112
/// unsafe {
11131113
/// let end: *const u8 = s.as_ptr().add(3);
1114-
/// println!("{}", *end.sub(1) as char);
1115-
/// println!("{}", *end.sub(2) as char);
1114+
/// assert_eq!('3', *end.sub(1) as char);
1115+
/// assert_eq!('2', *end.sub(2) as char);
11161116
/// }
11171117
/// ```
11181118
#[stable(feature = "pointer_methods", since = "1.26.0")]

library/std/src/fs.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ impl OpenOptions {
993993
/// If a file is opened with both read and append access, beware that after
994994
/// opening, and after every write, the position for reading may be set at the
995995
/// end of the file. So, before writing, save the current position (using
996-
/// <code>[seek]\([SeekFrom]::[Current]\(0))</code>), and restore it before the next read.
996+
/// <code>[Seek]::[stream_position]</code>), and restore it before the next read.
997997
///
998998
/// ## Note
999999
///
@@ -1002,8 +1002,7 @@ impl OpenOptions {
10021002
///
10031003
/// [`write()`]: Write::write "io::Write::write"
10041004
/// [`flush()`]: Write::flush "io::Write::flush"
1005-
/// [seek]: Seek::seek "io::Seek::seek"
1006-
/// [Current]: SeekFrom::Current "io::SeekFrom::Current"
1005+
/// [stream_position]: Seek::stream_position "io::Seek::stream_position"
10071006
///
10081007
/// # Examples
10091008
///

library/std/src/fs/tests.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ fn file_test_io_seek_and_tell_smoke_test() {
187187
{
188188
let mut read_stream = check!(File::open(filename));
189189
check!(read_stream.seek(SeekFrom::Start(set_cursor)));
190-
tell_pos_pre_read = check!(read_stream.seek(SeekFrom::Current(0)));
190+
tell_pos_pre_read = check!(read_stream.stream_position());
191191
check!(read_stream.read(&mut read_mem));
192-
tell_pos_post_read = check!(read_stream.seek(SeekFrom::Current(0)));
192+
tell_pos_post_read = check!(read_stream.stream_position());
193193
}
194194
check!(fs::remove_file(filename));
195195
let read_str = str::from_utf8(&read_mem).unwrap();
@@ -284,42 +284,42 @@ fn file_test_io_read_write_at() {
284284
let oo = OpenOptions::new().create_new(true).write(true).read(true).clone();
285285
let mut rw = check!(oo.open(&filename));
286286
assert_eq!(check!(rw.write_at(write1.as_bytes(), 5)), write1.len());
287-
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 0);
287+
assert_eq!(check!(rw.stream_position()), 0);
288288
assert_eq!(check!(rw.read_at(&mut buf, 5)), write1.len());
289289
assert_eq!(str::from_utf8(&buf[..write1.len()]), Ok(write1));
290-
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 0);
290+
assert_eq!(check!(rw.stream_position()), 0);
291291
assert_eq!(check!(rw.read_at(&mut buf[..write2.len()], 0)), write2.len());
292292
assert_eq!(str::from_utf8(&buf[..write2.len()]), Ok("\0\0\0\0\0"));
293-
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 0);
293+
assert_eq!(check!(rw.stream_position()), 0);
294294
assert_eq!(check!(rw.write(write2.as_bytes())), write2.len());
295-
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 5);
295+
assert_eq!(check!(rw.stream_position()), 5);
296296
assert_eq!(check!(rw.read(&mut buf)), write1.len());
297297
assert_eq!(str::from_utf8(&buf[..write1.len()]), Ok(write1));
298-
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 9);
298+
assert_eq!(check!(rw.stream_position()), 9);
299299
assert_eq!(check!(rw.read_at(&mut buf[..write2.len()], 0)), write2.len());
300300
assert_eq!(str::from_utf8(&buf[..write2.len()]), Ok(write2));
301-
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 9);
301+
assert_eq!(check!(rw.stream_position()), 9);
302302
assert_eq!(check!(rw.write_at(write3.as_bytes(), 9)), write3.len());
303-
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 9);
303+
assert_eq!(check!(rw.stream_position()), 9);
304304
}
305305
{
306306
let mut read = check!(File::open(&filename));
307307
assert_eq!(check!(read.read_at(&mut buf, 0)), content.len());
308308
assert_eq!(str::from_utf8(&buf[..content.len()]), Ok(content));
309-
assert_eq!(check!(read.seek(SeekFrom::Current(0))), 0);
309+
assert_eq!(check!(read.stream_position()), 0);
310310
assert_eq!(check!(read.seek(SeekFrom::End(-5))), 9);
311311
assert_eq!(check!(read.read_at(&mut buf, 0)), content.len());
312312
assert_eq!(str::from_utf8(&buf[..content.len()]), Ok(content));
313-
assert_eq!(check!(read.seek(SeekFrom::Current(0))), 9);
313+
assert_eq!(check!(read.stream_position()), 9);
314314
assert_eq!(check!(read.read(&mut buf)), write3.len());
315315
assert_eq!(str::from_utf8(&buf[..write3.len()]), Ok(write3));
316-
assert_eq!(check!(read.seek(SeekFrom::Current(0))), 14);
316+
assert_eq!(check!(read.stream_position()), 14);
317317
assert_eq!(check!(read.read_at(&mut buf, 0)), content.len());
318318
assert_eq!(str::from_utf8(&buf[..content.len()]), Ok(content));
319-
assert_eq!(check!(read.seek(SeekFrom::Current(0))), 14);
319+
assert_eq!(check!(read.stream_position()), 14);
320320
assert_eq!(check!(read.read_at(&mut buf, 14)), 0);
321321
assert_eq!(check!(read.read_at(&mut buf, 15)), 0);
322-
assert_eq!(check!(read.seek(SeekFrom::Current(0))), 14);
322+
assert_eq!(check!(read.stream_position()), 14);
323323
}
324324
check!(fs::remove_file(&filename));
325325
}
@@ -362,38 +362,38 @@ fn file_test_io_seek_read_write() {
362362
let oo = OpenOptions::new().create_new(true).write(true).read(true).clone();
363363
let mut rw = check!(oo.open(&filename));
364364
assert_eq!(check!(rw.seek_write(write1.as_bytes(), 5)), write1.len());
365-
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 9);
365+
assert_eq!(check!(rw.stream_position()), 9);
366366
assert_eq!(check!(rw.seek_read(&mut buf, 5)), write1.len());
367367
assert_eq!(str::from_utf8(&buf[..write1.len()]), Ok(write1));
368-
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 9);
368+
assert_eq!(check!(rw.stream_position()), 9);
369369
assert_eq!(check!(rw.seek(SeekFrom::Start(0))), 0);
370370
assert_eq!(check!(rw.write(write2.as_bytes())), write2.len());
371-
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 5);
371+
assert_eq!(check!(rw.stream_position()), 5);
372372
assert_eq!(check!(rw.read(&mut buf)), write1.len());
373373
assert_eq!(str::from_utf8(&buf[..write1.len()]), Ok(write1));
374-
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 9);
374+
assert_eq!(check!(rw.stream_position()), 9);
375375
assert_eq!(check!(rw.seek_read(&mut buf[..write2.len()], 0)), write2.len());
376376
assert_eq!(str::from_utf8(&buf[..write2.len()]), Ok(write2));
377-
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 5);
377+
assert_eq!(check!(rw.stream_position()), 5);
378378
assert_eq!(check!(rw.seek_write(write3.as_bytes(), 9)), write3.len());
379-
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 14);
379+
assert_eq!(check!(rw.stream_position()), 14);
380380
}
381381
{
382382
let mut read = check!(File::open(&filename));
383383
assert_eq!(check!(read.seek_read(&mut buf, 0)), content.len());
384384
assert_eq!(str::from_utf8(&buf[..content.len()]), Ok(content));
385-
assert_eq!(check!(read.seek(SeekFrom::Current(0))), 14);
385+
assert_eq!(check!(read.stream_position()), 14);
386386
assert_eq!(check!(read.seek(SeekFrom::End(-5))), 9);
387387
assert_eq!(check!(read.seek_read(&mut buf, 0)), content.len());
388388
assert_eq!(str::from_utf8(&buf[..content.len()]), Ok(content));
389-
assert_eq!(check!(read.seek(SeekFrom::Current(0))), 14);
389+
assert_eq!(check!(read.stream_position()), 14);
390390
assert_eq!(check!(read.seek(SeekFrom::End(-5))), 9);
391391
assert_eq!(check!(read.read(&mut buf)), write3.len());
392392
assert_eq!(str::from_utf8(&buf[..write3.len()]), Ok(write3));
393-
assert_eq!(check!(read.seek(SeekFrom::Current(0))), 14);
393+
assert_eq!(check!(read.stream_position()), 14);
394394
assert_eq!(check!(read.seek_read(&mut buf, 0)), content.len());
395395
assert_eq!(str::from_utf8(&buf[..content.len()]), Ok(content));
396-
assert_eq!(check!(read.seek(SeekFrom::Current(0))), 14);
396+
assert_eq!(check!(read.stream_position()), 14);
397397
assert_eq!(check!(read.seek_read(&mut buf, 14)), 0);
398398
assert_eq!(check!(read.seek_read(&mut buf, 15)), 0);
399399
}

library/std/src/io/buffered/tests.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn test_buffered_reader_seek() {
114114

115115
assert_eq!(reader.seek(SeekFrom::Start(3)).ok(), Some(3));
116116
assert_eq!(reader.fill_buf().ok(), Some(&[0, 1][..]));
117-
assert_eq!(reader.seek(SeekFrom::Current(0)).ok(), Some(3));
117+
assert_eq!(reader.stream_position().ok(), Some(3));
118118
assert_eq!(reader.fill_buf().ok(), Some(&[0, 1][..]));
119119
assert_eq!(reader.seek(SeekFrom::Current(1)).ok(), Some(4));
120120
assert_eq!(reader.fill_buf().ok(), Some(&[1, 2][..]));
@@ -230,6 +230,9 @@ fn test_buffered_reader_seek_underflow() {
230230
Ok(len)
231231
}
232232
}
233+
// note: this implementation of `Seek` is "broken" due to position
234+
// wrapping, so calling `reader.seek(Current(0))` is semantically different
235+
// than `reader.stream_position()`
233236
impl Seek for PositionReader {
234237
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
235238
match pos {
@@ -374,7 +377,7 @@ fn test_buffered_writer_seek() {
374377
let mut w = BufWriter::with_capacity(3, io::Cursor::new(Vec::new()));
375378
w.write_all(&[0, 1, 2, 3, 4, 5]).unwrap();
376379
w.write_all(&[6, 7]).unwrap();
377-
assert_eq!(w.seek(SeekFrom::Current(0)).ok(), Some(8));
380+
assert_eq!(w.stream_position().ok(), Some(8));
378381
assert_eq!(&w.get_ref().get_ref()[..], &[0, 1, 2, 3, 4, 5, 6, 7][..]);
379382
assert_eq!(w.seek(SeekFrom::Start(2)).ok(), Some(2));
380383
w.write_all(&[8, 9]).unwrap();

src/bootstrap/src/core/build_steps/test.rs

+10
Original file line numberDiff line numberDiff line change
@@ -3300,6 +3300,11 @@ impl Step for CodegenCranelift {
33003300
return;
33013301
}
33023302

3303+
if builder.download_rustc() {
3304+
builder.info("CI rustc uses the default codegen backend. skipping");
3305+
return;
3306+
}
3307+
33033308
if !target_supports_cranelift_backend(run.target) {
33043309
builder.info("target not supported by rustc_codegen_cranelift. skipping");
33053310
return;
@@ -3421,6 +3426,11 @@ impl Step for CodegenGCC {
34213426
return;
34223427
}
34233428

3429+
if builder.download_rustc() {
3430+
builder.info("CI rustc uses the default codegen backend. skipping");
3431+
return;
3432+
}
3433+
34243434
let triple = run.target.triple;
34253435
let target_supported =
34263436
if triple.contains("linux") { triple.contains("x86_64") } else { false };

src/librustdoc/passes/lint/redundant_explicit_links.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::SuggestionStyle;
66
use rustc_hir::def::{DefKind, DocLinkResMap, Namespace, Res};
77
use rustc_hir::HirId;
88
use rustc_lint_defs::Applicability;
9-
use rustc_resolve::rustdoc::source_span_for_markdown_range;
9+
use rustc_resolve::rustdoc::{prepare_to_doc_link_resolution, source_span_for_markdown_range};
1010
use rustc_span::def_id::DefId;
1111
use rustc_span::Symbol;
1212

@@ -29,16 +29,13 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
2929
return;
3030
};
3131

32-
let doc = item.doc_value();
33-
if doc.is_empty() {
34-
return;
35-
}
36-
37-
if let Some(item_id) = item.def_id() {
38-
check_redundant_explicit_link_for_did(cx, item, item_id, hir_id, &doc);
39-
}
40-
if let Some(item_id) = item.inline_stmt_id {
41-
check_redundant_explicit_link_for_did(cx, item, item_id, hir_id, &doc);
32+
let hunks = prepare_to_doc_link_resolution(&item.attrs.doc_strings);
33+
for (item_id, doc) in hunks {
34+
if let Some(item_id) = item_id.or(item.def_id())
35+
&& !doc.is_empty()
36+
{
37+
check_redundant_explicit_link_for_did(cx, item, item_id, hir_id, &doc);
38+
}
4239
}
4340
}
4441

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ check-pass
2+
#![deny(rustdoc::redundant_explicit_links)]
3+
4+
mod bar {
5+
/// [`Rc`](std::rc::Rc)
6+
pub enum Baz {}
7+
}
8+
9+
pub use bar::*;
10+
11+
use std::rc::Rc;
12+
13+
/// [`Rc::allocator`] [foo](std::rc::Rc)
14+
pub fn winit_runner() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait Hello {}
2+
3+
struct Foo<'a, T: ?Sized>(&'a T);
4+
5+
impl<'a, T: ?Sized> Hello for Foo<'a, &'a T> where Foo<'a, T>: Hello {}
6+
7+
impl Hello for Foo<'static, i32> {}
8+
9+
fn hello<T: ?Sized + Hello>() {}
10+
11+
fn main() {
12+
hello();
13+
//~^ ERROR type annotations needed
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0283]: type annotations needed
2+
--> $DIR/overflow-computing-ambiguity.rs:12:5
3+
|
4+
LL | hello();
5+
| ^^^^^ cannot infer type of the type parameter `T` declared on the function `hello`
6+
|
7+
= note: cannot satisfy `_: Hello`
8+
= help: the following types implement trait `Hello`:
9+
Foo<'a, &'a T>
10+
Foo<'static, i32>
11+
note: required by a bound in `hello`
12+
--> $DIR/overflow-computing-ambiguity.rs:9:22
13+
|
14+
LL | fn hello<T: ?Sized + Hello>() {}
15+
| ^^^^^ required by this bound in `hello`
16+
help: consider specifying the generic argument
17+
|
18+
LL | hello::<T>();
19+
| +++++
20+
21+
error: aborting due to 1 previous error
22+
23+
For more information about this error, try `rustc --explain E0283`.

0 commit comments

Comments
 (0)